@substrate-system/button 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +121 -0
- package/README.md +146 -0
- package/dist/index.cjs +172 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.css +121 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +153 -0
- package/dist/index.js.map +7 -0
- package/dist/index.min.css +2 -0
- package/dist/index.min.js +4 -0
- package/dist/index.min.js.map +7 -0
- package/dist/meta.json +30 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# PolyForm Small Business License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/small-business/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree
|
|
8
|
+
to them as both strict obligations and conditions to all
|
|
9
|
+
your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the
|
|
14
|
+
software to do everything you might do with the software
|
|
15
|
+
that would otherwise infringe the licensor's copyright
|
|
16
|
+
in it for any permitted purpose. However, you may
|
|
17
|
+
only distribute the software according to [Distribution
|
|
18
|
+
License](#distribution-license) and make changes or new works
|
|
19
|
+
based on the software according to [Changes and New Works
|
|
20
|
+
License](#changes-and-new-works-license).
|
|
21
|
+
|
|
22
|
+
## Distribution License
|
|
23
|
+
|
|
24
|
+
The licensor grants you an additional copyright license
|
|
25
|
+
to distribute copies of the software. Your license
|
|
26
|
+
to distribute covers distributing the software with
|
|
27
|
+
changes and new works permitted by [Changes and New Works
|
|
28
|
+
License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of
|
|
33
|
+
the software from you also gets a copy of these terms or the
|
|
34
|
+
URL for them above, as well as copies of any plain-text lines
|
|
35
|
+
beginning with `Required Notice:` that the licensor provided
|
|
36
|
+
with the software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Nick Thomas. (https://nichoth.com)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to
|
|
43
|
+
make changes and new works based on the software for any
|
|
44
|
+
permitted purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Fair Use
|
|
53
|
+
|
|
54
|
+
You may have "fair use" rights for the software under the
|
|
55
|
+
law. These terms do not limit them.
|
|
56
|
+
|
|
57
|
+
## Small Business
|
|
58
|
+
|
|
59
|
+
Use of the software for the benefit of your company is use for
|
|
60
|
+
a permitted purpose if your company has fewer than 100 total
|
|
61
|
+
individuals working as employees and independent contractors,
|
|
62
|
+
and less than 1,000,000 USD (2019) total revenue in the prior
|
|
63
|
+
tax year. Adjust this revenue threshold for inflation according
|
|
64
|
+
to the United States Bureau of Labor Statistics' consumer price
|
|
65
|
+
index for all urban consumers, U.S. city average, for all items,
|
|
66
|
+
not seasonally adjusted, with 1982–1984=100 reference base.
|
|
67
|
+
|
|
68
|
+
## No Other Rights
|
|
69
|
+
|
|
70
|
+
These terms do not allow you to sublicense or transfer any of
|
|
71
|
+
your licenses to anyone else, or prevent the licensor from
|
|
72
|
+
granting licenses to anyone else. These terms do not imply
|
|
73
|
+
any other licenses.
|
|
74
|
+
|
|
75
|
+
## Patent Defense
|
|
76
|
+
|
|
77
|
+
If you make any written claim that the software infringes or
|
|
78
|
+
contributes to infringement of any patent, your patent license
|
|
79
|
+
for the software granted under these terms ends immediately. If
|
|
80
|
+
your company makes such a claim, your patent license ends
|
|
81
|
+
immediately for work on behalf of your company.
|
|
82
|
+
|
|
83
|
+
## Violations
|
|
84
|
+
|
|
85
|
+
The first time you are notified in writing that you have
|
|
86
|
+
violated any of these terms, or done anything with the software
|
|
87
|
+
not covered by your licenses, your licenses can nonetheless
|
|
88
|
+
continue if you come into full compliance with these terms,
|
|
89
|
+
and take practical steps to correct past violations, within
|
|
90
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
91
|
+
end immediately.
|
|
92
|
+
|
|
93
|
+
## No Liability
|
|
94
|
+
|
|
95
|
+
***As far as the law allows, the software comes as is, without
|
|
96
|
+
any warranty or condition, and the licensor will not be liable
|
|
97
|
+
to you for any damages arising out of these terms or the use
|
|
98
|
+
or nature of the software, under any kind of legal claim.***
|
|
99
|
+
|
|
100
|
+
## Definitions
|
|
101
|
+
|
|
102
|
+
The **licensor** is the individual or entity offering these
|
|
103
|
+
terms, and the **software** is the software the licensor makes
|
|
104
|
+
available under these terms.
|
|
105
|
+
|
|
106
|
+
**You** refers to the individual or entity agreeing to these
|
|
107
|
+
terms.
|
|
108
|
+
|
|
109
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
110
|
+
or other kind of organization that you work for, plus all
|
|
111
|
+
organizations that have control over, are under the control of,
|
|
112
|
+
or are under common control with that organization. **Control**
|
|
113
|
+
means ownership of substantially all the assets of an entity,
|
|
114
|
+
or the power to direct its management and policies by vote,
|
|
115
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
116
|
+
|
|
117
|
+
**Your licenses** are all the licenses granted to you for the
|
|
118
|
+
software under these terms.
|
|
119
|
+
|
|
120
|
+
**Use** means anything you do with the software requiring one
|
|
121
|
+
of your licenses.
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# button
|
|
2
|
+

|
|
3
|
+
[](README.md)
|
|
4
|
+
[](README.md)
|
|
5
|
+
[](package.json)
|
|
6
|
+
[](https://packagephobia.com/result?p=@substrate-system/button)
|
|
7
|
+
[](https://semver.org/)
|
|
8
|
+
[](./CHANGELOG.md)
|
|
9
|
+

|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
A button web component, with a visual "loading" state.
|
|
14
|
+
|
|
15
|
+
[See a live demo](https://substrate-system.github.io/button/)
|
|
16
|
+
|
|
17
|
+
<!-- toc -->
|
|
18
|
+
|
|
19
|
+
- [install](#install)
|
|
20
|
+
- [API](#api)
|
|
21
|
+
* [ESM](#esm)
|
|
22
|
+
* [Common JS](#common-js)
|
|
23
|
+
- [CSS](#css)
|
|
24
|
+
* [Import CSS](#import-css)
|
|
25
|
+
* [Customize CSS via some variables](#customize-css-via-some-variables)
|
|
26
|
+
- [use](#use)
|
|
27
|
+
* [JS](#js)
|
|
28
|
+
* [HTML](#html)
|
|
29
|
+
* [pre-built](#pre-built)
|
|
30
|
+
|
|
31
|
+
<!-- tocstop -->
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm i -S @substrate-system/button
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Dependencies
|
|
40
|
+
|
|
41
|
+
Depends on these CSS variables, which are exposed in the
|
|
42
|
+
[@substrate-system/css](https://github.com/substrate-system/css) package.
|
|
43
|
+
|
|
44
|
+
```css
|
|
45
|
+
:root {
|
|
46
|
+
--substrate-medium: #999da0;
|
|
47
|
+
--substrate-button-text: #36393d;
|
|
48
|
+
--substrate-primary: #36393d;
|
|
49
|
+
--substrate-font: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
|
|
50
|
+
--substrate-button-background: #f5f5f5;
|
|
51
|
+
--substrate-button-shadow: #00000054;
|
|
52
|
+
--substrate-button-background-focus: #ededed;
|
|
53
|
+
--substrate-button-background-hover: #e6e6e6;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
This exposes ESM and common JS via [package.json `exports` field](https://nodejs.org/api/packages.html#exports).
|
|
60
|
+
|
|
61
|
+
### ESM
|
|
62
|
+
```js
|
|
63
|
+
import { SubstrateButton } from '@substrate-system/button'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Common JS
|
|
67
|
+
```js
|
|
68
|
+
const { SubstrateButton } = require('@substrate-system/button')
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## CSS
|
|
72
|
+
|
|
73
|
+
### Import CSS
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import '@substrate-system/button/css'
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Or minified:
|
|
80
|
+
```js
|
|
81
|
+
import '@substrate-system/button/css/min'
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Customize CSS via some variables
|
|
85
|
+
|
|
86
|
+
```css
|
|
87
|
+
substrate-button {
|
|
88
|
+
--example: pink;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Use
|
|
93
|
+
|
|
94
|
+
You will need to set a name for this custom element.
|
|
95
|
+
|
|
96
|
+
> [!CAUTION]
|
|
97
|
+
> If you change the name of the web component, it will break the CSS.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
To use the default, call
|
|
101
|
+
`.define()`:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
import { SubstrateButton } from '@substrate-system/button'
|
|
105
|
+
|
|
106
|
+
// create a web component named `substrate-button`
|
|
107
|
+
SubstrateButton.define()
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Or override the `tag` property to change the tag name:
|
|
111
|
+
```js
|
|
112
|
+
import { SubstrateButton } from '@substrate-system/button'
|
|
113
|
+
|
|
114
|
+
// set a custom name
|
|
115
|
+
SubstrateButton.tag = 'cool-button'
|
|
116
|
+
|
|
117
|
+
SubstrateButton.define()
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### HTML
|
|
121
|
+
```html
|
|
122
|
+
<div>
|
|
123
|
+
<substrate-button></substrate-button>
|
|
124
|
+
</div>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### pre-built
|
|
128
|
+
This package exposes minified JS and CSS files too. Copy them to a location that is
|
|
129
|
+
accessible to your web server, then link to them in HTML.
|
|
130
|
+
|
|
131
|
+
#### copy
|
|
132
|
+
```sh
|
|
133
|
+
cp ./node_modules/@substrate-system/button/dist/index.min.js ./public/substrate-button.min.js
|
|
134
|
+
cp ./node_modules/@substrate-system/button/dist/style.min.css ./public/substrate-button.css
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### HTML
|
|
138
|
+
```html
|
|
139
|
+
<head>
|
|
140
|
+
<link rel="stylesheet" href="./substrate-button.css">
|
|
141
|
+
</head>
|
|
142
|
+
<body>
|
|
143
|
+
<!-- ... -->
|
|
144
|
+
<script type="module" src="./substrate-button.min.js"></script>
|
|
145
|
+
</body>
|
|
146
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
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 index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
SubstrateButton: () => SubstrateButton
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(index_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
|
+
this.disabled = disabled !== null;
|
|
37
|
+
this.autofocus = this.getAttribute("autofocus") !== null;
|
|
38
|
+
this._isSpinning = this.getAttribute("spinning") !== null;
|
|
39
|
+
}
|
|
40
|
+
get form() {
|
|
41
|
+
return this.button?.form;
|
|
42
|
+
}
|
|
43
|
+
get disabled() {
|
|
44
|
+
return !!this.button?.hasAttribute("disabled");
|
|
45
|
+
}
|
|
46
|
+
get type() {
|
|
47
|
+
return this.button?.getAttribute("type");
|
|
48
|
+
}
|
|
49
|
+
get tabindex() {
|
|
50
|
+
const i = this.button?.getAttribute("tabindex");
|
|
51
|
+
if (!i) return 0;
|
|
52
|
+
return parseInt(i);
|
|
53
|
+
}
|
|
54
|
+
get spinning() {
|
|
55
|
+
return this._isSpinning;
|
|
56
|
+
}
|
|
57
|
+
set spinning(value) {
|
|
58
|
+
if (value) this.setAttribute("spinning", "");
|
|
59
|
+
else this.removeAttribute("spinning");
|
|
60
|
+
}
|
|
61
|
+
set type(value) {
|
|
62
|
+
this._setAttribute("type", value);
|
|
63
|
+
}
|
|
64
|
+
set disabled(disabledValue) {
|
|
65
|
+
if (!disabledValue) {
|
|
66
|
+
this._removeAttribute("disabled");
|
|
67
|
+
this.button?.setAttribute("aria-disabled", "false");
|
|
68
|
+
} else {
|
|
69
|
+
this.button?.setAttribute("disabled", "");
|
|
70
|
+
this.button?.setAttribute("aria-disabled", "true");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
get autofocus() {
|
|
74
|
+
return !!this.button?.hasAttribute("autofocus");
|
|
75
|
+
}
|
|
76
|
+
set autofocus(value) {
|
|
77
|
+
if (value) {
|
|
78
|
+
this._setAttribute("autofocus", value);
|
|
79
|
+
} else {
|
|
80
|
+
this._removeAttribute("autofocus");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
_setAttribute(name, value) {
|
|
84
|
+
if (value === false) {
|
|
85
|
+
this._removeAttribute(name);
|
|
86
|
+
this.button?.removeAttribute(name);
|
|
87
|
+
} else {
|
|
88
|
+
if (value === true) {
|
|
89
|
+
return this.button?.setAttribute(name, "");
|
|
90
|
+
}
|
|
91
|
+
if (value === null) {
|
|
92
|
+
return this._removeAttribute(name);
|
|
93
|
+
}
|
|
94
|
+
this.button?.setAttribute(name, value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Remove from `this` and also button child.
|
|
99
|
+
*/
|
|
100
|
+
_removeAttribute(name) {
|
|
101
|
+
this.removeAttribute(name);
|
|
102
|
+
this.button?.removeAttribute(name);
|
|
103
|
+
}
|
|
104
|
+
get button() {
|
|
105
|
+
return this.querySelector("button");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Handle 'autofocus' attribute changes
|
|
109
|
+
* @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}
|
|
110
|
+
*
|
|
111
|
+
* @param {string} oldValue The old attribute value
|
|
112
|
+
* @param {string} newValue The new attribute value
|
|
113
|
+
*/
|
|
114
|
+
handleChange_autofocus(_oldValue, newValue) {
|
|
115
|
+
this._setAttribute("autofocus", newValue);
|
|
116
|
+
}
|
|
117
|
+
handleChange_disabled(_old, newValue) {
|
|
118
|
+
this._setAttribute("disbaled", newValue);
|
|
119
|
+
}
|
|
120
|
+
handleChange_spinning(_, newValue) {
|
|
121
|
+
if (newValue !== null) {
|
|
122
|
+
this.classList.add("substrate-loading");
|
|
123
|
+
} else {
|
|
124
|
+
this.classList.remove("substrate-loading");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Runs when the value of an attribute is changed.
|
|
129
|
+
*
|
|
130
|
+
* Should add methods to this class like `handleChange_class`, to
|
|
131
|
+
* listen for changes to `class` attribute.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} name The attribute name
|
|
134
|
+
* @param {string} oldValue The old attribute value
|
|
135
|
+
* @param {string} newValue The new attribute value
|
|
136
|
+
*/
|
|
137
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
138
|
+
const handler = this[`handleChange_${name}`];
|
|
139
|
+
handler && handler.call(this, oldValue, newValue);
|
|
140
|
+
}
|
|
141
|
+
connectedCallback() {
|
|
142
|
+
this.render();
|
|
143
|
+
}
|
|
144
|
+
static define() {
|
|
145
|
+
if (!("customElements" in window)) return;
|
|
146
|
+
return customElements.define(
|
|
147
|
+
SubstrateButton.tag || "substrate-button",
|
|
148
|
+
SubstrateButton
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
render() {
|
|
152
|
+
const {
|
|
153
|
+
type,
|
|
154
|
+
autofocus,
|
|
155
|
+
tabindex,
|
|
156
|
+
disabled
|
|
157
|
+
} = this;
|
|
158
|
+
const classes = ["substrate-button"];
|
|
159
|
+
const btnProps = [
|
|
160
|
+
`class="${classes.join(" ")}"`,
|
|
161
|
+
disabled ? "disabled" : "",
|
|
162
|
+
autofocus ? "autofocus" : "",
|
|
163
|
+
type ? `type="${this.type}"` : "",
|
|
164
|
+
tabindex ? `tabindex=${tabindex}` : "0",
|
|
165
|
+
'role="button"'
|
|
166
|
+
].filter(Boolean).join(" ");
|
|
167
|
+
this.innerHTML = `<button ${btnProps}>
|
|
168
|
+
${this.innerHTML}
|
|
169
|
+
</button>`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 this.disabled = disabled !== null\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 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 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 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 _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 mean 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._setAttribute('disbaled', 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}` : '0',\n 'role=\"button\"'\n ]).filter(Boolean).join(' ')\n\n this.innerHTML = `<button ${btnProps}>\n ${this.innerHTML}\n </button>`\n }\n}\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,yBAA0B,MAAa,UAAiB,UAAiB;AACrE,UAAM,UAAU,KAAK,gBAAgB,IAAI,EAAE;AAC3C,IAAC,WAAW,QAAQ,KAAK,MAAM,UAAU,QAAQ;AAAA,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,YAAY,QAAQ,KAAK;AAAA,MACpC;AAAA,IACJ,EAAG,OAAO,OAAO,EAAE,KAAK,GAAG;AAE3B,SAAK,YAAY,WAAW,QAAQ;AAAA,cAC9B,KAAK,SAAS;AAAA;AAAA,EAExB;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
@keyframes spin {
|
|
2
|
+
from {
|
|
3
|
+
transform: rotate(0deg);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
to {
|
|
7
|
+
transform: rotate(360deg);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@keyframes spinner {
|
|
12
|
+
to {transform: rotate(360deg);}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@keyframes substrate-button-activate {
|
|
16
|
+
0% {
|
|
17
|
+
transform: scale(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
50% {
|
|
21
|
+
transform: scale(0.95);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
100% {
|
|
25
|
+
transform: scale(1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
substrate-button {
|
|
30
|
+
display: inline-block;
|
|
31
|
+
user-select: none;
|
|
32
|
+
min-width: 8rem;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
substrate-button.substrate-loading {
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
substrate-button.substrate-loading button {
|
|
40
|
+
color: transparent;
|
|
41
|
+
transition: all 0.3s ease;
|
|
42
|
+
pointer-events: none;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
:is(substrate-button.substrate-loading button):hover {
|
|
46
|
+
color: transparent;
|
|
47
|
+
background: var(--substrate-medium, #999da0)!important;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
:is(substrate-button.substrate-loading button)::after {
|
|
51
|
+
content: "";
|
|
52
|
+
background: transparent;
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
position: absolute;
|
|
55
|
+
width: 16px;
|
|
56
|
+
height: 16px;
|
|
57
|
+
inset: 0;
|
|
58
|
+
margin: auto;
|
|
59
|
+
border-radius: 50%;
|
|
60
|
+
border-top: 2px solid black;
|
|
61
|
+
border-right: 2px solid transparent;
|
|
62
|
+
animation: spinner 0.6s linear infinite;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
substrate-button button {
|
|
66
|
+
border: 1px solid black;
|
|
67
|
+
color: var(--substrate-button-text, var(--substrate-primary, #36393d));
|
|
68
|
+
width: 100%;
|
|
69
|
+
font-family: var(--substrate-font, 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif);
|
|
70
|
+
padding: 0.5em 1em;
|
|
71
|
+
position: relative;
|
|
72
|
+
background-color: var(--substrate-button-background, transparent);
|
|
73
|
+
transition: background-color 0.3s ease, color 0.3s ease;
|
|
74
|
+
box-shadow: 0 1px 2px var(--substrate-button-shadow);
|
|
75
|
+
appearance: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:is(substrate-button button):focus {
|
|
79
|
+
background-color: var(--substrate-button-background-focus, #f7f7f5);
|
|
80
|
+
outline: none;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[disabled]:is(substrate-button button),:is(substrate-button button):active {
|
|
84
|
+
color: var(--substrate-medium, #999da0);
|
|
85
|
+
background-color: var(--substrate-button-background-disabled, #f7f7f5);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
:is(substrate-button button):active {
|
|
89
|
+
animation-duration: .2s;
|
|
90
|
+
animation-name: substrate-button-activate;
|
|
91
|
+
transition-timing-function: ease;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
[type="icon"]:is(substrate-button button) button {
|
|
95
|
+
background: none;
|
|
96
|
+
box-shadow: none;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
[type="icon"]:is(substrate-button button) substrate-icon {
|
|
100
|
+
position: absolute;
|
|
101
|
+
top: 50%;
|
|
102
|
+
left: 50%;
|
|
103
|
+
transform: translate(-50%, -50%);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
:is(substrate-button button):not([disabled]):hover {
|
|
107
|
+
background-color: var(--substrate-button-background-hover, #e6e6e6)!important;
|
|
108
|
+
cursor: pointer;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
substrate-button[aria-disabled="true"] {
|
|
112
|
+
user-select: none;
|
|
113
|
+
background-color: transparent;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
substrate-button[aria-disabled="true"] button {
|
|
117
|
+
user-select: none;
|
|
118
|
+
background-color: transparent
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNyYy9pbmRleC5jc3MiXSwibmFtZXMiOltdLCJtYXBwaW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xuXG4gICAgICAgICYgYnV0dG9uIHtcbiAgICAgICAgICAgIGNvbG9yOiB0cmFuc3BhcmVudDtcbiAgICAgICAgICAgIHRyYW5zaXRpb246IGFsbCAwLjNzIGVhc2U7XG4gICAgICAgICAgICBwb2ludGVyLWV2ZW50czogbm9uZTtcblxuICAgICAgICAgICAgJjpob3ZlciB7XG4gICAgICAgICAgICAgICAgY29sb3I6IHRyYW5zcGFyZW50O1xuICAgICAgICAgICAgICAgIGJhY2tncm91bmQ6IHZhcigtLXN1YnN0cmF0ZS1tZWRpdW0sICM5OTlkYTApIWltcG9ydGFudDtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgJjo6YWZ0ZXIge1xuICAgICAgICAgICAgICAgIGNvbnRlbnQ6IFwiXCI7XG4gICAgICAgICAgICAgICAgYmFja2dyb3VuZDogdHJhbnNwYXJlbnQ7XG4gICAgICAgICAgICAgICAgYm94LXNpemluZzogYm9yZGVyLWJveDtcbiAgICAgICAgICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7XG4gICAgICAgICAgICAgICAgd2lkdGg6IDE2cHg7XG4gICAgICAgICAgICAgICAgaGVpZ2h0OiAxNnB4O1xuICAgICAgICAgICAgICAgIGluc2V0OiAwO1xuICAgICAgICAgICAgICAgIG1hcmdpbjogYXV0bztcbiAgICAgICAgICAgICAgICBib3JkZXItcmFkaXVzOiA1MCU7XG4gICAgICAgICAgICAgICAgYm9yZGVyLXRvcDogMnB4IHNvbGlkIGJsYWNrO1xuICAgICAgICAgICAgICAgIGJvcmRlci1yaWdodDogMnB4IHNvbGlkIHRyYW5zcGFyZW50O1xuICAgICAgICAgICAgICAgIGFuaW1hdGlvbjogc3Bpbm5lciAwLjZzIGxpbmVhciBpbmZpbml0ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgICYgYnV0dG9uIHtcbiAgICAgICAgYm9yZGVyOiAxcHggc29saWQgYmxhY2s7XG4gICAgICAgIGNvbG9yOiB2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G5cbiAgICAgICAgJjphY3RpdmUge1xuICAgICAgICAgICAgYW5pbWF0aW9uLWR1cmF0aW9uOiAuMnM7XG4gICAgICAgICAgICBhbmltYXRpb24tbmFtZTogc3Vic3RyYXRlLWJ1dHRvbi1hY3RpdmF0ZTtcbiAgICAgICAgICAgIHRyYW5zaXRpb24tdGltaW5nLWZ1bmN0aW9uOiBlYXNlO1xuICAgICAgICB9XG5cbiAgICAgICAgJlt0eXBlPVwiaWNvblwiXSB7XG4gICAgICAgICAgICAmIGJ1dHRvbiB7XG4gICAgICAgICAgICAgICAgYmFja2dyb3VuZDogbm9uZTtcbiAgICAgICAgICAgICAgICBib3gtc2hhZG93OiBub25lO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAmIHN1YnN0cmF0ZS1pY29uIHtcbiAgICAgICAgICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7XG4gICAgICAgICAgICAgICAgdG9wOiA1MCU7XG4gICAgICAgICAgICAgICAgbGVmdDogNTAlO1xuICAgICAgICAgICAgICAgIHRyYW5zZm9ybTogdHJhbnNsYXRlKC01MCUsIC01MCUpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgJjpub3QoW2Rpc2FibGVkXSk6aG92ZXIge1xuICAgICAgICAgICAgYmFja2dyb3VuZC1jb2xvcjogdmFyKC0tc3Vic3RyYXRlLWJ1dHRvbi1iYWNrZ3JvdW5kLWhvdmVyLCAjZTZlNmU2KSFpbXBvcnRhbnQ7XG4gICAgICAgICAgICBjdXJzb3I6IHBvaW50ZXI7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAmW2FyaWEtZGlzYWJsZWQ9XCJ0cnVlXCJdIHtcbiAgICAgICAgdXNlci1zZWxlY3Q6IG5vbmU7XG4gICAgICAgIGJhY2tncm91bmQtY29sb3I6IHRyYW5zcGFyZW50O1xuXG4gICAgICAgICYgYnV0dG9uIHtcbiAgICAgICAgICAgIHVzZXItc2VsZWN0OiBub25lO1xuICAgICAgICAgICAgYmFja2dyb3VuZC1jb2xvcjogdHJhbnNwYXJlbnRcbiAgICAgICAgfVxuICAgIH1cbn1cbiAgIl19 */
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
get type(): string | null | undefined;
|
|
14
|
+
get tabindex(): number;
|
|
15
|
+
get spinning(): boolean;
|
|
16
|
+
set spinning(value: boolean);
|
|
17
|
+
set type(value: string);
|
|
18
|
+
set disabled(disabledValue: boolean);
|
|
19
|
+
get autofocus(): boolean;
|
|
20
|
+
set autofocus(value: boolean);
|
|
21
|
+
_setAttribute(name: string, value: boolean | string | null): void;
|
|
22
|
+
/**
|
|
23
|
+
* Remove from `this` and also button child.
|
|
24
|
+
*/
|
|
25
|
+
_removeAttribute(name: string): void;
|
|
26
|
+
get button(): HTMLButtonElement | null;
|
|
27
|
+
/**
|
|
28
|
+
* Handle 'autofocus' attribute changes
|
|
29
|
+
* @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}
|
|
30
|
+
*
|
|
31
|
+
* @param {string} oldValue The old attribute value
|
|
32
|
+
* @param {string} newValue The new attribute value
|
|
33
|
+
*/
|
|
34
|
+
handleChange_autofocus(_oldValue: string, newValue: string): void;
|
|
35
|
+
handleChange_disabled(_old: any, newValue: boolean | string): void;
|
|
36
|
+
handleChange_spinning(_: any, newValue: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* Runs when the value of an attribute is changed.
|
|
39
|
+
*
|
|
40
|
+
* Should add methods to this class like `handleChange_class`, to
|
|
41
|
+
* listen for changes to `class` attribute.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} name The attribute name
|
|
44
|
+
* @param {string} oldValue The old attribute value
|
|
45
|
+
* @param {string} newValue The new attribute value
|
|
46
|
+
*/
|
|
47
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
48
|
+
connectedCallback(): void;
|
|
49
|
+
static define(): void;
|
|
50
|
+
render(): void;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;;IAUnB,IAAI,IAAI,IAAI,eAAe,GAAC,SAAS,GAAC,IAAI,CAEzC;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;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,QAAQ,CAAE,aAAa,EAAC,OAAO,EAQlC;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,SAAS,CAAE,KAAK,EAAC,OAAO,EAM3B;IAED,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;IAIpD,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;CAuBT"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
this.disabled = disabled !== null;
|
|
15
|
+
this.autofocus = this.getAttribute("autofocus") !== null;
|
|
16
|
+
this._isSpinning = this.getAttribute("spinning") !== null;
|
|
17
|
+
}
|
|
18
|
+
get form() {
|
|
19
|
+
return this.button?.form;
|
|
20
|
+
}
|
|
21
|
+
get disabled() {
|
|
22
|
+
return !!this.button?.hasAttribute("disabled");
|
|
23
|
+
}
|
|
24
|
+
get type() {
|
|
25
|
+
return this.button?.getAttribute("type");
|
|
26
|
+
}
|
|
27
|
+
get tabindex() {
|
|
28
|
+
const i = this.button?.getAttribute("tabindex");
|
|
29
|
+
if (!i) return 0;
|
|
30
|
+
return parseInt(i);
|
|
31
|
+
}
|
|
32
|
+
get spinning() {
|
|
33
|
+
return this._isSpinning;
|
|
34
|
+
}
|
|
35
|
+
set spinning(value) {
|
|
36
|
+
if (value) this.setAttribute("spinning", "");
|
|
37
|
+
else this.removeAttribute("spinning");
|
|
38
|
+
}
|
|
39
|
+
set type(value) {
|
|
40
|
+
this._setAttribute("type", value);
|
|
41
|
+
}
|
|
42
|
+
set disabled(disabledValue) {
|
|
43
|
+
if (!disabledValue) {
|
|
44
|
+
this._removeAttribute("disabled");
|
|
45
|
+
this.button?.setAttribute("aria-disabled", "false");
|
|
46
|
+
} else {
|
|
47
|
+
this.button?.setAttribute("disabled", "");
|
|
48
|
+
this.button?.setAttribute("aria-disabled", "true");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
get autofocus() {
|
|
52
|
+
return !!this.button?.hasAttribute("autofocus");
|
|
53
|
+
}
|
|
54
|
+
set autofocus(value) {
|
|
55
|
+
if (value) {
|
|
56
|
+
this._setAttribute("autofocus", value);
|
|
57
|
+
} else {
|
|
58
|
+
this._removeAttribute("autofocus");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
_setAttribute(name, value) {
|
|
62
|
+
if (value === false) {
|
|
63
|
+
this._removeAttribute(name);
|
|
64
|
+
this.button?.removeAttribute(name);
|
|
65
|
+
} else {
|
|
66
|
+
if (value === true) {
|
|
67
|
+
return this.button?.setAttribute(name, "");
|
|
68
|
+
}
|
|
69
|
+
if (value === null) {
|
|
70
|
+
return this._removeAttribute(name);
|
|
71
|
+
}
|
|
72
|
+
this.button?.setAttribute(name, value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Remove from `this` and also button child.
|
|
77
|
+
*/
|
|
78
|
+
_removeAttribute(name) {
|
|
79
|
+
this.removeAttribute(name);
|
|
80
|
+
this.button?.removeAttribute(name);
|
|
81
|
+
}
|
|
82
|
+
get button() {
|
|
83
|
+
return this.querySelector("button");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Handle 'autofocus' attribute changes
|
|
87
|
+
* @see {@link https://gomakethings.com/how-to-detect-when-attributes-change-on-a-web-component/#organizing-your-code Go Make Things article}
|
|
88
|
+
*
|
|
89
|
+
* @param {string} oldValue The old attribute value
|
|
90
|
+
* @param {string} newValue The new attribute value
|
|
91
|
+
*/
|
|
92
|
+
handleChange_autofocus(_oldValue, newValue) {
|
|
93
|
+
this._setAttribute("autofocus", newValue);
|
|
94
|
+
}
|
|
95
|
+
handleChange_disabled(_old, newValue) {
|
|
96
|
+
this._setAttribute("disbaled", newValue);
|
|
97
|
+
}
|
|
98
|
+
handleChange_spinning(_, newValue) {
|
|
99
|
+
if (newValue !== null) {
|
|
100
|
+
this.classList.add("substrate-loading");
|
|
101
|
+
} else {
|
|
102
|
+
this.classList.remove("substrate-loading");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Runs when the value of an attribute is changed.
|
|
107
|
+
*
|
|
108
|
+
* Should add methods to this class like `handleChange_class`, to
|
|
109
|
+
* listen for changes to `class` attribute.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} name The attribute name
|
|
112
|
+
* @param {string} oldValue The old attribute value
|
|
113
|
+
* @param {string} newValue The new attribute value
|
|
114
|
+
*/
|
|
115
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
116
|
+
const handler = this[`handleChange_${name}`];
|
|
117
|
+
handler && handler.call(this, oldValue, newValue);
|
|
118
|
+
}
|
|
119
|
+
connectedCallback() {
|
|
120
|
+
this.render();
|
|
121
|
+
}
|
|
122
|
+
static define() {
|
|
123
|
+
if (!("customElements" in window)) return;
|
|
124
|
+
return customElements.define(
|
|
125
|
+
SubstrateButton.tag || "substrate-button",
|
|
126
|
+
SubstrateButton
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
render() {
|
|
130
|
+
const {
|
|
131
|
+
type,
|
|
132
|
+
autofocus,
|
|
133
|
+
tabindex,
|
|
134
|
+
disabled
|
|
135
|
+
} = this;
|
|
136
|
+
const classes = ["substrate-button"];
|
|
137
|
+
const btnProps = [
|
|
138
|
+
`class="${classes.join(" ")}"`,
|
|
139
|
+
disabled ? "disabled" : "",
|
|
140
|
+
autofocus ? "autofocus" : "",
|
|
141
|
+
type ? `type="${this.type}"` : "",
|
|
142
|
+
tabindex ? `tabindex=${tabindex}` : "0",
|
|
143
|
+
'role="button"'
|
|
144
|
+
].filter(Boolean).join(" ");
|
|
145
|
+
this.innerHTML = `<button ${btnProps}>
|
|
146
|
+
${this.innerHTML}
|
|
147
|
+
</button>`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
SubstrateButton
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 this.disabled = disabled !== null\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 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 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 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 _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 mean 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._setAttribute('disbaled', 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}` : '0',\n 'role=\"button\"'\n ]).filter(Boolean).join(' ')\n\n this.innerHTML = `<button ${btnProps}>\n ${this.innerHTML}\n </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,SAAK,WAAW,aAAa;AAC7B,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,OAA8B;AAC9B,WAAO,KAAK,QAAQ,aAAa,MAAM;AAAA,EAC3C;AAAA,EAEA,IAAI,WAAmB;AACnB,UAAM,IAAI,KAAK,QAAQ,aAAa,UAAU;AAC9C,QAAI,CAAC,EAAG,QAAO;AACf,WAAO,SAAS,CAA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AAA;AAAA,EAExB;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}@keyframes spinner{to{transform:rotate(1turn)}}@keyframes substrate-button-activate{0%{transform:scale(1)}50%{transform:scale(.95)}to{transform:scale(1)}}substrate-button{display:inline-block;min-width:8rem;user-select:none}substrate-button.substrate-loading{pointer-events:none}substrate-button.substrate-loading button{color:transparent;pointer-events:none;transition:all .3s ease}:is(substrate-button.substrate-loading button):hover{background:var(--substrate-medium,#999da0)!important;color:transparent}:is(substrate-button.substrate-loading button):after{animation:spinner .6s linear infinite;background:transparent;border-radius:50%;border-right:2px solid transparent;border-top:2px solid #000;box-sizing:border-box;content:"";height:16px;inset:0;margin:auto;position:absolute;width:16px}substrate-button button{appearance:none;background-color:var(--substrate-button-background,transparent);border:1px solid #000;box-shadow:0 1px 2px var(--substrate-button-shadow);color:var(--substrate-button-text,var(--substrate-primary,#36393d));font-family:var(--substrate-font,"Gill Sans","Gill Sans MT",Calibri,"Trebuchet MS",sans-serif);padding:.5em 1em;position:relative;transition:background-color .3s ease,color .3s ease;width:100%}:is(substrate-button button):focus{background-color:var(--substrate-button-background-focus,#f7f7f5);outline:none}:is(substrate-button button):active,[disabled]:is(substrate-button button){background-color:var(--substrate-button-background-disabled,#f7f7f5);color:var(--substrate-medium,#999da0)}:is(substrate-button button):active{animation-duration:.2s;animation-name:substrate-button-activate;transition-timing-function:ease}[type=icon]:is(substrate-button button) button{background:none;box-shadow:none}[type=icon]:is(substrate-button button) substrate-icon{left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}:is(substrate-button button):not([disabled]):hover{background-color:var(--substrate-button-background-hover,#e6e6e6)!important;cursor:pointer}substrate-button[aria-disabled=true],substrate-button[aria-disabled=true] button{background-color:transparent;user-select:none}
|
|
2
|
+
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJ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gIGJhY2tncm91bmQ6IHZhcigtLXN1YnN0cmF0ZS1tZWRpdW0sICM5OTlkYTApIWltcG9ydGFudDtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgJjo6YWZ0ZXIge1xuICAgICAgICAgICAgICAgIGNvbnRlbnQ6IFwiXCI7XG4gICAgICAgICAgICAgICAgYmFja2dyb3VuZDogdHJhbnNwYXJlbnQ7XG4gICAgICAgICAgICAgICAgYm94LXNpemluZzogYm9yZGVyLWJveDtcbiAgICAgICAgICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7XG4gICAgICAgICAgICAgICAgd2lkdGg6IDE2cHg7XG4gICAgICAgICAgICAgICAgaGVpZ2h0OiAxNnB4O1xuICAgICAgICAgICAgICAgIGluc2V0OiAwO1xuICAgICAgICAgICAgICAgIG1hcmdpbjogYXV0bztcbiAgICAgICAgICAgICAgICBib3JkZXItcmFkaXVzOiA1MCU7XG4gICAgICAgICAgICAgICAgYm9yZGVyLXRvcDogMnB4IHNvbGlkIGJsYWNrO1xuICAgICAgICAgICAgICAgIGJvcmRlci1yaWdodDogMnB4IHNvbGlkIHRyYW5zcGFyZW50O1xuICAgICAgICAgICAgICAgIGFuaW1hdGlvbjogc3Bpbm5lciAwLjZzIGxpbmVhciBpbmZpbml0ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgICYgYnV0dG9uIHtcbiAgICAgICAgYm9yZGVyOiAxcHggc29saWQgYmxhY2s7XG4gICAgICAgIGNvbG9yOiB2YXIoLS1zdWJzdHJhdGUtYnV0dG9uLXRleHQsIHZhcigtLXN1YnN0cmF0ZS1wcmltYXJ5LCAjMzYzOTNkKSk7XG4gICAgICAgIHdpZHRoOiAxMDAlO1xuICAgICAgICBmb250LWZhbWlseTogdmFyKC0tc3Vic3RyYXRlLWZvbnQsICdHaWxsIFNhbnMnLCAnR2lsbCBTYW5zIE1UJywgQ2FsaWJyaSwgJ1RyZWJ1Y2hldCBNUycsIHNhbn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vblwiXSB7XG4gICAgICAgICAgICAmIGJ1dHRvbiB7XG4gICAgICAgICAgICAgICAgYmFja2dyb3VuZDogbm9uZTtcbiAgICAgICAgICAgICAgICBib3gtc2hhZG93OiBub25lO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAmIHN1YnN0cmF0ZS1pY29uIHtcbiAgICAgICAgICAgICAgICBwb3NpdGlvbjogYWJzb2x1dGU7XG4gICAgICAgICAgICAgICAgdG9wOiA1MCU7XG4gICAgICAgICAgICAgICAgbGVmdDogNTAlO1xuICAgICAgICAgICAgICAgIHRyYW5zZm9ybTogdHJhbnNsYXRlKC01MCUsIC01MCUpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgJjpub3QoW2Rpc2FibGVkXSk6aG92ZXIge1xuICAgICAgICAgICAgYmFja2dyb3VuZC1jb2xvcjogdmFyKC0tc3Vic3RyYXRlLWJ1dHRvbi1iYWNrZ3JvdW5kLWhvdmVyLCAjZTZlNmU2KSFpbXBvcnRhbnQ7XG4gICAgICAgICAgICBjdXJzb3I6IHBvaW50ZXI7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICAmW2FyaWEtZGlzYWJsZWQ9XCJ0cnVlXCJdIHtcbiAgICAgICAgdXNlci1zZWxlY3Q6IG5vbmU7XG4gICAgICAgIGJhY2tncm91bmQtY29sb3I6IHRyYW5zcGFyZW50O1xuXG4gICAgICAgICYgYnV0dG9uIHtcbiAgICAgICAgICAgIHVzZXItc2VsZWN0OiBub25lO1xuICAgICAgICAgICAgYmFja2dyb3VuZC1jb2xvcjogdHJhbnNwYXJlbnRcbiAgICAgICAgfVxuICAgIH1cbn1cbiAgIl19 */
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var b=Object.defineProperty;var r=(s,t)=>b(s,"name",{value:t,configurable:!0});var u=class s extends HTMLElement{static{r(this,"SubstrateButton")}static observedAttributes=["autofocus","disabled","spinning"];static tag="substrate-button";_isSpinning;constructor(){super();let t=this.getAttribute("disabled");this.disabled=t!==null,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")}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)}set disabled(t){t?(this.button?.setAttribute("disabled",""),this.button?.setAttribute("aria-disabled","true")):(this._removeAttribute("disabled"),this.button?.setAttribute("aria-disabled","false"))}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._setAttribute("disbaled",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}`:"0",'role="button"'].filter(Boolean).join(" ");this.innerHTML=`<button ${o}>
|
|
2
|
+
${this.innerHTML}
|
|
3
|
+
</button>`}};export{u as SubstrateButton};
|
|
4
|
+
//# sourceMappingURL=index.min.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 this.disabled = disabled !== null\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 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 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 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 _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 mean 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._setAttribute('disbaled', 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}` : '0',\n 'role=\"button\"'\n ]).filter(Boolean).join(' ')\n\n this.innerHTML = `<button ${btnProps}>\n ${this.innerHTML}\n </button>`\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAOO,IAAMA,EAAN,MAAMC,UAAwB,WAAY,CAPjD,MAOiD,CAAAC,EAAA,wBAE7C,OAAO,mBAAqB,CAAC,YAAa,WA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"__name", "disabled", "i", "value", "disabledValue", "name", "_oldValue", "newValue", "_old", "_", "oldValue", "handler", "type", "autofocus", "tabindex", "btnProps"]
|
|
7
|
+
}
|
package/dist/meta.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"inputs": {
|
|
3
|
+
"src/index.ts": {
|
|
4
|
+
"bytes": 5153,
|
|
5
|
+
"imports": [],
|
|
6
|
+
"format": "esm"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"outputs": {
|
|
10
|
+
"dist/index.js.map": {
|
|
11
|
+
"imports": [],
|
|
12
|
+
"exports": [],
|
|
13
|
+
"inputs": {},
|
|
14
|
+
"bytes": 8133
|
|
15
|
+
},
|
|
16
|
+
"dist/index.js": {
|
|
17
|
+
"imports": [],
|
|
18
|
+
"exports": [
|
|
19
|
+
"SubstrateButton"
|
|
20
|
+
],
|
|
21
|
+
"entryPoint": "src/index.ts",
|
|
22
|
+
"inputs": {
|
|
23
|
+
"src/index.ts": {
|
|
24
|
+
"bytesInOutput": 4112
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"bytes": 4305
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@substrate-system/button",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"./dist/*"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"lint": "eslint \"./**/*.{ts,js}\"",
|
|
11
|
+
"test": "npm run build && npm run build-tests && npm run test-tape-run",
|
|
12
|
+
"test-tape-run": "cat test/index.html | tape-run --input=html --static=test | tap-spec",
|
|
13
|
+
"build-tests": "esbuild test/index.ts --target=es2020 --bundle --keep-names > test/test-bundle.js",
|
|
14
|
+
"build-css": "postcss src/index.css --use postcss-nesting > dist/index.css",
|
|
15
|
+
"build-css:min": "postcss src/index.css --use cssnano postcss-nesting > dist/index.min.css",
|
|
16
|
+
"build-cjs": "esbuild src/*.ts --format=cjs --keep-names --tsconfig=tsconfig.build.json --outdir=./dist --out-extension:.js=.cjs --sourcemap",
|
|
17
|
+
"build-esm": "esbuild src/*.ts --format=esm --metafile=dist/meta.json --keep-names --tsconfig=tsconfig.build.json --outdir=./dist --sourcemap && tsc --emitDeclarationOnly --project tsconfig.build.json --outDir dist",
|
|
18
|
+
"build-esm:min": "esbuild ./src/*.ts --format=esm --keep-names --bundle --tsconfig=tsconfig.build.json --minify --out-extension:.js=.min.js --outdir=./dist --sourcemap",
|
|
19
|
+
"build-example": "mkdir -p ./public && rm -rf ./public/* && VITE_DEBUG_MODE=staging vite --mode staging --base=\"/button\" build",
|
|
20
|
+
"build-docs": "typedoc --tsconfig tsconfig.build.json ./src/index.ts",
|
|
21
|
+
"build": "mkdir -p ./dist && rm -rf ./dist/* && npm run build-cjs && npm run build-esm && npm run build-esm:min && npm run build-css && npm run build-css:min",
|
|
22
|
+
"start": "vite",
|
|
23
|
+
"toc": "markdown-toc --maxdepth 3 -i README.md",
|
|
24
|
+
"preversion": "npm run lint && stylelint src/*.css",
|
|
25
|
+
"version": "npm run toc && auto-changelog -p --template keepachangelog --breaking-pattern 'BREAKING CHANGE:' && git add CHANGELOG.md README.md",
|
|
26
|
+
"postversion": "git push --follow-tags && npm publish",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
},
|
|
34
|
+
"./css": "./dist/index.css",
|
|
35
|
+
"./css/min": "./dist/index.min.css",
|
|
36
|
+
"./*": {
|
|
37
|
+
"import": [
|
|
38
|
+
"./dist/*.js",
|
|
39
|
+
"./dist/*"
|
|
40
|
+
],
|
|
41
|
+
"require": [
|
|
42
|
+
"./dist/*.cjs",
|
|
43
|
+
"./dist/*"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@bicycle-codes/dom": "^0.1.2",
|
|
50
|
+
"@substrate-system/debug": "^0.9.0",
|
|
51
|
+
"@substrate-system/tapzero": "^0.10.13",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^8.7.0",
|
|
53
|
+
"@typescript-eslint/parser": "^8.7.0",
|
|
54
|
+
"auto-changelog": "^2.4.0",
|
|
55
|
+
"cssnano": "^7.0.3",
|
|
56
|
+
"esbuild": "^0.25.0",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"eslint-config-standard": "^17.1.0",
|
|
59
|
+
"markdown-toc": "^1.2.0",
|
|
60
|
+
"postcss": "^8.5.1",
|
|
61
|
+
"postcss-cli": "^11.0.0",
|
|
62
|
+
"postcss-nesting": "^13.0.1",
|
|
63
|
+
"stylelint": "^16.9.0",
|
|
64
|
+
"stylelint-config-standard": "^38.0.0",
|
|
65
|
+
"tap-spec": "^5.0.0",
|
|
66
|
+
"tape-run": "^11.0.0",
|
|
67
|
+
"typedoc": "^0.28.1",
|
|
68
|
+
"typescript": "^5.7.3",
|
|
69
|
+
"vite": "^6.0.11"
|
|
70
|
+
},
|
|
71
|
+
"author": "nichoth <nichoth@nichoth.com> (https://nichoth.com)",
|
|
72
|
+
"license": "MIT"
|
|
73
|
+
}
|