2023-02-21 19:35:28 +01:00
|
|
|
import React, { useRef } from 'react';
|
2023-07-25 06:13:17 +02:00
|
|
|
import { Meta } from '@storybook/react';
|
2023-02-21 19:35:28 +01:00
|
|
|
import { useArgs } from '@storybook/client-api';
|
|
|
|
|
|
|
|
import {
|
2023-07-25 06:13:17 +02:00
|
|
|
Display,
|
|
|
|
FlexDirection,
|
2023-02-21 19:35:28 +01:00
|
|
|
TextVariant,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
|
2023-07-25 06:13:17 +02:00
|
|
|
import { Button, Box, BUTTON_VARIANT } from '..';
|
2023-02-21 19:35:28 +01:00
|
|
|
|
2023-07-25 06:13:17 +02:00
|
|
|
import { InputType } from './input.types';
|
2023-02-21 19:35:28 +01:00
|
|
|
import { Input } from './input';
|
|
|
|
|
|
|
|
import README from './README.mdx';
|
|
|
|
|
|
|
|
const marginSizeControlOptions = [
|
|
|
|
undefined,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
6,
|
|
|
|
7,
|
|
|
|
8,
|
|
|
|
9,
|
|
|
|
10,
|
|
|
|
11,
|
|
|
|
12,
|
|
|
|
'auto',
|
|
|
|
];
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Components/ComponentLibrary/Input',
|
|
|
|
component: Input,
|
|
|
|
parameters: {
|
|
|
|
docs: {
|
|
|
|
page: README,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
argTypes: {
|
|
|
|
autoComplete: {
|
|
|
|
control: 'boolean',
|
|
|
|
},
|
|
|
|
autoFocus: {
|
|
|
|
control: 'boolean',
|
|
|
|
},
|
|
|
|
className: {
|
|
|
|
control: 'text',
|
|
|
|
},
|
|
|
|
defaultValue: {
|
|
|
|
control: 'text',
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
control: 'boolean',
|
|
|
|
},
|
|
|
|
disableStateStyles: {
|
|
|
|
control: 'boolean',
|
|
|
|
},
|
|
|
|
error: {
|
|
|
|
control: 'boolean',
|
|
|
|
},
|
|
|
|
id: {
|
|
|
|
control: 'text',
|
|
|
|
},
|
|
|
|
maxLength: {
|
|
|
|
control: 'number',
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
control: 'text',
|
|
|
|
},
|
|
|
|
onBlur: {
|
|
|
|
action: 'onBlur',
|
|
|
|
},
|
|
|
|
onChange: {
|
|
|
|
action: 'onChange',
|
|
|
|
},
|
|
|
|
onFocus: {
|
|
|
|
action: 'onFocus',
|
|
|
|
},
|
|
|
|
placeholder: {
|
|
|
|
control: 'text',
|
|
|
|
},
|
|
|
|
readOnly: {
|
|
|
|
control: 'boolean',
|
|
|
|
},
|
|
|
|
required: {
|
|
|
|
control: 'boolean',
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
control: 'select',
|
2023-07-25 06:13:17 +02:00
|
|
|
options: Object.values(InputType),
|
2023-02-21 19:35:28 +01:00
|
|
|
},
|
|
|
|
value: {
|
|
|
|
control: 'text',
|
|
|
|
},
|
|
|
|
textVariant: {
|
|
|
|
control: 'select',
|
|
|
|
options: Object.values(TextVariant),
|
|
|
|
},
|
|
|
|
marginTop: {
|
|
|
|
options: marginSizeControlOptions,
|
|
|
|
control: 'select',
|
|
|
|
table: { category: 'box props' },
|
|
|
|
},
|
|
|
|
marginRight: {
|
|
|
|
options: marginSizeControlOptions,
|
|
|
|
control: 'select',
|
|
|
|
table: { category: 'box props' },
|
|
|
|
},
|
|
|
|
marginBottom: {
|
|
|
|
options: marginSizeControlOptions,
|
|
|
|
control: 'select',
|
|
|
|
table: { category: 'box props' },
|
|
|
|
},
|
|
|
|
marginLeft: {
|
|
|
|
options: marginSizeControlOptions,
|
|
|
|
control: 'select',
|
|
|
|
table: { category: 'box props' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: {
|
|
|
|
placeholder: 'Placeholder...',
|
|
|
|
value: '',
|
|
|
|
},
|
2023-07-25 06:13:17 +02:00
|
|
|
} as Meta<typeof Input>;
|
2023-02-21 19:35:28 +01:00
|
|
|
|
|
|
|
const Template = (args) => {
|
|
|
|
const [{ value }, updateArgs] = useArgs();
|
|
|
|
const handleOnChange = (e) => {
|
|
|
|
updateArgs({ value: e.target.value });
|
|
|
|
};
|
|
|
|
return <Input {...args} value={value} onChange={handleOnChange} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const DefaultStory = Template.bind({});
|
|
|
|
DefaultStory.storyName = 'Default';
|
|
|
|
|
|
|
|
export const Type = (args) => (
|
|
|
|
<Box
|
2023-07-25 06:13:17 +02:00
|
|
|
display={Display.InlineFlex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
2023-02-21 19:35:28 +01:00
|
|
|
gap={4}
|
|
|
|
>
|
|
|
|
<Input {...args} placeholder="Default" />
|
2023-07-25 06:13:17 +02:00
|
|
|
<Input {...args} type={InputType.Password} placeholder="Password" />
|
|
|
|
<Input {...args} type={InputType.Number} placeholder="Number" />
|
|
|
|
<Input {...args} type={InputType.Search} placeholder="Search" />
|
2023-02-21 19:35:28 +01:00
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
|
|
|
|
Type.args = {
|
|
|
|
value: undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Ref = (args) => {
|
|
|
|
const [{ value }, updateArgs] = useArgs();
|
2023-07-25 06:13:17 +02:00
|
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
2023-02-21 19:35:28 +01:00
|
|
|
const handleOnClick = () => {
|
2023-07-25 06:13:17 +02:00
|
|
|
inputRef.current?.focus();
|
2023-02-21 19:35:28 +01:00
|
|
|
};
|
|
|
|
const handleOnChange = (e) => {
|
|
|
|
updateArgs({ value: e.target.value });
|
|
|
|
};
|
|
|
|
return (
|
2023-07-25 06:13:17 +02:00
|
|
|
<Box display={Display.Flex}>
|
2023-02-21 19:35:28 +01:00
|
|
|
<Input {...args} ref={inputRef} value={value} onChange={handleOnChange} />
|
2023-07-25 06:13:17 +02:00
|
|
|
<Button
|
|
|
|
variant={BUTTON_VARIANT.PRIMARY}
|
|
|
|
marginLeft={1}
|
|
|
|
onClick={handleOnClick}
|
|
|
|
>
|
2023-02-21 19:35:28 +01:00
|
|
|
Edit
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const AutoComplete = Template.bind({});
|
|
|
|
AutoComplete.args = {
|
|
|
|
autoComplete: true,
|
2023-07-25 06:13:17 +02:00
|
|
|
type: InputType.Password,
|
2023-02-21 19:35:28 +01:00
|
|
|
placeholder: 'Enter password',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const AutoFocus = Template.bind({});
|
|
|
|
AutoFocus.args = { autoFocus: true };
|
|
|
|
|
|
|
|
export const DefaultValue = () => (
|
|
|
|
<Input placeholder="Default value" defaultValue="Default value" />
|
|
|
|
);
|
|
|
|
export const Disabled = Template.bind({});
|
|
|
|
Disabled.args = { disabled: true };
|
|
|
|
|
|
|
|
export const ErrorStory = Template.bind({});
|
|
|
|
ErrorStory.args = { error: true };
|
|
|
|
ErrorStory.storyName = 'Error';
|
|
|
|
|
|
|
|
export const MaxLength = Template.bind({});
|
|
|
|
MaxLength.args = { maxLength: 10, placeholder: 'Max length 10' };
|
|
|
|
|
|
|
|
export const ReadOnly = Template.bind({});
|
|
|
|
ReadOnly.args = { readOnly: true, value: 'Read only' };
|
|
|
|
|
2023-07-25 06:13:17 +02:00
|
|
|
export const RequiredStory = Template.bind({});
|
|
|
|
RequiredStory.args = { required: true, placeholder: 'Required' };
|
|
|
|
RequiredStory.storyName = 'Required';
|
2023-02-21 19:35:28 +01:00
|
|
|
|
|
|
|
export const DisableStateStyles = Template.bind({});
|
|
|
|
DisableStateStyles.args = {
|
|
|
|
disableStateStyles: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const TextVariantStory = (args) => {
|
|
|
|
const [{ value }, updateArgs] = useArgs();
|
|
|
|
const handleOnChange = (e) => {
|
|
|
|
updateArgs({ value: e.target.value });
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<Box
|
2023-07-25 06:13:17 +02:00
|
|
|
display={Display.InlineFlex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
2023-02-21 19:35:28 +01:00
|
|
|
gap={4}
|
|
|
|
>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.displayMd}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.headingLg}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.headingMd}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.headingSm}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.bodyLgMedium}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.bodyMdBold}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.bodyMd}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.bodySm}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.bodySmBold}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
|
|
|
textVariant={TextVariant.bodyXs}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
TextVariantStory.storyName = 'Text Variant';
|