@c2n/icon-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 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,3 @@
1
+ # Icon-Button
2
+
3
+ // TODO
@@ -0,0 +1,67 @@
1
+ import { LitElement, html, nothing, unsafeCSS } from "lit";
2
+ import { customElement, property } from "lit/decorators.js";
3
+ import { ifDefined } from "lit/directives/if-defined.js";
4
+ import "@c2n/tooltip";
5
+ //#region src/icon-button.scss?inline
6
+ var icon_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:host([disabled]) {\n pointer-events: none;\n opacity: var(--c2-icon-button__disabled--opacity,0.38);\n}\n\n.c2-icon-button {\n appearance: none;\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n border: var(--c2-icon-button--border,none);\n font: inherit;\n color: inherit;\n line-height: 0;\n position: relative;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n user-select: none;\n width: var(--c2-icon-button__state-layer--size,48px);\n height: var(--c2-icon-button__state-layer--size,48px);\n border-radius: var(--c2-icon-button--border-radius,999px);\n background-color: var(--c2-icon-button--background-color);\n will-change: background-color;\n transition: background-color 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.c2-icon-button:hover {\n background-color: var(--c2-icon-button__hover--background-color,rgb(230, 230, 230));\n}\n.c2-icon-button:hover ::slotted(*) {\n color: var(--c2-icon-button__icon__hover--color);\n}\n.c2-icon-button:focus-visible {\n outline: var(--c2-icon-button__focus--outline,2px solid rgba(2, 101, 220, 0.4));\n outline-offset: var(--c2-icon-button__focus--outline-offset,2px);\n}\n\n:host([selected]) .c2-icon-button {\n background-color: var(--c2-icon-button__selected--background-color,rgb(230, 230, 230));\n}\n:host([selected]) .c2-icon-button ::slotted(*) {\n color: var(--c2-icon-button__icon__selected--color,var(--c2-icon-button__icon--color));\n}\n\n::slotted(*) {\n width: var(--c2-icon-button__icon--width,24px);\n height: var(--c2-icon-button__icon--height,24px);\n color: var(--c2-icon-button__icon--color);\n transition: color 250ms cubic-bezier(0.2, 0, 0, 1);\n --c2-feather-icon--size: var(--c2-icon-button__icon--width,24px);\n --c2-mat-icon--font-size: var(--c2-icon-button__icon--width,24px);\n}";
7
+ //#endregion
8
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
9
+ function __decorate(decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ 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;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ }
15
+ //#endregion
16
+ //#region src/icon-button.ts
17
+ var IconButton = class IconButton extends LitElement {
18
+ constructor(..._args) {
19
+ super(..._args);
20
+ this.tooltip = void 0;
21
+ this.disabled = false;
22
+ this.ariaLabel = null;
23
+ this.selected = false;
24
+ this.toggle = false;
25
+ }
26
+ static {
27
+ this.styles = unsafeCSS(icon_button_default);
28
+ }
29
+ static {
30
+ this.shadowRootOptions = {
31
+ ...LitElement.shadowRootOptions,
32
+ delegatesFocus: true
33
+ };
34
+ }
35
+ render() {
36
+ return html`
37
+ <button
38
+ class="c2-icon-button"
39
+ part="button"
40
+ type="button"
41
+ ?disabled=${this.disabled}
42
+ aria-pressed=${this.selected ? "true" : this.toggle ? "false" : nothing}
43
+ aria-label=${ifDefined(this.ariaLabel ?? this.tooltip)}
44
+ >
45
+ <slot></slot>
46
+ ${this.tooltip ? html`<c2-tooltip delay="800">${this.tooltip}</c2-tooltip>` : nothing}
47
+ </button>
48
+ `;
49
+ }
50
+ };
51
+ __decorate([property()], IconButton.prototype, "tooltip", void 0);
52
+ __decorate([property({
53
+ type: Boolean,
54
+ reflect: true
55
+ })], IconButton.prototype, "disabled", void 0);
56
+ __decorate([property({ attribute: "aria-label" })], IconButton.prototype, "ariaLabel", void 0);
57
+ __decorate([property({
58
+ type: Boolean,
59
+ reflect: true
60
+ })], IconButton.prototype, "selected", void 0);
61
+ __decorate([property({
62
+ type: Boolean,
63
+ reflect: true
64
+ })], IconButton.prototype, "toggle", void 0);
65
+ IconButton = __decorate([customElement("c2-icon-button")], IconButton);
66
+ //#endregion
67
+ export { IconButton };
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@c2n/icon-button",
3
+ "version": "0.0.6",
4
+ "type": "module",
5
+ "main": "dist/icon-button.js",
6
+ "exports": {
7
+ ".": {
8
+ "default": "./dist/icon-button.js",
9
+ "types": "./types/src/icon-button.d.ts"
10
+ },
11
+ "./custom-elements.json": "./custom-elements.json"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "types"
16
+ ],
17
+ "keywords": [
18
+ "icon-button",
19
+ "web component",
20
+ "lit"
21
+ ],
22
+ "author": "code2nguyen@gmail.com",
23
+ "publishConfig": {
24
+ "registry": "https://registry.npmjs.org",
25
+ "access": "public"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/code2nguyen/web-components.git"
30
+ },
31
+ "scripts": {
32
+ "dev": "vite",
33
+ "build": "wireit",
34
+ "type-check": "wireit"
35
+ },
36
+ "wireit": {
37
+ "type-check": {
38
+ "dependencies": [
39
+ "../../core:build",
40
+ "../tooltip:build"
41
+ ],
42
+ "command": "tsc -p tsconfig.lib.json --composite false"
43
+ },
44
+ "build": {
45
+ "dependencies": [
46
+ "type-check"
47
+ ],
48
+ "command": "vite build"
49
+ }
50
+ },
51
+ "dependencies": {
52
+ "@c2n/core": "0.0.6",
53
+ "@c2n/tooltip": "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,56 @@
1
+ import { LitElement } from 'lit';
2
+ import '@c2n/tooltip';
3
+ /**
4
+ * A round, hoverable button that wraps a slotted icon. Renders a real `<button>` (focus is delegated to
5
+ * it) so it is keyboard operable; set `aria-label` on the host to name it.
6
+ *
7
+ * @tag c2-icon-button
8
+ *
9
+ * @slot - The icon (an inline `<svg>`, a `c2-feather-*` or a `c2-mat-icon` element).
10
+ *
11
+ * @cssproperty {color} --c2-icon-button--background-color
12
+ * @cssproperty {border-radius} [--c2-icon-button--border-radius=999px]
13
+ * @cssproperty {border} [--c2-icon-button--border=none]
14
+ *
15
+ * @cssproperty {color} [--c2-icon-button__hover--background-color=rgb(230, 230, 230)]
16
+ * @cssproperty {outline} [--c2-icon-button__focus--outline=2px solid rgba(2, 101, 220, 0.4)]
17
+ * @cssproperty {pixel} [--c2-icon-button__focus--outline-offset=2px]
18
+ * @cssproperty {opacity} [--c2-icon-button__disabled--opacity=0.38]
19
+ * @cssproperty {color} [--c2-icon-button__selected--background-color=rgb(230, 230, 230)] - Pressed state of a toggle button (see `selected`).
20
+ *
21
+ * @cssproperty {pixel} [--c2-icon-button__icon--width=24px]
22
+ * @cssproperty {pixel} [--c2-icon-button__icon--height=24px]
23
+ * @cssproperty {color} --c2-icon-button__icon--color
24
+ * @cssproperty {color} --c2-icon-button__icon__hover--color
25
+ * @cssproperty {color} --c2-icon-button__icon__selected--color
26
+ *
27
+ * @cssproperty {pixel} [--c2-icon-button__state-layer--size=48px]
28
+ */
29
+ export declare class IconButton extends LitElement {
30
+ static styles: import("lit").CSSResult;
31
+ static shadowRootOptions: {
32
+ delegatesFocus: boolean;
33
+ clonable?: boolean;
34
+ customElementRegistry?: CustomElementRegistry | null;
35
+ mode: ShadowRootMode;
36
+ serializable?: boolean;
37
+ slotAssignment?: SlotAssignmentMode;
38
+ };
39
+ /** Tooltip text shown after a short delay; also used as the accessible name when `aria-label` is not set. */
40
+ tooltip: string | undefined;
41
+ /** Disables the button: no pointer events, no focus, reduced opacity. */
42
+ disabled: boolean;
43
+ /** Accessible name forwarded to the inner `<button>`. */
44
+ ariaLabel: string | null;
45
+ /** Pressed state of a toggle button (`aria-pressed="true"`); styled with the `__selected--*` variables. */
46
+ selected: boolean;
47
+ /** Declares a toggle button: `aria-pressed` is announced as `false` while not selected. Set by `c2-button-group` in selection modes. */
48
+ toggle: boolean;
49
+ render(): import("lit-html").TemplateResult<1>;
50
+ }
51
+ declare global {
52
+ interface HTMLElementTagNameMap {
53
+ 'c2-icon-button': IconButton;
54
+ }
55
+ }
56
+ //# sourceMappingURL=icon-button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon-button.d.ts","sourceRoot":"","sources":["../../src/icon-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,MAAM,KAAK,CAAA;AAK1D,OAAO,cAAc,CAAA;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBACa,UAAW,SAAQ,UAAU;IACxC,OAAgB,MAAM,0BAAoB;IAE1C,OAAgB,iBAAiB;;;;;;;MAA4D;IAE7F,6GAA6G;IACjG,OAAO,EAAE,MAAM,GAAG,SAAS,CAAY;IAEnD,yEAAyE;IAC7B,QAAQ,UAAQ;IAE5D,yDAAyD;IACT,SAAS,EAAE,MAAM,GAAG,IAAI,CAAO;IAE/E,2GAA2G;IAC/D,QAAQ,UAAQ;IAE5D,wIAAwI;IAC5F,MAAM,UAAQ;IAEjD,MAAM;CAehB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,gBAAgB,EAAE,UAAU,CAAA;KAC7B;CACF"}