generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into guoda-convert-panel-to-ts
- Loading branch information
Showing
51 changed files
with
1,428 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@cloudoperators/juno-ui-components": minor | ||
--- | ||
|
||
Migrate NativeSelect, NativeSelectionOption and NativeSelectOptionGroup components to TypeScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@cloudoperators/juno-ui-components": minor | ||
--- | ||
|
||
Migrate Form, FormRow and FormSection components to TypeScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
packages/ui-components/src/components/Form/Form.component.js
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
packages/ui-components/src/components/Form/Form.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { ReactNode, FormHTMLAttributes } from "react" | ||
|
||
const formBaseStyles = ` | ||
jn-mb-8 | ||
` | ||
|
||
const formTitleStyles = ` | ||
jn-text-2xl | ||
jn-font-bold | ||
jn-mb-4 | ||
` | ||
|
||
export interface FormProps extends FormHTMLAttributes<HTMLFormElement> { | ||
/** | ||
* Title for the form. | ||
*/ | ||
title?: string | ||
|
||
/** | ||
* Additional CSS classes to apply to the form for custom styling. | ||
*/ | ||
className?: string | ||
|
||
/** | ||
* Content to render inside the form. | ||
* This can include FormSections, FormGroups, and other form elements. | ||
*/ | ||
children?: ReactNode | ||
} | ||
|
||
/** | ||
* A Form component used to encapsulate FormSections and/or FormGroups. | ||
* Can be used to build complex forms with structured sections. | ||
*/ | ||
export const Form: React.FC<FormProps> = ({ title = "", className = "", children, ...props }) => { | ||
return ( | ||
<form className={`juno-form ${formBaseStyles} ${className}`} {...props}> | ||
{title ? <h1 className={`juno-form-heading ${formTitleStyles}`}>{title}</h1> : null} | ||
{children} | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as React from "react" | ||
import { render, screen } from "@testing-library/react" | ||
import { describe, expect, test } from "vitest" | ||
|
||
import { Form } from "./Form.component" | ||
|
||
describe("Form Component Tests", () => { | ||
describe("Basic Rendering", () => { | ||
test("renders a Form", () => { | ||
render(<Form data-testid="my-form" />) | ||
expect(screen.getByTestId("my-form")).toBeInTheDocument() | ||
}) | ||
|
||
test("renders a title", () => { | ||
render(<Form data-testid="my-form" title="My Form" />) | ||
expect(screen.getByTestId("my-form")).toBeInTheDocument() | ||
expect(screen.getByRole("heading")).toHaveClass("juno-form-heading") | ||
expect(screen.getByRole("heading")).toHaveTextContent("My Form") | ||
}) | ||
|
||
test("renders without any props", () => { | ||
const { container } = render(<Form />) | ||
expect(container.firstChild).toBeInTheDocument() | ||
expect(container.firstChild).toHaveClass("juno-form") | ||
}) | ||
|
||
test("renders with falsy values as title", () => { | ||
render(<Form data-testid="my-form" title={""} />) | ||
expect(screen.queryByRole("heading")).not.toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe("Props Handling", () => { | ||
test("renders a custom className", () => { | ||
render(<Form data-testid="my-form" className="my-custom-class" />) | ||
expect(screen.getByTestId("my-form")).toBeInTheDocument() | ||
expect(screen.getByTestId("my-form")).toHaveClass("my-custom-class") | ||
}) | ||
|
||
test("renders all props as passed", () => { | ||
render(<Form data-testid="23" data-lolol={true} />) | ||
expect(screen.getByTestId("23")).toBeInTheDocument() | ||
expect(screen.getByTestId("23")).toHaveAttribute("data-lolol") | ||
}) | ||
|
||
test("applies default styles", () => { | ||
const { container } = render(<Form />) | ||
expect(container.firstChild).toHaveClass("juno-form") | ||
expect(container.firstChild).toHaveClass("jn-mb-8") | ||
}) | ||
}) | ||
|
||
describe("Children Rendering", () => { | ||
test("renders children as passed", () => { | ||
render( | ||
<Form data-testid="my-form"> | ||
<button></button> | ||
</Form> | ||
) | ||
expect(screen.getByRole("button")).toBeInTheDocument() | ||
}) | ||
|
||
test("renders multiple children", () => { | ||
render( | ||
<Form data-testid="my-form"> | ||
<button>Button 1</button> | ||
<button>Button 2</button> | ||
</Form> | ||
) | ||
expect(screen.getByText("Button 1")).toBeInTheDocument() | ||
expect(screen.getByText("Button 2")).toBeInTheDocument() | ||
}) | ||
|
||
test("renders with no children", () => { | ||
render(<Form data-testid="my-form" />) | ||
expect(screen.getByTestId("my-form").childElementCount).toBe(0) | ||
}) | ||
}) | ||
}) |
File renamed without changes.
Oops, something went wrong.