@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/README.md +69 -31
- package/dist/client.cjs +163 -0
- package/dist/client.cjs.map +7 -0
- package/dist/client.d.ts +58 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +144 -0
- package/dist/client.js.map +7 -0
- package/dist/client.min.js +2 -0
- package/dist/client.min.js.map +7 -0
- package/dist/html.cjs +49 -0
- package/dist/html.cjs.map +7 -0
- package/dist/html.d.ts +9 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +30 -0
- package/dist/html.js.map +7 -0
- package/dist/html.min.js +4 -0
- package/dist/html.min.js.map +7 -0
- package/dist/index.cjs +20 -136
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +3 -51
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -136
- package/dist/index.js.map +2 -2
- package/dist/index.min.js +3 -1
- package/dist/index.min.js.map +4 -4
- package/dist/meta.json +64 -5
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# button
|
|
2
|
-
](https://github.com/substrate-system/button/actions/workflows/nodejs.yml)
|
|
3
3
|
[](README.md)
|
|
4
4
|
[](README.md)
|
|
5
5
|
[](package.json)
|
|
6
6
|
[](https://packagephobia.com/result?p=@substrate-system/button)
|
|
7
|
-
[](https://bundlephobia.com/package/@substrate-system/button)
|
|
8
8
|
[](https://semver.org/)
|
|
9
9
|
[](./CHANGELOG.md)
|
|
10
10
|
[](LICENSE)
|
|
@@ -29,10 +29,11 @@ A button web component, with a visual "loading" state.
|
|
|
29
29
|
* [Bundler](#bundler)
|
|
30
30
|
* [CSS import](#css-import)
|
|
31
31
|
- [Use](#use)
|
|
32
|
+
- [Module format](#module-format)
|
|
33
|
+
* [Bundler](#bundler-1)
|
|
34
|
+
* [pre-built](#pre-built)
|
|
32
35
|
* [Example](#example)
|
|
33
36
|
* [Attributes](#attributes)
|
|
34
|
-
* [HTML](#html)
|
|
35
|
-
* [pre-built](#pre-built)
|
|
36
37
|
|
|
37
38
|
<!-- tocstop -->
|
|
38
39
|
|
|
@@ -109,11 +110,11 @@ call `.define()`.
|
|
|
109
110
|
> [!CAUTION]
|
|
110
111
|
> If you change the name of the web component, it will break the CSS.
|
|
111
112
|
|
|
112
|
-
|
|
113
113
|
To use the default, call `.define()`:
|
|
114
114
|
|
|
115
115
|
```js
|
|
116
116
|
import { SubstrateButton } from '@substrate-system/button'
|
|
117
|
+
import '@substrate-system/button/css'
|
|
117
118
|
|
|
118
119
|
// create a web component named `substrate-button`
|
|
119
120
|
SubstrateButton.define()
|
|
@@ -129,50 +130,51 @@ SubstrateButton.tag = 'cool-button'
|
|
|
129
130
|
SubstrateButton.define()
|
|
130
131
|
```
|
|
131
132
|
|
|
132
|
-
|
|
133
|
+
## Module format
|
|
133
134
|
|
|
134
|
-
|
|
135
|
+
This package includes ESM, Common JS, and pre-bundled versions.
|
|
135
136
|
|
|
136
|
-
###
|
|
137
|
+
### Bundler
|
|
138
|
+
Just import like normal.
|
|
137
139
|
|
|
138
|
-
####
|
|
140
|
+
#### Full
|
|
139
141
|
|
|
140
|
-
|
|
142
|
+
This is a web component that knows how to render itself.
|
|
141
143
|
|
|
142
144
|
```js
|
|
143
|
-
|
|
144
|
-
el?.setAttribute('spinning', '')
|
|
145
|
-
// now it shows a spinning animation
|
|
146
|
-
```
|
|
145
|
+
import { SubstrateButton } from '@substrate-system/button'
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
```js
|
|
150
|
-
const el = document.querySelector('substrate-button')
|
|
151
|
-
el?.removeAttribute('spinning')
|
|
147
|
+
SubstrateButton.define()
|
|
152
148
|
```
|
|
153
149
|
|
|
154
|
-
####
|
|
150
|
+
#### Client
|
|
155
151
|
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
The client version should be used in conjunction with server-side rendering.
|
|
153
|
+
It does not know how to render itself.
|
|
158
154
|
|
|
159
155
|
```js
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
el.spinning = true // spin
|
|
156
|
+
import { SubstrateButton } from '@substrate-system/button/client'
|
|
163
157
|
|
|
164
|
-
|
|
158
|
+
SubstrateButton.define()
|
|
165
159
|
```
|
|
166
160
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
161
|
+
#### Server-side
|
|
162
|
+
|
|
163
|
+
Take some attributes, and return a string of HTML.
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
import { html } from '@substrate-system/button/html'
|
|
167
|
+
|
|
168
|
+
const htmlString = html({
|
|
169
|
+
classes: ['abc'],
|
|
170
|
+
disabled: false,
|
|
171
|
+
autofocus: false
|
|
172
|
+
})
|
|
172
173
|
```
|
|
173
174
|
|
|
174
175
|
### pre-built
|
|
175
|
-
|
|
176
|
+
|
|
177
|
+
This package exposes minified JS and CSS files. Copy them to a location that is
|
|
176
178
|
accessible to your web server, then link to them in HTML.
|
|
177
179
|
|
|
178
180
|
#### copy
|
|
@@ -191,3 +193,39 @@ cp ./node_modules/@substrate-system/button/dist/index.min.css ./public/substrate
|
|
|
191
193
|
<script type="module" src="./substrate-button.min.js"></script>
|
|
192
194
|
</body>
|
|
193
195
|
```
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
### Example
|
|
199
|
+
|
|
200
|
+
See the example in [./example](./example/).
|
|
201
|
+
|
|
202
|
+
### Attributes
|
|
203
|
+
|
|
204
|
+
#### spinning
|
|
205
|
+
|
|
206
|
+
Add an attribute `spinning` to set the loading state.
|
|
207
|
+
|
|
208
|
+
```js
|
|
209
|
+
const el = document.querySelector('substrate-button')
|
|
210
|
+
el?.setAttribute('spinning', '')
|
|
211
|
+
// now it shows a spinning animation
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Remove the attribute to stop the animation:
|
|
215
|
+
```js
|
|
216
|
+
const el = document.querySelector('substrate-button')
|
|
217
|
+
el?.removeAttribute('spinning')
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### JS API
|
|
221
|
+
|
|
222
|
+
Or, if you have a reference to the element, you can set the `spinning` property
|
|
223
|
+
for the same effect:
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
const el = document.querySelector('substrate-button')
|
|
227
|
+
|
|
228
|
+
el.spinning = true // spin
|
|
229
|
+
|
|
230
|
+
el.spinning = false // stop
|
|
231
|
+
```
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var client_exports = {};
|
|
21
|
+
__export(client_exports, {
|
|
22
|
+
SubstrateButton: () => SubstrateButton
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(client_exports);
|
|
25
|
+
class SubstrateButton extends HTMLElement {
|
|
26
|
+
static {
|
|
27
|
+
__name(this, "SubstrateButton");
|
|
28
|
+
}
|
|
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
|
+
static define() {
|
|
154
|
+
if (!("customElements" in window)) return;
|
|
155
|
+
return customElements.define(
|
|
156
|
+
SubstrateButton.TAG || "substrate-button",
|
|
157
|
+
SubstrateButton
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
render() {
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client.ts"],
|
|
4
|
+
"sourcesContent": ["// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'substrate-button': SubstrateButton\n }\n}\n\n/**\n * This is the lightweight version for browsers + server-side rendering.\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 // connect event listeners\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 // noop\n }\n}\n\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,MAAM,wBAAwB,YAAY;AAAA,EAVjD,OAUiD;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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[]
|
|
7
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface HTMLElementTagNameMap {
|
|
3
|
+
'substrate-button': SubstrateButton;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This is the lightweight version for browsers + server-side rendering.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SubstrateButton extends HTMLElement {
|
|
10
|
+
static observedAttributes: string[];
|
|
11
|
+
static TAG: string;
|
|
12
|
+
_isSpinning: boolean;
|
|
13
|
+
constructor();
|
|
14
|
+
get form(): HTMLFormElement | undefined | null;
|
|
15
|
+
get disabled(): boolean;
|
|
16
|
+
set disabled(disabledValue: boolean);
|
|
17
|
+
get type(): string | null | undefined;
|
|
18
|
+
get tabindex(): number;
|
|
19
|
+
get spinning(): boolean;
|
|
20
|
+
set spinning(value: boolean);
|
|
21
|
+
set type(value: string);
|
|
22
|
+
get autofocus(): boolean;
|
|
23
|
+
set autofocus(value: boolean);
|
|
24
|
+
/**
|
|
25
|
+
* Set attributes on the internal button element.
|
|
26
|
+
*/
|
|
27
|
+
_setAttribute(name: string, value: boolean | string | null): void;
|
|
28
|
+
/**
|
|
29
|
+
* Remove from `this` and also button child.
|
|
30
|
+
*/
|
|
31
|
+
_removeAttribute(name: string): void;
|
|
32
|
+
get button(): HTMLButtonElement | null;
|
|
33
|
+
/**
|
|
34
|
+
* Handle 'autofocus' attribute changes
|
|
35
|
+
* @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}
|
|
36
|
+
*
|
|
37
|
+
* @param {string} oldValue The old attribute value
|
|
38
|
+
* @param {string} newValue The new attribute value
|
|
39
|
+
*/
|
|
40
|
+
handleChange_autofocus(_oldValue: string, newValue: string): void;
|
|
41
|
+
handleChange_disabled(_old: any, newValue: boolean | string): void;
|
|
42
|
+
handleChange_spinning(_: any, newValue: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Runs when the value of an attribute is changed.
|
|
45
|
+
*
|
|
46
|
+
* Should add methods to this class like `handleChange_class`, to
|
|
47
|
+
* listen for changes to `class` attribute.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} name The attribute name
|
|
50
|
+
* @param {string} oldValue The old attribute value
|
|
51
|
+
* @param {string} newValue The new attribute value
|
|
52
|
+
*/
|
|
53
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
54
|
+
connectedCallback(): void;
|
|
55
|
+
static define(): void;
|
|
56
|
+
render(): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,kBAAkB,EAAE,eAAe,CAAA;KACtC;CACJ;AAED;;GAEG;AACH,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;IAKjB,MAAM,CAAC,MAAM;IASb,MAAM;CAGT"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class SubstrateButton extends HTMLElement {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "SubstrateButton");
|
|
6
|
+
}
|
|
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
|
+
static define() {
|
|
132
|
+
if (!("customElements" in window)) return;
|
|
133
|
+
return customElements.define(
|
|
134
|
+
SubstrateButton.TAG || "substrate-button",
|
|
135
|
+
SubstrateButton
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
render() {
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
SubstrateButton
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client.ts"],
|
|
4
|
+
"sourcesContent": ["// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'substrate-button': SubstrateButton\n }\n}\n\n/**\n * This is the lightweight version for browsers + server-side rendering.\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 // connect event listeners\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 // noop\n }\n}\n\n"],
|
|
5
|
+
"mappings": ";;AAUO,MAAM,wBAAwB,YAAY;AAAA,EAVjD,OAUiD;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,WAAmB;AACnB,UAAM,IAAI,KAAK,QAAQ,aAAa,UAAU;AAC9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MAAM,UAAyB;AAClD,SAAK,WAAY,aAAa;AAC9B,QAAI,aAAa,KAAM,MAAK,QAAQ,gBAAgB,UAAU;AAAA,QACzD,MAAK,QAAQ,aAAa,YAAY,KAAK,QAAQ;AAAA,EAC5D;AAAA,EAEA,sBAAuB,GAAG,UAAkB;AACxC,QAAI,aAAa,MAAM;AACnB,WAAK,UAAU,IAAI,mBAAmB;AAAA,IAC1C,OAAO;AACH,WAAK,UAAU,OAAO,mBAAmB;AAAA,IAC7C;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,yBAA0B,MAAa,UAAiB,UAAiB;AACrE,UAAM,UAAU,KAAK,gBAAgB,IAAI,EAAE;AAC3C,IAAC,WAAW,QAAQ,KAAK,MAAM,UAAU,QAAQ;AAAA,EACrD;AAAA,EAEA,oBAAqB;AAEjB,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;AAAA,EAEV;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var n=(i,t)=>o(i,"name",{value:t,configurable:!0});var r=class i 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,u){let s=this[`handleChange_${t}`];s&&s.call(this,e,u)}connectedCallback(){this.render()}static define(){if("customElements"in window)return customElements.define(i.TAG||"substrate-button",i)}render(){}};export{r as SubstrateButton};
|
|
2
|
+
//# sourceMappingURL=client.min.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client.ts"],
|
|
4
|
+
"sourcesContent": ["// for docuement.querySelector\ndeclare global {\n interface HTMLElementTagNameMap {\n 'substrate-button': SubstrateButton\n }\n}\n\n/**\n * This is the lightweight version for browsers + server-side rendering.\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 // connect event listeners\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 // noop\n }\n}\n\n"],
|
|
5
|
+
"mappings": "+EAUO,IAAMA,EAAN,MAAMC,UAAwB,WAAY,CAVjD,MAUiD,CAAAC,EAAA,wBAE7C,OAAO,mBAAqB,CAAC,YAAa,WAAY,UAAU,EAChE,OAAO,IAAM,mBACb,YAEA,aAAe,CACX,MAAM,EACW,KAAK,aAAa,UAAU,IAC5B,MACb,WAAW,IAAM,CAEb,KAAK,SAAW,EACpB,EAAG,CAAC,EAER,KAAK,UAAa,KAAK,aAAa,WAAW,IAAM,KACrD,KAAK,YAAe,KAAK,aAAa,UAAU,IAAM,IAC1D,CAEA,IAAI,MAAuC,CACvC,OAAO,KAAK,QAAQ,IACxB,CAEA,IAAI,UAAoB,CACpB,MAAO,CAAC,CAAE,KAAK,QAAQ,aAAa,UAAU,CAClD,CAEA,IAAI,SAAUC,EAAuB,CAC5BA,GAID,KAAK,QAAQ,aAAa,WAAY,EAAE,EACxC,KAAK,QAAQ,aAAa,gBAAiB,MAAM,IAJjD,KAAK,iBAAiB,UAAU,EAChC,K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Q,CAC5D,CAEA,sBAAuBE,EAAGF,EAAkB,CACpCA,IAAa,KACb,KAAK,UAAU,IAAI,mBAAmB,EAEtC,KAAK,UAAU,OAAO,mBAAmB,CAEjD,CAYA,yBAA0BF,EAAaK,EAAiBH,EAAiB,CACrE,IAAMI,EAAU,KAAK,gBAAgBN,CAAI,EAAE,EAC1CM,GAAWA,EAAQ,KAAK,KAAMD,EAAUH,CAAQ,CACrD,CAEA,mBAAqB,CAEjB,KAAK,OAAO,CAChB,CAEA,OAAO,QAAU,CACb,GAAM,mBAAoB,OAE1B,OAAO,eAAe,OAClBP,EAAgB,KAAO,mBACvBA,CACJ,CACJ,CAEA,QAAU,CAEV,CACJ",
|
|
6
|
+
"names": ["SubstrateButton", "_SubstrateButton", "__name", "disabledValue", "i", "value", "name", "_oldValue", "newValue", "_old", "_", "oldValue", "handler"]
|
|
7
|
+
}
|
package/dist/html.cjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var html_exports = {};
|
|
21
|
+
__export(html_exports, {
|
|
22
|
+
html: () => html
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(html_exports);
|
|
25
|
+
function html(attrs, textContent) {
|
|
26
|
+
const {
|
|
27
|
+
type,
|
|
28
|
+
autofocus,
|
|
29
|
+
tabindex,
|
|
30
|
+
disabled,
|
|
31
|
+
classes
|
|
32
|
+
} = attrs;
|
|
33
|
+
const _classes = new Set(classes);
|
|
34
|
+
_classes.add("substrate-button");
|
|
35
|
+
const arr = Array.from(_classes);
|
|
36
|
+
const btnProps = [
|
|
37
|
+
arr.length ? `class="${arr.filter(Boolean).join(" ")}"` : "",
|
|
38
|
+
disabled ? "disabled" : "",
|
|
39
|
+
autofocus ? "autofocus" : "",
|
|
40
|
+
type ? `type="${type}"` : "",
|
|
41
|
+
tabindex ? `tabindex="${tabindex}"` : 'tabindex="0"',
|
|
42
|
+
'role="button"'
|
|
43
|
+
].filter(Boolean).join(" ");
|
|
44
|
+
return `<button ${btnProps}>
|
|
45
|
+
${textContent}
|
|
46
|
+
</button>`;
|
|
47
|
+
}
|
|
48
|
+
__name(html, "html");
|
|
49
|
+
//# sourceMappingURL=html.cjs.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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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
|
+
}
|