-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathTextComponent.stories.tsx
More file actions
53 lines (49 loc) · 1.59 KB
/
TextComponent.stories.tsx
File metadata and controls
53 lines (49 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type { Meta, StoryObj } from '@storybook/react-vite';
import React, { useState } from 'react';
import { fn } from 'storybook/test';
import TextComponent from '../TextComponent';
import { withControlGroup } from '../../../../.storybook/withControlGroup';
const meta = {
component: TextComponent,
title: 'TextComponent',
argTypes: { handleChange: { action: 'handleChange' } },
render: (props) => {
// due to stories incompatibility, eslint rule is off
// React Hook "useState" is called in function "render" that is neither a React function component
// TODO: introduce a stateless stories component to reflect thaat component logic itself
const [value, setValue] = useState(props.value); // eslint-disable-line react-hooks/rules-of-hooks
return (
<TextComponent
{...props}
handleChange={(field, data) => {
setValue(data);
props.handleChange(field, data);
}}
value={value}
/>
);
},
decorators: [withControlGroup],
} satisfies Meta<typeof TextComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Base: Story = {
args: {
handleChange: fn(),
value: '',
field: 'field',
error: false,
encrypted: false,
disabled: false,
},
};
export const AllPropsTrue: Story = {
args: {
handleChange: fn(),
value: 'default value',
field: 'field',
error: true,
encrypted: true,
disabled: true,
},
};