@cas-smartdesign/button 5.4.0 → 7.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/dist/button.d.ts +13 -7
- package/dist/button.d.ts.map +1 -0
- package/dist/button.mjs +111 -188
- package/dist/button.mjs.map +1 -1
- package/dist/docs/created_from_source.js +1 -1
- package/dist/docs/doc.css +1 -1
- package/dist/docs/doc.mjs +404 -184
- package/dist/docs/index.html +1 -4
- package/dist/docs/new.svg +2 -5
- package/npm-third-party-licenses.json +61 -101
- package/package.json +22 -11
- package/readme.md +77 -3
- package/scss/_button.scss +85 -0
- package/scss/_config.scss +158 -0
- package/dist/button-with-externals.js +0 -108
- package/dist/button-with-externals.js.map +0 -7
- package/dist/docs/declarative_with_source.js +0 -1
- package/dist/docs/new_white.svg +0 -6
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
@use "sass:map";
|
|
2
|
+
|
|
3
|
+
// Single source of truth shared by the component's shadow styles (../styles.scss)
|
|
4
|
+
// and the public mixins (_button.scss). Keep selector-agnostic: declarations only,
|
|
5
|
+
// callers provide the selector (`:host(...)` for the component, `&` for consumers).
|
|
6
|
+
|
|
7
|
+
// Neutral (standard variant) colors per interactive state. These are the fallbacks
|
|
8
|
+
// the engine paints with when no variant overrides the corresponding --sd-button-*.
|
|
9
|
+
$neutral: (
|
|
10
|
+
"base": (
|
|
11
|
+
"bg": var(--color-bg-action-neutral-default, #d4d4d4),
|
|
12
|
+
"fg": var(--color-fg-action-neutral-default, #111111),
|
|
13
|
+
),
|
|
14
|
+
"hover": (
|
|
15
|
+
"bg": var(--color-bg-action-neutral-default-hover, #c6c6c6),
|
|
16
|
+
"fg": var(--color-fg-action-neutral-default-hover, #111111),
|
|
17
|
+
),
|
|
18
|
+
"pressed": (
|
|
19
|
+
"bg": var(--color-bg-action-neutral-default-pressed, #b3b3b3),
|
|
20
|
+
"fg": var(--color-fg-action-neutral-default-pressed, #111111),
|
|
21
|
+
),
|
|
22
|
+
"disabled": (
|
|
23
|
+
"bg": var(--color-bg-interaction-disabled, #e7e7e7),
|
|
24
|
+
"fg": var(--color-fg-interaction-disabled, #999999),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
// Custom variant rest colors: the consumer's --sd-button-* override, falling back
|
|
29
|
+
// to the neutral defaults the engine already paints. Used to derive coherent
|
|
30
|
+
// hover/pressed states so a minimal override (just rest bg + fg) is enough.
|
|
31
|
+
$_custom-bg: var(--sd-button-background-color, #{map.get(map.get($neutral, "base"), "bg")});
|
|
32
|
+
$_custom-fg: var(--sd-button-color, #{map.get(map.get($neutral, "base"), "fg")});
|
|
33
|
+
|
|
34
|
+
// Per-variant --sd-button-* values. Adding a variant is a single map entry.
|
|
35
|
+
$variants: (
|
|
36
|
+
"primary": (
|
|
37
|
+
"background-color": var(--color-bg-action-accent-default, #1467ba),
|
|
38
|
+
"color": var(--color-fg-interaction-on-color, #ffffff),
|
|
39
|
+
"background-color-hover": var(--color-bg-action-accent-default-hover, #0f4d8b),
|
|
40
|
+
"color-hover": var(--color-fg-interaction-on-color, #ffffff),
|
|
41
|
+
"background-color-pressed": var(--color-bg-action-accent-default-pressed, #0b3a69),
|
|
42
|
+
"color-pressed": var(--color-fg-interaction-on-color, #ffffff),
|
|
43
|
+
),
|
|
44
|
+
"outline": (
|
|
45
|
+
"background-color": var(--color-bg-action-accent-weak, #e0ebf6),
|
|
46
|
+
"color": var(--color-fg-action-accent-default, #1467ba),
|
|
47
|
+
"border": 1px solid var(--color-border-action-accent-default, #1467ba),
|
|
48
|
+
"background-color-hover": var(--color-bg-action-accent-weak-hover, #d5e4f3),
|
|
49
|
+
"color-hover": var(--color-fg-action-accent-default-hover, #0f4d8b),
|
|
50
|
+
"border-color-hover": var(--color-border-action-accent-default-hover, #0f4d8b),
|
|
51
|
+
"background-color-pressed": var(--color-bg-action-accent-weak-pressed, #c7dbef),
|
|
52
|
+
"color-pressed": var(--color-fg-action-accent-default-pressed, #0b3a69),
|
|
53
|
+
"border-color-pressed": var(--color-border-action-accent-default-pressed, #0b3a69),
|
|
54
|
+
"background-color-disabled": transparent,
|
|
55
|
+
"border-color-disabled": var(--color-border-interaction-disabled, #c6c6c6),
|
|
56
|
+
),
|
|
57
|
+
"ghost": (
|
|
58
|
+
"background-color": transparent,
|
|
59
|
+
"color": var(--color-fg-action-accent-default, #1467ba),
|
|
60
|
+
"background-color-hover": var(--color-bg-action-accent-weakest-hover, #e0ebf6),
|
|
61
|
+
"color-hover": var(--color-fg-action-accent-default-hover, #0f4d8b),
|
|
62
|
+
"background-color-pressed": var(--color-bg-action-accent-weakest-pressed, #c7dbef),
|
|
63
|
+
"color-pressed": var(--color-fg-action-accent-default-pressed, #0b3a69),
|
|
64
|
+
"background-color-disabled": transparent,
|
|
65
|
+
),
|
|
66
|
+
"outline-danger": (
|
|
67
|
+
"background-color": var(--color-bg-action-danger-default, #fbdde0),
|
|
68
|
+
"color": var(--color-fg-action-danger-default, #a90014),
|
|
69
|
+
"border": 1px solid var(--color-border-action-danger-default, #a90014),
|
|
70
|
+
"background-color-hover": var(--color-bg-action-danger-default-hover, #fad2d6),
|
|
71
|
+
"color-hover": var(--color-fg-action-danger-default-hover, #7f000f),
|
|
72
|
+
"border-color-hover": var(--color-border-action-danger-default-hover, #7f000f),
|
|
73
|
+
"background-color-pressed": var(--color-bg-action-danger-default-pressed, #f8c3c9),
|
|
74
|
+
"color-pressed": var(--color-fg-action-danger-default-pressed, #5f000b),
|
|
75
|
+
"border-color-pressed": var(--color-border-action-danger-default-pressed, #5f000b),
|
|
76
|
+
"background-color-disabled": transparent,
|
|
77
|
+
"border-color-disabled": var(--color-border-interaction-disabled, #c6c6c6),
|
|
78
|
+
),
|
|
79
|
+
"ghost-danger": (
|
|
80
|
+
"background-color": transparent,
|
|
81
|
+
"color": var(--color-fg-action-danger-default, #a90014),
|
|
82
|
+
"background-color-hover": var(--color-bg-action-danger-default-hover, #fad2d6),
|
|
83
|
+
"color-hover": var(--color-fg-action-danger-default-hover, #7f000f),
|
|
84
|
+
"background-color-pressed": var(--color-bg-action-danger-default-pressed, #f8c3c9),
|
|
85
|
+
"color-pressed": var(--color-fg-action-danger-default-pressed, #5f000b),
|
|
86
|
+
"background-color-disabled": transparent,
|
|
87
|
+
),
|
|
88
|
+
// Toggle/selection look (segmented controls, filter chips): neutral at rest,
|
|
89
|
+
// accent colors when selected. The selected appearance is applied via
|
|
90
|
+
// selection-checked-vars on [aria-pressed="true"].
|
|
91
|
+
"selection": (
|
|
92
|
+
"background-color": var(--color-bg-selection-neutral-weakest, #ffffff),
|
|
93
|
+
"color": var(--color-fg-selection-neutral-default, #111111),
|
|
94
|
+
"border": 1px solid var(--color-border-selection-neutral-default, #999999),
|
|
95
|
+
"background-color-hover": var(--color-bg-selection-accent-weak-hover, #e0ebf6),
|
|
96
|
+
"color-hover": var(--color-fg-selection-neutral-default, #111111),
|
|
97
|
+
"border-color-hover": var(--color-border-selection-neutral-default, #999999),
|
|
98
|
+
"background-color-pressed": var(--color-bg-selection-accent-weak, #c7dbef),
|
|
99
|
+
"color-pressed": var(--color-fg-selection-neutral-default, #111111),
|
|
100
|
+
"border-color-pressed": var(--color-border-selection-accent-default, #1467ba),
|
|
101
|
+
"border-color-disabled": var(--color-border-interaction-disabled, #c6c6c6),
|
|
102
|
+
),
|
|
103
|
+
// Sets no rest colors of its own — the consumer supplies --sd-button-background-color
|
|
104
|
+
// and --sd-button-color, and hover/pressed are derived from them automatically.
|
|
105
|
+
// Any state can still be pinned by overriding the matching --sd-button-* property.
|
|
106
|
+
"custom": (
|
|
107
|
+
"background-color-hover": color-mix(in oklab, $_custom-bg, var(--color-fg-default, #111111) 12%),
|
|
108
|
+
"color-hover": $_custom-fg,
|
|
109
|
+
"background-color-pressed": color-mix(in oklab, $_custom-bg, var(--color-fg-default, #111111) 22%),
|
|
110
|
+
"color-pressed": $_custom-fg,
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Paint one interactive state: reads the public --sd-button-* override with the
|
|
115
|
+
// neutral token as fallback. `$state` is one of the $neutral keys.
|
|
116
|
+
// $border-on-after: the web component draws its border on the :host::after
|
|
117
|
+
// overlay; consumer elements (mixin API) carry a real border, so the state
|
|
118
|
+
// color must land on the element itself there.
|
|
119
|
+
@mixin state($state, $border-on-after: true) {
|
|
120
|
+
$suffix: "";
|
|
121
|
+
@if $state != "base" {
|
|
122
|
+
$suffix: "-#{$state}";
|
|
123
|
+
}
|
|
124
|
+
$colors: map.get($neutral, $state);
|
|
125
|
+
background-color: var(--sd-button-background-color#{$suffix}, #{map.get($colors, "bg")});
|
|
126
|
+
color: var(--sd-button-color#{$suffix}, #{map.get($colors, "fg")});
|
|
127
|
+
@if $state != "base" {
|
|
128
|
+
$border-color: var(--sd-button-border-color#{$suffix}, transparent);
|
|
129
|
+
@if $border-on-after {
|
|
130
|
+
&::after {
|
|
131
|
+
border-color: $border-color;
|
|
132
|
+
}
|
|
133
|
+
} @else {
|
|
134
|
+
border-color: $border-color;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Selected appearance of the `selection` variant: re-points the same public
|
|
140
|
+
// --sd-button-* vars, pinning hover to the selected colors so the selected
|
|
141
|
+
// look survives the cursor. Pressed already matches the selected colors.
|
|
142
|
+
@mixin selection-checked-vars {
|
|
143
|
+
--sd-button-background-color: var(--color-bg-selection-accent-weak, #c7dbef);
|
|
144
|
+
--sd-button-border: 1px solid var(--color-border-selection-accent-default, #1467ba);
|
|
145
|
+
--sd-button-background-color-hover: var(--color-bg-selection-accent-weak, #c7dbef);
|
|
146
|
+
--sd-button-border-color-hover: var(--color-border-selection-accent-default, #1467ba);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Emit the --sd-button-* assignments for a named variant.
|
|
150
|
+
@mixin variant-vars($name) {
|
|
151
|
+
$props: map.get($variants, $name);
|
|
152
|
+
@if $props == null {
|
|
153
|
+
@error "Unknown button variant '#{$name}'. Known: #{map.keys($variants)}.";
|
|
154
|
+
}
|
|
155
|
+
@each $prop, $value in $props {
|
|
156
|
+
--sd-button-#{$prop}: #{$value};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
var window;(window||={})["@cas-smartdesign/button"]=(()=>{var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var m=(i,t)=>{for(var e in t)n(i,e,{get:t[e],enumerable:!0})},g=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of b(t))!p.call(i,a)&&a!==e&&n(i,a,{get:()=>t[a],enumerable:!(s=u(t,a))||s.enumerable});return i};var y=i=>g(n({},"__esModule",{value:!0}),i);var x={};m(x,{Button:()=>o});var d=class r extends HTMLElement{memoizedTemplate(){let t=this.is();if(r.TEMPLATE_CACHE[t])return r.TEMPLATE_CACHE[t];let e=this.template();return window.ShadyCSS&&window.ShadyCSS.prepareTemplate(e,this.is()),r.TEMPLATE_CACHE[t]=e,e}connectedCallback(){let t=this.memoizedTemplate();window.ShadyCSS&&window.ShadyCSS.styleElement(this),this.shadowRoot||(this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(document.importNode(t.content,!0)),requestAnimationFrame(()=>this.dispatchEvent(new CustomEvent("ready"))))}whenReady(t){this.shadowRoot?t():this.addEventListener("ready",()=>t())}};d.TEMPLATE_CACHE={};var c=d;var E=`<style>
|
|
2
|
-
:host {
|
|
3
|
-
contain: content;
|
|
4
|
-
background: rgba(20, 103, 186, 0);
|
|
5
|
-
color: #1467ba;
|
|
6
|
-
border: none;
|
|
7
|
-
outline: none;
|
|
8
|
-
padding: 0 8px;
|
|
9
|
-
height: 32px;
|
|
10
|
-
cursor: pointer;
|
|
11
|
-
user-select: none;
|
|
12
|
-
display: inline-flex;
|
|
13
|
-
align-items: center;
|
|
14
|
-
justify-content: center;
|
|
15
|
-
box-sizing: border-box;
|
|
16
|
-
vertical-align: middle;
|
|
17
|
-
border-radius: var(--sd-button-border-radius, 0px);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
:host(:focus),
|
|
21
|
-
:host(:not([disabled], [aria-disabled="true"]):hover) {
|
|
22
|
-
background: rgba(20, 103, 186, 0.1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@media (forced-colors: active) {
|
|
26
|
-
:host(:not([disabled], [aria-disabled="true"]):focus-visible) {
|
|
27
|
-
outline: 1px solid;
|
|
28
|
-
}
|
|
29
|
-
:host {
|
|
30
|
-
margin: 1px;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
:host(:not([disabled], [aria-disabled="true"]):focus-visible) {
|
|
35
|
-
box-shadow: 0 0 0 1px #1467ba inset;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
:host(:not([disabled], [aria-disabled="true"]):active) {
|
|
39
|
-
background: rgba(20, 103, 186, 0.2);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
:host([primary]) {
|
|
43
|
-
background: #1467ba;
|
|
44
|
-
color: #fff;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
:host([primary]:focus),
|
|
48
|
-
:host(:not([disabled], [aria-disabled="true"])[primary]:hover) {
|
|
49
|
-
background: #125da8;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
:host([primary]:focus-visible) {
|
|
53
|
-
box-shadow: 0 0 0 1px white inset;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
:host(:not([disabled], [aria-disabled="true"])[primary]:focus-visible) {
|
|
57
|
-
outline: 1px solid #1467ba;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
:host(:not([disabled], [aria-disabled="true"])[primary]:active) {
|
|
61
|
-
background: #0e4883;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
:host([disabled]),
|
|
65
|
-
:host([aria-disabled="true"]) {
|
|
66
|
-
filter: grayscale(100%);
|
|
67
|
-
opacity: 0.5;
|
|
68
|
-
cursor: default;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
:host([disabled]:focus-visible),
|
|
72
|
-
:host([aria-disabled="true"]:focus-visible) {
|
|
73
|
-
outline: 1px dashed #111;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
.icon:not([src]),
|
|
77
|
-
.icon[src=""],
|
|
78
|
-
.icon[src="data:,"] {
|
|
79
|
-
display: none;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.content {
|
|
83
|
-
display: flex;
|
|
84
|
-
align-items: center;
|
|
85
|
-
min-width: 0px;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.content ::slotted(*) {
|
|
89
|
-
margin-left: var(--sd-button-content-padding, 8px);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.content ::slotted(*:last-child) {
|
|
93
|
-
margin-right: var(--sd-button-content-padding, 8px);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.icon {
|
|
97
|
-
max-height: var(--sd-button-max-icon-size, 32px);
|
|
98
|
-
max-width: var(--sd-button-max-icon-size, 32px);
|
|
99
|
-
}
|
|
100
|
-
</style>
|
|
101
|
-
<slot name="icon">
|
|
102
|
-
<img class="icon" src="data:," alt part="icon" />
|
|
103
|
-
</slot>
|
|
104
|
-
<div class="content">
|
|
105
|
-
<slot></slot>
|
|
106
|
-
</div>
|
|
107
|
-
`,l=class h extends c{constructor(){super(),this._isSpaceOrEnterKeyDown=!1,this.addEventListener("keydown",t=>{this.isSpaceOrEnter(t)&&(this._isSpaceOrEnterKeyDown=!0,t.preventDefault())}),this.addEventListener("keyup",t=>{this.isSpaceOrEnter(t)&&this._isSpaceOrEnterKeyDown==!0&&(this._isSpaceOrEnterKeyDown=!1,this.click())}),this.addEventListener("click",t=>{if(this.disabled||this.hasAttribute("disabled")){t.stopImmediatePropagation();return}let e=this.getAttribute("type")?.toLowerCase()?.trim();if(e!=="submit"&&e!=="reset")return;let s=this.closest("form");s&&e==="submit"&&s.requestSubmit(),s&&e==="reset"&&s.reset()},{capture:!0})}get imageElement(){return this._image}get icon(){return this.getAttribute("icon")}set icon(t){this.icon!==t&&(t?this.setAttribute("icon",t):this.removeAttribute("icon"),this.updateIcon())}get primary(){return this.hasAttribute("primary")}set primary(t){t?this.setAttribute("primary",""):this.removeAttribute("primary")}get disabled(){return this.getAttribute("aria-disabled")=="true"}set disabled(t){this.setAttribute("aria-disabled",t.toString())}static get observedAttributes(){return["icon"]}is(){return h.ID}template(){let t=document.createElement("template");return t.innerHTML=E,t}isSpaceOrEnter(t){switch(t.key){case" ":case"Space":case"Enter":return!0;default:return!1}}click(){!this.disabled&&!this.hasAttribute("disabled")&&super.click()}connectedCallback(){super.connectedCallback(),this.hasAttribute("tabIndex")||(this.tabIndex=0),this._image=this.shadowRoot.querySelector(".icon"),this.updateIcon(),this.hasAttribute("role")||this.setAttribute("role","button")}attributeChangedCallback(){this.updateIcon()}updateIcon(){if(this._image){let t=this.getAttribute("icon");t&&(this._image.src=t)}}};l.ID="sd-button";var o=l;customElements.get(o.ID)||customElements.define(o.ID,o);return y(x);})();
|
|
108
|
-
//# sourceMappingURL=button-with-externals.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../element-base/element-base.ts", "../button.html", "../button.ts"],
|
|
4
|
-
"sourcesContent": ["export type IReadyEvent = void;\n\nexport interface CustomEventMap extends HTMLElementEventMap {\n ready: CustomEvent<IReadyEvent>;\n}\n\nexport interface ElementBase {\n addEventListener<K extends keyof CustomEventMap>(\n event: K,\n listener: ((this: this, ev: CustomEventMap[K]) => unknown) | null,\n options?: AddEventListenerOptions | boolean,\n ): void;\n addEventListener(\n type: string,\n callback: EventListenerOrEventListenerObject | null,\n options?: AddEventListenerOptions | boolean,\n ): void;\n removeEventListener<K extends keyof CustomEventMap>(\n type: K,\n listener: (this: this, ev: CustomEventMap[K]) => unknown,\n options?: boolean | EventListenerOptions,\n ): void;\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions,\n ): void;\n dispatchEvent<EventType extends CustomEventMap[keyof CustomEventMap]>(event: EventType): boolean;\n}\n\nexport abstract class ElementBase extends HTMLElement {\n public abstract is(): string;\n\n protected abstract template(): HTMLTemplateElement;\n private static readonly TEMPLATE_CACHE: {\n [name: string]: HTMLTemplateElement;\n } = {};\n private memoizedTemplate(): HTMLTemplateElement {\n const is = this.is();\n if (ElementBase.TEMPLATE_CACHE[is]) {\n return ElementBase.TEMPLATE_CACHE[is];\n }\n const template = this.template();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((window as any).ShadyCSS) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (window as any).ShadyCSS.prepareTemplate(template, this.is());\n }\n ElementBase.TEMPLATE_CACHE[is] = template;\n return template;\n }\n\n public connectedCallback() {\n const template = this.memoizedTemplate();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((window as any).ShadyCSS) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (window as any).ShadyCSS.styleElement(this);\n }\n if (!this.shadowRoot) {\n this.attachShadow({ mode: \"open\" });\n this.shadowRoot.appendChild(document.importNode(template.content, true));\n requestAnimationFrame(() => this.dispatchEvent(new CustomEvent<IReadyEvent>(\"ready\")));\n }\n }\n\n public whenReady(actor: () => void) {\n if (this.shadowRoot) {\n actor();\n } else {\n this.addEventListener(\"ready\", () => actor());\n }\n }\n}\n", "export default \"<style>\\n\\t:host {\\n\\t\\tcontain: content;\\n\\t\\tbackground: rgba(20, 103, 186, 0);\\n\\t\\tcolor: #1467ba;\\n\\t\\tborder: none;\\n\\t\\toutline: none;\\n\\t\\tpadding: 0 8px;\\n\\t\\theight: 32px;\\n\\t\\tcursor: pointer;\\n\\t\\tuser-select: none;\\n\\t\\tdisplay: inline-flex;\\n\\t\\talign-items: center;\\n\\t\\tjustify-content: center;\\n\\t\\tbox-sizing: border-box;\\n\\t\\tvertical-align: middle;\\n\\t\\tborder-radius: var(--sd-button-border-radius, 0px);\\n\\t}\\n\\n\\t:host(:focus),\\n\\t:host(:not([disabled], [aria-disabled=\\\"true\\\"]):hover) {\\n\\t\\tbackground: rgba(20, 103, 186, 0.1);\\n\\t}\\n\\n\\t@media (forced-colors: active) {\\n\\t\\t:host(:not([disabled], [aria-disabled=\\\"true\\\"]):focus-visible) {\\n\\t\\t\\toutline: 1px solid;\\n\\t\\t}\\n\\t\\t:host {\\n\\t\\t\\tmargin: 1px;\\n\\t\\t}\\n\\t}\\n\\n\\t:host(:not([disabled], [aria-disabled=\\\"true\\\"]):focus-visible) {\\n\\t\\tbox-shadow: 0 0 0 1px #1467ba inset;\\n\\t}\\n\\n\\t:host(:not([disabled], [aria-disabled=\\\"true\\\"]):active) {\\n\\t\\tbackground: rgba(20, 103, 186, 0.2);\\n\\t}\\n\\n\\t:host([primary]) {\\n\\t\\tbackground: #1467ba;\\n\\t\\tcolor: #fff;\\n\\t}\\n\\n\\t:host([primary]:focus),\\n\\t:host(:not([disabled], [aria-disabled=\\\"true\\\"])[primary]:hover) {\\n\\t\\tbackground: #125da8;\\n\\t}\\n\\n\\t:host([primary]:focus-visible) {\\n\\t\\tbox-shadow: 0 0 0 1px white inset;\\n\\t}\\n\\n\\t:host(:not([disabled], [aria-disabled=\\\"true\\\"])[primary]:focus-visible) {\\n\\t\\toutline: 1px solid #1467ba;\\n\\t}\\n\\n\\t:host(:not([disabled], [aria-disabled=\\\"true\\\"])[primary]:active) {\\n\\t\\tbackground: #0e4883;\\n\\t}\\n\\n\\t:host([disabled]),\\n\\t:host([aria-disabled=\\\"true\\\"]) {\\n\\t\\tfilter: grayscale(100%);\\n\\t\\topacity: 0.5;\\n\\t\\tcursor: default;\\n\\t}\\n\\n\\t:host([disabled]:focus-visible),\\n\\t:host([aria-disabled=\\\"true\\\"]:focus-visible) {\\n\\t\\toutline: 1px dashed #111;\\n\\t}\\n\\n\\t.icon:not([src]),\\n\\t.icon[src=\\\"\\\"],\\n\\t.icon[src=\\\"data:,\\\"] {\\n\\t\\tdisplay: none;\\n\\t}\\n\\n\\t.content {\\n\\t\\tdisplay: flex;\\n\\t\\talign-items: center;\\n\\t\\tmin-width: 0px;\\n\\t}\\n\\n\\t.content ::slotted(*) {\\n\\t\\tmargin-left: var(--sd-button-content-padding, 8px);\\n\\t}\\n\\n\\t.content ::slotted(*:last-child) {\\n\\t\\tmargin-right: var(--sd-button-content-padding, 8px);\\n\\t}\\n\\n\\t.icon {\\n\\t\\tmax-height: var(--sd-button-max-icon-size, 32px);\\n\\t\\tmax-width: var(--sd-button-max-icon-size, 32px);\\n\\t}\\n</style>\\n<slot name=\\\"icon\\\">\\n\\t<img class=\\\"icon\\\" src=\\\"data:,\\\" alt part=\\\"icon\\\" />\\n</slot>\\n<div class=\\\"content\\\">\\n\\t<slot></slot>\\n</div>\\n\"", "import { ElementBase } from \"@cas-smartdesign/element-base\";\n\nimport { default as htmlTemplate } from \"./button.html?raw\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n [Button.ID]: Button;\n }\n}\n\nexport class Button extends ElementBase {\n public static readonly ID = \"sd-button\";\n private _image: HTMLImageElement;\n private _isSpaceOrEnterKeyDown = false;\n\n public get imageElement() {\n return this._image;\n }\n\n public get icon(): string {\n return this.getAttribute(\"icon\");\n }\n\n public set icon(icon: string) {\n if (this.icon !== icon) {\n if (icon) {\n this.setAttribute(\"icon\", icon);\n } else {\n this.removeAttribute(\"icon\");\n }\n this.updateIcon();\n }\n }\n\n public get primary(): boolean {\n return this.hasAttribute(\"primary\");\n }\n\n public set primary(primary: boolean) {\n if (primary) {\n this.setAttribute(\"primary\", \"\");\n } else {\n this.removeAttribute(\"primary\");\n }\n }\n\n public get disabled(): boolean {\n return this.getAttribute(\"aria-disabled\") == \"true\";\n }\n\n public set disabled(disabled: boolean) {\n this.setAttribute(\"aria-disabled\", disabled.toString());\n }\n\n static get observedAttributes() {\n return [\"icon\"];\n }\n\n public is(): string {\n return Button.ID;\n }\n\n protected template(): HTMLTemplateElement {\n const template = document.createElement(\"template\");\n template.innerHTML = htmlTemplate;\n return template;\n }\n\n constructor() {\n super();\n this.addEventListener(\"keydown\", (e) => {\n if (this.isSpaceOrEnter(e)) {\n this._isSpaceOrEnterKeyDown = true;\n e.preventDefault(); // prevent potential scroll-down triggered by space\n }\n });\n this.addEventListener(\"keyup\", (e) => {\n if (this.isSpaceOrEnter(e) && this._isSpaceOrEnterKeyDown == true) {\n this._isSpaceOrEnterKeyDown = false;\n this.click();\n }\n });\n // As Button is not an input element, click is fired even in disabled state\n this.addEventListener(\n \"click\",\n (event) => {\n if (this.disabled || this.hasAttribute(\"disabled\")) {\n event.stopImmediatePropagation();\n return;\n }\n\n const type = this.getAttribute(\"type\")?.toLowerCase()?.trim();\n\n if (type !== \"submit\" && type !== \"reset\") {\n return;\n }\n\n const form = this.closest(\"form\");\n\n if (form && type === \"submit\") {\n form.requestSubmit();\n }\n\n if (form && type === \"reset\") {\n form.reset();\n }\n },\n { capture: true },\n );\n }\n\n private isSpaceOrEnter(event: KeyboardEvent): boolean {\n switch (event.key) {\n case \" \":\n case \"Space\":\n case \"Enter\":\n return true;\n default:\n return false;\n }\n }\n\n public click() {\n if (!this.disabled && !this.hasAttribute(\"disabled\")) {\n super.click();\n }\n }\n\n public connectedCallback() {\n super.connectedCallback();\n\n if (!this.hasAttribute(\"tabIndex\")) {\n this.tabIndex = 0;\n }\n\n this._image = this.shadowRoot.querySelector(\".icon\") as HTMLImageElement;\n\n this.updateIcon();\n if (!this.hasAttribute(\"role\")) {\n this.setAttribute(\"role\", \"button\");\n }\n }\n\n public attributeChangedCallback(): void {\n this.updateIcon();\n }\n\n private updateIcon() {\n if (this._image) {\n const iconSrc = this.getAttribute(\"icon\");\n if (iconSrc) {\n this._image.src = iconSrc;\n }\n }\n }\n}\n\nif (!customElements.get(Button.ID)) {\n customElements.define(Button.ID, Button);\n}\n"],
|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C,KAAK,aAAa,UAAU,GAC/C,MAAM,MAAA,CAEd,CAEO,mBAAoB,CACvB,MAAM,kBAAA,EAED,KAAK,aAAa,UAAU,IAC7B,KAAK,SAAW,GAGpB,KAAK,OAAS,KAAK,WAAW,cAAc,OAAO,EAEnD,KAAK,WAAA,EACA,KAAK,aAAa,MAAM,GACzB,KAAK,aAAa,OAAQ,QAAQ,CAE1C,CAEO,0BAAiC,CACpC,KAAK,WAAA,CACT,CAEQ,YAAa,CACjB,GAAI,KAAK,OAAQ,CACb,IAAMO,EAAU,KAAK,aAAa,MAAM,EACpCA,IACA,KAAK,OAAO,IAAMA,EAE1B,CACJ,CACJ,EAhJIV,EAAuB,GAAK,YADzB,IAAMW,EAANX,EAmJF,eAAe,IAAIW,EAAO,EAAE,GAC7B,eAAe,OAAOA,EAAO,GAAIA,CAAM",
|
|
6
|
-
"names": ["_ElementBase", "is", "template", "actor", "ElementBase", "htmlTemplate", "_Button", "ElementBase", "e", "event", "type", "form", "icon", "primary", "disabled", "template", "iconSrc", "Button"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./doc.mjs";document.querySelector("#declarative-with-code").addEventListener("click",e=>{e.currentTarget.innerText+="!",console.log("Test!")});
|
package/dist/docs/new_white.svg
DELETED