@geoffcox/sterling-svelte 0.0.13 → 0.0.15
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/buttons/Button.svelte +1 -1
- package/buttons/Button.svelte.d.ts +4 -1
- package/{lists → containers}/List.svelte +34 -39
- package/{lists → containers}/List.svelte.d.ts +21 -12
- package/containers/ListItem.svelte +48 -0
- package/containers/ListItem.svelte.d.ts +26 -0
- package/containers/Tab.svelte +327 -0
- package/containers/Tab.svelte.d.ts +55 -0
- package/containers/TabList.svelte +126 -0
- package/containers/TabList.svelte.d.ts +56 -0
- package/containers/Tabs.constants.d.ts +1 -0
- package/containers/Tabs.constants.js +1 -0
- package/containers/Tabs.types.d.ts +12 -0
- package/containers/Tabs.types.js +1 -0
- package/containers/Tree.constants.d.ts +2 -0
- package/containers/Tree.constants.js +2 -0
- package/containers/Tree.svelte +222 -0
- package/containers/Tree.svelte.d.ts +50 -0
- package/containers/Tree.types.d.ts +47 -0
- package/containers/Tree.types.js +1 -0
- package/containers/TreeChevron.svelte +109 -0
- package/containers/TreeChevron.svelte.d.ts +17 -0
- package/containers/TreeItem.svelte +96 -0
- package/containers/TreeItem.svelte.d.ts +60 -0
- package/containers/TreeNode.svelte +267 -0
- package/containers/TreeNode.svelte.d.ts +43 -0
- package/display/Progress.svelte +9 -7
- package/index.d.ts +12 -5
- package/index.js +7 -5
- package/inputs/Checkbox.svelte +1 -1
- package/inputs/Checkbox.svelte.d.ts +4 -1
- package/inputs/Input.svelte +8 -6
- package/inputs/Select.svelte +21 -19
- package/inputs/Select.svelte.d.ts +16 -12
- package/inputs/Slider.svelte +4 -6
- package/inputs/TextArea.svelte +8 -6
- package/package.json +13 -2
- package/surfaces/Dialog.svelte +0 -2
package/buttons/Button.svelte
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
<script>import { createEventDispatcher } from "svelte";
|
|
2
2
|
import { v4 as uuid } from "uuid";
|
|
3
3
|
import Label from "../display/Label.svelte";
|
|
4
|
+
import ListItem from "./ListItem.svelte";
|
|
4
5
|
export let disabled = false;
|
|
5
6
|
export let items = [];
|
|
6
7
|
export let horizontal = false;
|
|
7
8
|
export let selectedIndex = -1;
|
|
8
9
|
export let selectedItem = void 0;
|
|
10
|
+
export let composed = false;
|
|
9
11
|
$: {
|
|
10
12
|
selectedItem = items[selectedIndex];
|
|
11
13
|
}
|
|
12
14
|
const inputId = uuid();
|
|
13
15
|
let listRef;
|
|
14
16
|
let itemRefs = {};
|
|
15
|
-
let focusVisible = false;
|
|
16
17
|
const dispatch = createEventDispatcher();
|
|
17
18
|
const raiseItemSelected = (index) => {
|
|
18
19
|
dispatch("itemSelected", { index, item: items[index] });
|
|
@@ -37,6 +38,12 @@ export const selectNextItem = () => {
|
|
|
37
38
|
selectedIndex = Math.min(items.length - 1, selectedIndex + 1);
|
|
38
39
|
}
|
|
39
40
|
};
|
|
41
|
+
export const selectItem = (item) => {
|
|
42
|
+
const index = items.indexOf(item);
|
|
43
|
+
if (index !== -1) {
|
|
44
|
+
selectedIndex = index;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
40
47
|
$: {
|
|
41
48
|
raiseItemSelected(selectedIndex);
|
|
42
49
|
}
|
|
@@ -93,19 +100,17 @@ const onKeydown = (event) => {
|
|
|
93
100
|
@component
|
|
94
101
|
A list of items where a single item can be selected.
|
|
95
102
|
-->
|
|
96
|
-
|
|
103
|
+
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
104
|
+
<div class="sterling-list" class:horizontal class:disabled class:composed tabindex={0}>
|
|
97
105
|
{#if $$slots.label}
|
|
98
|
-
<
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
</Label>
|
|
102
|
-
</div>
|
|
106
|
+
<Label {disabled} for={inputId}>
|
|
107
|
+
<slot name="label" />
|
|
108
|
+
</Label>
|
|
103
109
|
{/if}
|
|
104
110
|
<div
|
|
105
111
|
bind:this={listRef}
|
|
106
112
|
class="list"
|
|
107
113
|
class:disabled
|
|
108
|
-
class:focus-visible={focusVisible}
|
|
109
114
|
class:horizontal
|
|
110
115
|
role="listbox"
|
|
111
116
|
tabindex={!disabled ? 0 : undefined}
|
|
@@ -140,14 +145,16 @@ A list of items where a single item can be selected.
|
|
|
140
145
|
bind:this={itemRefs[index]}
|
|
141
146
|
aria-selected={disabled ? undefined : selected}
|
|
142
147
|
class="list-item"
|
|
143
|
-
class:selected
|
|
144
|
-
class:disabled
|
|
145
148
|
data-index={index + 1}
|
|
146
149
|
role="option"
|
|
147
150
|
on:click={() => onItemClick(index)}
|
|
148
151
|
>
|
|
149
|
-
<slot {disabled} {index} {item} {selected}>
|
|
150
|
-
{item}
|
|
152
|
+
<slot name="item" {disabled} {index} {item} {selected}>
|
|
153
|
+
<ListItem {disabled} {selected} {index} {item}>
|
|
154
|
+
<slot {disabled} {index} {item} {selected}>
|
|
155
|
+
{item}
|
|
156
|
+
</slot>
|
|
157
|
+
</ListItem>
|
|
151
158
|
</slot>
|
|
152
159
|
</div>
|
|
153
160
|
{/each}
|
|
@@ -168,6 +175,7 @@ A list of items where a single item can be selected.
|
|
|
168
175
|
grid-template-rows: auto 1fr;
|
|
169
176
|
height: 100%;
|
|
170
177
|
margin: 0;
|
|
178
|
+
overflow: hidden;
|
|
171
179
|
padding: 0;
|
|
172
180
|
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
173
181
|
}
|
|
@@ -182,8 +190,7 @@ A list of items where a single item can be selected.
|
|
|
182
190
|
color: var(--Common__color--hover);
|
|
183
191
|
}
|
|
184
192
|
|
|
185
|
-
.sterling-list:focus-
|
|
186
|
-
.sterling-list.focus-visible {
|
|
193
|
+
.sterling-list:focus-within {
|
|
187
194
|
border-color: var(--Common__border-color--focus);
|
|
188
195
|
color: var(--Common__color--focus);
|
|
189
196
|
outline-color: var(--Common__outline-color);
|
|
@@ -199,6 +206,15 @@ A list of items where a single item can be selected.
|
|
|
199
206
|
cursor: not-allowed;
|
|
200
207
|
}
|
|
201
208
|
|
|
209
|
+
.sterling-list.composed,
|
|
210
|
+
.sterling-list:hover.composed,
|
|
211
|
+
.sterling-list:focus-visible.composed,
|
|
212
|
+
.sterling-list.disabled.composed {
|
|
213
|
+
background: none;
|
|
214
|
+
border: none;
|
|
215
|
+
outline: none;
|
|
216
|
+
}
|
|
217
|
+
|
|
202
218
|
.list {
|
|
203
219
|
display: flex;
|
|
204
220
|
flex-direction: column;
|
|
@@ -206,6 +222,7 @@ A list of items where a single item can be selected.
|
|
|
206
222
|
grid-row: 2 / span 1;
|
|
207
223
|
overflow-x: hidden;
|
|
208
224
|
overflow-y: scroll;
|
|
225
|
+
outline: none;
|
|
209
226
|
position: relative;
|
|
210
227
|
}
|
|
211
228
|
|
|
@@ -215,39 +232,17 @@ A list of items where a single item can be selected.
|
|
|
215
232
|
overflow-y: hidden;
|
|
216
233
|
}
|
|
217
234
|
|
|
218
|
-
.label {
|
|
235
|
+
.sterling-list > :global(label) {
|
|
219
236
|
font-size: 0.7em;
|
|
220
237
|
margin: 0.5em 0.7em;
|
|
221
238
|
}
|
|
222
239
|
|
|
223
|
-
.list
|
|
224
|
-
box-sizing: border-box;
|
|
225
|
-
color: var(--Input__color);
|
|
240
|
+
.sterling-list > :global(label):empty {
|
|
226
241
|
margin: 0;
|
|
227
|
-
padding: 0.5em;
|
|
228
|
-
outline: none;
|
|
229
|
-
text-overflow: ellipsis;
|
|
230
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
231
|
-
white-space: nowrap;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
.list-item:hover {
|
|
235
|
-
background-color: var(--Button__background-color--hover);
|
|
236
|
-
color: var(--Button__color--hover);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
.list-item.selected {
|
|
240
|
-
background-color: var(--Input__background-color--selected);
|
|
241
|
-
color: var(--Input__color--selected);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
.list-item.disabled {
|
|
245
|
-
color: var(--Input__color--disabled);
|
|
246
242
|
}
|
|
247
243
|
|
|
248
244
|
@media (prefers-reduced-motion) {
|
|
249
|
-
.sterling-list
|
|
250
|
-
.list-item {
|
|
245
|
+
.sterling-list {
|
|
251
246
|
transition: none;
|
|
252
247
|
}
|
|
253
248
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
declare
|
|
3
|
-
props: {
|
|
2
|
+
declare class __sveltets_Render<T> {
|
|
3
|
+
props(): {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
disabled?: boolean | undefined;
|
|
6
|
-
items?:
|
|
6
|
+
items?: T[] | undefined;
|
|
7
7
|
horizontal?: boolean | undefined;
|
|
8
8
|
selectedIndex?: number | undefined;
|
|
9
|
-
selectedItem?:
|
|
9
|
+
selectedItem?: T | undefined;
|
|
10
|
+
composed?: boolean | undefined;
|
|
10
11
|
focusSelectedItem?: (() => void) | undefined;
|
|
11
12
|
selectPreviousItem?: (() => void) | undefined;
|
|
12
13
|
selectNextItem?: (() => void) | undefined;
|
|
14
|
+
selectItem?: ((item: T) => void) | undefined;
|
|
13
15
|
};
|
|
14
|
-
events: {
|
|
16
|
+
events(): {
|
|
15
17
|
blur: FocusEvent;
|
|
16
18
|
click: MouseEvent;
|
|
17
19
|
copy: ClipboardEvent;
|
|
@@ -37,23 +39,30 @@ declare const __propDef: {
|
|
|
37
39
|
} & {
|
|
38
40
|
[evt: string]: CustomEvent<any>;
|
|
39
41
|
};
|
|
40
|
-
slots: {
|
|
42
|
+
slots(): {
|
|
41
43
|
label: {};
|
|
44
|
+
item: {
|
|
45
|
+
disabled: boolean;
|
|
46
|
+
index: any;
|
|
47
|
+
item: T;
|
|
48
|
+
selected: any;
|
|
49
|
+
};
|
|
42
50
|
default: {
|
|
43
51
|
disabled: boolean;
|
|
44
52
|
index: any;
|
|
45
|
-
item:
|
|
53
|
+
item: T;
|
|
46
54
|
selected: any;
|
|
47
55
|
};
|
|
48
56
|
};
|
|
49
|
-
}
|
|
50
|
-
export type ListProps =
|
|
51
|
-
export type ListEvents =
|
|
52
|
-
export type ListSlots =
|
|
57
|
+
}
|
|
58
|
+
export type ListProps<T> = ReturnType<__sveltets_Render<T>['props']>;
|
|
59
|
+
export type ListEvents<T> = ReturnType<__sveltets_Render<T>['events']>;
|
|
60
|
+
export type ListSlots<T> = ReturnType<__sveltets_Render<T>['slots']>;
|
|
53
61
|
/** A list of items where a single item can be selected. */
|
|
54
|
-
export default class List extends SvelteComponentTyped<ListProps
|
|
62
|
+
export default class List<T> extends SvelteComponentTyped<ListProps<T>, ListEvents<T>, ListSlots<T>> {
|
|
55
63
|
get focusSelectedItem(): () => void;
|
|
56
64
|
get selectPreviousItem(): () => void;
|
|
57
65
|
get selectNextItem(): () => void;
|
|
66
|
+
get selectItem(): (item: T) => void;
|
|
58
67
|
}
|
|
59
68
|
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script>export let disabled = false;
|
|
2
|
+
export let selected = false;
|
|
3
|
+
export let index = -1;
|
|
4
|
+
export let item = void 0;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<div
|
|
8
|
+
aria-selected={disabled ? undefined : selected}
|
|
9
|
+
class="sterling-list-item"
|
|
10
|
+
class:disabled
|
|
11
|
+
class:selected
|
|
12
|
+
>
|
|
13
|
+
<slot {disabled} {selected} {index} {item} />
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<style>
|
|
17
|
+
.sterling-list-item {
|
|
18
|
+
background-color: transparent;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
color: var(--Input__color);
|
|
21
|
+
margin: 0;
|
|
22
|
+
padding: 0.5em;
|
|
23
|
+
outline: none;
|
|
24
|
+
text-overflow: ellipsis;
|
|
25
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
26
|
+
white-space: nowrap;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.sterling-list-item:hover {
|
|
30
|
+
background-color: var(--Button__background-color--hover);
|
|
31
|
+
color: var(--Button__color--hover);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.sterling-list-item.selected {
|
|
35
|
+
background-color: var(--Input__background-color--selected);
|
|
36
|
+
color: var(--Input__color--selected);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.sterling-list-item.disabled {
|
|
40
|
+
color: var(--Input__color--disabled);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@media (prefers-reduced-motion) {
|
|
44
|
+
.sterling-list-item {
|
|
45
|
+
transition: none;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
</style>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare class __sveltets_Render<T> {
|
|
3
|
+
props(): {
|
|
4
|
+
disabled?: boolean | undefined;
|
|
5
|
+
selected?: boolean | undefined;
|
|
6
|
+
index?: number | undefined;
|
|
7
|
+
item?: T | undefined;
|
|
8
|
+
};
|
|
9
|
+
events(): {} & {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots(): {
|
|
13
|
+
default: {
|
|
14
|
+
disabled: boolean;
|
|
15
|
+
selected: boolean;
|
|
16
|
+
index: number;
|
|
17
|
+
item: T | undefined;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export type ListItemProps<T> = ReturnType<__sveltets_Render<T>['props']>;
|
|
22
|
+
export type ListItemEvents<T> = ReturnType<__sveltets_Render<T>['events']>;
|
|
23
|
+
export type ListItemSlots<T> = ReturnType<__sveltets_Render<T>['slots']>;
|
|
24
|
+
export default class ListItem<T> extends SvelteComponentTyped<ListItemProps<T>, ListItemEvents<T>, ListItemSlots<T>> {
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import { tabListContextKey } from "./Tabs.constants";
|
|
3
|
+
export let data = void 0;
|
|
4
|
+
export let disabled = false;
|
|
5
|
+
export let tabId = void 0;
|
|
6
|
+
export let text = void 0;
|
|
7
|
+
export let selected = false;
|
|
8
|
+
let tabRef;
|
|
9
|
+
const {
|
|
10
|
+
disabled: tabListDisabled,
|
|
11
|
+
selectedTabId,
|
|
12
|
+
selectionFollowsFocus,
|
|
13
|
+
vertical
|
|
14
|
+
} = getContext(tabListContextKey);
|
|
15
|
+
$:
|
|
16
|
+
_tabId = tabId || data?.tabId;
|
|
17
|
+
$:
|
|
18
|
+
_text = text || data?.text || _tabId;
|
|
19
|
+
$:
|
|
20
|
+
_disabled = $tabListDisabled || disabled || data?.disabled === true;
|
|
21
|
+
$: {
|
|
22
|
+
if (!_tabId) {
|
|
23
|
+
throw new Error("Both tabId and data.tabId are missing");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
$: {
|
|
27
|
+
selected = $selectedTabId === _tabId;
|
|
28
|
+
}
|
|
29
|
+
$: {
|
|
30
|
+
if (selected) {
|
|
31
|
+
selectedTabId.set(_tabId);
|
|
32
|
+
tabRef?.focus();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const getFirstActiveTab = () => {
|
|
36
|
+
let foundTab = tabRef.parentElement?.firstElementChild;
|
|
37
|
+
while (foundTab) {
|
|
38
|
+
if (!foundTab.disabled && foundTab.getAttribute("data-tab-id")) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
foundTab = foundTab.nextElementSibling;
|
|
42
|
+
}
|
|
43
|
+
return foundTab;
|
|
44
|
+
};
|
|
45
|
+
const getLastActiveTab = () => {
|
|
46
|
+
let foundTab = tabRef.parentElement?.lastElementChild;
|
|
47
|
+
while (foundTab) {
|
|
48
|
+
if (!foundTab.disabled && foundTab.getAttribute("data-tab-id")) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
foundTab = foundTab.previousElementSibling;
|
|
52
|
+
}
|
|
53
|
+
return foundTab;
|
|
54
|
+
};
|
|
55
|
+
const getPreviousActiveTab = () => {
|
|
56
|
+
let foundTab = tabRef?.previousElementSibling;
|
|
57
|
+
while (foundTab) {
|
|
58
|
+
if (!foundTab.disabled && foundTab.getAttribute("data-tab-id")) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
foundTab = foundTab.previousElementSibling;
|
|
62
|
+
}
|
|
63
|
+
return foundTab;
|
|
64
|
+
};
|
|
65
|
+
const getNextActiveTab = () => {
|
|
66
|
+
let foundTab = tabRef?.nextElementSibling;
|
|
67
|
+
while (foundTab) {
|
|
68
|
+
if (!foundTab.disabled && foundTab.getAttribute("data-tab-id")) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
foundTab = foundTab.nextElementSibling;
|
|
72
|
+
}
|
|
73
|
+
return foundTab;
|
|
74
|
+
};
|
|
75
|
+
const focusFirstTab = () => {
|
|
76
|
+
if (!_disabled) {
|
|
77
|
+
let foundTab = getFirstActiveTab();
|
|
78
|
+
if (foundTab) {
|
|
79
|
+
foundTab.focus();
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
};
|
|
85
|
+
const focusLastTab = () => {
|
|
86
|
+
if (!_disabled) {
|
|
87
|
+
let foundTab = getLastActiveTab();
|
|
88
|
+
if (foundTab) {
|
|
89
|
+
foundTab.focus();
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
};
|
|
95
|
+
const focusPreviousTab = () => {
|
|
96
|
+
if (!_disabled) {
|
|
97
|
+
let foundTab = getPreviousActiveTab();
|
|
98
|
+
if (foundTab) {
|
|
99
|
+
foundTab.focus();
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
};
|
|
105
|
+
const focusNextTab = () => {
|
|
106
|
+
if (!_disabled) {
|
|
107
|
+
let foundTab = getNextActiveTab();
|
|
108
|
+
if (foundTab) {
|
|
109
|
+
foundTab.focus();
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
};
|
|
115
|
+
const onClick = (event) => {
|
|
116
|
+
if (!_disabled) {
|
|
117
|
+
selectedTabId.set(_tabId);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const onFocus = (event) => {
|
|
121
|
+
if (!_disabled && $selectionFollowsFocus) {
|
|
122
|
+
selectedTabId.set(_tabId);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const onKeydown = (event) => {
|
|
126
|
+
if (!_disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
127
|
+
switch (event.key) {
|
|
128
|
+
case "Home":
|
|
129
|
+
if (focusFirstTab()) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
case "End":
|
|
135
|
+
if (focusLastTab()) {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case "ArrowLeft":
|
|
141
|
+
if (!$vertical && focusPreviousTab()) {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
case "ArrowRight":
|
|
147
|
+
if (!$vertical && focusNextTab()) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case "ArrowUp":
|
|
153
|
+
if ($vertical && focusPreviousTab()) {
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case "ArrowDown":
|
|
159
|
+
if ($vertical && focusNextTab()) {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
</script>
|
|
170
|
+
|
|
171
|
+
<button
|
|
172
|
+
bind:this={tabRef}
|
|
173
|
+
class="sterling-tab"
|
|
174
|
+
disabled={_disabled}
|
|
175
|
+
class:selected
|
|
176
|
+
class:vertical={$vertical}
|
|
177
|
+
data-tab-id={_tabId}
|
|
178
|
+
role="tab"
|
|
179
|
+
tabindex={selected ? 0 : -1}
|
|
180
|
+
type="button"
|
|
181
|
+
on:blur
|
|
182
|
+
on:click={onClick}
|
|
183
|
+
on:click
|
|
184
|
+
on:dblclick
|
|
185
|
+
on:focus={onFocus}
|
|
186
|
+
on:focus
|
|
187
|
+
on:focusin
|
|
188
|
+
on:focusout
|
|
189
|
+
on:keydown={onKeydown}
|
|
190
|
+
on:keydown
|
|
191
|
+
on:keypress
|
|
192
|
+
on:keyup
|
|
193
|
+
on:mousedown
|
|
194
|
+
on:mouseenter
|
|
195
|
+
on:mouseleave
|
|
196
|
+
on:mousemove
|
|
197
|
+
on:mouseover
|
|
198
|
+
on:mouseout
|
|
199
|
+
on:mouseup
|
|
200
|
+
on:pointercancel
|
|
201
|
+
on:pointerdown
|
|
202
|
+
on:pointerenter
|
|
203
|
+
on:pointerleave
|
|
204
|
+
on:pointermove
|
|
205
|
+
on:pointerover
|
|
206
|
+
on:pointerout
|
|
207
|
+
on:pointerup
|
|
208
|
+
on:wheel
|
|
209
|
+
>
|
|
210
|
+
<div class="content">
|
|
211
|
+
<slot {data} disabled={_disabled} {selected} tabId={_tabId} text={_text}>
|
|
212
|
+
<div class="text">
|
|
213
|
+
{_text || _tabId}
|
|
214
|
+
</div>
|
|
215
|
+
</slot>
|
|
216
|
+
</div>
|
|
217
|
+
<div class="indicator" />
|
|
218
|
+
</button>
|
|
219
|
+
|
|
220
|
+
<style>
|
|
221
|
+
.sterling-tab {
|
|
222
|
+
align-content: center;
|
|
223
|
+
align-items: center;
|
|
224
|
+
background-color: var(--Common__background-color);
|
|
225
|
+
border-color: transparent;
|
|
226
|
+
border-radius: var(--Button__border-radius);
|
|
227
|
+
border-style: var(--Common__border-style);
|
|
228
|
+
border-width: 0;
|
|
229
|
+
box-sizing: border-box;
|
|
230
|
+
color: var(--Common__color);
|
|
231
|
+
cursor: pointer;
|
|
232
|
+
display: grid;
|
|
233
|
+
font: inherit;
|
|
234
|
+
overflow: hidden;
|
|
235
|
+
padding: 0.5em 1em 0.25em 1em;
|
|
236
|
+
text-decoration: none;
|
|
237
|
+
text-overflow: ellipsis;
|
|
238
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
239
|
+
white-space: nowrap;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.sterling-tab:not(.vertical) {
|
|
243
|
+
grid-template-columns: 1fr;
|
|
244
|
+
grid-template-rows: 1fr 1em;
|
|
245
|
+
justify-content: center;
|
|
246
|
+
justify-items: center;
|
|
247
|
+
row-gap: 0.15em;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.sterling-tab.vertical {
|
|
251
|
+
grid-template-columns: auto 1em;
|
|
252
|
+
grid-template-rows: 1fr;
|
|
253
|
+
align-content: center;
|
|
254
|
+
align-items: center;
|
|
255
|
+
justify-content: flex-end;
|
|
256
|
+
justify-items: flex-end;
|
|
257
|
+
column-gap: 0.15em;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.sterling-tab:hover {
|
|
261
|
+
background-color: var(--Common__background-color--hover);
|
|
262
|
+
color: var(--Common__color--hover);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.sterling-tab:active {
|
|
266
|
+
background-color: var(--Common__background-color--active);
|
|
267
|
+
color: var(--Common__color--active);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.sterling-tab:focus-visible {
|
|
271
|
+
outline-color: var(--Common__outline-color);
|
|
272
|
+
outline-offset: var(--Common__outline-offset);
|
|
273
|
+
outline-style: var(--Common__outline-style);
|
|
274
|
+
outline-width: var(--Common__outline-width);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.sterling-tab:disabled {
|
|
278
|
+
color: var(--Common__color--disabled);
|
|
279
|
+
cursor: not-allowed;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.content {
|
|
283
|
+
padding: 0 0.2em;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.sterling-tab.vertical .content .text {
|
|
287
|
+
padding-top: 0.25em;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.indicator {
|
|
291
|
+
background-color: transparent;
|
|
292
|
+
border-radius: 10000px;
|
|
293
|
+
transition: background-color 250ms;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.sterling-tab:not(.vertical) .indicator {
|
|
297
|
+
justify-self: stretch;
|
|
298
|
+
height: 0.4em;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.sterling-tab.vertical .indicator {
|
|
302
|
+
align-self: stretch;
|
|
303
|
+
width: 0.4em;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.sterling-tab:hover .indicator {
|
|
307
|
+
background-color: var(--Display__color--faint);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.sterling-tab:active .indicator {
|
|
311
|
+
background-color: var(--Button__border-color--hover);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.sterling-tab:disabled .indicator,
|
|
315
|
+
.sterling-tab:disabled:hover .indicator,
|
|
316
|
+
.sterling-tab:disabled:active .indicator {
|
|
317
|
+
background-color: transparent;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.sterling-tab.selected .indicator {
|
|
321
|
+
background-color: var(--Input__color);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.sterling-tab.selected:disabled .indicator {
|
|
325
|
+
background-color: var(--Input__color--disabled);
|
|
326
|
+
}
|
|
327
|
+
</style>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { TabData } from './Tabs.types';
|
|
3
|
+
declare class __sveltets_Render<T> {
|
|
4
|
+
props(): {
|
|
5
|
+
data?: TabData<T> | undefined;
|
|
6
|
+
disabled?: boolean | undefined;
|
|
7
|
+
tabId?: string | undefined;
|
|
8
|
+
text?: string | undefined;
|
|
9
|
+
selected?: boolean | undefined;
|
|
10
|
+
};
|
|
11
|
+
events(): {
|
|
12
|
+
blur: FocusEvent;
|
|
13
|
+
click: MouseEvent;
|
|
14
|
+
dblclick: MouseEvent;
|
|
15
|
+
focus: FocusEvent;
|
|
16
|
+
focusin: FocusEvent;
|
|
17
|
+
focusout: FocusEvent;
|
|
18
|
+
keydown: KeyboardEvent;
|
|
19
|
+
keypress: KeyboardEvent;
|
|
20
|
+
keyup: KeyboardEvent;
|
|
21
|
+
mousedown: MouseEvent;
|
|
22
|
+
mouseenter: MouseEvent;
|
|
23
|
+
mouseleave: MouseEvent;
|
|
24
|
+
mousemove: MouseEvent;
|
|
25
|
+
mouseover: MouseEvent;
|
|
26
|
+
mouseout: MouseEvent;
|
|
27
|
+
mouseup: MouseEvent;
|
|
28
|
+
pointercancel: PointerEvent;
|
|
29
|
+
pointerdown: PointerEvent;
|
|
30
|
+
pointerenter: PointerEvent;
|
|
31
|
+
pointerleave: PointerEvent;
|
|
32
|
+
pointermove: PointerEvent;
|
|
33
|
+
pointerover: PointerEvent;
|
|
34
|
+
pointerout: PointerEvent;
|
|
35
|
+
pointerup: PointerEvent;
|
|
36
|
+
wheel: WheelEvent;
|
|
37
|
+
} & {
|
|
38
|
+
[evt: string]: CustomEvent<any>;
|
|
39
|
+
};
|
|
40
|
+
slots(): {
|
|
41
|
+
default: {
|
|
42
|
+
data: TabData<T> | undefined;
|
|
43
|
+
disabled: boolean;
|
|
44
|
+
selected: boolean;
|
|
45
|
+
tabId: string | undefined;
|
|
46
|
+
text: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export type TabProps<T> = ReturnType<__sveltets_Render<T>['props']>;
|
|
51
|
+
export type TabEvents<T> = ReturnType<__sveltets_Render<T>['events']>;
|
|
52
|
+
export type TabSlots<T> = ReturnType<__sveltets_Render<T>['slots']>;
|
|
53
|
+
export default class Tab<T> extends SvelteComponentTyped<TabProps<T>, TabEvents<T>, TabSlots<T>> {
|
|
54
|
+
}
|
|
55
|
+
export {};
|