@atomic-ui/ui 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/README.md +134 -2
- package/dist/base/FieldElement.d.ts +95 -0
- package/dist/base/ImpktElement.d.ts +21 -0
- package/dist/base/styles.d.ts +42 -0
- package/dist/base/tokens.d.ts +68 -0
- package/dist/chunk-26CSJMXY.js +122 -0
- package/dist/chunk-26CSJMXY.js.map +1 -0
- package/dist/chunk-3LFXWUOU.js +86 -0
- package/dist/chunk-3LFXWUOU.js.map +1 -0
- package/dist/chunk-43V4RFK4.js +94 -0
- package/dist/chunk-43V4RFK4.js.map +1 -0
- package/dist/chunk-4P3FLJZG.js +77 -0
- package/dist/chunk-4P3FLJZG.js.map +1 -0
- package/dist/chunk-5NBYZ5UC.js +164 -0
- package/dist/chunk-5NBYZ5UC.js.map +1 -0
- package/dist/chunk-BM73FVQ4.js +153 -0
- package/dist/chunk-BM73FVQ4.js.map +1 -0
- package/dist/chunk-CNFIYRPA.js +67 -0
- package/dist/chunk-CNFIYRPA.js.map +1 -0
- package/dist/chunk-G6X62CFC.js +713 -0
- package/dist/chunk-G6X62CFC.js.map +1 -0
- package/dist/chunk-M3WQZDWU.js +138 -0
- package/dist/chunk-M3WQZDWU.js.map +1 -0
- package/dist/chunk-O72RTRIJ.js +132 -0
- package/dist/chunk-O72RTRIJ.js.map +1 -0
- package/dist/chunk-OZNQ4GAR.js +159 -0
- package/dist/chunk-OZNQ4GAR.js.map +1 -0
- package/dist/chunk-PV4GMCP6.js +90 -0
- package/dist/chunk-PV4GMCP6.js.map +1 -0
- package/dist/chunk-QAKFGIOO.js +104 -0
- package/dist/chunk-QAKFGIOO.js.map +1 -0
- package/dist/chunk-RYJQKKJ4.js +133 -0
- package/dist/chunk-RYJQKKJ4.js.map +1 -0
- package/dist/chunk-SHGQMQXS.js +97 -0
- package/dist/chunk-SHGQMQXS.js.map +1 -0
- package/dist/chunk-TWCXYY4Z.js +83 -0
- package/dist/chunk-TWCXYY4Z.js.map +1 -0
- package/dist/chunk-UTL446G6.js +107 -0
- package/dist/chunk-UTL446G6.js.map +1 -0
- package/dist/chunk-VF6PNIPS.js +164 -0
- package/dist/chunk-VF6PNIPS.js.map +1 -0
- package/dist/chunk-VKQGLSDT.js +124 -0
- package/dist/chunk-VKQGLSDT.js.map +1 -0
- package/dist/chunk-WAB4TRB2.js +141 -0
- package/dist/chunk-WAB4TRB2.js.map +1 -0
- package/dist/chunk-WC5KO6KZ.js +44 -0
- package/dist/chunk-WC5KO6KZ.js.map +1 -0
- package/dist/chunk-YXHT3ZJU.js +81 -0
- package/dist/chunk-YXHT3ZJU.js.map +1 -0
- package/dist/components/accordion.d.ts +66 -0
- package/dist/components/accordion.js +8 -0
- package/dist/components/accordion.js.map +1 -0
- package/dist/components/alert.d.ts +49 -0
- package/dist/components/alert.js +8 -0
- package/dist/components/alert.js.map +1 -0
- package/dist/components/button.d.ts +70 -0
- package/dist/components/button.js +8 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/checkbox-group.d.ts +79 -0
- package/dist/components/checkbox-group.js +9 -0
- package/dist/components/checkbox-group.js.map +1 -0
- package/dist/components/checkbox.d.ts +64 -0
- package/dist/components/checkbox.js +9 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/date-input.d.ts +95 -0
- package/dist/components/date-input.js +9 -0
- package/dist/components/date-input.js.map +1 -0
- package/dist/components/dialog.d.ts +61 -0
- package/dist/components/dialog.js +8 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/grid.d.ts +34 -0
- package/dist/components/grid.js +8 -0
- package/dist/components/grid.js.map +1 -0
- package/dist/components/help.d.ts +103 -0
- package/dist/components/help.js +8 -0
- package/dist/components/help.js.map +1 -0
- package/dist/components/layout.d.ts +100 -0
- package/dist/components/layout.js +14 -0
- package/dist/components/layout.js.map +1 -0
- package/dist/components/link.d.ts +46 -0
- package/dist/components/link.js +8 -0
- package/dist/components/link.js.map +1 -0
- package/dist/components/media.d.ts +164 -0
- package/dist/components/media.js +12 -0
- package/dist/components/media.js.map +1 -0
- package/dist/components/price.d.ts +67 -0
- package/dist/components/price.js +8 -0
- package/dist/components/price.js.map +1 -0
- package/dist/components/progress.d.ts +50 -0
- package/dist/components/progress.js +8 -0
- package/dist/components/progress.js.map +1 -0
- package/dist/components/radio-group.d.ts +82 -0
- package/dist/components/radio-group.js +9 -0
- package/dist/components/radio-group.js.map +1 -0
- package/dist/components/select.d.ts +74 -0
- package/dist/components/select.js +9 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/summary-list.d.ts +47 -0
- package/dist/components/summary-list.js +8 -0
- package/dist/components/summary-list.js.map +1 -0
- package/dist/components/table.d.ts +49 -0
- package/dist/components/table.js +8 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/text-input.d.ts +80 -0
- package/dist/components/text-input.js +9 -0
- package/dist/components/text-input.js.map +1 -0
- package/dist/components/textarea.d.ts +59 -0
- package/dist/components/textarea.js +9 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +113 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -4
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A,
|
|
3
|
+
ImpktElement,
|
|
4
|
+
b,
|
|
5
|
+
focusRing,
|
|
6
|
+
fontSize,
|
|
7
|
+
fontWeight,
|
|
8
|
+
i,
|
|
9
|
+
space,
|
|
10
|
+
t
|
|
11
|
+
} from "./chunk-G6X62CFC.js";
|
|
12
|
+
|
|
13
|
+
// packages/ui/src/components/table.ts
|
|
14
|
+
var ImpktTable = class extends ImpktElement {
|
|
15
|
+
static {
|
|
16
|
+
this.properties = {
|
|
17
|
+
caption: { type: String },
|
|
18
|
+
columns: { type: Array },
|
|
19
|
+
rows: { type: Array }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.caption = "";
|
|
25
|
+
this.columns = [];
|
|
26
|
+
this.rows = [];
|
|
27
|
+
}
|
|
28
|
+
static {
|
|
29
|
+
this.styles = [
|
|
30
|
+
...ImpktElement.styles,
|
|
31
|
+
focusRing,
|
|
32
|
+
i`
|
|
33
|
+
:host {
|
|
34
|
+
display: block;
|
|
35
|
+
}
|
|
36
|
+
.scroller {
|
|
37
|
+
overflow-x: auto;
|
|
38
|
+
}
|
|
39
|
+
table {
|
|
40
|
+
inline-size: 100%;
|
|
41
|
+
border-collapse: collapse;
|
|
42
|
+
font-size: ${fontSize("md")};
|
|
43
|
+
}
|
|
44
|
+
caption {
|
|
45
|
+
text-align: start;
|
|
46
|
+
font-weight: ${fontWeight("semibold")};
|
|
47
|
+
padding-block-end: ${space(2)};
|
|
48
|
+
}
|
|
49
|
+
th,
|
|
50
|
+
td {
|
|
51
|
+
text-align: start;
|
|
52
|
+
padding: ${space(3)};
|
|
53
|
+
border-block-end: ${t.borderThin} solid ${t.border};
|
|
54
|
+
}
|
|
55
|
+
th {
|
|
56
|
+
font-weight: ${fontWeight("semibold")};
|
|
57
|
+
background: ${t.surfaceInset};
|
|
58
|
+
}
|
|
59
|
+
.numeric {
|
|
60
|
+
text-align: end;
|
|
61
|
+
font-variant-numeric: tabular-nums;
|
|
62
|
+
}
|
|
63
|
+
`
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
render() {
|
|
67
|
+
return b`
|
|
68
|
+
<div class="scroller" part="scroller" tabindex="0" role="region" aria-label=${this.caption || A}>
|
|
69
|
+
<table part="table">
|
|
70
|
+
${this.caption ? b`<caption part="caption">${this.caption}</caption>` : A}
|
|
71
|
+
<thead>
|
|
72
|
+
<tr>
|
|
73
|
+
${this.columns.map(
|
|
74
|
+
(c) => b`<th scope="col" class=${c.numeric ? "numeric" : ""}>${c.label}</th>`
|
|
75
|
+
)}
|
|
76
|
+
</tr>
|
|
77
|
+
</thead>
|
|
78
|
+
<tbody>
|
|
79
|
+
${this.rows.map(
|
|
80
|
+
(row, i2) => b`
|
|
81
|
+
<tr>
|
|
82
|
+
${this.columns.map(
|
|
83
|
+
(c, j) => (
|
|
84
|
+
// The first cell of each row is a row header, so a screen
|
|
85
|
+
// reader announces "Delivery charge, £250" rather than
|
|
86
|
+
// reading a bare number with no idea what it belongs to.
|
|
87
|
+
j === 0 ? b`<th scope="row" id=${`${this.uid}-r${i2}`}>${row[c.key] ?? ""}</th>` : b`<td class=${c.numeric ? "numeric" : ""}>${row[c.key] ?? ""}</td>`
|
|
88
|
+
)
|
|
89
|
+
)}
|
|
90
|
+
</tr>
|
|
91
|
+
`
|
|
92
|
+
)}
|
|
93
|
+
</tbody>
|
|
94
|
+
</table>
|
|
95
|
+
</div>
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
customElements.define("impkt-table", ImpktTable);
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
ImpktTable
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=chunk-QAKFGIOO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/table.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpktElement } from '../base/ImpktElement';\nimport { focusRing } from '../base/styles';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\nexport interface TableColumn {\n key: string;\n label: string;\n numeric?: boolean;\n}\n\n/**\n * A data table — a plan comparison, a payment schedule.\n *\n * **The caption is required.** It is the table's name, and a page with three\n * unnamed tables is a page a screen-reader user has to read in full to tell\n * apart. Visually it can be the heading they would have written anyway.\n *\n * **It scrolls, and the scroller is focusable.** A wide table cannot reflow to\n * 320px without becoming unreadable, so it scrolls horizontally — and a region\n * that scrolls must be reachable by keyboard, or a keyboard user simply cannot\n * see the right-hand columns. `tabindex=\"0\"` with a role and a name is the\n * established fix, and the name is why the role is there: a bare focusable div\n * announces nothing.\n\n *\n * @category content\n * @icon table\n */\nexport class ImpktTable extends ImpktElement {\n static properties = {\n caption: { type: String },\n columns: { type: Array },\n rows: { type: Array },\n };\n\n declare caption: string;\n declare columns: TableColumn[];\n declare rows: Array<Record<string, string>>;\n\n constructor() {\n super();\n this.caption = '';\n this.columns = [];\n this.rows = [];\n }\n\n static styles = [\n ...ImpktElement.styles,\n focusRing,\n css`\n :host {\n display: block;\n }\n .scroller {\n overflow-x: auto;\n }\n table {\n inline-size: 100%;\n border-collapse: collapse;\n font-size: ${fontSize('md')};\n }\n caption {\n text-align: start;\n font-weight: ${fontWeight('semibold')};\n padding-block-end: ${space(2)};\n }\n th,\n td {\n text-align: start;\n padding: ${space(3)};\n border-block-end: ${t.borderThin} solid ${t.border};\n }\n th {\n font-weight: ${fontWeight('semibold')};\n background: ${t.surfaceInset};\n }\n .numeric {\n text-align: end;\n font-variant-numeric: tabular-nums;\n }\n `,\n ];\n\n render(): TemplateResult {\n return html`\n <div class=\"scroller\" part=\"scroller\" tabindex=\"0\" role=\"region\" aria-label=${this.caption || nothing}>\n <table part=\"table\">\n ${this.caption ? html`<caption part=\"caption\">${this.caption}</caption>` : nothing}\n <thead>\n <tr>\n ${this.columns.map(\n (c) => html`<th scope=\"col\" class=${c.numeric ? 'numeric' : ''}>${c.label}</th>`,\n )}\n </tr>\n </thead>\n <tbody>\n ${this.rows.map(\n (row, i) => html`\n <tr>\n ${this.columns.map((c, j) =>\n // The first cell of each row is a row header, so a screen\n // reader announces \"Delivery charge, £250\" rather than\n // reading a bare number with no idea what it belongs to.\n j === 0\n ? html`<th scope=\"row\" id=${`${this.uid}-r${i}`}>${row[c.key] ?? ''}</th>`\n : html`<td class=${c.numeric ? 'numeric' : ''}>${row[c.key] ?? ''}</td>`,\n )}\n </tr>\n `,\n )}\n </tbody>\n </table>\n </div>\n `;\n }\n}\n\ncustomElements.define('impkt-table', ImpktTable);\n\ndeclare global {\n interface HTMLElementTagNameMap { 'impkt-table': ImpktTable }\n}\n"],"mappings":";;;;;;;;;;;;;AA6BO,IAAM,aAAN,cA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,GAAG,KAAK,EAAE,UACjE,cAAiB,EAAE,UAAU,YAAY,EAAE,IAAI,IAAI,EAAE,GAAG,KAAK,EAAE;AAAA;AAAA,MACrE,CAAC;AAAA;AAAA;AAAA,IAGP,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAKX;AACF;AAEA,eAAe,OAAO,eAAe,UAAU;","names":["i"]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldElement
|
|
3
|
+
} from "./chunk-5NBYZ5UC.js";
|
|
4
|
+
import {
|
|
5
|
+
A,
|
|
6
|
+
b,
|
|
7
|
+
fontSize,
|
|
8
|
+
i,
|
|
9
|
+
space,
|
|
10
|
+
t,
|
|
11
|
+
targetSize
|
|
12
|
+
} from "./chunk-G6X62CFC.js";
|
|
13
|
+
|
|
14
|
+
// packages/ui/src/components/checkbox-group.ts
|
|
15
|
+
var ImpktCheckboxGroup = class extends FieldElement {
|
|
16
|
+
static {
|
|
17
|
+
this.properties = {
|
|
18
|
+
...FieldElement.properties,
|
|
19
|
+
options: { type: Array },
|
|
20
|
+
values: { type: Array }
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.options = [];
|
|
26
|
+
this.values = [];
|
|
27
|
+
}
|
|
28
|
+
static {
|
|
29
|
+
this.styles = [
|
|
30
|
+
...FieldElement.styles,
|
|
31
|
+
i`
|
|
32
|
+
fieldset {
|
|
33
|
+
border: 0;
|
|
34
|
+
margin: 0;
|
|
35
|
+
padding: 0;
|
|
36
|
+
min-inline-size: 0;
|
|
37
|
+
}
|
|
38
|
+
legend {
|
|
39
|
+
padding: 0;
|
|
40
|
+
}
|
|
41
|
+
.option {
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: flex-start;
|
|
44
|
+
gap: ${space(3)};
|
|
45
|
+
padding: ${space(3)};
|
|
46
|
+
border: ${t.borderThin} solid ${t.border};
|
|
47
|
+
border-radius: ${t.radius};
|
|
48
|
+
margin-block-end: ${space(2)};
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
}
|
|
51
|
+
.option:hover {
|
|
52
|
+
background: ${t.surfaceSubtle};
|
|
53
|
+
}
|
|
54
|
+
.option input {
|
|
55
|
+
${targetSize}
|
|
56
|
+
inline-size: 20px;
|
|
57
|
+
block-size: 20px;
|
|
58
|
+
margin: 0;
|
|
59
|
+
flex: none;
|
|
60
|
+
accent-color: ${t.brand};
|
|
61
|
+
}
|
|
62
|
+
.option-text {
|
|
63
|
+
display: block;
|
|
64
|
+
font-size: ${fontSize("md")};
|
|
65
|
+
}
|
|
66
|
+
.option-description {
|
|
67
|
+
display: block;
|
|
68
|
+
font-size: ${fontSize("sm")};
|
|
69
|
+
color: ${t.textMuted};
|
|
70
|
+
margin-block-start: ${space(1)};
|
|
71
|
+
}
|
|
72
|
+
:host([invalid]) .option {
|
|
73
|
+
border-color: ${t.danger};
|
|
74
|
+
}
|
|
75
|
+
`
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
renderLabel() {
|
|
79
|
+
return b`<legend class="label" part="label">
|
|
80
|
+
${this.label}${this.required ? b`<span class="required"> (${this.requiredText})</span>` : A}
|
|
81
|
+
</legend>`;
|
|
82
|
+
}
|
|
83
|
+
onToggle(value, checked) {
|
|
84
|
+
this.values = checked ? [...this.values, value] : this.values.filter((v) => v !== value);
|
|
85
|
+
this.setFormValue(
|
|
86
|
+
this.options.filter((o) => this.values.includes(o.value)).map((o) => o.value).join(",")
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
renderControl() {
|
|
90
|
+
return b`
|
|
91
|
+
${this.options.map((option, i2) => {
|
|
92
|
+
const id = this.id_(`opt-${i2}`);
|
|
93
|
+
const descId = option.description ? this.id_(`opt-${i2}-desc`) : void 0;
|
|
94
|
+
return b`
|
|
95
|
+
<label class="option" part="option" for=${id}>
|
|
96
|
+
<input
|
|
97
|
+
type="checkbox"
|
|
98
|
+
id=${id}
|
|
99
|
+
value=${option.value}
|
|
100
|
+
.checked=${this.values.includes(option.value)}
|
|
101
|
+
?disabled=${this.disabled}
|
|
102
|
+
aria-describedby=${descId ?? A}
|
|
103
|
+
@change=${(e) => this.onToggle(option.value, e.target.checked)}
|
|
104
|
+
/>
|
|
105
|
+
<span>
|
|
106
|
+
<span class="option-text">${option.label}</span>
|
|
107
|
+
${option.description ? b`<span class="option-description" id=${descId}>${option.description}</span>` : A}
|
|
108
|
+
</span>
|
|
109
|
+
</label>
|
|
110
|
+
`;
|
|
111
|
+
})}
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
114
|
+
render() {
|
|
115
|
+
return b`
|
|
116
|
+
<fieldset part="fieldset" aria-describedby=${this.describedBy} aria-invalid=${this.error ? "true" : A}>
|
|
117
|
+
${this.renderLabel()}
|
|
118
|
+
${this.description ? b`<div class="description" id=${this.id_("description")} part="description">${this.description}</div>` : A}
|
|
119
|
+
${this.renderControl()}
|
|
120
|
+
<div class="error" id=${this.id_("error")} part="error" aria-live="polite">${this.error || A}</div>
|
|
121
|
+
</fieldset>
|
|
122
|
+
`;
|
|
123
|
+
}
|
|
124
|
+
updated(changed) {
|
|
125
|
+
if (changed.has("error")) this.toggleAttribute("invalid", Boolean(this.error));
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
customElements.define("impkt-checkbox-group", ImpktCheckboxGroup);
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
ImpktCheckboxGroup
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=chunk-RYJQKKJ4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/checkbox-group.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { FieldElement } from '../base/FieldElement';\nimport { targetSize } from '../base/styles';\nimport { fontSize, space, t } from '../base/tokens';\n\nexport interface CheckboxOption {\n value: string;\n label: string;\n description?: string;\n}\n\n/**\n * A choose-several group — the multi-select question type.\n *\n * Same shape as the radio group and for the same reasons: a `<fieldset>` with\n * a `<legend>`, because the question is asked of the set and `label for` names\n * one control.\n *\n * It differs from radios in one way that matters. Checkboxes have no roving\n * tabindex — every box is its own tab stop, which is correct, because each is\n * an independent yes or no rather than one choice among several. Nothing needs\n * to be implemented for that; it is what the platform does, and it is worth\n * knowing it is deliberate rather than missing.\n\n *\n * @category form\n * @icon checkbox\n */\nexport class ImpktCheckboxGroup extends FieldElement {\n static properties = {\n ...FieldElement.properties,\n options: { type: Array },\n values: { type: Array },\n };\n\n declare options: CheckboxOption[];\n declare values: string[];\n\n constructor() {\n super();\n this.options = [];\n this.values = [];\n }\n\n static styles = [\n ...FieldElement.styles,\n css`\n fieldset {\n border: 0;\n margin: 0;\n padding: 0;\n min-inline-size: 0;\n }\n legend {\n padding: 0;\n }\n .option {\n display: flex;\n align-items: flex-start;\n gap: ${space(3)};\n padding: ${space(3)};\n border: ${t.borderThin} solid ${t.border};\n border-radius: ${t.radius};\n margin-block-end: ${space(2)};\n cursor: pointer;\n }\n .option:hover {\n background: ${t.surfaceSubtle};\n }\n .option input {\n ${targetSize}\n inline-size: 20px;\n block-size: 20px;\n margin: 0;\n flex: none;\n accent-color: ${t.brand};\n }\n .option-text {\n display: block;\n font-size: ${fontSize('md')};\n }\n .option-description {\n display: block;\n font-size: ${fontSize('sm')};\n color: ${t.textMuted};\n margin-block-start: ${space(1)};\n }\n :host([invalid]) .option {\n border-color: ${t.danger};\n }\n `,\n ];\n\n protected renderLabel(): TemplateResult {\n return html`<legend class=\"label\" part=\"label\">\n ${this.label}${this.required ? html`<span class=\"required\"> (${this.requiredText})</span>` : nothing}\n </legend>`;\n }\n\n private onToggle(value: string, checked: boolean): void {\n this.values = checked ? [...this.values, value] : this.values.filter((v) => v !== value);\n // One form value, comma-joined — a multi-select arrives at a pricing API as\n // a list, and the order follows the options rather than the clicks.\n this.setFormValue(\n this.options.filter((o) => this.values.includes(o.value)).map((o) => o.value).join(','),\n );\n }\n\n protected renderControl(): TemplateResult {\n return html`\n ${this.options.map((option, i) => {\n const id = this.id_(`opt-${i}`);\n const descId = option.description ? this.id_(`opt-${i}-desc`) : undefined;\n return html`\n <label class=\"option\" part=\"option\" for=${id}>\n <input\n type=\"checkbox\"\n id=${id}\n value=${option.value}\n .checked=${this.values.includes(option.value)}\n ?disabled=${this.disabled}\n aria-describedby=${descId ?? nothing}\n @change=${(e: Event) => this.onToggle(option.value, (e.target as HTMLInputElement).checked)}\n />\n <span>\n <span class=\"option-text\">${option.label}</span>\n ${option.description\n ? html`<span class=\"option-description\" id=${descId!}>${option.description}</span>`\n : nothing}\n </span>\n </label>\n `;\n })}\n `;\n }\n\n render(): TemplateResult {\n return html`\n <fieldset part=\"fieldset\" aria-describedby=${this.describedBy} aria-invalid=${this.error ? 'true' : nothing}>\n ${this.renderLabel()}\n ${this.description\n ? html`<div class=\"description\" id=${this.id_('description')} part=\"description\">${this.description}</div>`\n : nothing}\n ${this.renderControl()}\n <div class=\"error\" id=${this.id_('error')} part=\"error\" aria-live=\"polite\">${this.error || nothing}</div>\n </fieldset>\n `;\n }\n\n updated(changed: Map<string, unknown>): void {\n if (changed.has('error')) this.toggleAttribute('invalid', Boolean(this.error));\n }\n}\n\ncustomElements.define('impkt-checkbox-group', ImpktCheckboxGroup);\n\ndeclare global {\n interface HTMLElementTagNameMap { 'impkt-checkbox-group': ImpktCheckboxGroup }\n}\n"],"mappings":";;;;;;;;;;;;;;AA4BO,IAAM,qBAAN,cAAiC,aAAa;AAAA,EACnD;AAAA,SAAO,aAAa;AAAA,MAClB,GAAG,aAAa;AAAA,MAChB,SAAS,EAAE,MAAM,MAAM;AAAA,MACvB,QAAQ,EAAE,MAAM,MAAM;AAAA,IACxB;AAAA;AAAA,EAKA,cAAc;AACZ,UAAM;AACN,SAAK,UAAU,CAAC;AAChB,SAAK,SAAS,CAAC;AAAA,EACjB;AAAA,EAEA;AAAA,SAAO,SAAS;AAAA,MACd,GAAG,aAAa;AAAA,MAChB;AAAA;AAAA;AAAA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A,mBAGnC,EAAE;AAAA,sBACC,OAAO,KAAK;AAAA,yBACT,KAAK,OAAO,SAAS,OAAO,KAAK,CAAC;AAAA,0BACjC,KAAK,QAAQ;AAAA,iCACN,UAAU,CAAO;AAAA,wBAC1B,CAAC,MAAa,KAAK,SAAS,OAAO,OAAQ,EAAE,OAA4B,OAAO,CAAC;AAAA;AAAA;AAAA,0CAG/D,OAAO,KAAK;AAAA,gBACtC,OAAO,cACL,wCAA2C,MAAO,IAAI,OAAO,WAAW,YACxE,CAAO;AAAA;AAAA;AAAA;AAAA,IAInB,CAAC,CAAC;AAAA;AAAA,EAEN;AAAA,EAEA,SAAyB;AACvB,WAAO;AAAA,mDACwC,KAAK,WAAW,iBAAiB,KAAK,QAAQ,SAAS,CAAO;AAAA,UACvG,KAAK,YAAY,CAAC;AAAA,UAClB,KAAK,cACH,gCAAmC,KAAK,IAAI,aAAa,CAAC,uBAAuB,KAAK,WAAW,WACjG,CAAO;AAAA,UACT,KAAK,cAAc,CAAC;AAAA,gCACE,KAAK,IAAI,OAAO,CAAC,oCAAoC,KAAK,SAAS,CAAO;AAAA;AAAA;AAAA,EAGxG;AAAA,EAEA,QAAQ,SAAqC;AAC3C,QAAI,QAAQ,IAAI,OAAO,EAAG,MAAK,gBAAgB,WAAW,QAAQ,KAAK,KAAK,CAAC;AAAA,EAC/E;AACF;AAEA,eAAe,OAAO,wBAAwB,kBAAkB;","names":["i"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A,
|
|
3
|
+
ImpktElement,
|
|
4
|
+
b,
|
|
5
|
+
fontSize,
|
|
6
|
+
fontWeight,
|
|
7
|
+
i,
|
|
8
|
+
space,
|
|
9
|
+
t,
|
|
10
|
+
visuallyHidden
|
|
11
|
+
} from "./chunk-G6X62CFC.js";
|
|
12
|
+
|
|
13
|
+
// packages/ui/src/components/progress.ts
|
|
14
|
+
var ImpktProgress = class extends ImpktElement {
|
|
15
|
+
static {
|
|
16
|
+
this.properties = {
|
|
17
|
+
steps: { type: Array },
|
|
18
|
+
current: { type: String },
|
|
19
|
+
label: { type: String }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.steps = [];
|
|
25
|
+
this.current = "";
|
|
26
|
+
this.label = "Progress";
|
|
27
|
+
}
|
|
28
|
+
static {
|
|
29
|
+
this.styles = [
|
|
30
|
+
...ImpktElement.styles,
|
|
31
|
+
i`
|
|
32
|
+
:host {
|
|
33
|
+
display: block;
|
|
34
|
+
margin-block-end: ${space(5)};
|
|
35
|
+
}
|
|
36
|
+
ol {
|
|
37
|
+
display: flex;
|
|
38
|
+
gap: ${space(2)};
|
|
39
|
+
list-style: none;
|
|
40
|
+
margin: 0;
|
|
41
|
+
padding: 0;
|
|
42
|
+
}
|
|
43
|
+
li {
|
|
44
|
+
flex: 1;
|
|
45
|
+
font-size: ${fontSize("xs")};
|
|
46
|
+
color: ${t.textMuted};
|
|
47
|
+
padding-block-start: ${space(2)};
|
|
48
|
+
border-block-start: 4px solid ${t.border};
|
|
49
|
+
}
|
|
50
|
+
li[data-state='done'] {
|
|
51
|
+
color: ${t.text};
|
|
52
|
+
border-block-start-color: ${t.brand};
|
|
53
|
+
}
|
|
54
|
+
li[data-state='current'] {
|
|
55
|
+
color: ${t.text};
|
|
56
|
+
font-weight: ${fontWeight("semibold")};
|
|
57
|
+
border-block-start-color: ${t.brand};
|
|
58
|
+
}
|
|
59
|
+
.sr-only {
|
|
60
|
+
${visuallyHidden}
|
|
61
|
+
}
|
|
62
|
+
/* Below 30rem the labels stop fitting; the position in words is the part
|
|
63
|
+
that has to survive, so the list collapses to bars and the current
|
|
64
|
+
step's name. */
|
|
65
|
+
@media (max-width: 30rem) {
|
|
66
|
+
li:not([data-state='current']) span:not(.sr-only) {
|
|
67
|
+
${visuallyHidden}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
render() {
|
|
74
|
+
const index = this.steps.findIndex((s) => s.id === this.current);
|
|
75
|
+
return b`
|
|
76
|
+
<nav part="nav" aria-label=${this.label}>
|
|
77
|
+
<ol part="list">
|
|
78
|
+
${this.steps.map((step, i2) => {
|
|
79
|
+
const state = i2 < index ? "done" : i2 === index ? "current" : "todo";
|
|
80
|
+
return b`
|
|
81
|
+
<li data-state=${state} aria-current=${state === "current" ? "step" : A}>
|
|
82
|
+
${state === "current" ? b`<span class="sr-only">Step ${i2 + 1} of ${this.steps.length}: </span>` : A}
|
|
83
|
+
<span>${step.label}</span>
|
|
84
|
+
</li>
|
|
85
|
+
`;
|
|
86
|
+
})}
|
|
87
|
+
</ol>
|
|
88
|
+
</nav>
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
customElements.define("impkt-progress", ImpktProgress);
|
|
93
|
+
|
|
94
|
+
export {
|
|
95
|
+
ImpktProgress
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=chunk-SHGQMQXS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/progress.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpktElement } from '../base/ImpktElement';\nimport { visuallyHidden } from '../base/styles';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\nexport interface ProgressStep {\n id: string;\n label: string;\n}\n\n/**\n * Where the customer is in a journey.\n *\n * **It is not a `progressbar`.** That role is for a task completing — a file\n * uploading, a price calculating — and it carries `aria-valuenow`. A journey\n * indicator is navigation: an ordered list of named steps with\n * `aria-current=\"step\"` on the one you are on. Using `progressbar` here\n * announces a percentage and loses the step names, which are the only useful\n * part.\n *\n * **The position is said in words.** \"Step 2 of 5\" is visually hidden and read\n * aloud, because the visual design communicates position through colour and a\n * filled bar, and neither is available to a screen-reader user — nor to anyone\n * who cannot distinguish the filled colour from the empty one, which is 1.4.1.\n\n *\n * @category content\n * @icon progress\n */\nexport class ImpktProgress extends ImpktElement {\n static properties = {\n steps: { type: Array },\n current: { type: String },\n label: { type: String },\n };\n\n declare steps: ProgressStep[];\n /** The id of the step being shown. */\n declare current: string;\n declare label: string;\n\n constructor() {\n super();\n this.steps = [];\n this.current = '';\n this.label = 'Progress';\n }\n\n static styles = [\n ...ImpktElement.styles,\n css`\n :host {\n display: block;\n margin-block-end: ${space(5)};\n }\n ol {\n display: flex;\n gap: ${space(2)};\n list-style: none;\n margin: 0;\n padding: 0;\n }\n li {\n flex: 1;\n font-size: ${fontSize('xs')};\n color: ${t.textMuted};\n padding-block-start: ${space(2)};\n border-block-start: 4px solid ${t.border};\n }\n li[data-state='done'] {\n color: ${t.text};\n border-block-start-color: ${t.brand};\n }\n li[data-state='current'] {\n color: ${t.text};\n font-weight: ${fontWeight('semibold')};\n border-block-start-color: ${t.brand};\n }\n .sr-only {\n ${visuallyHidden}\n }\n /* Below 30rem the labels stop fitting; the position in words is the part\n that has to survive, so the list collapses to bars and the current\n step's name. */\n @media (max-width: 30rem) {\n li:not([data-state='current']) span:not(.sr-only) {\n ${visuallyHidden}\n }\n }\n `,\n ];\n\n render(): TemplateResult {\n const index = this.steps.findIndex((s) => s.id === this.current);\n return html`\n <nav part=\"nav\" aria-label=${this.label}>\n <ol part=\"list\">\n ${this.steps.map((step, i) => {\n const state = i < index ? 'done' : i === index ? 'current' : 'todo';\n return html`\n <li data-state=${state} aria-current=${state === 'current' ? 'step' : nothing}>\n ${state === 'current'\n ? html`<span class=\"sr-only\">Step ${i + 1} of ${this.steps.length}: </span>`\n : nothing}\n <span>${step.label}</span>\n </li>\n `;\n })}\n </ol>\n </nav>\n `;\n }\n}\n\ncustomElements.define('impkt-progress', ImpktProgress);\n\ndeclare global {\n interface HTMLElementTagNameMap { 'impkt-progress': ImpktProgress }\n}\n"],"mappings":";;;;;;;;;;;;;AA6BO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EAC9C;AAAA,SAAO,aAAa;AAAA,MAClB,OAAO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GxB,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAIV;AACF;AAEA,eAAe,OAAO,kBAAkB,aAAa;","names":["i"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A,
|
|
3
|
+
ImpktElement,
|
|
4
|
+
b,
|
|
5
|
+
fontSize,
|
|
6
|
+
fontWeight,
|
|
7
|
+
i,
|
|
8
|
+
space,
|
|
9
|
+
t
|
|
10
|
+
} from "./chunk-G6X62CFC.js";
|
|
11
|
+
|
|
12
|
+
// packages/ui/src/components/price.ts
|
|
13
|
+
var ImpktPrice = class extends ImpktElement {
|
|
14
|
+
static {
|
|
15
|
+
this.properties = {
|
|
16
|
+
amount: { type: Number },
|
|
17
|
+
currency: { type: String },
|
|
18
|
+
locale: { type: String },
|
|
19
|
+
period: { type: String },
|
|
20
|
+
size: { type: String, reflect: true },
|
|
21
|
+
pending: { type: String }
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.amount = void 0;
|
|
27
|
+
this.currency = "GBP";
|
|
28
|
+
this.locale = "en-GB";
|
|
29
|
+
this.period = "";
|
|
30
|
+
this.size = "xl";
|
|
31
|
+
this.pending = "\u2014";
|
|
32
|
+
}
|
|
33
|
+
static {
|
|
34
|
+
this.styles = [
|
|
35
|
+
...ImpktElement.styles,
|
|
36
|
+
i`
|
|
37
|
+
:host {
|
|
38
|
+
display: inline-flex;
|
|
39
|
+
align-items: baseline;
|
|
40
|
+
gap: ${space(1)};
|
|
41
|
+
color: ${t.text};
|
|
42
|
+
}
|
|
43
|
+
.amount {
|
|
44
|
+
font-family: ${t.fontHeading};
|
|
45
|
+
font-weight: ${fontWeight("bold")};
|
|
46
|
+
/* Tabular figures so a price does not reflow as the digits change,
|
|
47
|
+
which otherwise makes a recalculating price jitter. */
|
|
48
|
+
font-variant-numeric: tabular-nums;
|
|
49
|
+
}
|
|
50
|
+
:host([size='md']) .amount { font-size: ${fontSize("lg")}; }
|
|
51
|
+
:host([size='lg']) .amount { font-size: ${fontSize("2xl")}; }
|
|
52
|
+
:host([size='xl']) .amount { font-size: ${fontSize("3xl")}; }
|
|
53
|
+
.period {
|
|
54
|
+
font-size: ${fontSize("sm")};
|
|
55
|
+
color: ${t.textMuted};
|
|
56
|
+
}
|
|
57
|
+
`
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
get formatted() {
|
|
61
|
+
if (this.amount === void 0 || Number.isNaN(this.amount)) return this.pending;
|
|
62
|
+
try {
|
|
63
|
+
return new Intl.NumberFormat(this.locale, {
|
|
64
|
+
style: "currency",
|
|
65
|
+
currency: this.currency
|
|
66
|
+
}).format(this.amount / 100);
|
|
67
|
+
} catch {
|
|
68
|
+
return (this.amount / 100).toFixed(2);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
render() {
|
|
72
|
+
return b`
|
|
73
|
+
<span class="amount" part="amount">${this.formatted}</span>
|
|
74
|
+
${this.period ? b`<span class="period" part="period">${this.period}</span>` : A}
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
customElements.define("impkt-price", ImpktPrice);
|
|
79
|
+
|
|
80
|
+
export {
|
|
81
|
+
ImpktPrice
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=chunk-TWCXYY4Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/price.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpktElement } from '../base/ImpktElement';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\n/**\n * A money amount.\n *\n * This component exists because of a decision taken in the content model: a\n * binding names a source and cannot compute\n * ([ADR 0003](../../../../docs/decisions/0003-binding-expressions.md)). The\n * consequence is that formatting lives here, where the locale and the currency\n * are known, rather than in authored content — so there is one place that\n * decides what \"£24.99\" looks like, and nobody writes a format string into a\n * CMS field.\n *\n * **The amount is one text node.** Splitting the pounds and the pence into\n * separate elements for typographic effect makes some screen readers read them\n * as two numbers, and \"twenty-four ninety-nine\" becomes \"twenty four, ninety\n * nine\". The visual emphasis is done with CSS over one node instead.\n *\n * **Minor units in, major units out.** `amount` is in pence, because a price\n * that arrives from a pricing API as a float has already lost money to binary\n * rounding before it reaches the screen.\n\n *\n * @category content\n * @icon price\n */\nexport class ImpktPrice extends ImpktElement {\n static properties = {\n amount: { type: Number },\n currency: { type: String },\n locale: { type: String },\n period: { type: String },\n size: { type: String, reflect: true },\n pending: { type: String },\n };\n\n /** In minor units — pence, cents. */\n declare amount: number | undefined;\n declare currency: string;\n declare locale: string;\n /** \"a month\", \"a year\". Read after the amount. */\n declare period: string;\n declare size: 'md' | 'lg' | 'xl';\n /** Shown while there is no amount yet. A price takes seconds to arrive. */\n declare pending: string;\n\n constructor() {\n super();\n this.amount = undefined;\n this.currency = 'GBP';\n this.locale = 'en-GB';\n this.period = '';\n this.size = 'xl';\n this.pending = '—';\n }\n\n static styles = [\n ...ImpktElement.styles,\n css`\n :host {\n display: inline-flex;\n align-items: baseline;\n gap: ${space(1)};\n color: ${t.text};\n }\n .amount {\n font-family: ${t.fontHeading};\n font-weight: ${fontWeight('bold')};\n /* Tabular figures so a price does not reflow as the digits change,\n which otherwise makes a recalculating price jitter. */\n font-variant-numeric: tabular-nums;\n }\n :host([size='md']) .amount { font-size: ${fontSize('lg')}; }\n :host([size='lg']) .amount { font-size: ${fontSize('2xl')}; }\n :host([size='xl']) .amount { font-size: ${fontSize('3xl')}; }\n .period {\n font-size: ${fontSize('sm')};\n color: ${t.textMuted};\n }\n `,\n ];\n\n private get formatted(): string {\n if (this.amount === undefined || Number.isNaN(this.amount)) return this.pending;\n try {\n return new Intl.NumberFormat(this.locale, {\n style: 'currency',\n currency: this.currency,\n }).format(this.amount / 100);\n } catch {\n // An unknown currency or locale must not take the page down. The number\n // is still the most useful thing on the screen.\n return (this.amount / 100).toFixed(2);\n }\n }\n\n render(): TemplateResult {\n return html`\n <span class=\"amount\" part=\"amount\">${this.formatted}</span>\n ${this.period ? html`<span class=\"period\" part=\"period\">${this.period}</span>` : nothing}\n `;\n }\n}\n\ncustomElements.define('impkt-price', ImpktPrice);\n\ndeclare global {\n interface HTMLElementTagNameMap { 'impkt-price': ImpktPrice }\n}\n"],"mappings":";;;;;;;;;;;;AA4BO,IAAM,aAAN,cAAyB,aAAa;AAAA,EAC3C;AAAA,SAAO,aAAa;AAAA,MAClB,QAAQ,EAAE,MAAM,OAAO;AAAA,MACvB,UAAU,EAAE,MAAM,OAAO;AAAA,MACzB,QAAQ,EAAE,MAAM,OAAO;AAAA,MACvB,QAAQ,EAAE,MAAM,OAAO;AAAA,MACvB,MAAM,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MACpC,SAAS,EAAE,MAAM,OAAO;AAAA,IAC1B;AAAA;AAAA,EAYA,cAAc;AACZ,UAAM;AACN,SAAK,SAAS;AACd,SAAK,WAAW;AAChB,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA;AAAA,SAAO,SAAS;AAAA,MACd,GAAG,aAAa;AAAA,MAChB;AAAA;AAAA;AAAA;AAAA,eAIW,MAAM,CAAC,CAAC;AAAA,iBACN,EAAE,IAAI;AAAA;AAAA;AAAA,uBAGA,EAAE,WAAW;AAAA,uBACb,WAAW,MAAM,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,gDAKO,SAAS,IAAI,CAAC;AAAA,gDACd,SAAS,KAAK,CAAC;AAAA,gDACf,SAAS,KAAK,CAAC;AAAA;AAAA,qBAE1C,SAAS,IAAI,CAAC;AAAA,iBAClB,EAAE,SAAS;AAAA;AAAA;AAAA,IAG1B;AAAA;AAAA,EAEA,IAAY,YAAoB;AAC9B,QAAI,KAAK,WAAW,UAAa,OAAO,MAAM,KAAK,MAAM,EAAG,QAAO,KAAK;AACxE,QAAI;AACF,aAAO,IAAI,KAAK,aAAa,KAAK,QAAQ;AAAA,QACxC,OAAO;AAAA,QACP,UAAU,KAAK;AAAA,MACjB,CAAC,EAAE,OAAO,KAAK,SAAS,GAAG;AAAA,IAC7B,QAAQ;AAGN,cAAQ,KAAK,SAAS,KAAK,QAAQ,CAAC;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,SAAyB;AACvB,WAAO;AAAA,2CACgC,KAAK,SAAS;AAAA,QACjD,KAAK,SAAS,uCAA0C,KAAK,MAAM,YAAY,CAAO;AAAA;AAAA,EAE5F;AACF;AAEA,eAAe,OAAO,eAAe,UAAU;","names":[]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A,
|
|
3
|
+
ImpktElement,
|
|
4
|
+
b,
|
|
5
|
+
fontSize,
|
|
6
|
+
fontWeight,
|
|
7
|
+
i,
|
|
8
|
+
space,
|
|
9
|
+
t
|
|
10
|
+
} from "./chunk-G6X62CFC.js";
|
|
11
|
+
|
|
12
|
+
// packages/ui/src/components/alert.ts
|
|
13
|
+
var ImpktAlert = class _ImpktAlert extends ImpktElement {
|
|
14
|
+
static {
|
|
15
|
+
this.properties = {
|
|
16
|
+
tone: { type: String, reflect: true },
|
|
17
|
+
heading: { type: String },
|
|
18
|
+
toneLabel: { type: String, attribute: "tone-label" }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
this.tone = "info";
|
|
24
|
+
this.heading = "";
|
|
25
|
+
this.toneLabel = "";
|
|
26
|
+
}
|
|
27
|
+
static {
|
|
28
|
+
this.TONE_WORDS = {
|
|
29
|
+
info: "Information",
|
|
30
|
+
success: "Success",
|
|
31
|
+
warning: "Warning",
|
|
32
|
+
danger: "Error"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static {
|
|
36
|
+
this.styles = [
|
|
37
|
+
...ImpktElement.styles,
|
|
38
|
+
i`
|
|
39
|
+
:host {
|
|
40
|
+
display: block;
|
|
41
|
+
margin-block-end: ${space(4)};
|
|
42
|
+
}
|
|
43
|
+
.alert {
|
|
44
|
+
padding: ${space(4)};
|
|
45
|
+
border-radius: ${t.radius};
|
|
46
|
+
border-inline-start: 4px solid;
|
|
47
|
+
font-size: ${fontSize("md")};
|
|
48
|
+
}
|
|
49
|
+
.heading {
|
|
50
|
+
font-weight: ${fontWeight("semibold")};
|
|
51
|
+
margin-block-end: ${space(1)};
|
|
52
|
+
}
|
|
53
|
+
:host([tone='info']) .alert {
|
|
54
|
+
background: ${t.infoSubtle};
|
|
55
|
+
border-color: ${t.info};
|
|
56
|
+
color: ${t.text};
|
|
57
|
+
}
|
|
58
|
+
:host([tone='success']) .alert {
|
|
59
|
+
background: ${t.successSubtle};
|
|
60
|
+
border-color: ${t.success};
|
|
61
|
+
color: ${t.text};
|
|
62
|
+
}
|
|
63
|
+
:host([tone='warning']) .alert {
|
|
64
|
+
background: ${t.warningSubtle};
|
|
65
|
+
border-color: ${t.warning};
|
|
66
|
+
color: ${t.text};
|
|
67
|
+
}
|
|
68
|
+
:host([tone='danger']) .alert {
|
|
69
|
+
background: ${t.dangerSubtle};
|
|
70
|
+
border-color: ${t.danger};
|
|
71
|
+
color: ${t.text};
|
|
72
|
+
}
|
|
73
|
+
/* Colour is the only signal left in forced-colours mode, and it is gone.
|
|
74
|
+
The border keeps the boundary; the tone word in the label carries the
|
|
75
|
+
meaning. */
|
|
76
|
+
@media (forced-colors: active) {
|
|
77
|
+
.alert {
|
|
78
|
+
border: 1px solid CanvasText;
|
|
79
|
+
border-inline-start-width: 4px;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
render() {
|
|
86
|
+
const word = this.toneLabel || _ImpktAlert.TONE_WORDS[this.tone];
|
|
87
|
+
return b`
|
|
88
|
+
<div
|
|
89
|
+
class="alert"
|
|
90
|
+
part="alert"
|
|
91
|
+
role=${this.tone === "danger" ? "alert" : "status"}
|
|
92
|
+
aria-label=${this.heading ? A : word}
|
|
93
|
+
>
|
|
94
|
+
${this.heading ? b`<div class="heading" part="heading">
|
|
95
|
+
<span class="tone-word">${word}:</span> ${this.heading}
|
|
96
|
+
</div>` : A}
|
|
97
|
+
<slot></slot>
|
|
98
|
+
</div>
|
|
99
|
+
`;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
customElements.define("impkt-alert", ImpktAlert);
|
|
103
|
+
|
|
104
|
+
export {
|
|
105
|
+
ImpktAlert
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=chunk-UTL446G6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/alert.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpktElement } from '../base/ImpktElement';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\nexport type AlertTone = 'info' | 'success' | 'warning' | 'danger';\n\n/**\n * A notice.\n *\n * **The role depends on the tone, and that is a real distinction.** `alert`\n * interrupts whatever a screen reader is saying; `status` waits for a pause.\n * A failed payment earns the interruption. \"Your basket has been saved\" does\n * not, and using `alert` for it is how users learn to tune the live region\n * out — at which point the one that mattered is also lost.\n *\n * **The tone is never carried by colour alone.** Each tone ships a word, in\n * the accessible name, because 1.4.1 Use of Colour says a red border is not a\n * message and because a red border is invisible in forced-colours mode.\n\n *\n * @category feedback\n * @icon alert\n * @slot - The body of the notice.\n */\nexport class ImpktAlert extends ImpktElement {\n static properties = {\n tone: { type: String, reflect: true },\n heading: { type: String },\n toneLabel: { type: String, attribute: 'tone-label' },\n };\n\n declare tone: AlertTone;\n declare heading: string;\n /** Overrides the default word for the tone, for translation. */\n declare toneLabel: string;\n\n constructor() {\n super();\n this.tone = 'info';\n this.heading = '';\n this.toneLabel = '';\n }\n\n private static readonly TONE_WORDS: Record<AlertTone, string> = {\n info: 'Information',\n success: 'Success',\n warning: 'Warning',\n danger: 'Error',\n };\n\n static styles = [\n ...ImpktElement.styles,\n css`\n :host {\n display: block;\n margin-block-end: ${space(4)};\n }\n .alert {\n padding: ${space(4)};\n border-radius: ${t.radius};\n border-inline-start: 4px solid;\n font-size: ${fontSize('md')};\n }\n .heading {\n font-weight: ${fontWeight('semibold')};\n margin-block-end: ${space(1)};\n }\n :host([tone='info']) .alert {\n background: ${t.infoSubtle};\n border-color: ${t.info};\n color: ${t.text};\n }\n :host([tone='success']) .alert {\n background: ${t.successSubtle};\n border-color: ${t.success};\n color: ${t.text};\n }\n :host([tone='warning']) .alert {\n background: ${t.warningSubtle};\n border-color: ${t.warning};\n color: ${t.text};\n }\n :host([tone='danger']) .alert {\n background: ${t.dangerSubtle};\n border-color: ${t.danger};\n color: ${t.text};\n }\n /* Colour is the only signal left in forced-colours mode, and it is gone.\n The border keeps the boundary; the tone word in the label carries the\n meaning. */\n @media (forced-colors: active) {\n .alert {\n border: 1px solid CanvasText;\n border-inline-start-width: 4px;\n }\n }\n `,\n ];\n\n render(): TemplateResult {\n const word = this.toneLabel || ImpktAlert.TONE_WORDS[this.tone];\n return html`\n <div\n class=\"alert\"\n part=\"alert\"\n role=${this.tone === 'danger' ? 'alert' : 'status'}\n aria-label=${this.heading ? nothing : word}\n >\n ${this.heading\n ? html`<div class=\"heading\" part=\"heading\">\n <span class=\"tone-word\">${word}:</span> ${this.heading}\n </div>`\n : nothing}\n <slot></slot>\n </div>\n `;\n }\n}\n\ncustomElements.define('impkt-alert', ImpktAlert);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'impkt-alert': ImpktAlert;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAwBO,IAAM,aAAN,MAAM,oBAAmB,aAAa;AAAA,EAC3C;AAAA,SAAO,aAAa;AAAA,MAClB,MAAM,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MACpC,SAAS,EAAE,MAAM,OAAO;AAAA,MACxB,WAAW,EAAE,MAAM,QAAQ,WAAW,aAAa;AAAA,IACrD;AAAA;AAAA,EAOA,cAAc;AACZ,UAAM;AACN,SAA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