diff --git a/.changeset/nice-moons-watch.md b/.changeset/nice-moons-watch.md new file mode 100644 index 000000000..fe03d2c25 --- /dev/null +++ b/.changeset/nice-moons-watch.md @@ -0,0 +1,5 @@ +--- +"@cloudoperators/juno-ui-components": minor +--- + +Migrate NativeSelect, NativeSelectionOption and NativeSelectOptionGroup components to TypeScript diff --git a/.changeset/shaggy-pots-repeat.md b/.changeset/shaggy-pots-repeat.md new file mode 100644 index 000000000..e1c0496ce --- /dev/null +++ b/.changeset/shaggy-pots-repeat.md @@ -0,0 +1,5 @@ +--- +"@cloudoperators/juno-ui-components": minor +--- + +Migrate Form, FormRow and FormSection components to TypeScript diff --git a/packages/ui-components/src/components/FilterInput/FilterInput.component.js b/packages/ui-components/src/components/FilterInput/FilterInput.component.js index 69fd626d1..4a748642d 100644 --- a/packages/ui-components/src/components/FilterInput/FilterInput.component.js +++ b/packages/ui-components/src/components/FilterInput/FilterInput.component.js @@ -5,8 +5,8 @@ import React, { useState, useEffect } from "react" import PropTypes from "prop-types" -import { NativeSelect } from "../NativeSelect/NativeSelect.component" -import { NativeSelectOption } from "../NativeSelectOption/NativeSelectOption.component" +import { NativeSelect } from "../../deprecated_js/NativeSelect/NativeSelect.component" +import { NativeSelectOption } from "../../deprecated_js/NativeSelectOption/NativeSelectOption.component" import { TextInput } from "../../deprecated_js/TextInput/TextInput.component" import { Icon } from "../../deprecated_js/Icon/Icon.component" diff --git a/packages/ui-components/src/components/Form/Form.component.js b/packages/ui-components/src/components/Form/Form.component.js deleted file mode 100644 index e85a6f8b3..000000000 --- a/packages/ui-components/src/components/Form/Form.component.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from "react" -import PropTypes from "prop-types" - -const formStyles = ` - jn-mb-8 -` - -const formHeading = ` - jn-text-2xl - jn-font-bold - jn-mb-4 -` - -/** A Form to hold FormSections and/or FormGroups with an optional title. */ -export const Form = ({ title = null, className = "", children = null, ...props }) => { - return ( -
- {title ?

{title}

: ""} - {children} -
- ) -} - -Form.propTypes = { - /** Title to be rendered in the Form`. */ - title: PropTypes.string, - /** Custom className */ - className: PropTypes.string, - /** Children to render in the form */ - children: PropTypes.node, -} diff --git a/packages/ui-components/src/components/Form/Form.component.tsx b/packages/ui-components/src/components/Form/Form.component.tsx new file mode 100644 index 000000000..422f037c0 --- /dev/null +++ b/packages/ui-components/src/components/Form/Form.component.tsx @@ -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 { + /** + * 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 = ({ title = "", className = "", children, ...props }) => { + return ( +
+ {title ?

{title}

: null} + {children} +
+ ) +} diff --git a/packages/ui-components/src/components/Form/Form.stories.js b/packages/ui-components/src/components/Form/Form.stories.tsx similarity index 59% rename from packages/ui-components/src/components/Form/Form.stories.js rename to packages/ui-components/src/components/Form/Form.stories.tsx index 30d3abbff..5e229095e 100644 --- a/packages/ui-components/src/components/Form/Form.stories.js +++ b/packages/ui-components/src/components/Form/Form.stories.tsx @@ -4,20 +4,31 @@ */ import React from "react" -import PropTypes from "prop-types" -import { Form } from "./index.js" -import { FormRow } from "../FormRow/index.js" -import { FormSection } from "../FormSection/index.js" -import { FormHint } from "../../deprecated_js/FormHint/index.js" -import { TextInput } from "../../deprecated_js/TextInput/index.js" -import { Select } from "../../deprecated_js/Select/index.js" -import { SelectOption } from "../../deprecated_js/SelectOption/index.js" -import { Switch } from "../../deprecated_js/Switch/Switch.component" -import { Textarea } from "../../deprecated_js/Textarea/index.js" -import { Button } from "../../deprecated_js/Button/index.js" -import { ButtonRow } from "../../deprecated_js/ButtonRow/index.js" -import { IntroBox } from "../IntroBox/index.ts" -import { PortalProvider } from "../../deprecated_js/PortalProvider/PortalProvider.component" +import { Meta, StoryFn } from "@storybook/react" + +import { Form, FormProps } from "./Form.component" +import { FormRow } from "../FormRow/FormRow.component" +import { FormHint } from "../FormHint/FormHint.component" +import { FormSection } from "../FormSection/FormSection.component" + +import { Select } from "../Select/Select.component" +import { SelectOption } from "../SelectOption/SelectOption.component" + +import { Textarea } from "../Textarea/Textarea.component" +import { TextInput } from "../TextInput/TextInput.component" + +import { Button } from "../Button/Button.component" +import { ButtonRow } from "../ButtonRow/ButtonRow.component" + +import { Radio } from "../Radio/Radio.component" +import { RadioGroup } from "../RadioGroup/RadioGroup.component" + +import { Checkbox } from "../Checkbox/Checkbox.component" +import { CheckboxGroup } from "../CheckboxGroup/CheckboxGroup.component" + +import { PortalProvider } from "../PortalProvider/PortalProvider.component" +import { IntroBox } from "../IntroBox/IntroBox.component" +import { Switch } from "../Switch/Switch.component" export default { title: "Forms/Form", @@ -30,10 +41,13 @@ export default { }, children: { control: false, + table: { + type: { summary: "ReactNode" }, + }, }, }, decorators: [ - (Story) => ( + (Story: StoryFn) => (
@@ -41,16 +55,13 @@ export default {
), ], -} +} as Meta -const Template = ({ children, ...args }) =>
{children}
-Template.propTypes = { - children: PropTypes.node, -} +// eslint-disable-next-line react/prop-types +const Template: StoryFn = ({ children, ...args }) =>
{children}
export const Default = { render: Template, - args: { title: "A Simple Form", children: [ @@ -73,7 +84,6 @@ export const Default = { export const ComplexForm = { render: Template, - args: { title: "A Complex Form", children: [ @@ -101,6 +111,16 @@ export const ComplexForm = { , + + + + + + + + + +