@flightlesslabs/dodo-ui 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -1
- package/dist/index.js +6 -0
- package/dist/stories/components/Form/Button/Button.stories.svelte +1 -1
- package/dist/stories/components/Form/Button/Button.svelte +37 -37
- package/dist/stories/components/Form/Button/Button.svelte.d.ts +1 -1
- package/dist/stories/components/Form/Button/Color/Color.stories.svelte +9 -7
- package/dist/stories/components/Form/FormControl/FormControl.svelte +1 -1
- package/dist/stories/components/Form/Message/Color/Color.stories.svelte +36 -0
- package/dist/stories/components/Form/Message/Color/Color.stories.svelte.d.ts +26 -0
- package/dist/stories/components/Form/Message/Message.stories.svelte +11 -26
- package/dist/stories/components/Form/Message/Message.stories.svelte.d.ts +2 -0
- package/dist/stories/components/Form/Message/Message.svelte +17 -6
- package/dist/stories/components/Form/Message/Message.svelte.d.ts +4 -1
- package/dist/stories/components/Form/Message/Size/Size.stories.svelte +24 -0
- package/dist/stories/components/Form/Message/Size/Size.stories.svelte.d.ts +26 -0
- package/dist/stories/components/Form/PasswordInput/PasswordInput.svelte +32 -130
- package/dist/stories/components/Form/PasswordInput/PasswordInput.svelte.d.ts +2 -3
- package/dist/stories/components/Form/SimpleSelect/Events/Events.stories.svelte +74 -0
- package/dist/stories/components/Form/SimpleSelect/Events/Events.stories.svelte.d.ts +18 -0
- package/dist/stories/components/Form/SimpleSelect/Roundness/Roundness.stories.svelte +24 -0
- package/dist/stories/components/Form/SimpleSelect/Roundness/Roundness.stories.svelte.d.ts +26 -0
- package/dist/stories/components/Form/SimpleSelect/SimpleSelect.stories.svelte +59 -0
- package/dist/stories/components/Form/SimpleSelect/SimpleSelect.stories.svelte.d.ts +23 -0
- package/dist/stories/components/Form/SimpleSelect/SimpleSelect.svelte +69 -0
- package/dist/stories/components/Form/SimpleSelect/SimpleSelect.svelte.d.ts +50 -0
- package/dist/stories/components/Form/SimpleSelect/Size/Size.stories.svelte +20 -0
- package/dist/stories/components/Form/SimpleSelect/Size/Size.stories.svelte.d.ts +26 -0
- package/dist/stories/components/Form/SimpleSelect/WithIcon/WithIcon.stories.svelte +36 -0
- package/dist/stories/components/Form/SimpleSelect/WithIcon/WithIcon.stories.svelte.d.ts +26 -0
- package/dist/stories/components/Form/TextInput/TextInput.svelte +22 -120
- package/dist/stories/components/Form/TextInput/TextInput.svelte.d.ts +1 -2
- package/dist/stories/components/Layout/Paper/Paper.stories.svelte +32 -0
- package/dist/stories/components/Layout/Paper/Paper.stories.svelte.d.ts +21 -0
- package/dist/stories/components/Layout/Paper/Paper.svelte +52 -0
- package/dist/stories/components/Layout/Paper/Paper.svelte.d.ts +23 -0
- package/dist/stories/components/Layout/Paper/Roundness/Roundness.stories.svelte +30 -0
- package/dist/stories/components/Layout/Paper/Roundness/Roundness.stories.svelte.d.ts +26 -0
- package/dist/stories/components/Layout/Paper/Shadow/Shadow.stories.svelte +42 -0
- package/dist/stories/components/Layout/Paper/Shadow/Shadow.stories.svelte.d.ts +26 -0
- package/dist/stories/developer tools/components/InputEnclosure/InputEnclosure.stories.svelte +34 -0
- package/dist/stories/developer tools/components/InputEnclosure/InputEnclosure.stories.svelte.d.ts +21 -0
- package/dist/stories/developer tools/components/InputEnclosure/InputEnclosure.svelte +120 -0
- package/dist/stories/developer tools/components/InputEnclosure/InputEnclosure.svelte.d.ts +29 -0
- package/dist/stories/developer tools/components/InputEnclosure/Roundness/Roundness.stories.svelte +20 -0
- package/dist/stories/developer tools/components/InputEnclosure/Roundness/Roundness.stories.svelte.d.ts +26 -0
- package/dist/stories/developer tools/components/InputEnclosure/Size/Size.stories.svelte +16 -0
- package/dist/stories/developer tools/components/InputEnclosure/Size/Size.stories.svelte.d.ts +26 -0
- package/dist/stories/developer tools/components/InputEnclosure/WithIcon/WithIcon.stories.svelte +47 -0
- package/dist/stories/developer tools/components/InputEnclosure/WithIcon/WithIcon.stories.svelte.d.ts +26 -0
- package/dist/stories/philosophy/Colors/utils/color.js +1 -1
- package/dist/styles/_colors.css +26 -26
- package/dist/styles/_shadow.css +39 -0
- package/dist/styles/global.css +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/lib/index.ts +17 -1
- package/src/lib/stories/components/Form/Button/Button.stories.svelte +1 -1
- package/src/lib/stories/components/Form/Button/Button.svelte +4 -4
- package/src/lib/stories/components/Form/Button/Color/Color.stories.svelte +9 -7
- package/src/lib/stories/components/Form/FormControl/FormControl.svelte +1 -1
- package/src/lib/stories/components/Form/Message/Color/Color.stories.svelte +36 -0
- package/src/lib/stories/components/Form/Message/Message.stories.svelte +13 -26
- package/src/lib/stories/components/Form/Message/Message.svelte +28 -7
- package/src/lib/stories/components/Form/Message/Size/Size.stories.svelte +24 -0
- package/src/lib/stories/components/Form/PasswordInput/PasswordInput.svelte +35 -157
- package/src/lib/stories/components/Form/SimpleSelect/Events/Events.stories.svelte +79 -0
- package/src/lib/stories/components/Form/SimpleSelect/Roundness/Roundness.stories.svelte +24 -0
- package/src/lib/stories/components/Form/SimpleSelect/SimpleSelect.stories.svelte +64 -0
- package/src/lib/stories/components/Form/SimpleSelect/SimpleSelect.svelte +159 -0
- package/src/lib/stories/components/Form/SimpleSelect/Size/Size.stories.svelte +20 -0
- package/src/lib/stories/components/Form/SimpleSelect/WithIcon/WithIcon.stories.svelte +36 -0
- package/src/lib/stories/components/Form/TextInput/TextInput.svelte +22 -143
- package/src/lib/stories/components/Layout/Paper/Paper.stories.svelte +36 -0
- package/src/lib/stories/components/Layout/Paper/Paper.svelte +91 -0
- package/src/lib/stories/components/Layout/Paper/Roundness/Roundness.stories.svelte +30 -0
- package/src/lib/stories/components/Layout/Paper/Shadow/Shadow.stories.svelte +42 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/InputEnclosure.stories.svelte +38 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/InputEnclosure.svelte +198 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/Roundness/Roundness.stories.svelte +20 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/Size/Size.stories.svelte +16 -0
- package/src/lib/stories/developer tools/components/InputEnclosure/WithIcon/WithIcon.stories.svelte +47 -0
- package/src/lib/styles/_colors.css +26 -26
- package/src/lib/styles/_shadow.css +39 -0
- package/src/lib/styles/global.css +1 -0
- package/src/lib/types.ts +1 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script lang="ts">
|
|
9
|
-
import type { ComponentSize } from '$lib/types.js';
|
|
9
|
+
import type { ComponentRoundness, ComponentSize } from '$lib/types.js';
|
|
10
10
|
import type { Snippet } from 'svelte';
|
|
11
11
|
import type {
|
|
12
12
|
ChangeEventHandler,
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
FocusEventHandler,
|
|
15
15
|
FormEventHandler,
|
|
16
16
|
} from 'svelte/elements';
|
|
17
|
-
import type { TextInputFocusEvent
|
|
17
|
+
import type { TextInputFocusEvent } from '../TextInput/TextInput.svelte';
|
|
18
18
|
import Icon from '@iconify/svelte';
|
|
19
19
|
import UtilityButton from '$lib/stories/developer tools/components/UtilityButton/UtilityButton.svelte';
|
|
20
|
+
import InputEnclosure from '$lib/stories/developer tools/components/InputEnclosure/InputEnclosure.svelte';
|
|
20
21
|
|
|
21
22
|
interface PasswordInputProps {
|
|
22
23
|
/** How large should the button be? */
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
/** Toggle Password Icon */
|
|
31
32
|
customPasswordToggleIcon?: (toggle: boolean) => Snippet;
|
|
32
33
|
/** How round should the border radius be? */
|
|
33
|
-
roundness?:
|
|
34
|
+
roundness?: ComponentRoundness | false;
|
|
34
35
|
/** Add a border around the button. Default True */
|
|
35
36
|
outline?: boolean;
|
|
36
37
|
/** Input value */
|
|
@@ -143,74 +144,41 @@
|
|
|
143
144
|
class:toggle
|
|
144
145
|
class={['dodo-ui-PasswordInput', `size--${size}`, `roundness--${roundness}`, className].join(' ')}
|
|
145
146
|
>
|
|
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
|
-
{/if}
|
|
178
|
-
</UtilityButton>
|
|
179
|
-
{/if}
|
|
180
|
-
|
|
181
|
-
{#if after}
|
|
182
|
-
<span class="content--after">
|
|
183
|
-
{@render after()}
|
|
184
|
-
</span>
|
|
185
|
-
{/if}
|
|
147
|
+
<InputEnclosure {outline} {disabled} {error} {focused} {size} {roundness} {before} {after}>
|
|
148
|
+
<input
|
|
149
|
+
type={passwordToggle && toggle ? 'text' : 'password'}
|
|
150
|
+
{name}
|
|
151
|
+
{id}
|
|
152
|
+
{disabled}
|
|
153
|
+
{oninput}
|
|
154
|
+
{onchange}
|
|
155
|
+
onfocus={onfocusMod}
|
|
156
|
+
onblur={onblurMod}
|
|
157
|
+
{onpaste}
|
|
158
|
+
{oncopy}
|
|
159
|
+
{oncut}
|
|
160
|
+
{placeholder}
|
|
161
|
+
bind:value
|
|
162
|
+
bind:this={ref}
|
|
163
|
+
{readonly}
|
|
164
|
+
/>
|
|
165
|
+
|
|
166
|
+
{#if passwordToggle && !disabled}
|
|
167
|
+
<UtilityButton {size} title="Toggle password" class="passwordToggle" onclick={ontoggleMod}>
|
|
168
|
+
{#if customPasswordToggleIcon}
|
|
169
|
+
{@render customPasswordToggleIconTyped(toggle)}
|
|
170
|
+
{:else if toggle}
|
|
171
|
+
<Icon icon="mdi:eye-off" width="24" height="24" />
|
|
172
|
+
{:else}
|
|
173
|
+
<Icon icon="mdi:eye" width="24" height="24" />
|
|
174
|
+
{/if}
|
|
175
|
+
</UtilityButton>
|
|
176
|
+
{/if}
|
|
177
|
+
</InputEnclosure>
|
|
186
178
|
</div>
|
|
187
179
|
|
|
188
180
|
<style lang="scss">
|
|
189
|
-
:global(:root) {
|
|
190
|
-
--dodo-ui-PasswordInput-border-color: var(--dodo-color-default-500);
|
|
191
|
-
--dodo-ui-PasswordInput-focus-border-color: var(--dodo-color-primary-500);
|
|
192
|
-
--dodo-ui-PasswordInput-error-border-color: var(--dodo-color-danger-500);
|
|
193
|
-
|
|
194
|
-
--dodo-ui-PasswordInput-disabled-color: var(--dodo-color-default-400);
|
|
195
|
-
--dodo-ui-PasswordInput-disabled-bg: var(--dodo-color-default-200);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
:global(.dodo-theme--dark) {
|
|
199
|
-
--dodo-ui-PasswordInput-border-color: var(--dodo-color-default-600);
|
|
200
|
-
--dodo-ui-PasswordInput-focus-border-color: var(--dodo-color-primary-600);
|
|
201
|
-
--dodo-ui-PasswordInput-error-border-color: var(--dodo-color-danger-600);
|
|
202
|
-
|
|
203
|
-
--dodo-ui-PasswordInput-disabled-bg: var(--dodo-color-default-100);
|
|
204
|
-
--dodo-ui-PasswordInput-disabled-color: var(--dodo-color-default-500);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
181
|
.dodo-ui-PasswordInput {
|
|
208
|
-
display: flex;
|
|
209
|
-
overflow: hidden;
|
|
210
|
-
color: var(--dodo-color-default-800);
|
|
211
|
-
transition: all 150ms;
|
|
212
|
-
border: 0;
|
|
213
|
-
|
|
214
182
|
input {
|
|
215
183
|
flex: 1;
|
|
216
184
|
border: 0;
|
|
@@ -222,116 +190,26 @@
|
|
|
222
190
|
letter-spacing: 0.3px;
|
|
223
191
|
}
|
|
224
192
|
|
|
225
|
-
&.outline {
|
|
226
|
-
border-style: solid;
|
|
227
|
-
border-width: var(--dodo-ui-element-border-width);
|
|
228
|
-
border-color: var(--dodo-ui-PasswordInput-border-color);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
&.focused {
|
|
232
|
-
border-color: var(--dodo-ui-PasswordInput-focus-border-color);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
&.error {
|
|
236
|
-
border-color: var(--dodo-ui-PasswordInput-error-border-color);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
&.disabled {
|
|
240
|
-
cursor: initial;
|
|
241
|
-
background-color: var(--dodo-ui-PasswordInput-disabled-bg);
|
|
242
|
-
color: var(--dodo-ui-PasswordInput-disabled-color);
|
|
243
|
-
border-color: var(--dodo-ui-PasswordInput-disabled-bg);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
.content {
|
|
247
|
-
&--after,
|
|
248
|
-
&--before {
|
|
249
|
-
&:empty {
|
|
250
|
-
display: none;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
&--after,
|
|
255
|
-
&--before {
|
|
256
|
-
display: inline-flex;
|
|
257
|
-
height: 100%;
|
|
258
|
-
align-items: center;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
193
|
&.size {
|
|
263
194
|
&--normal {
|
|
264
|
-
height: var(--dodo-ui-element-height-normal);
|
|
265
195
|
input {
|
|
266
196
|
font-size: 1rem;
|
|
267
197
|
padding: 0 12px;
|
|
268
198
|
}
|
|
269
|
-
|
|
270
|
-
.content {
|
|
271
|
-
&--before {
|
|
272
|
-
margin-left: 12px;
|
|
273
|
-
margin-right: -4px;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
&--after {
|
|
277
|
-
margin-right: 12px;
|
|
278
|
-
margin-left: -4px;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
199
|
}
|
|
282
200
|
|
|
283
201
|
&--small {
|
|
284
|
-
height: var(--dodo-ui-element-height-small);
|
|
285
202
|
input {
|
|
286
203
|
padding: 0 8px;
|
|
287
204
|
font-size: 0.9rem;
|
|
288
205
|
}
|
|
289
|
-
|
|
290
|
-
.content {
|
|
291
|
-
&--before {
|
|
292
|
-
margin-left: 8px;
|
|
293
|
-
margin-right: -2px;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
&--after {
|
|
297
|
-
margin-right: 8px;
|
|
298
|
-
margin-left: -2px;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
206
|
}
|
|
302
207
|
|
|
303
208
|
&--large {
|
|
304
|
-
height: var(--dodo-ui-element-height-large);
|
|
305
209
|
input {
|
|
306
210
|
font-size: 1.1rem;
|
|
307
211
|
padding: 0 14px;
|
|
308
212
|
}
|
|
309
|
-
|
|
310
|
-
.content {
|
|
311
|
-
&--before {
|
|
312
|
-
margin-left: 14px;
|
|
313
|
-
margin-right: -4px;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
&--after {
|
|
317
|
-
margin-right: 14px;
|
|
318
|
-
margin-left: -4px;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
&.roundness {
|
|
325
|
-
&--1x {
|
|
326
|
-
border-radius: var(--dodo-ui-element-roundness-1x);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
&--2x {
|
|
330
|
-
border-radius: var(--dodo-ui-element-roundness-2x);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
&--3x {
|
|
334
|
-
border-radius: var(--dodo-ui-element-roundness-3x);
|
|
335
213
|
}
|
|
336
214
|
}
|
|
337
215
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { type SimpleSelectFocusEvent } from '../SimpleSelect.svelte';
|
|
4
|
+
import SimpleSelect from '../SimpleSelect.svelte';
|
|
5
|
+
import {
|
|
6
|
+
storySimpleSelectArgTypes,
|
|
7
|
+
storySimpleSelectOptions,
|
|
8
|
+
} from '../SimpleSelect.stories.svelte';
|
|
9
|
+
|
|
10
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
11
|
+
const { Story } = defineMeta({
|
|
12
|
+
component: SimpleSelect,
|
|
13
|
+
tags: ['autodocs'],
|
|
14
|
+
argTypes: storySimpleSelectArgTypes,
|
|
15
|
+
args: { options: storySimpleSelectOptions },
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<Story
|
|
20
|
+
name="Change"
|
|
21
|
+
args={{
|
|
22
|
+
onchange: (e: Event) => {
|
|
23
|
+
const target = e.target as HTMLSelectElement;
|
|
24
|
+
|
|
25
|
+
console.log('onChange Event', target.value);
|
|
26
|
+
},
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<SimpleSelect
|
|
30
|
+
onchange={(e: Event) => {
|
|
31
|
+
const target = e.target as HTMLSelectElement;
|
|
32
|
+
|
|
33
|
+
console.log('onchange Event', target.value);
|
|
34
|
+
}}
|
|
35
|
+
options={storySimpleSelectOptions}
|
|
36
|
+
/>
|
|
37
|
+
</Story>
|
|
38
|
+
|
|
39
|
+
<!-- `e: SimpleSelectFocusEvent` -->
|
|
40
|
+
<Story
|
|
41
|
+
name="Focus"
|
|
42
|
+
args={{
|
|
43
|
+
onfocus: (e: SimpleSelectFocusEvent) => {
|
|
44
|
+
const target = e.target as HTMLSelectElement;
|
|
45
|
+
|
|
46
|
+
console.log('onfocus Event', target);
|
|
47
|
+
},
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<SimpleSelect
|
|
51
|
+
onfocus={(e: SimpleSelectFocusEvent) => {
|
|
52
|
+
const target = e.target as HTMLSelectElement;
|
|
53
|
+
|
|
54
|
+
console.log('onfocus Event', target);
|
|
55
|
+
}}
|
|
56
|
+
options={storySimpleSelectOptions}
|
|
57
|
+
/>
|
|
58
|
+
</Story>
|
|
59
|
+
|
|
60
|
+
<!-- `e: SimpleSelectFocusEvent` -->
|
|
61
|
+
<Story
|
|
62
|
+
name="Blur"
|
|
63
|
+
args={{
|
|
64
|
+
onblur: (e: SimpleSelectFocusEvent) => {
|
|
65
|
+
const target = e.target as HTMLSelectElement;
|
|
66
|
+
|
|
67
|
+
console.log('onblur Event', target);
|
|
68
|
+
},
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<SimpleSelect
|
|
72
|
+
onblur={(e: SimpleSelectFocusEvent) => {
|
|
73
|
+
const target = e.target as HTMLSelectElement;
|
|
74
|
+
|
|
75
|
+
console.log('onblur Event', target);
|
|
76
|
+
}}
|
|
77
|
+
options={storySimpleSelectOptions}
|
|
78
|
+
/>
|
|
79
|
+
</Story>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import SimpleSelect from '../SimpleSelect.svelte';
|
|
4
|
+
import {
|
|
5
|
+
storySimpleSelectArgTypes,
|
|
6
|
+
storySimpleSelectOptions,
|
|
7
|
+
} from '../SimpleSelect.stories.svelte';
|
|
8
|
+
|
|
9
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
10
|
+
const { Story } = defineMeta({
|
|
11
|
+
component: SimpleSelect,
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
argTypes: storySimpleSelectArgTypes,
|
|
14
|
+
args: { options: storySimpleSelectOptions },
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<Story name="Roundness 1x" />
|
|
19
|
+
|
|
20
|
+
<Story name="Roundness 2x" args={{ roundness: '2x' }} />
|
|
21
|
+
|
|
22
|
+
<Story name="Roundness 3x" args={{ roundness: '3x' }} />
|
|
23
|
+
|
|
24
|
+
<Story name="Roundness False" args={{ roundness: false }} />
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { type SimpleSelectOption } from './SimpleSelect.svelte';
|
|
4
|
+
import type { StoryBookArgTypes } from '$lib/storybook-types.js';
|
|
5
|
+
import SimpleSelect from './SimpleSelect.svelte';
|
|
6
|
+
|
|
7
|
+
export const storySimpleSelectArgTypes: StoryBookArgTypes = {
|
|
8
|
+
type: {
|
|
9
|
+
control: { type: 'select' },
|
|
10
|
+
options: ['text', 'tel', 'email', 'password', 'url', 'number'],
|
|
11
|
+
},
|
|
12
|
+
roundness: {
|
|
13
|
+
control: { type: 'select' },
|
|
14
|
+
options: [false, '1x', '2x', '3x'],
|
|
15
|
+
},
|
|
16
|
+
size: {
|
|
17
|
+
control: { type: 'select' },
|
|
18
|
+
options: ['normal', 'small', 'large'],
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const storySimpleSelectOptions: SimpleSelectOption[] = [
|
|
23
|
+
{
|
|
24
|
+
value: 'volvo',
|
|
25
|
+
label: 'Volvo',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
value: 'saab',
|
|
29
|
+
label: 'Saab',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
value: 'mercedes',
|
|
33
|
+
label: 'Mercedes',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
value: 'audi',
|
|
37
|
+
label: 'Audi',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
value: 'opel',
|
|
41
|
+
label: 'Opel',
|
|
42
|
+
disabled: true,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
47
|
+
const { Story } = defineMeta({
|
|
48
|
+
component: SimpleSelect,
|
|
49
|
+
tags: ['autodocs'],
|
|
50
|
+
argTypes: storySimpleSelectArgTypes,
|
|
51
|
+
args: { options: storySimpleSelectOptions },
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<!-- SimpleSelect with default style -->
|
|
56
|
+
<Story name="Default" />
|
|
57
|
+
|
|
58
|
+
<Story name="Placeholder" args={{ value: '', placeholder: 'Type something...' }} />
|
|
59
|
+
|
|
60
|
+
<Story name="No Outline" args={{ outline: false }} />
|
|
61
|
+
|
|
62
|
+
<Story name="Error" args={{ error: true }} />
|
|
63
|
+
|
|
64
|
+
<Story name="Disabled" args={{ disabled: true }} />
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type SimpleSelectFocusEvent = FocusEvent & {
|
|
3
|
+
currentTarget: EventTarget & HTMLSelectElement;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type SimpleSelectOption = {
|
|
7
|
+
value: string;
|
|
8
|
+
label: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import InputEnclosure from '$lib/stories/developer tools/components/InputEnclosure/InputEnclosure.svelte';
|
|
15
|
+
|
|
16
|
+
import type { ComponentRoundness, ComponentSize } from '$lib/types.js';
|
|
17
|
+
import type { Snippet } from 'svelte';
|
|
18
|
+
import type { ChangeEventHandler, FocusEventHandler } from 'svelte/elements';
|
|
19
|
+
|
|
20
|
+
interface SimpleSelectProps {
|
|
21
|
+
/** Select ref */
|
|
22
|
+
ref?: HTMLSelectElement;
|
|
23
|
+
/** How large should the button be? */
|
|
24
|
+
size?: ComponentSize;
|
|
25
|
+
/** How round should the border radius be? */
|
|
26
|
+
roundness?: ComponentRoundness | false;
|
|
27
|
+
/** How round should the border radius be? */
|
|
28
|
+
options: SimpleSelectOption[];
|
|
29
|
+
/** Add a border around the button. Default True */
|
|
30
|
+
outline?: boolean;
|
|
31
|
+
/** Select value */
|
|
32
|
+
value?: string;
|
|
33
|
+
/** How round should the border radius be? */
|
|
34
|
+
placeholder?: string;
|
|
35
|
+
/** disabled state */
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
/** is there any associated Error ? */
|
|
38
|
+
error?: boolean;
|
|
39
|
+
/** Name */
|
|
40
|
+
name?: string;
|
|
41
|
+
/** Id */
|
|
42
|
+
id?: string;
|
|
43
|
+
/** Icon before button content */
|
|
44
|
+
before?: Snippet;
|
|
45
|
+
/** Icon after button content */
|
|
46
|
+
after?: Snippet;
|
|
47
|
+
/** Custom css class*/
|
|
48
|
+
class?: string;
|
|
49
|
+
/** onchange event handler */
|
|
50
|
+
onchange?: ChangeEventHandler<HTMLSelectElement>;
|
|
51
|
+
/** onblur event handler */
|
|
52
|
+
onblur?: FocusEventHandler<HTMLSelectElement>;
|
|
53
|
+
/** onfocus event handler */
|
|
54
|
+
onfocus?: FocusEventHandler<HTMLSelectElement>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let {
|
|
58
|
+
size = 'normal',
|
|
59
|
+
roundness = '1x',
|
|
60
|
+
outline = true,
|
|
61
|
+
name,
|
|
62
|
+
id,
|
|
63
|
+
class: className = '',
|
|
64
|
+
disabled = false,
|
|
65
|
+
onchange,
|
|
66
|
+
onblur,
|
|
67
|
+
onfocus,
|
|
68
|
+
before,
|
|
69
|
+
after,
|
|
70
|
+
error = false,
|
|
71
|
+
value,
|
|
72
|
+
placeholder,
|
|
73
|
+
ref = $bindable<HTMLSelectElement>(),
|
|
74
|
+
options,
|
|
75
|
+
}: SimpleSelectProps = $props();
|
|
76
|
+
|
|
77
|
+
let focused: boolean = $state(false);
|
|
78
|
+
|
|
79
|
+
function onfocusMod(e: SimpleSelectFocusEvent) {
|
|
80
|
+
focused = true;
|
|
81
|
+
|
|
82
|
+
if (onfocus) {
|
|
83
|
+
onfocus(e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onblurMod(e: SimpleSelectFocusEvent) {
|
|
88
|
+
focused = false;
|
|
89
|
+
|
|
90
|
+
if (onblur) {
|
|
91
|
+
onblur(e);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<div
|
|
97
|
+
class:outline
|
|
98
|
+
class:disabled
|
|
99
|
+
class:error
|
|
100
|
+
class:focused
|
|
101
|
+
class={['dodo-ui-SimpleSelect', `size--${size}`, `roundness--${roundness}`, className].join(' ')}
|
|
102
|
+
>
|
|
103
|
+
<InputEnclosure {outline} {disabled} {error} {focused} {size} {roundness} {before} {after}>
|
|
104
|
+
<select
|
|
105
|
+
{name}
|
|
106
|
+
{id}
|
|
107
|
+
{disabled}
|
|
108
|
+
{onchange}
|
|
109
|
+
onfocus={onfocusMod}
|
|
110
|
+
onblur={onblurMod}
|
|
111
|
+
{placeholder}
|
|
112
|
+
bind:this={ref}
|
|
113
|
+
>
|
|
114
|
+
{#each options as option (option.value)}
|
|
115
|
+
<option value={option.value} disabled={option.disabled} selected={value === option.value}>
|
|
116
|
+
{option.label}
|
|
117
|
+
</option>
|
|
118
|
+
{/each}
|
|
119
|
+
</select>
|
|
120
|
+
</InputEnclosure>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<style lang="scss">
|
|
124
|
+
.dodo-ui-SimpleSelect {
|
|
125
|
+
select {
|
|
126
|
+
flex: 1;
|
|
127
|
+
border: 0;
|
|
128
|
+
outline: 0;
|
|
129
|
+
height: 100%;
|
|
130
|
+
background-color: transparent;
|
|
131
|
+
font-family: inherit;
|
|
132
|
+
color: inherit;
|
|
133
|
+
letter-spacing: 0.3px;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
&.size {
|
|
137
|
+
&--normal {
|
|
138
|
+
select {
|
|
139
|
+
font-size: 1rem;
|
|
140
|
+
padding: 0 12px;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
&--small {
|
|
145
|
+
select {
|
|
146
|
+
padding: 0 8px;
|
|
147
|
+
font-size: 0.9rem;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
&--large {
|
|
152
|
+
select {
|
|
153
|
+
font-size: 1.1rem;
|
|
154
|
+
padding: 0 14px;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import SimpleSelect from '../SimpleSelect.svelte';
|
|
4
|
+
import {
|
|
5
|
+
storySimpleSelectArgTypes,
|
|
6
|
+
storySimpleSelectOptions,
|
|
7
|
+
} from '../SimpleSelect.stories.svelte';
|
|
8
|
+
|
|
9
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
10
|
+
const { Story } = defineMeta({
|
|
11
|
+
component: SimpleSelect,
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
argTypes: storySimpleSelectArgTypes,
|
|
14
|
+
args: { options: storySimpleSelectOptions },
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<Story name="Normal" />
|
|
19
|
+
<Story name="Small" args={{ size: 'small' }} />
|
|
20
|
+
<Story name="Large" args={{ size: 'large' }} />
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import Icon from '@iconify/svelte';
|
|
4
|
+
|
|
5
|
+
import SimpleSelect from '../SimpleSelect.svelte';
|
|
6
|
+
import {
|
|
7
|
+
storySimpleSelectArgTypes,
|
|
8
|
+
storySimpleSelectOptions,
|
|
9
|
+
} from '../SimpleSelect.stories.svelte';
|
|
10
|
+
|
|
11
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
12
|
+
const { Story } = defineMeta({
|
|
13
|
+
component: SimpleSelect,
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
argTypes: storySimpleSelectArgTypes,
|
|
16
|
+
args: { options: storySimpleSelectOptions },
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<!-- SimpleSelect icon in front. -->
|
|
21
|
+
<Story name="Icon Before">
|
|
22
|
+
<SimpleSelect options={storySimpleSelectOptions}>
|
|
23
|
+
{#snippet before()}
|
|
24
|
+
<Icon icon="material-symbols:content-copy" />
|
|
25
|
+
{/snippet}
|
|
26
|
+
</SimpleSelect>
|
|
27
|
+
</Story>
|
|
28
|
+
|
|
29
|
+
<!-- SimpleSelect icon in front. -->
|
|
30
|
+
<Story name="Icon After">
|
|
31
|
+
<SimpleSelect options={storySimpleSelectOptions}>
|
|
32
|
+
{#snippet after()}
|
|
33
|
+
<Icon icon="material-symbols:download-2" />
|
|
34
|
+
{/snippet}
|
|
35
|
+
</SimpleSelect>
|
|
36
|
+
</Story>
|