2022-11-10 20:13:15 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { useArgs } from '@storybook/client-api';
|
2022-10-26 00:23:18 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
SIZES,
|
|
|
|
COLORS,
|
|
|
|
BORDER_RADIUS,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
|
|
|
|
import { TEXT_FIELD_SIZES, TEXT_FIELD_TYPES } from './text-field.constants';
|
|
|
|
import { TextField } from './text-field';
|
|
|
|
|
|
|
|
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/TextField',
|
2023-01-20 20:27:46 +01:00
|
|
|
|
2022-10-26 00:23:18 +02:00
|
|
|
component: TextField,
|
|
|
|
parameters: {
|
|
|
|
docs: {
|
|
|
|
page: README,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
argTypes: {
|
|
|
|
value: {
|
|
|
|
control: 'text',
|
|
|
|
},
|
|
|
|
onChange: {
|
|
|
|
action: 'onChange',
|
|
|
|
},
|
2022-11-10 20:13:15 +01:00
|
|
|
showClearButton: {
|
|
|
|
control: 'boolean',
|
2022-10-26 00:23:18 +02:00
|
|
|
},
|
2022-11-10 20:13:15 +01:00
|
|
|
clearButtonOnClick: {
|
|
|
|
action: 'clearButtonOnClick',
|
2022-10-26 00:23:18 +02:00
|
|
|
},
|
|
|
|
clearButtonProps: {
|
|
|
|
control: 'object',
|
|
|
|
},
|
|
|
|
autoComplete: {
|
|
|
|
control: 'boolean',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
autoFocus: {
|
|
|
|
control: 'boolean',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
className: {
|
|
|
|
control: 'text',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
control: 'boolean',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
error: {
|
|
|
|
control: 'boolean',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
id: {
|
|
|
|
control: 'text',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
inputProps: {
|
|
|
|
control: 'object',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
leftAccessory: {
|
|
|
|
control: 'text',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
maxLength: {
|
|
|
|
control: 'number',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
control: 'text',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
onBlur: {
|
|
|
|
action: 'onBlur',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
onClick: {
|
|
|
|
action: 'onClick',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
onFocus: {
|
|
|
|
action: 'onFocus',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
onKeyDown: {
|
|
|
|
action: 'onKeyDown',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
onKeyUp: {
|
|
|
|
action: 'onKeyUp',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
placeholder: {
|
|
|
|
control: 'text',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
readOnly: {
|
|
|
|
control: 'boolean',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
required: {
|
|
|
|
control: 'boolean',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
rightAccessory: {
|
|
|
|
control: 'text',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
control: 'select',
|
|
|
|
options: Object.values(TEXT_FIELD_SIZES),
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
control: 'select',
|
|
|
|
options: Object.values(TEXT_FIELD_TYPES),
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
truncate: {
|
|
|
|
control: 'boolean',
|
|
|
|
table: { category: 'text field base props' },
|
|
|
|
},
|
|
|
|
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: {
|
2022-11-10 20:13:15 +01:00
|
|
|
showClearButton: false,
|
2022-10-26 00:23:18 +02:00
|
|
|
placeholder: 'Placeholder...',
|
|
|
|
autoFocus: false,
|
|
|
|
disabled: false,
|
|
|
|
error: false,
|
|
|
|
id: '',
|
|
|
|
readOnly: false,
|
|
|
|
required: false,
|
|
|
|
size: SIZES.MD,
|
|
|
|
type: 'text',
|
|
|
|
truncate: false,
|
2022-12-06 20:52:03 +01:00
|
|
|
value: '',
|
2022-10-26 00:23:18 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-11-10 20:13:15 +01:00
|
|
|
const Template = (args) => {
|
|
|
|
const [{ value }, updateArgs] = useArgs();
|
2022-10-26 00:23:18 +02:00
|
|
|
const handleOnChange = (e) => {
|
2022-11-10 20:13:15 +01:00
|
|
|
updateArgs({ value: e.target.value });
|
|
|
|
};
|
|
|
|
const handleOnClear = () => {
|
|
|
|
updateArgs({ value: '' });
|
2022-10-26 00:23:18 +02:00
|
|
|
};
|
|
|
|
return (
|
|
|
|
<TextField
|
|
|
|
{...args}
|
|
|
|
value={value}
|
|
|
|
onChange={handleOnChange}
|
2022-11-10 20:13:15 +01:00
|
|
|
clearButtonOnClick={handleOnClear}
|
2022-10-26 00:23:18 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-11-10 20:13:15 +01:00
|
|
|
export const DefaultStory = Template.bind({});
|
|
|
|
DefaultStory.storyName = 'Default';
|
|
|
|
|
|
|
|
export const ShowClearButton = Template.bind({});
|
|
|
|
|
|
|
|
ShowClearButton.args = {
|
|
|
|
placeholder: 'Enter text to show clear',
|
|
|
|
showClearButton: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ClearButtonProps = Template.bind({});
|
|
|
|
ClearButtonProps.args = {
|
2022-10-26 00:23:18 +02:00
|
|
|
value: 'clear button props',
|
|
|
|
size: SIZES.LG,
|
2022-11-10 20:13:15 +01:00
|
|
|
showClearButton: true,
|
2022-10-26 00:23:18 +02:00
|
|
|
clearButtonProps: {
|
|
|
|
backgroundColor: COLORS.BACKGROUND_ALTERNATIVE,
|
|
|
|
borderRadius: BORDER_RADIUS.XS,
|
|
|
|
},
|
|
|
|
};
|