@telperion/elements 4.1.0 → 5.0.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/.build-manifest.json +12 -1
- package/README.md +42 -0
- package/button/button.element.cjs +216 -0
- package/button/button.element.cjs.map +1 -0
- package/button/button.element.js +216 -0
- package/button/button.element.js.map +1 -0
- package/button/index.cjs +11 -0
- package/button/index.cjs.map +1 -0
- package/button/index.d.cts +139 -0
- package/button/index.d.ts +139 -0
- package/button/index.js +2 -0
- package/button/index.js.map +1 -0
- package/fesm/elements.mjs +326 -2
- package/fesm/elements.mjs.map +1 -1
- package/iife/button/index.js +146 -0
- package/iife/button/index.js.map +1 -0
- package/iife/elements.js +133 -22
- package/iife/elements.js.map +1 -1
- package/iife/select/index.js +1 -1
- package/iife/select/index.js.map +1 -1
- package/index.cjs +5 -0
- package/index.cjs.map +1 -1
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +27 -3
- package/select/index.d.cts +13 -0
- package/select/index.d.ts +13 -0
- package/select/select.element.cjs.map +1 -1
- package/select/select.element.js.map +1 -1
- package/select/selected-content.element.cjs +1 -1
- package/select/selected-content.element.cjs.map +1 -1
- package/select/selected-content.element.js +1 -1
- package/select/selected-content.element.js.map +1 -1
- package/utils/shade-mixer-lit-element.cjs +123 -0
- package/utils/shade-mixer-lit-element.cjs.map +1 -0
- package/utils/shade-mixer-lit-element.js +121 -0
- package/utils/shade-mixer-lit-element.js.map +1 -0
package/.build-manifest.json
CHANGED
|
@@ -88,7 +88,18 @@
|
|
|
88
88
|
"dts": "select/index.d.ts",
|
|
89
89
|
"dcts": "select/index.d.cts"
|
|
90
90
|
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "button/index",
|
|
94
|
+
"sourcePath": "src/button/index.ts",
|
|
95
|
+
"outputs": {
|
|
96
|
+
"esm": "button/index.js",
|
|
97
|
+
"cjs": "button/index.cjs",
|
|
98
|
+
"iife": "iife/button/index.js",
|
|
99
|
+
"dts": "button/index.d.ts",
|
|
100
|
+
"dcts": "button/index.d.cts"
|
|
101
|
+
}
|
|
91
102
|
}
|
|
92
103
|
],
|
|
93
|
-
"generatedAt": "2026-05-
|
|
104
|
+
"generatedAt": "2026-05-06T16:50:35.164Z"
|
|
94
105
|
}
|
package/README.md
CHANGED
|
@@ -65,6 +65,9 @@ Use the **explicit `/iife/...` path** so the CDN serves the standalone bundle (s
|
|
|
65
65
|
|
|
66
66
|
<!-- Or just the select module (TelperionElements.Select) -->
|
|
67
67
|
<script src="https://unpkg.com/@telperion/elements/iife/select/index.js"></script>
|
|
68
|
+
|
|
69
|
+
<!-- Or just the button module (TelperionElements.Button) -->
|
|
70
|
+
<script src="https://unpkg.com/@telperion/elements/iife/button/index.js"></script>
|
|
68
71
|
```
|
|
69
72
|
|
|
70
73
|
Each per-module bundle is fully self-contained: side-effect imports register the custom elements as soon as the script is evaluated. jsDelivr (`https://cdn.jsdelivr.net/npm/@telperion/elements/iife/...`) and other npm CDNs work the same way.
|
|
@@ -250,6 +253,45 @@ import "@telperion/elements/select";
|
|
|
250
253
|
|
|
251
254
|
---
|
|
252
255
|
|
|
256
|
+
### Button
|
|
257
|
+
|
|
258
|
+
Framework-agnostic, form-associated button built with Lit. Behaves like the native `<button>` element — tab-selectable, activates on `Space` / `Enter`, and submits or resets its containing form via `type="submit"` / `type="reset"`.
|
|
259
|
+
|
|
260
|
+
**Includes:**
|
|
261
|
+
- `<tp-button>` — the button itself
|
|
262
|
+
|
|
263
|
+
**Features:**
|
|
264
|
+
- Three variants: `solid` · `outline` · `text`
|
|
265
|
+
- Form-associated via `ElementInternals` — `type="submit"` calls `form.requestSubmit()`, `type="reset"` calls `form.reset()`, and `.form` mirrors `HTMLButtonElement.form`
|
|
266
|
+
- Tab-selectable out of the box (`tabindex="0"`); `disabled` removes the button from the tab order, blocks click/keyboard activation, and sets `aria-disabled`
|
|
267
|
+
- `Space` / `Enter` activation matching native button semantics
|
|
268
|
+
- Announces `role="button"` to assistive technology through element internals
|
|
269
|
+
- Palette-driven color via the shared `ShadeMixerLitElement` mixin: pick a `color` token (`primary`, `secondary`, `success`, …) and tune intensity with `shade` (`0`–`1000`, `500` is the base color); `mixer` (`none` / `black` / `white`) is auto-derived from `shade`
|
|
270
|
+
- **Themable design system**: every palette token (`--tp-color-primary`, `--tp-color-success`, …) is overridable at `:root` or any ancestor; add brand-specific names with a single rule (`tp-button[color="brand"] { --tp-element-color: …; }`)
|
|
271
|
+
- Light-DOM rendering so consumer styling (Tailwind, CSS variables, design tokens) applies directly; pure-CSS hover, focus, and active transitions
|
|
272
|
+
|
|
273
|
+
#### JS/TS
|
|
274
|
+
```ts
|
|
275
|
+
import "@telperion/elements/button";
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
#### HTML
|
|
279
|
+
```html
|
|
280
|
+
<tp-button>Click me</tp-button>
|
|
281
|
+
<tp-button variant="outline" color="success">Save</tp-button>
|
|
282
|
+
<tp-button variant="text" color="danger" disabled>Delete</tp-button>
|
|
283
|
+
|
|
284
|
+
<form>
|
|
285
|
+
<input name="email" type="email" required />
|
|
286
|
+
<tp-button type="submit" color="primary">Subscribe</tp-button>
|
|
287
|
+
<tp-button type="reset" variant="outline">Reset</tp-button>
|
|
288
|
+
</form>
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
[Button Documentation →](./src/button/README.md)
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
253
295
|
This library is actively being developed. More components will be added over time.
|
|
254
296
|
|
|
255
297
|
## 🤝 Contributing
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var lit = require('lit');
|
|
5
|
+
var decorators_js = require('lit/decorators.js');
|
|
6
|
+
var shadeMixerLitElement = require('../utils/shade-mixer-lit-element.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `<tp-button>` — framework-agnostic, form-associated button.
|
|
10
|
+
*
|
|
11
|
+
* Behaves like the native `<button>` element:
|
|
12
|
+
*
|
|
13
|
+
* - Participates in the tab order (`tabindex="0"` on connect; `-1` while disabled).
|
|
14
|
+
* - Activates on `Space` / `Enter`.
|
|
15
|
+
* - With `type="submit"` calls `form.requestSubmit()`; with `type="reset"` calls `form.reset()`.
|
|
16
|
+
* - When `disabled`, blocks click and keyboard activation and updates `aria-disabled`.
|
|
17
|
+
* - Announces `role="button"` to assistive technology via `ElementInternals`.
|
|
18
|
+
*
|
|
19
|
+
* Color is supplied through {@link ShadeMixerLitElement}: pick a palette token via `color`,
|
|
20
|
+
* then lighten or darken it through `shade` (`0`–`1000`, `500` is the base color).
|
|
21
|
+
* The element renders into the **light DOM** so global CSS, Tailwind utilities, and consumer
|
|
22
|
+
* tokens apply directly.
|
|
23
|
+
*
|
|
24
|
+
* @element tp-button
|
|
25
|
+
*
|
|
26
|
+
* @attr {"solid" | "outline" | "text"} [variant="solid"] - Visual treatment.
|
|
27
|
+
* @attr {"button" | "submit" | "reset"} [type="button"] - Native button semantics.
|
|
28
|
+
* @attr {boolean} [disabled=false] - Disables interaction and removes the button from the tab order.
|
|
29
|
+
* @attr {string} [color="contrast"] - Palette token (`primary`, `secondary`, `success`, …) inherited from {@link ShadeMixerLitElement}.
|
|
30
|
+
* @attr {number} [shade=500] - Shade between `0` (lightest) and `1000` (darkest); `500` is the base color.
|
|
31
|
+
* @attr {"none" | "black" | "white"} [mixer="none"] - Auto-derived from `shade` (read-only output).
|
|
32
|
+
*
|
|
33
|
+
* @cssprop --tp-button-color - Resolved background/text color (defaults to the calculated palette color).
|
|
34
|
+
* @cssprop --tp-button-contrast-color - Resolved contrast color used for `solid` text.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```html
|
|
38
|
+
* <tp-button>Click me</tp-button>
|
|
39
|
+
* <tp-button variant="outline" color="success">Save</tp-button>
|
|
40
|
+
* <tp-button variant="text" color="danger" disabled>Delete</tp-button>
|
|
41
|
+
*
|
|
42
|
+
* <form>
|
|
43
|
+
* <input name="email" type="email" />
|
|
44
|
+
* <tp-button type="submit" color="primary">Subscribe</tp-button>
|
|
45
|
+
* </form>
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
exports.ButtonElement = class ButtonElement extends shadeMixerLitElement.ShadeMixerLitElement {
|
|
49
|
+
/** Marks the element as form-associated so `attachInternals().form` is populated. */
|
|
50
|
+
static { this.formAssociated = true; }
|
|
51
|
+
static { this.styles = (() => {
|
|
52
|
+
const style = lit.css `
|
|
53
|
+
tp-button {
|
|
54
|
+
${shadeMixerLitElement.ShadeMixerLitElement.shadedElementStyles}
|
|
55
|
+
--tp-button-color: var(--tp-calc-element-color);
|
|
56
|
+
--tp-button-contrast-color: var(--tp-calc-contrast-color);
|
|
57
|
+
display: inline-block;
|
|
58
|
+
border: 1px solid transparent;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
outline-offset: 1em;
|
|
61
|
+
outline: 1px solid transparent;
|
|
62
|
+
transform: scale(1);
|
|
63
|
+
transition: all 0.18s ease;
|
|
64
|
+
transition-property: background-color, color, outline-color, outline-offset, transform, border-width;
|
|
65
|
+
|
|
66
|
+
&:active {
|
|
67
|
+
transform: scale(0.98);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&:not(:active):focus {
|
|
71
|
+
outline-color: var(--tp-button-color);
|
|
72
|
+
outline-offset: 2px;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&[disabled] {
|
|
76
|
+
--tp-button-color: color-mix(in xyz, var(--tp-calc-element-color) 50%, var(--tp-color-white) 50%);
|
|
77
|
+
--tp-button-contrast-color: rgb(from var(--tp-calc-contrast-color) r g b / 50%);
|
|
78
|
+
pointer-events: none;
|
|
79
|
+
user-select: none;
|
|
80
|
+
cursor: not-allowed;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&[variant="solid"],
|
|
84
|
+
&[variant="outline"] {
|
|
85
|
+
padding: 0.5em 1em;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&[variant="solid"] {
|
|
89
|
+
background-color: var(--tp-button-color);
|
|
90
|
+
color: var(--tp-button-contrast-color);
|
|
91
|
+
|
|
92
|
+
&:hover {
|
|
93
|
+
background-color: color-mix(in xyz, var(--tp-button-color) 80%, var(--tp-color-black) 20%);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&[variant="outline"] {
|
|
98
|
+
color: var(--tp-button-color);
|
|
99
|
+
border-color: var(--tp-button-color);
|
|
100
|
+
background-color: transparent;
|
|
101
|
+
|
|
102
|
+
&:hover {
|
|
103
|
+
background-color: color-mix(in xyz, var(--tp-button-color) 10%, transparent 90%);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
&:focus-visible {
|
|
107
|
+
outline-color: transparent;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&[variant="text"] {
|
|
112
|
+
color: var(--tp-button-color);
|
|
113
|
+
background-color: transparent;
|
|
114
|
+
|
|
115
|
+
&:hover {
|
|
116
|
+
color: color-mix(in xyz, var(--tp-button-color) 80%, var(--tp-color-black) 20%);
|
|
117
|
+
text-decoration: underline;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
122
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, style.styleSheet];
|
|
123
|
+
return style;
|
|
124
|
+
})(); }
|
|
125
|
+
#internals;
|
|
126
|
+
constructor() {
|
|
127
|
+
super();
|
|
128
|
+
this.variant = "solid";
|
|
129
|
+
/**
|
|
130
|
+
* Native button semantics. Determines what happens to the associated form when
|
|
131
|
+
* the button is activated. `submit` calls `form.requestSubmit()`, `reset` calls
|
|
132
|
+
* `form.reset()`, and `button` (the default) does nothing implicit.
|
|
133
|
+
*/
|
|
134
|
+
this.type = "button";
|
|
135
|
+
/**
|
|
136
|
+
* When `true`, the button is removed from the tab order, click and keyboard
|
|
137
|
+
* activation are blocked, and `aria-disabled` is set on the element internals.
|
|
138
|
+
*/
|
|
139
|
+
this.disabled = false;
|
|
140
|
+
this.#handleClick = (event) => {
|
|
141
|
+
if (this.disabled) {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
event.stopImmediatePropagation();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const form = this.#internals.form;
|
|
147
|
+
if (!form)
|
|
148
|
+
return;
|
|
149
|
+
if (this.type === "submit") {
|
|
150
|
+
form.requestSubmit();
|
|
151
|
+
}
|
|
152
|
+
else if (this.type === "reset") {
|
|
153
|
+
form.reset();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
this.#handleKeydown = (event) => {
|
|
157
|
+
if (this.disabled)
|
|
158
|
+
return;
|
|
159
|
+
if (event.key === " " || event.key === "Enter") {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
this.click();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
this.#internals = this.attachInternals();
|
|
165
|
+
this.#internals.role = "button";
|
|
166
|
+
}
|
|
167
|
+
/** The form this button is associated with, if any. Mirrors `HTMLButtonElement.form`. */
|
|
168
|
+
get form() {
|
|
169
|
+
return this.#internals.form;
|
|
170
|
+
}
|
|
171
|
+
connectedCallback() {
|
|
172
|
+
super.connectedCallback();
|
|
173
|
+
if (!this.hasAttribute("tabindex")) {
|
|
174
|
+
this.setAttribute("tabindex", this.disabled ? "-1" : "0");
|
|
175
|
+
}
|
|
176
|
+
this.addEventListener("click", this.#handleClick);
|
|
177
|
+
this.addEventListener("keydown", this.#handleKeydown);
|
|
178
|
+
}
|
|
179
|
+
disconnectedCallback() {
|
|
180
|
+
super.disconnectedCallback();
|
|
181
|
+
this.removeEventListener("click", this.#handleClick);
|
|
182
|
+
this.removeEventListener("keydown", this.#handleKeydown);
|
|
183
|
+
}
|
|
184
|
+
updated(changed) {
|
|
185
|
+
super.updated?.(changed);
|
|
186
|
+
if (changed.has("disabled")) {
|
|
187
|
+
this.setAttribute("tabindex", this.disabled ? "-1" : "0");
|
|
188
|
+
this.#internals.ariaDisabled = this.disabled ? "true" : "false";
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
#handleClick;
|
|
192
|
+
#handleKeydown;
|
|
193
|
+
createRenderRoot() {
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
render() {
|
|
197
|
+
return lit.html ``;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
tslib.__decorate([
|
|
201
|
+
decorators_js.property({ type: String, reflect: true }),
|
|
202
|
+
tslib.__metadata("design:type", String)
|
|
203
|
+
], exports.ButtonElement.prototype, "variant", void 0);
|
|
204
|
+
tslib.__decorate([
|
|
205
|
+
decorators_js.property({ type: String, reflect: true }),
|
|
206
|
+
tslib.__metadata("design:type", String)
|
|
207
|
+
], exports.ButtonElement.prototype, "type", void 0);
|
|
208
|
+
tslib.__decorate([
|
|
209
|
+
decorators_js.property({ type: Boolean, reflect: true }),
|
|
210
|
+
tslib.__metadata("design:type", Object)
|
|
211
|
+
], exports.ButtonElement.prototype, "disabled", void 0);
|
|
212
|
+
exports.ButtonElement = tslib.__decorate([
|
|
213
|
+
decorators_js.customElement("tp-button"),
|
|
214
|
+
tslib.__metadata("design:paramtypes", [])
|
|
215
|
+
], exports.ButtonElement);
|
|
216
|
+
//# sourceMappingURL=button.element.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.element.cjs","sources":["../../../../libs/elements/src/button/button.element.ts"],"sourcesContent":[null],"names":["ButtonElement","ShadeMixerLitElement","css","html","__decorate","property","customElement"],"mappings":";;;;;;;AA4BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;AAEUA,qBAAa,GAAnB,MAAM,aAAc,SAAQC,yCAAoB,CAAA;;aAE9C,IAAA,CAAA,cAAc,GAAG,IAAH,CAAQ;aACb,IAAA,CAAA,M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IAQK,gBAAgB,GAAA;AACjC,QAAA,OAAO,IAAI;IACb;IAEmB,MAAM,GAAA;QACvB,OAAOE,QAAI,CAAA,CAAA,CAAE;IACf;;AAlFAC,gBAAA,CAAA;IADCC,sBAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AACT,CAAA,EAAAL,qBAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAQjCI,gBAAA,CAAA;IADCC,sBAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AACd,CAAA,EAAAL,qBAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAO5BI,gBAAA,CAAA;IADCC,sBAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AAC1B,CAAA,EAAAL,qBAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAhGNA,qBAAa,GAAAI,gBAAA,CAAA;IADzBE,2BAAa,CAAC,WAAW,CAAC;;AACd,CAAA,EAAAN,qBAAa,CAoKzB;;"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { css, html } from 'lit';
|
|
3
|
+
import { property, customElement } from 'lit/decorators.js';
|
|
4
|
+
import { ShadeMixerLitElement } from '../utils/shade-mixer-lit-element.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `<tp-button>` — framework-agnostic, form-associated button.
|
|
8
|
+
*
|
|
9
|
+
* Behaves like the native `<button>` element:
|
|
10
|
+
*
|
|
11
|
+
* - Participates in the tab order (`tabindex="0"` on connect; `-1` while disabled).
|
|
12
|
+
* - Activates on `Space` / `Enter`.
|
|
13
|
+
* - With `type="submit"` calls `form.requestSubmit()`; with `type="reset"` calls `form.reset()`.
|
|
14
|
+
* - When `disabled`, blocks click and keyboard activation and updates `aria-disabled`.
|
|
15
|
+
* - Announces `role="button"` to assistive technology via `ElementInternals`.
|
|
16
|
+
*
|
|
17
|
+
* Color is supplied through {@link ShadeMixerLitElement}: pick a palette token via `color`,
|
|
18
|
+
* then lighten or darken it through `shade` (`0`–`1000`, `500` is the base color).
|
|
19
|
+
* The element renders into the **light DOM** so global CSS, Tailwind utilities, and consumer
|
|
20
|
+
* tokens apply directly.
|
|
21
|
+
*
|
|
22
|
+
* @element tp-button
|
|
23
|
+
*
|
|
24
|
+
* @attr {"solid" | "outline" | "text"} [variant="solid"] - Visual treatment.
|
|
25
|
+
* @attr {"button" | "submit" | "reset"} [type="button"] - Native button semantics.
|
|
26
|
+
* @attr {boolean} [disabled=false] - Disables interaction and removes the button from the tab order.
|
|
27
|
+
* @attr {string} [color="contrast"] - Palette token (`primary`, `secondary`, `success`, …) inherited from {@link ShadeMixerLitElement}.
|
|
28
|
+
* @attr {number} [shade=500] - Shade between `0` (lightest) and `1000` (darkest); `500` is the base color.
|
|
29
|
+
* @attr {"none" | "black" | "white"} [mixer="none"] - Auto-derived from `shade` (read-only output).
|
|
30
|
+
*
|
|
31
|
+
* @cssprop --tp-button-color - Resolved background/text color (defaults to the calculated palette color).
|
|
32
|
+
* @cssprop --tp-button-contrast-color - Resolved contrast color used for `solid` text.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```html
|
|
36
|
+
* <tp-button>Click me</tp-button>
|
|
37
|
+
* <tp-button variant="outline" color="success">Save</tp-button>
|
|
38
|
+
* <tp-button variant="text" color="danger" disabled>Delete</tp-button>
|
|
39
|
+
*
|
|
40
|
+
* <form>
|
|
41
|
+
* <input name="email" type="email" />
|
|
42
|
+
* <tp-button type="submit" color="primary">Subscribe</tp-button>
|
|
43
|
+
* </form>
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
let ButtonElement = class ButtonElement extends ShadeMixerLitElement {
|
|
47
|
+
/** Marks the element as form-associated so `attachInternals().form` is populated. */
|
|
48
|
+
static { this.formAssociated = true; }
|
|
49
|
+
static { this.styles = (() => {
|
|
50
|
+
const style = css `
|
|
51
|
+
tp-button {
|
|
52
|
+
${ShadeMixerLitElement.shadedElementStyles}
|
|
53
|
+
--tp-button-color: var(--tp-calc-element-color);
|
|
54
|
+
--tp-button-contrast-color: var(--tp-calc-contrast-color);
|
|
55
|
+
display: inline-block;
|
|
56
|
+
border: 1px solid transparent;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
outline-offset: 1em;
|
|
59
|
+
outline: 1px solid transparent;
|
|
60
|
+
transform: scale(1);
|
|
61
|
+
transition: all 0.18s ease;
|
|
62
|
+
transition-property: background-color, color, outline-color, outline-offset, transform, border-width;
|
|
63
|
+
|
|
64
|
+
&:active {
|
|
65
|
+
transform: scale(0.98);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&:not(:active):focus {
|
|
69
|
+
outline-color: var(--tp-button-color);
|
|
70
|
+
outline-offset: 2px;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
&[disabled] {
|
|
74
|
+
--tp-button-color: color-mix(in xyz, var(--tp-calc-element-color) 50%, var(--tp-color-white) 50%);
|
|
75
|
+
--tp-button-contrast-color: rgb(from var(--tp-calc-contrast-color) r g b / 50%);
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
user-select: none;
|
|
78
|
+
cursor: not-allowed;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&[variant="solid"],
|
|
82
|
+
&[variant="outline"] {
|
|
83
|
+
padding: 0.5em 1em;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&[variant="solid"] {
|
|
87
|
+
background-color: var(--tp-button-color);
|
|
88
|
+
color: var(--tp-button-contrast-color);
|
|
89
|
+
|
|
90
|
+
&:hover {
|
|
91
|
+
background-color: color-mix(in xyz, var(--tp-button-color) 80%, var(--tp-color-black) 20%);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&[variant="outline"] {
|
|
96
|
+
color: var(--tp-button-color);
|
|
97
|
+
border-color: var(--tp-button-color);
|
|
98
|
+
background-color: transparent;
|
|
99
|
+
|
|
100
|
+
&:hover {
|
|
101
|
+
background-color: color-mix(in xyz, var(--tp-button-color) 10%, transparent 90%);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&:focus-visible {
|
|
105
|
+
outline-color: transparent;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&[variant="text"] {
|
|
110
|
+
color: var(--tp-button-color);
|
|
111
|
+
background-color: transparent;
|
|
112
|
+
|
|
113
|
+
&:hover {
|
|
114
|
+
color: color-mix(in xyz, var(--tp-button-color) 80%, var(--tp-color-black) 20%);
|
|
115
|
+
text-decoration: underline;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, style.styleSheet];
|
|
121
|
+
return style;
|
|
122
|
+
})(); }
|
|
123
|
+
#internals;
|
|
124
|
+
constructor() {
|
|
125
|
+
super();
|
|
126
|
+
this.variant = "solid";
|
|
127
|
+
/**
|
|
128
|
+
* Native button semantics. Determines what happens to the associated form when
|
|
129
|
+
* the button is activated. `submit` calls `form.requestSubmit()`, `reset` calls
|
|
130
|
+
* `form.reset()`, and `button` (the default) does nothing implicit.
|
|
131
|
+
*/
|
|
132
|
+
this.type = "button";
|
|
133
|
+
/**
|
|
134
|
+
* When `true`, the button is removed from the tab order, click and keyboard
|
|
135
|
+
* activation are blocked, and `aria-disabled` is set on the element internals.
|
|
136
|
+
*/
|
|
137
|
+
this.disabled = false;
|
|
138
|
+
this.#handleClick = (event) => {
|
|
139
|
+
if (this.disabled) {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
event.stopImmediatePropagation();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const form = this.#internals.form;
|
|
145
|
+
if (!form)
|
|
146
|
+
return;
|
|
147
|
+
if (this.type === "submit") {
|
|
148
|
+
form.requestSubmit();
|
|
149
|
+
}
|
|
150
|
+
else if (this.type === "reset") {
|
|
151
|
+
form.reset();
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
this.#handleKeydown = (event) => {
|
|
155
|
+
if (this.disabled)
|
|
156
|
+
return;
|
|
157
|
+
if (event.key === " " || event.key === "Enter") {
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
this.click();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
this.#internals = this.attachInternals();
|
|
163
|
+
this.#internals.role = "button";
|
|
164
|
+
}
|
|
165
|
+
/** The form this button is associated with, if any. Mirrors `HTMLButtonElement.form`. */
|
|
166
|
+
get form() {
|
|
167
|
+
return this.#internals.form;
|
|
168
|
+
}
|
|
169
|
+
connectedCallback() {
|
|
170
|
+
super.connectedCallback();
|
|
171
|
+
if (!this.hasAttribute("tabindex")) {
|
|
172
|
+
this.setAttribute("tabindex", this.disabled ? "-1" : "0");
|
|
173
|
+
}
|
|
174
|
+
this.addEventListener("click", this.#handleClick);
|
|
175
|
+
this.addEventListener("keydown", this.#handleKeydown);
|
|
176
|
+
}
|
|
177
|
+
disconnectedCallback() {
|
|
178
|
+
super.disconnectedCallback();
|
|
179
|
+
this.removeEventListener("click", this.#handleClick);
|
|
180
|
+
this.removeEventListener("keydown", this.#handleKeydown);
|
|
181
|
+
}
|
|
182
|
+
updated(changed) {
|
|
183
|
+
super.updated?.(changed);
|
|
184
|
+
if (changed.has("disabled")) {
|
|
185
|
+
this.setAttribute("tabindex", this.disabled ? "-1" : "0");
|
|
186
|
+
this.#internals.ariaDisabled = this.disabled ? "true" : "false";
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
#handleClick;
|
|
190
|
+
#handleKeydown;
|
|
191
|
+
createRenderRoot() {
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
render() {
|
|
195
|
+
return html ``;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
__decorate([
|
|
199
|
+
property({ type: String, reflect: true }),
|
|
200
|
+
__metadata("design:type", String)
|
|
201
|
+
], ButtonElement.prototype, "variant", void 0);
|
|
202
|
+
__decorate([
|
|
203
|
+
property({ type: String, reflect: true }),
|
|
204
|
+
__metadata("design:type", String)
|
|
205
|
+
], ButtonElement.prototype, "type", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
property({ type: Boolean, reflect: true }),
|
|
208
|
+
__metadata("design:type", Object)
|
|
209
|
+
], ButtonElement.prototype, "disabled", void 0);
|
|
210
|
+
ButtonElement = __decorate([
|
|
211
|
+
customElement("tp-button"),
|
|
212
|
+
__metadata("design:paramtypes", [])
|
|
213
|
+
], ButtonElement);
|
|
214
|
+
|
|
215
|
+
export { ButtonElement };
|
|
216
|
+
//# sourceMappingURL=button.element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.element.js","sources":["../../../../libs/elements/src/button/button.element.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AA4BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,oBAAoB,CAAA;;aAE9C,IAAA,CAAA,cAAc,GAAG,IAAH,CAAQ;aACb,IAAA,CAAA,MAAM,GAAG,CAAC,MAAK;QAC7B,MAAM,KAAK,GAAG,GAAG,CAAA,CAAA;;AAEX,QAAA,EAAA,oBAAoB,CAAC,mBAAmB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmE7C;AAED,QAAA,QAAQ,CAAC,kBAAkB,GAAG,CAAC,GAAG,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAC,UAAW,CAAC;AAEjF,QAAA,OAAO,KAAK;IACd,CAAC,GA3EqB,CA2EjB;AAoBI,IAAA,UAAU;AAEnB,IAAA,WAAA,GAAA;AACE,QAAA,KA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A,EAAA,MAAA,CAAA;AAO5B,UAAA,CAAA;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AAC1B,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;AAhGN,aAAa,GAAA,UAAA,CAAA;IADzB,aAAa,CAAC,WAAW,CAAC;;AACd,CAAA,EAAA,aAAa,CAoKzB;;;;"}
|
package/button/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
|
|
3
|
+
type PredefinedColors = "contrast" | "primary" | "secondary" | "tertiary" | "quaternary" | "success" | "danger" | "warning" | "neutral";
|
|
4
|
+
type ShadeMixerType = "none" | "black" | "white";
|
|
5
|
+
/**
|
|
6
|
+
* Base class that powers Telperion's shared color/design system.
|
|
7
|
+
*
|
|
8
|
+
* Elements that extend `ShadeMixerLitElement` participate in a fully themable
|
|
9
|
+
* palette driven entirely by CSS custom properties. The class:
|
|
10
|
+
*
|
|
11
|
+
* 1. Auto-injects a default palette onto `:root` — `--tp-color-white`,
|
|
12
|
+
* `--tp-color-black`, `--tp-color-contrast`, `--tp-color-primary`,
|
|
13
|
+
* `--tp-color-secondary`, `--tp-color-tertiary`, `--tp-color-quaternary`,
|
|
14
|
+
* `--tp-color-success`, `--tp-color-danger`, `--tp-color-warning`, and
|
|
15
|
+
* `--tp-color-neutral`. Override any of them at `:root` or any ancestor to
|
|
16
|
+
* re-theme every shade-mixer-aware element underneath.
|
|
17
|
+
* 2. Exposes `shadedElementStyles` — a `css` block that resolves the
|
|
18
|
+
* selected `color` to `--tp-element-color`, applies the `shade`/`mixer`
|
|
19
|
+
* math, and exposes the result as `--tp-calc-element-color` and
|
|
20
|
+
* `--tp-calc-contrast-color` for consumers (variants, hover, focus, …).
|
|
21
|
+
* Subclasses include it once in their own host rule.
|
|
22
|
+
* 3. Provides three reflected attributes that drive the math:
|
|
23
|
+
* - `color` — palette token name (predefined or custom).
|
|
24
|
+
* - `shade` (`0`–`1000`, default `500`) — lighten/darken the
|
|
25
|
+
* resolved color (`<500` mixes white, `>500` mixes black).
|
|
26
|
+
* - `mixer` (`none` / `black` / `white`) — read-only output, auto-set
|
|
27
|
+
* whenever `shade` changes.
|
|
28
|
+
*
|
|
29
|
+
* **Adding custom color tokens.** If the predefined names are not enough,
|
|
30
|
+
* declare a new selector that supplies `--tp-element-color`:
|
|
31
|
+
*
|
|
32
|
+
* ```css
|
|
33
|
+
* tp-button[color="brand"] {
|
|
34
|
+
* --tp-element-color: hsl(265 75% 45%);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* The shade math, hover/focus styles, and contrast color all derive from this
|
|
39
|
+
* one variable, so the new token "just works" with `shade`, `variant`, etc.
|
|
40
|
+
*/
|
|
41
|
+
declare class ShadeMixerLitElement extends LitElement {
|
|
42
|
+
static rootStyles: any;
|
|
43
|
+
static shadedElementStyles: any;
|
|
44
|
+
color: PredefinedColors | string;
|
|
45
|
+
shade: number;
|
|
46
|
+
mixer: ShadeMixerType;
|
|
47
|
+
protected willUpdate(changed: Map<string, unknown>): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Visual treatment applied by `<tp-button>`.
|
|
52
|
+
*
|
|
53
|
+
* - `solid`: filled background using the resolved color.
|
|
54
|
+
* - `outline`: transparent background with a colored border and text.
|
|
55
|
+
* - `text`: no background or border — just colored text with an underline on hover.
|
|
56
|
+
*/
|
|
57
|
+
type ButtonVariant = "solid" | "outline" | "text";
|
|
58
|
+
/**
|
|
59
|
+
* Mirrors the native HTML `<button>` `type` attribute.
|
|
60
|
+
*
|
|
61
|
+
* - `button`: no implicit form behaviour (default).
|
|
62
|
+
* - `submit`: clicks/Enter call `form.requestSubmit()` on the associated form.
|
|
63
|
+
* - `reset`: clicks/Enter call `form.reset()` on the associated form.
|
|
64
|
+
*/
|
|
65
|
+
type ButtonType = "button" | "submit" | "reset";
|
|
66
|
+
declare global {
|
|
67
|
+
interface HTMLElementTagNameMap {
|
|
68
|
+
"tp-button": ButtonElement;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `<tp-button>` — framework-agnostic, form-associated button.
|
|
73
|
+
*
|
|
74
|
+
* Behaves like the native `<button>` element:
|
|
75
|
+
*
|
|
76
|
+
* - Participates in the tab order (`tabindex="0"` on connect; `-1` while disabled).
|
|
77
|
+
* - Activates on `Space` / `Enter`.
|
|
78
|
+
* - With `type="submit"` calls `form.requestSubmit()`; with `type="reset"` calls `form.reset()`.
|
|
79
|
+
* - When `disabled`, blocks click and keyboard activation and updates `aria-disabled`.
|
|
80
|
+
* - Announces `role="button"` to assistive technology via `ElementInternals`.
|
|
81
|
+
*
|
|
82
|
+
* Color is supplied through {@link ShadeMixerLitElement}: pick a palette token via `color`,
|
|
83
|
+
* then lighten or darken it through `shade` (`0`–`1000`, `500` is the base color).
|
|
84
|
+
* The element renders into the **light DOM** so global CSS, Tailwind utilities, and consumer
|
|
85
|
+
* tokens apply directly.
|
|
86
|
+
*
|
|
87
|
+
* @element tp-button
|
|
88
|
+
*
|
|
89
|
+
* @attr {"solid" | "outline" | "text"} [variant="solid"] - Visual treatment.
|
|
90
|
+
* @attr {"button" | "submit" | "reset"} [type="button"] - Native button semantics.
|
|
91
|
+
* @attr {boolean} [disabled=false] - Disables interaction and removes the button from the tab order.
|
|
92
|
+
* @attr {string} [color="contrast"] - Palette token (`primary`, `secondary`, `success`, …) inherited from {@link ShadeMixerLitElement}.
|
|
93
|
+
* @attr {number} [shade=500] - Shade between `0` (lightest) and `1000` (darkest); `500` is the base color.
|
|
94
|
+
* @attr {"none" | "black" | "white"} [mixer="none"] - Auto-derived from `shade` (read-only output).
|
|
95
|
+
*
|
|
96
|
+
* @cssprop --tp-button-color - Resolved background/text color (defaults to the calculated palette color).
|
|
97
|
+
* @cssprop --tp-button-contrast-color - Resolved contrast color used for `solid` text.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```html
|
|
101
|
+
* <tp-button>Click me</tp-button>
|
|
102
|
+
* <tp-button variant="outline" color="success">Save</tp-button>
|
|
103
|
+
* <tp-button variant="text" color="danger" disabled>Delete</tp-button>
|
|
104
|
+
*
|
|
105
|
+
* <form>
|
|
106
|
+
* <input name="email" type="email" />
|
|
107
|
+
* <tp-button type="submit" color="primary">Subscribe</tp-button>
|
|
108
|
+
* </form>
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare class ButtonElement extends ShadeMixerLitElement {
|
|
112
|
+
#private;
|
|
113
|
+
/** Marks the element as form-associated so `attachInternals().form` is populated. */
|
|
114
|
+
static formAssociated: boolean;
|
|
115
|
+
static styles: any;
|
|
116
|
+
variant: ButtonVariant;
|
|
117
|
+
/**
|
|
118
|
+
* Native button semantics. Determines what happens to the associated form when
|
|
119
|
+
* the button is activated. `submit` calls `form.requestSubmit()`, `reset` calls
|
|
120
|
+
* `form.reset()`, and `button` (the default) does nothing implicit.
|
|
121
|
+
*/
|
|
122
|
+
type: ButtonType;
|
|
123
|
+
/**
|
|
124
|
+
* When `true`, the button is removed from the tab order, click and keyboard
|
|
125
|
+
* activation are blocked, and `aria-disabled` is set on the element internals.
|
|
126
|
+
*/
|
|
127
|
+
disabled: boolean;
|
|
128
|
+
constructor();
|
|
129
|
+
/** The form this button is associated with, if any. Mirrors `HTMLButtonElement.form`. */
|
|
130
|
+
get form(): HTMLFormElement | null;
|
|
131
|
+
connectedCallback(): void;
|
|
132
|
+
disconnectedCallback(): void;
|
|
133
|
+
protected updated(changed: Map<string, unknown>): void;
|
|
134
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
135
|
+
protected render(): any;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { ButtonElement };
|
|
139
|
+
export type { ButtonType, ButtonVariant };
|