aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/forms/labelled-field/labelled-field.stories.tsx
blob: 1d1af701c54fd6cef5ea7a153e35c4e8461e6ae1 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import { type ChangeEvent, useState, useCallback } from 'react';
import { Input, Label } from '../../../atoms';
import { LabelledField } from './labelled-field';

/**
 * LabelledField - Storybook Meta
 */
export default {
  title: 'Molecules/Forms/Field',
  component: LabelledField,
  argTypes: {
    className: {
      control: {
        type: 'text',
      },
      description: 'Set additional classnames to the field.',
      table: {
        category: 'Styles',
      },
      type: {
        name: 'string',
        required: false,
      },
    },
    field: {
      control: {
        type: null,
      },
      description: 'A component: Checkbox, Input, Select, Radio or TextArea.',
      type: {
        name: 'function',
        required: true,
      },
    },
    label: {
      control: {
        type: null,
      },
      description: 'A Label component.',
      type: {
        name: 'function',
        required: true,
      },
    },
    isInline: {
      control: {
        type: 'boolean',
      },
      description: 'Should the label and the field be inlined?',
      table: {
        category: 'Options',
        defaultValue: { summary: false },
      },
      type: {
        name: 'boolean',
        required: false,
      },
    },
    isReversedOrder: {
      control: {
        type: 'boolean',
      },
      description: 'Should the label and the field be reversed?',
      table: {
        category: 'Options',
        defaultValue: { summary: false },
      },
      type: {
        name: 'boolean',
        required: false,
      },
    },
  },
} as ComponentMeta<typeof LabelledField>;

const Template: ComponentStory<typeof LabelledField> = ({ ...args }) => {
  const id = 'sunt';
  const [value, setValue] = useState<string>('');
  const updateValue = useCallback((e: ChangeEvent<HTMLInputElement>) => {
    setValue(e.target.value);
  }, []);

  return (
    <LabelledField
      {...args}
      field={
        <Input
          id={id}
          name={id}
          onChange={updateValue}
          type="text"
          value={value}
        />
      }
      label={<Label htmlFor={id}>A label</Label>}
    />
  );
};

/**
 * Labelled Field Stories - Left
 */
export const Left = Template.bind({});
Left.args = {
  isInline: true,
};

/**
 * Labelled Field Stories - Right
 */
export const Right = Template.bind({});
Right.args = {
  isInline: true,
  isReversedOrder: true,
};

/**
 * Labelled Field Stories - Top
 */
export const Top = Template.bind({});
Top.args = {};

/**
 * Labelled Field Stories - Bottom
 */
export const Bottom = Template.bind({});
Bottom.args = {
  isReversedOrder: true,
};