@redvars/peacock 3.16.0 → 3.17.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 (147) hide show
  1. package/dist/assets/styles.css +1 -1
  2. package/dist/assets/styles.css.map +1 -1
  3. package/dist/assets/theme.js +19 -19
  4. package/dist/assets/tokens.css +1 -1
  5. package/dist/assets/tokens.css.map +1 -1
  6. package/dist/card-content.js +8 -7
  7. package/dist/card-content.js.map +1 -1
  8. package/dist/card.js +142 -98
  9. package/dist/card.js.map +1 -1
  10. package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
  11. package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
  12. package/dist/chart-area.js +78 -0
  13. package/dist/chart-area.js.map +1 -0
  14. package/dist/chart-bar.js +283 -213
  15. package/dist/chart-bar.js.map +1 -1
  16. package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
  17. package/dist/chart-base-C2qRMF48.js.map +1 -0
  18. package/dist/chart-doughnut.js +55 -287
  19. package/dist/chart-doughnut.js.map +1 -1
  20. package/dist/chart-line.js +626 -0
  21. package/dist/chart-line.js.map +1 -0
  22. package/dist/chart-pie.js +637 -195
  23. package/dist/chart-pie.js.map +1 -1
  24. package/dist/code-editor.js +704 -131
  25. package/dist/code-editor.js.map +1 -1
  26. package/dist/code-group.js +188 -0
  27. package/dist/code-group.js.map +1 -0
  28. package/dist/code-highlighter.js +895 -257
  29. package/dist/code-highlighter.js.map +1 -1
  30. package/dist/custom-elements-jsdocs.json +1675 -222
  31. package/dist/custom-elements.json +13351 -3970
  32. package/dist/image.js +5 -1
  33. package/dist/image.js.map +1 -1
  34. package/dist/index.js +8 -7
  35. package/dist/index.js.map +1 -1
  36. package/dist/loader-full.js +1 -1
  37. package/dist/loader.js +9 -3
  38. package/dist/loader.js.map +1 -1
  39. package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
  40. package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
  41. package/dist/path-CJ0Arqcy.js +166 -0
  42. package/dist/path-CJ0Arqcy.js.map +1 -0
  43. package/dist/snackbar.js +89 -34
  44. package/dist/snackbar.js.map +1 -1
  45. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  46. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  47. package/dist/src/__internal/chart/paths.d.ts +5 -0
  48. package/dist/src/__internal/chart/types.d.ts +42 -0
  49. package/dist/src/card/card-content.d.ts +2 -3
  50. package/dist/src/card/card.d.ts +31 -17
  51. package/dist/src/chart-area/chart-area.d.ts +54 -0
  52. package/dist/src/chart-area/index.d.ts +1 -0
  53. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  54. package/dist/src/chart-bar/index.d.ts +0 -1
  55. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  56. package/dist/src/chart-line/chart-line.d.ts +69 -0
  57. package/dist/src/chart-line/index.d.ts +1 -0
  58. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  59. package/dist/src/code-editor/code-editor.d.ts +52 -13
  60. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  61. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  62. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  63. package/dist/src/code-highlighter/index.d.ts +1 -0
  64. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  65. package/dist/src/code-highlighter/local.d.ts +4 -1
  66. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  67. package/dist/src/index.d.ts +4 -2
  68. package/dist/src/snackbar/snackbar.d.ts +13 -1
  69. package/dist/src/toolbar/toolbar.d.ts +56 -51
  70. package/dist/table.js +9 -4
  71. package/dist/table.js.map +1 -1
  72. package/dist/test/chart.test.d.ts +1 -0
  73. package/dist/test/code-highlighter.test.d.ts +1 -0
  74. package/dist/token-colors-0TFHWbcq.js +81 -0
  75. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  76. package/dist/toolbar.js +195 -184
  77. package/dist/toolbar.js.map +1 -1
  78. package/dist/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +1 -2
  80. package/readme.md +7 -6
  81. package/scss/_code-block.scss +139 -0
  82. package/scss/tokens.css +24 -0
  83. package/src/__internal/chart/cartesian-chart.ts +404 -0
  84. package/src/__internal/chart/chart-base.scss +252 -0
  85. package/src/__internal/chart/chart-base.ts +474 -0
  86. package/src/__internal/chart/paths.ts +28 -0
  87. package/src/__internal/chart/types.ts +49 -0
  88. package/src/card/card-content.ts +12 -9
  89. package/src/card/card.scss +66 -54
  90. package/src/card/card.ts +109 -73
  91. package/src/chart-area/chart-area.ts +82 -0
  92. package/src/chart-area/index.ts +1 -0
  93. package/src/chart-bar/chart-bar.ts +336 -250
  94. package/src/chart-bar/index.ts +0 -1
  95. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  96. package/src/chart-doughnut/demo/index.html +14 -22
  97. package/src/chart-line/chart-line.scss +25 -0
  98. package/src/chart-line/chart-line.ts +346 -0
  99. package/src/chart-line/index.ts +1 -0
  100. package/src/chart-pie/chart-pie.scss +35 -16
  101. package/src/chart-pie/chart-pie.ts +282 -188
  102. package/src/chart-pie/demo/index.html +13 -21
  103. package/src/code-editor/code-editor.scss +132 -36
  104. package/src/code-editor/code-editor.ts +308 -88
  105. package/src/code-editor/demo/index.html +39 -12
  106. package/src/code-editor/editor-theme.ts +213 -0
  107. package/src/code-highlighter/code-group.scss +34 -0
  108. package/src/code-highlighter/code-group.ts +173 -0
  109. package/src/code-highlighter/code-highlighter.scss +226 -111
  110. package/src/code-highlighter/code-highlighter.ts +554 -199
  111. package/src/code-highlighter/demo/index.html +68 -4
  112. package/src/code-highlighter/index.ts +1 -0
  113. package/src/code-highlighter/line-ranges.ts +81 -0
  114. package/src/code-highlighter/local.ts +9 -3
  115. package/src/code-highlighter/token-colors.ts +42 -0
  116. package/src/index.ts +4 -2
  117. package/src/loader.ts +8 -2
  118. package/src/snackbar/demo/index.html +39 -4
  119. package/src/snackbar/snackbar.scss +27 -10
  120. package/src/snackbar/snackbar.ts +80 -37
  121. package/src/table/table.scss +7 -1
  122. package/src/table/table.ts +4 -3
  123. package/src/toolbar/toolbar-colors.scss +6 -7
  124. package/src/toolbar/toolbar.scss +35 -106
  125. package/src/toolbar/toolbar.ts +180 -80
  126. package/dist/array-D5vjT2Xm.js +0 -14
  127. package/dist/array-D5vjT2Xm.js.map +0 -1
  128. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  129. package/dist/chart-stacked-bar.js +0 -403
  130. package/dist/chart-stacked-bar.js.map +0 -1
  131. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  132. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  133. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  134. package/dist/pie-Dz0IDiPt.js +0 -537
  135. package/dist/pie-Dz0IDiPt.js.map +0 -1
  136. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  137. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  138. package/dist/pierre-light-BEkAPImt.js +0 -4
  139. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  140. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  141. package/dist/src/code-highlighter/constants.d.ts +0 -1
  142. package/dist/transform-DSwFSqzD.js.map +0 -1
  143. package/src/chart-bar/chart-bar.scss +0 -58
  144. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  145. package/src/chart-doughnut/chart-donut.scss +0 -37
  146. package/src/code-highlighter/constants.ts +0 -117
  147. /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * SVG path for a rectangle with its own radius per corner, in the order top-left, top-right,
3
+ * bottom-right, bottom-left. Every path has the same commands, so d3 can tween between any two.
4
+ */
5
+ export function roundedRectPath(
6
+ x: number,
7
+ y: number,
8
+ width: number,
9
+ height: number,
10
+ radii: [number, number, number, number],
11
+ ): string {
12
+ const w = Math.max(width, 0);
13
+ const h = Math.max(height, 0);
14
+ const limit = Math.min(w / 2, h / 2);
15
+ const [tl, tr, br, bl] = radii.map(r => Math.max(Math.min(r, limit), 0));
16
+ return [
17
+ `M${x + tl},${y}`,
18
+ `H${x + w - tr}`,
19
+ `A${tr},${tr} 0 0 1 ${x + w},${y + tr}`,
20
+ `V${y + h - br}`,
21
+ `A${br},${br} 0 0 1 ${x + w - br},${y + h}`,
22
+ `H${x + bl}`,
23
+ `A${bl},${bl} 0 0 1 ${x},${y + h - bl}`,
24
+ `V${y + tl}`,
25
+ `A${tl},${tl} 0 0 1 ${x + tl},${y}`,
26
+ 'Z',
27
+ ].join('');
28
+ }
@@ -0,0 +1,49 @@
1
+ /** One series in a bar, line or area chart, keyed by the data field that holds its values. */
2
+ export type ChartSeriesConfig = {
3
+ /** Display name in the legend and tooltip. Defaults to the key. */
4
+ label?: string;
5
+ /** Any CSS color. Defaults to the next `--color-chart-n` token. */
6
+ color?: string;
7
+ };
8
+
9
+ /** Maps a data field to how its series is shown, for example `{ desktop: { label: 'Desktop' } }`. */
10
+ export type ChartConfig = Record<string, ChartSeriesConfig>;
11
+
12
+ /** One row of cartesian chart data: the category field (`index`) plus a number per series. */
13
+ export type ChartDatum = Record<string, unknown>;
14
+
15
+ /** Formats a value for tooltips, value labels and axis ticks. */
16
+ export type ChartValueFormatter = (value: number) => string;
17
+
18
+ /** A series resolved from config: key, label and color. */
19
+ export type ChartSeries = {
20
+ key: string;
21
+ label: string;
22
+ color: string;
23
+ };
24
+
25
+ /** A row in the tooltip. */
26
+ export type ChartTooltipRow = {
27
+ key: string;
28
+ label: string;
29
+ color: string;
30
+ value: string;
31
+ };
32
+
33
+ /** What the tooltip shows and where. Coordinates are relative to the plot element. */
34
+ export type ChartTooltipModel = {
35
+ title: string;
36
+ rows: ChartTooltipRow[];
37
+ x: number;
38
+ y: number;
39
+ };
40
+
41
+ /** Detail of the `chart-select` event. */
42
+ export type ChartSelectDetail = {
43
+ /** Index of the selected category or slice in `data`. */
44
+ index: number;
45
+ /** Series key, when a single series was selected. */
46
+ series?: string;
47
+ /** The selected data row. */
48
+ datum: unknown;
49
+ };
@@ -5,21 +5,24 @@ import IndividualComponent from '../IndividualComponent.js';
5
5
  * @label Card Content
6
6
  * @tag wc-card-content
7
7
  * @rawTag card-content
8
+ * @summary A padded block inside a card. A card can hold several, next to edge-to-edge media.
8
9
  *
9
- * @cssprop --card-content-padding - Inner padding for the card container. Defaults to 1rem.
10
- *
11
- * ```
10
+ * @cssprop --card-content-padding - Padding on all sides. Defaults to 1rem.
12
11
  */
13
12
  @IndividualComponent
14
13
  export class CardContent extends LitElement {
14
+ // ── Static ────────────────────────────────────────────────────────────────
15
+
15
16
  static styles = css`
16
- :host {
17
- padding-inline: 1rem;
18
- display: block;
19
- }
17
+ :host {
18
+ display: block;
19
+ padding: var(--card-content-padding, 1rem);
20
+ }
20
21
  `;
21
22
 
22
- render() {
23
+ // ── Render ────────────────────────────────────────────────────────────────
24
+
25
+ render() {
23
26
  return html`<slot></slot>`;
24
- }
27
+ }
25
28
  }
@@ -57,7 +57,6 @@
57
57
  overflow: hidden;
58
58
  padding: var(--card-padding);
59
59
 
60
- border: 1px solid transparent; /* Fixes overflow issues with border */
61
60
  border-start-start-radius: var(--_container-shape-start-start);
62
61
  border-start-end-radius: var(--_container-shape-start-end);
63
62
  border-end-start-radius: var(--_container-shape-end-start);
@@ -148,10 +147,13 @@
148
147
  corner-shape: var(--_container-corner-shape-variant);
149
148
  }
150
149
 
151
- :host([actionable]:not([disabled])),
150
+ /*
151
+ Actionable and link cards. A disabled one with a disabled-reason stays
152
+ focusable, so it keeps the focus ring; only enabled ones get the ripple.
153
+ */
154
+ :host([actionable]),
152
155
  :host([href]) {
153
- .focus-ring,
154
- .ripple {
156
+ .focus-ring {
155
157
  display: block;
156
158
  }
157
159
 
@@ -160,59 +162,66 @@
160
162
  }
161
163
  }
162
164
 
165
+ :host([actionable]:not([disabled])),
166
+ :host([href]:not([disabled])) {
167
+ .ripple {
168
+ display: block;
169
+ }
170
+ }
171
+
172
+ /*
173
+ Variants. Hover and press states apply to enabled actionable and link cards
174
+ only, so a static card never suggests it can be clicked.
175
+ */
163
176
  :host([variant='elevated']) {
164
177
  --_container-color: var(--elevated-card-container-color);
165
178
  --_label-text-color: var(--elevated-card-label-text-color);
166
179
  --_container-elevation-level: 1;
167
180
  --_container-state-color: var(--_label-text-color);
181
+ }
168
182
 
169
- &:hover:not([disabled]) {
170
- --_container-elevation-level: 2;
171
- --_container-state-opacity: 0.08;
172
- }
173
-
174
- &:active:not([disabled]) {
175
- --_container-elevation-level: 1;
176
- --_container-state-opacity: 0.12;
177
- }
183
+ :host([variant='elevated'][actionable]:not([disabled]):hover),
184
+ :host([variant='elevated'][href]:not([disabled]):hover) {
185
+ --_container-elevation-level: 2;
186
+ --_container-state-opacity: 0.08;
187
+ }
178
188
 
179
- &[disabled] {
180
- --_container-color: var(--color-on-surface);
181
- --_container-opacity: 0.1;
182
- --_label-text-color: var(--color-on-surface);
183
- --_label-text-opacity: 0.38;
189
+ :host([variant='elevated'][actionable]:not([disabled]):active),
190
+ :host([variant='elevated'][href]:not([disabled]):active) {
191
+ --_container-elevation-level: 1;
192
+ --_container-state-opacity: 0.12;
193
+ }
184
194
 
185
- .ripple {
186
- display: none;
187
- }
188
- }
195
+ :host([variant='elevated'][disabled]) {
196
+ --_container-color: var(--color-on-surface);
197
+ --_container-opacity: 0.1;
198
+ --_label-text-color: var(--color-on-surface);
199
+ --_label-text-opacity: 0.38;
189
200
  }
190
201
 
191
202
  :host([variant='filled']) {
192
203
  --_container-color: var(--filled-card-container-color);
193
204
  --_label-text-color: var(--filled-card-label-text-color);
194
205
  --_container-state-color: var(--_label-text-color);
206
+ }
195
207
 
196
- &:hover:not([disabled]) {
197
- --_container-elevation-level: 1;
198
- --_container-state-opacity: 0.08;
199
- }
200
-
201
- &:active:not([disabled]) {
202
- --_container-elevation-level: 0;
203
- --_container-state-opacity: 0.1;
204
- }
208
+ :host([variant='filled'][actionable]:not([disabled]):hover),
209
+ :host([variant='filled'][href]:not([disabled]):hover) {
210
+ --_container-elevation-level: 1;
211
+ --_container-state-opacity: 0.08;
212
+ }
205
213
 
206
- &[disabled] {
207
- --_container-color: var(--color-on-surface);
208
- --_container-opacity: 0.1;
209
- --_label-text-color: var(--color-on-surface);
210
- --_label-text-opacity: 0.38;
214
+ :host([variant='filled'][actionable]:not([disabled]):active),
215
+ :host([variant='filled'][href]:not([disabled]):active) {
216
+ --_container-elevation-level: 0;
217
+ --_container-state-opacity: 0.1;
218
+ }
211
219
 
212
- .ripple {
213
- display: none;
214
- }
215
- }
220
+ :host([variant='filled'][disabled]) {
221
+ --_container-color: var(--color-on-surface);
222
+ --_container-opacity: 0.1;
223
+ --_label-text-color: var(--color-on-surface);
224
+ --_label-text-opacity: 0.38;
216
225
  }
217
226
 
218
227
  :host([variant='outlined']) {
@@ -225,22 +234,25 @@
225
234
  display: block;
226
235
  }
227
236
 
228
- &:hover:not([disabled]) {
229
- --_container-state-opacity: 0.08;
237
+ /* Keep content, such as edge-to-edge media, from covering the outline. */
238
+ .card-content {
239
+ border: var(--_outline-width) solid transparent;
230
240
  }
241
+ }
231
242
 
232
- &:active:not([disabled]) {
233
- --_container-state-opacity: 0.12;
234
- }
243
+ :host([variant='outlined'][actionable]:not([disabled]):hover),
244
+ :host([variant='outlined'][href]:not([disabled]):hover) {
245
+ --_container-state-opacity: 0.08;
246
+ }
235
247
 
236
- &[disabled] {
237
- --_outline-color: var(--color-on-surface);
238
- --_label-text-color: var(--color-on-surface);
239
- --_label-text-opacity: 0.38;
240
- --_outline-opacity: 0.12;
248
+ :host([variant='outlined'][actionable]:not([disabled]):active),
249
+ :host([variant='outlined'][href]:not([disabled]):active) {
250
+ --_container-state-opacity: 0.12;
251
+ }
241
252
 
242
- .ripple {
243
- display: none;
244
- }
245
- }
253
+ :host([variant='outlined'][disabled]) {
254
+ --_outline-color: var(--color-on-surface);
255
+ --_label-text-color: var(--color-on-surface);
256
+ --_label-text-opacity: 0.38;
257
+ --_outline-opacity: 0.12;
246
258
  }
package/src/card/card.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { LitElement, html, nothing } from 'lit';
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 { ifDefined } from 'lit/directives/if-defined.js';
4
5
  import {
5
6
  dispatchActivationClick,
6
7
  isActivationClick,
@@ -15,66 +16,89 @@ import NativeHyperlinkMixin from '@/__internal/mixins/NativeHyperlinkMixin.js';
15
16
 
16
17
  type CardVariant = 'elevated' | 'filled' | 'outlined';
17
18
 
19
+ const DISABLED_REASON_ID = 'disabled-reason';
20
+
18
21
  /**
19
22
  * @label Card
20
23
  * @tag wc-card
21
24
  * @rawTag card
22
- * @summary A card surface for grouping related content.
23
- * @cssprop --card-padding - Inner padding for the card container. Defaults to 1rem.
24
- * @cssprop --card-shape - Corner radius for the card container. Defaults to a large radius.
25
- * @cssprop --card-gap - Gap between slotted children.
25
+ * @summary A surface that groups content and actions about one subject. Set `actionable` to make the whole card a button, or `href` to make it a link.
26
+ * @cssprop --card-container-shape - Corner radius of the card. Defaults to `--shape-corner-large`.
27
+ * @cssprop --card-padding - Padding inside the card, around its children. Defaults to 0; `wc-card-content` adds its own padding.
28
+ * @cssprop --card-gap - Gap between the card's children. Defaults to 0.
26
29
  *
27
30
  * @example
28
31
  * ```html
29
- * <wc-card variant="outlined" style="padding-block: 1rem;">
32
+ * <wc-card variant="outlined">
30
33
  * <wc-card-content>
31
- * <h3 class="text-headline">Title</h3>
32
- * <p class="text-body">Supportive text</p>
34
+ * <h3 class="text-title-large">Title</h3>
35
+ * <p class="text-body-medium">Supporting text</p>
33
36
  * </wc-card-content>
34
37
  * </wc-card>
35
38
  * ```
36
39
  */
37
40
  @IndividualComponent
38
41
  export class Card extends NativeHyperlinkMixin(LitElement) {
42
+ // ── Static ────────────────────────────────────────────────────────────────
43
+
39
44
  static styles = [styles, colorStyles];
40
45
 
41
- #id = crypto.randomUUID();
46
+ // ── Properties ────────────────────────────────────────────────────────────
42
47
 
48
+ /**
49
+ * Visual style of the card: `elevated` (a raised surface with a shadow), `filled` (a tonal surface)
50
+ * or `outlined` (a bordered surface). Defaults to `elevated`.
51
+ */
43
52
  @property({ type: String, reflect: true })
44
53
  variant: CardVariant = 'elevated';
45
54
 
55
+ /**
56
+ * Dims the card and makes its content inert. An actionable or link card also stops responding
57
+ * to clicks and leaves the tab order, unless `disabled-reason` is set.
58
+ */
46
59
  @property({ type: Boolean, reflect: true })
47
60
  disabled: boolean = false;
48
61
 
62
+ /**
63
+ * Makes the whole card a single button that fires `click`. Its content becomes inert, so don't
64
+ * put buttons or links inside an actionable card.
65
+ */
49
66
  @property({ type: Boolean, reflect: true })
50
67
  actionable: boolean = false;
51
68
 
52
69
  /**
53
- * If button is disabled, the reason why it is disabled.
70
+ * Why an actionable or link card is disabled. The card stays focusable and screen readers read
71
+ * the reason with it.
54
72
  */
55
73
  @property({ attribute: 'disabled-reason' })
56
74
  disabledReason: string = '';
57
75
 
58
76
  /**
59
- * Sets the delay for throttle in milliseconds. When null (default), no throttle is applied.
77
+ * Delay in milliseconds for throttling activation of an actionable or link card. When unset
78
+ * (default), no throttle is applied.
60
79
  */
61
- @property() throttleDelay?: number;
80
+ @property({ type: Number, attribute: 'throttle-delay' })
81
+ throttleDelay?: number;
62
82
 
63
- /**
64
- * States
65
- */
83
+ /** Whether the default slot holds meaningful content. */
66
84
  @state()
67
85
  private slotHasContent = false;
68
86
 
87
+ // ── Queries ───────────────────────────────────────────────────────────────
88
+
69
89
  @query('.card') readonly cardElement!: HTMLElement | null;
70
90
 
71
- #tabindex?: number = 0;
91
+ // ── Constructor ───────────────────────────────────────────────────────────
72
92
 
73
93
  constructor() {
74
94
  super();
75
- this.addEventListener('click', this.__dispatchClickWithThrottle);
95
+ // Look the handler up on every click, so the throttled version set in
96
+ // firstUpdated() is the one that runs.
97
+ this.addEventListener('click', event => this.__handleClick(event));
76
98
  }
77
99
 
100
+ // ── Lifecycle ─────────────────────────────────────────────────────────────
101
+
78
102
  override firstUpdated() {
79
103
  if (typeof this.throttleDelay === 'number') {
80
104
  this.__dispatchClickWithThrottle = throttle(
@@ -86,26 +110,28 @@ export class Card extends NativeHyperlinkMixin(LitElement) {
86
110
  this.renderRoot.querySelector('slot'),
87
111
  hasContent => {
88
112
  this.slotHasContent = hasContent;
89
- this.requestUpdate();
90
113
  },
91
114
  );
92
115
  }
93
116
 
94
- __dispatchClickWithThrottle: (event: MouseEvent | KeyboardEvent) => void =
95
- event => {
96
- this.__dispatchClick(event);
97
- };
117
+ // ── Private methods ───────────────────────────────────────────────────────
98
118
 
99
- __dispatchClick = (event: MouseEvent | KeyboardEvent) => {
100
- // If the button is soft-disabled or a disabled link, we need to explicitly
101
- // prevent the click from propagating to other event listeners as well as
102
- // prevent the default action.
103
- if (this.disabled && this.href) {
119
+ __handleClick(event: MouseEvent | KeyboardEvent) {
120
+ // A disabled card never activates, and consumer click listeners on it never run.
121
+ if (this.disabled) {
104
122
  event.stopImmediatePropagation();
105
123
  event.preventDefault();
106
124
  return;
107
125
  }
126
+ this.__dispatchClickWithThrottle(event);
127
+ }
108
128
 
129
+ __dispatchClickWithThrottle: (event: MouseEvent | KeyboardEvent) => void =
130
+ event => {
131
+ this.__dispatchClick(event);
132
+ };
133
+
134
+ __dispatchClick = (event: MouseEvent | KeyboardEvent) => {
109
135
  if (!isActivationClick(event) || !this.cardElement) {
110
136
  return;
111
137
  }
@@ -114,90 +140,100 @@ export class Card extends NativeHyperlinkMixin(LitElement) {
114
140
  dispatchActivationClick(this.cardElement);
115
141
  };
116
142
 
117
- __getDisabledReasonID() {
118
- return this.disabled && this.disabledReason
119
- ? `disabled-reason-${this.#id}`
120
- : nothing;
143
+ /** True when a disabled interactive card should stay focusable to expose its reason. */
144
+ __isSoftDisabled() {
145
+ return this.disabled && !!this.disabledReason;
121
146
  }
122
147
 
123
- __renderDisabledReason() {
124
- const disabledReasonID = this.__getDisabledReasonID();
125
- if (disabledReasonID)
126
- return html`<div
127
- id="disabled-reason-${this.#id}"
128
- role="tooltip"
129
- aria-label=${this.disabledReason}
130
- class="screen-reader-only"
131
- >
132
- ${this.disabledReason}
133
- </div>`;
134
- return nothing;
148
+ __getDisabledReasonID() {
149
+ return this.__isSoftDisabled() ? DISABLED_REASON_ID : undefined;
135
150
  }
136
151
 
137
- render() {
138
- const isLinkElement = isLink(this);
139
- const disableSlotTabbing = this.actionable || isLinkElement;
152
+ // ── Render helpers ────────────────────────────────────────────────────────
140
153
 
141
- return html`
142
- <wc-focus-ring class="focus-ring" for="card"></wc-focus-ring>
143
- <wc-elevation class="elevation"></wc-elevation>
144
- <div class="background"></div>
145
- <div class="outline"></div>
146
- <wc-ripple class="ripple" for="card"></wc-ripple>
147
-
148
- ${this.renderCardElement(isLinkElement, disableSlotTabbing)}
149
- `;
154
+ renderDisabledReason() {
155
+ if (!this.__isSoftDisabled()) return nothing;
156
+ return html`<div
157
+ id=${DISABLED_REASON_ID}
158
+ role="tooltip"
159
+ aria-label=${this.disabledReason}
160
+ class="screen-reader-only"
161
+ >
162
+ ${this.disabledReason}
163
+ </div>`;
150
164
  }
151
165
 
152
- renderCardElement(isLinkElement: boolean, disableSlotTabbing: boolean) {
166
+ renderCardElement(isLinkElement: boolean) {
167
+ const interactive = this.actionable || isLinkElement;
153
168
  const cssClasses = {
154
169
  card: true,
155
170
  'card-element': true,
156
171
  [`variant-${this.variant}`]: true,
157
- actionable: (this.actionable && !this.disabled) || isLinkElement,
172
+ actionable: interactive && !this.disabled,
158
173
  disabled: this.disabled,
159
174
  'has-content': this.slotHasContent,
160
175
  };
176
+ const inertContent = interactive || this.disabled;
161
177
 
162
- if (!this.actionable && !isLinkElement) {
178
+ if (!interactive) {
163
179
  return html`<div class=${classMap(cssClasses)} id="card">
164
- ${this.renderCardContent(disableSlotTabbing)}
180
+ ${this.renderCardContent(inertContent)}
165
181
  </div>`;
166
182
  }
167
183
 
184
+ const softDisabled = this.__isSoftDisabled();
185
+ const removedFromTabOrder = this.disabled && !softDisabled;
186
+
168
187
  if (!isLinkElement) {
169
188
  return html`<button
170
189
  class=${classMap(cssClasses)}
171
190
  id="card"
172
- tabindex=${this.#tabindex}
173
- ?aria-describedby=${this.__getDisabledReasonID()}
174
- aria-disabled=${`${this.disabled}`}
175
- ?disabled=${this.disabled}
191
+ type="button"
192
+ aria-describedby=${ifDefined(this.__getDisabledReasonID())}
193
+ aria-disabled=${ifDefined(this.disabled ? 'true' : undefined)}
194
+ ?disabled=${removedFromTabOrder}
176
195
  >
177
- ${this.renderCardContent(disableSlotTabbing)}
196
+ ${this.renderCardContent(inertContent)} ${this.renderDisabledReason()}
178
197
  </button>`;
179
198
  }
199
+
180
200
  return html`<a
181
201
  class=${classMap(cssClasses)}
182
202
  id="card"
183
- tabindex=${this.#tabindex}
184
- href=${this.href}
185
- target=${this.target}
186
- role="button"
187
- ?aria-describedby=${this.__getDisabledReasonID()}
188
- aria-disabled=${`${this.disabled}`}
203
+ href=${ifDefined(this.disabled ? undefined : this.href)}
204
+ target=${ifDefined(this.disabled ? undefined : this.target)}
205
+ rel=${ifDefined(this.disabled ? undefined : this.rel)}
206
+ download=${ifDefined(this.disabled ? undefined : this.download)}
207
+ role=${ifDefined(this.disabled ? 'link' : undefined)}
208
+ tabindex=${removedFromTabOrder ? '-1' : '0'}
209
+ aria-describedby=${ifDefined(this.__getDisabledReasonID())}
210
+ aria-disabled=${ifDefined(this.disabled ? 'true' : undefined)}
189
211
  >
190
- ${this.renderCardContent(disableSlotTabbing)}
212
+ ${this.renderCardContent(inertContent)} ${this.renderDisabledReason()}
191
213
  </a>`;
192
214
  }
193
215
 
194
- renderCardContent(disableSlotTabbing: boolean) {
216
+ renderCardContent(inertContent: boolean) {
195
217
  return html`
196
218
  <div class="card-content">
197
- <div class="slot-container" ?inert=${disableSlotTabbing}>
219
+ <div class="slot-container" ?inert=${inertContent}>
198
220
  <slot></slot>
199
221
  </div>
200
222
  </div>
201
223
  `;
202
224
  }
225
+
226
+ // ── Render ────────────────────────────────────────────────────────────────
227
+
228
+ render() {
229
+ return html`
230
+ <wc-focus-ring class="focus-ring" for="card"></wc-focus-ring>
231
+ <wc-elevation class="elevation"></wc-elevation>
232
+ <div class="background"></div>
233
+ <div class="outline"></div>
234
+ <wc-ripple class="ripple" for="card"></wc-ripple>
235
+
236
+ ${this.renderCardElement(isLink(this))}
237
+ `;
238
+ }
203
239
  }
@@ -0,0 +1,82 @@
1
+ import { property } from 'lit/decorators.js';
2
+ import IndividualComponent from '@/IndividualComponent.js';
3
+ import { ChartLine } from '../chart-line/chart-line.js';
4
+
5
+ export type {
6
+ ChartConfig,
7
+ ChartDatum,
8
+ ChartSelectDetail,
9
+ ChartSeriesConfig,
10
+ ChartValueFormatter,
11
+ } from '../__internal/chart/types.js';
12
+ export type { ChartCurve } from '../chart-line/chart-line.js';
13
+
14
+ /**
15
+ * @label Area Chart
16
+ * @tag wc-chart-area
17
+ * @rawTag chart-area
18
+ * @summary A line chart with the area under each line filled, optionally stacked to show parts of a total over time.
19
+ * @tags charts
20
+ *
21
+ * @example
22
+ * ```html
23
+ * <wc-chart-area index="month" stacked label="Visitors by month"></wc-chart-area>
24
+ * <script>
25
+ * const chart = document.querySelector('wc-chart-area');
26
+ * chart.config = {
27
+ * desktop: { label: 'Desktop' },
28
+ * mobile: { label: 'Mobile' },
29
+ * };
30
+ * chart.data = [
31
+ * { month: 'January', desktop: 186, mobile: 80 },
32
+ * { month: 'February', desktop: 305, mobile: 200 },
33
+ * { month: 'March', desktop: 237, mobile: 120 },
34
+ * ];
35
+ * </script>
36
+ * ```
37
+ *
38
+ * @slot empty - Shown when there is no data. Defaults to "No data".
39
+ *
40
+ * @fires chart-select - A category was clicked or chosen with Enter. `detail` holds `index` and `datum`.
41
+ *
42
+ * @csspart container - The outer wrapper.
43
+ * @csspart plot - The focusable plot area holding the SVG.
44
+ * @csspart tooltip - The tooltip.
45
+ * @csspart legend - The legend.
46
+ *
47
+ * @cssprop --color-chart-1 - Color of the first series; series cycle through `--color-chart-1` to `--color-chart-8`.
48
+ * @cssprop --chart-line-width - Stroke width of the lines. Defaults to `2px`.
49
+ * @cssprop --chart-grid-color - Gridline and baseline color. Defaults to `--color-outline-variant`.
50
+ * @cssprop --chart-axis-color - Axis label color. Defaults to `--color-on-surface-variant`.
51
+ * @cssprop --chart-dim-opacity - Opacity of series that are not highlighted. Defaults to `0.4`.
52
+ */
53
+ @IndividualComponent
54
+ export class ChartArea extends ChartLine {
55
+ // ── Properties
56
+
57
+ /** Stacks the series on each other so the top line shows the total. */
58
+ @property({ type: Boolean, reflect: true }) stacked: boolean = false;
59
+
60
+ // ── Constructor
61
+
62
+ constructor() {
63
+ super();
64
+ this.filled = true;
65
+ }
66
+
67
+ // ── Private methods
68
+
69
+ protected drawProperties(): string[] {
70
+ return [...super.drawProperties(), 'stacked'];
71
+ }
72
+
73
+ protected isStacked(): boolean {
74
+ return this.stacked;
75
+ }
76
+ }
77
+
78
+ declare global {
79
+ interface HTMLElementTagNameMap {
80
+ 'wc-chart-area': ChartArea;
81
+ }
82
+ }
@@ -0,0 +1 @@
1
+ export { ChartArea } from './chart-area.js';