@redvars/peacock 3.6.3 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ButtonConstants-D06bY4uy.js +114 -0
- package/dist/ButtonConstants-D06bY4uy.js.map +1 -0
- package/dist/{BaseHyperlinkMixin-BNuwbiEf.js → NativeHyperlinkMixin-DrYXyfMQ.js} +8 -10
- package/dist/NativeHyperlinkMixin-DrYXyfMQ.js.map +1 -0
- package/dist/assets/components.css +1 -1
- package/dist/assets/components.css.map +1 -1
- package/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/{button-colors-Cg6oxiz-.js → button-colors-DSuBHd-i.js} +200 -186
- package/dist/button-colors-DSuBHd-i.js.map +1 -0
- package/dist/button-group.js +8 -8
- package/dist/button-group.js.map +1 -1
- package/dist/button.js +224 -124
- package/dist/button.js.map +1 -1
- package/dist/calendar-column-view.js +0 -1
- package/dist/calendar-column-view.js.map +1 -1
- package/dist/calendar-month-view.js +0 -1
- package/dist/calendar-month-view.js.map +1 -1
- package/dist/card-content.js +0 -1
- package/dist/card-content.js.map +1 -1
- package/dist/card.js +96 -90
- package/dist/card.js.map +1 -1
- package/dist/cb-compound-expression.js +4 -1
- package/dist/cb-compound-expression.js.map +1 -1
- package/dist/cb-divider.js +0 -1
- package/dist/cb-divider.js.map +1 -1
- package/dist/cb-expression.js +0 -2
- package/dist/cb-expression.js.map +1 -1
- package/dist/cb-predicate.js +0 -1
- package/dist/cb-predicate.js.map +1 -1
- package/dist/code-highlighter.js +23 -6
- package/dist/code-highlighter.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +5102 -18408
- package/dist/custom-elements.json +19630 -20205
- package/dist/fab.js +181 -117
- package/dist/fab.js.map +1 -1
- package/dist/{flow-designer-node-9Bqyn6qx.js → flow-designer-node-BWrPuxAR.js} +1 -2
- package/dist/flow-designer-node-BWrPuxAR.js.map +1 -0
- package/dist/flow-designer-node.js +1 -1
- package/dist/flow-designer.js +5 -5
- package/dist/icon-button-CYqrnMnF.js +318 -0
- package/dist/icon-button-CYqrnMnF.js.map +1 -0
- package/dist/index.js +8 -8
- package/dist/{navigation-rail-DAUuJ_Yp.js → navigation-rail-CM_svs5_.js} +511 -295
- package/dist/navigation-rail-CM_svs5_.js.map +1 -0
- package/dist/observe-slot-change-D8Xg-kSS.js +60 -0
- package/dist/observe-slot-change-D8Xg-kSS.js.map +1 -0
- package/dist/peacock-loader.js +7 -7
- package/dist/peacock-loader.js.map +1 -1
- package/dist/popover-content.js +0 -1
- package/dist/popover-content.js.map +1 -1
- package/dist/search.js +4 -1
- package/dist/search.js.map +1 -1
- package/dist/src/__controllers/attachable-controller.d.ts +109 -0
- package/dist/src/__mixins/{BaseButtonMixin.d.ts → NativeButtonMixin.d.ts} +3 -3
- package/dist/src/__mixins/{BaseHyperlinkMixin.d.ts → NativeHyperlinkMixin.d.ts} +3 -4
- package/dist/src/__utils/is-link.d.ts +1 -0
- package/dist/src/__utils/observe-slot-change.d.ts +1 -1
- package/dist/src/accordion/accordion-item.d.ts +0 -1
- package/dist/src/breadcrumb/breadcrumb-item/breadcrumb-item.d.ts +0 -1
- package/dist/src/button/ButtonConstants.d.ts +1 -0
- package/dist/src/button/GroupButtonInterface.d.ts +4 -0
- package/dist/src/button/button/button.d.ts +32 -7
- package/dist/src/button/button-group/button-group.d.ts +2 -1
- package/dist/src/button/icon-button/icon-button.d.ts +26 -5
- package/dist/src/button/index.d.ts +1 -1
- package/dist/src/calendar/calendar-column-view.d.ts +0 -1
- package/dist/src/calendar/calendar-month-view.d.ts +0 -1
- package/dist/src/card/card-content.d.ts +0 -1
- package/dist/src/card/card.d.ts +9 -6
- package/dist/src/chip/chip/chip.d.ts +22 -3
- package/dist/src/condition-builder/cb-compound-expression.d.ts +0 -1
- package/dist/src/condition-builder/cb-divider.d.ts +0 -1
- package/dist/src/condition-builder/cb-expression.d.ts +0 -1
- package/dist/src/condition-builder/cb-predicate.d.ts +0 -1
- package/dist/src/fab/fab.d.ts +20 -6
- package/dist/src/flow-designer/flow-designer-node.d.ts +0 -1
- package/dist/src/focus-ring/focus-ring.d.ts +26 -20
- package/dist/src/item/item.d.ts +2 -1
- package/dist/src/link/link.d.ts +1 -1
- package/dist/src/list/list-item.d.ts +1 -2
- package/dist/src/menu/menu-item/menu-item.d.ts +1 -2
- package/dist/src/menu/sub-menu/sub-menu.d.ts +0 -1
- package/dist/src/navigation-rail/navigation-rail-item.d.ts +0 -2
- package/dist/src/popover/popover-content.d.ts +0 -1
- package/dist/src/ripple/ripple.d.ts +9 -1
- package/dist/src/segmented-button/segmented-button.d.ts +0 -1
- package/dist/src/select/option.d.ts +0 -1
- package/dist/src/sidebar-menu/sidebar-menu-item.d.ts +0 -1
- package/dist/src/sidebar-menu/sidebar-sub-menu.d.ts +0 -1
- package/dist/src/tabs/tab-panel.d.ts +0 -1
- package/dist/src/tabs/tab.d.ts +4 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/readme.md +2 -2
- package/scss/components.scss +0 -1
- package/scss/mixin.scss +10 -13
- package/scss/styles.scss +1 -3
- package/src/__controllers/attachable-controller.ts +198 -0
- package/src/__mixins/NativeButtonMixin.ts +87 -0
- package/src/__mixins/{BaseHyperlinkMixin.ts → NativeHyperlinkMixin.ts} +15 -15
- package/src/__utils/is-link.ts +3 -0
- package/src/__utils/observe-slot-change.ts +46 -14
- package/src/accordion/accordion-item.scss +1 -1
- package/src/accordion/accordion-item.ts +0 -1
- package/src/breadcrumb/breadcrumb-item/breadcrumb-item.ts +0 -1
- package/src/button/ButtonConstants.ts +1 -0
- package/src/button/GroupButtonInterface.ts +4 -0
- package/src/button/button/button-colors.scss +2 -2
- package/src/button/button/button-layers.scss +124 -0
- package/src/button/button/button-sizes.scss +20 -42
- package/src/button/button/button.scss +71 -169
- package/src/button/button/button.ts +229 -78
- package/src/button/button/only-button.scss +13 -0
- package/src/button/button-group/button-group.ts +59 -17
- package/src/button/icon-button/icon-button-sizes.scss +6 -21
- package/src/button/icon-button/icon-button.ts +198 -93
- package/src/button/index.ts +1 -1
- package/src/calendar/calendar-column-view.ts +0 -1
- package/src/calendar/calendar-month-view.ts +0 -1
- package/src/card/card-content.ts +2 -3
- package/src/card/card.scss +87 -95
- package/src/card/card.ts +62 -60
- package/src/chip/chip/chip.scss +65 -70
- package/src/chip/chip/chip.ts +155 -56
- package/src/code-highlighter/code-highlighter.scss +1 -1
- package/src/code-highlighter/code-highlighter.ts +20 -5
- package/src/condition-builder/cb-compound-expression.scss +4 -0
- package/src/condition-builder/cb-compound-expression.ts +0 -1
- package/src/condition-builder/cb-divider.ts +0 -1
- package/src/condition-builder/cb-expression.scss +0 -1
- package/src/condition-builder/cb-expression.ts +0 -1
- package/src/condition-builder/cb-predicate.ts +0 -1
- package/src/elevation/elevation.scss +5 -1
- package/src/fab/fab-colors.scss +2 -2
- package/src/fab/fab-sizes.scss +24 -34
- package/src/fab/fab.scss +77 -71
- package/src/fab/fab.ts +141 -65
- package/src/flow-designer/flow-designer-node.ts +0 -1
- package/src/focus-ring/focus-ring.ts +81 -72
- package/src/item/item.scss +77 -66
- package/src/item/item.ts +61 -39
- package/src/link/link.scss +1 -10
- package/src/link/link.ts +4 -2
- package/src/list/list-item.ts +8 -8
- package/src/menu/menu-item/menu-item.ts +17 -8
- package/src/menu/sub-menu/sub-menu.ts +0 -1
- package/src/navigation-rail/navigation-rail-item.scss +5 -0
- package/src/navigation-rail/navigation-rail-item.ts +10 -15
- package/src/peacock-loader.ts +1 -1
- package/src/popover/popover-content.ts +0 -1
- package/src/ripple/ripple.ts +52 -20
- package/src/search/search.scss +3 -0
- package/src/segmented-button/segmented-button.ts +0 -1
- package/src/select/option.ts +0 -1
- package/src/sidebar-menu/sidebar-menu-item.ts +0 -1
- package/src/sidebar-menu/sidebar-sub-menu.ts +0 -1
- package/src/skeleton/skeleton.scss +5 -1
- package/src/tabs/tab-panel.ts +0 -1
- package/src/tabs/tab.ts +60 -70
- package/src/text/text.css-component.scss +3 -21
- package/src/tooltip/tooltip.scss +5 -8
- package/src/tooltip/tooltip.ts +1 -2
- package/dist/BaseButton-BNFAYn-S.js +0 -219
- package/dist/BaseButton-BNFAYn-S.js.map +0 -1
- package/dist/BaseHyperlinkMixin-BNuwbiEf.js.map +0 -1
- package/dist/button-colors-Cg6oxiz-.js.map +0 -1
- package/dist/flow-designer-node-9Bqyn6qx.js.map +0 -1
- package/dist/icon-button-AdJBEoNy.js +0 -251
- package/dist/icon-button-AdJBEoNy.js.map +0 -1
- package/dist/navigation-rail-DAUuJ_Yp.js.map +0 -1
- package/dist/observe-slot-change-BGJfgg2E.js +0 -31
- package/dist/observe-slot-change-BGJfgg2E.js.map +0 -1
- package/dist/src/button/BaseButton.d.ts +0 -28
- package/dist/src/focus-ring/FocusAttachableController.d.ts +0 -8
- package/src/__mixins/BaseButtonMixin.ts +0 -83
- package/src/button/BaseButton.ts +0 -113
- package/src/focus-ring/FocusAttachableController.ts +0 -28
- package/src/popover/tooltip.css-component.scss +0 -19
package/src/card/card.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { LitElement, html, nothing } from 'lit';
|
|
2
2
|
import { property, query, state } from 'lit/decorators.js';
|
|
3
3
|
import { classMap } from 'lit/directives/class-map.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
dispatchActivationClick,
|
|
6
|
+
isActivationClick,
|
|
7
|
+
} from '../__utils/dispatch-event-utils.js';
|
|
8
|
+
import { isLink } from '@/__utils/is-link.js';
|
|
5
9
|
import { observerSlotChangesWithCallback } from '@/__utils/observe-slot-change.js';
|
|
6
10
|
import { throttle } from '@/__utils/throttle.js';
|
|
7
11
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
8
12
|
import styles from './card.scss';
|
|
9
13
|
import colorStyles from './card-colors.scss';
|
|
10
|
-
import
|
|
14
|
+
import NativeHyperlinkMixin from '@/__mixins/NativeHyperlinkMixin.js';
|
|
11
15
|
|
|
12
16
|
type CardVariant = 'elevated' | 'filled' | 'outlined';
|
|
13
17
|
|
|
@@ -22,14 +26,16 @@ type CardVariant = 'elevated' | 'filled' | 'outlined';
|
|
|
22
26
|
*
|
|
23
27
|
* @example
|
|
24
28
|
* ```html
|
|
25
|
-
* <wc-card variant="outlined">
|
|
26
|
-
* <
|
|
27
|
-
*
|
|
29
|
+
* <wc-card variant="outlined" style="padding-block: 1rem;">
|
|
30
|
+
* <wc-card-content>
|
|
31
|
+
* <h3 class="text-headline">Title</h3>
|
|
32
|
+
* <p class="text-body">Supportive text</p>
|
|
33
|
+
* </wc-card-content>
|
|
28
34
|
* </wc-card>
|
|
29
35
|
* ```
|
|
30
36
|
*/
|
|
31
37
|
@IndividualComponent
|
|
32
|
-
export class Card extends
|
|
38
|
+
export class Card extends NativeHyperlinkMixin(LitElement) {
|
|
33
39
|
static styles = [styles, colorStyles];
|
|
34
40
|
|
|
35
41
|
#id = crypto.randomUUID();
|
|
@@ -44,8 +50,8 @@ export class Card extends BaseHyperlinkMixin(LitElement) {
|
|
|
44
50
|
actionable: boolean = false;
|
|
45
51
|
|
|
46
52
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
* If button is disabled, the reason why it is disabled.
|
|
54
|
+
*/
|
|
49
55
|
@property({ attribute: 'disabled-reason' })
|
|
50
56
|
disabledReason: string = '';
|
|
51
57
|
|
|
@@ -63,7 +69,6 @@ export class Card extends BaseHyperlinkMixin(LitElement) {
|
|
|
63
69
|
@state()
|
|
64
70
|
private slotHasContent = false;
|
|
65
71
|
|
|
66
|
-
|
|
67
72
|
@query('.card') readonly cardElement!: HTMLElement | null;
|
|
68
73
|
|
|
69
74
|
#tabindex?: number = 0;
|
|
@@ -140,82 +145,79 @@ export class Card extends BaseHyperlinkMixin(LitElement) {
|
|
|
140
145
|
}
|
|
141
146
|
};
|
|
142
147
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
148
|
render() {
|
|
149
|
+
const isLinkElement = isLink(this);
|
|
150
|
+
const disableSlotTabbing = this.actionable || isLinkElement;
|
|
151
|
+
|
|
152
|
+
return html`
|
|
153
|
+
<wc-focus-ring class="focus-ring" for="card"></wc-focus-ring>
|
|
154
|
+
<wc-elevation class="elevation"></wc-elevation>
|
|
155
|
+
<div class="background"></div>
|
|
156
|
+
<div class="outline"></div>
|
|
157
|
+
<wc-ripple class="ripple" for="card"></wc-ripple>
|
|
147
158
|
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
${this.renderCardElement(isLinkElement, disableSlotTabbing)}
|
|
160
|
+
`;
|
|
161
|
+
}
|
|
150
162
|
|
|
163
|
+
renderCardElement(isLinkElement: boolean, disableSlotTabbing: boolean) {
|
|
151
164
|
const cssClasses = {
|
|
152
165
|
card: true,
|
|
153
166
|
'card-element': true,
|
|
154
167
|
[`variant-${this.variant}`]: true,
|
|
155
|
-
actionable: (this.actionable && !this.disabled) ||
|
|
168
|
+
actionable: (this.actionable && !this.disabled) || isLinkElement,
|
|
156
169
|
disabled: this.disabled,
|
|
157
170
|
pressed: this.isPressed,
|
|
158
171
|
'has-content': this.slotHasContent,
|
|
159
172
|
};
|
|
160
173
|
|
|
161
|
-
if (!this.actionable && !
|
|
162
|
-
return html`<div
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
>
|
|
166
|
-
${this.renderCardContent(disableSlotTabbing)}
|
|
167
|
-
</div>`;
|
|
174
|
+
if (!this.actionable && !isLinkElement) {
|
|
175
|
+
return html`<div class=${classMap(cssClasses)} id="card">
|
|
176
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
177
|
+
</div>`;
|
|
168
178
|
}
|
|
169
179
|
|
|
170
|
-
if (!
|
|
180
|
+
if (!isLinkElement) {
|
|
171
181
|
return html`<button
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
class=${classMap(cssClasses)}
|
|
183
|
+
id="card"
|
|
184
|
+
tabindex=${this.#tabindex}
|
|
185
|
+
@click=${this.__dispatchClickWithThrottle}
|
|
186
|
+
@mousedown=${this.__handlePress}
|
|
187
|
+
@keydown=${this.__handlePress}
|
|
188
|
+
@keyup=${this.__handlePress}
|
|
189
|
+
?aria-describedby=${this.__getDisabledReasonID()}
|
|
190
|
+
aria-disabled=${`${this.disabled}`}
|
|
191
|
+
?disabled=${this.disabled}
|
|
192
|
+
>
|
|
193
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
194
|
+
</button>`;
|
|
185
195
|
}
|
|
186
196
|
return html`<a
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
class=${classMap(cssClasses)}
|
|
198
|
+
id="card"
|
|
199
|
+
tabindex=${this.#tabindex}
|
|
200
|
+
href=${this.href}
|
|
201
|
+
target=${this.target}
|
|
202
|
+
@click=${this.__dispatchClickWithThrottle}
|
|
203
|
+
@mousedown=${this.__handlePress}
|
|
204
|
+
@keydown=${this.__handlePress}
|
|
205
|
+
@keyup=${this.__handlePress}
|
|
206
|
+
role="button"
|
|
207
|
+
?aria-describedby=${this.__getDisabledReasonID()}
|
|
208
|
+
aria-disabled=${`${this.disabled}`}
|
|
209
|
+
>
|
|
210
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
211
|
+
</a>`;
|
|
202
212
|
}
|
|
203
213
|
|
|
204
214
|
renderCardContent(disableSlotTabbing: boolean) {
|
|
205
215
|
return html`
|
|
206
|
-
<wc-focus-ring class="focus-ring" for='card'></wc-focus-ring>
|
|
207
|
-
<wc-elevation class="elevation"></wc-elevation>
|
|
208
|
-
<div class="background"></div>
|
|
209
|
-
<div class="outline"></div>
|
|
210
|
-
<wc-ripple class="ripple"></wc-ripple>
|
|
211
|
-
|
|
212
216
|
<div class="card-content">
|
|
213
|
-
|
|
214
217
|
<div class="slot-container" ?inert=${disableSlotTabbing}>
|
|
215
218
|
<slot></slot>
|
|
216
219
|
</div>
|
|
217
|
-
|
|
218
220
|
</div>
|
|
219
|
-
|
|
221
|
+
`;
|
|
220
222
|
}
|
|
221
223
|
}
|
package/src/chip/chip/chip.scss
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
@include mixin.base-styles;
|
|
4
4
|
|
|
5
5
|
:host {
|
|
6
|
+
position: relative;
|
|
6
7
|
display: inline-flex;
|
|
7
8
|
--chip-container-color: var(--color-surface);
|
|
8
9
|
--chip-label-text-color: var(--color-on-surface);
|
|
@@ -27,12 +28,12 @@
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
.chip {
|
|
30
|
-
position: relative;
|
|
31
31
|
display: inline-flex;
|
|
32
32
|
align-items: center;
|
|
33
33
|
height: var(--chip-height, var(--_chip-height, 2rem));
|
|
34
34
|
width: 100%;
|
|
35
35
|
cursor: pointer;
|
|
36
|
+
z-index: 0;
|
|
36
37
|
|
|
37
38
|
.tag-content {
|
|
38
39
|
position: relative;
|
|
@@ -57,7 +58,6 @@
|
|
|
57
58
|
white-space: nowrap;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
|
|
61
61
|
.close-btn {
|
|
62
62
|
height: 100%;
|
|
63
63
|
padding: 0;
|
|
@@ -85,20 +85,6 @@
|
|
|
85
85
|
--icon-size: 1rem;
|
|
86
86
|
--icon-color: var(--color-primary);
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.focus-ring {
|
|
92
|
-
z-index: 2;
|
|
93
|
-
display: block;
|
|
94
|
-
--focus-ring-container-shape: var(--chip-container-shape);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.ripple {
|
|
98
|
-
display: block;
|
|
99
|
-
border-radius: var(--chip-container-shape);
|
|
100
|
-
--ripple-state-opacity: var(--_chip-state-opacity, 0);
|
|
101
|
-
--ripple-pressed-color: var(--_chip-state-color);
|
|
102
88
|
}
|
|
103
89
|
|
|
104
90
|
&.disabled {
|
|
@@ -120,72 +106,81 @@
|
|
|
120
106
|
&.icon-slot-has-content .icon-slot-container, &.selected .icon-slot-container {
|
|
121
107
|
padding-inline: calc(var(--chip-container-padding) / 2);
|
|
122
108
|
}
|
|
109
|
+
}
|
|
123
110
|
|
|
111
|
+
/*
|
|
112
|
+
Background layers
|
|
113
|
+
*/
|
|
114
|
+
.focus-ring {
|
|
115
|
+
z-index: 2;
|
|
116
|
+
display: block;
|
|
117
|
+
--focus-ring-container-shape: var(--chip-container-shape);
|
|
118
|
+
}
|
|
124
119
|
|
|
120
|
+
.ripple {
|
|
121
|
+
display: block;
|
|
122
|
+
border-radius: var(--chip-container-shape);
|
|
123
|
+
--ripple-state-opacity: var(--_chip-state-opacity, 0);
|
|
124
|
+
--ripple-pressed-color: var(--_chip-state-color);
|
|
125
|
+
}
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
background: var(--_chip-container-color);
|
|
139
|
-
pointer-events: none;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
.outline {
|
|
143
|
-
z-index: 0;
|
|
144
|
-
display: block;
|
|
145
|
-
position: absolute;
|
|
146
|
-
left: 0;
|
|
147
|
-
width: 100%;
|
|
148
|
-
height: 100%;
|
|
149
|
-
border-radius: var(--chip-container-shape);
|
|
150
|
-
border: 1px solid var(--chip-outline-color);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
.elevation {
|
|
154
|
-
--elevation-level: 0;
|
|
155
|
-
transition-duration: 280ms;
|
|
156
|
-
--elevation-container-shape: var(--chip-container-shape);
|
|
157
|
-
}
|
|
127
|
+
.background {
|
|
128
|
+
display: block;
|
|
129
|
+
position: absolute;
|
|
130
|
+
top: 0;
|
|
131
|
+
left: 0;
|
|
132
|
+
width: 100%;
|
|
133
|
+
height: 100%;
|
|
134
|
+
border-radius: var(--chip-container-shape);
|
|
135
|
+
background: var(--_chip-container-color);
|
|
136
|
+
pointer-events: none;
|
|
137
|
+
}
|
|
158
138
|
|
|
139
|
+
.outline {
|
|
140
|
+
z-index: 0;
|
|
141
|
+
display: block;
|
|
142
|
+
position: absolute;
|
|
143
|
+
top: 0;
|
|
144
|
+
left: 0;
|
|
145
|
+
width: 100%;
|
|
146
|
+
height: 100%;
|
|
147
|
+
border-radius: var(--chip-container-shape);
|
|
148
|
+
border: 1px solid var(--chip-outline-color);
|
|
159
149
|
}
|
|
160
150
|
|
|
151
|
+
.elevation {
|
|
152
|
+
--elevation-level: 0;
|
|
153
|
+
transition-duration: 280ms;
|
|
154
|
+
--elevation-container-shape: var(--chip-container-shape);
|
|
155
|
+
}
|
|
161
156
|
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
/* Color/state management */
|
|
158
|
+
:host {
|
|
164
159
|
--_chip-container-color: var(--chip-container-color);
|
|
165
160
|
--_chip-text-color: var(--chip-label-text-color);
|
|
166
161
|
--_chip-state-color: var(--_chip-text-color);
|
|
162
|
+
}
|
|
167
163
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
:host:hover {
|
|
165
|
+
--_chip-state-opacity: 0.08;
|
|
166
|
+
}
|
|
171
167
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
&.selected {
|
|
177
|
-
--_chip-container-color: var(--color-secondary-container);
|
|
178
|
-
--_chip-text-color: var(--color-on-secondary-container);
|
|
179
|
-
}
|
|
168
|
+
:host([pressed]) {
|
|
169
|
+
--_chip-state-opacity: 0.12;
|
|
170
|
+
}
|
|
180
171
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
--_chip-text-opacity: 0.38;
|
|
172
|
+
:host([selected]) {
|
|
173
|
+
--_chip-container-color: var(--color-secondary-container);
|
|
174
|
+
--_chip-text-color: var(--color-on-secondary-container);
|
|
175
|
+
}
|
|
186
176
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
177
|
+
:host([disabled]) {
|
|
178
|
+
--_chip-container-color: var(--color-on-surface);
|
|
179
|
+
--_chip-container-opacity: 0.1;
|
|
180
|
+
--_chip-text-color: var(--color-on-surface);
|
|
181
|
+
--_chip-text-opacity: 0.38;
|
|
182
|
+
|
|
183
|
+
.ripple {
|
|
184
|
+
display: none;
|
|
190
185
|
}
|
|
191
|
-
}
|
|
186
|
+
}
|
package/src/chip/chip/chip.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import { html, nothing } from 'lit';
|
|
1
|
+
import { html, LitElement, nothing } from 'lit';
|
|
2
2
|
import { property, query, state } from 'lit/decorators.js';
|
|
3
3
|
import { classMap } from 'lit/directives/class-map.js';
|
|
4
4
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
5
5
|
import { observerSlotChangesWithCallback } from '@/__utils/observe-slot-change.js';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
dispatchActivationClick,
|
|
8
|
+
isActivationClick,
|
|
9
|
+
} from '@/__utils/dispatch-event-utils.js';
|
|
10
|
+
import { isLink } from '@/__utils/is-link.js';
|
|
7
11
|
import styles from './chip.scss';
|
|
8
12
|
import sizeStyles from './chip-sizes.scss';
|
|
9
13
|
import { spread } from '@/__directive/spread.js';
|
|
10
|
-
import {
|
|
14
|
+
import { DISABLED_REASON_ID } from '@/button/ButtonConstants.js';
|
|
15
|
+
import NativeButtonMixin from '@/__mixins/NativeButtonMixin.js';
|
|
16
|
+
import NativeHyperlinkMixin from '@/__mixins/NativeHyperlinkMixin.js';
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* @label Chip
|
|
@@ -21,7 +27,7 @@ import { BaseButton } from '@/button/BaseButton.js';
|
|
|
21
27
|
* <wc-chip>Chip content</wc-chip>
|
|
22
28
|
* ```
|
|
23
29
|
*/
|
|
24
|
-
export class Chip extends
|
|
30
|
+
export class Chip extends NativeButtonMixin(NativeHyperlinkMixin(LitElement)) {
|
|
25
31
|
// Define styles (Lit handles Scoping via Shadow DOM by default)
|
|
26
32
|
// You would typically import your tag.scss.js here or use the css tag
|
|
27
33
|
static styles = [styles, sizeStyles];
|
|
@@ -37,7 +43,99 @@ export class Chip extends BaseButton {
|
|
|
37
43
|
|
|
38
44
|
@state() private _hasIconSlotContent = false;
|
|
39
45
|
|
|
40
|
-
@
|
|
46
|
+
@property({ type: Boolean, reflect: true }) skeleton: boolean = false;
|
|
47
|
+
|
|
48
|
+
@property({ type: Boolean, reflect: true }) toggle: boolean = false;
|
|
49
|
+
|
|
50
|
+
@property({ type: Boolean, reflect: true }) selected: boolean = false;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Sets the delay for throttle in milliseconds. Defaults to 200 milliseconds.
|
|
54
|
+
*/
|
|
55
|
+
@property() throttleDelay = 200;
|
|
56
|
+
|
|
57
|
+
@property() tooltip?: string;
|
|
58
|
+
|
|
59
|
+
@property({ type: Boolean, reflect: true })
|
|
60
|
+
pressed = false;
|
|
61
|
+
|
|
62
|
+
@query('.button') readonly buttonElement!: HTMLElement | null;
|
|
63
|
+
|
|
64
|
+
override connectedCallback() {
|
|
65
|
+
super.connectedCallback();
|
|
66
|
+
this.addEventListener('click', this.__dispatchClickWithThrottle);
|
|
67
|
+
window.addEventListener('mouseup', this.__handlePress);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override disconnectedCallback() {
|
|
71
|
+
window.removeEventListener('mouseup', this.__handlePress);
|
|
72
|
+
this.removeEventListener('click', this.__dispatchClickWithThrottle);
|
|
73
|
+
super.disconnectedCallback();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
__handlePress = (event: KeyboardEvent | MouseEvent) => {
|
|
77
|
+
if (this.disabled || this.skeleton || this.softDisabled) return;
|
|
78
|
+
if (
|
|
79
|
+
event instanceof KeyboardEvent &&
|
|
80
|
+
event.type === 'keydown' &&
|
|
81
|
+
(event.key === 'Enter' || event.key === ' ')
|
|
82
|
+
) {
|
|
83
|
+
this.pressed = true;
|
|
84
|
+
} else if (event.type === 'mousedown') {
|
|
85
|
+
this.pressed = true;
|
|
86
|
+
} else {
|
|
87
|
+
this.pressed = false;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
__dispatchClickWithThrottle: (event: MouseEvent | KeyboardEvent) => void =
|
|
92
|
+
event => {
|
|
93
|
+
this.__dispatchClick(event);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
__dispatchClick = (event: MouseEvent | KeyboardEvent) => {
|
|
97
|
+
// If the button is soft-disabled or a disabled link, we need to explicitly
|
|
98
|
+
// prevent the click from propagating to other event listeners as well as
|
|
99
|
+
// prevent the default action.
|
|
100
|
+
if (this.softDisabled || (this.disabled && this.href) || this.skeleton) {
|
|
101
|
+
event.stopImmediatePropagation();
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!isActivationClick(event) || !this.buttonElement) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (this.toggle) {
|
|
111
|
+
this.selected = !this.selected;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.focus();
|
|
115
|
+
dispatchActivationClick(this.buttonElement);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
__renderDisabledReason(softDisabled: boolean) {
|
|
119
|
+
if (softDisabled)
|
|
120
|
+
return html`<div
|
|
121
|
+
id=${DISABLED_REASON_ID}
|
|
122
|
+
role="tooltip"
|
|
123
|
+
aria-label=${this.disabledReason}
|
|
124
|
+
class="screen-reader-only"
|
|
125
|
+
>
|
|
126
|
+
${this.disabledReason}
|
|
127
|
+
</div>`;
|
|
128
|
+
return nothing;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
__renderTooltip() {
|
|
132
|
+
if (this.tooltip) {
|
|
133
|
+
return html`<wc-tooltip class="tooltip" for="button"
|
|
134
|
+
>${this.tooltip}</wc-tooltip
|
|
135
|
+
>`;
|
|
136
|
+
}
|
|
137
|
+
return nothing;
|
|
138
|
+
}
|
|
41
139
|
|
|
42
140
|
override focus() {
|
|
43
141
|
this.buttonElement?.focus();
|
|
@@ -71,7 +169,6 @@ export class Chip extends BaseButton {
|
|
|
71
169
|
);
|
|
72
170
|
}
|
|
73
171
|
|
|
74
|
-
|
|
75
172
|
private _renderCloseButton() {
|
|
76
173
|
if (!this.dismissible) return nothing;
|
|
77
174
|
|
|
@@ -86,68 +183,71 @@ export class Chip extends BaseButton {
|
|
|
86
183
|
`;
|
|
87
184
|
}
|
|
88
185
|
|
|
89
|
-
|
|
90
|
-
|
|
91
186
|
render() {
|
|
187
|
+
return html`
|
|
188
|
+
<wc-focus-ring class="focus-ring" for="button"></wc-focus-ring>
|
|
189
|
+
<wc-elevation class="elevation"></wc-elevation>
|
|
190
|
+
<div class="background"></div>
|
|
191
|
+
<div class="outline"></div>
|
|
192
|
+
<wc-ripple class="ripple" for="button"></wc-ripple>
|
|
193
|
+
|
|
194
|
+
${this.renderChipElement()} ${this.__renderTooltip()}
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
renderChipElement() {
|
|
92
199
|
const cssClasses = {
|
|
93
200
|
chip: true,
|
|
94
201
|
button: true,
|
|
95
202
|
selected: this.selected,
|
|
96
203
|
dismissible: this.dismissible,
|
|
97
|
-
pressed: this.
|
|
204
|
+
pressed: this.pressed,
|
|
98
205
|
'icon-slot-has-content': this._hasIconSlotContent,
|
|
99
206
|
};
|
|
100
207
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
return html`<a
|
|
121
|
-
class=${classMap(cssClasses)}
|
|
122
|
-
id="button"
|
|
123
|
-
href=${this.href}
|
|
124
|
-
target=${this.target}
|
|
125
|
-
tabindex=${this.disabled ? '-1' : '0'}
|
|
126
|
-
|
|
127
|
-
@click=${this.__dispatchClick}
|
|
128
|
-
@mousedown=${this.__handlePress}
|
|
129
|
-
@keydown=${this.__handlePress}
|
|
130
|
-
@keyup=${this.__handlePress}
|
|
131
|
-
role="button"
|
|
132
|
-
|
|
133
|
-
aria-describedby=${ifDefined(this.softDisabled ? BaseButton.DISABLED_REASON_ID : undefined)}
|
|
134
|
-
?aria-disabled=${this.softDisabled}
|
|
135
|
-
|
|
136
|
-
${spread(this.configAria)}
|
|
137
|
-
>
|
|
138
|
-
${this.renderChipContent()}
|
|
139
|
-
</a>`;
|
|
208
|
+
if (!isLink(this)) {
|
|
209
|
+
return html`<button
|
|
210
|
+
class=${classMap(cssClasses)}
|
|
211
|
+
id="button"
|
|
212
|
+
type=${this.htmlType}
|
|
213
|
+
@click=${this.__dispatchClickWithThrottle}
|
|
214
|
+
@mousedown=${this.__handlePress}
|
|
215
|
+
@keydown=${this.__handlePress}
|
|
216
|
+
@keyup=${this.__handlePress}
|
|
217
|
+
aria-describedby=${ifDefined(
|
|
218
|
+
this.softDisabled ? DISABLED_REASON_ID : undefined,
|
|
219
|
+
)}
|
|
220
|
+
?aria-disabled=${this.softDisabled}
|
|
221
|
+
?disabled=${this.disabled}
|
|
222
|
+
${spread(this.configAria)}
|
|
223
|
+
>
|
|
224
|
+
${this.renderChipContent()}
|
|
225
|
+
</button>`;
|
|
140
226
|
}
|
|
227
|
+
return html`<a
|
|
228
|
+
class=${classMap(cssClasses)}
|
|
229
|
+
id="button"
|
|
230
|
+
href=${this.href}
|
|
231
|
+
target=${this.target}
|
|
232
|
+
tabindex=${this.disabled ? '-1' : '0'}
|
|
233
|
+
@click=${this.__dispatchClick}
|
|
234
|
+
@mousedown=${this.__handlePress}
|
|
235
|
+
@keydown=${this.__handlePress}
|
|
236
|
+
@keyup=${this.__handlePress}
|
|
237
|
+
role="button"
|
|
238
|
+
aria-describedby=${ifDefined(
|
|
239
|
+
this.softDisabled ? DISABLED_REASON_ID : undefined,
|
|
240
|
+
)}
|
|
241
|
+
?aria-disabled=${this.softDisabled}
|
|
242
|
+
${spread(this.configAria)}
|
|
243
|
+
>
|
|
244
|
+
${this.renderChipContent()}
|
|
245
|
+
</a>`;
|
|
246
|
+
}
|
|
141
247
|
|
|
142
248
|
renderChipContent() {
|
|
143
249
|
return html`
|
|
144
|
-
<wc-focus-ring class="focus-ring" for="button"></wc-focus-ring>
|
|
145
|
-
<wc-elevation class="elevation"></wc-elevation>
|
|
146
|
-
<div class="background"></div>
|
|
147
|
-
<div class="outline"></div>
|
|
148
|
-
<wc-ripple class="ripple"></wc-ripple>
|
|
149
250
|
<div class="tag-content">
|
|
150
|
-
|
|
151
251
|
<div class="icon-slot-container">
|
|
152
252
|
${this.selected
|
|
153
253
|
? html`<wc-icon class="selected-icon" name="check"></wc-icon>`
|
|
@@ -155,8 +255,7 @@ export class Chip extends BaseButton {
|
|
|
155
255
|
</div>
|
|
156
256
|
<div class="label-container">
|
|
157
257
|
<slot></slot>
|
|
158
|
-
</div>
|
|
159
|
-
|
|
258
|
+
</div>
|
|
160
259
|
${this._renderCloseButton()}
|
|
161
260
|
</div>
|
|
162
261
|
`;
|