@joralvmel/cosmos-elements 0.2.0 → 0.4.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 +15 -0
- package/dist/components/badge/cosm-badge.d.ts +64 -0
- package/dist/components/badge/cosm-badge.d.ts.map +1 -0
- package/dist/components/badge/cosm-badge.js +162 -0
- package/dist/components/badge/cosm-badge.js.map +1 -0
- package/dist/components/button/cosm-button.d.ts.map +1 -1
- package/dist/components/button/cosm-button.js +2 -0
- package/dist/components/button/cosm-button.js.map +1 -1
- package/dist/components/calendar/cosm-calendar.d.ts +77 -0
- package/dist/components/calendar/cosm-calendar.d.ts.map +1 -0
- package/dist/components/calendar/cosm-calendar.js +696 -0
- package/dist/components/calendar/cosm-calendar.js.map +1 -0
- package/dist/components/checkbox/cosm-checkbox.d.ts +122 -0
- package/dist/components/checkbox/cosm-checkbox.d.ts.map +1 -0
- package/dist/components/checkbox/cosm-checkbox.js +433 -0
- package/dist/components/checkbox/cosm-checkbox.js.map +1 -0
- package/dist/components/dialog/cosm-dialog.d.ts +103 -0
- package/dist/components/dialog/cosm-dialog.d.ts.map +1 -0
- package/dist/components/dialog/cosm-dialog.js +497 -0
- package/dist/components/dialog/cosm-dialog.js.map +1 -0
- package/dist/components/icon/cosm-icon.d.ts +7 -15
- package/dist/components/icon/cosm-icon.d.ts.map +1 -1
- package/dist/components/icon/cosm-icon.js +29 -30
- package/dist/components/icon/cosm-icon.js.map +1 -1
- package/dist/components/icon-button/cosm-icon-button.d.ts +79 -0
- package/dist/components/icon-button/cosm-icon-button.d.ts.map +1 -0
- package/dist/components/icon-button/cosm-icon-button.js +212 -0
- package/dist/components/icon-button/cosm-icon-button.js.map +1 -0
- package/dist/components/listbox/cosm-listbox.d.ts +136 -0
- package/dist/components/listbox/cosm-listbox.d.ts.map +1 -0
- package/dist/components/listbox/cosm-listbox.js +565 -0
- package/dist/components/listbox/cosm-listbox.js.map +1 -0
- package/dist/components/pagination/cosm-pagination.d.ts +118 -0
- package/dist/components/pagination/cosm-pagination.d.ts.map +1 -0
- package/dist/components/pagination/cosm-pagination.js +315 -0
- package/dist/components/pagination/cosm-pagination.js.map +1 -0
- package/dist/components/popover/cosm-popover.d.ts +100 -0
- package/dist/components/popover/cosm-popover.d.ts.map +1 -0
- package/dist/components/popover/cosm-popover.js +776 -0
- package/dist/components/popover/cosm-popover.js.map +1 -0
- package/dist/components/radio-group/cosm-radio-group.d.ts +111 -0
- package/dist/components/radio-group/cosm-radio-group.d.ts.map +1 -0
- package/dist/components/radio-group/cosm-radio-group.js +478 -0
- package/dist/components/radio-group/cosm-radio-group.js.map +1 -0
- package/dist/components/select/cosm-select.d.ts +126 -0
- package/dist/components/select/cosm-select.d.ts.map +1 -0
- package/dist/components/select/cosm-select.js +682 -0
- package/dist/components/select/cosm-select.js.map +1 -0
- package/dist/components/switch/cosm-switch.d.ts +103 -0
- package/dist/components/switch/cosm-switch.d.ts.map +1 -0
- package/dist/components/switch/cosm-switch.js +359 -0
- package/dist/components/switch/cosm-switch.js.map +1 -0
- package/dist/components/text-field/cosm-text-field.d.ts +193 -0
- package/dist/components/text-field/cosm-text-field.d.ts.map +1 -0
- package/dist/components/text-field/cosm-text-field.js +642 -0
- package/dist/components/text-field/cosm-text-field.js.map +1 -0
- package/dist/components/textarea/cosm-textarea.d.ts +131 -0
- package/dist/components/textarea/cosm-textarea.d.ts.map +1 -0
- package/dist/components/textarea/cosm-textarea.js +445 -0
- package/dist/components/textarea/cosm-textarea.js.map +1 -0
- package/dist/custom-elements.json +7605 -78
- package/dist/index.d.ts +14 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/current-page.d.ts +7 -0
- package/dist/internal/current-page.d.ts.map +1 -0
- package/dist/internal/current-page.js +18 -0
- package/dist/internal/current-page.js.map +1 -0
- package/llms.md +455 -7
- package/package.json +55 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cosm-icon.d.ts","sourceRoot":"","sources":["../../../src/components/icon/cosm-icon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,KAAK,cAAc,EAAoB,MAAM,yBAAyB,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAI7D,KAAK,KAAK,GAAG,aAAa,CAAC,OAAO,YAAY,EAAE,KAAK,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAC3F,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"cosm-icon.d.ts","sourceRoot":"","sources":["../../../src/components/icon/cosm-icon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,KAAK,cAAc,EAAoB,MAAM,yBAAyB,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAI7D,KAAK,KAAK,GAAG,aAAa,CAAC,OAAO,YAAY,EAAE,KAAK,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAC3F,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC;AA+BnE;;;;;;GAMG;AACH,qBAAa,QAAS,SAAQ,WAAW;;IACvC,OAAgB,UAAU;;;;;;;uCAKG,MAAM,GAAG,IAAI;qCAIf,YAAY;;;;;;;;;;;;;MAMrC;IAEF,OAAgB,MAAM,4BAAuB;IAErC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,eAAe,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;;cAUf,OAAO;cAcP,UAAU;cAoCV,MAAM;CAwB1B;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,QAAQ,CAAC;KACvB;CACF"}
|
|
@@ -5,6 +5,8 @@ import { CosmElement } from '../../internal/cosm-element.js';
|
|
|
5
5
|
import { define } from '../../internal/define.js';
|
|
6
6
|
import { boxSizing } from '../../internal/styles.js';
|
|
7
7
|
const svgNamespace = 'http://www.w3.org/2000/svg';
|
|
8
|
+
/** Standard Lucide stroke width in viewBox units; scales with the icon. */
|
|
9
|
+
const strokeWidth = 2;
|
|
8
10
|
const styles = css `
|
|
9
11
|
:host {
|
|
10
12
|
display: inline-block;
|
|
@@ -30,7 +32,7 @@ const styles = css `
|
|
|
30
32
|
}
|
|
31
33
|
`;
|
|
32
34
|
/**
|
|
33
|
-
* Renders a structured SVG icon as a decorative graphic or a named
|
|
35
|
+
* Renders a structured SVG icon as a decorative graphic or, with a nonempty `label`, a named image.
|
|
34
36
|
*
|
|
35
37
|
* @tag cosm-icon
|
|
36
38
|
* @csspart icon - The rendered SVG image.
|
|
@@ -48,21 +50,17 @@ export class CosmIcon extends CosmElement {
|
|
|
48
50
|
toAttribute: (value) => String(value),
|
|
49
51
|
},
|
|
50
52
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
strokeWidth: { type: Number, attribute: 'stroke-width' },
|
|
53
|
+
variant: { type: String, reflect: true },
|
|
54
|
+
color: { type: String },
|
|
54
55
|
label: { type: String },
|
|
55
|
-
decorative: { type: Boolean, reflect: true },
|
|
56
56
|
};
|
|
57
57
|
static styles = [boxSizing, styles];
|
|
58
58
|
constructor() {
|
|
59
59
|
super();
|
|
60
60
|
this.size = iconContract.props.size.default;
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this.strokeWidth = iconContract.props.strokeWidth.default;
|
|
61
|
+
this.variant = iconContract.props.variant.default;
|
|
62
|
+
this.color = iconContract.props.color.default;
|
|
64
63
|
this.label = undefined;
|
|
65
|
-
this.decorative = iconContract.props.decorative.default;
|
|
66
64
|
}
|
|
67
65
|
updated() {
|
|
68
66
|
const icon = this.#requireIcon();
|
|
@@ -85,18 +83,17 @@ export class CosmIcon extends CosmElement {
|
|
|
85
83
|
this.size !== 'md' &&
|
|
86
84
|
this.size !== 'lg')
|
|
87
85
|
throw new TypeError('Icon size must be sm, md, lg or a positive finite number.');
|
|
88
|
-
if (!
|
|
89
|
-
throw new TypeError('Icon
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
86
|
+
if (!iconContract.props.variant.values.includes(this.variant))
|
|
87
|
+
throw new TypeError('Icon variant must be outline or filled.');
|
|
88
|
+
const color = this.color;
|
|
89
|
+
if (typeof color !== 'string' ||
|
|
90
|
+
!color.trim() ||
|
|
91
|
+
/url\s*\(|javascript:|[;{}\\]/i.test(color) ||
|
|
92
|
+
[...color].some(character => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127) ||
|
|
93
|
+
(typeof CSS !== 'undefined' &&
|
|
94
|
+
typeof CSS.supports === 'function' &&
|
|
95
|
+
!CSS.supports('color', color)))
|
|
96
|
+
throw new TypeError('Icon color must be a supported CSS color without a URL.');
|
|
100
97
|
if (typeof this.size === 'number')
|
|
101
98
|
this.style.setProperty('--_cosm-icon-size', `${this.size}px`);
|
|
102
99
|
else
|
|
@@ -108,9 +105,6 @@ export class CosmIcon extends CosmElement {
|
|
|
108
105
|
if (!isIconDefinition(this.icon)) {
|
|
109
106
|
throw new TypeError('cosm-icon requires a valid IconDefinition in its "icon" property.');
|
|
110
107
|
}
|
|
111
|
-
if (!this.decorative && !this.label?.trim()) {
|
|
112
|
-
throw new TypeError('cosm-icon requires a non-empty "label" when decorative is false.');
|
|
113
|
-
}
|
|
114
108
|
return this.icon;
|
|
115
109
|
}
|
|
116
110
|
render() {
|
|
@@ -120,16 +114,21 @@ export class CosmIcon extends CosmElement {
|
|
|
120
114
|
cosm-icon requires a valid IconDefinition in its "icon" property.
|
|
121
115
|
</span>`;
|
|
122
116
|
}
|
|
117
|
+
const label = this.label?.trim();
|
|
118
|
+
// The root paints currentColor; the color attribute sets it, so explicit node fills
|
|
119
|
+
// (including currentColor dots) keep their own paint and follow the same color. The filled
|
|
120
|
+
// variant only changes the inherited root fill, so explicit node fills (even none) still win.
|
|
123
121
|
return html `<svg
|
|
124
122
|
part="icon"
|
|
125
|
-
aria-hidden=${
|
|
126
|
-
role=${
|
|
127
|
-
aria-label=${
|
|
123
|
+
aria-hidden=${label ? nothing : 'true'}
|
|
124
|
+
role=${label ? 'img' : nothing}
|
|
125
|
+
aria-label=${label || nothing}
|
|
128
126
|
focusable="false"
|
|
129
127
|
viewBox=${icon.viewBox}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
color=${this.color}
|
|
129
|
+
stroke="currentColor"
|
|
130
|
+
fill=${this.variant === 'filled' ? 'currentColor' : 'none'}
|
|
131
|
+
stroke-width=${strokeWidth}
|
|
133
132
|
></svg>`;
|
|
134
133
|
}
|
|
135
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cosm-icon.js","sourceRoot":"","sources":["../../../src/components/icon/cosm-icon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAuB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;A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ED,YAAY;QACV,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC9C,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAEkB,MAAM;QACvB,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAA;;cAEH,CAAC;QACX,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;QACjC,oFAAoF;QACpF,2FAA2F;QAC3F,8FAA8F;QAC9F,OAAO,IAAI,CAAA;;oBAEK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;aAC/B,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO;mBACjB,KAAK,IAAI,OAAO;;gBAEnB,IAAI,CAAC,OAAO;cACd,IAAI,CAAC,KAAK;;aAEX,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM;qBAC3C,WAAW;YACpB,CAAC;IACX,CAAC;;AAGH,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type ContractProps, type IconButtonPressedChangeDetail, iconButtonContract } from '@joralvmel/cosmos-core';
|
|
2
|
+
import { CosmElement } from '../../internal/cosm-element.js';
|
|
3
|
+
type Props = Required<ContractProps<typeof iconButtonContract, 'web'>>;
|
|
4
|
+
/**
|
|
5
|
+
* Labeled icon-only action or toggle.
|
|
6
|
+
* @tag cosm-icon-button
|
|
7
|
+
* @slot - Decorative icon.
|
|
8
|
+
* @csspart base - Native button.
|
|
9
|
+
* @fires {CustomEvent<IconButtonPressDetail>} cosm-press - Activation.
|
|
10
|
+
* @fires {CustomEvent<IconButtonPressedChangeDetail>} cosm-pressed-change - Proposed toggle state.
|
|
11
|
+
* @cssprop --cosm-icon-button-background - Background.
|
|
12
|
+
* @cssprop --cosm-icon-button-color - Icon color.
|
|
13
|
+
* @cssprop --cosm-icon-button-border - Border color.
|
|
14
|
+
* @cssprop --cosm-icon-button-radius - Corner radius.
|
|
15
|
+
* @cssprop --cosm-icon-button-focus - Focus indicator color.
|
|
16
|
+
*/
|
|
17
|
+
export declare class CosmIconButton extends CosmElement {
|
|
18
|
+
#private;
|
|
19
|
+
static formAssociated: boolean;
|
|
20
|
+
static shadowRootOptions: ShadowRootInit;
|
|
21
|
+
static properties: {
|
|
22
|
+
label: {};
|
|
23
|
+
mode: {
|
|
24
|
+
reflect: boolean;
|
|
25
|
+
};
|
|
26
|
+
variant: {
|
|
27
|
+
reflect: boolean;
|
|
28
|
+
};
|
|
29
|
+
tone: {
|
|
30
|
+
reflect: boolean;
|
|
31
|
+
};
|
|
32
|
+
size: {
|
|
33
|
+
reflect: boolean;
|
|
34
|
+
};
|
|
35
|
+
disabled: {
|
|
36
|
+
type: BooleanConstructor;
|
|
37
|
+
reflect: boolean;
|
|
38
|
+
};
|
|
39
|
+
type: {};
|
|
40
|
+
pressed: {
|
|
41
|
+
type: BooleanConstructor;
|
|
42
|
+
noAccessor: boolean;
|
|
43
|
+
};
|
|
44
|
+
defaultPressed: {
|
|
45
|
+
type: BooleanConstructor;
|
|
46
|
+
attribute: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
static styles: import("lit").CSSResult[];
|
|
50
|
+
label: string;
|
|
51
|
+
mode: Props['mode'];
|
|
52
|
+
variant: Props['variant'];
|
|
53
|
+
tone: Props['tone'];
|
|
54
|
+
size: Props['size'];
|
|
55
|
+
disabled: boolean;
|
|
56
|
+
type: Props['type'];
|
|
57
|
+
defaultPressed: boolean;
|
|
58
|
+
/** Adapters set ownership when a pressed binding is present. */
|
|
59
|
+
pressedControlled: boolean;
|
|
60
|
+
constructor();
|
|
61
|
+
get pressed(): boolean;
|
|
62
|
+
set pressed(value: boolean | undefined);
|
|
63
|
+
get form(): HTMLFormElement | null;
|
|
64
|
+
attributeChangedCallback(name: string, old: string | null, value: string | null): void;
|
|
65
|
+
formDisabledCallback(disabled: boolean): void;
|
|
66
|
+
protected willUpdate(changed: Map<PropertyKey, unknown>): void;
|
|
67
|
+
click(): void;
|
|
68
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
69
|
+
}
|
|
70
|
+
declare global {
|
|
71
|
+
interface HTMLElementTagNameMap {
|
|
72
|
+
'cosm-icon-button': CosmIconButton;
|
|
73
|
+
}
|
|
74
|
+
interface HTMLElementEventMap {
|
|
75
|
+
'cosm-pressed-change': CustomEvent<IconButtonPressedChangeDetail>;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=cosm-icon-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosm-icon-button.d.ts","sourceRoot":"","sources":["../../../src/components/icon-button/cosm-icon-button.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,6BAA6B,EAClC,kBAAkB,EAEnB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAI7D,KAAK,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC;AAwEvE;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,SAAQ,WAAW;;IAC7C,MAAM,CAAC,cAAc,UAAQ;IAC7B,OAAgB,iBAAiB,EAAE,cAAc,CAG/C;IACF,OAAgB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;MAUxB;IACF,OAAgB,MAAM,4BAAuB;IAErC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IAEhC,gEAAgE;IAChE,iBAAiB,UAAS;;IAsB1B,IAAI,OAAO,IAAI,OAAO,CAErB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAGrC;IAMD,IAAI,IAAI,IAAI,eAAe,GAAG,IAAI,CAEjC;IACQ,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAI/F,oBAAoB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;cAQ1B,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,IAAI;IAK9D,KAAK,IAAI,IAAI;cA+BH,MAAM;CAU1B;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,kBAAkB,EAAE,cAAc,CAAC;KACpC;IACD,UAAU,mBAAmB;QAC3B,qBAAqB,EAAE,WAAW,CAAC,6BAA6B,CAAC,CAAC;KACnE;CACF"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { iconButtonContract, } from '@joralvmel/cosmos-core';
|
|
2
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
3
|
+
import { CosmElement } from '../../internal/cosm-element.js';
|
|
4
|
+
import { define } from '../../internal/define.js';
|
|
5
|
+
import { boxSizing } from '../../internal/styles.js';
|
|
6
|
+
const styles = css `
|
|
7
|
+
:host {
|
|
8
|
+
--_solid: var(--cosm-primary, oklch(0.55 0.2 268));
|
|
9
|
+
--_on-solid: var(--cosm-primary-fg, oklch(1 0 0));
|
|
10
|
+
--_subtle: var(--cosm-primary-subtle, oklch(0.945 0.048 268));
|
|
11
|
+
--_text: var(--cosm-primary-text, oklch(0.44 0.18 268));
|
|
12
|
+
--_size: var(--cosm-control-md, 2.5rem);
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
vertical-align: middle;
|
|
15
|
+
}
|
|
16
|
+
:host([tone='neutral']) {
|
|
17
|
+
--_solid: var(--cosm-fg, oklch(0.24 0.01 268));
|
|
18
|
+
--_on-solid: var(--cosm-bg, oklch(0.985 0.007 268));
|
|
19
|
+
--_subtle: var(--cosm-neutral-3, oklch(0.945 0.01 268));
|
|
20
|
+
--_text: var(--cosm-fg, oklch(0.24 0.01 268));
|
|
21
|
+
}
|
|
22
|
+
:host([tone='danger']) {
|
|
23
|
+
--_solid: var(--cosm-danger, oklch(0.55 0.16 19));
|
|
24
|
+
--_on-solid: var(--cosm-danger-fg, oklch(1 0 0));
|
|
25
|
+
--_subtle: var(--cosm-danger-subtle, oklch(0.945 0.038 19));
|
|
26
|
+
--_text: var(--cosm-danger-text, oklch(0.44 0.144 19));
|
|
27
|
+
}
|
|
28
|
+
:host([size='sm']) { --_size: var(--cosm-control-sm, 2rem); }
|
|
29
|
+
:host([size='lg']) { --_size: var(--cosm-control-lg, 3rem); }
|
|
30
|
+
.base {
|
|
31
|
+
--_bg: var(--_solid);
|
|
32
|
+
--_fg: var(--_on-solid);
|
|
33
|
+
--_border: transparent;
|
|
34
|
+
display: inline-flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: center;
|
|
37
|
+
width: var(--_size);
|
|
38
|
+
height: var(--_size);
|
|
39
|
+
padding: 0;
|
|
40
|
+
border: 1px solid var(--cosm-icon-button-border, var(--_border));
|
|
41
|
+
border-radius: var(--cosm-icon-button-radius, var(--cosm-radius-md, 0.5rem));
|
|
42
|
+
background: var(--cosm-icon-button-background, var(--_bg));
|
|
43
|
+
color: var(--cosm-icon-button-color, var(--_fg));
|
|
44
|
+
font: inherit;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
transition: background-color var(--cosm-duration-fast, 120ms) var(--cosm-easing-standard, ease);
|
|
47
|
+
}
|
|
48
|
+
.icon {
|
|
49
|
+
display: flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
justify-content: center;
|
|
52
|
+
}
|
|
53
|
+
:host([variant='soft']) .base { --_bg: var(--_subtle); --_fg: var(--_text); }
|
|
54
|
+
:host([variant='outline']) .base {
|
|
55
|
+
--_bg: transparent;
|
|
56
|
+
--_fg: var(--_text);
|
|
57
|
+
--_border: var(--cosm-border-strong, oklch(0.64 0.01 268));
|
|
58
|
+
}
|
|
59
|
+
:host([variant='ghost']) .base { --_bg: transparent; --_fg: var(--_text); }
|
|
60
|
+
.base:hover { --_bg: color-mix(in oklab, var(--_solid), var(--_on-solid) 14%); }
|
|
61
|
+
:host([variant='soft']) .base:hover,
|
|
62
|
+
:host([variant='outline']) .base:hover,
|
|
63
|
+
:host([variant='ghost']) .base:hover { --_bg: var(--_subtle); }
|
|
64
|
+
.base:active { filter: brightness(0.9); }
|
|
65
|
+
.base[aria-pressed='true'] {
|
|
66
|
+
box-shadow: inset 0 0 0 2px currentColor;
|
|
67
|
+
}
|
|
68
|
+
.base:focus-visible {
|
|
69
|
+
outline: 2px solid var(--cosm-icon-button-focus, var(--cosm-focus-ring, oklch(0.55 0.2 268)));
|
|
70
|
+
outline-offset: 2px;
|
|
71
|
+
}
|
|
72
|
+
.base:disabled { cursor: not-allowed; opacity: 0.5; }
|
|
73
|
+
@media (prefers-reduced-motion: reduce) { .base { transition: none; } }
|
|
74
|
+
`;
|
|
75
|
+
/**
|
|
76
|
+
* Labeled icon-only action or toggle.
|
|
77
|
+
* @tag cosm-icon-button
|
|
78
|
+
* @slot - Decorative icon.
|
|
79
|
+
* @csspart base - Native button.
|
|
80
|
+
* @fires {CustomEvent<IconButtonPressDetail>} cosm-press - Activation.
|
|
81
|
+
* @fires {CustomEvent<IconButtonPressedChangeDetail>} cosm-pressed-change - Proposed toggle state.
|
|
82
|
+
* @cssprop --cosm-icon-button-background - Background.
|
|
83
|
+
* @cssprop --cosm-icon-button-color - Icon color.
|
|
84
|
+
* @cssprop --cosm-icon-button-border - Border color.
|
|
85
|
+
* @cssprop --cosm-icon-button-radius - Corner radius.
|
|
86
|
+
* @cssprop --cosm-icon-button-focus - Focus indicator color.
|
|
87
|
+
*/
|
|
88
|
+
export class CosmIconButton extends CosmElement {
|
|
89
|
+
static formAssociated = true;
|
|
90
|
+
static shadowRootOptions = {
|
|
91
|
+
...LitElement.shadowRootOptions,
|
|
92
|
+
delegatesFocus: true,
|
|
93
|
+
};
|
|
94
|
+
static properties = {
|
|
95
|
+
label: {},
|
|
96
|
+
mode: { reflect: true },
|
|
97
|
+
variant: { reflect: true },
|
|
98
|
+
tone: { reflect: true },
|
|
99
|
+
size: { reflect: true },
|
|
100
|
+
disabled: { type: Boolean, reflect: true },
|
|
101
|
+
type: {},
|
|
102
|
+
pressed: { type: Boolean, noAccessor: true },
|
|
103
|
+
defaultPressed: { type: Boolean, attribute: 'default-pressed' },
|
|
104
|
+
};
|
|
105
|
+
static styles = [boxSizing, styles];
|
|
106
|
+
/** Adapters set ownership when a pressed binding is present. */
|
|
107
|
+
pressedControlled = false;
|
|
108
|
+
#pressed = false;
|
|
109
|
+
#edited = false;
|
|
110
|
+
#formDisabled = false;
|
|
111
|
+
#nextSource;
|
|
112
|
+
#internals;
|
|
113
|
+
constructor() {
|
|
114
|
+
super();
|
|
115
|
+
const props = iconButtonContract.props;
|
|
116
|
+
this.label = '';
|
|
117
|
+
this.mode = props.mode.default;
|
|
118
|
+
this.variant = props.variant.default;
|
|
119
|
+
this.tone = props.tone.default;
|
|
120
|
+
this.size = props.size.default;
|
|
121
|
+
this.disabled = props.disabled.default;
|
|
122
|
+
this.type = props.type.default;
|
|
123
|
+
this.defaultPressed = props.defaultPressed.default;
|
|
124
|
+
this.#internals =
|
|
125
|
+
typeof this.attachInternals === 'function' ? this.attachInternals() : undefined;
|
|
126
|
+
}
|
|
127
|
+
get pressed() {
|
|
128
|
+
return this.#pressed;
|
|
129
|
+
}
|
|
130
|
+
set pressed(value) {
|
|
131
|
+
this.pressedControlled = value !== undefined;
|
|
132
|
+
if (value !== undefined)
|
|
133
|
+
this.#setPressed(value);
|
|
134
|
+
}
|
|
135
|
+
#setPressed(value) {
|
|
136
|
+
const old = this.#pressed;
|
|
137
|
+
this.#pressed = value;
|
|
138
|
+
this.requestUpdate('pressed', old);
|
|
139
|
+
}
|
|
140
|
+
get form() {
|
|
141
|
+
return this.#internals?.form ?? this.closest('form');
|
|
142
|
+
}
|
|
143
|
+
attributeChangedCallback(name, old, value) {
|
|
144
|
+
super.attributeChangedCallback(name, old, value);
|
|
145
|
+
if (name === 'pressed' && value === null)
|
|
146
|
+
this.pressedControlled = false;
|
|
147
|
+
}
|
|
148
|
+
formDisabledCallback(disabled) {
|
|
149
|
+
if (this.#formDisabled === disabled)
|
|
150
|
+
return;
|
|
151
|
+
this.#formDisabled = disabled;
|
|
152
|
+
const pending = this.isUpdatePending;
|
|
153
|
+
this.requestUpdate();
|
|
154
|
+
// Attribute reflection can invoke this callback during an ongoing Lit update.
|
|
155
|
+
if (pending)
|
|
156
|
+
queueMicrotask(() => this.requestUpdate());
|
|
157
|
+
}
|
|
158
|
+
willUpdate(changed) {
|
|
159
|
+
if (changed.has('defaultPressed') && !this.pressedControlled && !this.#edited) {
|
|
160
|
+
this.#setPressed(this.defaultPressed);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
click() {
|
|
164
|
+
const button = this.renderRoot.querySelector('button');
|
|
165
|
+
if (!button || button.disabled)
|
|
166
|
+
return;
|
|
167
|
+
this.#nextSource = 'programmatic';
|
|
168
|
+
button.click();
|
|
169
|
+
}
|
|
170
|
+
#onPointerDown = () => {
|
|
171
|
+
this.#nextSource = 'pointer';
|
|
172
|
+
};
|
|
173
|
+
#onKeyDown = (event) => {
|
|
174
|
+
if (event.key === 'Enter' || event.key === ' ')
|
|
175
|
+
this.#nextSource = 'keyboard';
|
|
176
|
+
};
|
|
177
|
+
#onClick = (event) => {
|
|
178
|
+
const source = this.#nextSource ?? (event.detail === 0 ? 'keyboard' : 'pointer');
|
|
179
|
+
this.#nextSource = undefined;
|
|
180
|
+
if (this.disabled || this.#formDisabled) {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
event.stopPropagation();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (this.mode === 'toggle') {
|
|
186
|
+
const pressed = !this.#pressed;
|
|
187
|
+
this.#edited = true;
|
|
188
|
+
if (!this.pressedControlled)
|
|
189
|
+
this.#setPressed(pressed);
|
|
190
|
+
this.emit('cosm-pressed-change', { pressed });
|
|
191
|
+
}
|
|
192
|
+
const form = this.form;
|
|
193
|
+
if (form && this.type === 'submit')
|
|
194
|
+
form.requestSubmit();
|
|
195
|
+
if (form && this.type === 'reset')
|
|
196
|
+
form.reset();
|
|
197
|
+
this.emit('cosm-press', { source });
|
|
198
|
+
};
|
|
199
|
+
render() {
|
|
200
|
+
if (!this.label?.trim())
|
|
201
|
+
throw new Error('cosm-icon-button requires a non-empty label.');
|
|
202
|
+
return html `<button
|
|
203
|
+
part="base" class="base" type="button"
|
|
204
|
+
?disabled=${this.disabled || this.#formDisabled}
|
|
205
|
+
aria-label=${this.label}
|
|
206
|
+
aria-pressed=${this.mode === 'toggle' ? String(this.#pressed) : nothing}
|
|
207
|
+
@pointerdown=${this.#onPointerDown} @keydown=${this.#onKeyDown} @click=${this.#onClick}
|
|
208
|
+
><span class="icon" aria-hidden="true"><slot></slot></span></button>`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
define('cosm-icon-button', CosmIconButton);
|
|
212
|
+
//# sourceMappingURL=cosm-icon-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|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C,aAAa,EAAE,CAAC;QACzD,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;YAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAChD,IAAI,CAAC,IAAI,CAAwB,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC;IACiB,MAAM;QACvB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QACzF,OAAO,IAAI,CAAA;;kBAEG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,aAAa;mBAClC,IAAI,CAAC,KAAK;qBACR,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO;qBACxD,IAAI,CAAC,cAAc,aAAa,IAAI,CAAC,UAAU,WAAW,IAAI,CAAC,QAAQ;yEACnB,CAAC;IACxE,CAAC;;AAGH,MAAM,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { type ContractProps, type ListboxItem, type ListboxSelectionChangeDetail, listboxContract } from '@joralvmel/cosmos-core';
|
|
2
|
+
import { type IconDefinition } from '@joralvmel/cosmos-icons';
|
|
3
|
+
import { CosmElement } from '../../internal/cosm-element.js';
|
|
4
|
+
import '../icon/cosm-icon.js';
|
|
5
|
+
type Props = ContractProps<typeof listboxContract, 'web', {
|
|
6
|
+
ListboxItems: readonly ListboxItem<IconDefinition>[];
|
|
7
|
+
ListboxValues: readonly string[];
|
|
8
|
+
}>;
|
|
9
|
+
export type ListboxSize = NonNullable<Props['size']>;
|
|
10
|
+
export type ListboxVariant = NonNullable<Props['variant']>;
|
|
11
|
+
/**
|
|
12
|
+
* Renders a named, keyboard-navigable single- or multiple-selection listbox.
|
|
13
|
+
*
|
|
14
|
+
* @tag cosm-listbox
|
|
15
|
+
* @slot - No content slot; options are supplied through the `items` property.
|
|
16
|
+
* @csspart base - Outer listbox container.
|
|
17
|
+
* @csspart label - Visible or visually hidden accessible label.
|
|
18
|
+
* @csspart list - Scrollable listbox element.
|
|
19
|
+
* @csspart group - Named, noninteractive option group.
|
|
20
|
+
* @csspart group-label - Noninteractive group heading.
|
|
21
|
+
* @csspart option - Selectable row with data-active, data-selected and data-disabled states.
|
|
22
|
+
* @csspart icon - Decorative option icon.
|
|
23
|
+
* @csspart content - Option text content wrapper.
|
|
24
|
+
* @csspart option-label - Primary option text.
|
|
25
|
+
* @csspart description - Supporting option text.
|
|
26
|
+
* @csspart indicator - Decorative selected-state indicator.
|
|
27
|
+
* @fires {CustomEvent<ListboxSelectionChangeDetail>} cosm-selection-change - Proposes a selection update.
|
|
28
|
+
* @cssprop --cosm-listbox-background - Container background.
|
|
29
|
+
* @cssprop --cosm-listbox-color - Primary foreground.
|
|
30
|
+
* @cssprop --cosm-listbox-border - Outlined container border color.
|
|
31
|
+
* @cssprop --cosm-listbox-radius - Container and option corner radius.
|
|
32
|
+
* @cssprop --cosm-listbox-option-height - Minimum option height.
|
|
33
|
+
* @cssprop --cosm-listbox-option-padding - Option padding.
|
|
34
|
+
* @cssprop --cosm-listbox-gap - Space between icon, content and selection indicator.
|
|
35
|
+
* @cssprop --cosm-listbox-font-size - Primary option text size.
|
|
36
|
+
* @cssprop --cosm-listbox-description-color - Supporting text color.
|
|
37
|
+
* @cssprop --cosm-listbox-selected-background - Selected option background.
|
|
38
|
+
* @cssprop --cosm-listbox-selected-color - Selected option foreground.
|
|
39
|
+
* @cssprop --cosm-listbox-focus - Visible keyboard focus outline color.
|
|
40
|
+
* @cssprop --cosm-listbox-max-height - Maximum scrollable list height.
|
|
41
|
+
*/
|
|
42
|
+
export declare class CosmListbox extends CosmElement {
|
|
43
|
+
#private;
|
|
44
|
+
static shadowRootOptions: ShadowRootInit;
|
|
45
|
+
static properties: {
|
|
46
|
+
label: {
|
|
47
|
+
type: StringConstructor;
|
|
48
|
+
};
|
|
49
|
+
labelHidden: {
|
|
50
|
+
type: BooleanConstructor;
|
|
51
|
+
reflect: boolean;
|
|
52
|
+
attribute: string;
|
|
53
|
+
};
|
|
54
|
+
items: {
|
|
55
|
+
attribute: boolean;
|
|
56
|
+
};
|
|
57
|
+
selectionMode: {
|
|
58
|
+
reflect: boolean;
|
|
59
|
+
attribute: string;
|
|
60
|
+
};
|
|
61
|
+
selectedValues: {
|
|
62
|
+
attribute: boolean;
|
|
63
|
+
noAccessor: boolean;
|
|
64
|
+
};
|
|
65
|
+
defaultSelectedValues: {
|
|
66
|
+
attribute: boolean;
|
|
67
|
+
};
|
|
68
|
+
variant: {
|
|
69
|
+
reflect: boolean;
|
|
70
|
+
};
|
|
71
|
+
size: {
|
|
72
|
+
reflect: boolean;
|
|
73
|
+
};
|
|
74
|
+
disabled: {
|
|
75
|
+
type: BooleanConstructor;
|
|
76
|
+
reflect: boolean;
|
|
77
|
+
};
|
|
78
|
+
readOnly: {
|
|
79
|
+
type: BooleanConstructor;
|
|
80
|
+
reflect: boolean;
|
|
81
|
+
attribute: string;
|
|
82
|
+
};
|
|
83
|
+
locale: {
|
|
84
|
+
type: StringConstructor;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
static styles: import("lit").CSSResult[];
|
|
88
|
+
/** Required, nonempty accessible name for the listbox. */
|
|
89
|
+
label: Props['label'];
|
|
90
|
+
/** Visually hides the label while retaining it as the listbox accessible name. */
|
|
91
|
+
labelHidden: Props['labelHidden'];
|
|
92
|
+
/** Ordered readonly options and named groups to render. */
|
|
93
|
+
items: Props['items'];
|
|
94
|
+
/** Permits one selected value or toggling multiple values. */
|
|
95
|
+
selectionMode: Props['selectionMode'];
|
|
96
|
+
/** Values used for the initial autonomous selection; later changes do not reset it. */
|
|
97
|
+
defaultSelectedValues: Props['defaultSelectedValues'];
|
|
98
|
+
/** Plain or outlined container presentation. */
|
|
99
|
+
variant: Props['variant'];
|
|
100
|
+
/** Small, medium or large option rows. */
|
|
101
|
+
size: ListboxSize;
|
|
102
|
+
/** Prevents focus and selection interaction for the whole list. */
|
|
103
|
+
disabled: Props['disabled'];
|
|
104
|
+
/** Allows exploration while preventing selection proposals. */
|
|
105
|
+
readOnly: Props['readOnly'];
|
|
106
|
+
/** Locale override for typeahead; otherwise inherits the nearest `lang`. */
|
|
107
|
+
locale: Props['locale'];
|
|
108
|
+
/** Set by adapters or imperative callers to override binding inference for `selectedValues`. */
|
|
109
|
+
get selectedValuesControlled(): boolean;
|
|
110
|
+
set selectedValuesControlled(value: boolean);
|
|
111
|
+
/** Controlled selected values; setting a defined array marks the state controlled. */
|
|
112
|
+
get selectedValues(): Props['selectedValues'];
|
|
113
|
+
set selectedValues(value: Props['selectedValues']);
|
|
114
|
+
/** The current committed selection, regardless of whether it is autonomous or controlled. */
|
|
115
|
+
get currentSelectedValues(): readonly string[];
|
|
116
|
+
/** The current roving option value, or `null` when every option is disabled or absent. */
|
|
117
|
+
get activeValue(): string | null;
|
|
118
|
+
constructor();
|
|
119
|
+
connectedCallback(): void;
|
|
120
|
+
disconnectedCallback(): void;
|
|
121
|
+
/** Focuses the active enabled option, or the initially selected enabled option. */
|
|
122
|
+
focus(options?: FocusOptions): void;
|
|
123
|
+
protected willUpdate(changed: Map<PropertyKey, unknown>): void;
|
|
124
|
+
protected updated(): void;
|
|
125
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
126
|
+
}
|
|
127
|
+
declare global {
|
|
128
|
+
interface HTMLElementTagNameMap {
|
|
129
|
+
'cosm-listbox': CosmListbox;
|
|
130
|
+
}
|
|
131
|
+
interface HTMLElementEventMap {
|
|
132
|
+
'cosm-selection-change': CustomEvent<ListboxSelectionChangeDetail>;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export {};
|
|
136
|
+
//# sourceMappingURL=cosm-listbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosm-listbox.d.ts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