@joralvmel/cosmos-elements 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +30 -2
- package/dist/components/button/cosm-button.d.ts +79 -0
- package/dist/components/button/cosm-button.d.ts.map +1 -0
- package/dist/components/button/cosm-button.js +243 -0
- package/dist/components/button/cosm-button.js.map +1 -0
- package/dist/custom-elements.json +293 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/cosm-element.d.ts +13 -0
- package/dist/internal/cosm-element.d.ts.map +1 -0
- package/dist/internal/cosm-element.js +17 -0
- package/dist/internal/cosm-element.js.map +1 -0
- package/dist/internal/define.d.ts +6 -0
- package/dist/internal/define.d.ts.map +1 -0
- package/dist/internal/define.js +11 -0
- package/dist/internal/define.js.map +1 -0
- package/dist/internal/styles.d.ts +5 -0
- package/dist/internal/styles.d.ts.map +1 -0
- package/dist/internal/styles.js +20 -0
- package/dist/internal/styles.js.map +1 -0
- package/llms.md +86 -0
- package/package.json +59 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jorge Andrés Álvarez Melchor (joralvmel)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @joralvmel/cosmos-elements
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Web Components for [Cosmos UI](../../README.md).
|
|
4
|
+
|
|
5
|
+
Framework-agnostic Cosmos components built with Lit. Styled only with Cosmos tokens.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import '@joralvmel/cosmos-tokens/tokens.css';
|
|
9
|
+
import '@joralvmel/cosmos-elements/button';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```html
|
|
13
|
+
<cosm-button variant="soft" tone="primary">Save</cosm-button>
|
|
14
|
+
<script type="module">
|
|
15
|
+
document.querySelector('cosm-button').addEventListener('cosm-press', event => {
|
|
16
|
+
console.log(event.detail.source); // 'pointer' | 'keyboard' | 'programmatic'
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Components
|
|
22
|
+
|
|
23
|
+
| Element | Import | Description |
|
|
24
|
+
| --------------- | ----------------------------------- | ---------------------------------- |
|
|
25
|
+
| `<cosm-button>` | `@joralvmel/cosmos-elements/button` | Action or form submit/reset button |
|
|
26
|
+
|
|
27
|
+
The Custom Elements Manifest is published as `@joralvmel/cosmos-elements/custom-elements.json`.
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
MIT
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type ButtonPressDetail, buttonContract, type ContractProps } from '@joralvmel/cosmos-core';
|
|
2
|
+
import { CosmElement } from '../../internal/cosm-element.js';
|
|
3
|
+
type Props = Required<ContractProps<typeof buttonContract, 'web'>>;
|
|
4
|
+
export type ButtonVariant = Props['variant'];
|
|
5
|
+
export type ButtonTone = Props['tone'];
|
|
6
|
+
export type ButtonSize = Props['size'];
|
|
7
|
+
export type ButtonType = Props['type'];
|
|
8
|
+
/**
|
|
9
|
+
* Triggers an action or submits a form. Renders a native `<button>` (WAI-ARIA APG button
|
|
10
|
+
* pattern) and is form-associated, so `type="submit"` and `type="reset"` work inside forms.
|
|
11
|
+
*
|
|
12
|
+
* @tag cosm-button
|
|
13
|
+
* @slot - Button label.
|
|
14
|
+
* @slot start - Content before the label, usually an icon.
|
|
15
|
+
* @slot end - Content after the label, usually an icon.
|
|
16
|
+
* @csspart base - The native button element.
|
|
17
|
+
* @csspart label - Wrapper of the label slot.
|
|
18
|
+
* @csspart spinner - Loading indicator.
|
|
19
|
+
* @fires {CustomEvent<ButtonPressDetail>} cosm-press - The button was activated.
|
|
20
|
+
* @cssprop --cosm-button-radius - Corner radius.
|
|
21
|
+
* @cssprop --cosm-button-gap - Space between icon and label.
|
|
22
|
+
* @cssprop --cosm-button-font-weight - Label font weight.
|
|
23
|
+
*/
|
|
24
|
+
export declare class CosmButton extends CosmElement {
|
|
25
|
+
#private;
|
|
26
|
+
static formAssociated: boolean;
|
|
27
|
+
static shadowRootOptions: ShadowRootInit;
|
|
28
|
+
static properties: {
|
|
29
|
+
variant: {
|
|
30
|
+
reflect: boolean;
|
|
31
|
+
};
|
|
32
|
+
tone: {
|
|
33
|
+
reflect: boolean;
|
|
34
|
+
};
|
|
35
|
+
size: {
|
|
36
|
+
reflect: boolean;
|
|
37
|
+
};
|
|
38
|
+
disabled: {
|
|
39
|
+
type: BooleanConstructor;
|
|
40
|
+
reflect: boolean;
|
|
41
|
+
};
|
|
42
|
+
loading: {
|
|
43
|
+
type: BooleanConstructor;
|
|
44
|
+
reflect: boolean;
|
|
45
|
+
};
|
|
46
|
+
fullWidth: {
|
|
47
|
+
type: BooleanConstructor;
|
|
48
|
+
reflect: boolean;
|
|
49
|
+
attribute: string;
|
|
50
|
+
};
|
|
51
|
+
type: {};
|
|
52
|
+
label: {};
|
|
53
|
+
};
|
|
54
|
+
static styles: import("lit").CSSResult[];
|
|
55
|
+
variant: ButtonVariant;
|
|
56
|
+
tone: ButtonTone;
|
|
57
|
+
size: ButtonSize;
|
|
58
|
+
disabled: boolean;
|
|
59
|
+
loading: boolean;
|
|
60
|
+
fullWidth: boolean;
|
|
61
|
+
type: ButtonType;
|
|
62
|
+
label: string | undefined;
|
|
63
|
+
constructor();
|
|
64
|
+
/** Form the button belongs to (form-associated, with a DOM fallback). */
|
|
65
|
+
get form(): HTMLFormElement | null;
|
|
66
|
+
/** Activates the button programmatically, reporting `source: 'programmatic'`. */
|
|
67
|
+
click(): void;
|
|
68
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
69
|
+
}
|
|
70
|
+
declare global {
|
|
71
|
+
interface HTMLElementTagNameMap {
|
|
72
|
+
'cosm-button': CosmButton;
|
|
73
|
+
}
|
|
74
|
+
interface HTMLElementEventMap {
|
|
75
|
+
'cosm-press': CustomEvent<ButtonPressDetail>;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=cosm-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosm-button.d.ts","sourceRoot":"","sources":["../../../src/components/button/cosm-button.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,cAAc,EACd,KAAK,aAAa,EAGnB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAA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 'lit';
|
|
3
|
+
import { CosmElement } from '../../internal/cosm-element.js';
|
|
4
|
+
import { define } from '../../internal/define.js';
|
|
5
|
+
import { boxSizing, focusRing } 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
|
+
--_height: var(--cosm-control-md, 2.5rem);
|
|
13
|
+
--_padding: var(--cosm-space-lg, 1rem);
|
|
14
|
+
--_font-size: var(--cosm-text-sm, 0.875rem);
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
vertical-align: middle;
|
|
17
|
+
}
|
|
18
|
+
:host([tone='neutral']) {
|
|
19
|
+
--_solid: var(--cosm-fg, oklch(0.24 0.01 268));
|
|
20
|
+
--_on-solid: var(--cosm-bg, oklch(0.985 0.007 268));
|
|
21
|
+
--_subtle: var(--cosm-neutral-3, oklch(0.945 0.01 268));
|
|
22
|
+
--_text: var(--cosm-fg, oklch(0.24 0.01 268));
|
|
23
|
+
}
|
|
24
|
+
:host([tone='danger']) {
|
|
25
|
+
--_solid: var(--cosm-danger, oklch(0.55 0.16 19));
|
|
26
|
+
--_on-solid: var(--cosm-danger-fg, oklch(1 0 0));
|
|
27
|
+
--_subtle: var(--cosm-danger-subtle, oklch(0.945 0.038 19));
|
|
28
|
+
--_text: var(--cosm-danger-text, oklch(0.44 0.144 19));
|
|
29
|
+
}
|
|
30
|
+
:host([size='sm']) {
|
|
31
|
+
--_height: var(--cosm-control-sm, 2rem);
|
|
32
|
+
--_padding: var(--cosm-space-md, 0.75rem);
|
|
33
|
+
--_font-size: var(--cosm-text-sm, 0.875rem);
|
|
34
|
+
}
|
|
35
|
+
:host([size='lg']) {
|
|
36
|
+
--_height: var(--cosm-control-lg, 3rem);
|
|
37
|
+
--_padding: var(--cosm-space-xl, 1.5rem);
|
|
38
|
+
--_font-size: var(--cosm-text-md, 1rem);
|
|
39
|
+
}
|
|
40
|
+
:host([full-width]) {
|
|
41
|
+
display: flex;
|
|
42
|
+
width: 100%;
|
|
43
|
+
}
|
|
44
|
+
:host([disabled]) {
|
|
45
|
+
pointer-events: none;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.base {
|
|
49
|
+
--_bg: var(--_solid);
|
|
50
|
+
--_fg: var(--_on-solid);
|
|
51
|
+
--_border: transparent;
|
|
52
|
+
display: inline-flex;
|
|
53
|
+
flex: 1;
|
|
54
|
+
align-items: center;
|
|
55
|
+
justify-content: center;
|
|
56
|
+
gap: var(--cosm-button-gap, var(--cosm-space-sm, 0.5rem));
|
|
57
|
+
min-height: var(--_height);
|
|
58
|
+
padding: 0 var(--_padding);
|
|
59
|
+
border: 1px solid var(--_border);
|
|
60
|
+
border-radius: var(--cosm-button-radius, var(--cosm-radius-md, 0.5rem));
|
|
61
|
+
background: var(--_bg);
|
|
62
|
+
color: var(--_fg);
|
|
63
|
+
font: inherit;
|
|
64
|
+
font-family: var(--cosm-font-sans, system-ui, sans-serif);
|
|
65
|
+
font-size: var(--_font-size);
|
|
66
|
+
font-weight: var(--cosm-button-font-weight, var(--cosm-weight-semibold, 600));
|
|
67
|
+
line-height: var(--cosm-leading-tight, 1.25);
|
|
68
|
+
cursor: pointer;
|
|
69
|
+
user-select: none;
|
|
70
|
+
transition:
|
|
71
|
+
background-color var(--cosm-duration-fast, 120ms) var(--cosm-easing-standard, ease),
|
|
72
|
+
border-color var(--cosm-duration-fast, 120ms) var(--cosm-easing-standard, ease);
|
|
73
|
+
}
|
|
74
|
+
.base:hover {
|
|
75
|
+
--_bg: color-mix(in oklab, var(--_solid), var(--_on-solid) 14%);
|
|
76
|
+
}
|
|
77
|
+
.base:active {
|
|
78
|
+
--_bg: color-mix(in oklab, var(--_solid), var(--_on-solid) 24%);
|
|
79
|
+
}
|
|
80
|
+
:host([variant='soft']) .base {
|
|
81
|
+
--_bg: var(--_subtle);
|
|
82
|
+
--_fg: var(--_text);
|
|
83
|
+
}
|
|
84
|
+
:host([variant='soft']) .base:hover {
|
|
85
|
+
--_bg: color-mix(in oklab, var(--_subtle), var(--_text) 10%);
|
|
86
|
+
}
|
|
87
|
+
:host([variant='outline']) .base {
|
|
88
|
+
--_bg: transparent;
|
|
89
|
+
--_fg: var(--_text);
|
|
90
|
+
--_border: var(--cosm-border-strong, oklch(0.64 0.01 268));
|
|
91
|
+
}
|
|
92
|
+
:host([variant='ghost']) .base {
|
|
93
|
+
--_bg: transparent;
|
|
94
|
+
--_fg: var(--_text);
|
|
95
|
+
}
|
|
96
|
+
:host([variant='outline']) .base:hover,
|
|
97
|
+
:host([variant='ghost']) .base:hover {
|
|
98
|
+
--_bg: var(--_subtle);
|
|
99
|
+
}
|
|
100
|
+
.base:disabled {
|
|
101
|
+
cursor: not-allowed;
|
|
102
|
+
opacity: 0.5;
|
|
103
|
+
}
|
|
104
|
+
.base[aria-busy='true'] {
|
|
105
|
+
cursor: progress;
|
|
106
|
+
}
|
|
107
|
+
.label {
|
|
108
|
+
display: inline-flex;
|
|
109
|
+
align-items: center;
|
|
110
|
+
}
|
|
111
|
+
::slotted(svg),
|
|
112
|
+
::slotted([slot='start']),
|
|
113
|
+
::slotted([slot='end']) {
|
|
114
|
+
flex-shrink: 0;
|
|
115
|
+
}
|
|
116
|
+
.spinner {
|
|
117
|
+
width: 1em;
|
|
118
|
+
height: 1em;
|
|
119
|
+
border: 2px solid currentColor;
|
|
120
|
+
border-inline-end-color: transparent;
|
|
121
|
+
border-radius: 50%;
|
|
122
|
+
animation: spin 0.8s linear infinite;
|
|
123
|
+
}
|
|
124
|
+
@keyframes spin {
|
|
125
|
+
to {
|
|
126
|
+
transform: rotate(1turn);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
@media (prefers-reduced-motion: reduce) {
|
|
130
|
+
.base {
|
|
131
|
+
transition: none;
|
|
132
|
+
}
|
|
133
|
+
.spinner {
|
|
134
|
+
animation-duration: 2.4s;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
`;
|
|
138
|
+
/**
|
|
139
|
+
* Triggers an action or submits a form. Renders a native `<button>` (WAI-ARIA APG button
|
|
140
|
+
* pattern) and is form-associated, so `type="submit"` and `type="reset"` work inside forms.
|
|
141
|
+
*
|
|
142
|
+
* @tag cosm-button
|
|
143
|
+
* @slot - Button label.
|
|
144
|
+
* @slot start - Content before the label, usually an icon.
|
|
145
|
+
* @slot end - Content after the label, usually an icon.
|
|
146
|
+
* @csspart base - The native button element.
|
|
147
|
+
* @csspart label - Wrapper of the label slot.
|
|
148
|
+
* @csspart spinner - Loading indicator.
|
|
149
|
+
* @fires {CustomEvent<ButtonPressDetail>} cosm-press - The button was activated.
|
|
150
|
+
* @cssprop --cosm-button-radius - Corner radius.
|
|
151
|
+
* @cssprop --cosm-button-gap - Space between icon and label.
|
|
152
|
+
* @cssprop --cosm-button-font-weight - Label font weight.
|
|
153
|
+
*/
|
|
154
|
+
export class CosmButton extends CosmElement {
|
|
155
|
+
static formAssociated = true;
|
|
156
|
+
static shadowRootOptions = {
|
|
157
|
+
...LitElement.shadowRootOptions,
|
|
158
|
+
delegatesFocus: true,
|
|
159
|
+
};
|
|
160
|
+
static properties = {
|
|
161
|
+
variant: { reflect: true },
|
|
162
|
+
tone: { reflect: true },
|
|
163
|
+
size: { reflect: true },
|
|
164
|
+
disabled: { type: Boolean, reflect: true },
|
|
165
|
+
loading: { type: Boolean, reflect: true },
|
|
166
|
+
fullWidth: { type: Boolean, reflect: true, attribute: 'full-width' },
|
|
167
|
+
type: {},
|
|
168
|
+
label: {},
|
|
169
|
+
};
|
|
170
|
+
static styles = [boxSizing, focusRing, styles];
|
|
171
|
+
#internals;
|
|
172
|
+
#nextSource;
|
|
173
|
+
constructor() {
|
|
174
|
+
super();
|
|
175
|
+
const props = buttonContract.props;
|
|
176
|
+
this.variant = props.variant.default;
|
|
177
|
+
this.tone = props.tone.default;
|
|
178
|
+
this.size = props.size.default;
|
|
179
|
+
this.disabled = props.disabled.default;
|
|
180
|
+
this.loading = props.loading.default;
|
|
181
|
+
this.fullWidth = props.fullWidth.default;
|
|
182
|
+
this.type = props.type.default;
|
|
183
|
+
this.label = undefined;
|
|
184
|
+
this.#internals =
|
|
185
|
+
typeof this.attachInternals === 'function' ? this.attachInternals() : undefined;
|
|
186
|
+
}
|
|
187
|
+
/** Form the button belongs to (form-associated, with a DOM fallback). */
|
|
188
|
+
get form() {
|
|
189
|
+
return this.#internals?.form ?? this.closest('form');
|
|
190
|
+
}
|
|
191
|
+
/** Activates the button programmatically, reporting `source: 'programmatic'`. */
|
|
192
|
+
click() {
|
|
193
|
+
const button = this.renderRoot.querySelector('button');
|
|
194
|
+
if (!button)
|
|
195
|
+
return;
|
|
196
|
+
this.#nextSource = 'programmatic';
|
|
197
|
+
button.click();
|
|
198
|
+
}
|
|
199
|
+
#onPointerDown = () => {
|
|
200
|
+
this.#nextSource = 'pointer';
|
|
201
|
+
};
|
|
202
|
+
#onKeyDown = (event) => {
|
|
203
|
+
if (event.key === 'Enter' || event.key === ' ')
|
|
204
|
+
this.#nextSource = 'keyboard';
|
|
205
|
+
};
|
|
206
|
+
#onClick = (event) => {
|
|
207
|
+
const source = this.#nextSource ?? (event.detail === 0 ? 'keyboard' : 'pointer');
|
|
208
|
+
this.#nextSource = undefined;
|
|
209
|
+
if (!getPressableState(this).interactive) {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
event.stopPropagation();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const form = this.form;
|
|
215
|
+
if (form && this.type === 'submit')
|
|
216
|
+
form.requestSubmit();
|
|
217
|
+
if (form && this.type === 'reset')
|
|
218
|
+
form.reset();
|
|
219
|
+
this.emit('cosm-press', { source });
|
|
220
|
+
};
|
|
221
|
+
render() {
|
|
222
|
+
const state = getPressableState(this);
|
|
223
|
+
return html `<button
|
|
224
|
+
part="base"
|
|
225
|
+
class="base"
|
|
226
|
+
type="button"
|
|
227
|
+
?disabled=${state.disabled}
|
|
228
|
+
aria-disabled=${state.busy ? 'true' : nothing}
|
|
229
|
+
aria-busy=${state.busy ? 'true' : nothing}
|
|
230
|
+
aria-label=${this.label || nothing}
|
|
231
|
+
@pointerdown=${this.#onPointerDown}
|
|
232
|
+
@keydown=${this.#onKeyDown}
|
|
233
|
+
@click=${this.#onClick}
|
|
234
|
+
>
|
|
235
|
+
${this.loading ? html `<span part="spinner" class="spinner" aria-hidden="true"></span>` : nothing}
|
|
236
|
+
<slot name="start"></slot>
|
|
237
|
+
<span part="label" class="label"><slot></slot></span>
|
|
238
|
+
<slot name="end"></slot>
|
|
239
|
+
</button>`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
define('cosm-button', CosmButton);
|
|
243
|
+
//# sourceMappingURL=cosm-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosm-button.js","sourceRoot":"","sources":["../../../src/components/button/cosm-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAEd,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAQhE,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmIjB,CAAC;AAEF;;;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E,CAAC;YACzC,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,KAAK,CAAC,eAAe,EAAE,CAAC;YACxB,OAAO;QACT,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;YAAE,IAAI,CAAC,aAAa,EAAE,CAAC;QACzD,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;YAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAChD,IAAI,CAAC,IAAI,CAAoB,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC;IAEiB,MAAM;QACvB,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACtC,OAAO,IAAI,CAAA;;;;kBAIG,KAAK,CAAC,QAAQ;sBACV,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;kBACjC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;mBAC5B,IAAI,CAAC,KAAK,IAAI,OAAO;qBACnB,IAAI,CAAC,cAAc;iBACvB,IAAI,CAAC,UAAU;eACjB,IAAI,CAAC,QAAQ;;QAEpB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA,iEAAiE,CAAC,CAAC,CAAC,OAAO;;;;cAIxF,CAAC;IACb,CAAC;;AAGH,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": "1.0.0",
|
|
3
|
+
"readme": "",
|
|
4
|
+
"modules": [
|
|
5
|
+
{
|
|
6
|
+
"kind": "javascript-module",
|
|
7
|
+
"path": "src/components/button/cosm-button.ts",
|
|
8
|
+
"declarations": [
|
|
9
|
+
{
|
|
10
|
+
"kind": "class",
|
|
11
|
+
"description": "Triggers an action or submits a form. Renders a native `<button>` (WAI-ARIA APG button\npattern) and is form-associated, so `type=\"submit\"` and `type=\"reset\"` work inside forms.",
|
|
12
|
+
"name": "CosmButton",
|
|
13
|
+
"cssProperties": [
|
|
14
|
+
{
|
|
15
|
+
"description": "Corner radius.",
|
|
16
|
+
"name": "--cosm-button-radius"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"description": "Space between icon and label.",
|
|
20
|
+
"name": "--cosm-button-gap"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"description": "Label font weight.",
|
|
24
|
+
"name": "--cosm-button-font-weight"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"cssParts": [
|
|
28
|
+
{
|
|
29
|
+
"description": "The native button element.",
|
|
30
|
+
"name": "base"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"description": "Wrapper of the label slot.",
|
|
34
|
+
"name": "label"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"description": "Loading indicator.",
|
|
38
|
+
"name": "spinner"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"slots": [
|
|
42
|
+
{
|
|
43
|
+
"description": "Button label.",
|
|
44
|
+
"name": ""
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"description": "Content before the label, usually an icon.",
|
|
48
|
+
"name": "start"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"description": "Content after the label, usually an icon.",
|
|
52
|
+
"name": "end"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"members": [
|
|
56
|
+
{
|
|
57
|
+
"kind": "field",
|
|
58
|
+
"name": "formAssociated",
|
|
59
|
+
"type": {
|
|
60
|
+
"text": "boolean"
|
|
61
|
+
},
|
|
62
|
+
"static": true,
|
|
63
|
+
"default": "true"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"kind": "field",
|
|
67
|
+
"name": "shadowRootOptions",
|
|
68
|
+
"type": {
|
|
69
|
+
"text": "ShadowRootInit"
|
|
70
|
+
},
|
|
71
|
+
"static": true,
|
|
72
|
+
"default": "{ ...LitElement.shadowRootOptions, delegatesFocus: true, }"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"kind": "field",
|
|
76
|
+
"name": "variant",
|
|
77
|
+
"privacy": "public",
|
|
78
|
+
"type": {
|
|
79
|
+
"text": "ButtonVariant"
|
|
80
|
+
},
|
|
81
|
+
"attribute": "variant",
|
|
82
|
+
"reflects": true
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"kind": "field",
|
|
86
|
+
"name": "tone",
|
|
87
|
+
"privacy": "public",
|
|
88
|
+
"type": {
|
|
89
|
+
"text": "ButtonTone"
|
|
90
|
+
},
|
|
91
|
+
"attribute": "tone",
|
|
92
|
+
"reflects": true
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"kind": "field",
|
|
96
|
+
"name": "size",
|
|
97
|
+
"privacy": "public",
|
|
98
|
+
"type": {
|
|
99
|
+
"text": "ButtonSize"
|
|
100
|
+
},
|
|
101
|
+
"attribute": "size",
|
|
102
|
+
"reflects": true
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"kind": "field",
|
|
106
|
+
"name": "disabled",
|
|
107
|
+
"privacy": "public",
|
|
108
|
+
"type": {
|
|
109
|
+
"text": "boolean"
|
|
110
|
+
},
|
|
111
|
+
"attribute": "disabled",
|
|
112
|
+
"reflects": true
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"kind": "field",
|
|
116
|
+
"name": "loading",
|
|
117
|
+
"privacy": "public",
|
|
118
|
+
"type": {
|
|
119
|
+
"text": "boolean"
|
|
120
|
+
},
|
|
121
|
+
"attribute": "loading",
|
|
122
|
+
"reflects": true
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"kind": "field",
|
|
126
|
+
"name": "fullWidth",
|
|
127
|
+
"privacy": "public",
|
|
128
|
+
"type": {
|
|
129
|
+
"text": "boolean"
|
|
130
|
+
},
|
|
131
|
+
"attribute": "full-width",
|
|
132
|
+
"reflects": true
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"kind": "field",
|
|
136
|
+
"name": "type",
|
|
137
|
+
"privacy": "public",
|
|
138
|
+
"type": {
|
|
139
|
+
"text": "ButtonType"
|
|
140
|
+
},
|
|
141
|
+
"attribute": "type"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"kind": "field",
|
|
145
|
+
"name": "label",
|
|
146
|
+
"privacy": "public",
|
|
147
|
+
"type": {
|
|
148
|
+
"text": "string | undefined"
|
|
149
|
+
},
|
|
150
|
+
"default": "undefined",
|
|
151
|
+
"attribute": "label"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"kind": "field",
|
|
155
|
+
"name": "#internals",
|
|
156
|
+
"privacy": "private",
|
|
157
|
+
"type": {
|
|
158
|
+
"text": "ElementInternals | undefined"
|
|
159
|
+
},
|
|
160
|
+
"readonly": true
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"kind": "field",
|
|
164
|
+
"name": "#nextSource",
|
|
165
|
+
"privacy": "private",
|
|
166
|
+
"type": {
|
|
167
|
+
"text": "PressSource | undefined"
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"kind": "field",
|
|
172
|
+
"name": "form",
|
|
173
|
+
"type": {
|
|
174
|
+
"text": "HTMLFormElement | null"
|
|
175
|
+
},
|
|
176
|
+
"description": "Form the button belongs to (form-associated, with a DOM fallback).",
|
|
177
|
+
"readonly": true
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"kind": "method",
|
|
181
|
+
"name": "click",
|
|
182
|
+
"return": {
|
|
183
|
+
"type": {
|
|
184
|
+
"text": "void"
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
"description": "Activates the button programmatically, reporting `source: 'programmatic'`."
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"kind": "field",
|
|
191
|
+
"name": "#onPointerDown",
|
|
192
|
+
"privacy": "private"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"kind": "field",
|
|
196
|
+
"name": "#onKeyDown",
|
|
197
|
+
"privacy": "private"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"kind": "field",
|
|
201
|
+
"name": "#onClick",
|
|
202
|
+
"privacy": "private"
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
"events": [
|
|
206
|
+
{
|
|
207
|
+
"type": {
|
|
208
|
+
"text": "CustomEvent<ButtonPressDetail>"
|
|
209
|
+
},
|
|
210
|
+
"description": "The button was activated.",
|
|
211
|
+
"name": "cosm-press"
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
"attributes": [
|
|
215
|
+
{
|
|
216
|
+
"name": "variant",
|
|
217
|
+
"type": {
|
|
218
|
+
"text": "ButtonVariant"
|
|
219
|
+
},
|
|
220
|
+
"fieldName": "variant"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"name": "tone",
|
|
224
|
+
"type": {
|
|
225
|
+
"text": "ButtonTone"
|
|
226
|
+
},
|
|
227
|
+
"fieldName": "tone"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"name": "size",
|
|
231
|
+
"type": {
|
|
232
|
+
"text": "ButtonSize"
|
|
233
|
+
},
|
|
234
|
+
"fieldName": "size"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"name": "disabled",
|
|
238
|
+
"type": {
|
|
239
|
+
"text": "boolean"
|
|
240
|
+
},
|
|
241
|
+
"fieldName": "disabled"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"name": "loading",
|
|
245
|
+
"type": {
|
|
246
|
+
"text": "boolean"
|
|
247
|
+
},
|
|
248
|
+
"fieldName": "loading"
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"name": "full-width",
|
|
252
|
+
"type": {
|
|
253
|
+
"text": "boolean"
|
|
254
|
+
},
|
|
255
|
+
"fieldName": "fullWidth"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"name": "type",
|
|
259
|
+
"type": {
|
|
260
|
+
"text": "ButtonType"
|
|
261
|
+
},
|
|
262
|
+
"fieldName": "type"
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"name": "label",
|
|
266
|
+
"type": {
|
|
267
|
+
"text": "string | undefined"
|
|
268
|
+
},
|
|
269
|
+
"default": "undefined",
|
|
270
|
+
"fieldName": "label"
|
|
271
|
+
}
|
|
272
|
+
],
|
|
273
|
+
"superclass": {
|
|
274
|
+
"name": "CosmElement",
|
|
275
|
+
"module": "/src/internal/cosm-element.js"
|
|
276
|
+
},
|
|
277
|
+
"tagName": "cosm-button",
|
|
278
|
+
"customElement": true
|
|
279
|
+
}
|
|
280
|
+
],
|
|
281
|
+
"exports": [
|
|
282
|
+
{
|
|
283
|
+
"kind": "js",
|
|
284
|
+
"name": "CosmButton",
|
|
285
|
+
"declaration": {
|
|
286
|
+
"name": "CosmButton",
|
|
287
|
+
"module": "src/components/button/cosm-button.ts"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { ButtonPressDetail, PressSource } from '@joralvmel/cosmos-core';
|
|
2
|
+
export { type ButtonSize, type ButtonTone, type ButtonType, type ButtonVariant, CosmButton, } from './components/button/cosm-button.js';
|
|
3
|
+
export { CosmElement, type EmitOptions } from './internal/cosm-element.js';
|
|
4
|
+
export { define } from './internal/define.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,UAAU,GACX,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,UAAU,GACX,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAoB,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
export interface EmitOptions {
|
|
3
|
+
cancelable?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/** Base class of every Cosmos element: typed, composed `cosm-*` events. */
|
|
6
|
+
export declare class CosmElement extends LitElement {
|
|
7
|
+
/**
|
|
8
|
+
* Dispatches a bubbling, composed `CustomEvent`. Returns `false` when a cancelable event was
|
|
9
|
+
* prevented, so callers can treat it as a rejected proposal.
|
|
10
|
+
*/
|
|
11
|
+
protected emit<T>(name: `cosm-${string}`, detail: T, options?: EmitOptions): boolean;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=cosm-element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosm-element.d.ts","sourceRoot":"","sources":["../../src/internal/cosm-element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEjC,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,2EAA2E;AAC3E,qBAAa,WAAY,SAAQ,UAAU;IACzC;;;OAGG;IACH,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO;CAUzF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
/** Base class of every Cosmos element: typed, composed `cosm-*` events. */
|
|
3
|
+
export class CosmElement extends LitElement {
|
|
4
|
+
/**
|
|
5
|
+
* Dispatches a bubbling, composed `CustomEvent`. Returns `false` when a cancelable event was
|
|
6
|
+
* prevented, so callers can treat it as a rejected proposal.
|
|
7
|
+
*/
|
|
8
|
+
emit(name, detail, options = {}) {
|
|
9
|
+
return this.dispatchEvent(new CustomEvent(name, {
|
|
10
|
+
detail,
|
|
11
|
+
bubbles: true,
|
|
12
|
+
composed: true,
|
|
13
|
+
cancelable: options.cancelable ?? false,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=cosm-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cosm-element.js","sourceRoot":"","sources":["../../src/internal/cosm-element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAMjC,2EAA2E;AAC3E,MAAM,OAAO,WAAY,SAAQ,UAAU;IACzC;;;OAGG;IACO,IAAI,CAAI,IAAsB,EAAE,MAAS,EAAE,UAAuB,EAAE;QAC5E,OAAO,IAAI,CAAC,aAAa,CACvB,IAAI,WAAW,CAAI,IAAI,EAAE;YACvB,MAAM;YACN,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,KAAK;SACxC,CAAC,CACH,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers a custom element once. Safe to call from several bundles or during hot reloads:
|
|
3
|
+
* a tag that is already defined is left untouched.
|
|
4
|
+
*/
|
|
5
|
+
export declare function define(tag: string, elementClass: CustomElementConstructor): void;
|
|
6
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/internal/define.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,wBAAwB,GAAG,IAAI,CAGhF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers a custom element once. Safe to call from several bundles or during hot reloads:
|
|
3
|
+
* a tag that is already defined is left untouched.
|
|
4
|
+
*/
|
|
5
|
+
export function define(tag, elementClass) {
|
|
6
|
+
if (typeof customElements === 'undefined')
|
|
7
|
+
return;
|
|
8
|
+
if (!customElements.get(tag))
|
|
9
|
+
customElements.define(tag, elementClass);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/internal/define.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW,EAAE,YAAsC;IACxE,IAAI,OAAO,cAAc,KAAK,WAAW;QAAE,OAAO;IAClD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/internal/styles.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,eAAO,MAAM,SAAS,yBAKrB,CAAC;AAEF,6CAA6C;AAC7C,eAAO,MAAM,SAAS,yBASrB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
/** Visible focus indicator shared by interactive elements. */
|
|
3
|
+
export const focusRing = css `
|
|
4
|
+
:focus-visible {
|
|
5
|
+
outline: 2px solid var(--cosm-focus-ring, oklch(0.55 0.2 268));
|
|
6
|
+
outline-offset: 2px;
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
/** Base box model reset for shadow roots. */
|
|
10
|
+
export const boxSizing = css `
|
|
11
|
+
:host {
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
}
|
|
14
|
+
*,
|
|
15
|
+
*::before,
|
|
16
|
+
*::after {
|
|
17
|
+
box-sizing: inherit;
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/internal/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,8DAA8D;AAC9D,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;;;;;CAK3B,CAAC;AAEF,6CAA6C;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;;;;;;;;;CAS3B,CAAC"}
|
package/llms.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @joralvmel/cosmos-elements
|
|
2
|
+
|
|
3
|
+
Framework-agnostic Web Components (Lit) of Cosmos UI. Use them in plain HTML or any framework; React and Angular users should prefer `@joralvmel/cosmos-react` / `@joralvmel/cosmos-angular`.
|
|
4
|
+
|
|
5
|
+
<!-- generated:start (npm run llms, do not edit this block by hand) -->
|
|
6
|
+
|
|
7
|
+
## Setup: HTML / CDN
|
|
8
|
+
|
|
9
|
+
**Load tokens and components from a CDN** (`index.html`)
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<!doctype html>
|
|
13
|
+
<html lang="en" data-theme="cosmos" data-mode="system">
|
|
14
|
+
<head>
|
|
15
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@joralvmel/cosmos-tokens/dist/tokens.css" />
|
|
16
|
+
<script type="module" src="https://esm.sh/@joralvmel/cosmos-elements/button"></script>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<cosm-button variant="soft">Save</cosm-button>
|
|
20
|
+
<script type="module">
|
|
21
|
+
document.querySelector('cosm-button').addEventListener('cosm-press', event => {
|
|
22
|
+
console.log(event.detail.source);
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- With a bundler, `npm install @joralvmel/cosmos-elements @joralvmel/cosmos-tokens` and import `@joralvmel/cosmos-elements/<component>`.
|
|
30
|
+
- DOM events are `cosm-*` CustomEvents that bubble and cross shadow roots.
|
|
31
|
+
|
|
32
|
+
Guide: https://joralvmel.github.io/cosmos-ui/guides/html-cdn/
|
|
33
|
+
|
|
34
|
+
## Components
|
|
35
|
+
|
|
36
|
+
Every component of this package (status of planned ones: https://joralvmel.github.io/cosmos-ui/components/status/).
|
|
37
|
+
|
|
38
|
+
### `<cosm-button>`
|
|
39
|
+
|
|
40
|
+
Triggers an action or submits a form.
|
|
41
|
+
|
|
42
|
+
| Prop | Type | Default | Description |
|
|
43
|
+
| --- | --- | --- | --- |
|
|
44
|
+
| `variant` | 'solid' \| 'soft' \| 'outline' \| 'ghost' | `solid` | Visual emphasis, from highest (solid) to lowest (ghost). |
|
|
45
|
+
| `tone` | 'primary' \| 'neutral' \| 'danger' | `primary` | Color role. Use danger for destructive actions. |
|
|
46
|
+
| `size` | 'sm' \| 'md' \| 'lg' | `md` | Control height and padding. |
|
|
47
|
+
| `disabled` | boolean | `false` | Prevents interaction and removes the button from the tab order. |
|
|
48
|
+
| `loading` | boolean | `false` | Shows a spinner, sets aria-busy and ignores presses while keeping focus. |
|
|
49
|
+
| `fullWidth` (`full-width`) | boolean | `false` | Stretches the button to the width of its container. |
|
|
50
|
+
| `type` | 'button' \| 'submit' \| 'reset' | `button` | Form behavior of the button. |
|
|
51
|
+
| `label` | string | — | Accessible name when the visible content is not descriptive (icon-only buttons). |
|
|
52
|
+
|
|
53
|
+
Events: `cosm-press` → `ButtonPressDetail`.
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<cosm-button>Button</cosm-button>
|
|
57
|
+
|
|
58
|
+
<script type="module">
|
|
59
|
+
import '@joralvmel/cosmos-elements/button';
|
|
60
|
+
|
|
61
|
+
const element = document.querySelector('cosm-button');
|
|
62
|
+
element.addEventListener('cosm-press', event => console.log(event.detail));
|
|
63
|
+
</script>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Themes
|
|
67
|
+
|
|
68
|
+
Built-in themes: `cosmos`, `nebula` (default `cosmos`), each with `light` and `dark` modes; `system` follows the OS.
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<html data-theme="nebula" data-mode="system">
|
|
72
|
+
<!-- runtime: setTheme(name), setMode(mode) from @joralvmel/cosmos-tokens/runtime -->
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Custom themes: `defineTheme()` in `@joralvmel/cosmos-tokens` (https://joralvmel.github.io/cosmos-ui/theming/themes/).
|
|
76
|
+
|
|
77
|
+
## Rules for AI assistants
|
|
78
|
+
|
|
79
|
+
- Use Cosmos components before writing custom UI; check `list_components` / the component status page for what exists.
|
|
80
|
+
- Style with Cosmos tokens: `var(--cosm-*)` in CSS or the Tailwind theme utilities (`bg-primary`, `text-fg-muted`, `rounded-md`). Never hard-code colors.
|
|
81
|
+
- Set the theme and mode with `data-theme` and `data-mode` on the root element (or `CosmosThemeProvider` on React Native).
|
|
82
|
+
- Keep accessibility: give icon-only buttons a `label`, never rely on color alone, keep keyboard support.
|
|
83
|
+
- Never render untrusted HTML (`innerHTML`, `dangerouslySetInnerHTML`) and never build class names from user input.
|
|
84
|
+
- Use `<cosm-*>` elements and listen to `cosm-*` DOM events; import each component from `@joralvmel/cosmos-elements/<name>`.
|
|
85
|
+
|
|
86
|
+
<!-- generated:end -->
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joralvmel/cosmos-elements",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Cosmos UI Web Components built with Lit: framework-agnostic, themeable and accessible.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"web-components",
|
|
7
|
+
"custom-elements",
|
|
8
|
+
"lit",
|
|
9
|
+
"design-system",
|
|
10
|
+
"cosmos-ui"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "joralvmel",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/joralvmel/cosmos-ui.git",
|
|
18
|
+
"directory": "packages/elements"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"./dist/components/**/*.js",
|
|
25
|
+
"./dist/index.js"
|
|
26
|
+
],
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"llms.md"
|
|
30
|
+
],
|
|
31
|
+
"customElements": "dist/custom-elements.json",
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./button": {
|
|
40
|
+
"types": "./dist/components/button/cosm-button.d.ts",
|
|
41
|
+
"default": "./dist/components/button/cosm-button.js"
|
|
42
|
+
},
|
|
43
|
+
"./custom-elements.json": "./dist/custom-elements.json",
|
|
44
|
+
"./llms.md": "./llms.md",
|
|
45
|
+
"./package.json": "./package.json"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.build.json && cem analyze",
|
|
49
|
+
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
|
|
50
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@joralvmel/cosmos-core": "^0.0.0",
|
|
56
|
+
"lit": "^3.3.3"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@custom-elements-manifest/analyzer": "^0.11.0"
|
|
60
|
+
}
|
|
61
|
+
}
|