diff --git a/packages/orbit-components/src/InputGroup/InputGroup.stories.tsx b/packages/orbit-components/src/InputGroup/InputGroup.stories.tsx index 0100d8da0c..a485b27976 100644 --- a/packages/orbit-components/src/InputGroup/InputGroup.stories.tsx +++ b/packages/orbit-components/src/InputGroup/InputGroup.stories.tsx @@ -1,20 +1,59 @@ import * as React from "react"; +import type { Meta, StoryObj } from "@storybook/react"; import { action } from "@storybook/addon-actions"; import Stack from "../Stack"; import InputField from "../InputField"; import Select from "../Select"; -import { SIZE_OPTIONS } from "./consts"; import CountryFlag from "../CountryFlag"; import RenderInRtl from "../utils/rtl/RenderInRtl"; import { SPACINGS_AFTER } from "../common/consts"; import InputGroup from "."; -export default { +type InputGroupPropsAndCustomArgs = React.ComponentProps & { + inputValue?: string | number; + placeholder?: string; + selectValue?: string | number; + errorGroup?: string; + helpGroup?: string; + errorSingleField?: string; + helpSingleField?: string; +}; + +const meta: Meta = { title: "InputGroup", + component: InputGroup, + + parameters: { + controls: { + exclude: ["onChange", "onFocus", "onBlur", "onBlurGroup", "size"], + }, + }, + + args: { + error: "", + help: "", + helpClosable: true, + onChange: action("onChange"), + onFocus: action("onFocus"), + onBlur: action("onBlur"), + onBlurGroup: action("onBlurGroup"), + }, + + argTypes: { + spaceAfter: { + options: Object.values(SPACINGS_AFTER), + control: { + type: "select", + }, + }, + }, }; +export default meta; +type Story = StoryObj; + const selectOptionsMonths = [ { value: "January", label: "January" }, { value: "February", label: "February" }, @@ -30,16 +69,9 @@ const selectOptionsMonths = [ { value: "December", label: "December" }, ]; -export const DateOfBirth = ({ label, flex, error, help, selectValue }) => { - return ( - +export const DateOfBirth: Story = { + render: ({ error, help, selectValue, ...args }) => ( + { } - error={error} - help={help} - /> - - - ); -}; - -PhoneNumber.story = { - name: "Phone number", - - parameters: { - info: "Some description about this type of InputGroup in general.", +export const PhoneNumber: Story = { + render: ({ error, help, selectValue, placeholder, inputValue, ...args }) => { + const countryFlagCode = selectOptionsPhoneNumber.filter( + option => option.value === selectValue, + )[0].code; + + return ( + + - + - ); -}; + ), -Error.args = { - label: "Label", - flex: ["0 0 60px", "1 1 100%", "0 0 90px"], - error: "Something went wrong on day field", - help: "", - selectValue: selectOptionsError[0].value, -}; + parameters: { + controls: { + exclude: ["onChange", "onFocus", "onBlur", "onBlurGroup", "size", "help", "helpClosable"], + }, + }, -Error.argTypes = { - selectValue: { - options: selectOptionsError.map(opt => opt.value), - control: { - type: "select", + args: { + label: "Label", + flex: ["0 0 60px", "1 1 100%", "0 0 90px"], + selectValue: selectOptionsError[0].value, + error: "Something went wrong on day field", + }, + + argTypes: { + selectValue: { + options: selectOptionsError.map(opt => opt.value), + control: { + type: "select", + }, }, }, }; -export const ValidationApproaches = ({ - inputValue, - errorGroup, - helpGroup, - errorSingleField, - helpSingleField, -}) => { - return ( +export const ValidationApproaches: Story = { + render: ({ inputValue, errorGroup, helpGroup, errorSingleField, helpSingleField }) => ( - + - ); -}; - -ValidationApproaches.story = { - name: "Validation approches", + ), parameters: { - info: "Some description about this type of InputGroup in general.", + controls: { + exclude: [ + "onChange", + "onFocus", + "onBlur", + "onBlurGroup", + "error", + "help", + "helpClosable", + "size", + "spaceAfter", + ], + }, }, -}; -ValidationApproaches.args = { - inputValue: "", - errorGroup: "Something went wrong on day field", - helpGroup: "", - errorSingleField: "Something went wrong on day field", - helpSingleField: "", + args: { + inputValue: "", + errorGroup: "Something went wrong on day field", + helpGroup: "", + errorSingleField: "Something went wrong on day field", + helpSingleField: "", + }, }; -export const OnChangeBehavior = ({ inputValue }) => { - return ( +export const OnChangeBehavior: Story = { + render: ({ inputValue }) => ( @@ -280,32 +284,41 @@ export const OnChangeBehavior = ({ inputValue }) => { /> - ); -}; - -OnChangeBehavior.story = { - name: "onChange behaviour", + ), parameters: { - info: "Some description about this type of InputGroup in general.", + controls: { + exclude: [ + "onChange", + "onFocus", + "onBlur", + "onBlurGroup", + "error", + "help", + "helpClosable", + "size", + "spaceAfter", + ], + }, }, -}; -OnChangeBehavior.args = { - inputValue: "", + args: { + inputValue: "", + }, }; -export const Disabled = () => { - return ( - +export const Disabled: Story = { + render: args => ( + - ); -}; + ), -Disabled.story = { - name: "Disabled", + args: { + label: "Disabled", + disabled: true, + }, }; const selectOptionsPlayground = [ @@ -313,116 +326,63 @@ const selectOptionsPlayground = [ { value: 2, label: "Second item" }, ]; -export const Playground = ({ - label, - flex, - size, - error, - help, - selectValue, - placeholder, - inputValue, - dataTest, - spaceAfter, -}) => { - return ( - +export const Playground: Story = { + render: ({ error, help, selectValue, placeholder, inputValue, ...args }) => ( + - ); -}; - -Playground.story = { - parameters: { - info: "Some description about this type of InputGroup in general.", + ), + + args: { + label: "Label", + flex: ["1 0 200px", "1 1 100%", "1 0 150px", "0 1 50%"], + selectValue: selectOptionsPlayground[0].value, + placeholder: "Placeholder", + inputValue: "", + spaceAfter: SPACINGS_AFTER.MEDIUM, + disabled: false, }, -}; -Playground.args = { - label: "Phone number", - flex: ["1 0 200px", "1 1 100%", "1 0 150px", "0 1 50%"], - size: SIZE_OPTIONS.NORMAL, - error: "", - help: "", - selectValue: selectOptionsPlayground[0].value, - placeholder: "Placeholder", - inputValue: "", - dataTest: "test", - spaceAfter: SPACINGS_AFTER.MEDIUM, -}; - -Playground.argTypes = { - size: { - options: Object.values(SIZE_OPTIONS), - control: { - type: "select", - }, - }, - selectValue: { - options: selectOptionsPlayground.map(opt => opt.value), - control: { - type: "select", - }, - }, - spaceAfter: { - options: Object.values(SPACINGS_AFTER), - control: { - type: "select", + argTypes: { + selectValue: { + options: selectOptionsPlayground.map(opt => opt.value), + control: { + type: "select", + }, }, }, }; -export const Rtl = ({ flex, selectValue, error, help, label }) => { - return ( +export const Rtl: Story = { + render: ({ selectValue, error, help, ...args }) => ( - +