@redvars/peacock 3.6.2 → 3.7.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.
Files changed (200) hide show
  1. package/dist/ButtonConstants-D06bY4uy.js +114 -0
  2. package/dist/ButtonConstants-D06bY4uy.js.map +1 -0
  3. package/dist/{BaseHyperlinkMixin-BNuwbiEf.js → NativeHyperlinkMixin-DrYXyfMQ.js} +8 -10
  4. package/dist/NativeHyperlinkMixin-DrYXyfMQ.js.map +1 -0
  5. package/dist/assets/components.css +1 -1
  6. package/dist/assets/components.css.map +1 -1
  7. package/dist/assets/styles.css +1 -1
  8. package/dist/assets/styles.css.map +1 -1
  9. package/dist/button-colors-Dwnez1tR.js +586 -0
  10. package/dist/button-colors-Dwnez1tR.js.map +1 -0
  11. package/dist/button-group.js +8 -8
  12. package/dist/button-group.js.map +1 -1
  13. package/dist/button.js +236 -133
  14. package/dist/button.js.map +1 -1
  15. package/dist/calendar-column-view.js +0 -1
  16. package/dist/calendar-column-view.js.map +1 -1
  17. package/dist/calendar-month-view.js +0 -1
  18. package/dist/calendar-month-view.js.map +1 -1
  19. package/dist/canvas.js +126 -107
  20. package/dist/canvas.js.map +1 -1
  21. package/dist/card-content.js +0 -1
  22. package/dist/card-content.js.map +1 -1
  23. package/dist/card.js +96 -90
  24. package/dist/card.js.map +1 -1
  25. package/dist/cb-compound-expression.js +4 -1
  26. package/dist/cb-compound-expression.js.map +1 -1
  27. package/dist/cb-divider.js +0 -1
  28. package/dist/cb-divider.js.map +1 -1
  29. package/dist/cb-expression.js +0 -2
  30. package/dist/cb-expression.js.map +1 -1
  31. package/dist/cb-predicate.js +0 -1
  32. package/dist/cb-predicate.js.map +1 -1
  33. package/dist/code-highlighter.js +23 -6
  34. package/dist/code-highlighter.js.map +1 -1
  35. package/dist/custom-elements-jsdocs.json +5079 -17882
  36. package/dist/custom-elements.json +19272 -19314
  37. package/dist/fab.js +181 -117
  38. package/dist/fab.js.map +1 -1
  39. package/dist/flow-designer.js +4 -4
  40. package/dist/icon-button-DJ0kZXYr.js +318 -0
  41. package/dist/icon-button-DJ0kZXYr.js.map +1 -0
  42. package/dist/index.js +7 -7
  43. package/dist/{navigation-rail-CD7IrqbN.js → navigation-rail-CM_svs5_.js} +1311 -730
  44. package/dist/navigation-rail-CM_svs5_.js.map +1 -0
  45. package/dist/observe-slot-change-D8Xg-kSS.js +60 -0
  46. package/dist/observe-slot-change-D8Xg-kSS.js.map +1 -0
  47. package/dist/peacock-loader.js +10 -7
  48. package/dist/peacock-loader.js.map +1 -1
  49. package/dist/popover-content.js +0 -1
  50. package/dist/popover-content.js.map +1 -1
  51. package/dist/search.js +15 -15
  52. package/dist/search.js.map +1 -1
  53. package/dist/src/__controllers/attachable-controller.d.ts +109 -0
  54. package/dist/src/__mixins/{BaseButtonMixin.d.ts → NativeButtonMixin.d.ts} +3 -3
  55. package/dist/src/__mixins/{BaseHyperlinkMixin.d.ts → NativeHyperlinkMixin.d.ts} +3 -4
  56. package/dist/src/__utils/is-link.d.ts +1 -0
  57. package/dist/src/__utils/observe-slot-change.d.ts +1 -1
  58. package/dist/src/accordion/accordion-item.d.ts +0 -1
  59. package/dist/src/breadcrumb/breadcrumb-item/breadcrumb-item.d.ts +0 -1
  60. package/dist/src/button/ButtonConstants.d.ts +1 -0
  61. package/dist/src/button/GroupButtonInterface.d.ts +4 -0
  62. package/dist/src/button/button/button.d.ts +32 -7
  63. package/dist/src/button/button-group/button-group.d.ts +2 -1
  64. package/dist/src/button/icon-button/icon-button.d.ts +26 -5
  65. package/dist/src/button/index.d.ts +1 -1
  66. package/dist/src/calendar/calendar-column-view.d.ts +0 -1
  67. package/dist/src/calendar/calendar-month-view.d.ts +0 -1
  68. package/dist/src/canvas/canvas.d.ts +3 -3
  69. package/dist/src/card/card-content.d.ts +0 -1
  70. package/dist/src/card/card.d.ts +9 -6
  71. package/dist/src/chip/chip/chip.d.ts +22 -3
  72. package/dist/src/condition-builder/cb-compound-expression.d.ts +0 -1
  73. package/dist/src/condition-builder/cb-divider.d.ts +0 -1
  74. package/dist/src/condition-builder/cb-expression.d.ts +0 -1
  75. package/dist/src/condition-builder/cb-predicate.d.ts +0 -1
  76. package/dist/src/fab/fab.d.ts +20 -6
  77. package/dist/src/field/field.d.ts +1 -0
  78. package/dist/src/focus-ring/focus-ring.d.ts +26 -20
  79. package/dist/src/image/image.d.ts +2 -2
  80. package/dist/src/index.d.ts +1 -0
  81. package/dist/src/input/input.d.ts +1 -3
  82. package/dist/src/item/index.d.ts +1 -0
  83. package/dist/src/item/item.d.ts +49 -0
  84. package/dist/src/link/link.d.ts +1 -1
  85. package/dist/src/list/list-item.d.ts +1 -2
  86. package/dist/src/menu/menu-item/menu-item.d.ts +9 -11
  87. package/dist/src/menu/sub-menu/sub-menu.d.ts +1 -1
  88. package/dist/src/navigation-rail/navigation-rail-item.d.ts +0 -2
  89. package/dist/src/navigation-rail/navigation-rail.d.ts +2 -6
  90. package/dist/src/popover/popover-content.d.ts +0 -1
  91. package/dist/src/ripple/ripple.d.ts +9 -1
  92. package/dist/src/search/search.d.ts +2 -6
  93. package/dist/src/segmented-button/segmented-button.d.ts +0 -1
  94. package/dist/src/select/option.d.ts +0 -1
  95. package/dist/src/sidebar-menu/sidebar-menu-item.d.ts +0 -1
  96. package/dist/src/sidebar-menu/sidebar-sub-menu.d.ts +0 -1
  97. package/dist/src/tabs/tab-panel.d.ts +0 -1
  98. package/dist/src/tabs/tab.d.ts +4 -6
  99. package/dist/test/item.test.d.ts +1 -0
  100. package/dist/tsconfig.tsbuildinfo +1 -1
  101. package/package.json +4 -2
  102. package/readme.md +2 -2
  103. package/scss/components.scss +0 -1
  104. package/scss/mixin.scss +33 -13
  105. package/scss/styles.scss +1 -3
  106. package/src/__controllers/attachable-controller.ts +198 -0
  107. package/src/__mixins/NativeButtonMixin.ts +87 -0
  108. package/src/__mixins/{BaseHyperlinkMixin.ts → NativeHyperlinkMixin.ts} +15 -15
  109. package/src/__utils/is-link.ts +3 -0
  110. package/src/__utils/observe-slot-change.ts +46 -14
  111. package/src/accordion/accordion-item.scss +1 -1
  112. package/src/accordion/accordion-item.ts +0 -1
  113. package/src/breadcrumb/breadcrumb-item/breadcrumb-item.ts +0 -1
  114. package/src/button/ButtonConstants.ts +1 -0
  115. package/src/button/GroupButtonInterface.ts +4 -0
  116. package/src/button/button/button-colors.scss +2 -2
  117. package/src/button/button/button-layers.scss +124 -0
  118. package/src/button/button/button-sizes.scss +31 -53
  119. package/src/button/button/button.scss +139 -262
  120. package/src/button/button/button.ts +260 -106
  121. package/src/button/button/only-button.scss +13 -0
  122. package/src/button/button-group/button-group.ts +59 -17
  123. package/src/button/icon-button/icon-button-sizes.scss +12 -27
  124. package/src/button/icon-button/icon-button.ts +191 -83
  125. package/src/button/index.ts +1 -1
  126. package/src/calendar/calendar-column-view.ts +0 -1
  127. package/src/calendar/calendar-month-view.ts +0 -1
  128. package/src/canvas/canvas.scss +18 -6
  129. package/src/canvas/canvas.ts +125 -103
  130. package/src/card/card-content.ts +2 -3
  131. package/src/card/card.scss +87 -95
  132. package/src/card/card.ts +62 -60
  133. package/src/chip/chip/chip.scss +66 -71
  134. package/src/chip/chip/chip.ts +155 -56
  135. package/src/code-highlighter/code-highlighter.scss +1 -1
  136. package/src/code-highlighter/code-highlighter.ts +20 -5
  137. package/src/condition-builder/cb-compound-expression.scss +4 -0
  138. package/src/condition-builder/cb-compound-expression.ts +0 -1
  139. package/src/condition-builder/cb-divider.ts +0 -1
  140. package/src/condition-builder/cb-expression.scss +0 -1
  141. package/src/condition-builder/cb-expression.ts +0 -1
  142. package/src/condition-builder/cb-predicate.ts +0 -1
  143. package/src/elevation/elevation.scss +5 -1
  144. package/src/empty-state/empty-state.scss +1 -0
  145. package/src/fab/fab-colors.scss +2 -2
  146. package/src/fab/fab-sizes.scss +24 -34
  147. package/src/fab/fab.scss +77 -71
  148. package/src/fab/fab.ts +141 -65
  149. package/src/field/field.ts +6 -0
  150. package/src/focus-ring/focus-ring.ts +81 -72
  151. package/src/image/image.scss +21 -16
  152. package/src/image/image.ts +13 -14
  153. package/src/index.ts +1 -0
  154. package/src/input/input.ts +16 -25
  155. package/src/item/index.ts +1 -0
  156. package/src/item/item.scss +195 -0
  157. package/src/item/item.ts +362 -0
  158. package/src/link/link.scss +1 -10
  159. package/src/link/link.ts +4 -2
  160. package/src/list/list-item.ts +8 -8
  161. package/src/menu/menu/menu.ts +5 -9
  162. package/src/menu/menu-item/menu-item.scss +30 -108
  163. package/src/menu/menu-item/menu-item.ts +102 -133
  164. package/src/menu/sub-menu/sub-menu.ts +6 -3
  165. package/src/navigation-rail/navigation-rail-item.scss +5 -0
  166. package/src/navigation-rail/navigation-rail-item.ts +10 -15
  167. package/src/navigation-rail/navigation-rail.ts +2 -6
  168. package/src/peacock-loader.ts +5 -1
  169. package/src/popover/popover-content.ts +0 -1
  170. package/src/ripple/ripple.ts +52 -20
  171. package/src/search/search.scss +3 -0
  172. package/src/search/search.ts +11 -16
  173. package/src/segmented-button/segmented-button.ts +0 -1
  174. package/src/select/option.ts +1 -2
  175. package/src/select/select.scss +1 -10
  176. package/src/select/select.ts +2 -0
  177. package/src/sidebar-menu/sidebar-menu-item.ts +0 -1
  178. package/src/sidebar-menu/sidebar-sub-menu.ts +0 -1
  179. package/src/skeleton/skeleton.scss +5 -1
  180. package/src/tabs/tab-panel.ts +0 -1
  181. package/src/tabs/tab.ts +60 -70
  182. package/src/text/text.css-component.scss +3 -21
  183. package/src/tooltip/tooltip.scss +5 -8
  184. package/src/tooltip/tooltip.ts +1 -2
  185. package/dist/BaseButton-BNFAYn-S.js +0 -219
  186. package/dist/BaseButton-BNFAYn-S.js.map +0 -1
  187. package/dist/BaseHyperlinkMixin-BNuwbiEf.js.map +0 -1
  188. package/dist/button-colors-AvGh22Zn.js +0 -561
  189. package/dist/button-colors-AvGh22Zn.js.map +0 -1
  190. package/dist/icon-button-ohxHhy4t.js +0 -247
  191. package/dist/icon-button-ohxHhy4t.js.map +0 -1
  192. package/dist/navigation-rail-CD7IrqbN.js.map +0 -1
  193. package/dist/observe-slot-change-BGJfgg2E.js +0 -31
  194. package/dist/observe-slot-change-BGJfgg2E.js.map +0 -1
  195. package/dist/src/button/BaseButton.d.ts +0 -28
  196. package/dist/src/focus-ring/FocusAttachableController.d.ts +0 -8
  197. package/src/__mixins/BaseButtonMixin.ts +0 -83
  198. package/src/button/BaseButton.ts +0 -113
  199. package/src/focus-ring/FocusAttachableController.ts +0 -28
  200. 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 { dispatchActivationClick, isActivationClick } from '../__utils/dispatch-event-utils.js';
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 BaseHyperlinkMixin from '@/__mixins/BaseHyperlinkMixin.js';
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
- * <h3>Title</h3>
27
- * <p>Supportive text</p>
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 BaseHyperlinkMixin(LitElement) {
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
- * If button is disabled, the reason why it is disabled.
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
- const isLink = this.__isLink();
149
- const disableSlotTabbing = this.actionable || isLink;
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) || isLink,
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 && !isLink) {
162
- return html`<div
163
- class=${classMap(cssClasses)}
164
- id="card"
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 (!isLink) {
180
+ if (!isLinkElement) {
171
181
  return html`<button
172
- class=${classMap(cssClasses)}
173
- id="card"
174
- tabindex=${this.#tabindex}
175
- @click=${this.__dispatchClickWithThrottle}
176
- @mousedown=${this.__handlePress}
177
- @keydown=${this.__handlePress}
178
- @keyup=${this.__handlePress}
179
- ?aria-describedby=${this.__getDisabledReasonID()}
180
- aria-disabled=${`${this.disabled}`}
181
- ?disabled=${this.disabled}
182
- >
183
- ${this.renderCardContent(disableSlotTabbing)}
184
- </button>`;
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
- class=${classMap(cssClasses)}
188
- id="card"
189
- tabindex=${this.#tabindex}
190
- href=${this.href}
191
- target=${this.target}
192
- @click=${this.__dispatchClickWithThrottle}
193
- @mousedown=${this.__handlePress}
194
- @keydown=${this.__handlePress}
195
- @keyup=${this.__handlePress}
196
- role="button"
197
- ?aria-describedby=${this.__getDisabledReasonID()}
198
- aria-disabled=${`${this.disabled}`}
199
- >
200
- ${this.renderCardContent(disableSlotTabbing)}
201
- </a>`;
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
  }
@@ -3,7 +3,8 @@
3
3
  @include mixin.base-styles;
4
4
 
5
5
  :host {
6
- display: inline-block;
6
+ position: relative;
7
+ display: inline-flex;
7
8
  --chip-container-color: var(--color-surface);
8
9
  --chip-label-text-color: var(--color-on-surface);
9
10
  --chip-outline-color: var(--color-outline-variant);
@@ -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
- * Tag background layers
128
- */
129
- .background {
130
- display: block;
131
- position: absolute;
132
- left: 0;
133
- width: 100%;
134
- height: 100%;
135
- border-radius: var(--chip-container-shape);
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
- /** Color state management */
163
- .chip {
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
- &:hover {
169
- --_chip-state-opacity: 0.08;
170
- }
164
+ :host:hover {
165
+ --_chip-state-opacity: 0.08;
166
+ }
171
167
 
172
- &.pressed {
173
- --_chip-state-opacity: 0.12;
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
- &.disabled {
182
- --_chip-container-color: var(--color-on-surface);
183
- --_chip-container-opacity: 0.1;
184
- --_chip-text-color: var(--color-on-surface);
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
- .ripple {
188
- display: none;
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
+ }
@@ -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 { dispatchActivationClick, isActivationClick } from '@/__utils/dispatch-event-utils.js';
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 { BaseButton } from '@/button/BaseButton.js';
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 BaseButton {
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
- @state() private _isPressed = false;
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._isPressed,
204
+ pressed: this.pressed,
98
205
  'icon-slot-has-content': this._hasIconSlotContent,
99
206
  };
100
207
 
101
- if (!this.__isLink()) {
102
- return html`<button
103
- class=${classMap(cssClasses)}
104
- id="button"
105
- type=${this.htmlType}
106
- @click=${this.__dispatchClickWithThrottle}
107
- @mousedown=${this.__handlePress}
108
- @keydown=${this.__handlePress}
109
- @keyup=${this.__handlePress}
110
-
111
- aria-describedby=${ifDefined(this.softDisabled ? BaseButton.DISABLED_REASON_ID : undefined)}
112
- ?aria-disabled=${this.softDisabled}
113
-
114
- ?disabled=${this.disabled}
115
- ${spread(this.configAria)}
116
- >
117
- ${this.renderChipContent()}
118
- </button>`;
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
  `;
@@ -6,7 +6,7 @@
6
6
  :host {
7
7
  display: block;
8
8
  height: 100%;
9
- --code-highlighter-background: var(--color-surface-container-high);
9
+ --code-highlighter-background: var(--color-surface-container);
10
10
  }
11
11
 
12
12
  .code-loader {