@tableslayer/ui 0.2.9 → 0.3.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/components/Autocomplete/Autocomplete.svelte +874 -0
- package/dist/components/Autocomplete/Autocomplete.svelte.d.ts +26 -0
- package/dist/components/Autocomplete/index.d.ts +2 -0
- package/dist/components/Autocomplete/index.js +2 -0
- package/dist/components/Autocomplete/types.d.ts +81 -0
- package/dist/components/Autocomplete/types.js +1 -0
- package/dist/components/Dialog/Dialog.svelte +174 -0
- package/dist/components/Dialog/Dialog.svelte.d.ts +23 -0
- package/dist/components/Dialog/index.d.ts +2 -0
- package/dist/components/Dialog/index.js +2 -0
- package/dist/components/Dialog/types.d.ts +20 -0
- package/dist/components/Dialog/types.js +1 -0
- package/dist/components/Input/FileInput.svelte.d.ts +1 -1
- package/dist/components/Input/InputCheckbox.svelte.d.ts +1 -1
- package/dist/components/NumberInput/NumberInput.svelte +241 -0
- package/dist/components/NumberInput/NumberInput.svelte.d.ts +16 -0
- package/dist/components/NumberInput/index.d.ts +2 -0
- package/dist/components/NumberInput/index.js +2 -0
- package/dist/components/NumberInput/types.d.ts +18 -0
- package/dist/components/NumberInput/types.js +1 -0
- package/dist/components/Tabs/Tabs.svelte +204 -0
- package/dist/components/Tabs/Tabs.svelte.d.ts +26 -0
- package/dist/components/Tabs/index.d.ts +2 -0
- package/dist/components/Tabs/index.js +2 -0
- package/dist/components/Tabs/types.d.ts +25 -0
- package/dist/components/Tabs/types.js +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Icon } from '../Icon';
|
|
3
|
+
import type { Tab, TabsProps } from './types';
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
tabs,
|
|
7
|
+
selected = $bindable(),
|
|
8
|
+
onSelectedChange,
|
|
9
|
+
variant = 'underline',
|
|
10
|
+
size = 'md',
|
|
11
|
+
children,
|
|
12
|
+
...restProps
|
|
13
|
+
}: TabsProps = $props();
|
|
14
|
+
|
|
15
|
+
const uid = $props.id();
|
|
16
|
+
const tabId = (id: string) => `${uid}-tab-${id}`;
|
|
17
|
+
const panelId = `${uid}-panel`;
|
|
18
|
+
let list = $state<HTMLElement | null>(null);
|
|
19
|
+
|
|
20
|
+
const select = (tab: Tab) => {
|
|
21
|
+
if (tab.isDisabled || tab.id === selected) return;
|
|
22
|
+
selected = tab.id;
|
|
23
|
+
onSelectedChange?.(tab.id);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Arrow keys move along the row and take the tab they land on, as a row of tabs is expected to. */
|
|
27
|
+
const onkeydown = (event: KeyboardEvent) => {
|
|
28
|
+
const open = tabs.filter((tab) => !tab.isDisabled);
|
|
29
|
+
const at = open.findIndex((tab) => tab.id === selected);
|
|
30
|
+
let to: Tab | undefined;
|
|
31
|
+
if (event.key === 'ArrowRight') to = open[(at + 1) % open.length];
|
|
32
|
+
else if (event.key === 'ArrowLeft') to = open[(at - 1 + open.length) % open.length];
|
|
33
|
+
else if (event.key === 'Home') to = open[0];
|
|
34
|
+
else if (event.key === 'End') to = open[open.length - 1];
|
|
35
|
+
if (!to) return;
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
const element = list?.querySelector<HTMLElement>(`#${CSS.escape(tabId(to.id))}`);
|
|
38
|
+
element?.focus();
|
|
39
|
+
// A link is followed by its own click; anything else is selected at once.
|
|
40
|
+
if (to.href) element?.click();
|
|
41
|
+
else select(to);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const classes = $derived(['tabs', `tabs--${variant}`, `tabs--${size}`, restProps.class ?? '']);
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<!--
|
|
48
|
+
@component
|
|
49
|
+
## Tabs
|
|
50
|
+
|
|
51
|
+
A row of tabs, one of them selected. With `children` it shows what the selected tab holds;
|
|
52
|
+
without, it is only the row, for a page that switches something of its own. A tab with an
|
|
53
|
+
`href` is a link.
|
|
54
|
+
|
|
55
|
+
@example
|
|
56
|
+
```svelte
|
|
57
|
+
<Tabs
|
|
58
|
+
tabs={[
|
|
59
|
+
{ id: 'terrain', label: 'Terrain' },
|
|
60
|
+
{ id: 'hexsides', label: 'Hexsides', badge: 12 }
|
|
61
|
+
]}
|
|
62
|
+
bind:selected
|
|
63
|
+
>
|
|
64
|
+
{#snippet children({ selected })}
|
|
65
|
+
{#if selected === 'terrain'}…{/if}
|
|
66
|
+
{/snippet}
|
|
67
|
+
</Tabs>
|
|
68
|
+
```
|
|
69
|
+
-->
|
|
70
|
+
<div {...restProps} class={classes}>
|
|
71
|
+
<!-- svelte-ignore a11y_interactive_supports_focus -->
|
|
72
|
+
<div bind:this={list} class="tabs__list" role="tablist" {onkeydown}>
|
|
73
|
+
{#each tabs as tab (tab.id)}
|
|
74
|
+
<svelte:element
|
|
75
|
+
this={tab.href && !tab.isDisabled ? 'a' : 'button'}
|
|
76
|
+
id={tabId(tab.id)}
|
|
77
|
+
class={['tabs__tab', tab.id === selected && 'tabs__tab--isSelected', tab.isDisabled && 'tabs__tab--isDisabled']}
|
|
78
|
+
role="tab"
|
|
79
|
+
href={tab.href && !tab.isDisabled ? tab.href : undefined}
|
|
80
|
+
type={tab.href && !tab.isDisabled ? undefined : 'button'}
|
|
81
|
+
aria-selected={tab.id === selected}
|
|
82
|
+
aria-controls={children ? panelId : undefined}
|
|
83
|
+
aria-disabled={tab.isDisabled}
|
|
84
|
+
disabled={tab.href ? undefined : tab.isDisabled}
|
|
85
|
+
tabindex={tab.id === selected ? 0 : -1}
|
|
86
|
+
onclick={() => select(tab)}
|
|
87
|
+
>
|
|
88
|
+
{#if tab.icon}
|
|
89
|
+
<Icon Icon={tab.icon} size={size === 'sm' ? '0.875rem' : '1rem'} />
|
|
90
|
+
{/if}
|
|
91
|
+
<span class="tabs__label">{tab.label}</span>
|
|
92
|
+
{#if tab.badge !== undefined}
|
|
93
|
+
<span class="tabs__badge">{tab.badge}</span>
|
|
94
|
+
{/if}
|
|
95
|
+
</svelte:element>
|
|
96
|
+
{/each}
|
|
97
|
+
</div>
|
|
98
|
+
{#if children}
|
|
99
|
+
<div id={panelId} class="tabs__panel" role="tabpanel" aria-labelledby={tabId(selected)}>
|
|
100
|
+
{@render children({ selected })}
|
|
101
|
+
</div>
|
|
102
|
+
{/if}
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<style>
|
|
106
|
+
.tabs {
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-direction: column;
|
|
109
|
+
min-width: 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.tabs__list {
|
|
113
|
+
display: flex;
|
|
114
|
+
flex: none;
|
|
115
|
+
align-items: stretch;
|
|
116
|
+
gap: 0.25rem;
|
|
117
|
+
min-width: 0;
|
|
118
|
+
overflow-x: auto;
|
|
119
|
+
scrollbar-width: none;
|
|
120
|
+
}
|
|
121
|
+
.tabs--underline .tabs__list {
|
|
122
|
+
border-bottom: var(--borderThin);
|
|
123
|
+
}
|
|
124
|
+
.tabs--segmented .tabs__list {
|
|
125
|
+
align-self: flex-start;
|
|
126
|
+
gap: 0;
|
|
127
|
+
padding: 0.125rem;
|
|
128
|
+
background: var(--contrastLow);
|
|
129
|
+
border-radius: var(--radius-2);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.tabs__tab {
|
|
133
|
+
display: flex;
|
|
134
|
+
align-items: center;
|
|
135
|
+
flex: none;
|
|
136
|
+
gap: 0.375rem;
|
|
137
|
+
height: 2rem;
|
|
138
|
+
padding: 0 0.625rem;
|
|
139
|
+
font-family: var(--font-sans);
|
|
140
|
+
font-size: 0.875rem;
|
|
141
|
+
font-weight: 500;
|
|
142
|
+
color: var(--fgMuted);
|
|
143
|
+
text-decoration: none;
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
background: transparent;
|
|
146
|
+
border: none;
|
|
147
|
+
cursor: pointer;
|
|
148
|
+
}
|
|
149
|
+
.tabs--sm .tabs__tab {
|
|
150
|
+
height: 1.5rem;
|
|
151
|
+
padding: 0 0.5rem;
|
|
152
|
+
font-size: 0.75rem;
|
|
153
|
+
}
|
|
154
|
+
.tabs__tab:hover {
|
|
155
|
+
color: var(--fg);
|
|
156
|
+
}
|
|
157
|
+
.tabs__tab:focus-visible {
|
|
158
|
+
outline: 2px solid var(--fg);
|
|
159
|
+
outline-offset: -2px;
|
|
160
|
+
}
|
|
161
|
+
.tabs__tab--isSelected {
|
|
162
|
+
color: var(--fg);
|
|
163
|
+
}
|
|
164
|
+
.tabs__tab--isDisabled {
|
|
165
|
+
opacity: 0.5;
|
|
166
|
+
cursor: not-allowed;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.tabs--underline .tabs__tab {
|
|
170
|
+
margin-bottom: -1px;
|
|
171
|
+
border-bottom: 2px solid transparent;
|
|
172
|
+
}
|
|
173
|
+
.tabs--underline .tabs__tab--isSelected {
|
|
174
|
+
border-bottom-color: var(--fgPrimary);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.tabs--segmented .tabs__tab {
|
|
178
|
+
border-radius: var(--radius-1);
|
|
179
|
+
}
|
|
180
|
+
.tabs--segmented .tabs__tab--isSelected {
|
|
181
|
+
background: var(--bg);
|
|
182
|
+
box-shadow: var(--shadow-1);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.tabs__badge {
|
|
186
|
+
min-width: 1.125rem;
|
|
187
|
+
padding: 0 0.3125rem;
|
|
188
|
+
font-family: var(--font-mono);
|
|
189
|
+
font-size: 0.6875rem;
|
|
190
|
+
line-height: 1.125rem;
|
|
191
|
+
text-align: center;
|
|
192
|
+
color: var(--fgMuted);
|
|
193
|
+
background: var(--contrastLow);
|
|
194
|
+
border-radius: 999px;
|
|
195
|
+
}
|
|
196
|
+
.tabs--segmented .tabs__badge {
|
|
197
|
+
background: var(--contrastMedium);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.tabs__panel {
|
|
201
|
+
flex: 1;
|
|
202
|
+
min-height: 0;
|
|
203
|
+
}
|
|
204
|
+
</style>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TabsProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* ## Tabs
|
|
4
|
+
*
|
|
5
|
+
* A row of tabs, one of them selected. With `children` it shows what the selected tab holds;
|
|
6
|
+
* without, it is only the row, for a page that switches something of its own. A tab with an
|
|
7
|
+
* `href` is a link.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```svelte
|
|
11
|
+
* <Tabs
|
|
12
|
+
* tabs={[
|
|
13
|
+
* { id: 'terrain', label: 'Terrain' },
|
|
14
|
+
* { id: 'hexsides', label: 'Hexsides', badge: 12 }
|
|
15
|
+
* ]}
|
|
16
|
+
* bind:selected
|
|
17
|
+
* >
|
|
18
|
+
* {#snippet children({ selected })}
|
|
19
|
+
* {#if selected === 'terrain'}…{/if}
|
|
20
|
+
* {/snippet}
|
|
21
|
+
* </Tabs>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare const Tabs: import("svelte").Component<TabsProps, {}, "selected">;
|
|
25
|
+
type Tabs = ReturnType<typeof Tabs>;
|
|
26
|
+
export default Tabs;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
export type Tab = {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** A Tabler icon component, shown before the label. */
|
|
7
|
+
icon?: any;
|
|
8
|
+
/** Makes the tab a link: choosing it goes there, and the page it leads to says which tab is selected. */
|
|
9
|
+
href?: string;
|
|
10
|
+
/** A small count or note after the label. */
|
|
11
|
+
badge?: string | number;
|
|
12
|
+
isDisabled?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type TabsProps = {
|
|
15
|
+
tabs: Tab[];
|
|
16
|
+
/** The id of the tab that is selected. */
|
|
17
|
+
selected: string;
|
|
18
|
+
onSelectedChange?: (selected: string) => void;
|
|
19
|
+
variant?: 'underline' | 'segmented';
|
|
20
|
+
size?: 'sm' | 'md';
|
|
21
|
+
/** What the selected tab shows. Left out, the tabs are a row to switch with and nothing more. */
|
|
22
|
+
children?: Snippet<[{
|
|
23
|
+
selected: string;
|
|
24
|
+
}]>;
|
|
25
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './Autocomplete';
|
|
1
2
|
export * from './Avatar';
|
|
2
3
|
export * from './BrushSizeSlider';
|
|
3
4
|
export * from './Button';
|
|
@@ -6,6 +7,7 @@ export * from './CodeBlock';
|
|
|
6
7
|
export * from './ColorMode';
|
|
7
8
|
export * from './ColorPicker';
|
|
8
9
|
export * from './ContextMenu';
|
|
10
|
+
export * from './Dialog';
|
|
9
11
|
export * from './Editor';
|
|
10
12
|
export * from './FogSliders';
|
|
11
13
|
export * from './Hr';
|
|
@@ -15,12 +17,14 @@ export * from './Link';
|
|
|
15
17
|
export * from './Loading';
|
|
16
18
|
export * from './Logo';
|
|
17
19
|
export * from './Menu';
|
|
20
|
+
export * from './NumberInput';
|
|
18
21
|
export * from './Panel';
|
|
19
22
|
export * from './PersistButton';
|
|
20
23
|
export * from './Popover';
|
|
21
24
|
export * from './Select';
|
|
22
25
|
export * from './Spacer';
|
|
23
26
|
export * from './Table';
|
|
27
|
+
export * from './Tabs';
|
|
24
28
|
export * from './Text';
|
|
25
29
|
export * from './TextHighlight';
|
|
26
30
|
export * from './Title';
|
package/dist/components/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './Autocomplete';
|
|
1
2
|
export * from './Avatar';
|
|
2
3
|
export * from './BrushSizeSlider';
|
|
3
4
|
export * from './Button';
|
|
@@ -6,6 +7,7 @@ export * from './CodeBlock';
|
|
|
6
7
|
export * from './ColorMode';
|
|
7
8
|
export * from './ColorPicker';
|
|
8
9
|
export * from './ContextMenu';
|
|
10
|
+
export * from './Dialog';
|
|
9
11
|
export * from './Editor';
|
|
10
12
|
export * from './FogSliders';
|
|
11
13
|
export * from './Hr';
|
|
@@ -15,12 +17,14 @@ export * from './Link';
|
|
|
15
17
|
export * from './Loading';
|
|
16
18
|
export * from './Logo';
|
|
17
19
|
export * from './Menu';
|
|
20
|
+
export * from './NumberInput';
|
|
18
21
|
export * from './Panel';
|
|
19
22
|
export * from './PersistButton';
|
|
20
23
|
export * from './Popover';
|
|
21
24
|
export * from './Select';
|
|
22
25
|
export * from './Spacer';
|
|
23
26
|
export * from './Table';
|
|
27
|
+
export * from './Tabs';
|
|
24
28
|
export * from './Text';
|
|
25
29
|
export * from './TextHighlight';
|
|
26
30
|
export * from './Title';
|