|
1 | 1 | import * as React from 'react'
|
2 |
| -import { InputField } from './index' |
3 |
| -import type { Story, Meta } from '@storybook/react' |
| 2 | +import { Flex, SPACING, VIEWPORT } from '@opentrons/components' |
| 3 | +import { InputField as InputFieldComponent } from './index' |
| 4 | +import type { Meta, StoryObj } from '@storybook/react' |
4 | 5 |
|
5 |
| -export default { |
| 6 | +const meta: Meta<typeof InputFieldComponent> = { |
| 7 | + // ToDo (kk05/02/2024) this should be in Library but at this moment there is the same name component in components |
| 8 | + // The unification for this component will be done when the old component is retired completely. |
6 | 9 | title: 'App/Atoms/InputField',
|
7 |
| - component: InputField, |
8 |
| -} as Meta |
| 10 | + component: InputFieldComponent, |
| 11 | + parameters: VIEWPORT.touchScreenViewport, |
| 12 | +} |
| 13 | + |
| 14 | +export default meta |
| 15 | +type Story = StoryObj<typeof InputFieldComponent> |
9 | 16 |
|
10 |
| -const Template: Story<React.ComponentProps<typeof InputField>> = args => ( |
11 |
| - <InputField {...args} /> |
12 |
| -) |
| 17 | +export const InputField: Story = args => { |
| 18 | + const [value, setValue] = React.useState(args.value) |
| 19 | + return ( |
| 20 | + <Flex padding={SPACING.spacing16} width="100%"> |
| 21 | + <InputFieldComponent |
| 22 | + {...args} |
| 23 | + value={value} |
| 24 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 25 | + setValue(e.target.value) |
| 26 | + }} |
| 27 | + units={args.type !== 'number' ? undefined : args.units} |
| 28 | + /> |
| 29 | + </Flex> |
| 30 | + ) |
| 31 | +} |
13 | 32 |
|
14 |
| -export const Primary = Template.bind({}) |
15 |
| -Primary.args = { |
| 33 | +InputField.args = { |
16 | 34 | value: 200,
|
17 | 35 | units: 'rpm',
|
18 | 36 | type: 'number',
|
19 | 37 | caption: 'example caption',
|
20 | 38 | max: 200,
|
21 |
| - min: 200, |
| 39 | + min: 10, |
| 40 | +} |
| 41 | + |
| 42 | +export const InputFieldWithError: Story = args => { |
| 43 | + const [value, setValue] = React.useState(args.value) |
| 44 | + return ( |
| 45 | + <Flex padding={SPACING.spacing16} width="100%"> |
| 46 | + <InputFieldComponent |
| 47 | + {...args} |
| 48 | + value={value} |
| 49 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 50 | + setValue(e.target.value) |
| 51 | + }} |
| 52 | + units={args.type !== 'number' ? undefined : args.units} |
| 53 | + /> |
| 54 | + </Flex> |
| 55 | + ) |
22 | 56 | }
|
23 | 57 |
|
24 |
| -export const ErrorMessage = Template.bind({}) |
25 |
| -ErrorMessage.args = { |
| 58 | +InputFieldWithError.args = { |
26 | 59 | units: 'C',
|
27 | 60 | type: 'number',
|
28 | 61 | caption: 'example caption',
|
|
0 commit comments