@bwui/vue 0.1.14 → 0.1.15

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/src/index.ts CHANGED
@@ -4,6 +4,12 @@ export {
4
4
  Badge,
5
5
  Chip,
6
6
  Card,
7
+ CardHeader,
8
+ CardTitle,
9
+ CardDescription,
10
+ CardBody,
11
+ CardMedia,
12
+ CardFooter,
7
13
  Alert,
8
14
  AlertTitle,
9
15
  AlertBody,
@@ -39,9 +45,35 @@ export {
39
45
  Topbar,
40
46
  PageHeader,
41
47
  } from './primitives'
48
+ export type { ButtonVariant, ButtonSize, ButtonFit } from './primitives'
49
+
50
+ export type {
51
+ CardSize,
52
+ CardSurface,
53
+ CardElevation,
54
+ CardRadius,
55
+ CardHeaderRecipe,
56
+ CardFooterRecipe,
57
+ CardMediaRecipe,
58
+ } from './primitives'
42
59
 
43
60
  export { Combobox } from './combobox'
44
- export type { ComboboxOption } from './combobox'
61
+ export type { ComboboxOption, ComboboxSize } from './combobox'
62
+
63
+ export {
64
+ Tabs,
65
+ TabList,
66
+ Tab,
67
+ TabPanel,
68
+ Avatar,
69
+ Breadcrumbs,
70
+ } from './chrome'
71
+ export type {
72
+ TabsVariant,
73
+ AvatarSize,
74
+ AvatarShape,
75
+ BreadcrumbItem,
76
+ } from './chrome'
45
77
 
46
78
  export { DatePicker, DateRangePicker } from './date-picker'
47
79
 
package/src/pages.ts CHANGED
@@ -47,7 +47,7 @@ export const Homepage = defineComponent({
47
47
  h('main', { id: 'main' }, [
48
48
  h('section', { class: 'bw-hero', style: { padding: 'var(--bw-space-12) var(--bw-space-6)' } }, [
49
49
  h(Stack, { style: { maxWidth: '40rem' } }, () => [
50
- h('h1', { class: 'bw-text-display-md' }, props.title),
50
+ h('h1', { class: 'bw-display-lg' }, props.title),
51
51
  h('p', { class: 'bw-body-lg', style: { color: 'var(--bw-color-fg-muted)' } }, props.description),
52
52
  h(Cluster, () => [
53
53
  h(ButtonLink, { href: '/gallery/forms', variant: 'primary', size: 'lg' }, () => 'Get started'),
@@ -95,7 +95,7 @@ export const Landing = defineComponent({
95
95
  ]),
96
96
  h('main', { id: 'main', style: { padding: 'var(--bw-space-12) var(--bw-space-6)' } }, [
97
97
  h(Stack, { class: 'bw-centre', style: { textAlign: 'center' } }, () => [
98
- h('h1', { class: 'bw-text-display-sm' }, props.title),
98
+ h('h1', { class: 'bw-heading-xl' }, props.title),
99
99
  h('p', { class: 'bw-body-lg', style: { color: 'var(--bw-color-fg-muted)' } }, props.description),
100
100
  h(Cluster, { style: { justifyContent: 'center' } }, () => [
101
101
  h(ButtonLink, { href: '/gallery/forms', variant: 'primary', size: 'lg' }, () => 'Start free'),
@@ -124,7 +124,7 @@ export const ContactForm = defineComponent({
124
124
  h(SkipLink),
125
125
  h('main', { id: 'main', style: { padding: 'var(--bw-space-10) var(--bw-space-6)', maxWidth: '32rem', marginInline: 'auto' } }, [
126
126
  h(Stack, () => [
127
- h('h1', { class: 'bw-text-title-lg' }, 'Contact'),
127
+ h('h1', { class: 'bw-heading-xl' }, 'Contact'),
128
128
  h(Form, { onSubmit: (e: Event) => e.preventDefault() }, () => [
129
129
  h(Field, () => [
130
130
  h(Label, { for: 'bw-contact-name' }, () => 'Name'),
@@ -137,7 +137,13 @@ export const ContactForm = defineComponent({
137
137
  ]),
138
138
  h(Field, () => [
139
139
  h(Label, { for: 'bw-contact-topic' }, () => 'Topic'),
140
- h(Combobox, { id: 'bw-contact-topic', name: 'topic', options: props.topics, placeholder: 'Search topics' }),
140
+ h(Combobox, {
141
+ id: 'bw-contact-topic',
142
+ name: 'topic',
143
+ options: props.topics,
144
+ placeholder: 'Search topics',
145
+ ariaLabel: 'Topic',
146
+ }),
141
147
  ]),
142
148
  h(Field, () => [
143
149
  h(Label, { for: 'bw-contact-date' }, () => 'Preferred date'),
package/src/primitives.ts CHANGED
@@ -2,64 +2,181 @@ let bwCopySeq = 0
2
2
  import { defineComponent, h, type PropType, computed, ref } from 'vue'
3
3
  import { cn } from './cn'
4
4
 
5
- type ButtonVariant =
6
- | 'primary'
7
- | 'secondary'
8
- | 'outline'
9
- | 'ghost'
10
- | 'danger'
11
- | 'solid'
12
- type ButtonSize = 'sm' | 'md' | 'lg'
5
+ // Button (docs/components/button.md). Same bw-* contract as HTML, Django and
6
+ // React (BTN-070 / GAP-BTN-10): variant, always-emitted size class (md included),
7
+ // icon-only, fit, loading and the disabled link span.
8
+
9
+ /**
10
+ * Closed grammar (BTN-002). `solid` is the early-draft name of primary:
11
+ * DEPRECATED, accepted and rendered as `bw-btn--primary`. `outline` was never
12
+ * a shipped class and is not accepted.
13
+ */
14
+ export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger' | 'solid'
15
+ /** Five ADR-125 steps (BTN-003). Every step emits `bw-btn--size-<step>`. */
16
+ export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
17
+ /** Width behaviour (ADR-126 section 3). `fill` is not accepted with icon-only. */
18
+ export type ButtonFit = 'auto' | 'fill'
19
+
20
+ function buttonClasses(
21
+ variant: ButtonVariant,
22
+ size: ButtonSize,
23
+ iconOnly: boolean,
24
+ fit: ButtonFit,
25
+ className?: string,
26
+ ) {
27
+ return cn(
28
+ 'bw-btn',
29
+ `bw-btn--${variant === 'solid' ? 'primary' : variant}`,
30
+ `bw-btn--size-${size}`,
31
+ iconOnly && 'bw-btn--icon-only',
32
+ fit === 'fill' && 'bw-btn--fit-fill',
33
+ className,
34
+ )
35
+ }
36
+
37
+ /** ICO-008: an icon-only control with no accessible name is a render error. */
38
+ function assertNamed(
39
+ iconOnly: boolean,
40
+ props: { 'aria-label'?: unknown; 'aria-labelledby'?: unknown },
41
+ ) {
42
+ if (!iconOnly) return
43
+ const label = typeof props['aria-label'] === 'string' ? props['aria-label'].trim() : ''
44
+ if (!label && !props['aria-labelledby']) {
45
+ throw new Error(
46
+ 'Button iconOnly requires aria-label (or aria-labelledby): an icon-only ' +
47
+ 'button with no accessible name is a WCAG 4.1.2 failure (ICO-008).',
48
+ )
49
+ }
50
+ }
51
+
52
+ /** ADR-060 section 3: no silent no-op. An icon-only control is a square, so `fill` has no meaning. */
53
+ function assertFit(iconOnly: boolean, fit: ButtonFit) {
54
+ if (fit !== 'auto' && fit !== 'fill') {
55
+ throw new Error(`Button fit must be "auto" or "fill", got ${JSON.stringify(fit)}.`)
56
+ }
57
+ if (iconOnly && fit === 'fill') {
58
+ throw new Error(
59
+ 'Button fit="fill" cannot be combined with iconOnly: an icon-only button is a square at its ' +
60
+ 'size step, so fill would do nothing (ADR-060 section 3).',
61
+ )
62
+ }
63
+ }
64
+
65
+ /** Same glyph as the Django spinner partial: aria-hidden; the host carries aria-busy. */
66
+ function ButtonSpinner() {
67
+ return h(
68
+ 'svg',
69
+ {
70
+ class: 'bw-spinner',
71
+ viewBox: '0 0 24 24',
72
+ fill: 'none',
73
+ stroke: 'currentColor',
74
+ 'stroke-width': 2,
75
+ 'stroke-linecap': 'round',
76
+ 'aria-hidden': 'true',
77
+ },
78
+ [h('path', { d: 'M21 12a9 9 0 1 1-6.219-8.56' })],
79
+ )
80
+ }
81
+
82
+ function buttonInner(loading: boolean, iconOnly: boolean, children: unknown) {
83
+ if (!loading) return children
84
+ return iconOnly ? [ButtonSpinner()] : [ButtonSpinner(), children]
85
+ }
86
+
87
+ const buttonSharedProps = {
88
+ variant: { type: String as PropType<ButtonVariant>, default: 'primary' },
89
+ size: { type: String as PropType<ButtonSize>, default: 'md' },
90
+ fit: { type: String as PropType<ButtonFit>, default: 'auto' },
91
+ loading: { type: Boolean, default: false },
92
+ iconOnly: { type: Boolean, default: false },
93
+ disabled: { type: Boolean, default: false },
94
+ }
13
95
 
14
96
  export const Button = defineComponent({
15
97
  name: 'BwButton',
98
+ inheritAttrs: false,
16
99
  props: {
17
- variant: { type: String as PropType<ButtonVariant>, default: 'primary' },
18
- size: { type: String as PropType<ButtonSize>, default: 'md' },
100
+ ...buttonSharedProps,
19
101
  type: { type: String as PropType<'button' | 'submit' | 'reset'>, default: 'button' },
20
102
  },
21
103
  setup(props, { slots, attrs }) {
22
- return () =>
23
- h(
104
+ return () => {
105
+ const { class: cls, ...rest } = attrs
106
+ assertNamed(props.iconOnly, rest as { 'aria-label'?: unknown; 'aria-labelledby'?: unknown })
107
+ assertFit(props.iconOnly, props.fit)
108
+ return h(
24
109
  'button',
25
110
  {
26
- ...attrs,
111
+ ...rest,
27
112
  type: props.type,
28
- class: cn(
29
- 'bw-btn',
30
- `bw-btn--${props.variant}`,
31
- props.size !== 'md' && `bw-btn--size-${props.size}`,
32
- String(attrs.class || ''),
33
- ),
113
+ class: buttonClasses(props.variant, props.size, props.iconOnly, props.fit, String(cls || '')),
114
+ disabled: props.disabled || props.loading || undefined,
115
+ 'aria-busy': props.loading ? true : undefined,
34
116
  },
35
- slots.default?.(),
117
+ buttonInner(props.loading, props.iconOnly, slots.default?.()) as any,
36
118
  )
119
+ }
37
120
  },
38
121
  })
39
122
 
40
123
  export const ButtonLink = defineComponent({
41
124
  name: 'BwButtonLink',
125
+ inheritAttrs: false,
42
126
  props: {
127
+ ...buttonSharedProps,
43
128
  href: { type: String, required: true },
44
- variant: { type: String as PropType<ButtonVariant>, default: 'primary' },
45
- size: { type: String as PropType<ButtonSize>, default: 'md' },
46
129
  },
47
130
  setup(props, { slots, attrs }) {
48
- return () =>
49
- h(
131
+ return () => {
132
+ const { class: cls, ...rest } = attrs
133
+ assertNamed(props.iconOnly, rest as { 'aria-label'?: unknown; 'aria-labelledby'?: unknown })
134
+ assertFit(props.iconOnly, props.fit)
135
+ const classes = buttonClasses(
136
+ props.variant,
137
+ props.size,
138
+ props.iconOnly,
139
+ props.fit,
140
+ String(cls || ''),
141
+ )
142
+ if (props.disabled || props.loading) {
143
+ // Not operable: no href and no handler (BTN-001). Disabled takes the
144
+ // flat colours; busy keeps the variant colours (BTN-031).
145
+ const inert: Record<string, unknown> = { ...rest }
146
+ for (const key of [
147
+ 'onClick',
148
+ 'onAuxclick',
149
+ 'onAuxClick',
150
+ 'target',
151
+ 'rel',
152
+ 'download',
153
+ 'hreflang',
154
+ 'hrefLang',
155
+ 'ping',
156
+ ]) {
157
+ delete inert[key]
158
+ }
159
+ return h(
160
+ 'span',
161
+ {
162
+ ...inert,
163
+ class: cn(classes, props.disabled && !props.loading && 'bw-btn--disabled'),
164
+ 'aria-disabled': 'true',
165
+ 'aria-busy': props.loading ? true : undefined,
166
+ },
167
+ buttonInner(props.loading, props.iconOnly, slots.default?.()) as any,
168
+ )
169
+ }
170
+ return h(
50
171
  'a',
51
172
  {
52
- ...attrs,
173
+ ...rest,
174
+ class: classes,
53
175
  href: props.href,
54
- class: cn(
55
- 'bw-btn',
56
- `bw-btn--${props.variant}`,
57
- props.size !== 'md' && `bw-btn--size-${props.size}`,
58
- String(attrs.class || ''),
59
- ),
60
176
  },
61
177
  slots.default?.(),
62
178
  )
179
+ }
63
180
  },
64
181
  })
65
182
 
@@ -180,10 +297,15 @@ export type CardSize = 'sm' | 'md' | 'lg'
180
297
  export type CardSurface = 'default' | 'raised' | 'tint' | 'inverse' | 'muted'
181
298
  export type CardElevation = '0' | '1' | '2' | '3'
182
299
  export type CardRadius = 'default' | 'sm' | 'lg' | 'xl' | 'none'
300
+ export type CardHeaderRecipe = 'plain' | 'bordered' | 'muted' | 'inverse' | 'accent'
301
+ export type CardFooterRecipe = 'plain' | 'muted' | 'actions'
302
+ export type CardMediaRecipe = 'bleed' | 'inset' | 'icon'
183
303
 
184
304
  // Card (docs/components/card.md): the same modifier grammar as React. `md` is
185
305
  // the base inset and emits a class only when asked for; `href` renders an
186
306
  // anchor and implies interactive; `bordered` is the APP-002 flat hairline mode.
307
+ // Region primitives (GAP-CRD-4) match React `CardHeader` / Body / Footer /
308
+ // Media / Title / Description and their recipe modifiers.
187
309
  export const Card = defineComponent({
188
310
  name: 'BwCard',
189
311
  inheritAttrs: false,
@@ -195,6 +317,8 @@ export const Card = defineComponent({
195
317
  radius: { type: String as PropType<CardRadius>, default: undefined },
196
318
  interactive: { type: Boolean, default: false },
197
319
  href: { type: String, default: undefined },
320
+ target: { type: String, default: undefined },
321
+ rel: { type: String, default: undefined },
198
322
  },
199
323
  setup(props, { slots, attrs }) {
200
324
  return () => {
@@ -211,13 +335,135 @@ export const Card = defineComponent({
211
335
  )
212
336
  return h(
213
337
  linked ? 'a' : 'div',
214
- { ...attrs, class: classes, ...(linked ? { href: props.href } : {}) },
338
+ {
339
+ ...attrs,
340
+ class: classes,
341
+ ...(linked
342
+ ? {
343
+ href: props.href,
344
+ ...(props.target !== undefined ? { target: props.target } : {}),
345
+ ...(props.rel !== undefined ? { rel: props.rel } : {}),
346
+ }
347
+ : {}),
348
+ },
215
349
  slots.default?.(),
216
350
  )
217
351
  }
218
352
  },
219
353
  })
220
354
 
355
+ export const CardHeader = defineComponent({
356
+ name: 'BwCardHeader',
357
+ inheritAttrs: false,
358
+ props: {
359
+ recipe: { type: String as PropType<CardHeaderRecipe>, default: undefined },
360
+ },
361
+ setup(props, { slots, attrs }) {
362
+ return () =>
363
+ h(
364
+ 'div',
365
+ {
366
+ ...attrs,
367
+ class: cn(
368
+ 'bw-card__header',
369
+ props.recipe && props.recipe !== 'plain' && `bw-card__header--${props.recipe}`,
370
+ String(attrs.class || ''),
371
+ ),
372
+ },
373
+ slots.default?.(),
374
+ )
375
+ },
376
+ })
377
+
378
+ /**
379
+ * The card heading is an `h3` (a card usually sits under a section `h2`).
380
+ * Django's `_card.html` emits `h2`; the difference is GAP-CRD-3.
381
+ */
382
+ export const CardTitle = defineComponent({
383
+ name: 'BwCardTitle',
384
+ inheritAttrs: false,
385
+ setup(_props, { slots, attrs }) {
386
+ return () =>
387
+ h(
388
+ 'h3',
389
+ { ...attrs, class: cn('bw-card__title', String(attrs.class || '')) },
390
+ slots.default?.(),
391
+ )
392
+ },
393
+ })
394
+
395
+ export const CardDescription = defineComponent({
396
+ name: 'BwCardDescription',
397
+ inheritAttrs: false,
398
+ setup(_props, { slots, attrs }) {
399
+ return () =>
400
+ h(
401
+ 'p',
402
+ { ...attrs, class: cn('bw-card__description', String(attrs.class || '')) },
403
+ slots.default?.(),
404
+ )
405
+ },
406
+ })
407
+
408
+ export const CardBody = defineComponent({
409
+ name: 'BwCardBody',
410
+ inheritAttrs: false,
411
+ setup(_props, { slots, attrs }) {
412
+ return () =>
413
+ h(
414
+ 'div',
415
+ { ...attrs, class: cn('bw-card__body', String(attrs.class || '')) },
416
+ slots.default?.(),
417
+ )
418
+ },
419
+ })
420
+
421
+ export const CardMedia = defineComponent({
422
+ name: 'BwCardMedia',
423
+ inheritAttrs: false,
424
+ props: {
425
+ recipe: { type: String as PropType<CardMediaRecipe>, default: undefined },
426
+ },
427
+ setup(props, { slots, attrs }) {
428
+ return () =>
429
+ h(
430
+ 'div',
431
+ {
432
+ ...attrs,
433
+ class: cn(
434
+ 'bw-card__media',
435
+ props.recipe && `bw-card__media--${props.recipe}`,
436
+ String(attrs.class || ''),
437
+ ),
438
+ },
439
+ slots.default?.(),
440
+ )
441
+ },
442
+ })
443
+
444
+ export const CardFooter = defineComponent({
445
+ name: 'BwCardFooter',
446
+ inheritAttrs: false,
447
+ props: {
448
+ recipe: { type: String as PropType<CardFooterRecipe>, default: undefined },
449
+ },
450
+ setup(props, { slots, attrs }) {
451
+ return () =>
452
+ h(
453
+ 'div',
454
+ {
455
+ ...attrs,
456
+ class: cn(
457
+ 'bw-card__footer',
458
+ props.recipe && props.recipe !== 'plain' && `bw-card__footer--${props.recipe}`,
459
+ String(attrs.class || ''),
460
+ ),
461
+ },
462
+ slots.default?.(),
463
+ )
464
+ },
465
+ })
466
+
221
467
  export const Alert = defineComponent({
222
468
  name: 'BwAlert',
223
469
  props: {