-
Notifications
You must be signed in to change notification settings - Fork 1
/
formSection.stories.tsx
126 lines (120 loc) 路 3.73 KB
/
formSection.stories.tsx
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
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import FormSection, { FormSectionLabelPosition } from '../src/formSection';
import TextInput from '../src/textInput';
import StoryColumn from './storyColumn';
interface IDemoStateWrapperProps {
render: (text: string, changeHandler: (event: React.ChangeEvent<HTMLInputElement>) => void) => any;
initialValue?: string;
}
const DemoStateWrapper = ({ render, initialValue }: IDemoStateWrapperProps) => {
const [text, setText] = React.useState(initialValue || '');
return render(text, ({ target }) => {
setText(target.value);
});
};
storiesOf('Components|Molecules (Composite)/FormSection', module)
.add('Default State', () => (
<StoryColumn>
<h1>
<code>{'<FormSection />'}</code> Component
</h1>
<h2>Default State</h2>
<FormSection title="Name">
{inputProps => (
<DemoStateWrapper
render={(text, onChange) => <TextInput value={text} onChange={onChange} {...inputProps} />}
/>
)}
</FormSection>
</StoryColumn>
))
.add('Required State', () => (
<StoryColumn>
<h1>
<code>{'<FormSection />'}</code> Component
</h1>
<h2>Required State</h2>
<h3>
<code>{'required={true}'}</code>
</h3>
<FormSection title="Name" required>
{inputProps => (
<DemoStateWrapper
render={(text, onChange) => <TextInput value={text} onChange={onChange} {...inputProps} />}
/>
)}
</FormSection>
</StoryColumn>
))
.add('Error State', () => (
<StoryColumn>
<h1>
<code>{'<FormSection />'}</code> Component
</h1>
<h2>Error State</h2>
<h3>
<code>error="Please enter your name"</code> <code>{'required={true}'}</code>
</h3>
<FormSection title="Name" required error="Please enter your name">
{inputProps => (
<DemoStateWrapper
render={(text, onChange) => <TextInput value={text} onChange={onChange} error {...inputProps} />}
/>
)}
</FormSection>
</StoryColumn>
))
.add('Info State', () => (
<StoryColumn>
<h1>
<code>{'<FormSection />'}</code> Component
</h1>
<h2>Info State</h2>
<h3>
<code>info="Nur alphanumerische Zeichen, Unterstriche und Bindestriche"</code> <code>{'required={true}'}</code>
</h3>
<FormSection title="API-Schl眉ssel" required info="Nur alphanumerische Zeichen, Unterstriche und Bindestriche">
{inputProps => (
<DemoStateWrapper
render={(text, onChange) => <TextInput value={text} onChange={onChange} {...inputProps} />}
/>
)}
</FormSection>
</StoryColumn>
))
.add('Inline Mode', () => (
<StoryColumn>
<h1>
<code>{'<FormSection />'}</code> Component
</h1>
<h2>Inline Mode</h2>
<h3>
<code>labelPosition="side"</code>
</h3>
<FormSection
labelPosition={FormSectionLabelPosition.side}
title="Brugernavn"
required
info="Alfanumeriske tegn, bindestreger og understregning kun"
>
{inputProps => (
<DemoStateWrapper
render={(text, onChange) => <TextInput value={text} onChange={onChange} {...inputProps} />}
/>
)}
</FormSection>
<FormSection
labelPosition={FormSectionLabelPosition.side}
title="Visningsnavn"
required
info="Dette vil v忙re det navn, der vises p氓 din profil"
>
{inputProps => (
<DemoStateWrapper
render={(text, onChange) => <TextInput value={text} onChange={onChange} {...inputProps} />}
/>
)}
</FormSection>
</StoryColumn>
));