@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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A snackbar rendered on the server, for a message that belongs to the page as it arrives (after a
|
|
4
|
+
* form redirected here, for example). The core's `initSnackbars`, loaded below, shows it in the top
|
|
5
|
+
* layer and adds the timing and closing. Client scripts show snackbars with `showSnackbar` from
|
|
6
|
+
* `@subfloor/core` instead.
|
|
7
|
+
*
|
|
8
|
+
* Without JavaScript it still shows, fixed at the bottom; the close button and the timeout need
|
|
9
|
+
* the script.
|
|
10
|
+
*/
|
|
11
|
+
// This component's styles (decision 0006); the project imports `@subfloor/core/base.css` once.
|
|
12
|
+
import '@subfloor/core/styles/snackbar.css'
|
|
13
|
+
import type { HTMLAttributes } from 'astro/types'
|
|
14
|
+
|
|
15
|
+
export interface Props extends HTMLAttributes<'div'> {
|
|
16
|
+
/** `done` (default), `info` or `problem` (stays until closed). */
|
|
17
|
+
tone?: 'done' | 'info' | 'problem'
|
|
18
|
+
/** Milliseconds before a `done` or `info` snackbar closes itself. Default 6000. */
|
|
19
|
+
timeout?: number
|
|
20
|
+
/** Accessible name of the close button. */
|
|
21
|
+
closeLabel?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
tone = 'done',
|
|
26
|
+
timeout,
|
|
27
|
+
closeLabel = 'Dismiss',
|
|
28
|
+
class: className,
|
|
29
|
+
...rest
|
|
30
|
+
} = Astro.props
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<div
|
|
34
|
+
{...rest}
|
|
35
|
+
class:list={['sf-snackbar', className]}
|
|
36
|
+
data-sf-snackbar=""
|
|
37
|
+
data-tone={tone}
|
|
38
|
+
data-timeout={timeout}
|
|
39
|
+
role={tone === 'problem' ? 'alert' : 'status'}
|
|
40
|
+
>
|
|
41
|
+
<span class="sf-snackbar__message">
|
|
42
|
+
<slot />
|
|
43
|
+
</span>
|
|
44
|
+
<button
|
|
45
|
+
type="button"
|
|
46
|
+
class="sf-snackbar__close"
|
|
47
|
+
aria-label={closeLabel}
|
|
48
|
+
hidden
|
|
49
|
+
>
|
|
50
|
+
<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true">
|
|
51
|
+
<path
|
|
52
|
+
d="M6 6l12 12M18 6 6 18"
|
|
53
|
+
fill="none"
|
|
54
|
+
stroke="currentColor"
|
|
55
|
+
stroke-width="2"
|
|
56
|
+
></path>
|
|
57
|
+
</svg>
|
|
58
|
+
</button>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<script>
|
|
62
|
+
import { initSnackbars } from '@subfloor/core'
|
|
63
|
+
|
|
64
|
+
initSnackbars()
|
|
65
|
+
document.addEventListener('astro:page-load', () => initSnackbars())
|
|
66
|
+
</script>
|
package/src/Switch.astro
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A setting that is on or off: a native checkbox with `role="switch"` (decision 0013). Saving is
|
|
4
|
+
* up to you. Native attributes go to the `<input>`. Slot `hint`: a hint with links.
|
|
5
|
+
*/
|
|
6
|
+
import Choice, { type InputProps, type RowProps } from './Choice.astro'
|
|
7
|
+
|
|
8
|
+
export type Props = InputProps & RowProps
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<Choice {...Astro.props} role="switch">
|
|
12
|
+
<slot name="hint" slot="hint" />
|
|
13
|
+
</Choice>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A native `<textarea>` in the kit's field. Native attributes go to the `<textarea>`.
|
|
4
|
+
*/
|
|
5
|
+
import type { ComponentProps, HTMLAttributes } from 'astro/types'
|
|
6
|
+
import Field from './Field.astro'
|
|
7
|
+
|
|
8
|
+
type FieldProps = Omit<ComponentProps<typeof Field>, 'suffix' | 'short'>
|
|
9
|
+
|
|
10
|
+
export type Props = FieldProps &
|
|
11
|
+
Omit<HTMLAttributes<'textarea'>, keyof FieldProps | 'value'> & {
|
|
12
|
+
/** The text at first. */
|
|
13
|
+
value?: string | undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
id,
|
|
18
|
+
label,
|
|
19
|
+
hideLabel,
|
|
20
|
+
hint,
|
|
21
|
+
error,
|
|
22
|
+
fieldClass,
|
|
23
|
+
value = '',
|
|
24
|
+
rows = 4,
|
|
25
|
+
class: className,
|
|
26
|
+
'aria-describedby': describedBy,
|
|
27
|
+
'aria-invalid': invalid,
|
|
28
|
+
...rest
|
|
29
|
+
} = Astro.props
|
|
30
|
+
const described = [hint && `${id}-hint`, error && `${id}-error`, describedBy]
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.join(' ')
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
<Field
|
|
36
|
+
id={id}
|
|
37
|
+
label={label}
|
|
38
|
+
hideLabel={hideLabel}
|
|
39
|
+
hint={hint}
|
|
40
|
+
error={error}
|
|
41
|
+
fieldClass={fieldClass}
|
|
42
|
+
>
|
|
43
|
+
<textarea
|
|
44
|
+
{...rest}
|
|
45
|
+
rows={rows}
|
|
46
|
+
id={id}
|
|
47
|
+
class:list={['sf-field__control', className]}
|
|
48
|
+
aria-describedby={described || undefined}
|
|
49
|
+
aria-invalid={error ? 'true' : invalid}
|
|
50
|
+
set:text={value}
|
|
51
|
+
/>
|
|
52
|
+
</Field>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A native `<input>` in the kit's field. Native attributes go to the `<input>`. Only a search field
|
|
4
|
+
* has a script, for its clear button; without it, the browser's own button stays, if it has one.
|
|
5
|
+
*/
|
|
6
|
+
import type { ComponentProps, HTMLAttributes } from 'astro/types'
|
|
7
|
+
import ClearButton from './ClearButton.astro'
|
|
8
|
+
import Field from './Field.astro'
|
|
9
|
+
|
|
10
|
+
type FieldProps = ComponentProps<typeof Field>
|
|
11
|
+
|
|
12
|
+
export type Props = FieldProps &
|
|
13
|
+
Omit<HTMLAttributes<'input'>, keyof FieldProps | 'type'> & {
|
|
14
|
+
/**
|
|
15
|
+
* `search` has a clear button. `time` is the browser's own: it decides its format, icon and
|
|
16
|
+
* picker. Leave it enough room. For a date, use DateField.
|
|
17
|
+
*/
|
|
18
|
+
type?:
|
|
19
|
+
| 'text'
|
|
20
|
+
| 'email'
|
|
21
|
+
| 'password'
|
|
22
|
+
| 'tel'
|
|
23
|
+
| 'url'
|
|
24
|
+
| 'search'
|
|
25
|
+
| 'time'
|
|
26
|
+
| undefined
|
|
27
|
+
/** Accessible name of a search field's clear button. */
|
|
28
|
+
clearLabel?: string | undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
id,
|
|
33
|
+
label,
|
|
34
|
+
hideLabel,
|
|
35
|
+
hint,
|
|
36
|
+
error,
|
|
37
|
+
fieldClass,
|
|
38
|
+
suffix,
|
|
39
|
+
short,
|
|
40
|
+
type = 'text',
|
|
41
|
+
clearLabel = 'Clear',
|
|
42
|
+
placeholder,
|
|
43
|
+
class: className,
|
|
44
|
+
'aria-describedby': describedBy,
|
|
45
|
+
'aria-invalid': invalid,
|
|
46
|
+
...rest
|
|
47
|
+
} = Astro.props
|
|
48
|
+
const search = type === 'search'
|
|
49
|
+
// In the order they are shown.
|
|
50
|
+
const described = [
|
|
51
|
+
hint && `${id}-hint`,
|
|
52
|
+
suffix && `${id}-suffix`,
|
|
53
|
+
error && `${id}-error`,
|
|
54
|
+
describedBy,
|
|
55
|
+
]
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
.join(' ')
|
|
58
|
+
const attributes = {
|
|
59
|
+
...rest,
|
|
60
|
+
type,
|
|
61
|
+
id,
|
|
62
|
+
// CSS knows that a field is empty only by its placeholder.
|
|
63
|
+
placeholder: search ? placeholder || ' ' : placeholder,
|
|
64
|
+
'aria-describedby': described || undefined,
|
|
65
|
+
'aria-invalid': error ? 'true' : invalid,
|
|
66
|
+
} as const
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
<Field
|
|
70
|
+
id={id}
|
|
71
|
+
label={label}
|
|
72
|
+
hideLabel={hideLabel}
|
|
73
|
+
hint={hint}
|
|
74
|
+
error={error}
|
|
75
|
+
fieldClass={fieldClass}
|
|
76
|
+
suffix={suffix}
|
|
77
|
+
short={short}
|
|
78
|
+
>
|
|
79
|
+
{search ? (
|
|
80
|
+
<div class="sf-field__search">
|
|
81
|
+
<input {...attributes} class:list={['sf-field__control', className]} />
|
|
82
|
+
<ClearButton label={clearLabel} />
|
|
83
|
+
</div>
|
|
84
|
+
) : (
|
|
85
|
+
<input {...attributes} class:list={['sf-field__control', className]} />
|
|
86
|
+
)}
|
|
87
|
+
</Field>
|