@spectrum-web-components/button 0.17.0 → 0.17.1
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/package.json +8 -8
- package/sp-button.d.ts +6 -0
- package/sp-button.js +14 -0
- package/sp-button.js.map +1 -0
- package/sp-clear-button.d.ts +6 -0
- package/sp-clear-button.js +14 -0
- package/sp-clear-button.js.map +1 -0
- package/sp-close-button.d.ts +6 -0
- package/sp-close-button.js +14 -0
- package/sp-close-button.js.map +1 -0
- package/src/Button.d.ts +36 -0
- package/src/Button.js +94 -0
- package/src/Button.js.map +1 -0
- package/src/ButtonBase.d.ts +42 -0
- package/src/ButtonBase.js +218 -0
- package/src/ButtonBase.js.map +1 -0
- package/src/ClearButton.d.ts +23 -0
- package/src/ClearButton.js +74 -0
- package/src/ClearButton.js.map +1 -0
- package/src/CloseButton.d.ts +26 -0
- package/src/CloseButton.js +72 -0
- package/src/CloseButton.js.map +1 -0
- package/src/StyledButton.d.ts +5 -0
- package/src/StyledButton.js +19 -0
- package/src/StyledButton.js.map +1 -0
- package/src/button-base.css.d.ts +2 -0
- package/src/button-base.css.js +21 -0
- package/src/button-base.css.js.map +1 -0
- package/src/button.css.d.ts +2 -0
- package/src/button.css.js +630 -0
- package/src/button.css.js.map +1 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +17 -0
- package/src/index.js.map +1 -0
- package/src/spectrum-button-base.css.d.ts +2 -0
- package/src/spectrum-button-base.css.js +17 -0
- package/src/spectrum-button-base.css.js.map +1 -0
- package/src/spectrum-button.css.d.ts +2 -0
- package/src/spectrum-button.css.js +598 -0
- package/src/spectrum-button.css.js.map +1 -0
- package/stories/button-accent-fill-sizes.stories.js +28 -0
- package/stories/button-accent-fill-sizes.stories.js.map +1 -0
- package/stories/button-accent-fill.stories.js +28 -0
- package/stories/button-accent-fill.stories.js.map +1 -0
- package/stories/button-accent-outline-sizes.stories.js +28 -0
- package/stories/button-accent-outline-sizes.stories.js.map +1 -0
- package/stories/button-accent-outline.stories.js +28 -0
- package/stories/button-accent-outline.stories.js.map +1 -0
- package/stories/button-black-fill-sizes.stories.js +29 -0
- package/stories/button-black-fill-sizes.stories.js.map +1 -0
- package/stories/button-black-fill.stories.js +29 -0
- package/stories/button-black-fill.stories.js.map +1 -0
- package/stories/button-black-outline-sizes.stories.js +29 -0
- package/stories/button-black-outline-sizes.stories.js.map +1 -0
- package/stories/button-black-outline.stories.js +29 -0
- package/stories/button-black-outline.stories.js.map +1 -0
- package/stories/button-negative-fill-sizes.stories.js +28 -0
- package/stories/button-negative-fill-sizes.stories.js.map +1 -0
- package/stories/button-negative-fill.stories.js +28 -0
- package/stories/button-negative-fill.stories.js.map +1 -0
- package/stories/button-negative-outline-sizes.stories.js +28 -0
- package/stories/button-negative-outline-sizes.stories.js.map +1 -0
- package/stories/button-negative-outline.stories.js +28 -0
- package/stories/button-negative-outline.stories.js.map +1 -0
- package/stories/button-primary-fill-sizes.stories.js +28 -0
- package/stories/button-primary-fill-sizes.stories.js.map +1 -0
- package/stories/button-primary-fill.stories.js +28 -0
- package/stories/button-primary-fill.stories.js.map +1 -0
- package/stories/button-primary-outline-sizes.stories.js +28 -0
- package/stories/button-primary-outline-sizes.stories.js.map +1 -0
- package/stories/button-primary-outline.stories.js +28 -0
- package/stories/button-primary-outline.stories.js.map +1 -0
- package/stories/button-secondary-fill-sizes.stories.js +28 -0
- package/stories/button-secondary-fill-sizes.stories.js.map +1 -0
- package/stories/button-secondary-fill.stories.js +28 -0
- package/stories/button-secondary-fill.stories.js.map +1 -0
- package/stories/button-secondary-outline-sizes.stories.js +28 -0
- package/stories/button-secondary-outline-sizes.stories.js.map +1 -0
- package/stories/button-secondary-outline.stories.js +28 -0
- package/stories/button-secondary-outline.stories.js.map +1 -0
- package/stories/button-white-fill-sizes.stories.js +29 -0
- package/stories/button-white-fill-sizes.stories.js.map +1 -0
- package/stories/button-white-fill.stories.js +29 -0
- package/stories/button-white-fill.stories.js.map +1 -0
- package/stories/button-white-outline-sizes.stories.js +29 -0
- package/stories/button-white-outline-sizes.stories.js.map +1 -0
- package/stories/button-white-outline.stories.js +29 -0
- package/stories/button-white-outline.stories.js.map +1 -0
- package/stories/index.js +182 -0
- package/stories/index.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/button",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"lit-html"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@spectrum-web-components/base": "^0.5.
|
|
52
|
-
"@spectrum-web-components/clear-button": "^0.1.
|
|
53
|
-
"@spectrum-web-components/close-button": "^0.1.
|
|
54
|
-
"@spectrum-web-components/icon": "^0.11.
|
|
55
|
-
"@spectrum-web-components/icons-ui": "^0.8.
|
|
56
|
-
"@spectrum-web-components/shared": "^0.13.
|
|
51
|
+
"@spectrum-web-components/base": "^0.5.4",
|
|
52
|
+
"@spectrum-web-components/clear-button": "^0.1.1",
|
|
53
|
+
"@spectrum-web-components/close-button": "^0.1.1",
|
|
54
|
+
"@spectrum-web-components/icon": "^0.11.5",
|
|
55
|
+
"@spectrum-web-components/icons-ui": "^0.8.5",
|
|
56
|
+
"@spectrum-web-components/shared": "^0.13.6",
|
|
57
57
|
"tslib": "^2.0.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"sideEffects": [
|
|
65
65
|
"./sp-*.js"
|
|
66
66
|
],
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "caf12727e7f91dcf961e1fadacc727eea9ece27b"
|
|
68
68
|
}
|
package/sp-button.d.ts
ADDED
package/sp-button.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { Button } from './src/Button.js';
|
|
13
|
+
customElements.define('sp-button', Button);
|
|
14
|
+
//# sourceMappingURL=sp-button.js.map
|
package/sp-button.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sp-button.js","sourceRoot":"","sources":["sp-button.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { Button } from './src/Button.js';\n\ncustomElements.define('sp-button', Button);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-button': Button;\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { ClearButton } from './src/ClearButton.js';
|
|
13
|
+
customElements.define('sp-clear-button', ClearButton);
|
|
14
|
+
//# sourceMappingURL=sp-clear-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sp-clear-button.js","sourceRoot":"","sources":["sp-clear-button.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ClearButton } from './src/ClearButton.js';\n\ncustomElements.define('sp-clear-button', ClearButton);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-clear-button': ClearButton;\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { CloseButton } from './src/CloseButton.js';
|
|
13
|
+
customElements.define('sp-close-button', CloseButton);
|
|
14
|
+
//# sourceMappingURL=sp-close-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sp-close-button.js","sourceRoot":"","sources":["sp-close-button.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { CloseButton } from './src/CloseButton.js';\n\ncustomElements.define('sp-close-button', CloseButton);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-close-button': CloseButton;\n }\n}\n"]}
|
package/src/Button.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CSSResultArray, PropertyValues } from '@spectrum-web-components/base';
|
|
2
|
+
import { StyledButton } from './StyledButton.js';
|
|
3
|
+
export declare type DeprecatedButtonVariants = 'cta' | 'overBackground';
|
|
4
|
+
export declare type ButtonStatics = 'white' | 'black';
|
|
5
|
+
export declare type ButtonVariants = 'accent' | 'primary' | 'secondary' | 'negative' | ButtonStatics | DeprecatedButtonVariants;
|
|
6
|
+
export declare const VALID_VARIANTS: string[];
|
|
7
|
+
export declare type ButtonTreatments = 'fill' | 'outline';
|
|
8
|
+
declare const Button_base: typeof StyledButton & {
|
|
9
|
+
new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
|
|
10
|
+
prototype: import("@spectrum-web-components/base").SizedElementInterface;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @element sp-button
|
|
14
|
+
*
|
|
15
|
+
* @slot - text label of the Button
|
|
16
|
+
* @slot icon - The icon to use for Button
|
|
17
|
+
*/
|
|
18
|
+
export declare class Button extends Button_base {
|
|
19
|
+
static get styles(): CSSResultArray;
|
|
20
|
+
/**
|
|
21
|
+
* The visual variant to apply to this button.
|
|
22
|
+
*/
|
|
23
|
+
get variant(): ButtonVariants;
|
|
24
|
+
set variant(variant: ButtonVariants);
|
|
25
|
+
private _variant;
|
|
26
|
+
/**
|
|
27
|
+
* The visual variant to apply to this button.
|
|
28
|
+
*/
|
|
29
|
+
treatment: ButtonTreatments;
|
|
30
|
+
/**
|
|
31
|
+
* Style this button to be less obvious
|
|
32
|
+
*/
|
|
33
|
+
set quiet(quiet: boolean);
|
|
34
|
+
protected firstUpdated(changes: PropertyValues<this>): void;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
package/src/Button.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { __decorate } from "tslib";
|
|
13
|
+
import { SizedMixin, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import { StyledButton } from './StyledButton.js';
|
|
16
|
+
import buttonStyles from './button.css.js';
|
|
17
|
+
export const VALID_VARIANTS = [
|
|
18
|
+
'accent',
|
|
19
|
+
'primary',
|
|
20
|
+
'secondary',
|
|
21
|
+
'negative',
|
|
22
|
+
'white',
|
|
23
|
+
'black',
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* @element sp-button
|
|
27
|
+
*
|
|
28
|
+
* @slot - text label of the Button
|
|
29
|
+
* @slot icon - The icon to use for Button
|
|
30
|
+
*/
|
|
31
|
+
export class Button extends SizedMixin(StyledButton) {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(...arguments);
|
|
34
|
+
this._variant = 'accent';
|
|
35
|
+
/**
|
|
36
|
+
* The visual variant to apply to this button.
|
|
37
|
+
*/
|
|
38
|
+
this.treatment = 'fill';
|
|
39
|
+
}
|
|
40
|
+
static get styles() {
|
|
41
|
+
return [...super.styles, buttonStyles];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The visual variant to apply to this button.
|
|
45
|
+
*/
|
|
46
|
+
get variant() {
|
|
47
|
+
return this._variant;
|
|
48
|
+
}
|
|
49
|
+
set variant(variant) {
|
|
50
|
+
if (variant === this.variant)
|
|
51
|
+
return;
|
|
52
|
+
this.requestUpdate('variant', this.variant);
|
|
53
|
+
switch (variant) {
|
|
54
|
+
case 'cta':
|
|
55
|
+
this._variant = 'accent';
|
|
56
|
+
break;
|
|
57
|
+
case 'overBackground':
|
|
58
|
+
this._variant = 'white';
|
|
59
|
+
this.treatment = 'outline';
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
if (!VALID_VARIANTS.includes(variant)) {
|
|
63
|
+
this._variant = 'accent';
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this._variant = variant;
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
this.setAttribute('variant', this.variant);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Style this button to be less obvious
|
|
74
|
+
*/
|
|
75
|
+
set quiet(quiet) {
|
|
76
|
+
this.treatment = quiet ? 'outline' : 'fill';
|
|
77
|
+
}
|
|
78
|
+
firstUpdated(changes) {
|
|
79
|
+
super.firstUpdated(changes);
|
|
80
|
+
if (!this.hasAttribute('variant')) {
|
|
81
|
+
this.setAttribute('variant', this.variant);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
__decorate([
|
|
86
|
+
property()
|
|
87
|
+
], Button.prototype, "variant", null);
|
|
88
|
+
__decorate([
|
|
89
|
+
property({ reflect: true })
|
|
90
|
+
], Button.prototype, "treatment", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
property({ type: Boolean })
|
|
93
|
+
], Button.prototype, "quiet", null);
|
|
94
|
+
//# sourceMappingURL=Button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Button.js","sourceRoot":"","sources":["Button.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAGH,UAAU,GACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAW3C,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,QAAQ;IACR,SAAS;IACT,WAAW;IACX,UAAU;IACV,OAAO;IACP,OAAO;CACV,CAAC;AAIF;;;;;GAKG;AACH,MAAM,OAAO,MAAO,SAAQ,UAAU,CAAC,YAAY,C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/B,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;SAC9C;IACL,CAAC;CACJ;AA/CG;IADC,QAAQ,EAAE;qCAGV;AA6BD;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yCACgB;AAM5C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;mCAG3B","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n PropertyValues,\n SizedMixin,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { StyledButton } from './StyledButton.js';\nimport buttonStyles from './button.css.js';\n\nexport type DeprecatedButtonVariants = 'cta' | 'overBackground';\nexport type ButtonStatics = 'white' | 'black';\nexport type ButtonVariants =\n | 'accent'\n | 'primary'\n | 'secondary'\n | 'negative'\n | ButtonStatics\n | DeprecatedButtonVariants;\nexport const VALID_VARIANTS = [\n 'accent',\n 'primary',\n 'secondary',\n 'negative',\n 'white',\n 'black',\n];\n\nexport type ButtonTreatments = 'fill' | 'outline';\n\n/**\n * @element sp-button\n *\n * @slot - text label of the Button\n * @slot icon - The icon to use for Button\n */\nexport class Button extends SizedMixin(StyledButton) {\n public static get styles(): CSSResultArray {\n return [...super.styles, buttonStyles];\n }\n\n /**\n * The visual variant to apply to this button.\n */\n @property()\n public get variant(): ButtonVariants {\n return this._variant;\n }\n public set variant(variant: ButtonVariants) {\n if (variant === this.variant) return;\n\n this.requestUpdate('variant', this.variant);\n switch (variant) {\n case 'cta':\n this._variant = 'accent';\n break;\n case 'overBackground':\n this._variant = 'white';\n this.treatment = 'outline';\n break;\n default:\n if (!VALID_VARIANTS.includes(variant)) {\n this._variant = 'accent';\n } else {\n this._variant = variant;\n }\n break;\n }\n this.setAttribute('variant', this.variant);\n }\n private _variant: ButtonVariants = 'accent';\n\n /**\n * The visual variant to apply to this button.\n */\n @property({ reflect: true })\n public treatment: ButtonTreatments = 'fill';\n\n /**\n * Style this button to be less obvious\n */\n @property({ type: Boolean })\n public set quiet(quiet: boolean) {\n this.treatment = quiet ? 'outline' : 'fill';\n }\n\n protected firstUpdated(changes: PropertyValues<this>): void {\n super.firstUpdated(changes);\n if (!this.hasAttribute('variant')) {\n this.setAttribute('variant', this.variant);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { PropertyValues, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
|
|
3
|
+
declare const ButtonBase_base: typeof Focusable & {
|
|
4
|
+
new (...args: any[]): import("@spectrum-web-components/shared").SlotPresenceObservingInterface;
|
|
5
|
+
prototype: import("@spectrum-web-components/shared").SlotPresenceObservingInterface;
|
|
6
|
+
} & {
|
|
7
|
+
new (...args: any[]): import("@spectrum-web-components/shared").SlotTextObservingInterface;
|
|
8
|
+
prototype: import("@spectrum-web-components/shared").SlotTextObservingInterface;
|
|
9
|
+
} & {
|
|
10
|
+
new (...args: any[]): import("@spectrum-web-components/shared").LikeAnchorInterface;
|
|
11
|
+
prototype: import("@spectrum-web-components/shared").LikeAnchorInterface;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @slot - text content to be displayed in the Button element
|
|
15
|
+
* @slot icon - icon element(s) to display at the start of the button
|
|
16
|
+
*/
|
|
17
|
+
export declare class ButtonBase extends ButtonBase_base {
|
|
18
|
+
protected get hasIcon(): boolean;
|
|
19
|
+
active: boolean;
|
|
20
|
+
type: 'button' | 'submit' | 'reset';
|
|
21
|
+
protected get hasLabel(): boolean;
|
|
22
|
+
private anchorElement;
|
|
23
|
+
get focusElement(): HTMLElement;
|
|
24
|
+
protected get buttonContent(): TemplateResult[];
|
|
25
|
+
constructor();
|
|
26
|
+
click(): void;
|
|
27
|
+
private handleClickCapture;
|
|
28
|
+
private proxyFocus;
|
|
29
|
+
private shouldProxyClick;
|
|
30
|
+
renderAnchor(): TemplateResult;
|
|
31
|
+
protected renderButton(): TemplateResult;
|
|
32
|
+
protected render(): TemplateResult;
|
|
33
|
+
protected handleKeydown(event: KeyboardEvent): void;
|
|
34
|
+
private handleKeypress;
|
|
35
|
+
protected handleKeyup(event: KeyboardEvent): void;
|
|
36
|
+
private handleRemoveActive;
|
|
37
|
+
private handlePointerdown;
|
|
38
|
+
private manageAnchor;
|
|
39
|
+
protected firstUpdated(changed: PropertyValues): void;
|
|
40
|
+
protected updated(changed: PropertyValues): void;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { __decorate } from "tslib";
|
|
13
|
+
import { html, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property, query, } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';
|
|
16
|
+
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
|
|
17
|
+
import { ObserveSlotPresence, ObserveSlotText, } from '@spectrum-web-components/shared';
|
|
18
|
+
/**
|
|
19
|
+
* @slot - text content to be displayed in the Button element
|
|
20
|
+
* @slot icon - icon element(s) to display at the start of the button
|
|
21
|
+
*/
|
|
22
|
+
export class ButtonBase extends LikeAnchor(ObserveSlotText(ObserveSlotPresence(Focusable, '[slot="icon"]'))) {
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.active = false;
|
|
26
|
+
this.type = 'button';
|
|
27
|
+
this.proxyFocus = this.proxyFocus.bind(this);
|
|
28
|
+
this.addEventListener('click', this.handleClickCapture, {
|
|
29
|
+
capture: true,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
get hasIcon() {
|
|
33
|
+
return this.slotContentIsPresent;
|
|
34
|
+
}
|
|
35
|
+
get hasLabel() {
|
|
36
|
+
return this.slotHasContent;
|
|
37
|
+
}
|
|
38
|
+
get focusElement() {
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
get buttonContent() {
|
|
42
|
+
const content = [
|
|
43
|
+
html `
|
|
44
|
+
<div id="label" ?hidden=${!this.hasLabel}>
|
|
45
|
+
<slot
|
|
46
|
+
id="slot"
|
|
47
|
+
@slotchange=${this.manageTextObservedSlot}
|
|
48
|
+
></slot>
|
|
49
|
+
</div>
|
|
50
|
+
`,
|
|
51
|
+
];
|
|
52
|
+
if (this.hasIcon) {
|
|
53
|
+
content.unshift(html `
|
|
54
|
+
<slot name="icon" ?icon-only=${!this.hasLabel}></slot>
|
|
55
|
+
`);
|
|
56
|
+
}
|
|
57
|
+
return content;
|
|
58
|
+
}
|
|
59
|
+
click() {
|
|
60
|
+
if (this.disabled) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (this.shouldProxyClick()) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
super.click();
|
|
67
|
+
}
|
|
68
|
+
handleClickCapture(event) {
|
|
69
|
+
if (this.disabled) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
event.stopImmediatePropagation();
|
|
72
|
+
event.stopPropagation();
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
proxyFocus() {
|
|
77
|
+
this.focus();
|
|
78
|
+
}
|
|
79
|
+
shouldProxyClick() {
|
|
80
|
+
let handled = false;
|
|
81
|
+
if (this.anchorElement) {
|
|
82
|
+
this.anchorElement.click();
|
|
83
|
+
handled = true;
|
|
84
|
+
}
|
|
85
|
+
else if (this.type !== 'button') {
|
|
86
|
+
const proxy = document.createElement('button');
|
|
87
|
+
proxy.type = this.type;
|
|
88
|
+
this.insertAdjacentElement('afterend', proxy);
|
|
89
|
+
proxy.click();
|
|
90
|
+
proxy.remove();
|
|
91
|
+
handled = true;
|
|
92
|
+
}
|
|
93
|
+
return handled;
|
|
94
|
+
}
|
|
95
|
+
renderAnchor() {
|
|
96
|
+
return html `
|
|
97
|
+
${this.buttonContent}
|
|
98
|
+
${super.renderAnchor({
|
|
99
|
+
id: 'button',
|
|
100
|
+
ariaHidden: true,
|
|
101
|
+
className: 'button anchor hidden',
|
|
102
|
+
})}
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
renderButton() {
|
|
106
|
+
return html `
|
|
107
|
+
${this.buttonContent}
|
|
108
|
+
`;
|
|
109
|
+
}
|
|
110
|
+
render() {
|
|
111
|
+
return this.href && this.href.length > 0
|
|
112
|
+
? this.renderAnchor()
|
|
113
|
+
: this.renderButton();
|
|
114
|
+
}
|
|
115
|
+
handleKeydown(event) {
|
|
116
|
+
const { code } = event;
|
|
117
|
+
switch (code) {
|
|
118
|
+
case 'Space':
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
if (typeof this.href === 'undefined') {
|
|
121
|
+
this.addEventListener('keyup', this.handleKeyup);
|
|
122
|
+
this.active = true;
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
handleKeypress(event) {
|
|
130
|
+
const { code } = event;
|
|
131
|
+
switch (code) {
|
|
132
|
+
case 'Enter':
|
|
133
|
+
case 'NumpadEnter':
|
|
134
|
+
this.click();
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
handleKeyup(event) {
|
|
141
|
+
const { code } = event;
|
|
142
|
+
switch (code) {
|
|
143
|
+
case 'Space':
|
|
144
|
+
this.removeEventListener('keyup', this.handleKeyup);
|
|
145
|
+
this.active = false;
|
|
146
|
+
this.click();
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
handleRemoveActive() {
|
|
153
|
+
this.active = false;
|
|
154
|
+
}
|
|
155
|
+
handlePointerdown() {
|
|
156
|
+
this.active = true;
|
|
157
|
+
}
|
|
158
|
+
manageAnchor() {
|
|
159
|
+
if (this.href && this.href.length > 0) {
|
|
160
|
+
if (this.getAttribute('role') === 'button') {
|
|
161
|
+
this.setAttribute('role', 'link');
|
|
162
|
+
}
|
|
163
|
+
this.removeEventListener('click', this.shouldProxyClick);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
if (!this.hasAttribute('role') ||
|
|
167
|
+
this.getAttribute('role') === 'link') {
|
|
168
|
+
this.setAttribute('role', 'button');
|
|
169
|
+
}
|
|
170
|
+
this.addEventListener('click', this.shouldProxyClick);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
firstUpdated(changed) {
|
|
174
|
+
super.firstUpdated(changed);
|
|
175
|
+
if (!this.hasAttribute('tabindex')) {
|
|
176
|
+
this.tabIndex = 0;
|
|
177
|
+
}
|
|
178
|
+
this.manageAnchor();
|
|
179
|
+
this.addEventListener('keydown', this.handleKeydown);
|
|
180
|
+
this.addEventListener('keypress', this.handleKeypress);
|
|
181
|
+
this.addEventListener('pointerdown', this.handlePointerdown);
|
|
182
|
+
}
|
|
183
|
+
updated(changed) {
|
|
184
|
+
super.updated(changed);
|
|
185
|
+
if (changed.has('href')) {
|
|
186
|
+
this.manageAnchor();
|
|
187
|
+
}
|
|
188
|
+
if (changed.has('label')) {
|
|
189
|
+
this.setAttribute('aria-label', this.label || '');
|
|
190
|
+
}
|
|
191
|
+
if (changed.has('active')) {
|
|
192
|
+
if (this.active) {
|
|
193
|
+
this.addEventListener('focusout', this.handleRemoveActive);
|
|
194
|
+
this.addEventListener('pointerup', this.handleRemoveActive);
|
|
195
|
+
this.addEventListener('pointerleave', this.handleRemoveActive);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
this.removeEventListener('focusout', this.handleRemoveActive);
|
|
199
|
+
this.removeEventListener('pointerup', this.handleRemoveActive);
|
|
200
|
+
this.removeEventListener('pointerleave', this.handleRemoveActive);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (this.anchorElement) {
|
|
204
|
+
this.anchorElement.addEventListener('focus', this.proxyFocus);
|
|
205
|
+
this.anchorElement.tabIndex = -1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
__decorate([
|
|
210
|
+
property({ type: Boolean, reflect: true })
|
|
211
|
+
], ButtonBase.prototype, "active", void 0);
|
|
212
|
+
__decorate([
|
|
213
|
+
property({ type: String })
|
|
214
|
+
], ButtonBase.prototype, "type", void 0);
|
|
215
|
+
__decorate([
|
|
216
|
+
query('.anchor')
|
|
217
|
+
], ButtonBase.prototype, "anchorElement", void 0);
|
|
218
|
+
//# sourceMappingURL=ButtonBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ButtonBase.js","sourceRoot":"","sources":["ButtonBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EACH,IAAI,GAGP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,QAAQ,EACR,KAAK,GACR,MAAM,i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AAE,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;SACrD;QACD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YACvB,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBAC3D,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBAC5D,IAAI,CAAC,gBAAgB,CAAC,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;aAClE;iBAAM;gBACH,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBAC9D,IAAI,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBAC/D,IAAI,CAAC,mBAAmB,CACpB,cAAc,EACd,IAAI,CAAC,kBAAkB,CAC1B,CAAC;aACL;SACJ;QACD,IAAI,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9D,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;SACpC;IACL,CAAC;CACJ;AAnNG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CACrB;AAGtB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAC2B;AAOtD;IADC,KAAK,CAAC,SAAS,CAAC;iDACyB","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\nimport {\n ObserveSlotPresence,\n ObserveSlotText,\n} from '@spectrum-web-components/shared';\n\n/**\n * @slot - text content to be displayed in the Button element\n * @slot icon - icon element(s) to display at the start of the button\n */\nexport class ButtonBase extends LikeAnchor(\n ObserveSlotText(ObserveSlotPresence(Focusable, '[slot=\"icon\"]'))\n) {\n protected get hasIcon(): boolean {\n return this.slotContentIsPresent;\n }\n\n @property({ type: Boolean, reflect: true })\n public active = false;\n\n @property({ type: String })\n public type: 'button' | 'submit' | 'reset' = 'button';\n\n protected get hasLabel(): boolean {\n return this.slotHasContent;\n }\n\n @query('.anchor')\n private anchorElement!: HTMLButtonElement;\n\n public get focusElement(): HTMLElement {\n return this;\n }\n\n protected get buttonContent(): TemplateResult[] {\n const content = [\n html`\n <div id=\"label\" ?hidden=${!this.hasLabel}>\n <slot\n id=\"slot\"\n @slotchange=${this.manageTextObservedSlot}\n ></slot>\n </div>\n `,\n ];\n if (this.hasIcon) {\n content.unshift(html`\n <slot name=\"icon\" ?icon-only=${!this.hasLabel}></slot>\n `);\n }\n return content;\n }\n\n constructor() {\n super();\n this.proxyFocus = this.proxyFocus.bind(this);\n\n this.addEventListener('click', this.handleClickCapture, {\n capture: true,\n });\n }\n\n public click(): void {\n if (this.disabled) {\n return;\n }\n\n if (this.shouldProxyClick()) {\n return;\n }\n\n super.click();\n }\n\n private handleClickCapture(event: Event): void | boolean {\n if (this.disabled) {\n event.preventDefault();\n event.stopImmediatePropagation();\n event.stopPropagation();\n return false;\n }\n }\n\n private proxyFocus(): void {\n this.focus();\n }\n\n private shouldProxyClick(): boolean {\n let handled = false;\n if (this.anchorElement) {\n this.anchorElement.click();\n handled = true;\n } else if (this.type !== 'button') {\n const proxy = document.createElement('button');\n proxy.type = this.type;\n this.insertAdjacentElement('afterend', proxy);\n proxy.click();\n proxy.remove();\n handled = true;\n }\n return handled;\n }\n\n public renderAnchor(): TemplateResult {\n return html`\n ${this.buttonContent}\n ${super.renderAnchor({\n id: 'button',\n ariaHidden: true,\n className: 'button anchor hidden',\n })}\n `;\n }\n\n protected renderButton(): TemplateResult {\n return html`\n ${this.buttonContent}\n `;\n }\n\n protected render(): TemplateResult {\n return this.href && this.href.length > 0\n ? this.renderAnchor()\n : this.renderButton();\n }\n\n protected handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n switch (code) {\n case 'Space':\n event.preventDefault();\n if (typeof this.href === 'undefined') {\n this.addEventListener('keyup', this.handleKeyup);\n this.active = true;\n }\n break;\n default:\n break;\n }\n }\n\n private handleKeypress(event: KeyboardEvent): void {\n const { code } = event;\n switch (code) {\n case 'Enter':\n case 'NumpadEnter':\n this.click();\n break;\n default:\n break;\n }\n }\n\n protected handleKeyup(event: KeyboardEvent): void {\n const { code } = event;\n switch (code) {\n case 'Space':\n this.removeEventListener('keyup', this.handleKeyup);\n this.active = false;\n this.click();\n break;\n default:\n break;\n }\n }\n\n private handleRemoveActive(): void {\n this.active = false;\n }\n\n private handlePointerdown(): void {\n this.active = true;\n }\n\n private manageAnchor(): void {\n if (this.href && this.href.length > 0) {\n if (this.getAttribute('role') === 'button') {\n this.setAttribute('role', 'link');\n }\n this.removeEventListener('click', this.shouldProxyClick);\n } else {\n if (\n !this.hasAttribute('role') ||\n this.getAttribute('role') === 'link'\n ) {\n this.setAttribute('role', 'button');\n }\n this.addEventListener('click', this.shouldProxyClick);\n }\n }\n\n protected firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n if (!this.hasAttribute('tabindex')) {\n this.tabIndex = 0;\n }\n this.manageAnchor();\n this.addEventListener('keydown', this.handleKeydown);\n this.addEventListener('keypress', this.handleKeypress);\n this.addEventListener('pointerdown', this.handlePointerdown);\n }\n\n protected updated(changed: PropertyValues): void {\n super.updated(changed);\n if (changed.has('href')) {\n this.manageAnchor();\n }\n if (changed.has('label')) {\n this.setAttribute('aria-label', this.label || '');\n }\n if (changed.has('active')) {\n if (this.active) {\n this.addEventListener('focusout', this.handleRemoveActive);\n this.addEventListener('pointerup', this.handleRemoveActive);\n this.addEventListener('pointerleave', this.handleRemoveActive);\n } else {\n this.removeEventListener('focusout', this.handleRemoveActive);\n this.removeEventListener('pointerup', this.handleRemoveActive);\n this.removeEventListener(\n 'pointerleave',\n this.handleRemoveActive\n );\n }\n }\n if (this.anchorElement) {\n this.anchorElement.addEventListener('focus', this.proxyFocus);\n this.anchorElement.tabIndex = -1;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CSSResultArray, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import { StyledButton } from './StyledButton.js';
|
|
3
|
+
import '@spectrum-web-components/icons-ui/icons/sp-icon-cross75.js';
|
|
4
|
+
declare const ClearButton_base: typeof StyledButton & {
|
|
5
|
+
new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
|
|
6
|
+
prototype: import("@spectrum-web-components/base").SizedElementInterface;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @element sp-clear-button
|
|
10
|
+
*
|
|
11
|
+
* @slot - text label of the Clear Button
|
|
12
|
+
* @slot icon - The icon to use for Clear Button
|
|
13
|
+
*/
|
|
14
|
+
export declare class ClearButton extends ClearButton_base {
|
|
15
|
+
static get styles(): CSSResultArray;
|
|
16
|
+
/**
|
|
17
|
+
* The visual variant to apply to this button.
|
|
18
|
+
*/
|
|
19
|
+
variant: 'overBackground' | '';
|
|
20
|
+
protected get buttonContent(): TemplateResult[];
|
|
21
|
+
protected render(): TemplateResult;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { __decorate } from "tslib";
|
|
13
|
+
import { html, SizedMixin, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import { StyledButton } from './StyledButton.js';
|
|
16
|
+
import buttonStyles from '@spectrum-web-components/clear-button/src/clear-button.css.js';
|
|
17
|
+
import '@spectrum-web-components/icons-ui/icons/sp-icon-cross75.js';
|
|
18
|
+
import crossMediumStyles from '@spectrum-web-components/icon/src/spectrum-icon-cross.css.js';
|
|
19
|
+
const crossIcon = {
|
|
20
|
+
s: () => html `
|
|
21
|
+
<sp-icon-cross75
|
|
22
|
+
slot="icon"
|
|
23
|
+
class="icon spectrum-UIIcon-Cross75"
|
|
24
|
+
></sp-icon-cross75>
|
|
25
|
+
`,
|
|
26
|
+
m: () => html `
|
|
27
|
+
<sp-icon-cross100
|
|
28
|
+
slot="icon"
|
|
29
|
+
class="icon spectrum-UIIcon-Cross100"
|
|
30
|
+
></sp-icon-cross100>
|
|
31
|
+
`,
|
|
32
|
+
l: () => html `
|
|
33
|
+
<sp-icon-cross200
|
|
34
|
+
slot="icon"
|
|
35
|
+
class="icon spectrum-UIIcon-Cross200"
|
|
36
|
+
></sp-icon-cross200>
|
|
37
|
+
`,
|
|
38
|
+
xl: () => html `
|
|
39
|
+
<sp-icon-cross300
|
|
40
|
+
slot="icon"
|
|
41
|
+
class="icon spectrum-UIIcon-Cross300"
|
|
42
|
+
></sp-icon-cross300>
|
|
43
|
+
`,
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @element sp-clear-button
|
|
47
|
+
*
|
|
48
|
+
* @slot - text label of the Clear Button
|
|
49
|
+
* @slot icon - The icon to use for Clear Button
|
|
50
|
+
*/
|
|
51
|
+
export class ClearButton extends SizedMixin(StyledButton) {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
/**
|
|
55
|
+
* The visual variant to apply to this button.
|
|
56
|
+
*/
|
|
57
|
+
this.variant = '';
|
|
58
|
+
}
|
|
59
|
+
static get styles() {
|
|
60
|
+
return [...super.styles, buttonStyles, crossMediumStyles];
|
|
61
|
+
}
|
|
62
|
+
get buttonContent() {
|
|
63
|
+
return [crossIcon[this.size]()];
|
|
64
|
+
}
|
|
65
|
+
render() {
|
|
66
|
+
return html `
|
|
67
|
+
<div class="fill">${super.render()}</div>
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
__decorate([
|
|
72
|
+
property({ reflect: true })
|
|
73
|
+
], ClearButton.prototype, "variant", void 0);
|
|
74
|
+
//# sourceMappingURL=ClearButton.js.map
|