@conalog/ds-svelte 0.0.0-stage → 1.0.0-alpha.1
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 +21 -0
- package/README.md +6 -2
- package/SUPPORT.json +366 -0
- package/dist/ActionButton.svelte +11 -0
- package/dist/Badge.svelte +49 -0
- package/dist/Button.svelte +107 -0
- package/dist/Card.svelte +76 -0
- package/dist/Checkbox.svelte +60 -0
- package/dist/Chip.svelte +133 -0
- package/dist/CircularSpinner.svelte +30 -0
- package/dist/Divider.svelte +29 -0
- package/dist/DsTheme.svelte +14 -0
- package/dist/IconButton.svelte +7 -0
- package/dist/Menu.svelte +277 -0
- package/dist/Modal.svelte +86 -0
- package/dist/Navigation.svelte +87 -0
- package/dist/PageHeader.svelte +81 -0
- package/dist/ScopePicker.svelte +271 -0
- package/dist/SearchField.svelte +7 -0
- package/dist/SegmentedControl.svelte +154 -0
- package/dist/StatusBanner.svelte +48 -0
- package/dist/Table.svelte +180 -0
- package/dist/Tabs.svelte +121 -0
- package/dist/TextField.svelte +122 -0
- package/dist/Tooltip.svelte +147 -0
- package/dist/button-options.mjs +1 -0
- package/dist/button.css +514 -0
- package/dist/display.css +47 -0
- package/dist/draft-overlay.mjs +67 -0
- package/dist/draft.css +248 -0
- package/dist/icon-provenance.json +62 -0
- package/dist/icons/check/filled.d.mts +3 -0
- package/dist/icons/check/filled.mjs +1 -0
- package/dist/icons/check/filled.svelte +10 -0
- package/dist/icons/check.d.mts +1 -0
- package/dist/icons/check.mjs +1 -0
- package/dist/icons/headset/filled.d.mts +3 -0
- package/dist/icons/headset/filled.mjs +1 -0
- package/dist/icons/headset/filled.svelte +10 -0
- package/dist/icons/headset.d.mts +1 -0
- package/dist/icons/headset.mjs +1 -0
- package/dist/icons/notification-bell/filled.d.mts +3 -0
- package/dist/icons/notification-bell/filled.mjs +1 -0
- package/dist/icons/notification-bell/filled.svelte +10 -0
- package/dist/icons/notification-bell-off/filled.d.mts +3 -0
- package/dist/icons/notification-bell-off/filled.mjs +1 -0
- package/dist/icons/notification-bell-off/filled.svelte +10 -0
- package/dist/icons/notification-bell-off.d.mts +1 -0
- package/dist/icons/notification-bell-off.mjs +1 -0
- package/dist/icons/notification-bell.d.mts +1 -0
- package/dist/icons/notification-bell.mjs +1 -0
- package/dist/icons/plant/filled.d.mts +3 -0
- package/dist/icons/plant/filled.mjs +1 -0
- package/dist/icons/plant/filled.svelte +13 -0
- package/dist/icons/plant.d.mts +1 -0
- package/dist/icons/plant.mjs +1 -0
- package/dist/icons/search/outlined.d.mts +3 -0
- package/dist/icons/search/outlined.mjs +1 -0
- package/dist/icons/search/outlined.svelte +10 -0
- package/dist/icons/search.d.mts +1 -0
- package/dist/icons/search.mjs +1 -0
- package/dist/icons.d.mts +6 -0
- package/dist/icons.mjs +6 -0
- package/dist/index.d.ts +269 -0
- package/dist/index.mjs +21 -0
- package/dist/licenses/check/filled.txt +202 -0
- package/dist/licenses/headset/filled.txt +21 -0
- package/dist/licenses/notification-bell/filled.txt +21 -0
- package/dist/licenses/notification-bell-off/filled.txt +21 -0
- package/dist/licenses/plant/filled.txt +24 -0
- package/dist/licenses/search/outlined.txt +21 -0
- package/package.json +58 -4
- package/release-source.json +5 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import './draft.css';
|
|
3
|
+
|
|
4
|
+
const id = $props.id();
|
|
5
|
+
let { mode = 'data', label, caption, size = 'md', columns = [], rows, cell, badges } = $props();
|
|
6
|
+
|
|
7
|
+
function value(text) {
|
|
8
|
+
return text === undefined || text === null || text === '' ? '—' : text;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function watchOverflow(region) {
|
|
12
|
+
const table = region.querySelector('table');
|
|
13
|
+
function update() {
|
|
14
|
+
if (region.scrollWidth > region.clientWidth || region.scrollHeight > region.clientHeight) {
|
|
15
|
+
region.tabIndex = 0;
|
|
16
|
+
} else {
|
|
17
|
+
region.removeAttribute('tabindex');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
update();
|
|
21
|
+
const observer = new ResizeObserver(update);
|
|
22
|
+
observer.observe(region);
|
|
23
|
+
if (table) observer.observe(table);
|
|
24
|
+
return () => observer.disconnect();
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<div data-ds-component="table" class={{ compact: size === 'sm' }}>
|
|
29
|
+
{#if mode === 'data'}
|
|
30
|
+
<div class="data" role="region" aria-labelledby={caption ? id : undefined}
|
|
31
|
+
aria-label={caption ? undefined : label} {@attach watchOverflow}>
|
|
32
|
+
<table aria-label={caption ? undefined : label}>
|
|
33
|
+
{#if caption}<caption id={id}>{caption}</caption>{/if}
|
|
34
|
+
<thead>
|
|
35
|
+
<tr>
|
|
36
|
+
{#each columns as column (column.id)}
|
|
37
|
+
<th scope="col" class={{ numeric: column.numeric }}>{column.label}</th>
|
|
38
|
+
{/each}
|
|
39
|
+
</tr>
|
|
40
|
+
</thead>
|
|
41
|
+
<tbody>
|
|
42
|
+
{#each rows as row (row.id)}
|
|
43
|
+
<tr class={{ linked: row.href }}>
|
|
44
|
+
{#each columns as column, index (column.id)}
|
|
45
|
+
<svelte:element this={column.rowHeader ? 'th' : 'td'} scope={column.rowHeader ? 'row' : undefined}
|
|
46
|
+
class={{ numeric: column.numeric }}>
|
|
47
|
+
{#if row.href && index === 0}
|
|
48
|
+
<a href={row.href}>{value(row.cells?.[column.id])}<span class="arrow" aria-hidden="true"></span></a>
|
|
49
|
+
{:else if cell}
|
|
50
|
+
{@render cell(row, column)}
|
|
51
|
+
{:else}
|
|
52
|
+
{value(row.cells?.[column.id])}
|
|
53
|
+
{/if}
|
|
54
|
+
</svelte:element>
|
|
55
|
+
{/each}
|
|
56
|
+
</tr>
|
|
57
|
+
{/each}
|
|
58
|
+
</tbody>
|
|
59
|
+
</table>
|
|
60
|
+
</div>
|
|
61
|
+
{:else if mode === 'property'}
|
|
62
|
+
<dl aria-label={label}>
|
|
63
|
+
{#each rows as row (row.id)}
|
|
64
|
+
<div class={['property', { linked: row.href }]}>
|
|
65
|
+
<dt>{value(row.label)}</dt>
|
|
66
|
+
<dd>
|
|
67
|
+
{#if row.href}
|
|
68
|
+
<a href={row.href}>{value(row.value)}<span class="arrow" aria-hidden="true"></span></a>
|
|
69
|
+
{:else}
|
|
70
|
+
{value(row.value)}
|
|
71
|
+
{/if}
|
|
72
|
+
</dd>
|
|
73
|
+
</div>
|
|
74
|
+
{/each}
|
|
75
|
+
</dl>
|
|
76
|
+
{:else}
|
|
77
|
+
<ul aria-label={label}>
|
|
78
|
+
{#each rows as row (row.id)}
|
|
79
|
+
<li class={['entry', { linked: row.href }]}>
|
|
80
|
+
<div class="line">
|
|
81
|
+
{#if row.href}
|
|
82
|
+
<a href={row.href} class="title">{value(row.title)}<span class="arrow" aria-hidden="true"></span></a>
|
|
83
|
+
{:else}
|
|
84
|
+
<span class="title">{value(row.title)}</span>
|
|
85
|
+
{/if}
|
|
86
|
+
{#if badges}<span class="badges">{@render badges(row)}</span>{/if}
|
|
87
|
+
</div>
|
|
88
|
+
{#if row.description || row.meta}
|
|
89
|
+
<div class="line muted">
|
|
90
|
+
<span>{row.description ?? ''}</span>
|
|
91
|
+
<span>{row.meta ?? ''}</span>
|
|
92
|
+
</div>
|
|
93
|
+
{/if}
|
|
94
|
+
</li>
|
|
95
|
+
{/each}
|
|
96
|
+
</ul>
|
|
97
|
+
{/if}
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<style>
|
|
101
|
+
[data-ds-component="table"] {
|
|
102
|
+
--data-height: var(--ds-draft-dimension-x10);
|
|
103
|
+
--property-height: var(--ds-draft-dimension-x10);
|
|
104
|
+
--head-height: var(--ds-draft-dimension-x8);
|
|
105
|
+
--head-padding: var(--ds-draft-dimension-x1-5);
|
|
106
|
+
--property-gap: var(--ds-draft-dimension-x2);
|
|
107
|
+
color: var(--ds-draft-fg-neutral);
|
|
108
|
+
font: var(--ds-draft-type-body-font-weight) var(--ds-draft-type-body-font-size) / var(--ds-draft-type-body-line-height) var(--ds-draft-type-body-font-family);
|
|
109
|
+
}
|
|
110
|
+
.compact {
|
|
111
|
+
--data-height: var(--ds-draft-dimension-x8);
|
|
112
|
+
--property-height: var(--ds-draft-dimension-x8);
|
|
113
|
+
--head-height: var(--ds-draft-dimension-x7);
|
|
114
|
+
--head-padding: var(--ds-draft-dimension-x1);
|
|
115
|
+
--property-gap: var(--ds-draft-dimension-x1);
|
|
116
|
+
}
|
|
117
|
+
.data {
|
|
118
|
+
overflow: auto;
|
|
119
|
+
max-inline-size: 100%;
|
|
120
|
+
padding: var(--ds-draft-spacing-card-edge) var(--ds-draft-spacing-card-edge) var(--ds-draft-dimension-x2);
|
|
121
|
+
}
|
|
122
|
+
.data:focus-visible, .linked:focus-within { outline: 2px solid var(--ds-draft-stroke-neutral-focused); outline-offset: -2px; border-radius: var(--ds-draft-radius-r1-5); }
|
|
123
|
+
table { inline-size: 100%; border-collapse: collapse; }
|
|
124
|
+
caption {
|
|
125
|
+
caption-side: bottom;
|
|
126
|
+
padding-block-start: var(--ds-draft-dimension-x2);
|
|
127
|
+
text-align: start;
|
|
128
|
+
color: var(--ds-draft-fg-neutral-muted);
|
|
129
|
+
font: var(--ds-draft-type-sub-font-weight) var(--ds-draft-type-sub-font-size) / var(--ds-draft-type-sub-line-height) var(--ds-draft-type-sub-font-family);
|
|
130
|
+
}
|
|
131
|
+
td, th { text-align: start; white-space: nowrap; }
|
|
132
|
+
:is(td, th):not(:last-child) { padding-inline-end: var(--ds-draft-dimension-x4); }
|
|
133
|
+
thead th {
|
|
134
|
+
block-size: var(--head-height);
|
|
135
|
+
vertical-align: bottom;
|
|
136
|
+
padding-block-end: var(--head-padding);
|
|
137
|
+
box-sizing: border-box;
|
|
138
|
+
border-block-end: 1px solid var(--ds-draft-stroke-neutral);
|
|
139
|
+
color: var(--ds-draft-fg-neutral-muted);
|
|
140
|
+
font: var(--ds-draft-type-meta-font-weight) var(--ds-draft-type-meta-font-size) / var(--ds-draft-type-meta-line-height) var(--ds-draft-type-meta-font-family);
|
|
141
|
+
}
|
|
142
|
+
tbody :is(td, th) {
|
|
143
|
+
block-size: var(--data-height);
|
|
144
|
+
border-block-end: 1px solid var(--ds-draft-stroke-neutral-weak);
|
|
145
|
+
font-weight: inherit;
|
|
146
|
+
}
|
|
147
|
+
:is(td, th).numeric { text-align: end; font-variant-numeric: tabular-nums; }
|
|
148
|
+
dl, ul { margin: 0; padding: 0 var(--ds-draft-spacing-card-edge); list-style: none; }
|
|
149
|
+
.property, .entry { border-block-end: 1px solid var(--ds-draft-stroke-neutral-weak); }
|
|
150
|
+
.property {
|
|
151
|
+
display: flex;
|
|
152
|
+
align-items: center;
|
|
153
|
+
gap: var(--property-gap);
|
|
154
|
+
min-block-size: var(--property-height);
|
|
155
|
+
}
|
|
156
|
+
dt { color: var(--ds-draft-fg-neutral-muted); }
|
|
157
|
+
.compact dt { font-size: var(--ds-draft-type-sub-font-size); }
|
|
158
|
+
dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
159
|
+
.entry { padding-block: var(--ds-draft-dimension-x3); }
|
|
160
|
+
.line {
|
|
161
|
+
display: flex;
|
|
162
|
+
justify-content: space-between;
|
|
163
|
+
align-items: center;
|
|
164
|
+
gap: var(--ds-draft-dimension-x4);
|
|
165
|
+
}
|
|
166
|
+
.line + .line { margin-block-start: var(--ds-draft-dimension-x1); }
|
|
167
|
+
.title { font-weight: var(--ds-draft-type-title-font-weight); }
|
|
168
|
+
.muted { color: var(--ds-draft-fg-neutral-muted); font-size: var(--ds-draft-type-sub-font-size); }
|
|
169
|
+
.badges { display: flex; align-items: center; gap: var(--ds-draft-dimension-x1); }
|
|
170
|
+
a { display: inline-flex; align-items: center; gap: var(--ds-draft-dimension-x2); color: inherit; }
|
|
171
|
+
.linked:hover { background: var(--ds-draft-bg-layer-default-pressed); }
|
|
172
|
+
.arrow {
|
|
173
|
+
inline-size: var(--ds-draft-dimension-x1-5);
|
|
174
|
+
aspect-ratio: 1;
|
|
175
|
+
border: solid currentColor;
|
|
176
|
+
border-width: 0 1.5px 1.5px 0;
|
|
177
|
+
transform: rotate(-45deg);
|
|
178
|
+
}
|
|
179
|
+
.arrow:dir(rtl) { transform: rotate(45deg); }
|
|
180
|
+
</style>
|
package/dist/Tabs.svelte
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import './display.css';
|
|
3
|
+
|
|
4
|
+
const id = $props.id();
|
|
5
|
+
let { label, items, selected = $bindable(), size = 'md', onchange } = $props();
|
|
6
|
+
let options = $derived.by(() => {
|
|
7
|
+
if (typeof label !== 'string' || !label.trim()) throw new TypeError('Tabs require an accessible name');
|
|
8
|
+
if (!['sm', 'md'].includes(size)) throw new RangeError('Invalid Tab size');
|
|
9
|
+
if (!Array.isArray(items) || new Set(items.map(item => item.id)).size !== items.length ||
|
|
10
|
+
items.some(item => typeof item.id !== 'string' || !item.id.trim() ||
|
|
11
|
+
typeof item.label !== 'string' || !item.label.trim() || typeof item.content !== 'function')) {
|
|
12
|
+
throw new TypeError('Tabs require unique IDs, labels and content snippets');
|
|
13
|
+
}
|
|
14
|
+
return items;
|
|
15
|
+
});
|
|
16
|
+
let active = $derived(options.findIndex(item => item.id === selected && !item.disabled));
|
|
17
|
+
let activeIndex = $derived(active >= 0 ? active : options.findIndex(item => !item.disabled));
|
|
18
|
+
|
|
19
|
+
function activate(index) {
|
|
20
|
+
const item = options[index];
|
|
21
|
+
if (!item || item.disabled || selected === item.id) return;
|
|
22
|
+
selected = item.id;
|
|
23
|
+
onchange?.(item.id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function navigate(event, index) {
|
|
27
|
+
const row = event.currentTarget.parentElement;
|
|
28
|
+
const direction = getComputedStyle(row).direction === 'rtl' ? -1 : 1;
|
|
29
|
+
const enabled = options.flatMap((item, position) => item.disabled ? [] : [position]);
|
|
30
|
+
if (!enabled.length) return;
|
|
31
|
+
const current = enabled.indexOf(index);
|
|
32
|
+
let next;
|
|
33
|
+
switch (event.key) {
|
|
34
|
+
case 'Home': next = enabled[0]; break;
|
|
35
|
+
case 'End': next = enabled.at(-1); break;
|
|
36
|
+
case 'ArrowLeft': next = enabled[(current - direction + enabled.length) % enabled.length]; break;
|
|
37
|
+
case 'ArrowRight': next = enabled[(current + direction + enabled.length) % enabled.length]; break;
|
|
38
|
+
default: return;
|
|
39
|
+
}
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
activate(next);
|
|
42
|
+
row.children[next]?.focus();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function trackIndicator(rail, index, displayedItems) {
|
|
46
|
+
const labels = displayedItems.map((_, position) => rail.children[position].firstElementChild);
|
|
47
|
+
const activeLabel = labels[index];
|
|
48
|
+
function measure() {
|
|
49
|
+
const rect = activeLabel?.getBoundingClientRect();
|
|
50
|
+
const left = rect ? rect.left - rail.getBoundingClientRect().left : 0;
|
|
51
|
+
rail.style.setProperty('--indicator-width', (rect?.width ?? 0) + 'px');
|
|
52
|
+
rail.style.setProperty('--indicator-left', left + 'px');
|
|
53
|
+
}
|
|
54
|
+
measure();
|
|
55
|
+
const observer = new ResizeObserver(measure);
|
|
56
|
+
observer.observe(rail);
|
|
57
|
+
for (const span of labels) observer.observe(span);
|
|
58
|
+
return () => observer.disconnect();
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<div data-ds-component="tab" data-ds-display={'tab-' + size}>
|
|
63
|
+
<div class="scroll">
|
|
64
|
+
<div class="rail" role="tablist" aria-label={label} {@attach rail => trackIndicator(rail, activeIndex, options)}>
|
|
65
|
+
{#each options as item, index (item.id)}
|
|
66
|
+
<button type="button" role="tab" id={id + '-tab-' + index} aria-controls={id + '-panel-' + index}
|
|
67
|
+
aria-selected={index === activeIndex} tabindex={index === activeIndex ? 0 : -1} disabled={item.disabled}
|
|
68
|
+
onclick={() => activate(index)} onkeydown={(event) => navigate(event, index)}>
|
|
69
|
+
<span>{item.label}</span>
|
|
70
|
+
</button>
|
|
71
|
+
{/each}
|
|
72
|
+
<span class="indicator" aria-hidden="true"></span>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
{#each options as item, index (item.id)}
|
|
76
|
+
<div role="tabpanel" id={id + '-panel-' + index} aria-labelledby={id + '-tab-' + index} hidden={index !== activeIndex} tabindex="0">
|
|
77
|
+
{@render item.content()}
|
|
78
|
+
</div>
|
|
79
|
+
{/each}
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<style>
|
|
83
|
+
.scroll { overflow-x: auto; }
|
|
84
|
+
.rail {
|
|
85
|
+
position: relative;
|
|
86
|
+
display: flex;
|
|
87
|
+
inline-size: max-content;
|
|
88
|
+
min-inline-size: 100%;
|
|
89
|
+
box-shadow: inset 0 calc(-1 * var(--ds-display-rail-border-width)) 0 var(--ds-display-rail-border-color);
|
|
90
|
+
}
|
|
91
|
+
button {
|
|
92
|
+
appearance: none;
|
|
93
|
+
background: transparent;
|
|
94
|
+
border: 0;
|
|
95
|
+
border-radius: var(--ds-display-control-border-radius);
|
|
96
|
+
color: var(--ds-display-label-color);
|
|
97
|
+
cursor: pointer;
|
|
98
|
+
font: var(--ds-display-label-font-weight) var(--ds-display-label-font-size)/var(--ds-display-label-line-height) var(--ds-display-label-font-family);
|
|
99
|
+
letter-spacing: var(--ds-display-label-letter-spacing);
|
|
100
|
+
min-block-size: var(--ds-display-control-min-height);
|
|
101
|
+
padding-inline: var(--ds-display-control-padding-inline);
|
|
102
|
+
white-space: nowrap;
|
|
103
|
+
}
|
|
104
|
+
button[aria-selected="true"], button:is(:hover, :active) { color: var(--ds-display-indicator-color); }
|
|
105
|
+
button:focus-visible {
|
|
106
|
+
outline: var(--ds-display-control-outline-width) solid var(--ds-display-control-outline-color);
|
|
107
|
+
outline-offset: calc(-1 * var(--ds-display-control-outline-width));
|
|
108
|
+
}
|
|
109
|
+
button:disabled { color: var(--ds-display-disabled-color); cursor: default; }
|
|
110
|
+
.indicator {
|
|
111
|
+
position: absolute;
|
|
112
|
+
inset-block-end: 0;
|
|
113
|
+
left: var(--indicator-left, 0px);
|
|
114
|
+
inline-size: var(--indicator-width, 0px);
|
|
115
|
+
block-size: var(--ds-display-indicator-height);
|
|
116
|
+
background: var(--ds-display-indicator-color);
|
|
117
|
+
pointer-events: none;
|
|
118
|
+
transition: left 200ms ease-out, inline-size 200ms ease-out;
|
|
119
|
+
}
|
|
120
|
+
@media (prefers-reduced-motion: reduce) { .indicator { transition: none; } }
|
|
121
|
+
</style>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import './display.css';
|
|
3
|
+
|
|
4
|
+
const id = $props.id();
|
|
5
|
+
const detailsId = id + '-details';
|
|
6
|
+
let { label, value = $bindable(''), name, placeholder, help, error, unit, icon: Icon, size = 'md', disabled = false,
|
|
7
|
+
required = false, type = 'text', showLabel = true, clearLabel = '지우기', oninput } = $props();
|
|
8
|
+
let input = $state();
|
|
9
|
+
let styling = $derived.by(() => {
|
|
10
|
+
if (typeof label !== 'string' || !label.trim()) throw new TypeError('Text Field label must contain text');
|
|
11
|
+
if (!['sm', 'md'].includes(size)) throw new RangeError('Invalid Text Field size');
|
|
12
|
+
if (!['text', 'search'].includes(type)) throw new RangeError('Invalid Text Field type');
|
|
13
|
+
return 'text-field-' + size;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function clear() {
|
|
17
|
+
if (disabled || !value) return;
|
|
18
|
+
value = '';
|
|
19
|
+
input?.focus();
|
|
20
|
+
oninput?.(value);
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<div class="root" data-ds-component={type === 'search' ? 'search-field' : 'text-field'} data-ds-display={styling}>
|
|
25
|
+
{#if showLabel}<label for={id}>{label}</label>{/if}
|
|
26
|
+
<div class={['field', { invalid: error, disabled }]}>
|
|
27
|
+
{#if Icon || type === 'search'}
|
|
28
|
+
<span class="icon" aria-hidden="true">
|
|
29
|
+
{#if Icon}<Icon />{:else}<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="8.5" cy="8.5" r="4.5"/><path d="m12 12 4 4"/></svg>{/if}
|
|
30
|
+
</span>
|
|
31
|
+
{/if}
|
|
32
|
+
<input {type} {id} {name} {placeholder} bind:this={input} bind:value {disabled} {required}
|
|
33
|
+
aria-label={showLabel ? undefined : label} oninput={(event) => oninput?.(event.currentTarget.value)}
|
|
34
|
+
aria-describedby={error || help ? detailsId : undefined} aria-invalid={error ? 'true' : undefined} />
|
|
35
|
+
{#if unit}<span class="unit">{unit}</span>{/if}
|
|
36
|
+
{#if type === 'search' && value !== '' && !disabled}
|
|
37
|
+
<button class="clear" type="button" aria-label={clearLabel} onclick={clear}>×</button>
|
|
38
|
+
{/if}
|
|
39
|
+
</div>
|
|
40
|
+
{#if error || help}<p id={detailsId} class={{ error }}>{error || help}</p>{/if}
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<style>
|
|
44
|
+
.root { display: grid; }
|
|
45
|
+
label {
|
|
46
|
+
color: var(--ds-display-label-color);
|
|
47
|
+
font: var(--ds-display-label-font-weight) var(--ds-display-label-font-size)/var(--ds-display-label-line-height) var(--ds-display-label-font-family);
|
|
48
|
+
letter-spacing: var(--ds-display-label-letter-spacing);
|
|
49
|
+
padding-block-end: var(--ds-display-label-padding-block-end);
|
|
50
|
+
}
|
|
51
|
+
.field {
|
|
52
|
+
--field-line-color: var(--ds-display-field-border-color);
|
|
53
|
+
--field-line-width: var(--ds-display-field-border-width);
|
|
54
|
+
align-items: center;
|
|
55
|
+
background: var(--ds-display-field-background-color);
|
|
56
|
+
border-radius: var(--ds-display-field-border-radius);
|
|
57
|
+
box-shadow: inset 0 0 0 var(--field-line-width) var(--field-line-color);
|
|
58
|
+
box-sizing: border-box;
|
|
59
|
+
display: flex;
|
|
60
|
+
gap: var(--ds-display-field-column-gap);
|
|
61
|
+
min-block-size: var(--ds-display-field-min-height);
|
|
62
|
+
padding-inline: var(--ds-display-field-padding-inline);
|
|
63
|
+
}
|
|
64
|
+
.field:not(.disabled):hover { --field-line-color: var(--ds-display-field-outline-color); }
|
|
65
|
+
.field:focus-within {
|
|
66
|
+
--field-line-color: var(--ds-display-field-outline-color);
|
|
67
|
+
--field-line-width: var(--ds-display-field-outline-width);
|
|
68
|
+
}
|
|
69
|
+
.field.invalid:not(.disabled) {
|
|
70
|
+
--field-line-color: var(--ds-display-error-border-color);
|
|
71
|
+
--field-line-width: var(--ds-display-field-outline-width);
|
|
72
|
+
}
|
|
73
|
+
.field.disabled { background: var(--ds-display-disabled-background-color); }
|
|
74
|
+
input, .unit {
|
|
75
|
+
color: var(--ds-display-input-color);
|
|
76
|
+
font: var(--ds-display-input-font-weight) var(--ds-display-input-font-size)/var(--ds-display-input-line-height) var(--ds-display-input-font-family);
|
|
77
|
+
letter-spacing: var(--ds-display-input-letter-spacing);
|
|
78
|
+
}
|
|
79
|
+
input {
|
|
80
|
+
appearance: none;
|
|
81
|
+
align-self: stretch;
|
|
82
|
+
background: transparent;
|
|
83
|
+
border: 0;
|
|
84
|
+
flex: 1;
|
|
85
|
+
min-inline-size: 0;
|
|
86
|
+
outline: none;
|
|
87
|
+
padding: 0;
|
|
88
|
+
}
|
|
89
|
+
input:disabled, .disabled .unit, .disabled .icon { color: var(--ds-display-disabled-color); }
|
|
90
|
+
input::placeholder { color: var(--ds-display-hint-color); opacity: 1; }
|
|
91
|
+
input:disabled::placeholder { color: inherit; }
|
|
92
|
+
input[type='search']::-webkit-search-cancel-button { appearance: none; }
|
|
93
|
+
.clear {
|
|
94
|
+
display: inline-grid;
|
|
95
|
+
place-items: center;
|
|
96
|
+
padding: 0;
|
|
97
|
+
border: 0;
|
|
98
|
+
border-radius: .25rem;
|
|
99
|
+
min-inline-size: 24px;
|
|
100
|
+
min-block-size: 24px;
|
|
101
|
+
color: var(--ds-display-icon-color);
|
|
102
|
+
background: transparent;
|
|
103
|
+
font: inherit;
|
|
104
|
+
cursor: pointer;
|
|
105
|
+
}
|
|
106
|
+
.clear:focus-visible { outline: 2px solid var(--ds-display-field-outline-color); }
|
|
107
|
+
.icon {
|
|
108
|
+
display: flex;
|
|
109
|
+
color: var(--ds-display-icon-color);
|
|
110
|
+
inline-size: var(--ds-display-icon-width);
|
|
111
|
+
transform: translateY(1px);
|
|
112
|
+
}
|
|
113
|
+
.icon :global(svg) { block-size: auto; inline-size: 100%; }
|
|
114
|
+
p {
|
|
115
|
+
color: var(--ds-display-hint-color);
|
|
116
|
+
font: var(--ds-display-hint-font-weight) var(--ds-display-hint-font-size)/var(--ds-display-hint-line-height) var(--ds-display-hint-font-family);
|
|
117
|
+
letter-spacing: var(--ds-display-hint-letter-spacing);
|
|
118
|
+
margin: 0;
|
|
119
|
+
padding-block-start: var(--ds-display-hint-padding-block-start);
|
|
120
|
+
}
|
|
121
|
+
p.error { color: var(--ds-display-error-color); }
|
|
122
|
+
</style>
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
let openTooltips = 0;
|
|
3
|
+
let lastHide = -Infinity;
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<script>
|
|
7
|
+
import { onDestroy } from 'svelte';
|
|
8
|
+
import './draft.css';
|
|
9
|
+
import { attachOverlay } from './draft-overlay.mjs';
|
|
10
|
+
|
|
11
|
+
const describedby = $props.id();
|
|
12
|
+
let { label, children, delay = 600 } = $props();
|
|
13
|
+
let visible = $state(false);
|
|
14
|
+
let trigger = $state();
|
|
15
|
+
let hover = false;
|
|
16
|
+
let focused = false;
|
|
17
|
+
let hoveredPanel = false;
|
|
18
|
+
let dismissed = false;
|
|
19
|
+
let timer;
|
|
20
|
+
|
|
21
|
+
function attachDescription(wrapper) {
|
|
22
|
+
let describedElement;
|
|
23
|
+
let addedDescription = false;
|
|
24
|
+
function clearDescription() {
|
|
25
|
+
if (!describedElement || !addedDescription) return;
|
|
26
|
+
const other = (describedElement.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(value => value && value !== describedby);
|
|
27
|
+
if (other.length) describedElement.setAttribute('aria-describedby', other.join(' '));
|
|
28
|
+
else describedElement.removeAttribute('aria-describedby');
|
|
29
|
+
addedDescription = false;
|
|
30
|
+
}
|
|
31
|
+
function connect() {
|
|
32
|
+
const target = wrapper.querySelector('button, a[href], input, select, textarea, [tabindex]');
|
|
33
|
+
trigger = target ?? wrapper;
|
|
34
|
+
if (target === describedElement) return;
|
|
35
|
+
clearDescription();
|
|
36
|
+
describedElement = target;
|
|
37
|
+
if (!target) return;
|
|
38
|
+
const existing = (target.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
|
|
39
|
+
if (!existing.includes(describedby)) {
|
|
40
|
+
target.setAttribute('aria-describedby', [...existing, describedby].join(' '));
|
|
41
|
+
addedDescription = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
connect();
|
|
45
|
+
const observer = new MutationObserver(connect);
|
|
46
|
+
observer.observe(wrapper, { childList: true, subtree: true });
|
|
47
|
+
wrapper.addEventListener('pointerenter', pointerEnter);
|
|
48
|
+
wrapper.addEventListener('pointerleave', pointerLeave);
|
|
49
|
+
return () => {
|
|
50
|
+
observer.disconnect();
|
|
51
|
+
clearDescription();
|
|
52
|
+
wrapper.removeEventListener('pointerenter', pointerEnter);
|
|
53
|
+
wrapper.removeEventListener('pointerleave', pointerLeave);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function show(wait = 0) {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
if (dismissed || visible) return;
|
|
60
|
+
if (wait > 0) {
|
|
61
|
+
timer = setTimeout(() => show(), wait);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
visible = true;
|
|
65
|
+
openTooltips++;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function hide() {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
if (!visible) return;
|
|
71
|
+
visible = false;
|
|
72
|
+
openTooltips--;
|
|
73
|
+
lastHide = performance.now();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function release() {
|
|
77
|
+
if (hover || focused || hoveredPanel) return;
|
|
78
|
+
dismissed = false;
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
timer = setTimeout(hide, 120);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function pointerEnter(event) {
|
|
84
|
+
if (event.pointerType === 'touch') return;
|
|
85
|
+
hover = true;
|
|
86
|
+
show(openTooltips || performance.now() - lastHide < 180 ? 0 : delay);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function pointerLeave() {
|
|
90
|
+
hover = false;
|
|
91
|
+
release();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function focusIn(event) {
|
|
95
|
+
if (!event.target.matches(':focus-visible')) return;
|
|
96
|
+
focused = true;
|
|
97
|
+
show();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function escape(event) {
|
|
101
|
+
if (event.key !== 'Escape' || !visible) return;
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
dismissed = true;
|
|
104
|
+
hoveredPanel = false;
|
|
105
|
+
hide();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
onDestroy(hide);
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
<svelte:window onkeydown={escape} />
|
|
112
|
+
|
|
113
|
+
<span class="trigger" data-ds-component="tooltip" {@attach attachDescription}
|
|
114
|
+
onfocusin={focusIn} onfocusout={() => { focused = false; release(); }}>
|
|
115
|
+
{@render children({ describedby })}
|
|
116
|
+
</span>
|
|
117
|
+
<span id={describedby} role="tooltip" popover="manual" class="panel" hidden={!visible}
|
|
118
|
+
{@attach node => attachOverlay(trigger, node, visible, {
|
|
119
|
+
placement: 'above', maxWidth: 240, gap: 4, onAnchorHidden: hide,
|
|
120
|
+
})}
|
|
121
|
+
onpointerenter={() => { hoveredPanel = true; clearTimeout(timer); }}
|
|
122
|
+
onpointerleave={() => { hoveredPanel = false; release(); }}>
|
|
123
|
+
{label}
|
|
124
|
+
</span>
|
|
125
|
+
|
|
126
|
+
<style>
|
|
127
|
+
.trigger { display: inline-flex; }
|
|
128
|
+
.panel {
|
|
129
|
+
position: fixed;
|
|
130
|
+
z-index: 15;
|
|
131
|
+
inset: auto;
|
|
132
|
+
box-sizing: border-box;
|
|
133
|
+
inline-size: max-content;
|
|
134
|
+
max-inline-size: 240px;
|
|
135
|
+
overflow-wrap: anywhere;
|
|
136
|
+
overflow: auto;
|
|
137
|
+
margin: 0;
|
|
138
|
+
padding: var(--ds-draft-dimension-x1) var(--ds-draft-dimension-x2);
|
|
139
|
+
border: 0;
|
|
140
|
+
border-radius: var(--ds-draft-radius-r1-5);
|
|
141
|
+
background: var(--ds-draft-bg-neutral-solid);
|
|
142
|
+
color: var(--ds-draft-fg-neutral-inverted);
|
|
143
|
+
text-align: start;
|
|
144
|
+
font: var(--ds-draft-type-sub-font-weight) var(--ds-draft-type-sub-font-size) / var(--ds-draft-type-sub-line-height) var(--ds-draft-type-sub-font-family);
|
|
145
|
+
}
|
|
146
|
+
.panel[hidden] { display: none; }
|
|
147
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const buttonOptions = {"action-button":{"color":["primary","neutral","critical"],"variant":["solid","weak","outline","clear","quiet"],"size":["xs","sm","md","lg"],"variantColors":{"quiet":["neutral"]}},"icon-button":{"color":["primary","neutral","critical"],"variant":["weak","outline","clear","quiet"],"size":["xs","sm","md","lg"],"variantColors":{"quiet":["neutral"]}}};
|