@c2n/button 0.0.6
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 +23 -0
- package/dist/button.js +72 -0
- package/package.json +61 -0
- package/types/src/button.d.ts +61 -0
- package/types/src/button.d.ts.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Nguyen Thai Vinh
|
|
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
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @c2n/button
|
|
2
|
+
|
|
3
|
+
`c2-button` is a themeable button with slots for the label text, a prefix icon, a suffix icon and a running (busy) icon.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @c2n/button
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script type="module">
|
|
11
|
+
import '@c2n/button'
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<c2-button>
|
|
15
|
+
<svg slot="prefix-icon" viewBox="0 0 24 24" ...></svg>
|
|
16
|
+
Save
|
|
17
|
+
</c2-button>
|
|
18
|
+
|
|
19
|
+
<c2-button running>Saving…</c2-button>
|
|
20
|
+
<c2-button disabled>Disabled</c2-button>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Every visual aspect is controlled through `--c2-button__*` CSS custom properties; see the generated `custom-elements.json` or the demo site for the full list.
|
package/dist/button.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { LitElement, html, nothing, unsafeCSS } from "lit";
|
|
2
|
+
import { customElement, property } from "lit/decorators.js";
|
|
3
|
+
//#region src/button.scss?inline
|
|
4
|
+
var button_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: inline-flex;\n}\n\n:host([hidden]) {\n display: none;\n}\n\n.c2-button {\n all: unset;\n box-sizing: border-box;\n display: inline-flex;\n flex: 1;\n align-items: center;\n justify-content: center;\n gap: var(--c2-button__container--gap,8px);\n height: var(--c2-button__container--height,36px);\n padding-left: var(--c2-button__container--padding-left,16px);\n padding-right: var(--c2-button__container--padding-right,16px);\n border: var(--c2-button__container--border,1px solid transparent);\n border-radius: var(--c2-button__container--border-radius,6px);\n background-color: var(--c2-button__container--background-color,rgb(2, 101, 220));\n color: var(--c2-button__container--color,#ffffff);\n font-family: inherit;\n font-size: var(--c2-button__container--font-size,14px);\n font-weight: var(--c2-button__container--font-weight,500);\n line-height: 1;\n white-space: nowrap;\n cursor: pointer;\n user-select: none;\n -webkit-tap-highlight-color: transparent;\n will-change: background-color, color, border-color;\n transition: background-color 250ms cubic-bezier(0.2, 0, 0, 1), color 250ms cubic-bezier(0.2, 0, 0, 1), border-color 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.c2-button:hover:not(:disabled) {\n background-color: var(--c2-button__container__hover--background-color,var(--c2-button__container--background-color,rgb(1, 84, 184)));\n color: var(--c2-button__container__hover--color,var(--c2-button__container--color,#ffffff));\n border: var(--c2-button__container__hover--border,var(--c2-button__container--border,1px solid transparent));\n}\n.c2-button:active:not(:disabled) {\n background-color: var(--c2-button__container__active--background-color,var(--c2-button__container__hover--background-color,var(--c2-button__container--background-color,rgb(1, 70, 154))));\n}\n.c2-button:focus-visible {\n outline: var(--c2-button__container__focus--outline,2px solid rgba(2, 101, 220, 0.4));\n outline-offset: var(--c2-button__container__focus--outline-offset,2px);\n}\n\n:host([selected]) .c2-button,\n:host([selected]) .c2-button:hover:not(:disabled) {\n background-color: var(--c2-button__container__selected--background-color,var(--c2-button__container__hover--background-color,var(--c2-button__container--background-color,rgb(1, 84, 184))));\n color: var(--c2-button__container__selected--color,var(--c2-button__container--color,#ffffff));\n border: var(--c2-button__container__selected--border,var(--c2-button__container--border,1px solid transparent));\n}\n\n:host([disabled]) .c2-button {\n cursor: default;\n opacity: var(--c2-button__container__disabled--opacity,0.38);\n}\n\n:host([running]) .c2-button {\n cursor: progress;\n}\n\n.label {\n display: inline-flex;\n align-items: center;\n}\n\n.icon::slotted(*) {\n flex-shrink: 0;\n width: var(--c2-button__icon--size,18px);\n height: var(--c2-button__icon--size,18px);\n color: var(--c2-button__icon--color,var(--c2-button__container--color,#ffffff));\n --c2-feather-icon--size: var(--c2-button__icon--size,18px);\n --c2-mat-icon--font-size: var(--c2-button__icon--size,18px);\n}\n\n.running-icon {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n width: var(--c2-button__running-icon--size,18px);\n height: var(--c2-button__running-icon--size,18px);\n color: var(--c2-button__running-icon--color,var(--c2-button__container--color,#ffffff));\n --c2-feather-icon--size: var(--c2-button__running-icon--size,18px);\n --c2-mat-icon--font-size: var(--c2-button__running-icon--size,18px);\n animation: c2-button-spin var(--c2-button__running-icon--animation-duration,800ms) linear infinite;\n}\n\n.running-icon ::slotted(*),\n.running-icon svg {\n width: 100%;\n height: 100%;\n}\n\n@keyframes c2-button-spin {\n to {\n transform: rotate(360deg);\n }\n}";
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
|
|
7
|
+
function __decorate(decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/button.ts
|
|
15
|
+
var Button = class Button extends LitElement {
|
|
16
|
+
constructor(..._args) {
|
|
17
|
+
super(..._args);
|
|
18
|
+
this.disabled = false;
|
|
19
|
+
this.running = false;
|
|
20
|
+
this.selected = false;
|
|
21
|
+
this.toggle = false;
|
|
22
|
+
}
|
|
23
|
+
static {
|
|
24
|
+
this.styles = unsafeCSS(button_default);
|
|
25
|
+
}
|
|
26
|
+
static {
|
|
27
|
+
this.shadowRootOptions = {
|
|
28
|
+
...LitElement.shadowRootOptions,
|
|
29
|
+
delegatesFocus: true
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
render() {
|
|
33
|
+
return html`
|
|
34
|
+
<button
|
|
35
|
+
class="c2-button"
|
|
36
|
+
part="button"
|
|
37
|
+
?disabled=${this.disabled || this.running}
|
|
38
|
+
aria-busy=${this.running ? "true" : nothing}
|
|
39
|
+
aria-pressed=${this.selected ? "true" : this.toggle ? "false" : nothing}
|
|
40
|
+
>
|
|
41
|
+
${this.running ? html`<span class="running-icon" part="running-icon">
|
|
42
|
+
<slot name="running-icon">
|
|
43
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" aria-hidden="true" focusable="false">
|
|
44
|
+
<path d="M21 12a9 9 0 1 1-6.22-8.56"></path>
|
|
45
|
+
</svg>
|
|
46
|
+
</slot>
|
|
47
|
+
</span>` : html`<slot name="prefix-icon" class="icon prefix-icon"></slot>`}
|
|
48
|
+
<span class="label"><slot></slot></span>
|
|
49
|
+
<slot name="suffix-icon" class="icon suffix-icon"></slot>
|
|
50
|
+
</button>
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
__decorate([property({
|
|
55
|
+
type: Boolean,
|
|
56
|
+
reflect: true
|
|
57
|
+
})], Button.prototype, "disabled", void 0);
|
|
58
|
+
__decorate([property({
|
|
59
|
+
type: Boolean,
|
|
60
|
+
reflect: true
|
|
61
|
+
})], Button.prototype, "running", void 0);
|
|
62
|
+
__decorate([property({
|
|
63
|
+
type: Boolean,
|
|
64
|
+
reflect: true
|
|
65
|
+
})], Button.prototype, "selected", void 0);
|
|
66
|
+
__decorate([property({
|
|
67
|
+
type: Boolean,
|
|
68
|
+
reflect: true
|
|
69
|
+
})], Button.prototype, "toggle", void 0);
|
|
70
|
+
Button = __decorate([customElement("c2-button")], Button);
|
|
71
|
+
//#endregion
|
|
72
|
+
export { Button };
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@c2n/button",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/button.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"default": "./dist/button.js",
|
|
9
|
+
"types": "./types/src/button.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./custom-elements.json": "./custom-elements.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"types"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"button",
|
|
19
|
+
"web component",
|
|
20
|
+
"lit"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "code2nguyen@gmail.com",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"registry": "https://registry.npmjs.org",
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/code2nguyen/web-components.git"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "vite",
|
|
34
|
+
"build": "wireit",
|
|
35
|
+
"build:only": "vite build",
|
|
36
|
+
"type-check": "wireit"
|
|
37
|
+
},
|
|
38
|
+
"wireit": {
|
|
39
|
+
"type-check": {
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"../../core:build"
|
|
42
|
+
],
|
|
43
|
+
"command": "tsc -p tsconfig.lib.json --composite false"
|
|
44
|
+
},
|
|
45
|
+
"build": {
|
|
46
|
+
"dependencies": [
|
|
47
|
+
"type-check"
|
|
48
|
+
],
|
|
49
|
+
"command": "vite build"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@c2n/core": "0.0.6",
|
|
54
|
+
"lit": "3.3.3"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@c2n/config": "*"
|
|
58
|
+
},
|
|
59
|
+
"customElements": "custom-elements.json",
|
|
60
|
+
"gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
|
|
61
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* @tag c2-button
|
|
4
|
+
*
|
|
5
|
+
* @slot default - Button label text.
|
|
6
|
+
* @slot prefix-icon - Icon shown before the label. Replaced by `running-icon` while the button is running.
|
|
7
|
+
* @slot suffix-icon - Icon shown after the label.
|
|
8
|
+
* @slot running-icon - Icon shown in place of the prefix icon while `running` is set. Defaults to a spinner; the slot wrapper rotates, so slotted content spins too.
|
|
9
|
+
*
|
|
10
|
+
* @cssproperty {pixel} [--c2-button__container--height=36px]
|
|
11
|
+
* @cssproperty {padding} [--c2-button__container--padding-left=16px]
|
|
12
|
+
* @cssproperty {padding} [--c2-button__container--padding-right=16px]
|
|
13
|
+
* @cssproperty {pixel} [--c2-button__container--gap=8px]
|
|
14
|
+
* @cssproperty {border-radius} [--c2-button__container--border-radius=6px]
|
|
15
|
+
* @cssproperty {border} [--c2-button__container--border=1px solid transparent]
|
|
16
|
+
* @cssproperty {color} [--c2-button__container--background-color=rgb(2, 101, 220)]
|
|
17
|
+
* @cssproperty {color} [--c2-button__container--color=#ffffff]
|
|
18
|
+
* @cssproperty {pixel} [--c2-button__container--font-size=14px]
|
|
19
|
+
* @cssproperty {font-weight} [--c2-button__container--font-weight=500]
|
|
20
|
+
*
|
|
21
|
+
* @cssproperty {color} [--c2-button__container__hover--background-color=rgb(1, 84, 184)]
|
|
22
|
+
* @cssproperty {color} --c2-button__container__hover--color
|
|
23
|
+
* @cssproperty {border} --c2-button__container__hover--border
|
|
24
|
+
*
|
|
25
|
+
* @cssproperty {color} [--c2-button__container__active--background-color=rgb(1, 70, 154)]
|
|
26
|
+
*
|
|
27
|
+
* @cssproperty {color} --c2-button__container__selected--background-color - Pressed state of a toggle button (see `selected`).
|
|
28
|
+
* @cssproperty {color} --c2-button__container__selected--color
|
|
29
|
+
* @cssproperty {border} --c2-button__container__selected--border
|
|
30
|
+
*
|
|
31
|
+
* @cssproperty {outline} [--c2-button__container__focus--outline=2px solid rgba(2, 101, 220, 0.4)]
|
|
32
|
+
* @cssproperty {pixel} [--c2-button__container__focus--outline-offset=2px]
|
|
33
|
+
*
|
|
34
|
+
* @cssproperty {opacity} [--c2-button__container__disabled--opacity=0.38]
|
|
35
|
+
*
|
|
36
|
+
* @cssproperty {pixel} [--c2-button__icon--size=18px]
|
|
37
|
+
* @cssproperty {color} --c2-button__icon--color
|
|
38
|
+
*
|
|
39
|
+
* @cssproperty {pixel} [--c2-button__running-icon--size=18px]
|
|
40
|
+
* @cssproperty {color} --c2-button__running-icon--color
|
|
41
|
+
* @cssproperty {duration} [--c2-button__running-icon--animation-duration=800ms]
|
|
42
|
+
*/
|
|
43
|
+
export declare class Button extends LitElement {
|
|
44
|
+
static styles: import("lit").CSSResult;
|
|
45
|
+
static shadowRootOptions: ShadowRootInit;
|
|
46
|
+
/** Disables the button: it no longer receives clicks and is rendered dimmed. */
|
|
47
|
+
disabled: boolean;
|
|
48
|
+
/** Marks the button as busy: clicks are ignored and the `running-icon` slot replaces the prefix icon. */
|
|
49
|
+
running: boolean;
|
|
50
|
+
/** Pressed state of a toggle button (`aria-pressed="true"`); styled with the `container__selected--*` variables. */
|
|
51
|
+
selected: boolean;
|
|
52
|
+
/** Declares a toggle button: `aria-pressed` is announced as `false` while not selected. Set by `c2-button-group` in selection modes. */
|
|
53
|
+
toggle: boolean;
|
|
54
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
55
|
+
}
|
|
56
|
+
declare global {
|
|
57
|
+
interface HTMLElementTagNameMap {
|
|
58
|
+
'c2-button': Button;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../src/button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,MAAM,KAAK,CAAA;AAI1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBACa,MAAO,SAAQ,UAAU;IACpC,OAAgB,MAAM,0BAAoB;IAE1C,OAAgB,iBAAiB,EAAE,cAAc,CAA4D;IAE7G,gFAAgF;IACpC,QAAQ,UAAQ;IAE5D,yGAAyG;IAC7D,OAAO,UAAQ;IAE3D,oHAAoH;IACxE,QAAQ,UAAQ;IAE5D,wIAAwI;IAC5F,MAAM,UAAQ;IAEjD,MAAM;CAyBhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,MAAM,CAAA;KACpB;CACF"}
|