@bwui/vue 0.1.9 → 0.1.12
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/date-picker.d.ts +36 -0
- package/dist/date-picker.js +25 -5
- package/dist/index.d.ts +7 -1
- package/dist/index.js +5 -1
- package/dist/modal.d.ts +75 -0
- package/dist/modal.js +124 -0
- package/dist/pages.d.ts +2 -2
- package/dist/popover.d.ts +100 -0
- package/dist/popover.js +182 -0
- package/dist/primitives.d.ts +738 -22
- package/dist/primitives.js +680 -26
- package/dist/stat.d.ts +216 -0
- package/dist/stat.js +111 -0
- package/package.json +3 -3
- package/src/date-picker.ts +70 -42
- package/src/index.ts +25 -0
- package/src/modal.ts +160 -0
- package/src/popover.ts +241 -0
- package/src/primitives.ts +914 -27
- package/src/stat.ts +138 -0
package/src/primitives.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
let bwCopySeq = 0
|
|
2
|
+
import { defineComponent, h, type PropType, computed, ref } from 'vue'
|
|
2
3
|
import { cn } from './cn'
|
|
3
4
|
|
|
4
5
|
type ButtonVariant =
|
|
@@ -62,41 +63,200 @@ export const ButtonLink = defineComponent({
|
|
|
62
63
|
},
|
|
63
64
|
})
|
|
64
65
|
|
|
66
|
+
export type BadgeVariant =
|
|
67
|
+
| 'neutral'
|
|
68
|
+
| 'outline'
|
|
69
|
+
| 'success'
|
|
70
|
+
| 'warning'
|
|
71
|
+
| 'danger'
|
|
72
|
+
| 'info'
|
|
73
|
+
| 'default'
|
|
74
|
+
| 'secondary'
|
|
75
|
+
export type BadgeSize = 'sm' | 'md'
|
|
76
|
+
|
|
77
|
+
function resolveBadgeVariant(variant: string): string {
|
|
78
|
+
if (variant === 'default') return 'neutral'
|
|
79
|
+
if (variant === 'secondary') return 'outline'
|
|
80
|
+
return variant
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Badge (docs/components/badge.md): status tag / pace pill. */
|
|
65
84
|
export const Badge = defineComponent({
|
|
66
85
|
name: 'BwBadge',
|
|
67
86
|
props: {
|
|
68
|
-
variant: { type: String
|
|
87
|
+
variant: { type: String as PropType<BadgeVariant>, default: 'neutral' },
|
|
88
|
+
size: { type: String as PropType<BadgeSize>, default: 'md' },
|
|
69
89
|
},
|
|
70
90
|
setup(props, { slots, attrs }) {
|
|
71
91
|
return () =>
|
|
72
92
|
h(
|
|
73
93
|
'span',
|
|
74
|
-
{
|
|
94
|
+
{
|
|
95
|
+
...attrs,
|
|
96
|
+
class: cn(
|
|
97
|
+
'bw-badge',
|
|
98
|
+
`bw-badge--${resolveBadgeVariant(props.variant)}`,
|
|
99
|
+
`bw-badge--size-${props.size}`,
|
|
100
|
+
String(attrs.class || ''),
|
|
101
|
+
),
|
|
102
|
+
},
|
|
75
103
|
slots.default?.(),
|
|
76
104
|
)
|
|
77
105
|
},
|
|
78
106
|
})
|
|
79
107
|
|
|
108
|
+
|
|
109
|
+
export type ChipSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
110
|
+
export type ChipVariant = 'neutral' | 'success' | 'warning' | 'danger' | 'info'
|
|
111
|
+
|
|
112
|
+
export const Chip = defineComponent({
|
|
113
|
+
name: 'BwChip',
|
|
114
|
+
inheritAttrs: false,
|
|
115
|
+
props: {
|
|
116
|
+
size: { type: String as () => ChipSize, default: 'md' },
|
|
117
|
+
variant: { type: String as () => ChipVariant, default: 'neutral' },
|
|
118
|
+
selected: { type: Boolean, default: false },
|
|
119
|
+
toggle: { type: Boolean, default: false },
|
|
120
|
+
href: { type: String, default: undefined },
|
|
121
|
+
dismissLabel: { type: String, default: undefined },
|
|
122
|
+
},
|
|
123
|
+
emits: ['dismiss'],
|
|
124
|
+
setup(props, { slots, attrs, emit }) {
|
|
125
|
+
return () => {
|
|
126
|
+
const { class: cls, ...rest } = attrs
|
|
127
|
+
const classes = cn(
|
|
128
|
+
'bw-chip',
|
|
129
|
+
`bw-chip--${props.variant}`,
|
|
130
|
+
`bw-chip--size-${props.size}`,
|
|
131
|
+
props.selected && 'bw-chip--selected',
|
|
132
|
+
String(cls || ''),
|
|
133
|
+
)
|
|
134
|
+
const label = h('span', { class: 'bw-chip__label' }, slots.default?.())
|
|
135
|
+
if (props.dismissLabel) {
|
|
136
|
+
return h('span', { ...rest, class: classes }, [
|
|
137
|
+
label,
|
|
138
|
+
h(
|
|
139
|
+
'button',
|
|
140
|
+
{
|
|
141
|
+
type: 'button',
|
|
142
|
+
class: 'bw-chip__close',
|
|
143
|
+
'aria-label': props.dismissLabel,
|
|
144
|
+
onClick: () => emit('dismiss'),
|
|
145
|
+
},
|
|
146
|
+
slots.close?.(),
|
|
147
|
+
),
|
|
148
|
+
])
|
|
149
|
+
}
|
|
150
|
+
if (props.href) {
|
|
151
|
+
return h(
|
|
152
|
+
'a',
|
|
153
|
+
{
|
|
154
|
+
...rest,
|
|
155
|
+
class: classes,
|
|
156
|
+
href: props.href,
|
|
157
|
+
'aria-current': props.selected ? 'true' : undefined,
|
|
158
|
+
},
|
|
159
|
+
[label],
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
if (props.toggle || props.selected) {
|
|
163
|
+
return h(
|
|
164
|
+
'button',
|
|
165
|
+
{
|
|
166
|
+
...rest,
|
|
167
|
+
type: 'button',
|
|
168
|
+
class: classes,
|
|
169
|
+
'aria-pressed': props.selected,
|
|
170
|
+
},
|
|
171
|
+
[label],
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
return h('span', { ...rest, class: classes }, [label])
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
export type CardSize = 'sm' | 'md' | 'lg'
|
|
180
|
+
export type CardSurface = 'default' | 'raised' | 'tint' | 'inverse' | 'muted'
|
|
181
|
+
export type CardElevation = '0' | '1' | '2' | '3'
|
|
182
|
+
export type CardRadius = 'default' | 'sm' | 'lg' | 'xl' | 'none'
|
|
183
|
+
|
|
184
|
+
// Card (docs/components/card.md): the same modifier grammar as React. `md` is
|
|
185
|
+
// the base inset and emits a class only when asked for; `href` renders an
|
|
186
|
+
// anchor and implies interactive; `bordered` is the APP-002 flat hairline mode.
|
|
80
187
|
export const Card = defineComponent({
|
|
81
188
|
name: 'BwCard',
|
|
82
|
-
|
|
83
|
-
|
|
189
|
+
inheritAttrs: false,
|
|
190
|
+
props: {
|
|
191
|
+
size: { type: String as PropType<CardSize>, default: undefined },
|
|
192
|
+
bordered: { type: Boolean, default: false },
|
|
193
|
+
surface: { type: String as PropType<CardSurface>, default: undefined },
|
|
194
|
+
elevation: { type: String as PropType<CardElevation>, default: undefined },
|
|
195
|
+
radius: { type: String as PropType<CardRadius>, default: undefined },
|
|
196
|
+
interactive: { type: Boolean, default: false },
|
|
197
|
+
href: { type: String, default: undefined },
|
|
198
|
+
},
|
|
199
|
+
setup(props, { slots, attrs }) {
|
|
200
|
+
return () => {
|
|
201
|
+
const linked = props.href !== undefined
|
|
202
|
+
const classes = cn(
|
|
203
|
+
'bw-card',
|
|
204
|
+
(props.interactive || linked) && 'bw-card--interactive',
|
|
205
|
+
props.bordered && 'bw-card--bordered',
|
|
206
|
+
props.size && `bw-card--size-${props.size}`,
|
|
207
|
+
props.radius && props.radius !== 'default' && props.radius !== 'lg' && `bw-card--radius-${props.radius}`,
|
|
208
|
+
props.surface && props.surface !== 'default' && `bw-card--surface-${props.surface}`,
|
|
209
|
+
props.elevation && props.elevation !== '1' && `bw-card--elevation-${props.elevation}`,
|
|
210
|
+
String(attrs.class || ''),
|
|
211
|
+
)
|
|
212
|
+
return h(
|
|
213
|
+
linked ? 'a' : 'div',
|
|
214
|
+
{ ...attrs, class: classes, ...(linked ? { href: props.href } : {}) },
|
|
215
|
+
slots.default?.(),
|
|
216
|
+
)
|
|
217
|
+
}
|
|
84
218
|
},
|
|
85
219
|
})
|
|
86
220
|
|
|
87
221
|
export const Alert = defineComponent({
|
|
88
222
|
name: 'BwAlert',
|
|
89
|
-
props: {
|
|
223
|
+
props: {
|
|
224
|
+
variant: { type: String, default: 'info' },
|
|
225
|
+
},
|
|
226
|
+
setup(props, { slots, attrs }) {
|
|
227
|
+
const allowed = new Set(['info', 'success', 'warning', 'danger'])
|
|
228
|
+
return () => {
|
|
229
|
+
const variant = allowed.has(props.variant) ? props.variant : 'info'
|
|
230
|
+
return h(
|
|
231
|
+
'div',
|
|
232
|
+
{
|
|
233
|
+
...attrs,
|
|
234
|
+
role: 'alert',
|
|
235
|
+
class: cn('bw-alert', `bw-alert--${variant}`, String(attrs.class || '')),
|
|
236
|
+
},
|
|
237
|
+
slots.default?.(),
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
export const Banner = defineComponent({
|
|
244
|
+
name: 'BwBanner',
|
|
245
|
+
props: {
|
|
246
|
+
variant: { type: String, default: 'info' },
|
|
247
|
+
edge: { type: String, default: 'top' },
|
|
248
|
+
},
|
|
90
249
|
setup(props, { slots, attrs }) {
|
|
91
250
|
return () =>
|
|
92
251
|
h(
|
|
93
252
|
'div',
|
|
94
253
|
{
|
|
95
254
|
...attrs,
|
|
96
|
-
role: '
|
|
255
|
+
role: 'region',
|
|
97
256
|
class: cn(
|
|
98
|
-
'bw-
|
|
99
|
-
|
|
257
|
+
'bw-banner',
|
|
258
|
+
`bw-banner--${props.variant}`,
|
|
259
|
+
`bw-banner--edge-${props.edge}`,
|
|
100
260
|
String(attrs.class || ''),
|
|
101
261
|
),
|
|
102
262
|
},
|
|
@@ -115,10 +275,87 @@ function div(name: string, className: string) {
|
|
|
115
275
|
})
|
|
116
276
|
}
|
|
117
277
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
278
|
+
function p(name: string, className: string) {
|
|
279
|
+
return defineComponent({
|
|
280
|
+
name,
|
|
281
|
+
setup(_, { slots, attrs }) {
|
|
282
|
+
return () =>
|
|
283
|
+
h('p', { ...attrs, class: cn(className, String(attrs.class || '')) }, slots.default?.())
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export const AlertTitle = p('BwAlertTitle', 'bw-alert__title')
|
|
289
|
+
export const AlertBody = p('BwAlertBody', 'bw-alert__message')
|
|
290
|
+
|
|
291
|
+
type LayoutGap = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
292
|
+
type InsetSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
293
|
+
|
|
294
|
+
function layoutWithGap(name: string, baseClass: string) {
|
|
295
|
+
return defineComponent({
|
|
296
|
+
name,
|
|
297
|
+
props: {
|
|
298
|
+
gap: { type: String as PropType<LayoutGap>, default: 'md' },
|
|
299
|
+
},
|
|
300
|
+
setup(props, { slots, attrs }) {
|
|
301
|
+
return () =>
|
|
302
|
+
h(
|
|
303
|
+
'div',
|
|
304
|
+
{
|
|
305
|
+
...attrs,
|
|
306
|
+
class: cn(
|
|
307
|
+
baseClass,
|
|
308
|
+
props.gap !== 'md' && `${baseClass}--gap-${props.gap}`,
|
|
309
|
+
String(attrs.class || ''),
|
|
310
|
+
),
|
|
311
|
+
},
|
|
312
|
+
slots.default?.(),
|
|
313
|
+
)
|
|
314
|
+
},
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export const Stack = layoutWithGap('BwStack', 'bw-stack')
|
|
319
|
+
export const Cluster = layoutWithGap('BwCluster', 'bw-cluster')
|
|
320
|
+
export const Grid = layoutWithGap('BwGrid', 'bw-grid')
|
|
321
|
+
|
|
322
|
+
export const Inset = defineComponent({
|
|
323
|
+
name: 'BwInset',
|
|
324
|
+
props: {
|
|
325
|
+
size: { type: String as PropType<InsetSize>, default: 'md' },
|
|
326
|
+
},
|
|
327
|
+
setup(props, { slots, attrs }) {
|
|
328
|
+
return () =>
|
|
329
|
+
h(
|
|
330
|
+
'div',
|
|
331
|
+
{
|
|
332
|
+
...attrs,
|
|
333
|
+
class: cn(
|
|
334
|
+
'bw-inset',
|
|
335
|
+
props.size !== 'md' && `bw-inset--size-${props.size}`,
|
|
336
|
+
String(attrs.class || ''),
|
|
337
|
+
),
|
|
338
|
+
},
|
|
339
|
+
slots.default?.(),
|
|
340
|
+
)
|
|
341
|
+
},
|
|
342
|
+
})
|
|
343
|
+
|
|
121
344
|
export const Container = div('BwContainer', 'bw-container')
|
|
345
|
+
export const Centre = div('BwCentre', 'bw-centre')
|
|
346
|
+
|
|
347
|
+
export const VisuallyHidden = defineComponent({
|
|
348
|
+
name: 'BwVisuallyHidden',
|
|
349
|
+
setup(_, { slots, attrs }) {
|
|
350
|
+
return () =>
|
|
351
|
+
h(
|
|
352
|
+
'span',
|
|
353
|
+
{ ...attrs, class: cn('bw-visually-hidden', String(attrs.class || '')) },
|
|
354
|
+
slots.default?.(),
|
|
355
|
+
)
|
|
356
|
+
},
|
|
357
|
+
})
|
|
358
|
+
|
|
122
359
|
export const Field = div('BwField', 'bw-field')
|
|
123
360
|
export const FormActions = div('BwFormActions', 'bw-form__actions bw-cluster')
|
|
124
361
|
|
|
@@ -142,7 +379,7 @@ export const Hint = defineComponent({
|
|
|
142
379
|
name: 'BwHint',
|
|
143
380
|
setup(_, { slots, attrs }) {
|
|
144
381
|
return () =>
|
|
145
|
-
h('p', { ...attrs, class: cn('bw-field__hint', String(attrs.class || '')) }, slots.default?.())
|
|
382
|
+
h('p', { ...attrs, class: cn('bw-field__help', 'bw-field__hint', String(attrs.class || '')) }, slots.default?.())
|
|
146
383
|
},
|
|
147
384
|
})
|
|
148
385
|
|
|
@@ -154,71 +391,253 @@ export const FieldError = defineComponent({
|
|
|
154
391
|
},
|
|
155
392
|
})
|
|
156
393
|
|
|
394
|
+
export type InputSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
395
|
+
|
|
157
396
|
export const Input = defineComponent({
|
|
158
397
|
name: 'BwInput',
|
|
159
398
|
inheritAttrs: false,
|
|
160
|
-
|
|
161
|
-
|
|
399
|
+
props: {
|
|
400
|
+
size: { type: String as () => InputSize, default: 'md' },
|
|
401
|
+
},
|
|
402
|
+
setup(props, { attrs }) {
|
|
403
|
+
return () =>
|
|
404
|
+
h('input', {
|
|
405
|
+
...attrs,
|
|
406
|
+
class: cn('bw-input', `bw-input--size-${props.size}`, String(attrs.class || '')),
|
|
407
|
+
})
|
|
162
408
|
},
|
|
163
409
|
})
|
|
164
410
|
|
|
165
411
|
export const Textarea = defineComponent({
|
|
166
412
|
name: 'BwTextarea',
|
|
167
413
|
inheritAttrs: false,
|
|
168
|
-
|
|
169
|
-
|
|
414
|
+
props: {
|
|
415
|
+
size: { type: String as () => InputSize, default: 'md' },
|
|
416
|
+
},
|
|
417
|
+
setup(props, { attrs }) {
|
|
418
|
+
return () =>
|
|
419
|
+
h('textarea', {
|
|
420
|
+
...attrs,
|
|
421
|
+
class: cn(
|
|
422
|
+
'bw-input',
|
|
423
|
+
'bw-textarea',
|
|
424
|
+
`bw-input--size-${props.size}`,
|
|
425
|
+
String(attrs.class || ''),
|
|
426
|
+
),
|
|
427
|
+
})
|
|
428
|
+
},
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
export type SwitchSize = InputSize
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Switch (docs/components/switch.md): native checkbox with role="switch"
|
|
435
|
+
* inside a bw-switch root. Attributes land on the input (name, id, checked,
|
|
436
|
+
* disabled, aria-label); `class` lands on the root. The accessible name is the
|
|
437
|
+
* consumer's.
|
|
438
|
+
*/
|
|
439
|
+
export const Switch = defineComponent({
|
|
440
|
+
name: 'BwSwitch',
|
|
441
|
+
inheritAttrs: false,
|
|
442
|
+
props: {
|
|
443
|
+
size: { type: String as () => SwitchSize, default: 'md' },
|
|
444
|
+
},
|
|
445
|
+
setup(props, { attrs }) {
|
|
446
|
+
return () => {
|
|
447
|
+
const { class: cls, ...rest } = attrs
|
|
448
|
+
return h(
|
|
449
|
+
'span',
|
|
450
|
+
{ class: cn('bw-switch', `bw-switch--size-${props.size}`, String(cls || '')) },
|
|
451
|
+
[
|
|
452
|
+
h('input', { ...rest, type: 'checkbox', role: 'switch' }),
|
|
453
|
+
h('span', { class: 'bw-switch__track', 'aria-hidden': 'true' }),
|
|
454
|
+
h('span', { class: 'bw-switch__thumb', 'aria-hidden': 'true' }),
|
|
455
|
+
],
|
|
456
|
+
)
|
|
457
|
+
}
|
|
170
458
|
},
|
|
171
459
|
})
|
|
172
460
|
|
|
173
461
|
export const Select = defineComponent({
|
|
174
462
|
name: 'BwSelect',
|
|
175
463
|
inheritAttrs: false,
|
|
176
|
-
|
|
464
|
+
props: {
|
|
465
|
+
size: { type: String as () => InputSize, default: 'md' },
|
|
466
|
+
},
|
|
467
|
+
setup(props, { slots, attrs }) {
|
|
177
468
|
return () =>
|
|
178
|
-
h(
|
|
469
|
+
h(
|
|
470
|
+
'select',
|
|
471
|
+
{
|
|
472
|
+
...attrs,
|
|
473
|
+
class: cn('bw-select', `bw-select--size-${props.size}`, String(attrs.class || '')),
|
|
474
|
+
},
|
|
475
|
+
slots.default?.(),
|
|
476
|
+
)
|
|
179
477
|
},
|
|
180
478
|
})
|
|
181
479
|
|
|
182
480
|
export const Checkbox = defineComponent({
|
|
183
481
|
name: 'BwCheckbox',
|
|
184
482
|
inheritAttrs: false,
|
|
185
|
-
|
|
483
|
+
props: {
|
|
484
|
+
size: { type: String as () => InputSize, default: 'md' },
|
|
485
|
+
indeterminate: { type: Boolean, default: false },
|
|
486
|
+
},
|
|
487
|
+
setup(props, { attrs }) {
|
|
186
488
|
return () =>
|
|
187
|
-
h('input', {
|
|
489
|
+
h('input', {
|
|
490
|
+
...attrs,
|
|
491
|
+
type: 'checkbox',
|
|
492
|
+
indeterminate: props.indeterminate,
|
|
493
|
+
class: cn('bw-checkbox', `bw-checkbox--size-${props.size}`, String(attrs.class || '')),
|
|
494
|
+
})
|
|
188
495
|
},
|
|
189
496
|
})
|
|
190
497
|
|
|
498
|
+
export type RadioSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
499
|
+
|
|
191
500
|
export const Radio = defineComponent({
|
|
192
501
|
name: 'BwRadio',
|
|
193
502
|
inheritAttrs: false,
|
|
194
|
-
|
|
503
|
+
props: {
|
|
504
|
+
size: { type: String as () => RadioSize, default: 'md' },
|
|
505
|
+
},
|
|
506
|
+
setup(props, { attrs }) {
|
|
195
507
|
return () =>
|
|
196
|
-
h('input', {
|
|
508
|
+
h('input', {
|
|
509
|
+
...attrs,
|
|
510
|
+
type: 'radio',
|
|
511
|
+
class: cn('bw-radio', `bw-radio--size-${props.size}`, String(attrs.class || '')),
|
|
512
|
+
})
|
|
513
|
+
},
|
|
514
|
+
})
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
export type SliderSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
518
|
+
|
|
519
|
+
function sliderPercent(value: number, min: number, max: number): number {
|
|
520
|
+
if (max === min) return 0
|
|
521
|
+
return ((value - min) / (max - min)) * 100
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Slider (docs/components/slider.md): native range inside bw-slider root.
|
|
526
|
+
* Attributes land on the input; `class` lands on the root. Fill sync via
|
|
527
|
+
* --bw-slider-percent (SLD-034).
|
|
528
|
+
*/
|
|
529
|
+
export const Slider = defineComponent({
|
|
530
|
+
name: 'BwSlider',
|
|
531
|
+
inheritAttrs: false,
|
|
532
|
+
props: {
|
|
533
|
+
size: { type: String as () => SliderSize, default: 'md' },
|
|
534
|
+
},
|
|
535
|
+
setup(props, { attrs }) {
|
|
536
|
+
return () => {
|
|
537
|
+
const { class: cls, style, min = 0, max = 100, value, modelValue, ...rest } = attrs as Record<
|
|
538
|
+
string,
|
|
539
|
+
unknown
|
|
540
|
+
>
|
|
541
|
+
const minN = Number(min)
|
|
542
|
+
const maxN = Number(max)
|
|
543
|
+
const current =
|
|
544
|
+
value !== undefined
|
|
545
|
+
? Number(value)
|
|
546
|
+
: modelValue !== undefined
|
|
547
|
+
? Number(modelValue)
|
|
548
|
+
: minN
|
|
549
|
+
const percent = sliderPercent(current, minN, maxN)
|
|
550
|
+
const onInput = (event: Event) => {
|
|
551
|
+
const input = event.currentTarget as HTMLInputElement
|
|
552
|
+
const root = input.parentElement as HTMLElement | null
|
|
553
|
+
if (root) {
|
|
554
|
+
root.style.setProperty(
|
|
555
|
+
'--bw-slider-percent',
|
|
556
|
+
String(sliderPercent(input.valueAsNumber, Number(input.min), Number(input.max))),
|
|
557
|
+
)
|
|
558
|
+
}
|
|
559
|
+
const prior = rest.onInput as ((e: Event) => void) | undefined
|
|
560
|
+
prior?.(event)
|
|
561
|
+
}
|
|
562
|
+
const mergedStyle = {
|
|
563
|
+
...(typeof style === 'object' && style ? (style as object) : {}),
|
|
564
|
+
'--bw-slider-percent': percent,
|
|
565
|
+
}
|
|
566
|
+
return h(
|
|
567
|
+
'span',
|
|
568
|
+
{ class: cn('bw-slider', `bw-slider--size-${props.size}`, String(cls || '')), style: mergedStyle },
|
|
569
|
+
[
|
|
570
|
+
h('input', {
|
|
571
|
+
...rest,
|
|
572
|
+
min,
|
|
573
|
+
max,
|
|
574
|
+
value,
|
|
575
|
+
type: 'range',
|
|
576
|
+
class: 'bw-slider__input',
|
|
577
|
+
onInput,
|
|
578
|
+
}),
|
|
579
|
+
],
|
|
580
|
+
)
|
|
581
|
+
}
|
|
197
582
|
},
|
|
198
583
|
})
|
|
199
584
|
|
|
200
585
|
export const TimeInput = defineComponent({
|
|
201
586
|
name: 'BwTimeInput',
|
|
202
587
|
inheritAttrs: false,
|
|
203
|
-
|
|
588
|
+
props: {
|
|
589
|
+
size: { type: String as () => InputSize, default: 'md' },
|
|
590
|
+
},
|
|
591
|
+
setup(props, { attrs }) {
|
|
204
592
|
return () =>
|
|
205
|
-
h('input', {
|
|
593
|
+
h('input', {
|
|
594
|
+
...attrs,
|
|
595
|
+
type: 'time',
|
|
596
|
+
class: cn('bw-input', `bw-input--size-${props.size}`, String(attrs.class || '')),
|
|
597
|
+
})
|
|
206
598
|
},
|
|
207
599
|
})
|
|
208
600
|
|
|
209
601
|
export const DateTimeInput = defineComponent({
|
|
210
602
|
name: 'BwDateTimeInput',
|
|
211
603
|
inheritAttrs: false,
|
|
212
|
-
|
|
604
|
+
props: {
|
|
605
|
+
size: { type: String as () => InputSize, default: 'md' },
|
|
606
|
+
},
|
|
607
|
+
setup(props, { attrs }) {
|
|
213
608
|
return () =>
|
|
214
609
|
h('input', {
|
|
215
610
|
...attrs,
|
|
216
611
|
type: 'datetime-local',
|
|
217
|
-
class: cn('bw-input', String(attrs.class || '')),
|
|
612
|
+
class: cn('bw-input', `bw-input--size-${props.size}`, String(attrs.class || '')),
|
|
218
613
|
})
|
|
219
614
|
},
|
|
220
615
|
})
|
|
221
616
|
|
|
617
|
+
export const InputGroup = defineComponent({
|
|
618
|
+
name: 'BwInputGroup',
|
|
619
|
+
inheritAttrs: false,
|
|
620
|
+
props: {
|
|
621
|
+
size: { type: String as () => InputSize, default: 'md' },
|
|
622
|
+
},
|
|
623
|
+
setup(props, { slots, attrs }) {
|
|
624
|
+
return () =>
|
|
625
|
+
h(
|
|
626
|
+
'div',
|
|
627
|
+
{
|
|
628
|
+
...attrs,
|
|
629
|
+
role: 'group',
|
|
630
|
+
class: cn(
|
|
631
|
+
'bw-input-group',
|
|
632
|
+
`bw-input-group--size-${props.size}`,
|
|
633
|
+
String(attrs.class || ''),
|
|
634
|
+
),
|
|
635
|
+
},
|
|
636
|
+
slots.default?.(),
|
|
637
|
+
)
|
|
638
|
+
},
|
|
639
|
+
})
|
|
640
|
+
|
|
222
641
|
export const SkipLink = defineComponent({
|
|
223
642
|
name: 'BwSkipLink',
|
|
224
643
|
props: { href: { type: String, default: '#main' } },
|
|
@@ -254,3 +673,471 @@ export const ThemeToggle = defineComponent({
|
|
|
254
673
|
)
|
|
255
674
|
},
|
|
256
675
|
})
|
|
676
|
+
|
|
677
|
+
export type SegmentedSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
678
|
+
|
|
679
|
+
export type SegmentedOption = {
|
|
680
|
+
value: string
|
|
681
|
+
label: string
|
|
682
|
+
disabled?: boolean
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Segmented control (docs/components/segmented.md): role=group of buttons with
|
|
687
|
+
* aria-pressed. Size re-points the five role variables. Accessible name is the
|
|
688
|
+
* consumer's (aria-label / aria-labelledby on the root).
|
|
689
|
+
*/
|
|
690
|
+
export const Segmented = defineComponent({
|
|
691
|
+
name: 'BwSegmented',
|
|
692
|
+
props: {
|
|
693
|
+
size: { type: String as () => SegmentedSize, default: 'md' },
|
|
694
|
+
value: { type: String, required: true },
|
|
695
|
+
options: { type: Array as () => SegmentedOption[], required: true },
|
|
696
|
+
disabled: { type: Boolean, default: false },
|
|
697
|
+
},
|
|
698
|
+
emits: ['update:value'],
|
|
699
|
+
setup(props, { attrs, emit }) {
|
|
700
|
+
return () =>
|
|
701
|
+
h(
|
|
702
|
+
'div',
|
|
703
|
+
{
|
|
704
|
+
...attrs,
|
|
705
|
+
role: 'group',
|
|
706
|
+
class: cn(
|
|
707
|
+
'bw-segmented',
|
|
708
|
+
`bw-segmented--size-${props.size}`,
|
|
709
|
+
String(attrs.class || ''),
|
|
710
|
+
),
|
|
711
|
+
},
|
|
712
|
+
props.options.map((option) => {
|
|
713
|
+
const pressed = option.value === props.value
|
|
714
|
+
const itemDisabled = props.disabled || Boolean(option.disabled)
|
|
715
|
+
return h(
|
|
716
|
+
'button',
|
|
717
|
+
{
|
|
718
|
+
key: option.value,
|
|
719
|
+
type: 'button',
|
|
720
|
+
class: 'bw-segmented__item',
|
|
721
|
+
'aria-pressed': pressed,
|
|
722
|
+
disabled: itemDisabled || undefined,
|
|
723
|
+
onClick: () => {
|
|
724
|
+
if (itemDisabled || pressed) return
|
|
725
|
+
emit('update:value', option.value)
|
|
726
|
+
},
|
|
727
|
+
},
|
|
728
|
+
option.label,
|
|
729
|
+
)
|
|
730
|
+
}),
|
|
731
|
+
)
|
|
732
|
+
},
|
|
733
|
+
})
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
export type NumberStepperSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* NumberStepper (docs/components/number-stepper.md). A decrement button, a
|
|
740
|
+
* native `<input type="number">`, and an increment button in a connected group.
|
|
741
|
+
* Root `role="group"` must be labelled by the consumer via `aria-label` or
|
|
742
|
+
* `aria-labelledby`. Component name `BwNumberStepper`. `class` lands on the root;
|
|
743
|
+
* all other attributes land on the input unless handled as a prop.
|
|
744
|
+
*/
|
|
745
|
+
export const NumberStepper = defineComponent({
|
|
746
|
+
name: 'BwNumberStepper',
|
|
747
|
+
inheritAttrs: false,
|
|
748
|
+
props: {
|
|
749
|
+
size: { type: String as () => NumberStepperSize, default: 'md' },
|
|
750
|
+
value: { type: Number as PropType<number | undefined>, default: undefined },
|
|
751
|
+
min: { type: Number as PropType<number | undefined>, default: undefined },
|
|
752
|
+
max: { type: Number as PropType<number | undefined>, default: undefined },
|
|
753
|
+
step: { type: Number, default: 1 },
|
|
754
|
+
disabled: { type: Boolean, default: false },
|
|
755
|
+
readOnly: { type: Boolean, default: false },
|
|
756
|
+
decrementLabel: { type: String, default: 'Decrease' },
|
|
757
|
+
incrementLabel: { type: String, default: 'Increase' },
|
|
758
|
+
'aria-label': { type: String as PropType<string | undefined>, default: undefined },
|
|
759
|
+
'aria-labelledby': { type: String as PropType<string | undefined>, default: undefined },
|
|
760
|
+
},
|
|
761
|
+
emits: ['update:value'],
|
|
762
|
+
setup(props, { attrs, emit }) {
|
|
763
|
+
return () => {
|
|
764
|
+
const { class: cls, ...inputAttrs } = attrs
|
|
765
|
+
const val = props.value
|
|
766
|
+
const atMin = val !== undefined && props.min !== undefined && val <= props.min
|
|
767
|
+
const atMax = val !== undefined && props.max !== undefined && val >= props.max
|
|
768
|
+
|
|
769
|
+
function decrement() {
|
|
770
|
+
if (props.disabled || props.readOnly) return
|
|
771
|
+
let next: number
|
|
772
|
+
if (val === undefined) {
|
|
773
|
+
next = props.min !== undefined ? props.min : 0
|
|
774
|
+
} else {
|
|
775
|
+
next = val - props.step
|
|
776
|
+
if (props.min !== undefined) next = Math.max(next, props.min)
|
|
777
|
+
}
|
|
778
|
+
emit('update:value', next)
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function increment() {
|
|
782
|
+
if (props.disabled || props.readOnly) return
|
|
783
|
+
let next: number
|
|
784
|
+
if (val === undefined) {
|
|
785
|
+
next = props.max !== undefined ? props.max : props.step
|
|
786
|
+
} else {
|
|
787
|
+
next = val + props.step
|
|
788
|
+
if (props.max !== undefined) next = Math.min(next, props.max)
|
|
789
|
+
}
|
|
790
|
+
emit('update:value', next)
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
return h(
|
|
794
|
+
'div',
|
|
795
|
+
{
|
|
796
|
+
class: cn('bw-number-stepper', `bw-number-stepper--size-${props.size}`, String(cls || '')),
|
|
797
|
+
role: 'group',
|
|
798
|
+
'aria-label': props['aria-label'] || undefined,
|
|
799
|
+
'aria-labelledby': props['aria-labelledby'] || undefined,
|
|
800
|
+
},
|
|
801
|
+
[
|
|
802
|
+
h(
|
|
803
|
+
'button',
|
|
804
|
+
{
|
|
805
|
+
type: 'button',
|
|
806
|
+
class: cn('bw-number-stepper__button', 'bw-number-stepper__button--decrement'),
|
|
807
|
+
'aria-label': props.decrementLabel,
|
|
808
|
+
disabled: props.disabled || props.readOnly || atMin || undefined,
|
|
809
|
+
onClick: decrement,
|
|
810
|
+
},
|
|
811
|
+
[
|
|
812
|
+
h(
|
|
813
|
+
'svg',
|
|
814
|
+
{
|
|
815
|
+
class: 'bw-icon',
|
|
816
|
+
'aria-hidden': 'true',
|
|
817
|
+
width: '16',
|
|
818
|
+
height: '16',
|
|
819
|
+
viewBox: '0 0 16 16',
|
|
820
|
+
fill: 'none',
|
|
821
|
+
},
|
|
822
|
+
[h('path', { d: 'M4 8h8', stroke: 'currentColor', 'stroke-width': '1.5', 'stroke-linecap': 'round' })],
|
|
823
|
+
),
|
|
824
|
+
],
|
|
825
|
+
),
|
|
826
|
+
h('input', {
|
|
827
|
+
...inputAttrs,
|
|
828
|
+
type: 'number',
|
|
829
|
+
class: 'bw-number-stepper__input',
|
|
830
|
+
value: props.value,
|
|
831
|
+
min: props.min,
|
|
832
|
+
max: props.max,
|
|
833
|
+
step: props.step,
|
|
834
|
+
disabled: props.disabled || undefined,
|
|
835
|
+
readonly: props.readOnly || undefined,
|
|
836
|
+
onInput: (e: Event) => {
|
|
837
|
+
const raw = (e.target as HTMLInputElement).value
|
|
838
|
+
emit('update:value', raw === '' ? undefined : parseFloat(raw))
|
|
839
|
+
},
|
|
840
|
+
onKeydown: (e: KeyboardEvent) => {
|
|
841
|
+
const mn = props.min
|
|
842
|
+
const mx = props.max
|
|
843
|
+
if (e.key === 'Home' && mn !== undefined) {
|
|
844
|
+
e.preventDefault()
|
|
845
|
+
emit('update:value', mn)
|
|
846
|
+
} else if (e.key === 'End' && mx !== undefined) {
|
|
847
|
+
e.preventDefault()
|
|
848
|
+
emit('update:value', mx)
|
|
849
|
+
}
|
|
850
|
+
},
|
|
851
|
+
}),
|
|
852
|
+
h(
|
|
853
|
+
'button',
|
|
854
|
+
{
|
|
855
|
+
type: 'button',
|
|
856
|
+
class: cn('bw-number-stepper__button', 'bw-number-stepper__button--increment'),
|
|
857
|
+
'aria-label': props.incrementLabel,
|
|
858
|
+
disabled: props.disabled || props.readOnly || atMax || undefined,
|
|
859
|
+
onClick: increment,
|
|
860
|
+
},
|
|
861
|
+
[
|
|
862
|
+
h(
|
|
863
|
+
'svg',
|
|
864
|
+
{
|
|
865
|
+
class: 'bw-icon',
|
|
866
|
+
'aria-hidden': 'true',
|
|
867
|
+
width: '16',
|
|
868
|
+
height: '16',
|
|
869
|
+
viewBox: '0 0 16 16',
|
|
870
|
+
fill: 'none',
|
|
871
|
+
},
|
|
872
|
+
[h('path', { d: 'M8 4v8M4 8h8', stroke: 'currentColor', 'stroke-width': '1.5', 'stroke-linecap': 'round' })],
|
|
873
|
+
),
|
|
874
|
+
],
|
|
875
|
+
),
|
|
876
|
+
],
|
|
877
|
+
)
|
|
878
|
+
}
|
|
879
|
+
},
|
|
880
|
+
})
|
|
881
|
+
|
|
882
|
+
export const Topbar = defineComponent({
|
|
883
|
+
name: 'BwTopbar',
|
|
884
|
+
setup(_, { slots, attrs }) {
|
|
885
|
+
return () =>
|
|
886
|
+
h(
|
|
887
|
+
'header',
|
|
888
|
+
{ ...attrs, class: cn('bw-topbar', String(attrs.class || '')) },
|
|
889
|
+
slots.default?.(),
|
|
890
|
+
)
|
|
891
|
+
},
|
|
892
|
+
})
|
|
893
|
+
|
|
894
|
+
export type PageHeaderSurface = 'default' | 'tint'
|
|
895
|
+
|
|
896
|
+
export const PageHeader = defineComponent({
|
|
897
|
+
name: 'BwPageHeader',
|
|
898
|
+
props: {
|
|
899
|
+
title: { type: [String, Object] as PropType<unknown>, default: undefined },
|
|
900
|
+
description: { type: [String, Object] as PropType<unknown>, default: undefined },
|
|
901
|
+
surface: { type: String as PropType<PageHeaderSurface>, default: 'default' },
|
|
902
|
+
loading: { type: Boolean, default: false },
|
|
903
|
+
},
|
|
904
|
+
setup(props, { slots, attrs }) {
|
|
905
|
+
return () => {
|
|
906
|
+
const body = props.loading
|
|
907
|
+
? [
|
|
908
|
+
h('div', { class: 'bw-skeleton bw-skeleton--title', 'aria-hidden': 'true' }),
|
|
909
|
+
h('div', { class: 'bw-skeleton bw-skeleton--text', 'aria-hidden': 'true' }),
|
|
910
|
+
]
|
|
911
|
+
: h('div', { class: 'bw-page-header__titles' }, [
|
|
912
|
+
props.title != null
|
|
913
|
+
? h('h1', { class: 'bw-page-header__title' }, props.title as any)
|
|
914
|
+
: slots.title?.(),
|
|
915
|
+
slots.titleBadge?.(),
|
|
916
|
+
props.description != null
|
|
917
|
+
? h('p', { class: 'bw-page-header__description' }, props.description as any)
|
|
918
|
+
: slots.description?.(),
|
|
919
|
+
])
|
|
920
|
+
return h(
|
|
921
|
+
'header',
|
|
922
|
+
{
|
|
923
|
+
...attrs,
|
|
924
|
+
class: cn(
|
|
925
|
+
'bw-page-header',
|
|
926
|
+
props.surface === 'tint' && 'bw-page-header--surface-tint',
|
|
927
|
+
String(attrs.class || ''),
|
|
928
|
+
),
|
|
929
|
+
},
|
|
930
|
+
[slots.breadcrumb?.(), body, slots.actions?.(), slots.tabs?.()],
|
|
931
|
+
)
|
|
932
|
+
}
|
|
933
|
+
},
|
|
934
|
+
})
|
|
935
|
+
|
|
936
|
+
// --- Description list (D15 / R19) ---
|
|
937
|
+
|
|
938
|
+
type DescriptionListLayout = 'stacked' | 'inline'
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Description list root (`<dl>`). Mirrors the React `DescriptionList` contract
|
|
942
|
+
* (DDL-070). Pass `layout="inline"` and/or `divided` props; child term and
|
|
943
|
+
* details elements receive the correct BEM classes. Auto-wrap is not applied
|
|
944
|
+
* in the Vue adapter; wrap each pair in a `<div>` for inline and divided
|
|
945
|
+
* mode (DDL-003). Recorded as GAP-DDL-3 in the craft document.
|
|
946
|
+
*/
|
|
947
|
+
export const BwDescriptionList = defineComponent({
|
|
948
|
+
name: 'BwDescriptionList',
|
|
949
|
+
props: {
|
|
950
|
+
layout: { type: String as PropType<DescriptionListLayout>, default: 'stacked' },
|
|
951
|
+
divided: { type: Boolean, default: false },
|
|
952
|
+
},
|
|
953
|
+
setup(props, { slots, attrs }) {
|
|
954
|
+
return () =>
|
|
955
|
+
h(
|
|
956
|
+
'dl',
|
|
957
|
+
{
|
|
958
|
+
...attrs,
|
|
959
|
+
class: cn(
|
|
960
|
+
'bw-description-list',
|
|
961
|
+
props.layout === 'inline' && 'bw-description-list--inline',
|
|
962
|
+
props.divided && 'bw-description-list--divided',
|
|
963
|
+
String(attrs.class || ''),
|
|
964
|
+
),
|
|
965
|
+
},
|
|
966
|
+
slots.default?.(),
|
|
967
|
+
)
|
|
968
|
+
},
|
|
969
|
+
})
|
|
970
|
+
|
|
971
|
+
/** Description term (`<dt>`). Applies caption type role and muted ink (DDL-002, DDL-013). */
|
|
972
|
+
export const BwDescriptionTerm = defineComponent({
|
|
973
|
+
name: 'BwDescriptionTerm',
|
|
974
|
+
setup(_, { slots, attrs }) {
|
|
975
|
+
return () =>
|
|
976
|
+
h(
|
|
977
|
+
'dt',
|
|
978
|
+
{ ...attrs, class: cn('bw-description-list__term', 'bw-text-xs', String(attrs.class || '')) },
|
|
979
|
+
slots.default?.(),
|
|
980
|
+
)
|
|
981
|
+
},
|
|
982
|
+
})
|
|
983
|
+
|
|
984
|
+
/** Description details (`<dd>`). Applies body type role and full-fg ink (DDL-002, DDL-014). */
|
|
985
|
+
export const BwDescriptionDetails = defineComponent({
|
|
986
|
+
name: 'BwDescriptionDetails',
|
|
987
|
+
setup(_, { slots, attrs }) {
|
|
988
|
+
return () =>
|
|
989
|
+
h(
|
|
990
|
+
'dd',
|
|
991
|
+
{ ...attrs, class: cn('bw-description-list__details', 'bw-text-md', String(attrs.class || '')) },
|
|
992
|
+
slots.default?.(), )
|
|
993
|
+
},
|
|
994
|
+
})
|
|
995
|
+
|
|
996
|
+
export type CopyButtonSize = InputSize
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* Copy-to-clipboard button (docs/components/copy-button.md). Consumer supplies
|
|
1000
|
+
* name, outcome strings and icon slot. No English defaults.
|
|
1001
|
+
*/
|
|
1002
|
+
export const CopyButton = defineComponent({
|
|
1003
|
+
name: 'BwCopyButton',
|
|
1004
|
+
inheritAttrs: false,
|
|
1005
|
+
props: {
|
|
1006
|
+
size: { type: String as () => CopyButtonSize, default: 'md' },
|
|
1007
|
+
value: { type: String, default: undefined },
|
|
1008
|
+
target: { type: String, default: undefined },
|
|
1009
|
+
successLabel: { type: String, required: true },
|
|
1010
|
+
errorLabel: { type: String, required: true },
|
|
1011
|
+
label: { type: String, default: undefined },
|
|
1012
|
+
disabled: { type: Boolean, default: false },
|
|
1013
|
+
},
|
|
1014
|
+
emits: ['copy'],
|
|
1015
|
+
setup(props, { attrs, slots, emit }) {
|
|
1016
|
+
const state = ref<'idle' | 'copied' | 'failed'>('idle')
|
|
1017
|
+
const statusEl = ref<HTMLElement | null>(null)
|
|
1018
|
+
const hostEl = ref<HTMLButtonElement | null>(null)
|
|
1019
|
+
let resetTimer = 0
|
|
1020
|
+
bwCopySeq += 1
|
|
1021
|
+
const hostId = String(attrs.id || `bw-copy-vue-${bwCopySeq}`)
|
|
1022
|
+
|
|
1023
|
+
function announce(message: string) {
|
|
1024
|
+
const status = statusEl.value
|
|
1025
|
+
if (!status) return
|
|
1026
|
+
status.textContent = ''
|
|
1027
|
+
if (!message) return
|
|
1028
|
+
if (typeof requestAnimationFrame !== 'function') {
|
|
1029
|
+
status.textContent = message
|
|
1030
|
+
return
|
|
1031
|
+
}
|
|
1032
|
+
requestAnimationFrame(() => {
|
|
1033
|
+
status.textContent = message
|
|
1034
|
+
})
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
function copyViaExecCommand(text: string): boolean {
|
|
1038
|
+
const textarea = document.createElement('textarea')
|
|
1039
|
+
textarea.value = text
|
|
1040
|
+
textarea.style.position = 'fixed'
|
|
1041
|
+
textarea.style.top = '0'
|
|
1042
|
+
textarea.style.left = '-9999px'
|
|
1043
|
+
textarea.setAttribute('readonly', '')
|
|
1044
|
+
document.body.appendChild(textarea)
|
|
1045
|
+
textarea.select()
|
|
1046
|
+
textarea.setSelectionRange(0, textarea.value.length)
|
|
1047
|
+
let ok = false
|
|
1048
|
+
try {
|
|
1049
|
+
ok = document.execCommand('copy')
|
|
1050
|
+
} catch {
|
|
1051
|
+
ok = false
|
|
1052
|
+
} finally {
|
|
1053
|
+
document.body.removeChild(textarea)
|
|
1054
|
+
}
|
|
1055
|
+
return ok
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
function resolveText(): string | null {
|
|
1059
|
+
if (props.value !== undefined) return props.value
|
|
1060
|
+
if (props.target) {
|
|
1061
|
+
const el = document.querySelector(props.target)
|
|
1062
|
+
if (!el) return null
|
|
1063
|
+
if (
|
|
1064
|
+
el instanceof HTMLInputElement ||
|
|
1065
|
+
el instanceof HTMLTextAreaElement ||
|
|
1066
|
+
el instanceof HTMLSelectElement
|
|
1067
|
+
) {
|
|
1068
|
+
return el.value
|
|
1069
|
+
}
|
|
1070
|
+
return el.textContent || ''
|
|
1071
|
+
}
|
|
1072
|
+
return null
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
async function onClick() {
|
|
1076
|
+
if (props.disabled) return
|
|
1077
|
+
const host = hostEl.value
|
|
1078
|
+
const text = resolveText()
|
|
1079
|
+
let ok = false
|
|
1080
|
+
if (text !== null) {
|
|
1081
|
+
if (navigator.clipboard?.writeText) {
|
|
1082
|
+
try {
|
|
1083
|
+
await navigator.clipboard.writeText(text)
|
|
1084
|
+
ok = true
|
|
1085
|
+
} catch {
|
|
1086
|
+
ok = false
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
if (!ok) ok = copyViaExecCommand(text)
|
|
1090
|
+
}
|
|
1091
|
+
announce(ok ? props.successLabel : props.errorLabel)
|
|
1092
|
+
state.value = ok ? 'copied' : 'failed'
|
|
1093
|
+
emit('copy', ok)
|
|
1094
|
+
host?.dispatchEvent(
|
|
1095
|
+
new CustomEvent('bw:copy', { detail: { id: hostId, ok }, bubbles: true }),
|
|
1096
|
+
)
|
|
1097
|
+
if (resetTimer) window.clearTimeout(resetTimer)
|
|
1098
|
+
resetTimer = window.setTimeout(() => {
|
|
1099
|
+
state.value = 'idle'
|
|
1100
|
+
}, 1500)
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
return () => {
|
|
1104
|
+
const { class: cls, ...rest } = attrs
|
|
1105
|
+
return h(
|
|
1106
|
+
'button',
|
|
1107
|
+
{
|
|
1108
|
+
...rest,
|
|
1109
|
+
id: hostId,
|
|
1110
|
+
ref: hostEl,
|
|
1111
|
+
type: 'button',
|
|
1112
|
+
disabled: props.disabled,
|
|
1113
|
+
'data-bw-copy-state': state.value,
|
|
1114
|
+
'data-bw-copy-success': props.successLabel,
|
|
1115
|
+
'data-bw-copy-error': props.errorLabel,
|
|
1116
|
+
...(props.value !== undefined ? { 'data-bw-copy-value': props.value } : {}),
|
|
1117
|
+
...(props.target ? { 'data-bw-copy-target': props.target } : {}),
|
|
1118
|
+
class: cn('bw-copy', `bw-copy--size-${props.size}`, String(cls || '')),
|
|
1119
|
+
onClick,
|
|
1120
|
+
},
|
|
1121
|
+
[
|
|
1122
|
+
slots.default
|
|
1123
|
+
? h('span', { class: 'bw-copy__icon', 'aria-hidden': 'true' }, slots.default())
|
|
1124
|
+
: null,
|
|
1125
|
+
h('span', { class: 'bw-copy__mark bw-copy__mark--done', 'aria-hidden': 'true' }, [
|
|
1126
|
+
h('svg', { viewBox: '0 0 16 16' }, [h('path', { d: 'M3.5 8.5 6.5 11.5 12.5 4.5' })]),
|
|
1127
|
+
]),
|
|
1128
|
+
h('span', { class: 'bw-copy__mark bw-copy__mark--fail', 'aria-hidden': 'true' }, [
|
|
1129
|
+
h('svg', { viewBox: '0 0 16 16' }, [
|
|
1130
|
+
h('path', { d: 'M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5' }),
|
|
1131
|
+
]),
|
|
1132
|
+
]),
|
|
1133
|
+
props.label ? h('span', { class: 'bw-copy__label' }, props.label) : null,
|
|
1134
|
+
h('span', {
|
|
1135
|
+
class: 'bw-copy__status bw-visually-hidden',
|
|
1136
|
+
'aria-live': 'polite',
|
|
1137
|
+
ref: statusEl,
|
|
1138
|
+
}),
|
|
1139
|
+
],
|
|
1140
|
+
)
|
|
1141
|
+
}
|
|
1142
|
+
},
|
|
1143
|
+
})
|