@dawn-studio/astryx-svelte 0.0.0-stage → 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 +201 -0
- package/NOTICE +35 -0
- package/README.md +147 -2
- package/dist/themes/dawn.css +770 -0
- package/dist/themes/neutral.css +752 -0
- package/package.json +1 -6
- package/src/Button.svelte +168 -0
- package/src/Card.svelte +48 -0
- package/src/Dialog.svelte +177 -0
- package/src/Switch.svelte +146 -0
- package/src/Tabs.svelte +168 -0
- package/src/TextInput.svelte +208 -0
- package/src/Theme.svelte +40 -0
- package/src/index.ts +8 -0
package/src/Tabs.svelte
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
// Astryx TabList/Tab (spec: TabList.doc.mjs in @astryxdesign/core),
|
|
5
|
+
// WAI-ARIA tabs pattern: roving tabindex, automatic activation,
|
|
6
|
+
// ArrowLeft/ArrowRight/Home/End keyboard navigation.
|
|
7
|
+
export interface TabItem {
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
tabs,
|
|
15
|
+
value = $bindable(''),
|
|
16
|
+
onChange,
|
|
17
|
+
class: className = '',
|
|
18
|
+
panel,
|
|
19
|
+
}: {
|
|
20
|
+
tabs: TabItem[];
|
|
21
|
+
value?: string;
|
|
22
|
+
onChange?: (value: string) => void;
|
|
23
|
+
class?: string;
|
|
24
|
+
panel?: Snippet<[{ value: string }]>;
|
|
25
|
+
} = $props();
|
|
26
|
+
|
|
27
|
+
const uid = $props.id();
|
|
28
|
+
let focusedValue = $state('');
|
|
29
|
+
const activeValue = $derived(tabs.some((t) => t.value === value) ? value : (tabs[0]?.value ?? ''));
|
|
30
|
+
const rovingValue = $derived(focusedValue || activeValue);
|
|
31
|
+
|
|
32
|
+
let tabEls = $state<HTMLButtonElement[]>([]);
|
|
33
|
+
|
|
34
|
+
function select(next: string, focus = false) {
|
|
35
|
+
const tab = tabs.find((t) => t.value === next);
|
|
36
|
+
if (!tab || tab.disabled) return;
|
|
37
|
+
focusedValue = next;
|
|
38
|
+
if (value !== next) {
|
|
39
|
+
value = next;
|
|
40
|
+
onChange?.(next);
|
|
41
|
+
}
|
|
42
|
+
if (focus) {
|
|
43
|
+
const idx = tabs.findIndex((t) => t.value === next);
|
|
44
|
+
tabEls[idx]?.focus();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
49
|
+
const enabled = tabs.filter((t) => !t.disabled);
|
|
50
|
+
if (enabled.length === 0) return;
|
|
51
|
+
const currentIdx = enabled.findIndex((t) => t.value === rovingValue);
|
|
52
|
+
let next: TabItem | undefined;
|
|
53
|
+
switch (e.key) {
|
|
54
|
+
case 'ArrowRight':
|
|
55
|
+
next = enabled[(currentIdx + 1) % enabled.length];
|
|
56
|
+
break;
|
|
57
|
+
case 'ArrowLeft':
|
|
58
|
+
next = enabled[(currentIdx - 1 + enabled.length) % enabled.length];
|
|
59
|
+
break;
|
|
60
|
+
case 'Home':
|
|
61
|
+
next = enabled[0];
|
|
62
|
+
break;
|
|
63
|
+
case 'End':
|
|
64
|
+
next = enabled[enabled.length - 1];
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
if (next) select(next.value, true);
|
|
71
|
+
}
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<div class="ax-tabs {className}">
|
|
75
|
+
<div class="ax-tabs__list" role="tablist" onkeydown={handleKeydown}>
|
|
76
|
+
{#each tabs as tab, i (tab.value)}
|
|
77
|
+
<button
|
|
78
|
+
bind:this={tabEls[i]}
|
|
79
|
+
type="button"
|
|
80
|
+
role="tab"
|
|
81
|
+
id="{uid}-tab-{tab.value}"
|
|
82
|
+
class="ax-tabs__tab"
|
|
83
|
+
class:ax-tabs__tab--active={tab.value === activeValue}
|
|
84
|
+
aria-selected={tab.value === activeValue}
|
|
85
|
+
aria-controls="{uid}-panel-{tab.value}"
|
|
86
|
+
tabindex={tab.value === rovingValue && !tab.disabled ? 0 : -1}
|
|
87
|
+
disabled={tab.disabled}
|
|
88
|
+
onclick={() => select(tab.value)}
|
|
89
|
+
onfocus={() => (focusedValue = tab.value)}
|
|
90
|
+
>
|
|
91
|
+
<span class="ax-tabs__label">{tab.label}</span>
|
|
92
|
+
</button>
|
|
93
|
+
{/each}
|
|
94
|
+
</div>
|
|
95
|
+
{#if panel}
|
|
96
|
+
<div
|
|
97
|
+
role="tabpanel"
|
|
98
|
+
id="{uid}-panel-{activeValue}"
|
|
99
|
+
aria-labelledby="{uid}-tab-{activeValue}"
|
|
100
|
+
tabindex="0"
|
|
101
|
+
class="ax-tabs__panel"
|
|
102
|
+
>
|
|
103
|
+
{@render panel({ value: activeValue })}
|
|
104
|
+
</div>
|
|
105
|
+
{/if}
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<style>
|
|
109
|
+
/* NO STRETCH: the strip is a fixed-height row; labels clamp with
|
|
110
|
+
ellipsis inside min-width:0 tabs instead of widening the strip. */
|
|
111
|
+
.ax-tabs {
|
|
112
|
+
min-width: 0;
|
|
113
|
+
font-family: var(--font-family-body);
|
|
114
|
+
}
|
|
115
|
+
.ax-tabs__list {
|
|
116
|
+
display: flex;
|
|
117
|
+
gap: 0.25rem;
|
|
118
|
+
border-bottom: 1px solid var(--color-border);
|
|
119
|
+
overflow-x: auto;
|
|
120
|
+
scrollbar-width: none;
|
|
121
|
+
}
|
|
122
|
+
.ax-tabs__tab {
|
|
123
|
+
flex: none;
|
|
124
|
+
min-width: 0;
|
|
125
|
+
max-width: 12rem;
|
|
126
|
+
height: 2.75rem;
|
|
127
|
+
padding-inline: 1rem;
|
|
128
|
+
border: none;
|
|
129
|
+
background: transparent;
|
|
130
|
+
color: var(--color-text-secondary);
|
|
131
|
+
font: inherit;
|
|
132
|
+
font-size: var(--text-label-size, 0.875rem);
|
|
133
|
+
font-weight: var(--text-label-weight, 500);
|
|
134
|
+
cursor: pointer;
|
|
135
|
+
box-shadow: inset 0 -2px 0 transparent;
|
|
136
|
+
}
|
|
137
|
+
.ax-tabs__tab:hover:not(:disabled) {
|
|
138
|
+
color: var(--color-text-primary);
|
|
139
|
+
background: var(--color-overlay-hover);
|
|
140
|
+
}
|
|
141
|
+
.ax-tabs__tab--active {
|
|
142
|
+
color: var(--color-text-primary);
|
|
143
|
+
box-shadow: inset 0 -2px 0 var(--color-accent);
|
|
144
|
+
}
|
|
145
|
+
.ax-tabs__tab:focus-visible {
|
|
146
|
+
outline: 2px solid var(--color-accent);
|
|
147
|
+
outline-offset: -2px;
|
|
148
|
+
}
|
|
149
|
+
.ax-tabs__tab:disabled {
|
|
150
|
+
color: var(--color-text-disabled);
|
|
151
|
+
cursor: not-allowed;
|
|
152
|
+
}
|
|
153
|
+
.ax-tabs__label {
|
|
154
|
+
display: block;
|
|
155
|
+
min-width: 0;
|
|
156
|
+
overflow: hidden;
|
|
157
|
+
text-overflow: ellipsis;
|
|
158
|
+
white-space: nowrap;
|
|
159
|
+
}
|
|
160
|
+
.ax-tabs__panel {
|
|
161
|
+
padding-top: 1rem;
|
|
162
|
+
min-width: 0;
|
|
163
|
+
}
|
|
164
|
+
.ax-tabs__panel:focus-visible {
|
|
165
|
+
outline: 2px solid var(--color-accent);
|
|
166
|
+
outline-offset: 2px;
|
|
167
|
+
}
|
|
168
|
+
</style>
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// Astryx TextInput (spec: TextInput.doc.mjs in @astryxdesign/core).
|
|
3
|
+
// The label is ALWAYS rendered (spec) — isLabelHidden only hides it
|
|
4
|
+
// visually. Enter handling is IME-safe: an Enter that confirms a CJK
|
|
5
|
+
// composition candidate (isComposing / keyCode 229) never fires onEnter.
|
|
6
|
+
let {
|
|
7
|
+
label,
|
|
8
|
+
value = $bindable(''),
|
|
9
|
+
placeholder,
|
|
10
|
+
description,
|
|
11
|
+
error,
|
|
12
|
+
isLabelHidden = false,
|
|
13
|
+
isDisabled = false,
|
|
14
|
+
isReadOnly = false,
|
|
15
|
+
isRequired = false,
|
|
16
|
+
isOptional = false,
|
|
17
|
+
hasClear = false,
|
|
18
|
+
type = 'text',
|
|
19
|
+
name,
|
|
20
|
+
autocomplete,
|
|
21
|
+
onEnter,
|
|
22
|
+
onchange,
|
|
23
|
+
class: className = '',
|
|
24
|
+
}: {
|
|
25
|
+
label: string;
|
|
26
|
+
value?: string;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
error?: string;
|
|
30
|
+
isLabelHidden?: boolean;
|
|
31
|
+
isDisabled?: boolean;
|
|
32
|
+
isReadOnly?: boolean;
|
|
33
|
+
isRequired?: boolean;
|
|
34
|
+
isOptional?: boolean;
|
|
35
|
+
hasClear?: boolean;
|
|
36
|
+
type?: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
autocomplete?: string;
|
|
39
|
+
onEnter?: () => void;
|
|
40
|
+
onchange?: (value: string) => void;
|
|
41
|
+
class?: string;
|
|
42
|
+
} = $props();
|
|
43
|
+
|
|
44
|
+
const uid = $props.id();
|
|
45
|
+
const inputId = `${uid}-input`;
|
|
46
|
+
const descId = `${uid}-desc`;
|
|
47
|
+
const errorId = `${uid}-error`;
|
|
48
|
+
const describedBy = $derived(
|
|
49
|
+
[description ? descId : null, error ? errorId : null].filter(Boolean).join(' ') || undefined,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
53
|
+
if (e.key !== 'Enter') return;
|
|
54
|
+
// IME guard: composition-confirming Enter must not submit.
|
|
55
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
56
|
+
onEnter?.();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handleInput(e: Event) {
|
|
60
|
+
value = (e.currentTarget as HTMLInputElement).value;
|
|
61
|
+
onchange?.(value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function clear() {
|
|
65
|
+
value = '';
|
|
66
|
+
onchange?.('');
|
|
67
|
+
}
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<div class="ax-field {className}">
|
|
71
|
+
<label class="ax-field__label" class:ax-visually-hidden={isLabelHidden} for={inputId}>
|
|
72
|
+
{label}
|
|
73
|
+
{#if isOptional}<span class="ax-field__optional">(optional)</span>{/if}
|
|
74
|
+
</label>
|
|
75
|
+
|
|
76
|
+
<div class="ax-field__control">
|
|
77
|
+
<input
|
|
78
|
+
id={inputId}
|
|
79
|
+
class="ax-field__input"
|
|
80
|
+
class:ax-field__input--error={!!error}
|
|
81
|
+
{type}
|
|
82
|
+
{name}
|
|
83
|
+
{autocomplete}
|
|
84
|
+
{placeholder}
|
|
85
|
+
{value}
|
|
86
|
+
disabled={isDisabled}
|
|
87
|
+
readonly={isReadOnly}
|
|
88
|
+
required={isRequired}
|
|
89
|
+
aria-invalid={error ? true : undefined}
|
|
90
|
+
aria-describedby={describedBy}
|
|
91
|
+
oninput={handleInput}
|
|
92
|
+
onkeydown={handleKeydown}
|
|
93
|
+
/>
|
|
94
|
+
{#if hasClear && value && !isDisabled && !isReadOnly}
|
|
95
|
+
<button type="button" class="ax-field__clear" aria-label="Clear" onclick={clear}>×</button>
|
|
96
|
+
{/if}
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
{#if description}
|
|
100
|
+
<p class="ax-field__description" id={descId}>{description}</p>
|
|
101
|
+
{/if}
|
|
102
|
+
{#if error}
|
|
103
|
+
<p class="ax-field__error" id={errorId} role="alert">{error}</p>
|
|
104
|
+
{/if}
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<style>
|
|
108
|
+
/* NO STRETCH: the field is a fluid column capped at 100%; the input's
|
|
109
|
+
height is fixed and its text scrolls inside, never resizing the field. */
|
|
110
|
+
.ax-field {
|
|
111
|
+
display: flex;
|
|
112
|
+
flex-direction: column;
|
|
113
|
+
gap: 0.375rem;
|
|
114
|
+
width: 100%;
|
|
115
|
+
max-width: 100%;
|
|
116
|
+
min-width: 0;
|
|
117
|
+
font-family: var(--font-family-body);
|
|
118
|
+
}
|
|
119
|
+
.ax-field__label {
|
|
120
|
+
font-size: var(--text-label-size, 0.875rem);
|
|
121
|
+
font-weight: var(--text-label-weight, 500);
|
|
122
|
+
line-height: var(--text-label-leading, 1.4286);
|
|
123
|
+
color: var(--color-text-primary);
|
|
124
|
+
}
|
|
125
|
+
.ax-field__optional {
|
|
126
|
+
color: var(--color-text-secondary);
|
|
127
|
+
font-weight: 400;
|
|
128
|
+
}
|
|
129
|
+
.ax-field__control {
|
|
130
|
+
position: relative;
|
|
131
|
+
display: flex;
|
|
132
|
+
min-width: 0;
|
|
133
|
+
}
|
|
134
|
+
.ax-field__input {
|
|
135
|
+
flex: 1;
|
|
136
|
+
min-width: 0;
|
|
137
|
+
width: 100%;
|
|
138
|
+
height: 2.75rem;
|
|
139
|
+
padding-inline: 0.75rem;
|
|
140
|
+
background: var(--color-background-surface);
|
|
141
|
+
border: 1px solid var(--color-border);
|
|
142
|
+
border-radius: var(--radius-element, 0.5rem);
|
|
143
|
+
color: var(--color-text-primary);
|
|
144
|
+
font: inherit;
|
|
145
|
+
font-size: var(--text-body-size, 0.875rem);
|
|
146
|
+
}
|
|
147
|
+
.ax-field__input::placeholder {
|
|
148
|
+
color: var(--color-text-secondary);
|
|
149
|
+
}
|
|
150
|
+
.ax-field__input:hover:not(:disabled) {
|
|
151
|
+
border-color: var(--color-border-emphasized);
|
|
152
|
+
}
|
|
153
|
+
.ax-field__input:focus {
|
|
154
|
+
outline: 2px solid var(--color-accent);
|
|
155
|
+
outline-offset: -1px;
|
|
156
|
+
border-color: var(--color-accent);
|
|
157
|
+
}
|
|
158
|
+
.ax-field__input--error {
|
|
159
|
+
border-color: var(--color-border-error);
|
|
160
|
+
}
|
|
161
|
+
.ax-field__input--error:focus {
|
|
162
|
+
outline-color: var(--color-error);
|
|
163
|
+
border-color: var(--color-border-error);
|
|
164
|
+
}
|
|
165
|
+
.ax-field__input:disabled {
|
|
166
|
+
color: var(--color-text-disabled);
|
|
167
|
+
background: var(--color-background-muted);
|
|
168
|
+
cursor: not-allowed;
|
|
169
|
+
}
|
|
170
|
+
.ax-field__clear {
|
|
171
|
+
position: absolute;
|
|
172
|
+
inset-inline-end: 0.375rem;
|
|
173
|
+
top: 50%;
|
|
174
|
+
translate: 0 -50%;
|
|
175
|
+
width: 2rem;
|
|
176
|
+
height: 2rem;
|
|
177
|
+
border: none;
|
|
178
|
+
border-radius: var(--radius-full, 999px);
|
|
179
|
+
background: transparent;
|
|
180
|
+
color: var(--color-icon-secondary);
|
|
181
|
+
font-size: 1.125rem;
|
|
182
|
+
line-height: 1;
|
|
183
|
+
cursor: pointer;
|
|
184
|
+
}
|
|
185
|
+
.ax-field__clear:hover {
|
|
186
|
+
background: var(--color-overlay-hover);
|
|
187
|
+
}
|
|
188
|
+
.ax-field__description {
|
|
189
|
+
margin: 0;
|
|
190
|
+
font-size: var(--text-supporting-size, 0.8125rem);
|
|
191
|
+
line-height: var(--text-supporting-leading, 1.4);
|
|
192
|
+
color: var(--color-text-secondary);
|
|
193
|
+
}
|
|
194
|
+
.ax-field__error {
|
|
195
|
+
margin: 0;
|
|
196
|
+
font-size: var(--text-supporting-size, 0.8125rem);
|
|
197
|
+
line-height: var(--text-supporting-leading, 1.4);
|
|
198
|
+
color: var(--color-error);
|
|
199
|
+
}
|
|
200
|
+
.ax-visually-hidden {
|
|
201
|
+
position: absolute;
|
|
202
|
+
width: 1px;
|
|
203
|
+
height: 1px;
|
|
204
|
+
overflow: hidden;
|
|
205
|
+
clip-path: inset(50%);
|
|
206
|
+
white-space: nowrap;
|
|
207
|
+
}
|
|
208
|
+
</style>
|
package/src/Theme.svelte
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
// Scope element for the Astryx token CSS. The theme stylesheets
|
|
5
|
+
// (@dawn-studio/astryx-svelte/themes/dawn.css | neutral.css) define every
|
|
6
|
+
// semantic token under [data-astryx-theme]; `mode` drives the CSS
|
|
7
|
+
// light-dark() token values via color-scheme. Dawn default: dark (§5).
|
|
8
|
+
let {
|
|
9
|
+
theme = 'dawn',
|
|
10
|
+
mode = 'dark',
|
|
11
|
+
class: className = '',
|
|
12
|
+
children,
|
|
13
|
+
}: {
|
|
14
|
+
theme?: 'dawn' | 'neutral';
|
|
15
|
+
mode?: 'dark' | 'light';
|
|
16
|
+
class?: string;
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
} = $props();
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<div data-astryx-theme={theme} data-theme={mode} class="ax-theme {className}">
|
|
22
|
+
{@render children?.()}
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<style>
|
|
26
|
+
.ax-theme {
|
|
27
|
+
color-scheme: light;
|
|
28
|
+
background: var(--color-background-body);
|
|
29
|
+
color: var(--color-text-primary);
|
|
30
|
+
font-family: var(--font-family-body);
|
|
31
|
+
font-size: var(--text-body-size);
|
|
32
|
+
line-height: var(--text-body-leading);
|
|
33
|
+
}
|
|
34
|
+
.ax-theme[data-theme='dark'] {
|
|
35
|
+
color-scheme: dark;
|
|
36
|
+
}
|
|
37
|
+
.ax-theme[data-theme='light'] {
|
|
38
|
+
color-scheme: light;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as Theme } from './Theme.svelte';
|
|
2
|
+
export { default as Button } from './Button.svelte';
|
|
3
|
+
export { default as TextInput } from './TextInput.svelte';
|
|
4
|
+
export { default as Card } from './Card.svelte';
|
|
5
|
+
export { default as Dialog } from './Dialog.svelte';
|
|
6
|
+
export { default as Tabs } from './Tabs.svelte';
|
|
7
|
+
export type { TabItem } from './Tabs.svelte';
|
|
8
|
+
export { default as Switch } from './Switch.svelte';
|