@bwui/vue 0.1.8 → 0.1.11

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.
@@ -1,4 +1,5 @@
1
- import { defineComponent, h } from 'vue';
1
+ let bwCopySeq = 0;
2
+ import { defineComponent, h, ref } from 'vue';
2
3
  import { cn } from './cn';
3
4
  export const Button = defineComponent({
4
5
  name: 'BwButton',
@@ -30,29 +31,126 @@ export const ButtonLink = defineComponent({
30
31
  }, slots.default?.());
31
32
  },
32
33
  });
34
+ function resolveBadgeVariant(variant) {
35
+ if (variant === 'default')
36
+ return 'neutral';
37
+ if (variant === 'secondary')
38
+ return 'outline';
39
+ return variant;
40
+ }
41
+ /** Badge (docs/components/badge.md): status tag / pace pill. */
33
42
  export const Badge = defineComponent({
34
43
  name: 'BwBadge',
35
44
  props: {
36
- variant: { type: String, default: 'default' },
45
+ variant: { type: String, default: 'neutral' },
46
+ size: { type: String, default: 'md' },
37
47
  },
38
48
  setup(props, { slots, attrs }) {
39
- return () => h('span', { ...attrs, class: cn('bw-badge', `bw-badge--${props.variant}`, String(attrs.class || '')) }, slots.default?.());
49
+ return () => h('span', {
50
+ ...attrs,
51
+ class: cn('bw-badge', `bw-badge--${resolveBadgeVariant(props.variant)}`, `bw-badge--size-${props.size}`, String(attrs.class || '')),
52
+ }, slots.default?.());
53
+ },
54
+ });
55
+ export const Chip = defineComponent({
56
+ name: 'BwChip',
57
+ inheritAttrs: false,
58
+ props: {
59
+ size: { type: String, default: 'md' },
60
+ variant: { type: String, default: 'neutral' },
61
+ selected: { type: Boolean, default: false },
62
+ toggle: { type: Boolean, default: false },
63
+ href: { type: String, default: undefined },
64
+ dismissLabel: { type: String, default: undefined },
65
+ },
66
+ emits: ['dismiss'],
67
+ setup(props, { slots, attrs, emit }) {
68
+ return () => {
69
+ const { class: cls, ...rest } = attrs;
70
+ const classes = cn('bw-chip', `bw-chip--${props.variant}`, `bw-chip--size-${props.size}`, props.selected && 'bw-chip--selected', String(cls || ''));
71
+ const label = h('span', { class: 'bw-chip__label' }, slots.default?.());
72
+ if (props.dismissLabel) {
73
+ return h('span', { ...rest, class: classes }, [
74
+ label,
75
+ h('button', {
76
+ type: 'button',
77
+ class: 'bw-chip__close',
78
+ 'aria-label': props.dismissLabel,
79
+ onClick: () => emit('dismiss'),
80
+ }, slots.close?.()),
81
+ ]);
82
+ }
83
+ if (props.href) {
84
+ return h('a', {
85
+ ...rest,
86
+ class: classes,
87
+ href: props.href,
88
+ 'aria-current': props.selected ? 'true' : undefined,
89
+ }, [label]);
90
+ }
91
+ if (props.toggle || props.selected) {
92
+ return h('button', {
93
+ ...rest,
94
+ type: 'button',
95
+ class: classes,
96
+ 'aria-pressed': props.selected,
97
+ }, [label]);
98
+ }
99
+ return h('span', { ...rest, class: classes }, [label]);
100
+ };
40
101
  },
41
102
  });
103
+ // Card (docs/components/card.md): the same modifier grammar as React. `md` is
104
+ // the base inset and emits a class only when asked for; `href` renders an
105
+ // anchor and implies interactive; `bordered` is the APP-002 flat hairline mode.
42
106
  export const Card = defineComponent({
43
107
  name: 'BwCard',
44
- setup(_, { slots, attrs }) {
45
- return () => h('div', { ...attrs, class: cn('bw-card', String(attrs.class || '')) }, slots.default?.());
108
+ inheritAttrs: false,
109
+ props: {
110
+ size: { type: String, default: undefined },
111
+ bordered: { type: Boolean, default: false },
112
+ surface: { type: String, default: undefined },
113
+ elevation: { type: String, default: undefined },
114
+ radius: { type: String, default: undefined },
115
+ interactive: { type: Boolean, default: false },
116
+ href: { type: String, default: undefined },
117
+ },
118
+ setup(props, { slots, attrs }) {
119
+ return () => {
120
+ const linked = props.href !== undefined;
121
+ const classes = cn('bw-card', (props.interactive || linked) && 'bw-card--interactive', props.bordered && 'bw-card--bordered', props.size && `bw-card--size-${props.size}`, props.radius && props.radius !== 'default' && props.radius !== 'lg' && `bw-card--radius-${props.radius}`, props.surface && props.surface !== 'default' && `bw-card--surface-${props.surface}`, props.elevation && props.elevation !== '1' && `bw-card--elevation-${props.elevation}`, String(attrs.class || ''));
122
+ return h(linked ? 'a' : 'div', { ...attrs, class: classes, ...(linked ? { href: props.href } : {}) }, slots.default?.());
123
+ };
46
124
  },
47
125
  });
48
126
  export const Alert = defineComponent({
49
127
  name: 'BwAlert',
50
- props: { variant: { type: String, default: 'default' } },
128
+ props: {
129
+ variant: { type: String, default: 'info' },
130
+ },
131
+ setup(props, { slots, attrs }) {
132
+ const allowed = new Set(['info', 'success', 'warning', 'danger']);
133
+ return () => {
134
+ const variant = allowed.has(props.variant) ? props.variant : 'info';
135
+ return h('div', {
136
+ ...attrs,
137
+ role: 'alert',
138
+ class: cn('bw-alert', `bw-alert--${variant}`, String(attrs.class || '')),
139
+ }, slots.default?.());
140
+ };
141
+ },
142
+ });
143
+ export const Banner = defineComponent({
144
+ name: 'BwBanner',
145
+ props: {
146
+ variant: { type: String, default: 'info' },
147
+ edge: { type: String, default: 'top' },
148
+ },
51
149
  setup(props, { slots, attrs }) {
52
150
  return () => h('div', {
53
151
  ...attrs,
54
- role: 'alert',
55
- class: cn('bw-alert', props.variant !== 'default' && `bw-alert--${props.variant}`, String(attrs.class || '')),
152
+ role: 'region',
153
+ class: cn('bw-banner', `bw-banner--${props.variant}`, `bw-banner--edge-${props.edge}`, String(attrs.class || '')),
56
154
  }, slots.default?.());
57
155
  },
58
156
  });
@@ -64,10 +162,53 @@ function div(name, className) {
64
162
  },
65
163
  });
66
164
  }
67
- export const Stack = div('BwStack', 'bw-stack');
68
- export const Cluster = div('BwCluster', 'bw-cluster');
69
- export const Grid = div('BwGrid', 'bw-grid');
165
+ function p(name, className) {
166
+ return defineComponent({
167
+ name,
168
+ setup(_, { slots, attrs }) {
169
+ return () => h('p', { ...attrs, class: cn(className, String(attrs.class || '')) }, slots.default?.());
170
+ },
171
+ });
172
+ }
173
+ export const AlertTitle = p('BwAlertTitle', 'bw-alert__title');
174
+ export const AlertBody = p('BwAlertBody', 'bw-alert__message');
175
+ function layoutWithGap(name, baseClass) {
176
+ return defineComponent({
177
+ name,
178
+ props: {
179
+ gap: { type: String, default: 'md' },
180
+ },
181
+ setup(props, { slots, attrs }) {
182
+ return () => h('div', {
183
+ ...attrs,
184
+ class: cn(baseClass, props.gap !== 'md' && `${baseClass}--gap-${props.gap}`, String(attrs.class || '')),
185
+ }, slots.default?.());
186
+ },
187
+ });
188
+ }
189
+ export const Stack = layoutWithGap('BwStack', 'bw-stack');
190
+ export const Cluster = layoutWithGap('BwCluster', 'bw-cluster');
191
+ export const Grid = layoutWithGap('BwGrid', 'bw-grid');
192
+ export const Inset = defineComponent({
193
+ name: 'BwInset',
194
+ props: {
195
+ size: { type: String, default: 'md' },
196
+ },
197
+ setup(props, { slots, attrs }) {
198
+ return () => h('div', {
199
+ ...attrs,
200
+ class: cn('bw-inset', props.size !== 'md' && `bw-inset--size-${props.size}`, String(attrs.class || '')),
201
+ }, slots.default?.());
202
+ },
203
+ });
70
204
  export const Container = div('BwContainer', 'bw-container');
205
+ export const Centre = div('BwCentre', 'bw-centre');
206
+ export const VisuallyHidden = defineComponent({
207
+ name: 'BwVisuallyHidden',
208
+ setup(_, { slots, attrs }) {
209
+ return () => h('span', { ...attrs, class: cn('bw-visually-hidden', String(attrs.class || '')) }, slots.default?.());
210
+ },
211
+ });
71
212
  export const Field = div('BwField', 'bw-field');
72
213
  export const FormActions = div('BwFormActions', 'bw-form__actions bw-cluster');
73
214
  export const Form = defineComponent({
@@ -85,7 +226,7 @@ export const Label = defineComponent({
85
226
  export const Hint = defineComponent({
86
227
  name: 'BwHint',
87
228
  setup(_, { slots, attrs }) {
88
- return () => h('p', { ...attrs, class: cn('bw-field__hint', String(attrs.class || '')) }, slots.default?.());
229
+ return () => h('p', { ...attrs, class: cn('bw-field__help', 'bw-field__hint', String(attrs.class || '')) }, slots.default?.());
89
230
  },
90
231
  });
91
232
  export const FieldError = defineComponent({
@@ -97,56 +238,191 @@ export const FieldError = defineComponent({
97
238
  export const Input = defineComponent({
98
239
  name: 'BwInput',
99
240
  inheritAttrs: false,
100
- setup(_, { attrs }) {
101
- return () => h('input', { ...attrs, class: cn('bw-input', String(attrs.class || '')) });
241
+ props: {
242
+ size: { type: String, default: 'md' },
243
+ },
244
+ setup(props, { attrs }) {
245
+ return () => h('input', {
246
+ ...attrs,
247
+ class: cn('bw-input', `bw-input--size-${props.size}`, String(attrs.class || '')),
248
+ });
102
249
  },
103
250
  });
104
251
  export const Textarea = defineComponent({
105
252
  name: 'BwTextarea',
106
253
  inheritAttrs: false,
107
- setup(_, { attrs }) {
108
- return () => h('textarea', { ...attrs, class: cn('bw-textarea', String(attrs.class || '')) });
254
+ props: {
255
+ size: { type: String, default: 'md' },
256
+ },
257
+ setup(props, { attrs }) {
258
+ return () => h('textarea', {
259
+ ...attrs,
260
+ class: cn('bw-input', 'bw-textarea', `bw-input--size-${props.size}`, String(attrs.class || '')),
261
+ });
262
+ },
263
+ });
264
+ /**
265
+ * Switch (docs/components/switch.md): native checkbox with role="switch"
266
+ * inside a bw-switch root. Attributes land on the input (name, id, checked,
267
+ * disabled, aria-label); `class` lands on the root. The accessible name is the
268
+ * consumer's.
269
+ */
270
+ export const Switch = defineComponent({
271
+ name: 'BwSwitch',
272
+ inheritAttrs: false,
273
+ props: {
274
+ size: { type: String, default: 'md' },
275
+ },
276
+ setup(props, { attrs }) {
277
+ return () => {
278
+ const { class: cls, ...rest } = attrs;
279
+ return h('span', { class: cn('bw-switch', `bw-switch--size-${props.size}`, String(cls || '')) }, [
280
+ h('input', { ...rest, type: 'checkbox', role: 'switch' }),
281
+ h('span', { class: 'bw-switch__track', 'aria-hidden': 'true' }),
282
+ h('span', { class: 'bw-switch__thumb', 'aria-hidden': 'true' }),
283
+ ]);
284
+ };
109
285
  },
110
286
  });
111
287
  export const Select = defineComponent({
112
288
  name: 'BwSelect',
113
289
  inheritAttrs: false,
114
- setup(_, { slots, attrs }) {
115
- return () => h('select', { ...attrs, class: cn('bw-select', String(attrs.class || '')) }, slots.default?.());
290
+ props: {
291
+ size: { type: String, default: 'md' },
292
+ },
293
+ setup(props, { slots, attrs }) {
294
+ return () => h('select', {
295
+ ...attrs,
296
+ class: cn('bw-select', `bw-select--size-${props.size}`, String(attrs.class || '')),
297
+ }, slots.default?.());
116
298
  },
117
299
  });
118
300
  export const Checkbox = defineComponent({
119
301
  name: 'BwCheckbox',
120
302
  inheritAttrs: false,
121
- setup(_, { attrs }) {
122
- return () => h('input', { ...attrs, type: 'checkbox', class: cn('bw-checkbox', String(attrs.class || '')) });
303
+ props: {
304
+ size: { type: String, default: 'md' },
305
+ indeterminate: { type: Boolean, default: false },
306
+ },
307
+ setup(props, { attrs }) {
308
+ return () => h('input', {
309
+ ...attrs,
310
+ type: 'checkbox',
311
+ indeterminate: props.indeterminate,
312
+ class: cn('bw-checkbox', `bw-checkbox--size-${props.size}`, String(attrs.class || '')),
313
+ });
123
314
  },
124
315
  });
125
316
  export const Radio = defineComponent({
126
317
  name: 'BwRadio',
127
318
  inheritAttrs: false,
128
- setup(_, { attrs }) {
129
- return () => h('input', { ...attrs, type: 'radio', class: cn('bw-radio', String(attrs.class || '')) });
319
+ props: {
320
+ size: { type: String, default: 'md' },
321
+ },
322
+ setup(props, { attrs }) {
323
+ return () => h('input', {
324
+ ...attrs,
325
+ type: 'radio',
326
+ class: cn('bw-radio', `bw-radio--size-${props.size}`, String(attrs.class || '')),
327
+ });
328
+ },
329
+ });
330
+ function sliderPercent(value, min, max) {
331
+ if (max === min)
332
+ return 0;
333
+ return ((value - min) / (max - min)) * 100;
334
+ }
335
+ /**
336
+ * Slider (docs/components/slider.md): native range inside bw-slider root.
337
+ * Attributes land on the input; `class` lands on the root. Fill sync via
338
+ * --bw-slider-percent (SLD-034).
339
+ */
340
+ export const Slider = defineComponent({
341
+ name: 'BwSlider',
342
+ inheritAttrs: false,
343
+ props: {
344
+ size: { type: String, default: 'md' },
345
+ },
346
+ setup(props, { attrs }) {
347
+ return () => {
348
+ const { class: cls, style, min = 0, max = 100, value, modelValue, ...rest } = attrs;
349
+ const minN = Number(min);
350
+ const maxN = Number(max);
351
+ const current = value !== undefined
352
+ ? Number(value)
353
+ : modelValue !== undefined
354
+ ? Number(modelValue)
355
+ : minN;
356
+ const percent = sliderPercent(current, minN, maxN);
357
+ const onInput = (event) => {
358
+ const input = event.currentTarget;
359
+ const root = input.parentElement;
360
+ if (root) {
361
+ root.style.setProperty('--bw-slider-percent', String(sliderPercent(input.valueAsNumber, Number(input.min), Number(input.max))));
362
+ }
363
+ const prior = rest.onInput;
364
+ prior?.(event);
365
+ };
366
+ const mergedStyle = {
367
+ ...(typeof style === 'object' && style ? style : {}),
368
+ '--bw-slider-percent': percent,
369
+ };
370
+ return h('span', { class: cn('bw-slider', `bw-slider--size-${props.size}`, String(cls || '')), style: mergedStyle }, [
371
+ h('input', {
372
+ ...rest,
373
+ min,
374
+ max,
375
+ value,
376
+ type: 'range',
377
+ class: 'bw-slider__input',
378
+ onInput,
379
+ }),
380
+ ]);
381
+ };
130
382
  },
131
383
  });
132
384
  export const TimeInput = defineComponent({
133
385
  name: 'BwTimeInput',
134
386
  inheritAttrs: false,
135
- setup(_, { attrs }) {
136
- return () => h('input', { ...attrs, type: 'time', class: cn('bw-input', String(attrs.class || '')) });
387
+ props: {
388
+ size: { type: String, default: 'md' },
389
+ },
390
+ setup(props, { attrs }) {
391
+ return () => h('input', {
392
+ ...attrs,
393
+ type: 'time',
394
+ class: cn('bw-input', `bw-input--size-${props.size}`, String(attrs.class || '')),
395
+ });
137
396
  },
138
397
  });
139
398
  export const DateTimeInput = defineComponent({
140
399
  name: 'BwDateTimeInput',
141
400
  inheritAttrs: false,
142
- setup(_, { attrs }) {
401
+ props: {
402
+ size: { type: String, default: 'md' },
403
+ },
404
+ setup(props, { attrs }) {
143
405
  return () => h('input', {
144
406
  ...attrs,
145
407
  type: 'datetime-local',
146
- class: cn('bw-input', String(attrs.class || '')),
408
+ class: cn('bw-input', `bw-input--size-${props.size}`, String(attrs.class || '')),
147
409
  });
148
410
  },
149
411
  });
412
+ export const InputGroup = defineComponent({
413
+ name: 'BwInputGroup',
414
+ inheritAttrs: false,
415
+ props: {
416
+ size: { type: String, default: 'md' },
417
+ },
418
+ setup(props, { slots, attrs }) {
419
+ return () => h('div', {
420
+ ...attrs,
421
+ role: 'group',
422
+ class: cn('bw-input-group', `bw-input-group--size-${props.size}`, String(attrs.class || '')),
423
+ }, slots.default?.());
424
+ },
425
+ });
150
426
  export const SkipLink = defineComponent({
151
427
  name: 'BwSkipLink',
152
428
  props: { href: { type: String, default: '#main' } },
@@ -171,3 +447,381 @@ export const ThemeToggle = defineComponent({
171
447
  }, 'Theme');
172
448
  },
173
449
  });
450
+ /**
451
+ * Segmented control (docs/components/segmented.md): role=group of buttons with
452
+ * aria-pressed. Size re-points the five role variables. Accessible name is the
453
+ * consumer's (aria-label / aria-labelledby on the root).
454
+ */
455
+ export const Segmented = defineComponent({
456
+ name: 'BwSegmented',
457
+ props: {
458
+ size: { type: String, default: 'md' },
459
+ value: { type: String, required: true },
460
+ options: { type: Array, required: true },
461
+ disabled: { type: Boolean, default: false },
462
+ },
463
+ emits: ['update:value'],
464
+ setup(props, { attrs, emit }) {
465
+ return () => h('div', {
466
+ ...attrs,
467
+ role: 'group',
468
+ class: cn('bw-segmented', `bw-segmented--size-${props.size}`, String(attrs.class || '')),
469
+ }, props.options.map((option) => {
470
+ const pressed = option.value === props.value;
471
+ const itemDisabled = props.disabled || Boolean(option.disabled);
472
+ return h('button', {
473
+ key: option.value,
474
+ type: 'button',
475
+ class: 'bw-segmented__item',
476
+ 'aria-pressed': pressed,
477
+ disabled: itemDisabled || undefined,
478
+ onClick: () => {
479
+ if (itemDisabled || pressed)
480
+ return;
481
+ emit('update:value', option.value);
482
+ },
483
+ }, option.label);
484
+ }));
485
+ },
486
+ });
487
+ /**
488
+ * NumberStepper (docs/components/number-stepper.md). A decrement button, a
489
+ * native `<input type="number">`, and an increment button in a connected group.
490
+ * Root `role="group"` must be labelled by the consumer via `aria-label` or
491
+ * `aria-labelledby`. Component name `BwNumberStepper`. `class` lands on the root;
492
+ * all other attributes land on the input unless handled as a prop.
493
+ */
494
+ export const NumberStepper = defineComponent({
495
+ name: 'BwNumberStepper',
496
+ inheritAttrs: false,
497
+ props: {
498
+ size: { type: String, default: 'md' },
499
+ value: { type: Number, default: undefined },
500
+ min: { type: Number, default: undefined },
501
+ max: { type: Number, default: undefined },
502
+ step: { type: Number, default: 1 },
503
+ disabled: { type: Boolean, default: false },
504
+ readOnly: { type: Boolean, default: false },
505
+ decrementLabel: { type: String, default: 'Decrease' },
506
+ incrementLabel: { type: String, default: 'Increase' },
507
+ 'aria-label': { type: String, default: undefined },
508
+ 'aria-labelledby': { type: String, default: undefined },
509
+ },
510
+ emits: ['update:value'],
511
+ setup(props, { attrs, emit }) {
512
+ return () => {
513
+ const { class: cls, ...inputAttrs } = attrs;
514
+ const val = props.value;
515
+ const atMin = val !== undefined && props.min !== undefined && val <= props.min;
516
+ const atMax = val !== undefined && props.max !== undefined && val >= props.max;
517
+ function decrement() {
518
+ if (props.disabled || props.readOnly)
519
+ return;
520
+ let next;
521
+ if (val === undefined) {
522
+ next = props.min !== undefined ? props.min : 0;
523
+ }
524
+ else {
525
+ next = val - props.step;
526
+ if (props.min !== undefined)
527
+ next = Math.max(next, props.min);
528
+ }
529
+ emit('update:value', next);
530
+ }
531
+ function increment() {
532
+ if (props.disabled || props.readOnly)
533
+ return;
534
+ let next;
535
+ if (val === undefined) {
536
+ next = props.max !== undefined ? props.max : props.step;
537
+ }
538
+ else {
539
+ next = val + props.step;
540
+ if (props.max !== undefined)
541
+ next = Math.min(next, props.max);
542
+ }
543
+ emit('update:value', next);
544
+ }
545
+ return h('div', {
546
+ class: cn('bw-number-stepper', `bw-number-stepper--size-${props.size}`, String(cls || '')),
547
+ role: 'group',
548
+ 'aria-label': props['aria-label'] || undefined,
549
+ 'aria-labelledby': props['aria-labelledby'] || undefined,
550
+ }, [
551
+ h('button', {
552
+ type: 'button',
553
+ class: cn('bw-number-stepper__button', 'bw-number-stepper__button--decrement'),
554
+ 'aria-label': props.decrementLabel,
555
+ disabled: props.disabled || props.readOnly || atMin || undefined,
556
+ onClick: decrement,
557
+ }, [
558
+ h('svg', {
559
+ class: 'bw-icon',
560
+ 'aria-hidden': 'true',
561
+ width: '16',
562
+ height: '16',
563
+ viewBox: '0 0 16 16',
564
+ fill: 'none',
565
+ }, [h('path', { d: 'M4 8h8', stroke: 'currentColor', 'stroke-width': '1.5', 'stroke-linecap': 'round' })]),
566
+ ]),
567
+ h('input', {
568
+ ...inputAttrs,
569
+ type: 'number',
570
+ class: 'bw-number-stepper__input',
571
+ value: props.value,
572
+ min: props.min,
573
+ max: props.max,
574
+ step: props.step,
575
+ disabled: props.disabled || undefined,
576
+ readonly: props.readOnly || undefined,
577
+ onInput: (e) => {
578
+ const raw = e.target.value;
579
+ emit('update:value', raw === '' ? undefined : parseFloat(raw));
580
+ },
581
+ onKeydown: (e) => {
582
+ const mn = props.min;
583
+ const mx = props.max;
584
+ if (e.key === 'Home' && mn !== undefined) {
585
+ e.preventDefault();
586
+ emit('update:value', mn);
587
+ }
588
+ else if (e.key === 'End' && mx !== undefined) {
589
+ e.preventDefault();
590
+ emit('update:value', mx);
591
+ }
592
+ },
593
+ }),
594
+ h('button', {
595
+ type: 'button',
596
+ class: cn('bw-number-stepper__button', 'bw-number-stepper__button--increment'),
597
+ 'aria-label': props.incrementLabel,
598
+ disabled: props.disabled || props.readOnly || atMax || undefined,
599
+ onClick: increment,
600
+ }, [
601
+ h('svg', {
602
+ class: 'bw-icon',
603
+ 'aria-hidden': 'true',
604
+ width: '16',
605
+ height: '16',
606
+ viewBox: '0 0 16 16',
607
+ fill: 'none',
608
+ }, [h('path', { d: 'M8 4v8M4 8h8', stroke: 'currentColor', 'stroke-width': '1.5', 'stroke-linecap': 'round' })]),
609
+ ]),
610
+ ]);
611
+ };
612
+ },
613
+ });
614
+ export const Topbar = defineComponent({
615
+ name: 'BwTopbar',
616
+ setup(_, { slots, attrs }) {
617
+ return () => h('header', { ...attrs, class: cn('bw-topbar', String(attrs.class || '')) }, slots.default?.());
618
+ },
619
+ });
620
+ export const PageHeader = defineComponent({
621
+ name: 'BwPageHeader',
622
+ props: {
623
+ title: { type: [String, Object], default: undefined },
624
+ description: { type: [String, Object], default: undefined },
625
+ surface: { type: String, default: 'default' },
626
+ loading: { type: Boolean, default: false },
627
+ },
628
+ setup(props, { slots, attrs }) {
629
+ return () => {
630
+ const body = props.loading
631
+ ? [
632
+ h('div', { class: 'bw-skeleton bw-skeleton--title', 'aria-hidden': 'true' }),
633
+ h('div', { class: 'bw-skeleton bw-skeleton--text', 'aria-hidden': 'true' }),
634
+ ]
635
+ : h('div', { class: 'bw-page-header__titles' }, [
636
+ props.title != null
637
+ ? h('h1', { class: 'bw-page-header__title' }, props.title)
638
+ : slots.title?.(),
639
+ slots.titleBadge?.(),
640
+ props.description != null
641
+ ? h('p', { class: 'bw-page-header__description' }, props.description)
642
+ : slots.description?.(),
643
+ ]);
644
+ return h('header', {
645
+ ...attrs,
646
+ class: cn('bw-page-header', props.surface === 'tint' && 'bw-page-header--surface-tint', String(attrs.class || '')),
647
+ }, [slots.breadcrumb?.(), body, slots.actions?.(), slots.tabs?.()]);
648
+ };
649
+ },
650
+ });
651
+ /**
652
+ * Description list root (`<dl>`). Mirrors the React `DescriptionList` contract
653
+ * (DDL-070). Pass `layout="inline"` and/or `divided` props; child term and
654
+ * details elements receive the correct BEM classes. Auto-wrap is not applied
655
+ * in the Vue adapter; wrap each pair in a `<div>` for inline and divided
656
+ * mode (DDL-003). Recorded as GAP-DDL-3 in the craft document.
657
+ */
658
+ export const BwDescriptionList = defineComponent({
659
+ name: 'BwDescriptionList',
660
+ props: {
661
+ layout: { type: String, default: 'stacked' },
662
+ divided: { type: Boolean, default: false },
663
+ },
664
+ setup(props, { slots, attrs }) {
665
+ return () => h('dl', {
666
+ ...attrs,
667
+ class: cn('bw-description-list', props.layout === 'inline' && 'bw-description-list--inline', props.divided && 'bw-description-list--divided', String(attrs.class || '')),
668
+ }, slots.default?.());
669
+ },
670
+ });
671
+ /** Description term (`<dt>`). Applies caption type role and muted ink (DDL-002, DDL-013). */
672
+ export const BwDescriptionTerm = defineComponent({
673
+ name: 'BwDescriptionTerm',
674
+ setup(_, { slots, attrs }) {
675
+ return () => h('dt', { ...attrs, class: cn('bw-description-list__term', 'bw-text-xs', String(attrs.class || '')) }, slots.default?.());
676
+ },
677
+ });
678
+ /** Description details (`<dd>`). Applies body type role and full-fg ink (DDL-002, DDL-014). */
679
+ export const BwDescriptionDetails = defineComponent({
680
+ name: 'BwDescriptionDetails',
681
+ setup(_, { slots, attrs }) {
682
+ return () => h('dd', { ...attrs, class: cn('bw-description-list__details', 'bw-text-md', String(attrs.class || '')) }, slots.default?.());
683
+ },
684
+ });
685
+ /**
686
+ * Copy-to-clipboard button (docs/components/copy-button.md). Consumer supplies
687
+ * name, outcome strings and icon slot. No English defaults.
688
+ */
689
+ export const CopyButton = defineComponent({
690
+ name: 'BwCopyButton',
691
+ inheritAttrs: false,
692
+ props: {
693
+ size: { type: String, default: 'md' },
694
+ value: { type: String, default: undefined },
695
+ target: { type: String, default: undefined },
696
+ successLabel: { type: String, required: true },
697
+ errorLabel: { type: String, required: true },
698
+ label: { type: String, default: undefined },
699
+ disabled: { type: Boolean, default: false },
700
+ },
701
+ emits: ['copy'],
702
+ setup(props, { attrs, slots, emit }) {
703
+ const state = ref('idle');
704
+ const statusEl = ref(null);
705
+ const hostEl = ref(null);
706
+ let resetTimer = 0;
707
+ bwCopySeq += 1;
708
+ const hostId = String(attrs.id || `bw-copy-vue-${bwCopySeq}`);
709
+ function announce(message) {
710
+ const status = statusEl.value;
711
+ if (!status)
712
+ return;
713
+ status.textContent = '';
714
+ if (!message)
715
+ return;
716
+ if (typeof requestAnimationFrame !== 'function') {
717
+ status.textContent = message;
718
+ return;
719
+ }
720
+ requestAnimationFrame(() => {
721
+ status.textContent = message;
722
+ });
723
+ }
724
+ function copyViaExecCommand(text) {
725
+ const textarea = document.createElement('textarea');
726
+ textarea.value = text;
727
+ textarea.style.position = 'fixed';
728
+ textarea.style.top = '0';
729
+ textarea.style.left = '-9999px';
730
+ textarea.setAttribute('readonly', '');
731
+ document.body.appendChild(textarea);
732
+ textarea.select();
733
+ textarea.setSelectionRange(0, textarea.value.length);
734
+ let ok = false;
735
+ try {
736
+ ok = document.execCommand('copy');
737
+ }
738
+ catch {
739
+ ok = false;
740
+ }
741
+ finally {
742
+ document.body.removeChild(textarea);
743
+ }
744
+ return ok;
745
+ }
746
+ function resolveText() {
747
+ if (props.value !== undefined)
748
+ return props.value;
749
+ if (props.target) {
750
+ const el = document.querySelector(props.target);
751
+ if (!el)
752
+ return null;
753
+ if (el instanceof HTMLInputElement ||
754
+ el instanceof HTMLTextAreaElement ||
755
+ el instanceof HTMLSelectElement) {
756
+ return el.value;
757
+ }
758
+ return el.textContent || '';
759
+ }
760
+ return null;
761
+ }
762
+ async function onClick() {
763
+ if (props.disabled)
764
+ return;
765
+ const host = hostEl.value;
766
+ const text = resolveText();
767
+ let ok = false;
768
+ if (text !== null) {
769
+ if (navigator.clipboard?.writeText) {
770
+ try {
771
+ await navigator.clipboard.writeText(text);
772
+ ok = true;
773
+ }
774
+ catch {
775
+ ok = false;
776
+ }
777
+ }
778
+ if (!ok)
779
+ ok = copyViaExecCommand(text);
780
+ }
781
+ announce(ok ? props.successLabel : props.errorLabel);
782
+ state.value = ok ? 'copied' : 'failed';
783
+ emit('copy', ok);
784
+ host?.dispatchEvent(new CustomEvent('bw:copy', { detail: { id: hostId, ok }, bubbles: true }));
785
+ if (resetTimer)
786
+ window.clearTimeout(resetTimer);
787
+ resetTimer = window.setTimeout(() => {
788
+ state.value = 'idle';
789
+ }, 1500);
790
+ }
791
+ return () => {
792
+ const { class: cls, ...rest } = attrs;
793
+ return h('button', {
794
+ ...rest,
795
+ id: hostId,
796
+ ref: hostEl,
797
+ type: 'button',
798
+ disabled: props.disabled,
799
+ 'data-bw-copy-state': state.value,
800
+ 'data-bw-copy-success': props.successLabel,
801
+ 'data-bw-copy-error': props.errorLabel,
802
+ ...(props.value !== undefined ? { 'data-bw-copy-value': props.value } : {}),
803
+ ...(props.target ? { 'data-bw-copy-target': props.target } : {}),
804
+ class: cn('bw-copy', `bw-copy--size-${props.size}`, String(cls || '')),
805
+ onClick,
806
+ }, [
807
+ slots.default
808
+ ? h('span', { class: 'bw-copy__icon', 'aria-hidden': 'true' }, slots.default())
809
+ : null,
810
+ h('span', { class: 'bw-copy__mark bw-copy__mark--done', 'aria-hidden': 'true' }, [
811
+ h('svg', { viewBox: '0 0 16 16' }, [h('path', { d: 'M3.5 8.5 6.5 11.5 12.5 4.5' })]),
812
+ ]),
813
+ h('span', { class: 'bw-copy__mark bw-copy__mark--fail', 'aria-hidden': 'true' }, [
814
+ h('svg', { viewBox: '0 0 16 16' }, [
815
+ h('path', { d: 'M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5' }),
816
+ ]),
817
+ ]),
818
+ props.label ? h('span', { class: 'bw-copy__label' }, props.label) : null,
819
+ h('span', {
820
+ class: 'bw-copy__status bw-visually-hidden',
821
+ 'aria-live': 'polite',
822
+ ref: statusEl,
823
+ }),
824
+ ]);
825
+ };
826
+ },
827
+ });