@subfloor/astro 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +23 -2
- package/package.json +49 -3
- package/src/Button.astro +68 -0
- package/src/ButtonContent.astro +19 -0
- package/src/ButtonLink.astro +35 -0
- package/src/Checkbox.astro +39 -0
- package/src/CheckboxGroup.astro +13 -0
- package/src/Choice.astro +87 -0
- package/src/ChoiceGroup.astro +58 -0
- package/src/ClearButton.astro +30 -0
- package/src/DateField.astro +85 -0
- package/src/Dialog.astro +82 -0
- package/src/Field.astro +76 -0
- package/src/Menu.astro +118 -0
- package/src/MobileNav.astro +81 -0
- package/src/Modal.astro +12 -0
- package/src/Popover.astro +65 -0
- package/src/RadioGroup.astro +76 -0
- package/src/Segmented.astro +74 -0
- package/src/SegmentedLinks.astro +63 -0
- package/src/Select.astro +80 -0
- package/src/Sidepanel.astro +16 -0
- package/src/Snackbar.astro +66 -0
- package/src/Switch.astro +13 -0
- package/src/TextArea.astro +52 -0
- package/src/TextField.astro +87 -0
package/src/Field.astro
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The label, hint and error around a control (R-28): the @subfloor/core field markup that Select,
|
|
4
|
+
* TextField and TextArea share. They set the matching `aria-describedby` on their control; this
|
|
5
|
+
* file is not exported from the package.
|
|
6
|
+
*/
|
|
7
|
+
// This component's styles (decision 0006); the project imports `@subfloor/core/base.css` once.
|
|
8
|
+
import '@subfloor/core/styles/field.css'
|
|
9
|
+
|
|
10
|
+
export interface Props {
|
|
11
|
+
/** The control's id; the hint's and error's ids come from it. */
|
|
12
|
+
id: string
|
|
13
|
+
label: string
|
|
14
|
+
/**
|
|
15
|
+
* Hides the label on screen; it is still the name. Only where its purpose is clear without it: a
|
|
16
|
+
* placeholder does not replace a label, as it goes once there is text.
|
|
17
|
+
*/
|
|
18
|
+
hideLabel?: boolean | undefined
|
|
19
|
+
/** A quiet line under the label: what to enter, or why. */
|
|
20
|
+
hint?: string | undefined
|
|
21
|
+
/**
|
|
22
|
+
* What is wrong. While set, the control is `aria-invalid`, whatever `aria-invalid` you pass. An
|
|
23
|
+
* error there at page load may not be announced, but it describes the control.
|
|
24
|
+
*/
|
|
25
|
+
error?: string | undefined
|
|
26
|
+
/** Classes for the wrapper (`class` goes to the control). */
|
|
27
|
+
fieldClass?: string | undefined
|
|
28
|
+
/** Text beside the control, such as a unit. It also describes the control. TextField only. */
|
|
29
|
+
suffix?: string | undefined
|
|
30
|
+
/**
|
|
31
|
+
* A short control, `--sf-field-short-width` (6rem) wide, for a few characters. TextField only.
|
|
32
|
+
*/
|
|
33
|
+
short?: boolean | undefined
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
id,
|
|
38
|
+
label,
|
|
39
|
+
hideLabel = false,
|
|
40
|
+
hint,
|
|
41
|
+
error,
|
|
42
|
+
fieldClass,
|
|
43
|
+
suffix,
|
|
44
|
+
short = false,
|
|
45
|
+
} = Astro.props
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
<div class:list={['sf-field', fieldClass]} data-short={short ? '' : undefined}>
|
|
49
|
+
<label
|
|
50
|
+
class="sf-field__label"
|
|
51
|
+
for={id}
|
|
52
|
+
data-hidden={hideLabel ? '' : undefined}
|
|
53
|
+
>
|
|
54
|
+
{label}
|
|
55
|
+
</label>
|
|
56
|
+
{hint && (
|
|
57
|
+
<p class="sf-field__hint" id={`${id}-hint`}>
|
|
58
|
+
{hint}
|
|
59
|
+
</p>
|
|
60
|
+
)}
|
|
61
|
+
{suffix ? (
|
|
62
|
+
<div class="sf-field__row">
|
|
63
|
+
<slot />
|
|
64
|
+
<span class="sf-field__suffix" id={`${id}-suffix`}>
|
|
65
|
+
{suffix}
|
|
66
|
+
</span>
|
|
67
|
+
</div>
|
|
68
|
+
) : (
|
|
69
|
+
<slot />
|
|
70
|
+
)}
|
|
71
|
+
{error && (
|
|
72
|
+
<p class="sf-field__error" id={`${id}-error`} role="alert">
|
|
73
|
+
{error}
|
|
74
|
+
</p>
|
|
75
|
+
)}
|
|
76
|
+
</div>
|
package/src/Menu.astro
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The action menu: a button and a popover of menu items, the @subfloor/core menu markup; the
|
|
4
|
+
* behaviour (the WAI-ARIA menu button keyboard) is the core's `createMenu`, loaded by the script
|
|
5
|
+
* below. A choice dispatches `sf:select` on the menu with the item's `value`.
|
|
6
|
+
*/
|
|
7
|
+
// This component's styles (decision 0006); the project imports `@subfloor/core/base.css` once.
|
|
8
|
+
import '@subfloor/core/styles/caret.css'
|
|
9
|
+
import '@subfloor/core/styles/popover.css'
|
|
10
|
+
import '@subfloor/core/styles/menu.css'
|
|
11
|
+
import type { HTMLAttributes } from 'astro/types'
|
|
12
|
+
|
|
13
|
+
export type MenuItem =
|
|
14
|
+
| {
|
|
15
|
+
label: string
|
|
16
|
+
/** A link; otherwise a button whose choice is reported by `sf:select`. */
|
|
17
|
+
href?: string
|
|
18
|
+
/** Reported in `sf:select`; the label by default. */
|
|
19
|
+
value?: string
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
/** Destructive: drawn in the danger colour. */
|
|
22
|
+
danger?: boolean
|
|
23
|
+
}
|
|
24
|
+
| 'separator'
|
|
25
|
+
|
|
26
|
+
export interface Props extends Omit<HTMLAttributes<'div'>, 'popover'> {
|
|
27
|
+
id: string
|
|
28
|
+
/** The button's text (or use the `trigger` slot). */
|
|
29
|
+
label?: string
|
|
30
|
+
/** The menu's accessible name; the button's text by default. */
|
|
31
|
+
menuLabel?: string
|
|
32
|
+
items: MenuItem[]
|
|
33
|
+
placement?: 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end'
|
|
34
|
+
/** Adds the kit's caret after the button's content; it turns while open (needs the script). */
|
|
35
|
+
caret?: boolean
|
|
36
|
+
/** Classes for the button. */
|
|
37
|
+
triggerClass?: string
|
|
38
|
+
/** The button's accessible name, for a button with an icon only. */
|
|
39
|
+
triggerLabel?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
id,
|
|
44
|
+
label,
|
|
45
|
+
menuLabel,
|
|
46
|
+
items,
|
|
47
|
+
placement = 'bottom-start',
|
|
48
|
+
caret = false,
|
|
49
|
+
triggerClass,
|
|
50
|
+
triggerLabel,
|
|
51
|
+
class: className,
|
|
52
|
+
...rest
|
|
53
|
+
} = Astro.props
|
|
54
|
+
const anchor = `--sf-anchor-${id}`
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
<button
|
|
58
|
+
type="button"
|
|
59
|
+
id={`${id}-trigger`}
|
|
60
|
+
class={triggerClass}
|
|
61
|
+
popovertarget={id}
|
|
62
|
+
aria-haspopup="menu"
|
|
63
|
+
aria-controls={id}
|
|
64
|
+
aria-label={triggerLabel}
|
|
65
|
+
style={`anchor-name: ${anchor}`}
|
|
66
|
+
>
|
|
67
|
+
<slot name="trigger">{label}</slot>
|
|
68
|
+
{caret && <span class="sf-caret" aria-hidden="true" />}
|
|
69
|
+
</button>
|
|
70
|
+
<div
|
|
71
|
+
{...rest}
|
|
72
|
+
id={id}
|
|
73
|
+
popover="auto"
|
|
74
|
+
role="menu"
|
|
75
|
+
aria-label={menuLabel ?? triggerLabel ?? label}
|
|
76
|
+
class:list={['sf-popover', 'sf-menu', className]}
|
|
77
|
+
data-sf-menu=""
|
|
78
|
+
data-placement={placement}
|
|
79
|
+
style={`position-anchor: ${anchor}`}
|
|
80
|
+
>
|
|
81
|
+
{items.map((item) =>
|
|
82
|
+
item === 'separator' ? (
|
|
83
|
+
<hr class="sf-menu__separator" role="separator" />
|
|
84
|
+
) : item.href ? (
|
|
85
|
+
<a
|
|
86
|
+
class="sf-menu__item"
|
|
87
|
+
role="menuitem"
|
|
88
|
+
tabindex="-1"
|
|
89
|
+
href={item.href}
|
|
90
|
+
aria-disabled={item.disabled ? 'true' : undefined}
|
|
91
|
+
data-danger={item.danger ? '' : undefined}
|
|
92
|
+
data-value={item.value}
|
|
93
|
+
>
|
|
94
|
+
{item.label}
|
|
95
|
+
</a>
|
|
96
|
+
) : (
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
class="sf-menu__item"
|
|
100
|
+
role="menuitem"
|
|
101
|
+
tabindex="-1"
|
|
102
|
+
aria-disabled={item.disabled ? 'true' : undefined}
|
|
103
|
+
data-danger={item.danger ? '' : undefined}
|
|
104
|
+
data-value={item.value}
|
|
105
|
+
>
|
|
106
|
+
{item.label}
|
|
107
|
+
</button>
|
|
108
|
+
),
|
|
109
|
+
)}
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<script>
|
|
113
|
+
import { destroyMenus, initMenus } from '@subfloor/core'
|
|
114
|
+
|
|
115
|
+
initMenus()
|
|
116
|
+
document.addEventListener('astro:before-swap', () => destroyMenus())
|
|
117
|
+
document.addEventListener('astro:page-load', () => initMenus())
|
|
118
|
+
</script>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The phone menu: the @subfloor/core dialog with a list of links; the behaviour is the core's
|
|
4
|
+
* `createMobileNav`, loaded by the script below. Open it with a button anywhere on the page:
|
|
5
|
+
* <button command="show-modal" commandfor="site-nav" aria-haspopup="dialog">Menu</button>
|
|
6
|
+
*/
|
|
7
|
+
// This component's styles (decision 0006); the project imports `@subfloor/core/base.css` once.
|
|
8
|
+
import '@subfloor/core/styles/mobile-nav.css'
|
|
9
|
+
import type { ComponentProps } from 'astro/types'
|
|
10
|
+
import Dialog from './Dialog.astro'
|
|
11
|
+
|
|
12
|
+
export interface MobileNavLink {
|
|
13
|
+
href: string
|
|
14
|
+
label: string
|
|
15
|
+
/** Marks the current page (`aria-current="page"`). */
|
|
16
|
+
current?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type Props = Omit<
|
|
20
|
+
ComponentProps<typeof Dialog>,
|
|
21
|
+
'placement' | 'title' | 'swipeToClose'
|
|
22
|
+
> & {
|
|
23
|
+
/** The heading; it also names the dialog and the `<nav>`. Default "Menu". */
|
|
24
|
+
title?: string
|
|
25
|
+
/** `end` (default) or `start`. */
|
|
26
|
+
placement?: 'start' | 'end'
|
|
27
|
+
links?: MobileNavLink[]
|
|
28
|
+
/** A media query; the menu closes once it matches, e.g. `(min-width: 768px)`. */
|
|
29
|
+
closeAt?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
id,
|
|
34
|
+
title = 'Menu',
|
|
35
|
+
placement = 'end',
|
|
36
|
+
links = [],
|
|
37
|
+
closeAt,
|
|
38
|
+
closeLabel = 'Close menu',
|
|
39
|
+
class: className,
|
|
40
|
+
...rest
|
|
41
|
+
} = Astro.props
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
<Dialog
|
|
45
|
+
{...rest}
|
|
46
|
+
id={id}
|
|
47
|
+
title={title}
|
|
48
|
+
placement={placement}
|
|
49
|
+
closeLabel={closeLabel}
|
|
50
|
+
class:list={['sf-mobile-nav', className]}
|
|
51
|
+
data-sf-mobile-nav=""
|
|
52
|
+
data-sf-close-at={closeAt}
|
|
53
|
+
>
|
|
54
|
+
<nav class="sf-mobile-nav__nav" aria-labelledby={`${id}-title`}>
|
|
55
|
+
{links.length > 0 && (
|
|
56
|
+
<ul class="sf-mobile-nav__list">
|
|
57
|
+
{links.map((link) => (
|
|
58
|
+
<li>
|
|
59
|
+
<a
|
|
60
|
+
class="sf-mobile-nav__link"
|
|
61
|
+
href={link.href}
|
|
62
|
+
aria-current={link.current ? 'page' : undefined}
|
|
63
|
+
>
|
|
64
|
+
{link.label}
|
|
65
|
+
</a>
|
|
66
|
+
</li>
|
|
67
|
+
))}
|
|
68
|
+
</ul>
|
|
69
|
+
)}
|
|
70
|
+
<slot />
|
|
71
|
+
</nav>
|
|
72
|
+
<slot name="footer" slot="footer" />
|
|
73
|
+
</Dialog>
|
|
74
|
+
|
|
75
|
+
<script>
|
|
76
|
+
import { destroyMobileNavs, initMobileNavs } from '@subfloor/core'
|
|
77
|
+
|
|
78
|
+
initMobileNavs()
|
|
79
|
+
document.addEventListener('astro:before-swap', () => destroyMobileNavs())
|
|
80
|
+
document.addEventListener('astro:page-load', () => initMobileNavs())
|
|
81
|
+
</script>
|
package/src/Modal.astro
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
/** A centred modal dialog. Props and slots as in Dialog.astro. */
|
|
3
|
+
import type { ComponentProps } from 'astro/types'
|
|
4
|
+
import Dialog from './Dialog.astro'
|
|
5
|
+
|
|
6
|
+
type Props = Omit<ComponentProps<typeof Dialog>, 'placement' | 'swipeToClose'>
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
<Dialog {...Astro.props} placement="center">
|
|
10
|
+
<slot />
|
|
11
|
+
<slot name="footer" slot="footer" />
|
|
12
|
+
</Dialog>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A button and the non-modal panel it opens: the @subfloor/core popover markup; the behaviour is
|
|
4
|
+
* the core's `createPopover`, loaded by the script below. Without JavaScript the button still
|
|
5
|
+
* opens and closes it (`popovertarget`), and an outside press or Escape closes it.
|
|
6
|
+
*/
|
|
7
|
+
// This component's styles (decision 0006); the project imports `@subfloor/core/base.css` once.
|
|
8
|
+
import '@subfloor/core/styles/caret.css'
|
|
9
|
+
import '@subfloor/core/styles/popover.css'
|
|
10
|
+
import type { HTMLAttributes } from 'astro/types'
|
|
11
|
+
|
|
12
|
+
export interface Props extends Omit<HTMLAttributes<'div'>, 'popover'> {
|
|
13
|
+
id: string
|
|
14
|
+
/** The button's text (or use the `trigger` slot). */
|
|
15
|
+
label?: string
|
|
16
|
+
/** Where it opens; it flips at a screen edge. */
|
|
17
|
+
placement?: 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end'
|
|
18
|
+
/** Adds the kit's caret after the button's content; it turns while open (needs the script). */
|
|
19
|
+
caret?: boolean
|
|
20
|
+
/** Classes for the button. */
|
|
21
|
+
triggerClass?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
id,
|
|
26
|
+
label,
|
|
27
|
+
placement = 'bottom-start',
|
|
28
|
+
caret = false,
|
|
29
|
+
triggerClass,
|
|
30
|
+
class: className,
|
|
31
|
+
...rest
|
|
32
|
+
} = Astro.props
|
|
33
|
+
const anchor = `--sf-anchor-${id}`
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
id={`${id}-trigger`}
|
|
39
|
+
class={triggerClass}
|
|
40
|
+
popovertarget={id}
|
|
41
|
+
aria-controls={id}
|
|
42
|
+
style={`anchor-name: ${anchor}`}
|
|
43
|
+
>
|
|
44
|
+
<slot name="trigger">{label}</slot>
|
|
45
|
+
{caret && <span class="sf-caret" aria-hidden="true" />}
|
|
46
|
+
</button>
|
|
47
|
+
<div
|
|
48
|
+
{...rest}
|
|
49
|
+
id={id}
|
|
50
|
+
popover="auto"
|
|
51
|
+
class:list={['sf-popover', className]}
|
|
52
|
+
data-sf-popover=""
|
|
53
|
+
data-placement={placement}
|
|
54
|
+
style={`position-anchor: ${anchor}`}
|
|
55
|
+
>
|
|
56
|
+
<slot />
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<script>
|
|
60
|
+
import { destroyPopovers, initPopovers } from '@subfloor/core'
|
|
61
|
+
|
|
62
|
+
initPopovers()
|
|
63
|
+
document.addEventListener('astro:before-swap', () => destroyPopovers())
|
|
64
|
+
document.addEventListener('astro:page-load', () => initPopovers())
|
|
65
|
+
</script>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* One choice of a few, all in view: native radio buttons in a `<fieldset>` (decision 0013).
|
|
4
|
+
* `disabled` disables all of them. It works without JavaScript; the script only keeps the focus
|
|
5
|
+
* ring in WebKit. For two to five short choices in a row, use Segmented.
|
|
6
|
+
*/
|
|
7
|
+
import ChoiceGroup, { type GroupProps } from './ChoiceGroup.astro'
|
|
8
|
+
|
|
9
|
+
export interface RadioOption {
|
|
10
|
+
value: string
|
|
11
|
+
label: string
|
|
12
|
+
/** A quiet line under the label: the option's description. */
|
|
13
|
+
hint?: string | undefined
|
|
14
|
+
disabled?: boolean | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type Props = GroupProps & {
|
|
18
|
+
/** The form field's name; it also makes the choices one group. */
|
|
19
|
+
name: string
|
|
20
|
+
/** Each value only once. */
|
|
21
|
+
options: readonly RadioOption[]
|
|
22
|
+
/** The value chosen at first. */
|
|
23
|
+
value?: string | undefined
|
|
24
|
+
/** One has to be chosen. */
|
|
25
|
+
required?: boolean | undefined
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
id,
|
|
30
|
+
name,
|
|
31
|
+
options,
|
|
32
|
+
value,
|
|
33
|
+
required = false,
|
|
34
|
+
'aria-invalid': invalid,
|
|
35
|
+
...group
|
|
36
|
+
} = Astro.props
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
<ChoiceGroup
|
|
40
|
+
{...group}
|
|
41
|
+
id={id}
|
|
42
|
+
role="radiogroup"
|
|
43
|
+
aria-invalid={group.error ? 'true' : invalid}
|
|
44
|
+
aria-required={required ? 'true' : undefined}
|
|
45
|
+
>
|
|
46
|
+
{options.map((option, index) => (
|
|
47
|
+
<div class="sf-choice">
|
|
48
|
+
<input
|
|
49
|
+
class="sf-choice__input"
|
|
50
|
+
type="radio"
|
|
51
|
+
id={`${id}-${index}`}
|
|
52
|
+
name={name}
|
|
53
|
+
value={option.value}
|
|
54
|
+
checked={option.value === value}
|
|
55
|
+
disabled={option.disabled}
|
|
56
|
+
required={required}
|
|
57
|
+
aria-describedby={option.hint ? `${id}-${index}-hint` : undefined}
|
|
58
|
+
/>
|
|
59
|
+
<label class="sf-choice__label" for={`${id}-${index}`}>
|
|
60
|
+
{option.label}
|
|
61
|
+
</label>
|
|
62
|
+
{option.hint && (
|
|
63
|
+
<p class="sf-field__hint" id={`${id}-${index}-hint`}>
|
|
64
|
+
{option.hint}
|
|
65
|
+
</p>
|
|
66
|
+
)}
|
|
67
|
+
</div>
|
|
68
|
+
))}
|
|
69
|
+
</ChoiceGroup>
|
|
70
|
+
|
|
71
|
+
<script>
|
|
72
|
+
import { initChoices } from '@subfloor/core'
|
|
73
|
+
|
|
74
|
+
initChoices()
|
|
75
|
+
document.addEventListener('astro:page-load', () => initChoices())
|
|
76
|
+
</script>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A choice that changes the page in place, or a form value: native radio buttons in a row
|
|
4
|
+
* (decision 0008). It works without JavaScript; the script only shows the current choice of a row
|
|
5
|
+
* too long for its place, and keeps the focus ring in WebKit. For choices that change the address, use SegmentedLinks.
|
|
6
|
+
*/
|
|
7
|
+
// This component's styles (decision 0006); the project imports `@subfloor/core/base.css` once.
|
|
8
|
+
import '@subfloor/core/styles/segmented.css'
|
|
9
|
+
import type { HTMLAttributes } from 'astro/types'
|
|
10
|
+
|
|
11
|
+
export interface SegmentedOption {
|
|
12
|
+
value: string
|
|
13
|
+
label: string
|
|
14
|
+
disabled?: boolean | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type Props = Omit<
|
|
18
|
+
HTMLAttributes<'div'>,
|
|
19
|
+
'role' | 'aria-label' | 'data-sf-segmented'
|
|
20
|
+
> & {
|
|
21
|
+
/** The group's accessible name, such as "Group by". An `aria-labelledby` you pass wins. */
|
|
22
|
+
label: string
|
|
23
|
+
/** The form field's name; it also makes the choices one group. */
|
|
24
|
+
name: string
|
|
25
|
+
/** Two to five short choices; for more, use a Select. */
|
|
26
|
+
options: readonly SegmentedOption[]
|
|
27
|
+
/** The value chosen at first. */
|
|
28
|
+
value?: string | undefined
|
|
29
|
+
/** Disables every choice. */
|
|
30
|
+
disabled?: boolean | undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
label,
|
|
35
|
+
name,
|
|
36
|
+
options,
|
|
37
|
+
value,
|
|
38
|
+
disabled = false,
|
|
39
|
+
class: className,
|
|
40
|
+
...rest
|
|
41
|
+
} = Astro.props
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
<div
|
|
45
|
+
{...rest}
|
|
46
|
+
role="radiogroup"
|
|
47
|
+
aria-label={label}
|
|
48
|
+
class:list={['sf-segmented', className]}
|
|
49
|
+
data-sf-segmented=""
|
|
50
|
+
>
|
|
51
|
+
{/* Not a Tab stop of its own: Firefox makes a row that scrolls one. */}
|
|
52
|
+
<div class="sf-segmented__row" tabindex="-1">
|
|
53
|
+
{options.map((option) => (
|
|
54
|
+
<label class="sf-segmented__item">
|
|
55
|
+
<input
|
|
56
|
+
class="sf-segmented__input"
|
|
57
|
+
type="radio"
|
|
58
|
+
name={name}
|
|
59
|
+
value={option.value}
|
|
60
|
+
checked={option.value === value}
|
|
61
|
+
disabled={disabled || option.disabled}
|
|
62
|
+
/>
|
|
63
|
+
<span>{option.label}</span>
|
|
64
|
+
</label>
|
|
65
|
+
))}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<script>
|
|
70
|
+
import { initSegmented } from '@subfloor/core'
|
|
71
|
+
|
|
72
|
+
initSegmented()
|
|
73
|
+
document.addEventListener('astro:page-load', () => initSegmented())
|
|
74
|
+
</script>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Choices that change the address: links in the look of Segmented (decision 0008). It works without
|
|
4
|
+
* JavaScript; the script only shows the current link of a row too long for its place.
|
|
5
|
+
*/
|
|
6
|
+
// This component's styles (decision 0006); the project imports `@subfloor/core/base.css` once.
|
|
7
|
+
import '@subfloor/core/styles/segmented.css'
|
|
8
|
+
import type { HTMLAttributes } from 'astro/types'
|
|
9
|
+
|
|
10
|
+
export interface SegmentedLink {
|
|
11
|
+
href: string
|
|
12
|
+
label: string
|
|
13
|
+
/** The page or view now shown. */
|
|
14
|
+
current?: boolean | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type Props = Omit<
|
|
18
|
+
HTMLAttributes<'div'>,
|
|
19
|
+
'role' | 'aria-label' | 'data-sf-segmented'
|
|
20
|
+
> & {
|
|
21
|
+
/** The row's accessible name, such as "Analytics". An `aria-labelledby` you pass wins. */
|
|
22
|
+
label: string
|
|
23
|
+
links: readonly SegmentedLink[]
|
|
24
|
+
/**
|
|
25
|
+
* `page` (default): links between pages, in a `<nav>`, with `aria-current="page"`. `view`: views
|
|
26
|
+
* of the same page, in a group, with `aria-current="true"`.
|
|
27
|
+
*/
|
|
28
|
+
kind?: 'page' | 'view' | undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { label, links, kind = 'page', class: className, ...rest } = Astro.props
|
|
32
|
+
const Row = kind === 'page' ? 'nav' : 'div'
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
<Row
|
|
36
|
+
{...rest}
|
|
37
|
+
role={kind === 'page' ? undefined : 'group'}
|
|
38
|
+
aria-label={label}
|
|
39
|
+
class:list={['sf-segmented', className]}
|
|
40
|
+
data-sf-segmented=""
|
|
41
|
+
>
|
|
42
|
+
{/* Not a Tab stop of its own: Firefox makes a row that scrolls one. */}
|
|
43
|
+
<div class="sf-segmented__row" tabindex="-1">
|
|
44
|
+
{links.map((link) => (
|
|
45
|
+
<a
|
|
46
|
+
class="sf-segmented__item"
|
|
47
|
+
href={link.href}
|
|
48
|
+
aria-current={
|
|
49
|
+
link.current ? (kind === 'page' ? 'page' : 'true') : undefined
|
|
50
|
+
}
|
|
51
|
+
>
|
|
52
|
+
{link.label}
|
|
53
|
+
</a>
|
|
54
|
+
))}
|
|
55
|
+
</div>
|
|
56
|
+
</Row>
|
|
57
|
+
|
|
58
|
+
<script>
|
|
59
|
+
import { initSegmented } from '@subfloor/core'
|
|
60
|
+
|
|
61
|
+
initSegmented()
|
|
62
|
+
document.addEventListener('astro:page-load', () => initSegmented())
|
|
63
|
+
</script>
|
package/src/Select.astro
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A native `<select>` in the kit's look (decision 0007). Native attributes go to the `<select>`, so
|
|
4
|
+
* forms, validation and autofill work as usual, with or without JavaScript.
|
|
5
|
+
*/
|
|
6
|
+
// This component's styles (decision 0006); the project imports `@subfloor/core/base.css` once.
|
|
7
|
+
import '@subfloor/core/styles/caret.css'
|
|
8
|
+
import '@subfloor/core/styles/select.css'
|
|
9
|
+
import type { ComponentProps, HTMLAttributes } from 'astro/types'
|
|
10
|
+
import Field from './Field.astro'
|
|
11
|
+
|
|
12
|
+
type FieldProps = Omit<ComponentProps<typeof Field>, 'suffix' | 'short'>
|
|
13
|
+
|
|
14
|
+
export interface SelectOption {
|
|
15
|
+
value: string
|
|
16
|
+
label: string
|
|
17
|
+
disabled?: boolean | undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** `multiple` and `size` draw a list box, not a closed box with a caret. */
|
|
21
|
+
export type Props = FieldProps &
|
|
22
|
+
Omit<
|
|
23
|
+
HTMLAttributes<'select'>,
|
|
24
|
+
keyof FieldProps | 'multiple' | 'size' | 'value'
|
|
25
|
+
> & {
|
|
26
|
+
/** The options; or put `<option>` and `<optgroup>` in the slot (after these, if both). */
|
|
27
|
+
options?: readonly SelectOption[] | undefined
|
|
28
|
+
/** The value selected at first, among `options`. */
|
|
29
|
+
value?: string | undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
id,
|
|
34
|
+
label,
|
|
35
|
+
hideLabel,
|
|
36
|
+
hint,
|
|
37
|
+
error,
|
|
38
|
+
fieldClass,
|
|
39
|
+
options = [],
|
|
40
|
+
value,
|
|
41
|
+
class: className,
|
|
42
|
+
'aria-describedby': describedBy,
|
|
43
|
+
'aria-invalid': invalid,
|
|
44
|
+
...rest
|
|
45
|
+
} = Astro.props
|
|
46
|
+
const described = [hint && `${id}-hint`, error && `${id}-error`, describedBy]
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join(' ')
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
<Field
|
|
52
|
+
id={id}
|
|
53
|
+
label={label}
|
|
54
|
+
hideLabel={hideLabel}
|
|
55
|
+
hint={hint}
|
|
56
|
+
error={error}
|
|
57
|
+
fieldClass={fieldClass}
|
|
58
|
+
>
|
|
59
|
+
<div class="sf-select">
|
|
60
|
+
<select
|
|
61
|
+
{...rest}
|
|
62
|
+
id={id}
|
|
63
|
+
class:list={['sf-field__control', 'sf-select__control', className]}
|
|
64
|
+
aria-describedby={described || undefined}
|
|
65
|
+
aria-invalid={error ? 'true' : invalid}
|
|
66
|
+
>
|
|
67
|
+
{options.map((option) => (
|
|
68
|
+
<option
|
|
69
|
+
value={option.value}
|
|
70
|
+
disabled={option.disabled}
|
|
71
|
+
selected={option.value === value}
|
|
72
|
+
>
|
|
73
|
+
{option.label}
|
|
74
|
+
</option>
|
|
75
|
+
))}
|
|
76
|
+
<slot />
|
|
77
|
+
</select>
|
|
78
|
+
<span class="sf-caret" aria-hidden="true"></span>
|
|
79
|
+
</div>
|
|
80
|
+
</Field>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
/** A sidepanel along an edge (`end` by default), or a bottom sheet with `placement="bottom"`. */
|
|
3
|
+
import type { ComponentProps } from 'astro/types'
|
|
4
|
+
import Dialog from './Dialog.astro'
|
|
5
|
+
|
|
6
|
+
type Props = Omit<ComponentProps<typeof Dialog>, 'placement'> & {
|
|
7
|
+
placement?: 'start' | 'end' | 'bottom'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { placement = 'end', ...rest } = Astro.props
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<Dialog {...rest} placement={placement}>
|
|
14
|
+
<slot />
|
|
15
|
+
<slot name="footer" slot="footer" />
|
|
16
|
+
</Dialog>
|