@sveltia/ui 0.2.0 → 0.2.2
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/package/components/composite/calendar.svelte +239 -0
- package/package/components/composite/calendar.svelte.d.ts +27 -0
- package/package/components/composite/checkbox-group.svelte +43 -0
- package/package/components/composite/checkbox-group.svelte.d.ts +34 -0
- package/package/components/composite/combobox.svelte +208 -0
- package/package/components/composite/combobox.svelte.d.ts +47 -0
- package/package/components/composite/disclosure.svelte +60 -0
- package/package/components/composite/disclosure.svelte.d.ts +35 -0
- package/package/components/composite/grid.svelte +24 -0
- package/package/components/composite/grid.svelte.d.ts +31 -0
- package/package/components/composite/listbox.svelte +63 -0
- package/package/components/composite/listbox.svelte.d.ts +52 -0
- package/package/components/composite/menu-item-group.svelte +31 -0
- package/package/components/composite/menu-item-group.svelte.d.ts +33 -0
- package/package/components/composite/menu.svelte +44 -0
- package/package/components/composite/menu.svelte.d.ts +41 -0
- package/package/components/composite/radio-button-group.svelte +45 -0
- package/package/components/composite/radio-button-group.svelte.d.ts +36 -0
- package/package/components/composite/select-button-group.svelte +71 -0
- package/package/components/composite/select-button-group.svelte.d.ts +44 -0
- package/package/components/composite/select.svelte +34 -0
- package/package/components/composite/select.svelte.d.ts +38 -0
- package/package/components/composite/tab-list.svelte +76 -0
- package/package/components/composite/tab-list.svelte.d.ts +55 -0
- package/package/components/core/button.svelte +222 -0
- package/package/components/core/button.svelte.d.ts +109 -0
- package/package/components/core/checkbox.svelte +114 -0
- package/package/components/core/checkbox.svelte.d.ts +45 -0
- package/package/components/core/dialog.svelte +288 -0
- package/package/components/core/dialog.svelte.d.ts +73 -0
- package/package/components/core/drawer.svelte +338 -0
- package/package/components/core/drawer.svelte.d.ts +59 -0
- package/package/components/core/grid-cell.svelte +14 -0
- package/package/components/core/grid-cell.svelte.d.ts +29 -0
- package/package/components/core/group.svelte +31 -0
- package/package/components/core/group.svelte.d.ts +33 -0
- package/package/components/core/icon.svelte +21 -0
- package/package/components/core/icon.svelte.d.ts +27 -0
- package/package/components/core/menu-button.svelte +57 -0
- package/package/components/core/menu-button.svelte.d.ts +46 -0
- package/package/components/core/menu-item-checkbox.svelte +24 -0
- package/package/components/core/menu-item-checkbox.svelte.d.ts +34 -0
- package/package/components/core/menu-item-radio.svelte +19 -0
- package/package/components/core/menu-item-radio.svelte.d.ts +34 -0
- package/package/components/core/menu-item.svelte +113 -0
- package/package/components/core/menu-item.svelte.d.ts +44 -0
- package/package/components/core/number-input.svelte +112 -0
- package/package/components/core/number-input.svelte.d.ts +42 -0
- package/package/components/core/option.svelte +65 -0
- package/package/components/core/option.svelte.d.ts +60 -0
- package/package/components/core/password-input.svelte +81 -0
- package/package/components/core/password-input.svelte.d.ts +36 -0
- package/package/components/core/radio-button.svelte +93 -0
- package/package/components/core/radio-button.svelte.d.ts +37 -0
- package/package/components/core/row-group.svelte +14 -0
- package/package/components/core/row-group.svelte.d.ts +29 -0
- package/package/components/core/row.svelte +14 -0
- package/package/components/core/row.svelte.d.ts +33 -0
- package/package/components/core/search-bar.svelte +91 -0
- package/package/components/core/search-bar.svelte.d.ts +49 -0
- package/package/components/core/select-button.svelte +31 -0
- package/package/components/core/select-button.svelte.d.ts +52 -0
- package/package/components/core/separator.svelte +28 -0
- package/package/components/core/separator.svelte.d.ts +26 -0
- package/package/components/core/slider.svelte +271 -0
- package/package/components/core/slider.svelte.d.ts +51 -0
- package/package/components/core/spacer.svelte +22 -0
- package/package/components/core/spacer.svelte.d.ts +25 -0
- package/package/components/core/switch.svelte +86 -0
- package/package/components/core/switch.svelte.d.ts +37 -0
- package/package/components/core/tab-panel.svelte +23 -0
- package/package/components/core/tab-panel.svelte.d.ts +33 -0
- package/package/components/core/tab.svelte +22 -0
- package/package/components/core/tab.svelte.d.ts +45 -0
- package/package/components/core/text-area.svelte +90 -0
- package/package/components/core/text-area.svelte.d.ts +57 -0
- package/package/components/core/text-input.svelte +146 -0
- package/package/components/core/text-input.svelte.d.ts +71 -0
- package/package/components/core/toolbar.svelte +74 -0
- package/package/components/core/toolbar.svelte.d.ts +35 -0
- package/package/components/editor/markdown.svelte +78 -0
- package/package/components/editor/markdown.svelte.d.ts +25 -0
- package/package/components/helpers/group.d.ts +37 -0
- package/package/components/helpers/group.js +246 -0
- package/package/components/helpers/popup.d.ts +31 -0
- package/package/components/helpers/popup.js +165 -0
- package/package/components/helpers/util.d.ts +1 -0
- package/package/components/helpers/util.js +8 -0
- package/package/components/util/app-shell.svelte +354 -0
- package/package/components/util/app-shell.svelte.d.ts +38 -0
- package/package/components/util/misc.d.ts +2 -0
- package/package/components/util/misc.js +22 -0
- package/package/components/util/popup.svelte +155 -0
- package/package/components/util/popup.svelte.d.ts +53 -0
- package/package/components/util/portal.svelte +34 -0
- package/package/components/util/portal.svelte.d.ts +28 -0
- package/package/index.d.ts +43 -0
- package/package/index.js +68 -0
- package/package/locales/en.d.ts +42 -0
- package/package/locales/en.js +41 -0
- package/package/locales/ja.d.ts +42 -0
- package/package/locales/ja.js +41 -0
- package/package/styles/core.scss +134 -0
- package/package/styles/variables.scss +184 -0
- package/package/typedef.d.ts +0 -0
- package/package/typedef.js +0 -0
- package/package.json +2 -3
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { _ } from 'svelte-i18n';
|
|
3
|
+
import Button from '../core/button.svelte';
|
|
4
|
+
import Icon from '../core/icon.svelte';
|
|
5
|
+
import Separator from '../core/separator.svelte';
|
|
6
|
+
import Spacer from '../core/spacer.svelte';
|
|
7
|
+
|
|
8
|
+
/** @type {(String|undefined)} */
|
|
9
|
+
export let value = undefined;
|
|
10
|
+
|
|
11
|
+
const dayList = [];
|
|
12
|
+
const weeks = [];
|
|
13
|
+
const now = new Date();
|
|
14
|
+
|
|
15
|
+
$: date = value ? new Date(value) : now;
|
|
16
|
+
$: firstDayOfMonth = new Date(date.getUTCFullYear(), date.getUTCMonth(), 1);
|
|
17
|
+
$: firstDay = new Date(firstDayOfMonth);
|
|
18
|
+
|
|
19
|
+
const getWeeks = () => {
|
|
20
|
+
const cursor = new Date(firstDay);
|
|
21
|
+
|
|
22
|
+
// Start from Sunday
|
|
23
|
+
cursor.setDate(1 - cursor.getUTCDay());
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < 42; i += 1) {
|
|
26
|
+
const week = Math.floor(i / 7);
|
|
27
|
+
|
|
28
|
+
dayList[i] = { day: new Date(cursor) };
|
|
29
|
+
weeks[week] ||= [];
|
|
30
|
+
weeks[week][cursor.getUTCDay() % 7] = { day: new Date(cursor) };
|
|
31
|
+
cursor.setUTCDate(cursor.getUTCDate() + 1);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
$: {
|
|
36
|
+
if (firstDay) {
|
|
37
|
+
getWeeks();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<div role="group">
|
|
43
|
+
<input type="hidden" bind:value />
|
|
44
|
+
<div class="header">
|
|
45
|
+
<Button
|
|
46
|
+
class="ghost"
|
|
47
|
+
label={firstDay.toLocaleDateString('en', { year: 'numeric', month: 'short' })}
|
|
48
|
+
aria-haspopup="dialog"
|
|
49
|
+
>
|
|
50
|
+
<Icon slot="end-icon" name="arrow_drop_down" />
|
|
51
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
52
|
+
<div slot="popup" class="popup-inner" on:click|stopPropagation>
|
|
53
|
+
<div role="group" aria-label={$_('_sui.calendar.year')}>
|
|
54
|
+
<div class="header">
|
|
55
|
+
<Button
|
|
56
|
+
on:click={() => {
|
|
57
|
+
//
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
<Icon name="chevron_left" label={$_('_sui.calendar.previous_decade')} />
|
|
61
|
+
</Button>
|
|
62
|
+
<Button
|
|
63
|
+
on:click={() => {
|
|
64
|
+
//
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<Icon name="chevron_right" label={$_('_sui.calendar.next_decade')} />
|
|
68
|
+
</Button>
|
|
69
|
+
</div>
|
|
70
|
+
<div class="grid">
|
|
71
|
+
{#each [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] as year}
|
|
72
|
+
<div>
|
|
73
|
+
<Button>202{year}</Button>
|
|
74
|
+
</div>
|
|
75
|
+
{/each}
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
<Separator orientation="vertical" />
|
|
79
|
+
<div role="group" aria-label={$_('_sui.calendar.month')}>
|
|
80
|
+
<div class="grid">
|
|
81
|
+
{#each [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] as month}
|
|
82
|
+
<div>
|
|
83
|
+
<Button>
|
|
84
|
+
{new Date(date.getUTCFullYear(), month, 10).toLocaleDateString('en', {
|
|
85
|
+
month: 'short',
|
|
86
|
+
})}
|
|
87
|
+
</Button>
|
|
88
|
+
</div>
|
|
89
|
+
{/each}
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
</Button>
|
|
94
|
+
<Button
|
|
95
|
+
on:click={() => {
|
|
96
|
+
firstDay.setUTCMonth(firstDay.getUTCMonth() - 1);
|
|
97
|
+
firstDay = firstDay;
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<Icon name="chevron_left" label={$_('_sui.calendar.previous_month')} />
|
|
101
|
+
</Button>
|
|
102
|
+
<Button
|
|
103
|
+
on:click={() => {
|
|
104
|
+
firstDay.setUTCMonth(firstDay.getUTCMonth() + 1);
|
|
105
|
+
firstDay = firstDay;
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
<Icon name="chevron_right" label={$_('_sui.calendar.next_month')} />
|
|
109
|
+
</Button>
|
|
110
|
+
</div>
|
|
111
|
+
<div class="grid" role="listbox">
|
|
112
|
+
{#each dayList.slice(0, 7) as { day }}
|
|
113
|
+
<div class="weekday" role="presentation">
|
|
114
|
+
{day.toLocaleDateString('en', { weekday: 'narrow' })}
|
|
115
|
+
</div>
|
|
116
|
+
{/each}
|
|
117
|
+
{#each dayList as { day }}
|
|
118
|
+
<div
|
|
119
|
+
class:other-month={day.getUTCMonth() !== firstDay.getUTCMonth()}
|
|
120
|
+
class:today={day.getFullYear() === now.getFullYear() &&
|
|
121
|
+
day.getMonth() === now.getMonth() &&
|
|
122
|
+
day.getDate() === now.getDate()}
|
|
123
|
+
>
|
|
124
|
+
<Button
|
|
125
|
+
role="option"
|
|
126
|
+
aria-selected={false}
|
|
127
|
+
on:click={() => {
|
|
128
|
+
[value] = day.toJSON().split('T');
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
131
|
+
{day.getUTCDate()}
|
|
132
|
+
</Button>
|
|
133
|
+
</div>
|
|
134
|
+
{/each}
|
|
135
|
+
</div>
|
|
136
|
+
<div class="footer">
|
|
137
|
+
<Button
|
|
138
|
+
on:click={() => {
|
|
139
|
+
value = '';
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
{$_('_sui._.clear')}
|
|
143
|
+
</Button>
|
|
144
|
+
<Spacer flex={true} />
|
|
145
|
+
<Button
|
|
146
|
+
on:click={() => {
|
|
147
|
+
[value] = now.toJSON().split('T');
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
{$_('_sui.calendar.today')}
|
|
151
|
+
</Button>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
|
|
155
|
+
<style>[role=group] {
|
|
156
|
+
display: inline-flex;
|
|
157
|
+
flex-direction: column;
|
|
158
|
+
gap: 8px;
|
|
159
|
+
-webkit-user-select: none;
|
|
160
|
+
user-select: none;
|
|
161
|
+
cursor: default;
|
|
162
|
+
}
|
|
163
|
+
[role=group] > * {
|
|
164
|
+
flex: none;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.header,
|
|
168
|
+
.footer {
|
|
169
|
+
display: flex;
|
|
170
|
+
gap: 8px;
|
|
171
|
+
height: 24px;
|
|
172
|
+
align-items: center;
|
|
173
|
+
}
|
|
174
|
+
.header :global(button.secondary),
|
|
175
|
+
.footer :global(button.secondary) {
|
|
176
|
+
width: 100px;
|
|
177
|
+
flex: auto;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.grid {
|
|
181
|
+
display: grid !important;
|
|
182
|
+
grid-template-columns: repeat(auto-fill, 24px);
|
|
183
|
+
gap: 2px;
|
|
184
|
+
width: 180px;
|
|
185
|
+
}
|
|
186
|
+
.grid div {
|
|
187
|
+
display: flex;
|
|
188
|
+
justify-content: center;
|
|
189
|
+
align-items: center;
|
|
190
|
+
width: 24px;
|
|
191
|
+
height: 24px;
|
|
192
|
+
font-size: var(--font-size--small);
|
|
193
|
+
}
|
|
194
|
+
.grid div.weekday {
|
|
195
|
+
color: var(--secondary-foreground-color);
|
|
196
|
+
}
|
|
197
|
+
.grid div.other-month {
|
|
198
|
+
color: var(--tertiary-foreground-color);
|
|
199
|
+
}
|
|
200
|
+
.grid div.today :global(button) {
|
|
201
|
+
color: var(--highlight-foreground-color);
|
|
202
|
+
background-color: var(--primary-accent-color);
|
|
203
|
+
}
|
|
204
|
+
.grid div :global(button) {
|
|
205
|
+
justify-content: center;
|
|
206
|
+
width: 100%;
|
|
207
|
+
height: 24px;
|
|
208
|
+
border-radius: 50%;
|
|
209
|
+
}
|
|
210
|
+
.grid div :global(button):hover {
|
|
211
|
+
background-color: var(--highlight-background-color);
|
|
212
|
+
}
|
|
213
|
+
.grid div :global(button):focus {
|
|
214
|
+
border-width: 1px;
|
|
215
|
+
border-color: var(--primary-accent-color-lighter);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.footer :global(button) {
|
|
219
|
+
font-size: var(--font-size--small);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.popup-inner {
|
|
223
|
+
display: flex;
|
|
224
|
+
gap: 8px;
|
|
225
|
+
padding: 8px;
|
|
226
|
+
}
|
|
227
|
+
.popup-inner [role=group] {
|
|
228
|
+
gap: 0;
|
|
229
|
+
}
|
|
230
|
+
.popup-inner [role=group] .header {
|
|
231
|
+
justify-content: center;
|
|
232
|
+
}
|
|
233
|
+
.popup-inner .grid {
|
|
234
|
+
grid-template-columns: repeat(auto-fill, 48px);
|
|
235
|
+
width: 98px;
|
|
236
|
+
}
|
|
237
|
+
.popup-inner .grid > div {
|
|
238
|
+
width: 48px;
|
|
239
|
+
}</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} CalendarProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} CalendarEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} CalendarSlots */
|
|
4
|
+
export default class Calendar extends SvelteComponentTyped<{
|
|
5
|
+
value?: string;
|
|
6
|
+
}, {
|
|
7
|
+
click: MouseEvent;
|
|
8
|
+
} & {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
}, {}> {
|
|
11
|
+
}
|
|
12
|
+
export type CalendarProps = typeof __propDef.props;
|
|
13
|
+
export type CalendarEvents = typeof __propDef.events;
|
|
14
|
+
export type CalendarSlots = typeof __propDef.slots;
|
|
15
|
+
import { SvelteComponentTyped } from "svelte";
|
|
16
|
+
declare const __propDef: {
|
|
17
|
+
props: {
|
|
18
|
+
value?: (string | undefined);
|
|
19
|
+
};
|
|
20
|
+
events: {
|
|
21
|
+
click: MouseEvent;
|
|
22
|
+
} & {
|
|
23
|
+
[evt: string]: CustomEvent<any>;
|
|
24
|
+
};
|
|
25
|
+
slots: {};
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
The container of `<Checkbox>`es.
|
|
4
|
+
-->
|
|
5
|
+
<script>
|
|
6
|
+
/**
|
|
7
|
+
* CSS class name on the button.
|
|
8
|
+
* @type {String}
|
|
9
|
+
*/
|
|
10
|
+
// eslint-disable-next-line padding-line-between-statements
|
|
11
|
+
let className = '';
|
|
12
|
+
|
|
13
|
+
export { className as class };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The `aria-label` attribute on the button element.
|
|
17
|
+
* @type {String}
|
|
18
|
+
*/
|
|
19
|
+
export let ariaLabel = '';
|
|
20
|
+
|
|
21
|
+
/** @type {('horizontal'|'vertical')} */
|
|
22
|
+
export let orientation = 'horizontal';
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div
|
|
26
|
+
class="sui checkbox-group {className} {orientation}"
|
|
27
|
+
role="group"
|
|
28
|
+
aria-label={ariaLabel}
|
|
29
|
+
{...$$restProps}
|
|
30
|
+
>
|
|
31
|
+
<slot />
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<style>.checkbox-group {
|
|
35
|
+
display: inline-flex;
|
|
36
|
+
gap: 16px;
|
|
37
|
+
}
|
|
38
|
+
.checkbox-group.horizontal {
|
|
39
|
+
align-items: center;
|
|
40
|
+
}
|
|
41
|
+
.checkbox-group.vertical {
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
}</style>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} CheckboxGroupProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} CheckboxGroupEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} CheckboxGroupSlots */
|
|
4
|
+
/** The container of `<Checkbox>`es. */
|
|
5
|
+
export default class CheckboxGroup extends SvelteComponentTyped<{
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
class?: string;
|
|
8
|
+
orientation?: "horizontal" | "vertical";
|
|
9
|
+
ariaLabel?: string;
|
|
10
|
+
}, {
|
|
11
|
+
[evt: string]: CustomEvent<any>;
|
|
12
|
+
}, {
|
|
13
|
+
default: {};
|
|
14
|
+
}> {
|
|
15
|
+
}
|
|
16
|
+
export type CheckboxGroupProps = typeof __propDef.props;
|
|
17
|
+
export type CheckboxGroupEvents = typeof __propDef.events;
|
|
18
|
+
export type CheckboxGroupSlots = typeof __propDef.slots;
|
|
19
|
+
import { SvelteComponentTyped } from "svelte";
|
|
20
|
+
declare const __propDef: {
|
|
21
|
+
props: {
|
|
22
|
+
[x: string]: any;
|
|
23
|
+
class?: string;
|
|
24
|
+
orientation?: ('horizontal' | 'vertical');
|
|
25
|
+
ariaLabel?: string;
|
|
26
|
+
};
|
|
27
|
+
events: {
|
|
28
|
+
[evt: string]: CustomEvent<any>;
|
|
29
|
+
};
|
|
30
|
+
slots: {
|
|
31
|
+
default: {};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
@see https://w3c.github.io/aria/#combobox
|
|
4
|
+
@see https://w3c.github.io/aria-practices/#combobox
|
|
5
|
+
-->
|
|
6
|
+
<script>
|
|
7
|
+
import { createEventDispatcher } from 'svelte';
|
|
8
|
+
import { _ } from 'svelte-i18n';
|
|
9
|
+
import { writable } from 'svelte/store';
|
|
10
|
+
import Button from '../core/button.svelte';
|
|
11
|
+
import Icon from '../core/icon.svelte';
|
|
12
|
+
import TextInput from '../core/text-input.svelte';
|
|
13
|
+
import { getRandomId } from '../helpers/util';
|
|
14
|
+
import Popup from '../util/popup.svelte';
|
|
15
|
+
import Listbox from './listbox.svelte';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* CSS class name on the button.
|
|
19
|
+
* @type {String}
|
|
20
|
+
*/
|
|
21
|
+
let className = '';
|
|
22
|
+
|
|
23
|
+
export { className as class };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Where to show the dropdown menu.
|
|
27
|
+
* @type {PopupPosition}
|
|
28
|
+
*/
|
|
29
|
+
export let position = 'bottom-left';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether the textbox is editable.
|
|
33
|
+
*/
|
|
34
|
+
export let readOnly = false;
|
|
35
|
+
|
|
36
|
+
export let disabled = false;
|
|
37
|
+
|
|
38
|
+
export let label = '';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Selected option’s value.
|
|
42
|
+
* @type {(String|undefined)}
|
|
43
|
+
*/
|
|
44
|
+
export let value = undefined;
|
|
45
|
+
|
|
46
|
+
const dispatch = createEventDispatcher();
|
|
47
|
+
const id = getRandomId('combobox');
|
|
48
|
+
let comboboxElement;
|
|
49
|
+
/** @type {(TextInput| undefined)} */
|
|
50
|
+
let inputComponent;
|
|
51
|
+
/** @type {(Popup| undefined)} */
|
|
52
|
+
let popupComponent;
|
|
53
|
+
let isPopupOpen = writable(false);
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<div class="sui combobox {className}">
|
|
57
|
+
{#if readOnly}
|
|
58
|
+
<div
|
|
59
|
+
class:selected={value !== undefined}
|
|
60
|
+
role="combobox"
|
|
61
|
+
{id}
|
|
62
|
+
tabindex={disabled ? -1 : 0}
|
|
63
|
+
aria-controls="{id}-popup"
|
|
64
|
+
aria-expanded={$isPopupOpen}
|
|
65
|
+
aria-disabled={disabled ? true : undefined}
|
|
66
|
+
aria-haspopup="listbox"
|
|
67
|
+
aria-activedescendant="selected-option"
|
|
68
|
+
{...$$restProps}
|
|
69
|
+
bind:this={comboboxElement}
|
|
70
|
+
>
|
|
71
|
+
<div class="label">
|
|
72
|
+
{value !== undefined ? label || value : $_('_sui.combobox.select_an_option')}
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
{:else}
|
|
76
|
+
<TextInput
|
|
77
|
+
role="combobox"
|
|
78
|
+
{id}
|
|
79
|
+
{value}
|
|
80
|
+
{disabled}
|
|
81
|
+
aria-controls="{id}-popup"
|
|
82
|
+
aria-expanded={$isPopupOpen}
|
|
83
|
+
aria-disabled={disabled ? true : undefined}
|
|
84
|
+
aria-haspopup="listbox"
|
|
85
|
+
aria-activedescendant="selected-option"
|
|
86
|
+
{...$$restProps}
|
|
87
|
+
bind:this={inputComponent}
|
|
88
|
+
/>
|
|
89
|
+
{/if}
|
|
90
|
+
<Button
|
|
91
|
+
{disabled}
|
|
92
|
+
tabindex={readOnly || disabled ? -1 : 0}
|
|
93
|
+
aria-controls="{id}-popup"
|
|
94
|
+
aria-expanded={$isPopupOpen}
|
|
95
|
+
aria-disabled={disabled ? true : undefined}
|
|
96
|
+
class="ghost iconic"
|
|
97
|
+
on:click={(event) => {
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
|
|
100
|
+
if (!disabled) {
|
|
101
|
+
$isPopupOpen = !$isPopupOpen;
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
<Icon
|
|
106
|
+
slot="start-icon"
|
|
107
|
+
name="expand_more"
|
|
108
|
+
label={$isPopupOpen ? $_('_sui._.collapse') : $_('_sui._.expand')}
|
|
109
|
+
/>
|
|
110
|
+
</Button>
|
|
111
|
+
</div>
|
|
112
|
+
<Popup
|
|
113
|
+
id="{id}-popup"
|
|
114
|
+
anchor={comboboxElement || inputComponent?.element}
|
|
115
|
+
{position}
|
|
116
|
+
bind:open={isPopupOpen}
|
|
117
|
+
bind:this={popupComponent}
|
|
118
|
+
>
|
|
119
|
+
<Listbox
|
|
120
|
+
on:click={({ target }) => {
|
|
121
|
+
if (target.matches('[role="option"]')) {
|
|
122
|
+
// @todo support more types
|
|
123
|
+
value = target.dataset.type === 'number' ? Number(target.value) : target.value;
|
|
124
|
+
label = target.querySelector('.label')?.textContent || target.value;
|
|
125
|
+
dispatch('change', { target: inputComponent?.element, value });
|
|
126
|
+
}
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
<slot />
|
|
130
|
+
</Listbox>
|
|
131
|
+
</Popup>
|
|
132
|
+
|
|
133
|
+
<style>.combobox {
|
|
134
|
+
display: flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
position: relative;
|
|
137
|
+
min-width: var(--combobox-min-width, 160px);
|
|
138
|
+
}
|
|
139
|
+
.combobox :global(.icon) {
|
|
140
|
+
font-size: var(--font-size--xx-large);
|
|
141
|
+
opacity: 0.5;
|
|
142
|
+
}
|
|
143
|
+
.combobox > :global(.icon) {
|
|
144
|
+
position: absolute;
|
|
145
|
+
inset: 8px auto auto 8px;
|
|
146
|
+
z-index: 1;
|
|
147
|
+
}
|
|
148
|
+
.combobox > :global(button) {
|
|
149
|
+
position: absolute;
|
|
150
|
+
inset: 0 0 auto auto;
|
|
151
|
+
z-index: 1;
|
|
152
|
+
border-top-left-radius: 0;
|
|
153
|
+
border-bottom-left-radius: 0;
|
|
154
|
+
}
|
|
155
|
+
.combobox > :global(button[tabindex="-1"]) {
|
|
156
|
+
pointer-events: none;
|
|
157
|
+
}
|
|
158
|
+
.combobox div[role=combobox] {
|
|
159
|
+
display: flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
border-width: 1px;
|
|
162
|
+
border-color: var(--control-border-color);
|
|
163
|
+
border-radius: 4px;
|
|
164
|
+
padding: 0 32px 0 8px;
|
|
165
|
+
width: 100%;
|
|
166
|
+
height: var(--input--medium--height);
|
|
167
|
+
background-color: var(--disabled-background-color);
|
|
168
|
+
-webkit-user-select: none;
|
|
169
|
+
user-select: none;
|
|
170
|
+
cursor: pointer;
|
|
171
|
+
transition: all 200ms;
|
|
172
|
+
}
|
|
173
|
+
.combobox div[role=combobox]:not(.selected) {
|
|
174
|
+
font-style: italic;
|
|
175
|
+
}
|
|
176
|
+
.combobox div[role=combobox]:hover, .combobox div[role=combobox]:focus {
|
|
177
|
+
background-color: var(--highlight-background-color);
|
|
178
|
+
}
|
|
179
|
+
.combobox div[role=combobox][aria-disabled=true] {
|
|
180
|
+
background-color: var(--disabled-background-color);
|
|
181
|
+
opacity: 0.4;
|
|
182
|
+
cursor: default;
|
|
183
|
+
}
|
|
184
|
+
.combobox div[role=combobox] .label {
|
|
185
|
+
display: block;
|
|
186
|
+
overflow: hidden;
|
|
187
|
+
width: 100%;
|
|
188
|
+
white-space: nowrap;
|
|
189
|
+
text-overflow: ellipsis;
|
|
190
|
+
}
|
|
191
|
+
.combobox :global(input) {
|
|
192
|
+
padding: 0 32px 0 8px;
|
|
193
|
+
width: 100%;
|
|
194
|
+
}
|
|
195
|
+
.combobox + :global([role="listbox"]) {
|
|
196
|
+
position: fixed;
|
|
197
|
+
z-index: 100;
|
|
198
|
+
border-radius: 4px;
|
|
199
|
+
box-shadow: 0 8px 16px var(--popup-shadow-color);
|
|
200
|
+
overflow: auto;
|
|
201
|
+
background-color: var(--secondary-background-color);
|
|
202
|
+
backdrop-filter: blur(16px);
|
|
203
|
+
transition: opacity 100ms 100ms;
|
|
204
|
+
}
|
|
205
|
+
.combobox + :global([role="listbox"]:not(.open)) {
|
|
206
|
+
opacity: 0;
|
|
207
|
+
pointer-events: none;
|
|
208
|
+
}</style>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} ComboboxProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} ComboboxEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} ComboboxSlots */
|
|
4
|
+
/**
|
|
5
|
+
* @see https://w3c.github.io/aria/#combobox
|
|
6
|
+
* @see https://w3c.github.io/aria-practices/#combobox
|
|
7
|
+
*/
|
|
8
|
+
export default class Combobox extends SvelteComponentTyped<{
|
|
9
|
+
[x: string]: any;
|
|
10
|
+
label?: string;
|
|
11
|
+
position?: any;
|
|
12
|
+
class?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
value?: string;
|
|
15
|
+
readOnly?: boolean;
|
|
16
|
+
}, {
|
|
17
|
+
change: CustomEvent<any>;
|
|
18
|
+
} & {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
}, {
|
|
21
|
+
default: {};
|
|
22
|
+
}> {
|
|
23
|
+
}
|
|
24
|
+
export type ComboboxProps = typeof __propDef.props;
|
|
25
|
+
export type ComboboxEvents = typeof __propDef.events;
|
|
26
|
+
export type ComboboxSlots = typeof __propDef.slots;
|
|
27
|
+
import { SvelteComponentTyped } from "svelte";
|
|
28
|
+
declare const __propDef: {
|
|
29
|
+
props: {
|
|
30
|
+
[x: string]: any;
|
|
31
|
+
label?: string;
|
|
32
|
+
position?: any;
|
|
33
|
+
class?: string;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
value?: (string | undefined);
|
|
36
|
+
readOnly?: boolean;
|
|
37
|
+
};
|
|
38
|
+
events: {
|
|
39
|
+
change: CustomEvent<any>;
|
|
40
|
+
} & {
|
|
41
|
+
[evt: string]: CustomEvent<any>;
|
|
42
|
+
};
|
|
43
|
+
slots: {
|
|
44
|
+
default: {};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
@see https://w3c.github.io/aria-practices/#disclosure
|
|
4
|
+
@see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
|
|
5
|
+
-->
|
|
6
|
+
<script>
|
|
7
|
+
import Button from '../core/button.svelte';
|
|
8
|
+
import Icon from '../core/icon.svelte';
|
|
9
|
+
import { getRandomId } from '../helpers/util';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* CSS class name on the button.
|
|
13
|
+
* @type {String}
|
|
14
|
+
*/
|
|
15
|
+
let className = '';
|
|
16
|
+
|
|
17
|
+
export { className as class };
|
|
18
|
+
|
|
19
|
+
export let label = '';
|
|
20
|
+
|
|
21
|
+
export let expanded = false;
|
|
22
|
+
|
|
23
|
+
const id = getRandomId('disclosure');
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<div class="sui disclosure {className}" {id} role="group" aria-labelledby="{id}-header">
|
|
27
|
+
<Button
|
|
28
|
+
class="header"
|
|
29
|
+
id="{id}-header"
|
|
30
|
+
aria-controls="{id}-content"
|
|
31
|
+
aria-expanded={expanded}
|
|
32
|
+
on:click={() => {
|
|
33
|
+
expanded = !expanded;
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<Icon name="expand_more" />
|
|
37
|
+
{label}
|
|
38
|
+
</Button>
|
|
39
|
+
<div class="content" id="{id}-content" hidden={!expanded ? 'hidden' : undefined}>
|
|
40
|
+
<slot />
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<style>.disclosure :global(button) {
|
|
45
|
+
display: flex;
|
|
46
|
+
width: 100%;
|
|
47
|
+
justify-content: space-between;
|
|
48
|
+
}
|
|
49
|
+
.disclosure :global(button .icon) {
|
|
50
|
+
transition: all 200ms;
|
|
51
|
+
}
|
|
52
|
+
.disclosure :global(button[aria-expanded="false"] .icon) {
|
|
53
|
+
transform: rotate(-90deg);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.content[hidden] {
|
|
57
|
+
display: block;
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
height: 0;
|
|
60
|
+
}</style>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} DisclosureProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} DisclosureEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} DisclosureSlots */
|
|
4
|
+
/**
|
|
5
|
+
* @see https://w3c.github.io/aria-practices/#disclosure
|
|
6
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
|
|
7
|
+
*/
|
|
8
|
+
export default class Disclosure extends SvelteComponentTyped<{
|
|
9
|
+
label?: string;
|
|
10
|
+
class?: string;
|
|
11
|
+
expanded?: boolean;
|
|
12
|
+
}, {
|
|
13
|
+
[evt: string]: CustomEvent<any>;
|
|
14
|
+
}, {
|
|
15
|
+
default: {};
|
|
16
|
+
}> {
|
|
17
|
+
}
|
|
18
|
+
export type DisclosureProps = typeof __propDef.props;
|
|
19
|
+
export type DisclosureEvents = typeof __propDef.events;
|
|
20
|
+
export type DisclosureSlots = typeof __propDef.slots;
|
|
21
|
+
import { SvelteComponentTyped } from "svelte";
|
|
22
|
+
declare const __propDef: {
|
|
23
|
+
props: {
|
|
24
|
+
label?: string;
|
|
25
|
+
class?: string;
|
|
26
|
+
expanded?: boolean;
|
|
27
|
+
};
|
|
28
|
+
events: {
|
|
29
|
+
[evt: string]: CustomEvent<any>;
|
|
30
|
+
};
|
|
31
|
+
slots: {
|
|
32
|
+
default: {};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export {};
|