@sveltia/ui 0.1.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/LICENSE.txt +21 -0
- package/package/components/composite/calendar.svelte +240 -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 +179 -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 +44 -0
- package/package/components/composite/radio-button-group.svelte.d.ts +36 -0
- package/package/components/composite/select-button-group.svelte +69 -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 +209 -0
- package/package/components/core/button.svelte.d.ts +113 -0
- package/package/components/core/checkbox.svelte +105 -0
- package/package/components/core/checkbox.svelte.d.ts +43 -0
- package/package/components/core/dialog.svelte +258 -0
- package/package/components/core/dialog.svelte.d.ts +73 -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 +65 -0
- package/package/components/core/menu-button.svelte.d.ts +36 -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 +109 -0
- package/package/components/core/number-input.svelte.d.ts +40 -0
- package/package/components/core/option.svelte +57 -0
- package/package/components/core/option.svelte.d.ts +44 -0
- package/package/components/core/password-input.svelte +76 -0
- package/package/components/core/password-input.svelte.d.ts +36 -0
- package/package/components/core/radio-button.svelte +91 -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 +90 -0
- package/package/components/core/search-bar.svelte.d.ts +49 -0
- package/package/components/core/select-button.svelte +29 -0
- package/package/components/core/select-button.svelte.d.ts +40 -0
- package/package/components/core/separator.svelte +28 -0
- package/package/components/core/separator.svelte.d.ts +26 -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 +80 -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 +20 -0
- package/package/components/core/tab.svelte.d.ts +33 -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 +145 -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 +75 -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 +134 -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 +282 -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 +110 -0
- package/package/components/util/popup.svelte.d.ts +46 -0
- package/package/components/util/portal.svelte +34 -0
- package/package/components/util/portal.svelte.d.ts +28 -0
- package/package/index.d.ts +40 -0
- package/package/index.js +65 -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 +113 -0
- package/package/typedef.d.ts +0 -0
- package/package/typedef.js +0 -0
- package/package.json +461 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Kohei Yoshino.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { _ } from 'svelte-i18n';
|
|
3
|
+
import Button from '../core/button.svelte';
|
|
4
|
+
import Icon from '../core/icon.svelte';
|
|
5
|
+
import MenuButton from '../core/menu-button.svelte';
|
|
6
|
+
import Separator from '../core/separator.svelte';
|
|
7
|
+
import Spacer from '../core/spacer.svelte';
|
|
8
|
+
|
|
9
|
+
/** @type {(String|undefined)} */
|
|
10
|
+
export let value = undefined;
|
|
11
|
+
|
|
12
|
+
const dayList = [];
|
|
13
|
+
const weeks = [];
|
|
14
|
+
const now = new Date();
|
|
15
|
+
|
|
16
|
+
$: date = value ? new Date(value) : now;
|
|
17
|
+
$: firstDayOfMonth = new Date(date.getUTCFullYear(), date.getUTCMonth(), 1);
|
|
18
|
+
$: firstDay = new Date(firstDayOfMonth);
|
|
19
|
+
|
|
20
|
+
const getWeeks = () => {
|
|
21
|
+
const cursor = new Date(firstDay);
|
|
22
|
+
|
|
23
|
+
// Start from Sunday
|
|
24
|
+
cursor.setDate(1 - cursor.getUTCDay());
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < 42; i += 1) {
|
|
27
|
+
const week = Math.floor(i / 7);
|
|
28
|
+
|
|
29
|
+
dayList[i] = { day: new Date(cursor) };
|
|
30
|
+
weeks[week] ||= [];
|
|
31
|
+
weeks[week][cursor.getUTCDay() % 7] = { day: new Date(cursor) };
|
|
32
|
+
cursor.setUTCDate(cursor.getUTCDate() + 1);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
$: {
|
|
37
|
+
if (firstDay) {
|
|
38
|
+
getWeeks();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<div role="group">
|
|
44
|
+
<input type="hidden" bind:value />
|
|
45
|
+
<div class="header">
|
|
46
|
+
<MenuButton
|
|
47
|
+
class="ternary"
|
|
48
|
+
label={firstDay.toLocaleDateString('en', { year: 'numeric', month: 'short' })}
|
|
49
|
+
iconName="arrow_drop_down"
|
|
50
|
+
>
|
|
51
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
52
|
+
<div 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
|
+
</MenuButton>
|
|
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.calendar.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
|
+
font-size: 14px;
|
|
163
|
+
}
|
|
164
|
+
[role=group] > * {
|
|
165
|
+
flex: none;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.header,
|
|
169
|
+
.footer {
|
|
170
|
+
display: flex;
|
|
171
|
+
gap: 8px;
|
|
172
|
+
height: 24px;
|
|
173
|
+
align-items: center;
|
|
174
|
+
}
|
|
175
|
+
.header :global(button.secondary),
|
|
176
|
+
.footer :global(button.secondary) {
|
|
177
|
+
width: 100px;
|
|
178
|
+
flex: auto;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.grid {
|
|
182
|
+
display: grid !important;
|
|
183
|
+
grid-template-columns: repeat(auto-fill, 24px);
|
|
184
|
+
gap: 2px;
|
|
185
|
+
width: 180px;
|
|
186
|
+
}
|
|
187
|
+
.grid div {
|
|
188
|
+
display: flex;
|
|
189
|
+
justify-content: center;
|
|
190
|
+
align-items: center;
|
|
191
|
+
width: 24px;
|
|
192
|
+
height: 24px;
|
|
193
|
+
font-size: 12px;
|
|
194
|
+
}
|
|
195
|
+
.grid div.weekday {
|
|
196
|
+
color: var(--secondary-foreground-color);
|
|
197
|
+
}
|
|
198
|
+
.grid div.other-month {
|
|
199
|
+
color: var(--ternary-foreground-color);
|
|
200
|
+
}
|
|
201
|
+
.grid div.today :global(button) {
|
|
202
|
+
color: var(--highlight-foreground-color);
|
|
203
|
+
background-color: var(--primary-accent-color);
|
|
204
|
+
}
|
|
205
|
+
.grid div :global(button) {
|
|
206
|
+
justify-content: center;
|
|
207
|
+
width: 100%;
|
|
208
|
+
height: 24px;
|
|
209
|
+
border-radius: 50%;
|
|
210
|
+
}
|
|
211
|
+
.grid div :global(button):hover {
|
|
212
|
+
background-color: var(--highlight-background-color);
|
|
213
|
+
}
|
|
214
|
+
.grid div :global(button):focus {
|
|
215
|
+
border-width: 1px;
|
|
216
|
+
border-color: var(--primary-accent-color-lighter);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.footer :global(button) {
|
|
220
|
+
font-size: 12px;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.popup-inner {
|
|
224
|
+
display: flex;
|
|
225
|
+
gap: 8px;
|
|
226
|
+
padding: 8px;
|
|
227
|
+
}
|
|
228
|
+
.popup-inner [role=group] {
|
|
229
|
+
gap: 0;
|
|
230
|
+
}
|
|
231
|
+
.popup-inner [role=group] .header {
|
|
232
|
+
justify-content: center;
|
|
233
|
+
}
|
|
234
|
+
.popup-inner .grid {
|
|
235
|
+
grid-template-columns: repeat(auto-fill, 48px);
|
|
236
|
+
width: 98px;
|
|
237
|
+
}
|
|
238
|
+
.popup-inner .grid > div {
|
|
239
|
+
width: 48px;
|
|
240
|
+
}</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?: "vertical" | "horizontal";
|
|
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,179 @@
|
|
|
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 TextInput from '../core/text-input.svelte';
|
|
12
|
+
import Popup from '../util/popup.svelte';
|
|
13
|
+
import Listbox from './listbox.svelte';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* CSS class name on the button.
|
|
17
|
+
* @type {String}
|
|
18
|
+
*/
|
|
19
|
+
let className = '';
|
|
20
|
+
|
|
21
|
+
export { className as class };
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Where to show the dropdown menu.
|
|
25
|
+
* @type {PopupPosition}
|
|
26
|
+
*/
|
|
27
|
+
export let position = 'bottom-left';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether the textbox is editable.
|
|
31
|
+
*/
|
|
32
|
+
export let readOnly = false;
|
|
33
|
+
|
|
34
|
+
export let disabled = false;
|
|
35
|
+
|
|
36
|
+
export let label = '';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Selected option’s value.
|
|
40
|
+
* @type {(String|undefined)}
|
|
41
|
+
*/
|
|
42
|
+
export let value = undefined;
|
|
43
|
+
|
|
44
|
+
const dispatch = createEventDispatcher();
|
|
45
|
+
let comboboxElement;
|
|
46
|
+
/** @type {(TextInput| undefined)} */
|
|
47
|
+
let inputComponent;
|
|
48
|
+
/** @type {(Popup| undefined)} */
|
|
49
|
+
let popupComponent;
|
|
50
|
+
let open = writable(false);
|
|
51
|
+
|
|
52
|
+
$: {
|
|
53
|
+
dispatch('change', { target: inputComponent?.element, value });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
$: {
|
|
57
|
+
if (readOnly && value && popupComponent?.element) {
|
|
58
|
+
window.requestAnimationFrame(() => {
|
|
59
|
+
label =
|
|
60
|
+
popupComponent?.element.querySelector('[aria-selected="true"] .label')?.textContent || '';
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<div class="sui combobox {className}">
|
|
67
|
+
{#if readOnly}
|
|
68
|
+
<!-- svelte-ignore a11y-role-has-required-aria-props -->
|
|
69
|
+
<div
|
|
70
|
+
class:selected={value !== undefined}
|
|
71
|
+
role="combobox"
|
|
72
|
+
aria-disabled={disabled ? true : undefined}
|
|
73
|
+
aria-haspopup="listbox"
|
|
74
|
+
aria-activedescendant="selected-option"
|
|
75
|
+
{...$$restProps}
|
|
76
|
+
bind:this={comboboxElement}
|
|
77
|
+
>
|
|
78
|
+
{value !== undefined ? label || value : $_('sui.combobox.select_an_option')}
|
|
79
|
+
</div>
|
|
80
|
+
{:else}
|
|
81
|
+
<TextInput
|
|
82
|
+
role="combobox"
|
|
83
|
+
{value}
|
|
84
|
+
{disabled}
|
|
85
|
+
aria-haspopup="listbox"
|
|
86
|
+
aria-activedescendant="selected-option"
|
|
87
|
+
{...$$restProps}
|
|
88
|
+
bind:this={inputComponent}
|
|
89
|
+
/>
|
|
90
|
+
{/if}
|
|
91
|
+
<Button
|
|
92
|
+
{disabled}
|
|
93
|
+
class="ternary iconic"
|
|
94
|
+
iconName="expand_more"
|
|
95
|
+
iconLabel={$open ? $_('sui._.collapse') : $_('sui._.expand')}
|
|
96
|
+
on:click={(event) => {
|
|
97
|
+
event.stopPropagation();
|
|
98
|
+
|
|
99
|
+
if (!disabled) {
|
|
100
|
+
open.set(!$open);
|
|
101
|
+
}
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
</div>
|
|
105
|
+
<Popup
|
|
106
|
+
anchor={comboboxElement || inputComponent?.element}
|
|
107
|
+
{position}
|
|
108
|
+
bind:open
|
|
109
|
+
bind:this={popupComponent}
|
|
110
|
+
>
|
|
111
|
+
<Listbox
|
|
112
|
+
on:click={({ target }) => {
|
|
113
|
+
if (target.matches('[role="option"]')) {
|
|
114
|
+
value = target.value;
|
|
115
|
+
}
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<slot />
|
|
119
|
+
</Listbox>
|
|
120
|
+
</Popup>
|
|
121
|
+
|
|
122
|
+
<style>.combobox {
|
|
123
|
+
display: flex;
|
|
124
|
+
align-items: center;
|
|
125
|
+
position: relative;
|
|
126
|
+
}
|
|
127
|
+
.combobox :global(.icon) {
|
|
128
|
+
font-size: 20px;
|
|
129
|
+
opacity: 0.5;
|
|
130
|
+
}
|
|
131
|
+
.combobox > :global(.icon) {
|
|
132
|
+
position: absolute;
|
|
133
|
+
inset: 8px auto auto 8px;
|
|
134
|
+
z-index: 1;
|
|
135
|
+
}
|
|
136
|
+
.combobox > :global(button) {
|
|
137
|
+
position: absolute;
|
|
138
|
+
inset: 0 0 auto auto;
|
|
139
|
+
z-index: 1;
|
|
140
|
+
}
|
|
141
|
+
.combobox div[role=combobox] {
|
|
142
|
+
display: flex;
|
|
143
|
+
align-items: center;
|
|
144
|
+
border-width: 1px;
|
|
145
|
+
border-color: var(--control-border-color);
|
|
146
|
+
border-radius: 4px;
|
|
147
|
+
padding: 0 32px 0 8px;
|
|
148
|
+
width: 100%;
|
|
149
|
+
height: var(--input--medium--height);
|
|
150
|
+
-webkit-user-select: none;
|
|
151
|
+
user-select: none;
|
|
152
|
+
cursor: pointer;
|
|
153
|
+
}
|
|
154
|
+
.combobox div[role=combobox]:not(.selected) {
|
|
155
|
+
font-style: italic;
|
|
156
|
+
}
|
|
157
|
+
.combobox div[role=combobox][aria-disabled=true] {
|
|
158
|
+
background-color: var(--disabled-background-color);
|
|
159
|
+
opacity: 0.4;
|
|
160
|
+
cursor: default;
|
|
161
|
+
}
|
|
162
|
+
.combobox :global(input) {
|
|
163
|
+
padding: 0 32px 0 8px;
|
|
164
|
+
width: 100%;
|
|
165
|
+
}
|
|
166
|
+
.combobox + :global([role="listbox"]) {
|
|
167
|
+
position: fixed;
|
|
168
|
+
z-index: 100;
|
|
169
|
+
border-radius: 4px;
|
|
170
|
+
box-shadow: 0 8px 16px var(--popup-shadow-color);
|
|
171
|
+
overflow: auto;
|
|
172
|
+
background-color: var(--secondary-background-color);
|
|
173
|
+
backdrop-filter: blur(16px);
|
|
174
|
+
transition: opacity 100ms 100ms;
|
|
175
|
+
}
|
|
176
|
+
.combobox + :global([role="listbox"]:not(.open)) {
|
|
177
|
+
opacity: 0;
|
|
178
|
+
pointer-events: none;
|
|
179
|
+
}</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
|
+
class?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
value?: string;
|
|
14
|
+
position?: any;
|
|
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
|
+
class?: string;
|
|
32
|
+
label?: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
value?: (string | undefined);
|
|
35
|
+
position?: any;
|
|
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
|
+
class?: string;
|
|
10
|
+
label?: 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
|
+
class?: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
expanded?: boolean;
|
|
27
|
+
};
|
|
28
|
+
events: {
|
|
29
|
+
[evt: string]: CustomEvent<any>;
|
|
30
|
+
};
|
|
31
|
+
slots: {
|
|
32
|
+
default: {};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export {};
|