@substrate-system/button 0.0.17 → 0.0.19

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/html.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type Attrs = {
2
+ type: string | null;
3
+ autofocus: boolean;
4
+ tabindex: string | number;
5
+ disabled: boolean;
6
+ classes: string[] | Set<string>;
7
+ };
8
+ export declare function html(attrs: Partial<Attrs>, textContent: string): string;
9
+ //# sourceMappingURL=html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IAChB,IAAI,EAAC,MAAM,GAAC,IAAI,CAAC;IACjB,SAAS,EAAC,OAAO,CAAC;IAClB,QAAQ,EAAC,MAAM,GAAC,MAAM,CAAC;IACvB,QAAQ,EAAC,OAAO,CAAC;IACjB,OAAO,EAAC,MAAM,EAAE,GAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAChC,CAAA;AACD,wBAAgB,IAAI,CAAE,KAAK,EAAC,OAAO,CAAC,KAAK,CAAC,EAAE,WAAW,EAAC,MAAM,UAyB7D"}
package/dist/html.js ADDED
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function html(attrs, textContent) {
4
+ const {
5
+ type,
6
+ autofocus,
7
+ tabindex,
8
+ disabled,
9
+ classes
10
+ } = attrs;
11
+ const _classes = new Set(classes);
12
+ _classes.add("substrate-button");
13
+ const arr = Array.from(_classes);
14
+ const btnProps = [
15
+ arr.length ? `class="${arr.filter(Boolean).join(" ")}"` : "",
16
+ disabled ? "disabled" : "",
17
+ autofocus ? "autofocus" : "",
18
+ type ? `type="${type}"` : "",
19
+ tabindex ? `tabindex="${tabindex}"` : 'tabindex="0"',
20
+ 'role="button"'
21
+ ].filter(Boolean).join(" ");
22
+ return `<button ${btnProps}>
23
+ ${textContent}
24
+ </button>`;
25
+ }
26
+ __name(html, "html");
27
+ export {
28
+ html
29
+ };
30
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/html.ts"],
4
+ "sourcesContent": ["export type Attrs = {\n type:string|null;\n autofocus:boolean;\n tabindex:string|number;\n disabled:boolean;\n classes:string[]|Set<string>;\n}\nexport function html (attrs:Partial<Attrs>, textContent:string) {\n const {\n type,\n autofocus,\n tabindex,\n disabled,\n classes\n } = attrs\n\n const _classes = new Set(classes)\n _classes.add('substrate-button')\n const arr = Array.from(_classes)\n\n const btnProps = ([\n arr.length ? `class=\"${arr.filter(Boolean).join(' ')}\"` : '',\n disabled ? 'disabled' : '',\n autofocus ? 'autofocus' : '',\n type ? `type=\"${type}\"` : '',\n tabindex ? `tabindex=\"${tabindex}\"` : 'tabindex=\"0\"',\n 'role=\"button\"'\n ]).filter(Boolean).join(' ')\n\n return `<button ${btnProps}>\n ${textContent}\n </button>`\n}\n"],
5
+ "mappings": ";;AAOO,SAAS,KAAM,OAAsB,aAAoB;AAC5D,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI;AAEJ,QAAM,WAAW,IAAI,IAAI,OAAO;AAChC,WAAS,IAAI,kBAAkB;AAC/B,QAAM,MAAM,MAAM,KAAK,QAAQ;AAE/B,QAAM,WAAY;AAAA,IACd,IAAI,SAAS,UAAU,IAAI,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC,MAAM;AAAA,IAC1D,WAAW,aAAa;AAAA,IACxB,YAAY,cAAc;AAAA,IAC1B,OAAO,SAAS,IAAI,MAAM;AAAA,IAC1B,WAAW,aAAa,QAAQ,MAAM;AAAA,IACtC;AAAA,EACJ,EAAG,OAAO,OAAO,EAAE,KAAK,GAAG;AAE3B,SAAO,WAAW,QAAQ;AAAA,UACpB,WAAW;AAAA;AAErB;AAzBgB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,4 @@
1
+ var u=Object.defineProperty;var r=(t,n)=>u(t,"name",{value:n,configurable:!0});function p(t,n){let{type:s,autofocus:l,tabindex:o,disabled:i,classes:b}=t,e=new Set(b);e.add("substrate-button");let a=Array.from(e);return`<button ${[a.length?`class="${a.filter(Boolean).join(" ")}"`:"",i?"disabled":"",l?"autofocus":"",s?`type="${s}"`:"",o?`tabindex="${o}"`:'tabindex="0"','role="button"'].filter(Boolean).join(" ")}>
2
+ ${n}
3
+ </button>`}r(p,"html");export{p as html};
4
+ //# sourceMappingURL=html.min.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/html.ts"],
4
+ "sourcesContent": ["export type Attrs = {\n type:string|null;\n autofocus:boolean;\n tabindex:string|number;\n disabled:boolean;\n classes:string[]|Set<string>;\n}\nexport function html (attrs:Partial<Attrs>, textContent:string) {\n const {\n type,\n autofocus,\n tabindex,\n disabled,\n classes\n } = attrs\n\n const _classes = new Set(classes)\n _classes.add('substrate-button')\n const arr = Array.from(_classes)\n\n const btnProps = ([\n arr.length ? `class=\"${arr.filter(Boolean).join(' ')}\"` : '',\n disabled ? 'disabled' : '',\n autofocus ? 'autofocus' : '',\n type ? `type=\"${type}\"` : '',\n tabindex ? `tabindex=\"${tabindex}\"` : 'tabindex=\"0\"',\n 'role=\"button\"'\n ]).filter(Boolean).join(' ')\n\n return `<button ${btnProps}>\n ${textContent}\n </button>`\n}\n"],
5
+ "mappings": "+EAOO,SAASA,EAAMC,EAAsBC,EAAoB,CAC5D,GAAM,CACF,KAAAC,EACA,UAAAC,EACA,SAAAC,EACA,SAAAC,EACA,QAAAC,CACJ,EAAIN,EAEEO,EAAW,IAAI,IAAID,CAAO,EAChCC,EAAS,IAAI,kBAAkB,EAC/B,IAAMC,EAAM,MAAM,KAAKD,CAAQ,EAW/B,MAAO,WATW,CACdC,EAAI,OAAS,UAAUA,EAAI,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC,IAAM,GAC1DH,EAAW,WAAa,GACxBF,EAAY,YAAc,GAC1BD,EAAO,SAASA,CAAI,IAAM,GAC1BE,EAAW,aAAaA,CAAQ,IAAM,eACtC,eACJ,EAAG,OAAO,OAAO,EAAE,KAAK,GAAG,CAED;AAAA,UACpBH,CAAW;AAAA,cAErB,CAzBgBQ,EAAAV,EAAA",
6
+ "names": ["html", "attrs", "textContent", "type", "autofocus", "tabindex", "disabled", "classes", "_classes", "arr", "__name"]
7
+ }
package/dist/index.cjs CHANGED
@@ -22,141 +22,22 @@ __export(index_exports, {
22
22
  SubstrateButton: () => SubstrateButton
23
23
  });
24
24
  module.exports = __toCommonJS(index_exports);
25
- class SubstrateButton extends HTMLElement {
25
+ var import_html = require("./html.js");
26
+ var import_client = require("./client.js");
27
+ class SubstrateButton extends import_client.SubstrateButton {
26
28
  static {
27
29
  __name(this, "SubstrateButton");
28
30
  }
29
- // for `attributeChangedCallback`
30
- static observedAttributes = ["autofocus", "disabled", "spinning"];
31
- static tag = "substrate-button";
32
- _isSpinning;
33
- constructor() {
34
- super();
35
- const disabled = this.getAttribute("disabled");
36
- if (disabled !== null) {
37
- setTimeout(() => {
38
- this.disabled = true;
39
- }, 0);
40
- }
41
- this.autofocus = this.getAttribute("autofocus") !== null;
42
- this._isSpinning = this.getAttribute("spinning") !== null;
43
- }
44
- get form() {
45
- return this.button?.form;
46
- }
47
- get disabled() {
48
- return !!this.button?.hasAttribute("disabled");
49
- }
50
- set disabled(disabledValue) {
51
- if (!disabledValue) {
52
- this._removeAttribute("disabled");
53
- this.button?.setAttribute("aria-disabled", "false");
54
- } else {
55
- this.button?.setAttribute("disabled", "");
56
- this.button?.setAttribute("aria-disabled", "true");
57
- }
58
- }
59
- get type() {
60
- return this.button?.getAttribute("type");
61
- }
62
- get tabindex() {
63
- const i = this.button?.getAttribute("tabindex");
64
- if (!i) return 0;
65
- return parseInt(i);
66
- }
67
- get spinning() {
68
- return this._isSpinning;
69
- }
70
- set spinning(value) {
71
- if (value) this.setAttribute("spinning", "");
72
- else this.removeAttribute("spinning");
73
- }
74
- set type(value) {
75
- this._setAttribute("type", value);
76
- }
77
- get autofocus() {
78
- return !!this.button?.hasAttribute("autofocus");
79
- }
80
- set autofocus(value) {
81
- if (value) {
82
- this._setAttribute("autofocus", value);
83
- } else {
84
- this._removeAttribute("autofocus");
85
- }
86
- }
87
- /**
88
- * Set attributes on the internal button element.
89
- */
90
- _setAttribute(name, value) {
91
- if (value === false) {
92
- this._removeAttribute(name);
93
- this.button?.removeAttribute(name);
94
- } else {
95
- if (value === true) {
96
- return this.button?.setAttribute(name, "");
97
- }
98
- if (value === null) {
99
- return this._removeAttribute(name);
100
- }
101
- this.button?.setAttribute(name, value);
102
- }
103
- }
104
- /**
105
- * Remove from `this` and also button child.
106
- */
107
- _removeAttribute(name) {
108
- this.removeAttribute(name);
109
- this.button?.removeAttribute(name);
110
- }
111
- get button() {
112
- return this.querySelector("button");
113
- }
114
- /**
115
- * Handle 'autofocus' attribute changes
116
- * @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}
117
- *
118
- * @param {string} oldValue The old attribute value
119
- * @param {string} newValue The new attribute value
120
- */
121
- handleChange_autofocus(_oldValue, newValue) {
122
- this._setAttribute("autofocus", newValue);
123
- }
124
- handleChange_disabled(_old, newValue) {
125
- this.disabled = newValue !== null;
126
- if (newValue === null) this.button?.removeAttribute("disabled");
127
- else this.button?.setAttribute("disabled", "" + newValue);
128
- }
129
- handleChange_spinning(_, newValue) {
130
- if (newValue !== null) {
131
- this.classList.add("substrate-loading");
132
- } else {
133
- this.classList.remove("substrate-loading");
134
- }
135
- }
136
- /**
137
- * Runs when the value of an attribute is changed.
138
- *
139
- * Should add methods to this class like `handleChange_class`, to
140
- * listen for changes to `class` attribute.
141
- *
142
- * @param {string} name The attribute name
143
- * @param {string} oldValue The old attribute value
144
- * @param {string} newValue The new attribute value
145
- */
146
- attributeChangedCallback(name, oldValue, newValue) {
147
- const handler = this[`handleChange_${name}`];
148
- handler && handler.call(this, oldValue, newValue);
149
- }
150
- connectedCallback() {
151
- this.render();
152
- }
153
31
  static define() {
154
32
  if (!("customElements" in window)) return;
155
33
  return customElements.define(
156
- SubstrateButton.tag || "substrate-button",
34
+ SubstrateButton.TAG || "substrate-button",
157
35
  SubstrateButton
158
36
  );
159
37
  }
38
+ connectedCallback() {
39
+ this.render();
40
+ }
160
41
  render() {
161
42
  const {
162
43
  type,
@@ -164,16 +45,19 @@ class SubstrateButton extends HTMLElement {
164
45
  tabindex,
165
46
  disabled
166
47
  } = this;
167
- const classes = ["substrate-button"];
168
- const btnProps = [
169
- `class="${classes.join(" ")}"`,
170
- disabled ? "disabled" : "",
171
- autofocus ? "autofocus" : "",
172
- type ? `type="${this.type}"` : "",
173
- tabindex ? `tabindex="${tabindex}"` : 'tabindex="0"',
174
- 'role="button"'
175
- ].filter(Boolean).join(" ");
176
- this.innerHTML = `<button ${btnProps}>${this.innerHTML}</button>`;
48
+ const classes = [
49
+ "substrate-button",
50
+ this.getAttribute("class")
51
+ ];
52
+ const text = this.innerHTML;
53
+ const btnProps = {
54
+ classes: classes.filter(Boolean),
55
+ disabled,
56
+ autofocus,
57
+ tabindex,
58
+ type
59
+ };
60
+ this.innerHTML = (0, import_html.html)(btnProps, text);
177
61
  }
178
62
  }
179
63
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'substrate-button': SubstrateButton\n }\n}\n\nexport class SubstrateButton extends HTMLElement {\n // for `attributeChangedCallback`\n static observedAttributes = ['autofocus', 'disabled', 'spinning']\n static tag = 'substrate-button'\n _isSpinning:boolean\n\n constructor () {\n super()\n const disabled = this.getAttribute('disabled')\n if (disabled !== null) {\n setTimeout(() => {\n // need to wait for it to render\n this.disabled = true\n }, 0)\n }\n this.autofocus = (this.getAttribute('autofocus') !== null)\n this._isSpinning = (this.getAttribute('spinning') !== null)\n }\n\n get form ():HTMLFormElement|undefined|null {\n return this.button?.form\n }\n\n get disabled ():boolean {\n return !!(this.button?.hasAttribute('disabled'))\n }\n\n set disabled (disabledValue:boolean) {\n if (!disabledValue) {\n this._removeAttribute('disabled')\n this.button?.setAttribute('aria-disabled', 'false')\n } else {\n this.button?.setAttribute('disabled', '')\n this.button?.setAttribute('aria-disabled', 'true')\n }\n }\n\n get type ():string|null|undefined {\n return this.button?.getAttribute('type')\n }\n\n get tabindex ():number {\n const i = this.button?.getAttribute('tabindex')\n if (!i) return 0\n return parseInt(i)\n }\n\n get spinning ():boolean {\n return this._isSpinning\n }\n\n set spinning (value:boolean) {\n if (value) this.setAttribute('spinning', '')\n else this.removeAttribute('spinning')\n }\n\n set type (value:string) {\n this._setAttribute('type', value)\n }\n\n get autofocus ():boolean {\n return !!(this.button?.hasAttribute('autofocus'))\n }\n\n set autofocus (value:boolean) {\n if (value) {\n this._setAttribute('autofocus', value)\n } else {\n this._removeAttribute('autofocus')\n }\n }\n\n /**\n * Set attributes on the internal button element.\n */\n _setAttribute (name:string, value:boolean|string|null):void {\n if (value === false) {\n // false means remove the attribute\n this._removeAttribute(name)\n this.button?.removeAttribute(name)\n } else {\n if (value === true) {\n // true means set the attribute with no value\n return this.button?.setAttribute(name, '')\n }\n\n if (value === null) {\n // null means remove\n return this._removeAttribute(name)\n }\n\n // else, set value to a string\n this.button?.setAttribute(name, value)\n }\n }\n\n /**\n * Remove from `this` and also button child.\n */\n _removeAttribute (name:string) {\n this.removeAttribute(name)\n this.button?.removeAttribute(name)\n }\n\n get button ():HTMLButtonElement|null {\n return this.querySelector('button')\n }\n\n /**\n * Handle 'autofocus' attribute changes\n * @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}\n *\n * @param {string} oldValue The old attribute value\n * @param {string} newValue The new attribute value\n */\n handleChange_autofocus (_oldValue:string, newValue:string) {\n this._setAttribute('autofocus', newValue)\n }\n\n handleChange_disabled (_old, newValue:boolean|string) {\n this.disabled = (newValue !== null)\n if (newValue === null) this.button?.removeAttribute('disabled')\n else this.button?.setAttribute('disabled', '' + newValue)\n }\n\n handleChange_spinning (_, newValue:boolean) {\n if (newValue !== null) {\n this.classList.add('substrate-loading')\n } else {\n this.classList.remove('substrate-loading')\n }\n }\n\n /**\n * Runs when the value of an attribute is changed.\n *\n * Should add methods to this class like `handleChange_class`, to\n * listen for changes to `class` attribute.\n *\n * @param {string} name The attribute name\n * @param {string} oldValue The old attribute value\n * @param {string} newValue The new attribute value\n */\n attributeChangedCallback (name:string, oldValue:string, newValue:string) {\n const handler = this[`handleChange_${name}`];\n (handler && handler.call(this, oldValue, newValue))\n }\n\n connectedCallback () {\n this.render()\n }\n\n static define () {\n if (!('customElements' in window)) return\n\n return customElements.define(\n SubstrateButton.tag || 'substrate-button',\n SubstrateButton\n )\n }\n\n render () {\n const {\n type,\n autofocus,\n tabindex,\n disabled,\n } = this\n\n const classes:string[] = ['substrate-button']\n\n const btnProps = ([\n `class=\"${classes.join(' ')}\"`,\n disabled ? 'disabled' : '',\n autofocus ? 'autofocus' : '',\n type ? `type=\"${this.type}\"` : '',\n tabindex ? `tabindex=\"${tabindex}\"` : 'tabindex=\"0\"',\n 'role=\"button\"'\n ]).filter(Boolean).join(' ')\n\n this.innerHTML = `<button ${btnProps}>${this.innerHTML}</button>`\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAM,wBAAwB,YAAY;AAAA,EAPjD,OAOiD;AAAA;AAAA;AAAA;AAAA,EAE7C,OAAO,qBAAqB,CAAC,aAAa,YAAY,UAAU;AAAA,EAChE,OAAO,MAAM;AAAA,EACb;AAAA,EAEA,cAAe;AACX,UAAM;AACN,UAAM,WAAW,KAAK,aAAa,UAAU;AAC7C,QAAI,aAAa,MAAM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EACrD;AAAA,EAEA,oBAAqB;AACjB,SAAK,OAAO;AAAA,EAChB;AAAA,EAEA,OAAO,SAAU;AACb,QAAI,EAAE,oBAAoB,QAAS;AAEnC,WAAO,eAAe;AAAA,MAClB,gBAAgB,OAAO;AAAA,MACvB;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,SAAU;AACN,UAAM;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,IAAI;AAEJ,UAAM,UAAmB,CAAC,kBAAkB;AAE5C,UAAM,WAAY;AAAA,MACd,UAAU,QAAQ,KAAK,GAAG,CAAC;AAAA,MAC3B,WAAW,aAAa;AAAA,MACxB,YAAY,cAAc;AAAA,MAC1B,OAAO,SAAS,KAAK,IAAI,MAAM;AAAA,MAC/B,WAAW,aAAa,QAAQ,MAAM;AAAA,MACtC;AAAA,IACJ,EAAG,OAAO,OAAO,EAAE,KAAK,GAAG;AAE3B,SAAK,YAAY,WAAW,QAAQ,IAAI,KAAK,SAAS;AAAA,EAC1D;AACJ;",
6
- "names": []
4
+ "sourcesContent": ["import { html } from './html.js'\nimport { SubstrateButton as SubstrateButtonLight } from './client.js'\n// import Debug from '@substrate-system/debug'\n// const debug = Debug()\n\nexport class SubstrateButton extends SubstrateButtonLight {\n static define () {\n if (!('customElements' in window)) return\n\n return customElements.define(\n SubstrateButton.TAG || 'substrate-button',\n SubstrateButton\n )\n }\n\n connectedCallback ():void {\n this.render()\n }\n\n render () {\n const {\n type,\n autofocus,\n tabindex,\n disabled,\n } = this\n\n const classes:(string|null)[] = [\n 'substrate-button',\n this.getAttribute('class')\n ]\n const text = this.innerHTML\n\n const btnProps = {\n classes: classes.filter(Boolean),\n disabled,\n autofocus,\n tabindex,\n type,\n }\n\n this.innerHTML = html(btnProps, text)\n }\n}\n\n// export class SubstrateButton extends HTMLElement {\n// // for `attributeChangedCallback`\n// static observedAttributes = ['autofocus', 'disabled', 'spinning']\n// static TAG = 'substrate-button'\n// _isSpinning:boolean\n\n// constructor () {\n// super()\n// const disabled = this.getAttribute('disabled')\n// if (disabled !== null) {\n// setTimeout(() => {\n// // need to wait for it to render\n// this.disabled = true\n// }, 0)\n// }\n// this.autofocus = (this.getAttribute('autofocus') !== null)\n// this._isSpinning = (this.getAttribute('spinning') !== null)\n// }\n\n// get form ():HTMLFormElement|undefined|null {\n// return this.button?.form\n// }\n\n// get disabled ():boolean {\n// return !!(this.button?.hasAttribute('disabled'))\n// }\n\n// set disabled (disabledValue:boolean) {\n// if (!disabledValue) {\n// this._removeAttribute('disabled')\n// this.button?.setAttribute('aria-disabled', 'false')\n// } else {\n// this.button?.setAttribute('disabled', '')\n// this.button?.setAttribute('aria-disabled', 'true')\n// }\n// }\n\n// get type ():string|null|undefined {\n// return this.button?.getAttribute('type')\n// }\n\n// get tabindex ():number {\n// const i = this.button?.getAttribute('tabindex')\n// if (!i) return 0\n// return parseInt(i)\n// }\n\n// get spinning ():boolean {\n// return this._isSpinning\n// }\n\n// set spinning (value:boolean) {\n// if (value) this.setAttribute('spinning', '')\n// else this.removeAttribute('spinning')\n// }\n\n// set type (value:string) {\n// this._setAttribute('type', value)\n// }\n\n// get autofocus ():boolean {\n// return !!(this.button?.hasAttribute('autofocus'))\n// }\n\n// set autofocus (value:boolean) {\n// if (value) {\n// this._setAttribute('autofocus', value)\n// } else {\n// this._removeAttribute('autofocus')\n// }\n// }\n\n// /**\n// * Set attributes on the internal button element.\n// */\n// _setAttribute (name:string, value:boolean|string|null):void {\n// if (value === false) {\n// // false means remove the attribute\n// this._removeAttribute(name)\n// this.button?.removeAttribute(name)\n// } else {\n// if (value === true) {\n// // true means set the attribute with no value\n// return this.button?.setAttribute(name, '')\n// }\n\n// if (value === null) {\n// // null means remove\n// return this._removeAttribute(name)\n// }\n\n// // else, set value to a string\n// this.button?.setAttribute(name, value)\n// }\n// }\n\n// /**\n// * Remove from `this` and also button child.\n// */\n// _removeAttribute (name:string) {\n// this.removeAttribute(name)\n// this.button?.removeAttribute(name)\n// }\n\n// get button ():HTMLButtonElement|null {\n// return this.querySelector('button')\n// }\n\n// /**\n// * Handle 'autofocus' attribute changes\n// * @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}\n// *\n// * @param {string} oldValue The old attribute value\n// * @param {string} newValue The new attribute value\n// */\n// handleChange_autofocus (_oldValue:string, newValue:string) {\n// this._setAttribute('autofocus', newValue)\n// }\n\n// handleChange_disabled (_old, newValue:boolean|string) {\n// this.disabled = (newValue !== null)\n// if (newValue === null) this.button?.removeAttribute('disabled')\n// else this.button?.setAttribute('disabled', '' + newValue)\n// }\n\n// handleChange_spinning (_, newValue:boolean) {\n// if (newValue !== null) {\n// this.classList.add('substrate-loading')\n// } else {\n// this.classList.remove('substrate-loading')\n// }\n// }\n\n// /**\n// * Runs when the value of an attribute is changed.\n// *\n// * Should add methods to this class like `handleChange_class`, to\n// * listen for changes to `class` attribute.\n// *\n// * @param {string} name The attribute name\n// * @param {string} oldValue The old attribute value\n// * @param {string} newValue The new attribute value\n// */\n// attributeChangedCallback (name:string, oldValue:string, newValue:string) {\n// const handler = this[`handleChange_${name}`];\n// (handler && handler.call(this, oldValue, newValue))\n// }\n\n// connectedCallback () {\n// debug('this.inner', this.innerHTML)\n// this.render()\n// }\n\n// static define () {\n// if (!('customElements' in window)) return\n\n// return customElements.define(\n// SubstrateButton.TAG || 'substrate-button',\n// SubstrateButton\n// )\n// }\n\n// render () {\n// const {\n// type,\n// autofocus,\n// tabindex,\n// disabled,\n// } = this\n\n// const classes:(string|null)[] = [\n// 'substrate-button',\n// this.getAttribute('class')\n// ]\n// const text = this.innerHTML\n\n// const btnProps = {\n// classes: classes.filter(Boolean),\n// disabled,\n// autofocus,\n// tabindex,\n// type,\n// }\n\n// this.innerHTML = html(btnProps, text)\n// }\n// }\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,oBAAwD;AAIjD,MAAM,wBAAwB,cAAAA,gBAAqB;AAAA,EAL1D,OAK0D;AAAA;AAAA;AAAA,EACtD,OAAO,SAAU;AACb,QAAI,EAAE,oBAAoB,QAAS;AAEnC,WAAO,eAAe;AAAA,MAClB,gBAAgB,OAAO;AAAA,MACvB;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,oBAA0B;AACtB,SAAK,OAAO;AAAA,EAChB;AAAA,EAEA,SAAU;AACN,UAAM;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,IAAI;AAEJ,UAAM,UAA0B;AAAA,MAC5B;AAAA,MACA,KAAK,aAAa,OAAO;AAAA,IAC7B;AACA,UAAM,OAAO,KAAK;AAElB,UAAM,WAAW;AAAA,MACb,SAAS,QAAQ,OAAO,OAAO;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAEA,SAAK,gBAAY,kBAAK,UAAU,IAAI;AAAA,EACxC;AACJ;",
6
+ "names": ["SubstrateButtonLight"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,55 +1,7 @@
1
- declare global {
2
- interface HTMLElementTagNameMap {
3
- 'substrate-button': SubstrateButton;
4
- }
5
- }
6
- export declare class SubstrateButton extends HTMLElement {
7
- static observedAttributes: string[];
8
- static tag: string;
9
- _isSpinning: boolean;
10
- constructor();
11
- get form(): HTMLFormElement | undefined | null;
12
- get disabled(): boolean;
13
- set disabled(disabledValue: boolean);
14
- get type(): string | null | undefined;
15
- get tabindex(): number;
16
- get spinning(): boolean;
17
- set spinning(value: boolean);
18
- set type(value: string);
19
- get autofocus(): boolean;
20
- set autofocus(value: boolean);
21
- /**
22
- * Set attributes on the internal button element.
23
- */
24
- _setAttribute(name: string, value: boolean | string | null): void;
25
- /**
26
- * Remove from `this` and also button child.
27
- */
28
- _removeAttribute(name: string): void;
29
- get button(): HTMLButtonElement | null;
30
- /**
31
- * Handle 'autofocus' attribute changes
32
- * @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}
33
- *
34
- * @param {string} oldValue The old attribute value
35
- * @param {string} newValue The new attribute value
36
- */
37
- handleChange_autofocus(_oldValue: string, newValue: string): void;
38
- handleChange_disabled(_old: any, newValue: boolean | string): void;
39
- handleChange_spinning(_: any, newValue: boolean): void;
40
- /**
41
- * Runs when the value of an attribute is changed.
42
- *
43
- * Should add methods to this class like `handleChange_class`, to
44
- * listen for changes to `class` attribute.
45
- *
46
- * @param {string} name The attribute name
47
- * @param {string} oldValue The old attribute value
48
- * @param {string} newValue The new attribute value
49
- */
50
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
51
- connectedCallback(): void;
1
+ import { SubstrateButton as SubstrateButtonLight } from './client.js';
2
+ export declare class SubstrateButton extends SubstrateButtonLight {
52
3
  static define(): void;
4
+ connectedCallback(): void;
53
5
  render(): void;
54
6
  }
55
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,kBAAkB,EAAE,eAAe,CAAA;KACtC;CACJ;AAED,qBAAa,eAAgB,SAAQ,WAAW;IAE5C,MAAM,CAAC,kBAAkB,WAAwC;IACjE,MAAM,CAAC,GAAG,SAAqB;IAC/B,WAAW,EAAC,OAAO,CAAA;;IAenB,IAAI,IAAI,IAAI,eAAe,GAAC,SAAS,GAAC,IAAI,CAEzC;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,QAAQ,CAAE,aAAa,EAAC,OAAO,EAQlC;IAED,IAAI,IAAI,IAAI,MAAM,GAAC,IAAI,GAAC,SAAS,CAEhC;IAED,IAAI,QAAQ,IAAI,MAAM,CAIrB;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,QAAQ,CAAE,KAAK,EAAC,OAAO,EAG1B;IAED,IAAI,IAAI,CAAE,KAAK,EAAC,MAAM,EAErB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,SAAS,CAAE,KAAK,EAAC,OAAO,EAM3B;IAED;;OAEG;IACH,aAAa,CAAE,IAAI,EAAC,MAAM,EAAE,KAAK,EAAC,OAAO,GAAC,MAAM,GAAC,IAAI,GAAE,IAAI;IAqB3D;;OAEG;IACH,gBAAgB,CAAE,IAAI,EAAC,MAAM;IAK7B,IAAI,MAAM,IAAI,iBAAiB,GAAC,IAAI,CAEnC;IAED;;;;;;OAMG;IACH,sBAAsB,CAAE,SAAS,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM;IAIzD,qBAAqB,CAAE,IAAI,KAAA,EAAE,QAAQ,EAAC,OAAO,GAAC,MAAM;IAMpD,qBAAqB,CAAE,CAAC,KAAA,EAAE,QAAQ,EAAC,OAAO;IAQ1C;;;;;;;;;OASG;IACH,wBAAwB,CAAE,IAAI,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM;IAKvE,iBAAiB;IAIjB,MAAM,CAAC,MAAM;IASb,MAAM;CAqBT"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,IAAI,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAIrE,qBAAa,eAAgB,SAAQ,oBAAoB;IACrD,MAAM,CAAC,MAAM;IASb,iBAAiB,IAAI,IAAI;IAIzB,MAAM;CAwBT"}
package/dist/index.js CHANGED
@@ -1,140 +1,21 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- class SubstrateButton extends HTMLElement {
3
+ import { html } from "./html.js";
4
+ import { SubstrateButton as SubstrateButtonLight } from "./client.js";
5
+ class SubstrateButton extends SubstrateButtonLight {
4
6
  static {
5
7
  __name(this, "SubstrateButton");
6
8
  }
7
- // for `attributeChangedCallback`
8
- static observedAttributes = ["autofocus", "disabled", "spinning"];
9
- static tag = "substrate-button";
10
- _isSpinning;
11
- constructor() {
12
- super();
13
- const disabled = this.getAttribute("disabled");
14
- if (disabled !== null) {
15
- setTimeout(() => {
16
- this.disabled = true;
17
- }, 0);
18
- }
19
- this.autofocus = this.getAttribute("autofocus") !== null;
20
- this._isSpinning = this.getAttribute("spinning") !== null;
21
- }
22
- get form() {
23
- return this.button?.form;
24
- }
25
- get disabled() {
26
- return !!this.button?.hasAttribute("disabled");
27
- }
28
- set disabled(disabledValue) {
29
- if (!disabledValue) {
30
- this._removeAttribute("disabled");
31
- this.button?.setAttribute("aria-disabled", "false");
32
- } else {
33
- this.button?.setAttribute("disabled", "");
34
- this.button?.setAttribute("aria-disabled", "true");
35
- }
36
- }
37
- get type() {
38
- return this.button?.getAttribute("type");
39
- }
40
- get tabindex() {
41
- const i = this.button?.getAttribute("tabindex");
42
- if (!i) return 0;
43
- return parseInt(i);
44
- }
45
- get spinning() {
46
- return this._isSpinning;
47
- }
48
- set spinning(value) {
49
- if (value) this.setAttribute("spinning", "");
50
- else this.removeAttribute("spinning");
51
- }
52
- set type(value) {
53
- this._setAttribute("type", value);
54
- }
55
- get autofocus() {
56
- return !!this.button?.hasAttribute("autofocus");
57
- }
58
- set autofocus(value) {
59
- if (value) {
60
- this._setAttribute("autofocus", value);
61
- } else {
62
- this._removeAttribute("autofocus");
63
- }
64
- }
65
- /**
66
- * Set attributes on the internal button element.
67
- */
68
- _setAttribute(name, value) {
69
- if (value === false) {
70
- this._removeAttribute(name);
71
- this.button?.removeAttribute(name);
72
- } else {
73
- if (value === true) {
74
- return this.button?.setAttribute(name, "");
75
- }
76
- if (value === null) {
77
- return this._removeAttribute(name);
78
- }
79
- this.button?.setAttribute(name, value);
80
- }
81
- }
82
- /**
83
- * Remove from `this` and also button child.
84
- */
85
- _removeAttribute(name) {
86
- this.removeAttribute(name);
87
- this.button?.removeAttribute(name);
88
- }
89
- get button() {
90
- return this.querySelector("button");
91
- }
92
- /**
93
- * Handle 'autofocus' attribute changes
94
- * @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}
95
- *
96
- * @param {string} oldValue The old attribute value
97
- * @param {string} newValue The new attribute value
98
- */
99
- handleChange_autofocus(_oldValue, newValue) {
100
- this._setAttribute("autofocus", newValue);
101
- }
102
- handleChange_disabled(_old, newValue) {
103
- this.disabled = newValue !== null;
104
- if (newValue === null) this.button?.removeAttribute("disabled");
105
- else this.button?.setAttribute("disabled", "" + newValue);
106
- }
107
- handleChange_spinning(_, newValue) {
108
- if (newValue !== null) {
109
- this.classList.add("substrate-loading");
110
- } else {
111
- this.classList.remove("substrate-loading");
112
- }
113
- }
114
- /**
115
- * Runs when the value of an attribute is changed.
116
- *
117
- * Should add methods to this class like `handleChange_class`, to
118
- * listen for changes to `class` attribute.
119
- *
120
- * @param {string} name The attribute name
121
- * @param {string} oldValue The old attribute value
122
- * @param {string} newValue The new attribute value
123
- */
124
- attributeChangedCallback(name, oldValue, newValue) {
125
- const handler = this[`handleChange_${name}`];
126
- handler && handler.call(this, oldValue, newValue);
127
- }
128
- connectedCallback() {
129
- this.render();
130
- }
131
9
  static define() {
132
10
  if (!("customElements" in window)) return;
133
11
  return customElements.define(
134
- SubstrateButton.tag || "substrate-button",
12
+ SubstrateButton.TAG || "substrate-button",
135
13
  SubstrateButton
136
14
  );
137
15
  }
16
+ connectedCallback() {
17
+ this.render();
18
+ }
138
19
  render() {
139
20
  const {
140
21
  type,
@@ -142,16 +23,19 @@ class SubstrateButton extends HTMLElement {
142
23
  tabindex,
143
24
  disabled
144
25
  } = this;
145
- const classes = ["substrate-button"];
146
- const btnProps = [
147
- `class="${classes.join(" ")}"`,
148
- disabled ? "disabled" : "",
149
- autofocus ? "autofocus" : "",
150
- type ? `type="${this.type}"` : "",
151
- tabindex ? `tabindex="${tabindex}"` : 'tabindex="0"',
152
- 'role="button"'
153
- ].filter(Boolean).join(" ");
154
- this.innerHTML = `<button ${btnProps}>${this.innerHTML}</button>`;
26
+ const classes = [
27
+ "substrate-button",
28
+ this.getAttribute("class")
29
+ ];
30
+ const text = this.innerHTML;
31
+ const btnProps = {
32
+ classes: classes.filter(Boolean),
33
+ disabled,
34
+ autofocus,
35
+ tabindex,
36
+ type
37
+ };
38
+ this.innerHTML = html(btnProps, text);
155
39
  }
156
40
  }
157
41
  export {
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'substrate-button': SubstrateButton\n }\n}\n\nexport class SubstrateButton extends HTMLElement {\n // for `attributeChangedCallback`\n static observedAttributes = ['autofocus', 'disabled', 'spinning']\n static tag = 'substrate-button'\n _isSpinning:boolean\n\n constructor () {\n super()\n const disabled = this.getAttribute('disabled')\n if (disabled !== null) {\n setTimeout(() => {\n // need to wait for it to render\n this.disabled = true\n }, 0)\n }\n this.autofocus = (this.getAttribute('autofocus') !== null)\n this._isSpinning = (this.getAttribute('spinning') !== null)\n }\n\n get form ():HTMLFormElement|undefined|null {\n return this.button?.form\n }\n\n get disabled ():boolean {\n return !!(this.button?.hasAttribute('disabled'))\n }\n\n set disabled (disabledValue:boolean) {\n if (!disabledValue) {\n this._removeAttribute('disabled')\n this.button?.setAttribute('aria-disabled', 'false')\n } else {\n this.button?.setAttribute('disabled', '')\n this.button?.setAttribute('aria-disabled', 'true')\n }\n }\n\n get type ():string|null|undefined {\n return this.button?.getAttribute('type')\n }\n\n get tabindex ():number {\n const i = this.button?.getAttribute('tabindex')\n if (!i) return 0\n return parseInt(i)\n }\n\n get spinning ():boolean {\n return this._isSpinning\n }\n\n set spinning (value:boolean) {\n if (value) this.setAttribute('spinning', '')\n else this.removeAttribute('spinning')\n }\n\n set type (value:string) {\n this._setAttribute('type', value)\n }\n\n get autofocus ():boolean {\n return !!(this.button?.hasAttribute('autofocus'))\n }\n\n set autofocus (value:boolean) {\n if (value) {\n this._setAttribute('autofocus', value)\n } else {\n this._removeAttribute('autofocus')\n }\n }\n\n /**\n * Set attributes on the internal button element.\n */\n _setAttribute (name:string, value:boolean|string|null):void {\n if (value === false) {\n // false means remove the attribute\n this._removeAttribute(name)\n this.button?.removeAttribute(name)\n } else {\n if (value === true) {\n // true means set the attribute with no value\n return this.button?.setAttribute(name, '')\n }\n\n if (value === null) {\n // null means remove\n return this._removeAttribute(name)\n }\n\n // else, set value to a string\n this.button?.setAttribute(name, value)\n }\n }\n\n /**\n * Remove from `this` and also button child.\n */\n _removeAttribute (name:string) {\n this.removeAttribute(name)\n this.button?.removeAttribute(name)\n }\n\n get button ():HTMLButtonElement|null {\n return this.querySelector('button')\n }\n\n /**\n * Handle 'autofocus' attribute changes\n * @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}\n *\n * @param {string} oldValue The old attribute value\n * @param {string} newValue The new attribute value\n */\n handleChange_autofocus (_oldValue:string, newValue:string) {\n this._setAttribute('autofocus', newValue)\n }\n\n handleChange_disabled (_old, newValue:boolean|string) {\n this.disabled = (newValue !== null)\n if (newValue === null) this.button?.removeAttribute('disabled')\n else this.button?.setAttribute('disabled', '' + newValue)\n }\n\n handleChange_spinning (_, newValue:boolean) {\n if (newValue !== null) {\n this.classList.add('substrate-loading')\n } else {\n this.classList.remove('substrate-loading')\n }\n }\n\n /**\n * Runs when the value of an attribute is changed.\n *\n * Should add methods to this class like `handleChange_class`, to\n * listen for changes to `class` attribute.\n *\n * @param {string} name The attribute name\n * @param {string} oldValue The old attribute value\n * @param {string} newValue The new attribute value\n */\n attributeChangedCallback (name:string, oldValue:string, newValue:string) {\n const handler = this[`handleChange_${name}`];\n (handler && handler.call(this, oldValue, newValue))\n }\n\n connectedCallback () {\n this.render()\n }\n\n static define () {\n if (!('customElements' in window)) return\n\n return customElements.define(\n SubstrateButton.tag || 'substrate-button',\n SubstrateButton\n )\n }\n\n render () {\n const {\n type,\n autofocus,\n tabindex,\n disabled,\n } = this\n\n const classes:string[] = ['substrate-button']\n\n const btnProps = ([\n `class=\"${classes.join(' ')}\"`,\n disabled ? 'disabled' : '',\n autofocus ? 'autofocus' : '',\n type ? `type=\"${this.type}\"` : '',\n tabindex ? `tabindex=\"${tabindex}\"` : 'tabindex=\"0\"',\n 'role=\"button\"'\n ]).filter(Boolean).join(' ')\n\n this.innerHTML = `<button ${btnProps}>${this.innerHTML}</button>`\n }\n}\n"],
5
- "mappings": ";;AAOO,MAAM,wBAAwB,YAAY;AAAA,EAPjD,OAOiD;AAAA;AAAA;AAAA;AAAA,EAE7C,OAAO,qBAAqB,CAAC,aAAa,YAAY,UAAU;AAAA,EAChE,OAAO,MAAM;AAAA,EACb;AAAA,EAEA,cAAe;AACX,UAAM;AACN,UAAM,WAAW,KAAK,aAAa,UAAU;AAC7C,QAAI,aAAa,MAAM;AACnB,iBAAW,MAAM;AAEb,aAAK,WAAW;AAAA,MACpB,GAAG,CAAC;AAAA,IACR;AACA,SAAK,YAAa,KAAK,aAAa,WAAW,MAAM;AACrD,SAAK,cAAe,KAAK,aAAa,UAAU,MAAM;AAAA,EAC1D;AAAA,EAEA,IAAI,OAAuC;AACvC,WAAO,KAAK,QAAQ;AAAA,EACxB;AAAA,EAEA,IAAI,WAAoB;AACpB,WAAO,CAAC,CAAE,KAAK,QAAQ,aAAa,UAAU;AAAA,EAClD;AAAA,EAEA,IAAI,SAAU,eAAuB;AACjC,QAAI,CAAC,eAAe;AAChB,WAAK,iBAAiB,UAAU;AAChC,WAAK,QAAQ,aAAa,iBAAiB,OAAO;AAAA,IACtD,OAAO;AACH,WAAK,QAAQ,aAAa,YAAY,EAAE;AACxC,WAAK,QAAQ,aAAa,iBAAiB,MAAM;AAAA,IACrD;AAAA,EACJ;AAAA,EAEA,IAAI,OAA8B;AAC9B,WAAO,KAAK,QAAQ,aAAa,MAAM;AAAA,EAC3C;AAAA,EAEA,IAAI,WAAm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["import { html } from './html.js'\nimport { SubstrateButton as SubstrateButtonLight } from './client.js'\n// import Debug from '@substrate-system/debug'\n// const debug = Debug()\n\nexport class SubstrateButton extends SubstrateButtonLight {\n static define () {\n if (!('customElements' in window)) return\n\n return customElements.define(\n SubstrateButton.TAG || 'substrate-button',\n SubstrateButton\n )\n }\n\n connectedCallback ():void {\n this.render()\n }\n\n render () {\n const {\n type,\n autofocus,\n tabindex,\n disabled,\n } = this\n\n const classes:(string|null)[] = [\n 'substrate-button',\n this.getAttribute('class')\n ]\n const text = this.innerHTML\n\n const btnProps = {\n classes: classes.filter(Boolean),\n disabled,\n autofocus,\n tabindex,\n type,\n }\n\n this.innerHTML = html(btnProps, text)\n }\n}\n\n// export class SubstrateButton extends HTMLElement {\n// // for `attributeChangedCallback`\n// static observedAttributes = ['autofocus', 'disabled', 'spinning']\n// static TAG = 'substrate-button'\n// _isSpinning:boolean\n\n// constructor () {\n// super()\n// const disabled = this.getAttribute('disabled')\n// if (disabled !== null) {\n// setTimeout(() => {\n// // need to wait for it to render\n// this.disabled = true\n// }, 0)\n// }\n// this.autofocus = (this.getAttribute('autofocus') !== null)\n// this._isSpinning = (this.getAttribute('spinning') !== null)\n// }\n\n// get form ():HTMLFormElement|undefined|null {\n// return this.button?.form\n// }\n\n// get disabled ():boolean {\n// return !!(this.button?.hasAttribute('disabled'))\n// }\n\n// set disabled (disabledValue:boolean) {\n// if (!disabledValue) {\n// this._removeAttribute('disabled')\n// this.button?.setAttribute('aria-disabled', 'false')\n// } else {\n// this.button?.setAttribute('disabled', '')\n// this.button?.setAttribute('aria-disabled', 'true')\n// }\n// }\n\n// get type ():string|null|undefined {\n// return this.button?.getAttribute('type')\n// }\n\n// get tabindex ():number {\n// const i = this.button?.getAttribute('tabindex')\n// if (!i) return 0\n// return parseInt(i)\n// }\n\n// get spinning ():boolean {\n// return this._isSpinning\n// }\n\n// set spinning (value:boolean) {\n// if (value) this.setAttribute('spinning', '')\n// else this.removeAttribute('spinning')\n// }\n\n// set type (value:string) {\n// this._setAttribute('type', value)\n// }\n\n// get autofocus ():boolean {\n// return !!(this.button?.hasAttribute('autofocus'))\n// }\n\n// set autofocus (value:boolean) {\n// if (value) {\n// this._setAttribute('autofocus', value)\n// } else {\n// this._removeAttribute('autofocus')\n// }\n// }\n\n// /**\n// * Set attributes on the internal button element.\n// */\n// _setAttribute (name:string, value:boolean|string|null):void {\n// if (value === false) {\n// // false means remove the attribute\n// this._removeAttribute(name)\n// this.button?.removeAttribute(name)\n// } else {\n// if (value === true) {\n// // true means set the attribute with no value\n// return this.button?.setAttribute(name, '')\n// }\n\n// if (value === null) {\n// // null means remove\n// return this._removeAttribute(name)\n// }\n\n// // else, set value to a string\n// this.button?.setAttribute(name, value)\n// }\n// }\n\n// /**\n// * Remove from `this` and also button child.\n// */\n// _removeAttribute (name:string) {\n// this.removeAttribute(name)\n// this.button?.removeAttribute(name)\n// }\n\n// get button ():HTMLButtonElement|null {\n// return this.querySelector('button')\n// }\n\n// /**\n// * Handle 'autofocus' attribute changes\n// * @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}\n// *\n// * @param {string} oldValue The old attribute value\n// * @param {string} newValue The new attribute value\n// */\n// handleChange_autofocus (_oldValue:string, newValue:string) {\n// this._setAttribute('autofocus', newValue)\n// }\n\n// handleChange_disabled (_old, newValue:boolean|string) {\n// this.disabled = (newValue !== null)\n// if (newValue === null) this.button?.removeAttribute('disabled')\n// else this.button?.setAttribute('disabled', '' + newValue)\n// }\n\n// handleChange_spinning (_, newValue:boolean) {\n// if (newValue !== null) {\n// this.classList.add('substrate-loading')\n// } else {\n// this.classList.remove('substrate-loading')\n// }\n// }\n\n// /**\n// * Runs when the value of an attribute is changed.\n// *\n// * Should add methods to this class like `handleChange_class`, to\n// * listen for changes to `class` attribute.\n// *\n// * @param {string} name The attribute name\n// * @param {string} oldValue The old attribute value\n// * @param {string} newValue The new attribute value\n// */\n// attributeChangedCallback (name:string, oldValue:string, newValue:string) {\n// const handler = this[`handleChange_${name}`];\n// (handler && handler.call(this, oldValue, newValue))\n// }\n\n// connectedCallback () {\n// debug('this.inner', this.innerHTML)\n// this.render()\n// }\n\n// static define () {\n// if (!('customElements' in window)) return\n\n// return customElements.define(\n// SubstrateButton.TAG || 'substrate-button',\n// SubstrateButton\n// )\n// }\n\n// render () {\n// const {\n// type,\n// autofocus,\n// tabindex,\n// disabled,\n// } = this\n\n// const classes:(string|null)[] = [\n// 'substrate-button',\n// this.getAttribute('class')\n// ]\n// const text = this.innerHTML\n\n// const btnProps = {\n// classes: classes.filter(Boolean),\n// disabled,\n// autofocus,\n// tabindex,\n// type,\n// }\n\n// this.innerHTML = html(btnProps, text)\n// }\n// }\n"],
5
+ "mappings": ";;AAAA,SAAS,YAAY;AACrB,SAAS,mBAAmB,4BAA4B;AAIjD,MAAM,wBAAwB,qBAAqB;AAAA,EAL1D,OAK0D;AAAA;AAAA;AAAA,EACtD,OAAO,SAAU;AACb,QAAI,EAAE,oBAAoB,QAAS;AAEnC,WAAO,eAAe;AAAA,MAClB,gBAAgB,OAAO;AAAA,MACvB;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,oBAA0B;AACtB,SAAK,OAAO;AAAA,EAChB;AAAA,EAEA,SAAU;AACN,UAAM;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,IAAI;AAEJ,UAAM,UAA0B;AAAA,MAC5B;AAAA,MACA,KAAK,aAAa,OAAO;AAAA,IAC7B;AACA,UAAM,OAAO,KAAK;AAElB,UAAM,WAAW;AAAA,MACb,SAAS,QAAQ,OAAO,OAAO;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ;AAEA,SAAK,YAAY,KAAK,UAAU,IAAI;AAAA,EACxC;AACJ;",
6
6
  "names": []
7
7
  }
package/dist/index.min.js CHANGED
@@ -1,2 +1,4 @@
1
- var b=Object.defineProperty;var u=(s,t)=>b(s,"name",{value:t,configurable:!0});var r=class s extends HTMLElement{static{u(this,"SubstrateButton")}static observedAttributes=["autofocus","disabled","spinning"];static tag="substrate-button";_isSpinning;constructor(){super(),this.getAttribute("disabled")!==null&&setTimeout(()=>{this.disabled=!0},0),this.autofocus=this.getAttribute("autofocus")!==null,this._isSpinning=this.getAttribute("spinning")!==null}get form(){return this.button?.form}get disabled(){return!!this.button?.hasAttribute("disabled")}set disabled(t){t?(this.button?.setAttribute("disabled",""),this.button?.setAttribute("aria-disabled","true")):(this._removeAttribute("disabled"),this.button?.setAttribute("aria-disabled","false"))}get type(){return this.button?.getAttribute("type")}get tabindex(){let t=this.button?.getAttribute("tabindex");return t?parseInt(t):0}get spinning(){return this._isSpinning}set spinning(t){t?this.setAttribute("spinning",""):this.removeAttribute("spinning")}set type(t){this._setAttribute("type",t)}get autofocus(){return!!this.button?.hasAttribute("autofocus")}set autofocus(t){t?this._setAttribute("autofocus",t):this._removeAttribute("autofocus")}_setAttribute(t,e){if(e===!1)this._removeAttribute(t),this.button?.removeAttribute(t);else{if(e===!0)return this.button?.setAttribute(t,"");if(e===null)return this._removeAttribute(t);this.button?.setAttribute(t,e)}}_removeAttribute(t){this.removeAttribute(t),this.button?.removeAttribute(t)}get button(){return this.querySelector("button")}handleChange_autofocus(t,e){this._setAttribute("autofocus",e)}handleChange_disabled(t,e){this.disabled=e!==null,e===null?this.button?.removeAttribute("disabled"):this.button?.setAttribute("disabled",""+e)}handleChange_spinning(t,e){e!==null?this.classList.add("substrate-loading"):this.classList.remove("substrate-loading")}attributeChangedCallback(t,e,i){let n=this[`handleChange_${t}`];n&&n.call(this,e,i)}connectedCallback(){this.render()}static define(){if("customElements"in window)return customElements.define(s.tag||"substrate-button",s)}render(){let{type:t,autofocus:e,tabindex:i,disabled:n}=this,o=[`class="${["substrate-button"].join(" ")}"`,n?"disabled":"",e?"autofocus":"",t?`type="${this.type}"`:"",i?`tabindex="${i}"`:'tabindex="0"','role="button"'].filter(Boolean).join(" ");this.innerHTML=`<button ${o}>${this.innerHTML}</button>`}};export{r as SubstrateButton};
1
+ var c=Object.defineProperty;var n=(s,t)=>c(s,"name",{value:t,configurable:!0});function d(s,t){let{type:e,autofocus:r,tabindex:i,disabled:b,classes:a}=s,o=new Set(a);o.add("substrate-button");let l=Array.from(o);return`<button ${[l.length?`class="${l.filter(Boolean).join(" ")}"`:"",b?"disabled":"",r?"autofocus":"",e?`type="${e}"`:"",i?`tabindex="${i}"`:'tabindex="0"','role="button"'].filter(Boolean).join(" ")}>
2
+ ${t}
3
+ </button>`}n(d,"html");var u=class s extends HTMLElement{static{n(this,"SubstrateButton")}static observedAttributes=["autofocus","disabled","spinning"];static TAG="substrate-button";_isSpinning;constructor(){super(),this.getAttribute("disabled")!==null&&setTimeout(()=>{this.disabled=!0},0),this.autofocus=this.getAttribute("autofocus")!==null,this._isSpinning=this.getAttribute("spinning")!==null}get form(){return this.button?.form}get disabled(){return!!this.button?.hasAttribute("disabled")}set disabled(t){t?(this.button?.setAttribute("disabled",""),this.button?.setAttribute("aria-disabled","true")):(this._removeAttribute("disabled"),this.button?.setAttribute("aria-disabled","false"))}get type(){return this.button?.getAttribute("type")}get tabindex(){let t=this.button?.getAttribute("tabindex");return t?parseInt(t):0}get spinning(){return this._isSpinning}set spinning(t){t?this.setAttribute("spinning",""):this.removeAttribute("spinning")}set type(t){this._setAttribute("type",t)}get autofocus(){return!!this.button?.hasAttribute("autofocus")}set autofocus(t){t?this._setAttribute("autofocus",t):this._removeAttribute("autofocus")}_setAttribute(t,e){if(e===!1)this._removeAttribute(t),this.button?.removeAttribute(t);else{if(e===!0)return this.button?.setAttribute(t,"");if(e===null)return this._removeAttribute(t);this.button?.setAttribute(t,e)}}_removeAttribute(t){this.removeAttribute(t),this.button?.removeAttribute(t)}get button(){return this.querySelector("button")}handleChange_autofocus(t,e){this._setAttribute("autofocus",e)}handleChange_disabled(t,e){this.disabled=e!==null,e===null?this.button?.removeAttribute("disabled"):this.button?.setAttribute("disabled",""+e)}handleChange_spinning(t,e){e!==null?this.classList.add("substrate-loading"):this.classList.remove("substrate-loading")}attributeChangedCallback(t,e,r){let i=this[`handleChange_${t}`];i&&i.call(this,e,r)}connectedCallback(){this.render()}static define(){if("customElements"in window)return customElements.define(s.TAG||"substrate-button",s)}render(){}};var h=class s extends u{static{n(this,"SubstrateButton")}static define(){if("customElements"in window)return customElements.define(s.TAG||"substrate-button",s)}connectedCallback(){this.render()}render(){let{type:t,autofocus:e,tabindex:r,disabled:i}=this,b=["substrate-button",this.getAttribute("class")],a=this.innerHTML,o={classes:b.filter(Boolean),disabled:i,autofocus:e,tabindex:r,type:t};this.innerHTML=d(o,a)}};export{h as SubstrateButton};
2
4
  //# sourceMappingURL=index.min.js.map