@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,138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldElement
|
|
3
|
+
} from "./chunk-5NBYZ5UC.js";
|
|
4
|
+
import {
|
|
5
|
+
A,
|
|
6
|
+
b,
|
|
7
|
+
fontSize,
|
|
8
|
+
i,
|
|
9
|
+
space,
|
|
10
|
+
t
|
|
11
|
+
} from "./chunk-G6X62CFC.js";
|
|
12
|
+
|
|
13
|
+
// packages/ui/src/components/date-input.ts
|
|
14
|
+
var ImpktDateInput = class extends FieldElement {
|
|
15
|
+
static {
|
|
16
|
+
this.properties = {
|
|
17
|
+
...FieldElement.properties,
|
|
18
|
+
day: { type: String },
|
|
19
|
+
month: { type: String },
|
|
20
|
+
year: { type: String },
|
|
21
|
+
autocompleteSection: { type: String, attribute: "autocomplete-section" }
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.day = "";
|
|
27
|
+
this.month = "";
|
|
28
|
+
this.year = "";
|
|
29
|
+
this.autocompleteSection = "bday";
|
|
30
|
+
}
|
|
31
|
+
static {
|
|
32
|
+
this.styles = [
|
|
33
|
+
...FieldElement.styles,
|
|
34
|
+
i`
|
|
35
|
+
fieldset {
|
|
36
|
+
border: 0;
|
|
37
|
+
margin: 0;
|
|
38
|
+
padding: 0;
|
|
39
|
+
min-inline-size: 0;
|
|
40
|
+
}
|
|
41
|
+
legend {
|
|
42
|
+
padding: 0;
|
|
43
|
+
}
|
|
44
|
+
.parts {
|
|
45
|
+
display: flex;
|
|
46
|
+
gap: ${space(3)};
|
|
47
|
+
}
|
|
48
|
+
.part {
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-direction: column;
|
|
51
|
+
gap: ${space(1)};
|
|
52
|
+
}
|
|
53
|
+
.part label {
|
|
54
|
+
font-size: ${fontSize("sm")};
|
|
55
|
+
color: ${t.textMuted};
|
|
56
|
+
}
|
|
57
|
+
input {
|
|
58
|
+
min-block-size: 44px;
|
|
59
|
+
padding: ${space(3)};
|
|
60
|
+
font-family: inherit;
|
|
61
|
+
font-size: ${fontSize("md")};
|
|
62
|
+
color: ${t.text};
|
|
63
|
+
background: ${t.surfaceCard};
|
|
64
|
+
border: ${t.borderThin} solid ${t.border};
|
|
65
|
+
border-radius: ${t.radius};
|
|
66
|
+
inline-size: 4ch;
|
|
67
|
+
}
|
|
68
|
+
.year input {
|
|
69
|
+
inline-size: 6ch;
|
|
70
|
+
}
|
|
71
|
+
:host([invalid]) input {
|
|
72
|
+
border-color: ${t.danger};
|
|
73
|
+
border-width: ${t.borderThick};
|
|
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
|
+
datePart(name, label, length, autocomplete) {
|
|
84
|
+
const id = this.id_(name);
|
|
85
|
+
return b`
|
|
86
|
+
<div class="part ${name}">
|
|
87
|
+
<label for=${id}>${label}</label>
|
|
88
|
+
<input
|
|
89
|
+
id=${id}
|
|
90
|
+
type="text"
|
|
91
|
+
inputmode="numeric"
|
|
92
|
+
maxlength=${length}
|
|
93
|
+
.value=${this[name]}
|
|
94
|
+
autocomplete=${this.autocompleteSection ? `${this.autocompleteSection}-${autocomplete}` : A}
|
|
95
|
+
?disabled=${this.disabled}
|
|
96
|
+
@input=${(e) => {
|
|
97
|
+
this[name] = e.target.value;
|
|
98
|
+
this.emit();
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
102
|
+
`;
|
|
103
|
+
}
|
|
104
|
+
/** ISO, or empty while incomplete. Partial dates are not half-valid. */
|
|
105
|
+
emit() {
|
|
106
|
+
const complete = this.day && this.month && this.year.length === 4;
|
|
107
|
+
const iso = complete ? `${this.year}-${this.month.padStart(2, "0")}-${this.day.padStart(2, "0")}` : "";
|
|
108
|
+
this.setFormValue(iso);
|
|
109
|
+
}
|
|
110
|
+
renderControl() {
|
|
111
|
+
return b`
|
|
112
|
+
<div class="parts" part="parts">
|
|
113
|
+
${this.datePart("day", "Day", 2, "day")}
|
|
114
|
+
${this.datePart("month", "Month", 2, "month")}
|
|
115
|
+
${this.datePart("year", "Year", 4, "year")}
|
|
116
|
+
</div>
|
|
117
|
+
`;
|
|
118
|
+
}
|
|
119
|
+
render() {
|
|
120
|
+
return b`
|
|
121
|
+
<fieldset part="fieldset" aria-describedby=${this.describedBy} aria-invalid=${this.error ? "true" : A}>
|
|
122
|
+
${this.renderLabel()}
|
|
123
|
+
${this.description ? b`<div class="description" id=${this.id_("description")} part="description">${this.description}</div>` : A}
|
|
124
|
+
${this.renderControl()}
|
|
125
|
+
<div class="error" id=${this.id_("error")} part="error" aria-live="polite">${this.error || A}</div>
|
|
126
|
+
</fieldset>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
updated(changed) {
|
|
130
|
+
if (changed.has("error")) this.toggleAttribute("invalid", Boolean(this.error));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
customElements.define("impkt-date-input", ImpktDateInput);
|
|
134
|
+
|
|
135
|
+
export {
|
|
136
|
+
ImpktDateInput
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=chunk-M3WQZDWU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/date-input.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { FieldElement } from '../base/FieldElement';\nimport { fontSize, space, t } from '../base/tokens';\n\n/**\n * A date, as three fields.\n *\n * **Why not `<input type=\"date\">`.** The native control is excellent for\n * picking a date near today — an appointment, a start date — and poor for a\n * date of birth, which is the date this product asks for most. Its picker\n * opens on the current month and makes a user born in 1958 navigate eight\n * hundred steps back, its text entry expects a locale-specific format the\n * field does not state, and its rendering differs enough between browsers that\n * no single hint is correct everywhere.\n *\n * Three fields is the pattern government services converged on after testing\n * it on exactly this problem. Each part is typed directly, in any order, with\n * no picker to fight.\n *\n * **The accessibility shape.** A `<fieldset>` and `<legend>` ask the question\n * once; each part has its own visible label, so \"Month\" is announced rather\n * than \"second field\"; `inputmode=\"numeric\"` brings up a number pad without\n * `type=\"number\"`, which on a date part gives spinners, scroll-wheel surprises\n * and silent stripping of a leading zero. The parts carry `autocomplete`\n * tokens so autofill still works, which is 1.3.5.\n\n *\n * @category form\n * @icon calendar\n */\nexport class ImpktDateInput extends FieldElement {\n static properties = {\n ...FieldElement.properties,\n day: { type: String },\n month: { type: String },\n year: { type: String },\n autocompleteSection: { type: String, attribute: 'autocomplete-section' },\n };\n\n declare day: string;\n declare month: string;\n declare year: string;\n /** \"bday\" fills a date of birth. Empty disables autofill for this field. */\n declare autocompleteSection: string;\n\n constructor() {\n super();\n this.day = '';\n this.month = '';\n this.year = '';\n this.autocompleteSection = 'bday';\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 .parts {\n display: flex;\n gap: ${space(3)};\n }\n .part {\n display: flex;\n flex-direction: column;\n gap: ${space(1)};\n }\n .part label {\n font-size: ${fontSize('sm')};\n color: ${t.textMuted};\n }\n input {\n min-block-size: 44px;\n padding: ${space(3)};\n font-family: inherit;\n font-size: ${fontSize('md')};\n color: ${t.text};\n background: ${t.surfaceCard};\n border: ${t.borderThin} solid ${t.border};\n border-radius: ${t.radius};\n inline-size: 4ch;\n }\n .year input {\n inline-size: 6ch;\n }\n :host([invalid]) input {\n border-color: ${t.danger};\n border-width: ${t.borderThick};\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 datePart(\n name: 'day' | 'month' | 'year',\n label: string,\n length: number,\n autocomplete: string,\n ): TemplateResult {\n const id = this.id_(name);\n return html`\n <div class=\"part ${name}\">\n <label for=${id}>${label}</label>\n <input\n id=${id}\n type=\"text\"\n inputmode=\"numeric\"\n maxlength=${length}\n .value=${this[name]}\n autocomplete=${this.autocompleteSection ? `${this.autocompleteSection}-${autocomplete}` : nothing}\n ?disabled=${this.disabled}\n @input=${(e: Event) => {\n this[name] = (e.target as HTMLInputElement).value;\n this.emit();\n }}\n />\n </div>\n `;\n }\n\n /** ISO, or empty while incomplete. Partial dates are not half-valid. */\n private emit(): void {\n const complete = this.day && this.month && this.year.length === 4;\n const iso = complete\n ? `${this.year}-${this.month.padStart(2, '0')}-${this.day.padStart(2, '0')}`\n : '';\n this.setFormValue(iso);\n }\n\n protected renderControl(): TemplateResult {\n return html`\n <div class=\"parts\" part=\"parts\">\n ${this.datePart('day', 'Day', 2, 'day')}\n ${this.datePart('month', 'Month', 2, 'month')}\n ${this.datePart('year', 'Year', 4, 'year')}\n </div>\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-date-input', ImpktDateInput);\n\ndeclare global {\n interface HTMLElementTagNameMap { 'impkt-date-input': ImpktDateInput }\n}\n"],"mappings":";;;;;;;;;;;;;AA8BO,IAAM,iBAAN,cAA6B,aAAa;AAAA,EAC/C;AAAA,SAAO,aAAa;AAAA,MAClB,GAAG,aAAa;AAAA,MAChB,KAAK,EAAE,MAAM,OAAO;AAAA,MACpB,OAAO,EAAE,MAAM,OAAO;AAAA,MACtB,MAAM,EAAE,MAAM,OAAO;AAAA,MACrB,qBAAqB,EAAE,MAAM,QAAQ,WAAW,uBAAuB;AAAA,IACzE;AAAA;AAAA,EAQA,cAAc;AACZ,UAAM;AACN,SAAK,MAAM;AACX,SAAK,QAAQ;AACb,SAAK,OAAO;AACZ,SAAK,sBAAsB;AAAA,EAC7B;AAAA,EAEA;AAAA,SAAO,SAAS;AAAA,MACd,GAAG,aAAa;AAAA,MAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAYW,MAAM,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,eAKR,MAAM,CAAC,CAAC;AAAA;AAAA;AAAA,qBAGF,SAAS,IAAI,CAAC;AAAA,iBAClB,EAAE,SA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AK,CAAC;AAAA,UACrC,KAAK,SAAS,SAAS,SAAS,GAAG,OAAO,CAAC;AAAA,UAC3C,KAAK,SAAS,QAAQ,QAAQ,GAAG,MAAM,CAAC;AAAA;AAAA;AAAA,EAGhD;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,oBAAoB,cAAc;","names":[]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A,
|
|
3
|
+
ImpktElement,
|
|
4
|
+
b,
|
|
5
|
+
focusRing,
|
|
6
|
+
fontSize,
|
|
7
|
+
fontWeight,
|
|
8
|
+
i,
|
|
9
|
+
space,
|
|
10
|
+
t,
|
|
11
|
+
targetSize
|
|
12
|
+
} from "./chunk-G6X62CFC.js";
|
|
13
|
+
|
|
14
|
+
// packages/ui/src/components/dialog.ts
|
|
15
|
+
var ImpktDialog = class extends ImpktElement {
|
|
16
|
+
static {
|
|
17
|
+
this.properties = {
|
|
18
|
+
open: { type: Boolean, reflect: true },
|
|
19
|
+
heading: { type: String },
|
|
20
|
+
closeLabel: { type: String, attribute: "close-label" },
|
|
21
|
+
dismissible: { type: Boolean }
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.open = false;
|
|
27
|
+
this.heading = "";
|
|
28
|
+
this.closeLabel = "Close";
|
|
29
|
+
this.dismissible = true;
|
|
30
|
+
}
|
|
31
|
+
static {
|
|
32
|
+
this.styles = [
|
|
33
|
+
...ImpktElement.styles,
|
|
34
|
+
focusRing,
|
|
35
|
+
i`
|
|
36
|
+
dialog {
|
|
37
|
+
padding: 0;
|
|
38
|
+
border: 0;
|
|
39
|
+
border-radius: ${t.radiusLg};
|
|
40
|
+
background: ${t.surfaceCard};
|
|
41
|
+
color: ${t.text};
|
|
42
|
+
max-inline-size: min(32rem, calc(100vw - 2rem));
|
|
43
|
+
/* 1.4.10 Reflow: a dialog taller than the viewport must scroll inside
|
|
44
|
+
itself rather than clipping, at 320px and at 400% zoom alike. */
|
|
45
|
+
max-block-size: calc(100vh - 2rem);
|
|
46
|
+
overflow: auto;
|
|
47
|
+
}
|
|
48
|
+
dialog::backdrop {
|
|
49
|
+
background: rgb(0 0 0 / 0.5);
|
|
50
|
+
}
|
|
51
|
+
.head {
|
|
52
|
+
display: flex;
|
|
53
|
+
align-items: flex-start;
|
|
54
|
+
justify-content: space-between;
|
|
55
|
+
gap: ${space(3)};
|
|
56
|
+
padding: ${space(5)} ${space(5)} 0;
|
|
57
|
+
}
|
|
58
|
+
.heading {
|
|
59
|
+
margin: 0;
|
|
60
|
+
font-family: ${t.fontHeading};
|
|
61
|
+
font-size: ${fontSize("xl")};
|
|
62
|
+
font-weight: ${fontWeight("bold")};
|
|
63
|
+
color: ${t.textHeading};
|
|
64
|
+
}
|
|
65
|
+
.body {
|
|
66
|
+
padding: ${space(4)} ${space(5)} ${space(5)};
|
|
67
|
+
}
|
|
68
|
+
.close {
|
|
69
|
+
${targetSize}
|
|
70
|
+
flex: none;
|
|
71
|
+
background: none;
|
|
72
|
+
border: 0;
|
|
73
|
+
border-radius: ${t.radius};
|
|
74
|
+
font: inherit;
|
|
75
|
+
font-size: ${fontSize("lg")};
|
|
76
|
+
color: ${t.text};
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
}
|
|
79
|
+
`
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
get dialog() {
|
|
83
|
+
return this.renderRoot.querySelector("dialog");
|
|
84
|
+
}
|
|
85
|
+
updated(changed) {
|
|
86
|
+
if (!changed.has("open")) return;
|
|
87
|
+
const dialog = this.dialog;
|
|
88
|
+
if (!dialog) return;
|
|
89
|
+
if (this.open) {
|
|
90
|
+
if (typeof dialog.showModal === "function") dialog.showModal();
|
|
91
|
+
else dialog.setAttribute("open", "");
|
|
92
|
+
} else if (typeof dialog.close === "function" && dialog.open) {
|
|
93
|
+
dialog.close();
|
|
94
|
+
} else {
|
|
95
|
+
dialog.removeAttribute("open");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
close() {
|
|
99
|
+
this.open = false;
|
|
100
|
+
this.dispatchEvent(new CustomEvent("impkt-close", { bubbles: true, composed: true }));
|
|
101
|
+
}
|
|
102
|
+
render() {
|
|
103
|
+
return b`
|
|
104
|
+
<dialog
|
|
105
|
+
part="dialog"
|
|
106
|
+
aria-labelledby=${this.heading ? this.id_("heading") : A}
|
|
107
|
+
@cancel=${(e) => {
|
|
108
|
+
if (!this.dismissible) e.preventDefault();
|
|
109
|
+
else this.close();
|
|
110
|
+
}}
|
|
111
|
+
@close=${() => {
|
|
112
|
+
if (this.open) this.close();
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
<div class="head">
|
|
116
|
+
${this.heading ? b`<h2 class="heading" id=${this.id_("heading")} part="heading">${this.heading}</h2>` : A}
|
|
117
|
+
${this.dismissible ? b`<button class="close" part="close" type="button" @click=${this.close}>
|
|
118
|
+
<span aria-hidden="true">×</span>
|
|
119
|
+
<span class="sr-only" style="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">${this.closeLabel}</span>
|
|
120
|
+
</button>` : A}
|
|
121
|
+
</div>
|
|
122
|
+
<div class="body" part="body"><slot></slot></div>
|
|
123
|
+
</dialog>
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
customElements.define("impkt-dialog", ImpktDialog);
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
ImpktDialog
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=chunk-O72RTRIJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/dialog.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpktElement } from '../base/ImpktElement';\nimport { focusRing, targetSize } from '../base/styles';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\n/**\n * A modal dialog — \"are you sure you want to leave this order?\".\n *\n * **It is a native `<dialog>` opened with `showModal()`, and that is the whole\n * design.** The platform then provides, correctly and in every browser: a\n * focus trap, Escape to close, the rest of the page made inert so a screen\n * reader cannot wander out of the dialog, rendering in the top layer so no\n * `z-index` can cover it, and focus returned to whatever opened it when it\n * closes.\n *\n * Every one of those is a thing hand-rolled modals get wrong. The focus trap\n * is the famous one, but inertness is the worse failure: a dialog that traps\n * the Tab key but leaves the background in the accessibility tree lets a\n * screen-reader user read straight past it into a page they cannot interact\n * with, and nothing on screen tells them that is what happened.\n *\n * What is left to get right is the labelling. `aria-labelledby` points at the\n * dialog's own heading, so it is announced by name on open rather than as\n * \"dialog\".\n\n *\n * @category feedback\n * @icon dialog\n * @slot - The body of the dialog.\n */\nexport class ImpktDialog extends ImpktElement {\n static properties = {\n open: { type: Boolean, reflect: true },\n heading: { type: String },\n closeLabel: { type: String, attribute: 'close-label' },\n dismissible: { type: Boolean },\n };\n\n declare open: boolean;\n declare heading: string;\n declare closeLabel: string;\n /** When false, Escape and the backdrop do not close it — a decision must be made. */\n declare dismissible: boolean;\n\n constructor() {\n super();\n this.open = false;\n this.heading = '';\n this.closeLabel = 'Close';\n this.dismissible = true;\n }\n\n static styles = [\n ...ImpktElement.styles,\n focusRing,\n css`\n dialog {\n padding: 0;\n border: 0;\n border-radius: ${t.radiusLg};\n background: ${t.surfaceCard};\n color: ${t.text};\n max-inline-size: min(32rem, calc(100vw - 2rem));\n /* 1.4.10 Reflow: a dialog taller than the viewport must scroll inside\n itself rather than clipping, at 320px and at 400% zoom alike. */\n max-block-size: calc(100vh - 2rem);\n overflow: auto;\n }\n dialog::backdrop {\n background: rgb(0 0 0 / 0.5);\n }\n .head {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n gap: ${space(3)};\n padding: ${space(5)} ${space(5)} 0;\n }\n .heading {\n margin: 0;\n font-family: ${t.fontHeading};\n font-size: ${fontSize('xl')};\n font-weight: ${fontWeight('bold')};\n color: ${t.textHeading};\n }\n .body {\n padding: ${space(4)} ${space(5)} ${space(5)};\n }\n .close {\n ${targetSize}\n flex: none;\n background: none;\n border: 0;\n border-radius: ${t.radius};\n font: inherit;\n font-size: ${fontSize('lg')};\n color: ${t.text};\n cursor: pointer;\n }\n `,\n ];\n\n private get dialog(): HTMLDialogElement | null {\n return this.renderRoot.querySelector('dialog');\n }\n\n updated(changed: Map<string, unknown>): void {\n if (!changed.has('open')) return;\n const dialog = this.dialog;\n if (!dialog) return;\n // happy-dom and older engines do not implement showModal. Falling back to\n // the `open` attribute renders a NON-modal dialog — no focus trap, no\n // inert background — so it is used only to keep tests and ancient browsers\n // from throwing, never as an equivalent.\n if (this.open) {\n if (typeof dialog.showModal === 'function') dialog.showModal();\n else dialog.setAttribute('open', '');\n } else if (typeof dialog.close === 'function' && dialog.open) {\n dialog.close();\n } else {\n dialog.removeAttribute('open');\n }\n }\n\n private close(): void {\n this.open = false;\n this.dispatchEvent(new CustomEvent('impkt-close', { bubbles: true, composed: true }));\n }\n\n render(): TemplateResult {\n return html`\n <dialog\n part=\"dialog\"\n aria-labelledby=${this.heading ? this.id_('heading') : nothing}\n @cancel=${(e: Event) => {\n // `cancel` fires on Escape. Blocking it is what makes a dialog\n // non-dismissible, and it is why `dismissible` exists rather than\n // leaving a caller to re-open on close.\n if (!this.dismissible) e.preventDefault();\n else this.close();\n }}\n @close=${() => { if (this.open) this.close(); }}\n >\n <div class=\"head\">\n ${this.heading\n ? html`<h2 class=\"heading\" id=${this.id_('heading')} part=\"heading\">${this.heading}</h2>`\n : nothing}\n ${this.dismissible\n ? html`<button class=\"close\" part=\"close\" type=\"button\" @click=${this.close}>\n <span aria-hidden=\"true\">×</span>\n <span class=\"sr-only\" style=\"position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)\">${this.closeLabel}</span>\n </button>`\n : nothing}\n </div>\n <div class=\"body\" part=\"body\"><slot></slot></div>\n </dialog>\n `;\n }\n}\n\ncustomElements.define('impkt-dialog', ImpktDialog);\n\ndeclare global {\n interface HTMLElementTagNameMap { 'impkt-dialog': ImpktDialog }\n}\n"],"mappings":";;;;;;;;;;;;;;AA8BO,IAAM,cAAN,cAA0B,aAAa;AAAA,EAC5C;AAAA,SAAO,aAAa;AAAA,MAClB,MAAM,EAAE,MAAM,SAAS,SAAS,KAAK;AAAA,MACrC,SAAS,EAAE,MAAM,OAAO;AAAA,MACxB,YAAY,EAAE,MAAM,QAAQ,WAAW,cAAc;AAAA,MACrD,aAAa,EAAE,MAAM,QAAQ;AAAA,IAC/B;AAAA;AAAA,EAQA,cAAc;AACZ,UAAM;AACN,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA;AAAA,SAAO,SAAS;AAAA,MACd,GAAG,aAAa;AAAA,MAChB;AAAA,MACA;AAAA;AAAA;AAAA;AAAA,yBAIqB,EAAE,QAAQ;AAAA,sBACb,EAAE,WAAW;AAAA,iBAClB,EAAE,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAcR,MAAM,CAAC,CAAC;AAAA,mBACJ,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,uBAIhB,EAAE,WAAW;AAAA,qBACf,SA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BAA8B,KAAK,IAAI,SAAS,CAAC,mBAAmB,KAAK,OAAO,UAChF,CAAO;AAAA,YACT,KAAK,cACH,4DAA+D,KAAK,KAAK;AAAA;AAAA,4HAEqC,KAAK,UAAU;AAAA,2BAE7H,CAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKnB;AACF;AAEA,eAAe,OAAO,gBAAgB,WAAW;","names":[]}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A,
|
|
3
|
+
ImpktElement,
|
|
4
|
+
b,
|
|
5
|
+
focusRing,
|
|
6
|
+
fontSize,
|
|
7
|
+
fontWeight,
|
|
8
|
+
i,
|
|
9
|
+
space,
|
|
10
|
+
t,
|
|
11
|
+
targetSize,
|
|
12
|
+
visuallyHidden
|
|
13
|
+
} from "./chunk-G6X62CFC.js";
|
|
14
|
+
|
|
15
|
+
// packages/ui/src/components/button.ts
|
|
16
|
+
var ImpktButton = class extends ImpktElement {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.internals = null;
|
|
20
|
+
this.variant = "primary";
|
|
21
|
+
this.type = "button";
|
|
22
|
+
this.disabled = false;
|
|
23
|
+
this.busy = false;
|
|
24
|
+
this.busyLabel = "Working";
|
|
25
|
+
this.full = false;
|
|
26
|
+
try {
|
|
27
|
+
this.internals = this.attachInternals();
|
|
28
|
+
} catch {
|
|
29
|
+
this.internals = null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static {
|
|
33
|
+
this.formAssociated = true;
|
|
34
|
+
}
|
|
35
|
+
static {
|
|
36
|
+
this.properties = {
|
|
37
|
+
variant: { type: String, reflect: true },
|
|
38
|
+
type: { type: String },
|
|
39
|
+
disabled: { type: Boolean, reflect: true },
|
|
40
|
+
busy: { type: Boolean, reflect: true },
|
|
41
|
+
busyLabel: { type: String, attribute: "busy-label" },
|
|
42
|
+
full: { type: Boolean, reflect: true }
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
static {
|
|
46
|
+
this.styles = [
|
|
47
|
+
...ImpktElement.styles,
|
|
48
|
+
focusRing,
|
|
49
|
+
i`
|
|
50
|
+
:host {
|
|
51
|
+
display: inline-block;
|
|
52
|
+
}
|
|
53
|
+
:host([full]) {
|
|
54
|
+
display: block;
|
|
55
|
+
}
|
|
56
|
+
button {
|
|
57
|
+
${targetSize}
|
|
58
|
+
display: inline-flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
gap: ${space(2)};
|
|
62
|
+
inline-size: 100%;
|
|
63
|
+
padding: ${space(3)} ${space(5)};
|
|
64
|
+
font-family: inherit;
|
|
65
|
+
font-size: ${fontSize("md")};
|
|
66
|
+
font-weight: ${fontWeight("semibold")};
|
|
67
|
+
line-height: 1.2;
|
|
68
|
+
border-radius: ${t.radius};
|
|
69
|
+
border: ${t.borderThick} solid transparent;
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
transition: background-color 120ms ease-in-out, border-color 120ms ease-in-out;
|
|
72
|
+
}
|
|
73
|
+
/* The cursor is the only thing that changes while busy. Moving or
|
|
74
|
+
recolouring a control the moment it is pressed is how a user loses it. */
|
|
75
|
+
button[aria-disabled='true'] {
|
|
76
|
+
cursor: progress;
|
|
77
|
+
}
|
|
78
|
+
:host([disabled]) button {
|
|
79
|
+
cursor: not-allowed;
|
|
80
|
+
opacity: 0.55;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
button.primary {
|
|
84
|
+
background: ${t.brand};
|
|
85
|
+
color: ${t.onBrand};
|
|
86
|
+
}
|
|
87
|
+
button.primary:hover:not([aria-disabled='true']) {
|
|
88
|
+
background: ${t.brandHover};
|
|
89
|
+
}
|
|
90
|
+
button.primary:active:not([aria-disabled='true']) {
|
|
91
|
+
background: ${t.brandActive};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
button.secondary {
|
|
95
|
+
background: transparent;
|
|
96
|
+
color: ${t.link};
|
|
97
|
+
border-color: currentColor;
|
|
98
|
+
}
|
|
99
|
+
button.secondary:hover:not([aria-disabled='true']) {
|
|
100
|
+
background: ${t.brandSubtle};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
button.ghost {
|
|
104
|
+
background: transparent;
|
|
105
|
+
color: ${t.link};
|
|
106
|
+
border-color: transparent;
|
|
107
|
+
text-decoration: underline;
|
|
108
|
+
}
|
|
109
|
+
button.ghost:hover:not([aria-disabled='true']) {
|
|
110
|
+
background: ${t.brandSubtle};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.sr-only {
|
|
114
|
+
${visuallyHidden}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Windows High Contrast Mode drops background and border colours, so a
|
|
118
|
+
button styled only by background becomes invisible. A forced-colors
|
|
119
|
+
border puts the boundary back. */
|
|
120
|
+
@media (forced-colors: active) {
|
|
121
|
+
button {
|
|
122
|
+
border-color: ButtonBorder;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
`
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
onClick(event) {
|
|
129
|
+
if (this.disabled || this.busy) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
event.stopImmediatePropagation();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (this.type === "submit") this.internals?.form?.requestSubmit();
|
|
135
|
+
if (this.type === "reset") this.internals?.form?.reset();
|
|
136
|
+
}
|
|
137
|
+
render() {
|
|
138
|
+
return b`
|
|
139
|
+
<button
|
|
140
|
+
class=${this.variant}
|
|
141
|
+
type="button"
|
|
142
|
+
part="button"
|
|
143
|
+
?disabled=${this.disabled}
|
|
144
|
+
aria-disabled=${this.busy ? "true" : A}
|
|
145
|
+
aria-busy=${this.busy ? "true" : A}
|
|
146
|
+
@click=${this.onClick}
|
|
147
|
+
>
|
|
148
|
+
<slot></slot>
|
|
149
|
+
${this.busy ? b`<span class="sr-only">${this.busyLabel}</span>` : A}
|
|
150
|
+
</button>
|
|
151
|
+
`;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
customElements.define("impkt-button", ImpktButton);
|
|
155
|
+
|
|
156
|
+
export {
|
|
157
|
+
ImpktButton
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=chunk-OZNQ4GAR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/button.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpktElement } from '../base/ImpktElement';\nimport { focusRing, targetSize, visuallyHidden } from '../base/styles';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\n/**\n * A button.\n *\n * Two decisions carry the accessibility weight here.\n *\n * **A busy button is not a disabled button.** While an action is in flight the\n * control keeps its place in the tab order and reports `aria-disabled`, rather\n * than taking the native `disabled` attribute. A natively disabled element is\n * removed from the tab order, so a keyboard user who had just activated it\n * loses their focus position to the top of the document — at precisely the\n * moment something is happening that they need to be told about. Activation is\n * blocked in the handler instead.\n *\n * **It renders a real `<button>`.** A `<div role=\"button\">` needs Enter and\n * Space handling, a tabindex, and a disabled story, and it will still not\n * submit a form. The native element already has all of that, correctly, in\n * every browser and every assistive technology.\n\n *\n * @category action\n * @icon button\n * @slot - The button label.\n */\nexport class ImpktButton extends ImpktElement {\n static formAssociated = true;\n\n static properties = {\n variant: { type: String, reflect: true },\n type: { type: String },\n disabled: { type: Boolean, reflect: true },\n busy: { type: Boolean, reflect: true },\n busyLabel: { type: String, attribute: 'busy-label' },\n full: { type: Boolean, reflect: true },\n };\n\n declare variant: 'primary' | 'secondary' | 'ghost';\n declare type: 'button' | 'submit' | 'reset';\n declare disabled: boolean;\n declare busy: boolean;\n /** Announced when the button becomes busy. Says what is happening, not that something is. */\n declare busyLabel: string;\n declare full: boolean;\n\n private internals: ElementInternals | null = null;\n\n constructor() {\n super();\n this.variant = 'primary';\n this.type = 'button';\n this.disabled = false;\n this.busy = false;\n this.busyLabel = 'Working';\n this.full = false;\n try {\n this.internals = this.attachInternals();\n } catch {\n this.internals = null;\n }\n }\n\n static styles = [\n ...ImpktElement.styles,\n focusRing,\n css`\n :host {\n display: inline-block;\n }\n :host([full]) {\n display: block;\n }\n button {\n ${targetSize}\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: ${space(2)};\n inline-size: 100%;\n padding: ${space(3)} ${space(5)};\n font-family: inherit;\n font-size: ${fontSize('md')};\n font-weight: ${fontWeight('semibold')};\n line-height: 1.2;\n border-radius: ${t.radius};\n border: ${t.borderThick} solid transparent;\n cursor: pointer;\n transition: background-color 120ms ease-in-out, border-color 120ms ease-in-out;\n }\n /* The cursor is the only thing that changes while busy. Moving or\n recolouring a control the moment it is pressed is how a user loses it. */\n button[aria-disabled='true'] {\n cursor: progress;\n }\n :host([disabled]) button {\n cursor: not-allowed;\n opacity: 0.55;\n }\n\n button.primary {\n background: ${t.brand};\n color: ${t.onBrand};\n }\n button.primary:hover:not([aria-disabled='true']) {\n background: ${t.brandHover};\n }\n button.primary:active:not([aria-disabled='true']) {\n background: ${t.brandActive};\n }\n\n button.secondary {\n background: transparent;\n color: ${t.link};\n border-color: currentColor;\n }\n button.secondary:hover:not([aria-disabled='true']) {\n background: ${t.brandSubtle};\n }\n\n button.ghost {\n background: transparent;\n color: ${t.link};\n border-color: transparent;\n text-decoration: underline;\n }\n button.ghost:hover:not([aria-disabled='true']) {\n background: ${t.brandSubtle};\n }\n\n .sr-only {\n ${visuallyHidden}\n }\n\n /* Windows High Contrast Mode drops background and border colours, so a\n button styled only by background becomes invisible. A forced-colors\n border puts the boundary back. */\n @media (forced-colors: active) {\n button {\n border-color: ButtonBorder;\n }\n }\n `,\n ];\n\n private onClick(event: MouseEvent): void {\n if (this.disabled || this.busy) {\n event.preventDefault();\n event.stopImmediatePropagation();\n return;\n }\n // A shadow-rooted button does not submit the outer form by itself, because\n // the click never reaches it. `requestSubmit` rather than `submit` so that\n // native validation and the submit event both still run.\n if (this.type === 'submit') this.internals?.form?.requestSubmit();\n if (this.type === 'reset') this.internals?.form?.reset();\n }\n\n render(): TemplateResult {\n return html`\n <button\n class=${this.variant}\n type=\"button\"\n part=\"button\"\n ?disabled=${this.disabled}\n aria-disabled=${this.busy ? 'true' : nothing}\n aria-busy=${this.busy ? 'true' : nothing}\n @click=${this.onClick}\n >\n <slot></slot>\n ${this.busy ? html`<span class=\"sr-only\">${this.busyLabel}</span>` : nothing}\n </button>\n `;\n }\n}\n\ncustomElements.define('impkt-button', ImpktButton);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'impkt-button': ImpktButton;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BO,IAAM,cAAN,cAA0B,aAAa;AAAA,EAsB5C,cAAc;AACZ,UAAM;AAHR,SAAQ,YAAqC;AAI3C,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,OAAO;AACZ,SAAK,YAAY;AACjB,SAAK,OAAO;AACZ,QAAI;AACF,WAAK,YAAY,KAAK,gBAAgB;AAAA,IACxC,QAAQ;AACN,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA,EAlCA;AAAA,SAAO,iBAAiB;AAAA;AAAA,EAExB;AAAA,SAAO,aAAa;AAAA,MAClB,SAAS,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MACvC,MAAM,EAAE,MAAM,OAAO;AAAA,MACrB,UAAU,EAAE,MAAM,SAAS,SAAS,KAAK;AAAA,MACzC,MAAM,EAAE,MAAM,SAAS,SAAS,KAAK;AAAA,MACrC,WAAW,EAAE,MAAM,QAAQ,WAAW,aAAa;AAAA,MACnD,MAAM,EAAE,MAAM,SAAS,SAAS,KAAK;AAAA,IACvC;AAAA;AAAA,EA2BA;AAAA,SAAO,SAAS;AAAA,MACd,GAAG,aAAa;AAAA,MAChB;AAAA,MACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAQM,UAAU;AAAA;AAAA;AAAA;AAAA,eAIL,MAAM,CAAC,CAAC;AAAA;AAAA,m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EAGlF;AACF;AAEA,eAAe,OAAO,gBAAgB,WAAW;","names":[]}
|
|
@@ -0,0 +1,90 @@
|
|
|
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.ts
|
|
15
|
+
var ImpktCheckbox = class extends FieldElement {
|
|
16
|
+
static {
|
|
17
|
+
this.properties = {
|
|
18
|
+
...FieldElement.properties,
|
|
19
|
+
checked: { type: Boolean, reflect: true }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.checked = false;
|
|
25
|
+
}
|
|
26
|
+
static {
|
|
27
|
+
this.styles = [
|
|
28
|
+
...FieldElement.styles,
|
|
29
|
+
i`
|
|
30
|
+
.row {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: flex-start;
|
|
33
|
+
gap: ${space(3)};
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
}
|
|
36
|
+
input {
|
|
37
|
+
${targetSize}
|
|
38
|
+
inline-size: 20px;
|
|
39
|
+
block-size: 20px;
|
|
40
|
+
margin: 0;
|
|
41
|
+
flex: none;
|
|
42
|
+
accent-color: ${t.brand};
|
|
43
|
+
}
|
|
44
|
+
.text {
|
|
45
|
+
font-size: ${fontSize("md")};
|
|
46
|
+
}
|
|
47
|
+
:host([invalid]) .row {
|
|
48
|
+
color: ${t.dangerText};
|
|
49
|
+
}
|
|
50
|
+
`
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
renderControl() {
|
|
54
|
+
return b`
|
|
55
|
+
<label class="row" part="row" for=${this.controlId}>
|
|
56
|
+
<input
|
|
57
|
+
type="checkbox"
|
|
58
|
+
id=${this.controlId}
|
|
59
|
+
part="input"
|
|
60
|
+
name=${this.name || A}
|
|
61
|
+
.checked=${this.checked}
|
|
62
|
+
?disabled=${this.disabled}
|
|
63
|
+
?required=${this.required}
|
|
64
|
+
aria-describedby=${this.describedBy}
|
|
65
|
+
aria-invalid=${this.error ? "true" : A}
|
|
66
|
+
@change=${(e) => {
|
|
67
|
+
this.checked = e.target.checked;
|
|
68
|
+
this.setFormValue(this.checked ? "on" : "");
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
<span class="text">
|
|
72
|
+
${this.label}${this.required ? b`<span class="required"> (${this.requiredText})</span>` : A}
|
|
73
|
+
</span>
|
|
74
|
+
</label>
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
/** The label is inside the control here, so the base class's is suppressed. */
|
|
78
|
+
renderLabel() {
|
|
79
|
+
return b`${A}`;
|
|
80
|
+
}
|
|
81
|
+
updated(changed) {
|
|
82
|
+
if (changed.has("error")) this.toggleAttribute("invalid", Boolean(this.error));
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
customElements.define("impkt-checkbox", ImpktCheckbox);
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
ImpktCheckbox
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=chunk-PV4GMCP6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/checkbox.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\n/**\n * A single checkbox — a consent, an opt-in, a confirmation.\n *\n * The label sits beside the box rather than above it, so this overrides the\n * base layout. The whole `<label>` is the hit area: a 20px box is legal under\n * 2.5.8 and still unkind, and the row costs nothing.\n\n *\n * @category form\n * @icon checkbox\n */\nexport class ImpktCheckbox extends FieldElement {\n static properties = {\n ...FieldElement.properties,\n checked: { type: Boolean, reflect: true },\n };\n\n declare checked: boolean;\n\n constructor() {\n super();\n this.checked = false;\n }\n\n static styles = [\n ...FieldElement.styles,\n css`\n .row {\n display: flex;\n align-items: flex-start;\n gap: ${space(3)};\n cursor: pointer;\n }\n input {\n ${targetSize}\n inline-size: 20px;\n block-size: 20px;\n margin: 0;\n flex: none;\n accent-color: ${t.brand};\n }\n .text {\n font-size: ${fontSize('md')};\n }\n :host([invalid]) .row {\n color: ${t.dangerText};\n }\n `,\n ];\n\n protected renderControl(): TemplateResult {\n return html`\n <label class=\"row\" part=\"row\" for=${this.controlId}>\n <input\n type=\"checkbox\"\n id=${this.controlId}\n part=\"input\"\n name=${this.name || nothing}\n .checked=${this.checked}\n ?disabled=${this.disabled}\n ?required=${this.required}\n aria-describedby=${this.describedBy}\n aria-invalid=${this.error ? 'true' : nothing}\n @change=${(e: Event) => {\n this.checked = (e.target as HTMLInputElement).checked;\n this.setFormValue(this.checked ? 'on' : '');\n }}\n />\n <span class=\"text\">\n ${this.label}${this.required\n ? html`<span class=\"required\"> (${this.requiredText})</span>`\n : nothing}\n </span>\n </label>\n `;\n }\n\n /** The label is inside the control here, so the base class's is suppressed. */\n protected renderLabel(): TemplateResult {\n return html`${nothing}`;\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', ImpktCheckbox);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'impkt-checkbox': ImpktCheckbox;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EAC9C;AAAA,SAAO,aAAa;AAAA,MAClB,GAAG,aAAa;AAAA,MAChB,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK;AAAA,IAC1C;AAAA;AAAA,EAIA,cAAc;AACZ,UAAM;AACN,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA;AAAA,SAAO,S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