-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathThing.stories.tsx
218 lines (206 loc) · 4.47 KB
/
Thing.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import React, { useState } from 'react';
import styled, { ThemeProvider } from 'styled-components';
import ReactTooltip from 'react-tooltip';
import { InOutTextarea, Props, InOptions, OutOptions } from '../src';
export default {
title: 'Welcome',
argTypes: {
font: {
control: {
type: 'select',
options: ['monospace', 'Roboto', 'Arial', 'Comic Sans'],
},
},
maxContentLength: {
control: {
type: 'range',
options: {
min: 1,
max: 100,
step: 1,
},
},
},
},
};
// By passing optional props to this story, you can control the props of the component when
// you consume the story in a test.
export const Default = (props?: Partial<Props>) => {
const [inValue, setInValue] = useState<string>('Hello');
const [inOptions, setInOptions] = useState<InOptions>([
{
name: 'English',
active: false,
},
{
name: 'German',
active: true,
},
{
name: 'Russian',
active: false,
},
{
name: 'Turkish',
active: false,
},
{
name: 'Swedish',
active: false,
},
{
name: 'Spanish',
active: false,
},
{
name: 'Chinese',
active: false,
},
{
name: 'Chinese 1',
active: false,
},
{
name: 'Chinese 2',
active: false,
},
{
name: 'Chinese 3',
active: false,
},
{
name: 'Chinese 4',
active: false,
},
{
name: 'Chinese 5',
active: false,
},
{
name: 'Chinese 6',
active: false,
},
{
name: 'Chinese 7',
active: false,
},
]);
const [outOptions, setOutOptions] = useState<OutOptions>([
{
name: 'English',
active: true,
activeClicked: false,
},
{
name: 'German',
active: false,
activeClicked: false,
},
{
name: 'Russian',
active: false,
activeClicked: false,
},
{
name: 'Chinese 1',
active: false,
activeClicked: false,
},
{
name: 'Chinese 2',
active: false,
activeClicked: false,
},
{
name: 'Chinese 3',
active: false,
activeClicked: false,
},
{
name: 'Chinese 4',
active: false,
activeClicked: false,
},
{
name: 'Chinese 5',
active: false,
activeClicked: false,
},
{
name: 'Chinese 6',
active: false,
activeClicked: false,
},
]);
return (
<div style={{ maxWidth: '1100px' }}>
<InOutTextarea
{...props}
inValue={inValue}
onInInput={newValue => setInValue(newValue)}
inOptions={inOptions}
onInOptionsUpdate={newInOptions => {
setInOptions(newInOptions);
}}
outOptions={outOptions}
onOutOptionsUpdate={newOutOptions => {
setOutOptions(newOutOptions);
}}
outValue={'Hello'}
/>
</div>
);
};
type CustomFontProps = Partial<Props> & { font: string };
export const _CustomFont = ({ font, ...args }: CustomFontProps) => {
return (
<ThemeProvider theme={{ font }}>
<Default {...args} />
</ThemeProvider>
);
};
export const CustomFont = _CustomFont.bind({});
CustomFont.args = {
font: 'Roboto',
};
type CustomMaxContentLengthProps = Partial<Props> & {
maxContentLength: number;
};
const _WithLengthLimit = ({
maxContentLength,
...args
}: CustomMaxContentLengthProps) => {
const [inValue, setInValue] = useState<string>(
`Has a limit = to ${maxContentLength}!`
);
return (
<div style={{ maxWidth: '1100px' }}>
<InOutTextarea
inValue={inValue}
outValue={inValue
.split('')
.reverse()
.join('')}
inOptions={[{ active: true, name: 'English' }]}
outOptions={[{ active: true, name: 'German', activeClicked: true }]}
onInInput={setInValue}
onInOptionsUpdate={() => true}
onOutOptionsUpdate={() => true}
maxContentLength={maxContentLength}
maxContentLengthIndicator={{
show: true,
// See https://www.npmjs.com/package/react-tooltip for more information
tooltip: (
<ReactTooltip place="top" type="dark" effect="solid">
You can only use up to {maxContentLength} characters
</ReactTooltip>
),
}}
/>
</div>
);
};
export const WithLengthLimit = _WithLengthLimit.bind({});
WithLengthLimit.args = {
maxContentLength: 100,
};