@redvars/peacock 3.3.1 → 3.3.2

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 (88) hide show
  1. package/dist/{IndividualComponent-tDnXrOLV.js → IndividualComponent-Dt5xirYG.js} +2 -2
  2. package/dist/{IndividualComponent-tDnXrOLV.js.map → IndividualComponent-Dt5xirYG.js.map} +1 -1
  3. package/dist/array-D5vjT2Xm.js +14 -0
  4. package/dist/array-D5vjT2Xm.js.map +1 -0
  5. package/dist/{button-trIfcqC7.js → button-ClzS8JLq.js} +3 -3
  6. package/dist/{button-trIfcqC7.js.map → button-ClzS8JLq.js.map} +1 -1
  7. package/dist/{button-group-DA7xoziD.js → button-group-BMS5WvaF.js} +4 -4
  8. package/dist/{button-group-DA7xoziD.js.map → button-group-BMS5WvaF.js.map} +1 -1
  9. package/dist/button-group.js +4 -4
  10. package/dist/button.js +3 -3
  11. package/dist/card.js +104 -0
  12. package/dist/card.js.map +1 -0
  13. package/dist/chart-bar-DbnXQgvS.js +1121 -0
  14. package/dist/chart-bar-DbnXQgvS.js.map +1 -0
  15. package/dist/chart-bar.js +259 -0
  16. package/dist/chart-bar.js.map +1 -0
  17. package/dist/chart-donut.js +4 -2
  18. package/dist/chart-donut.js.map +1 -1
  19. package/dist/chart-doughnut.js +4 -2
  20. package/dist/chart-doughnut.js.map +1 -1
  21. package/dist/chart-pie.js +4 -2
  22. package/dist/chart-pie.js.map +1 -1
  23. package/dist/chart-stacked-bar.js +401 -0
  24. package/dist/chart-stacked-bar.js.map +1 -0
  25. package/dist/{class-map-hJdvjl-W.js → class-map-59YGWLnx.js} +2 -2
  26. package/dist/{class-map-hJdvjl-W.js.map → class-map-59YGWLnx.js.map} +1 -1
  27. package/dist/clock.js +1 -1
  28. package/dist/code-editor.js +3 -3
  29. package/dist/code-highlighter.js +3 -3
  30. package/dist/custom-elements-jsdocs.json +2308 -766
  31. package/dist/custom-elements.json +909 -25
  32. package/dist/index.js +16 -9
  33. package/dist/index.js.map +1 -1
  34. package/dist/number-counter.js +2 -2
  35. package/dist/{observe-theme-change-BISF-Gl5.js → observe-theme-change-pALI5fmV.js} +2 -2
  36. package/dist/{observe-theme-change-BISF-Gl5.js.map → observe-theme-change-pALI5fmV.js.map} +1 -1
  37. package/dist/peacock-loader.js +22 -526
  38. package/dist/peacock-loader.js.map +1 -1
  39. package/dist/pie-Dz0IDiPt.js +537 -0
  40. package/dist/pie-Dz0IDiPt.js.map +1 -0
  41. package/dist/{tree-view-CLolVlU0.js → snackbar-74YCdMPL.js} +1005 -143
  42. package/dist/snackbar-74YCdMPL.js.map +1 -0
  43. package/dist/src/card/card.d.ts +27 -0
  44. package/dist/src/card/index.d.ts +1 -0
  45. package/dist/src/chart-bar/chart-bar.d.ts +53 -0
  46. package/dist/src/chart-bar/chart-stacked-bar.d.ts +78 -0
  47. package/dist/src/chart-bar/index.d.ts +2 -0
  48. package/dist/src/index.d.ts +5 -0
  49. package/dist/src/menu/menu-item/menu-item.d.ts +1 -1
  50. package/dist/src/snackbar/index.d.ts +1 -0
  51. package/dist/src/snackbar/snackbar.d.ts +40 -0
  52. package/dist/src/tabs/tab-group.d.ts +1 -1
  53. package/dist/src/tabs/tab-panel.d.ts +1 -0
  54. package/dist/src/tabs/tab.d.ts +2 -1
  55. package/dist/{style-map-CfNHEkQp.js → style-map-DcB52w-l.js} +2 -2
  56. package/dist/{style-map-CfNHEkQp.js.map → style-map-DcB52w-l.js.map} +1 -1
  57. package/dist/test/card.test.d.ts +1 -0
  58. package/dist/test/chart-bar.test.d.ts +1 -0
  59. package/dist/test/snackbar.test.d.ts +1 -0
  60. package/dist/{transform-DRuHEvar.js → transform-DSwFSqzD.js} +13 -558
  61. package/dist/transform-DSwFSqzD.js.map +1 -0
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/dist/{unsafe-html-CV6Je6HL.js → unsafe-html-C2r3PyzF.js} +2 -2
  64. package/dist/{unsafe-html-CV6Je6HL.js.map → unsafe-html-C2r3PyzF.js.map} +1 -1
  65. package/package.json +1 -1
  66. package/readme.md +2 -2
  67. package/src/card/card.scss +61 -0
  68. package/src/card/card.ts +38 -0
  69. package/src/card/index.ts +1 -0
  70. package/src/chart-bar/chart-bar.scss +58 -0
  71. package/src/chart-bar/chart-bar.ts +306 -0
  72. package/src/chart-bar/chart-stacked-bar.ts +402 -0
  73. package/src/chart-bar/index.ts +2 -0
  74. package/src/index.ts +5 -0
  75. package/src/menu/menu-item/menu-item.ts +1 -1
  76. package/src/peacock-loader.ts +14 -0
  77. package/src/snackbar/demo/index.html +29 -0
  78. package/src/snackbar/index.ts +1 -0
  79. package/src/snackbar/snackbar.scss +73 -0
  80. package/src/snackbar/snackbar.ts +151 -0
  81. package/src/tabs/tab-group.ts +57 -28
  82. package/src/tabs/tab-panel.scss +3 -3
  83. package/src/tabs/tab-panel.ts +2 -0
  84. package/src/tabs/tab.scss +76 -2
  85. package/src/tabs/tab.ts +28 -6
  86. package/src/tabs/tabs.ts +15 -3
  87. package/dist/transform-DRuHEvar.js.map +0 -1
  88. package/dist/tree-view-CLolVlU0.js.map +0 -1
@@ -0,0 +1,402 @@
1
+ import { html, LitElement, PropertyValues } from 'lit';
2
+ import { property, query } from 'lit/decorators.js';
3
+ import { styleMap } from 'lit/directives/style-map.js';
4
+ import IndividualComponent from 'src/IndividualComponent.js';
5
+ import * as d3 from 'd3';
6
+ import styles from './chart-bar.scss';
7
+
8
+ export type ChartStackedSegment = {
9
+ name: string;
10
+ value: number;
11
+ label?: string;
12
+ color?: string;
13
+ };
14
+
15
+ export type ChartStackedBarItem = {
16
+ name: string;
17
+ label?: string;
18
+ segments: ChartStackedSegment[];
19
+ };
20
+
21
+ const chartColors: string[] = [];
22
+ ['purple', 'blue', 'red', 'green', 'yellow', 'orange'].forEach(colorName => {
23
+ chartColors.push(`var(--color-${colorName})`);
24
+ });
25
+
26
+ const DEFAULT_WIDTH = 520;
27
+ const DEFAULT_HEIGHT = 360;
28
+ const BAR_RADIUS = 8;
29
+ const DURATION = 450;
30
+
31
+ function debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T {
32
+ let timer: ReturnType<typeof setTimeout>;
33
+ return ((...args: any[]) => {
34
+ clearTimeout(timer);
35
+ timer = setTimeout(() => fn(...args), wait);
36
+ }) as T;
37
+ }
38
+
39
+ /**
40
+ * @label Chart Stacked Bar
41
+ * @tag wc-chart-stacked-bar
42
+ * @rawTag chart-stacked-bar
43
+ * @summary A stacked bar chart that groups series by category using Material Design 3 tokens.
44
+ * @tags charts
45
+ *
46
+ * @example
47
+ * ```html
48
+ * <wc-chart-stacked-bar width="560" height="360"></wc-chart-stacked-bar>
49
+ * <script>
50
+ * document.querySelector('wc-chart-stacked-bar').data = [
51
+ * {
52
+ * name: 'q1',
53
+ * label: 'Q1',
54
+ * segments: [
55
+ * { name: 'mobile', label: 'Mobile', value: 40 },
56
+ * { name: 'web', label: 'Web', value: 25 },
57
+ * { name: 'store', label: 'Store', value: 15 },
58
+ * ],
59
+ * },
60
+ * {
61
+ * name: 'q2',
62
+ * label: 'Q2',
63
+ * segments: [
64
+ * { name: 'mobile', label: 'Mobile', value: 32 },
65
+ * { name: 'web', label: 'Web', value: 30 },
66
+ * { name: 'store', label: 'Store', value: 18 },
67
+ * ],
68
+ * },
69
+ * ];
70
+ * </script>
71
+ * ```
72
+ */
73
+ @IndividualComponent
74
+ export class ChartStackedBar extends LitElement {
75
+ static styles = [styles];
76
+
77
+ @query('svg')
78
+ private svgElement?: SVGElement;
79
+
80
+ /** Width of the chart in pixels. */
81
+ @property({ type: Number, reflect: true }) width: number = 0;
82
+
83
+ /** Height of the chart in pixels. */
84
+ @property({ type: Number, reflect: true }) height: number = DEFAULT_HEIGHT;
85
+
86
+ /** Margin around the chart drawing area. */
87
+ @property({ type: Number }) margin: number = 28;
88
+
89
+ /** Chart data array. Each item holds the stacked segments for a category. */
90
+ @property({ type: Array }) data: ChartStackedBarItem[] = [];
91
+
92
+ /** Whether to render total value labels above each stack. */
93
+ @property({ type: Boolean, attribute: 'show-values' }) showValues: boolean = true;
94
+
95
+ /** Whether to render the legend. */
96
+ @property({ type: Boolean, attribute: 'show-legend' }) showLegend: boolean = true;
97
+
98
+ private _initialized = false;
99
+
100
+ private _debouncedRenderChart = debounce(() => {
101
+ this._renderChart(true);
102
+ }, 200);
103
+
104
+ firstUpdated() {
105
+ this._renderChart(false);
106
+ }
107
+
108
+ updated(changedProperties: PropertyValues) {
109
+ if (!this._initialized) {
110
+ this._initialized = true;
111
+ return;
112
+ }
113
+ const watchedProps = [
114
+ 'width',
115
+ 'height',
116
+ 'margin',
117
+ 'data',
118
+ 'showValues',
119
+ 'showLegend',
120
+ ];
121
+ const hasChanged = watchedProps.some(prop => changedProperties.has(prop));
122
+ if (hasChanged) {
123
+ this._debouncedRenderChart();
124
+ }
125
+ }
126
+
127
+ private _getSegmentKeys() {
128
+ const keys = new Set<string>();
129
+ this.data?.forEach(item => {
130
+ item.segments?.forEach(segment => keys.add(segment.name));
131
+ });
132
+ return Array.from(keys);
133
+ }
134
+
135
+ private _getColorScale(keys: string[]) {
136
+ return d3
137
+ .scaleOrdinal<string, string>()
138
+ .domain(keys)
139
+ .range(chartColors);
140
+ }
141
+
142
+ private _getColorMap(
143
+ keys: string[],
144
+ scale: d3.ScaleOrdinal<string, string>,
145
+ ) {
146
+ const map = new Map<string, string>();
147
+ keys.forEach(key => {
148
+ const override = this.data
149
+ .map(item => item.segments.find(seg => seg.name === key)?.color)
150
+ .find(color => !!color);
151
+ map.set(key, override || scale(key));
152
+ });
153
+ return map;
154
+ }
155
+
156
+ private _getSegmentLabel(key: string) {
157
+ const segment = this.data
158
+ .map(item => item.segments.find(seg => seg.name === key))
159
+ .find(Boolean);
160
+ return segment?.label ?? key;
161
+ }
162
+
163
+ private _getTotals() {
164
+ return this.data.map(item =>
165
+ item.segments.reduce((sum, seg) => sum + seg.value, 0),
166
+ );
167
+ }
168
+
169
+ private _renderChart(animate: boolean) {
170
+ if (!this.svgElement) return;
171
+
172
+ const width = this.width > 0 ? this.width : DEFAULT_WIDTH;
173
+ const height = this.height > 0 ? this.height : DEFAULT_HEIGHT;
174
+ const margin = Math.max(this.margin, 16);
175
+ const data = this.data ?? [];
176
+
177
+ const svg = d3.select(this.svgElement);
178
+ svg.attr('width', width).attr('height', height);
179
+
180
+ const innerWidth = Math.max(width - margin * 2, 0);
181
+ const innerHeight = Math.max(height - margin * 2, 0);
182
+
183
+ const container = svg.select<SVGGElement>('.chart-container');
184
+ container.attr('transform', `translate(${margin},${margin})`);
185
+
186
+ if (!data.length || innerWidth === 0 || innerHeight === 0) {
187
+ container.select('.bars').selectAll('*').remove();
188
+ container.select('.x-axis').selectAll('*').remove();
189
+ container.select('.y-grid').selectAll('*').remove();
190
+ container.select('.value-labels').selectAll('*').remove();
191
+ return;
192
+ }
193
+
194
+ const keys = this._getSegmentKeys();
195
+ const colorScale = this._getColorScale(keys);
196
+ const colorMap = this._getColorMap(keys, colorScale);
197
+
198
+ const totals = this._getTotals();
199
+ const xScale = d3
200
+ .scaleBand<string>()
201
+ .domain(data.map(d => d.name))
202
+ .range([0, innerWidth])
203
+ .padding(0.3);
204
+ const maxValue = d3.max(totals) ?? 0;
205
+ const yScale = d3
206
+ .scaleLinear()
207
+ .domain([0, maxValue || 1])
208
+ .nice()
209
+ .range([innerHeight, 0]);
210
+
211
+ const stackedSeries = d3
212
+ .stack<ChartStackedBarItem, string>()
213
+ .keys(keys)
214
+ .value(
215
+ (d, key) => d.segments.find(segment => segment.name === key)?.value ?? 0,
216
+ )(data);
217
+
218
+ const yGrid = container.select<SVGGElement>('.y-grid');
219
+ yGrid
220
+ .call(
221
+ d3
222
+ .axisLeft(yScale)
223
+ .ticks(5)
224
+ .tickSize(-innerWidth)
225
+ .tickFormat(() => ''),
226
+ )
227
+ .selectAll('.tick text')
228
+ .remove();
229
+ yGrid.select('.domain').remove();
230
+ yGrid.selectAll('.tick line').attr('class', 'gridline');
231
+
232
+ const xAxis = container.select<SVGGElement>('.x-axis');
233
+ xAxis
234
+ .attr('transform', `translate(0,${innerHeight})`)
235
+ .call(
236
+ d3
237
+ .axisBottom(xScale)
238
+ .tickSizeOuter(0)
239
+ .tickFormat(name => {
240
+ const entry = data.find(d => d.name === name);
241
+ return entry?.label ?? name;
242
+ }),
243
+ );
244
+ xAxis.select('.domain').attr('stroke', 'var(--color-outline-variant)');
245
+ xAxis.selectAll('.tick line').remove();
246
+ xAxis
247
+ .selectAll('.tick text')
248
+ .attr('class', 'axis-label')
249
+ .attr('dy', '1.1em');
250
+
251
+ const barGroups = container
252
+ .select('.bars')
253
+ .selectAll<SVGGElement, d3.Series<ChartStackedBarItem, string>>(
254
+ '.bar-group',
255
+ )
256
+ .data(stackedSeries, series => series.key)
257
+ .join(
258
+ enter =>
259
+ enter
260
+ .append('g')
261
+ .attr('class', 'bar-group')
262
+ .style('fill', series => colorMap.get(series.key) ?? ''),
263
+ update => update,
264
+ exit => exit.remove(),
265
+ )
266
+ .style('fill', series => colorMap.get(series.key) ?? colorScale(series.key));
267
+
268
+ const segmentJoin = barGroups
269
+ .selectAll<SVGRectElement, d3.SeriesPoint<ChartStackedBarItem>>('rect')
270
+ .data(series => series, d => d.data.name)
271
+ .join(
272
+ enter =>
273
+ enter
274
+ .append('rect')
275
+ .attr('class', 'stacked-segment')
276
+ .attr('x', d => xScale(d.data.name) ?? 0)
277
+ .attr('width', xScale.bandwidth())
278
+ .attr('y', innerHeight)
279
+ .attr('height', 0)
280
+ .attr('rx', BAR_RADIUS)
281
+ .attr('ry', BAR_RADIUS),
282
+ update => update,
283
+ exit =>
284
+ exit
285
+ .transition()
286
+ .duration(DURATION)
287
+ .attr('y', innerHeight)
288
+ .attr('height', 0)
289
+ .remove(),
290
+ );
291
+
292
+ segmentJoin
293
+ .attr('x', d => xScale(d.data.name) ?? 0)
294
+ .attr('width', xScale.bandwidth())
295
+ .attr('rx', BAR_RADIUS)
296
+ .attr('ry', BAR_RADIUS);
297
+
298
+ if (animate) {
299
+ segmentJoin
300
+ .transition()
301
+ .duration(DURATION)
302
+ .attr('y', d => yScale(d[1]))
303
+ .attr('height', d => yScale(d[0]) - yScale(d[1]));
304
+ } else {
305
+ segmentJoin
306
+ .attr('y', d => yScale(d[1]))
307
+ .attr('height', d => yScale(d[0]) - yScale(d[1]));
308
+ }
309
+
310
+ const totalLabels = container
311
+ .select('.value-labels')
312
+ .selectAll<SVGTextElement, ChartStackedBarItem>('text')
313
+ .data(this.showValues ? data : [], d => d.name)
314
+ .join(
315
+ enter =>
316
+ enter
317
+ .append('text')
318
+ .attr('class', 'value-label')
319
+ .attr('text-anchor', 'middle')
320
+ .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)
321
+ .attr('y', innerHeight - 6)
322
+ .text(d =>
323
+ d.segments
324
+ .reduce((sum, seg) => sum + seg.value, 0)
325
+ .toLocaleString(),
326
+ ),
327
+ update => update,
328
+ exit => exit.remove(),
329
+ );
330
+
331
+ const labelPosition = (item: ChartStackedBarItem) => {
332
+ const total = item.segments.reduce((sum, seg) => sum + seg.value, 0);
333
+ const offset = yScale(total) - 8;
334
+ return Math.min(offset, innerHeight - 8);
335
+ };
336
+
337
+ if (animate) {
338
+ totalLabels
339
+ .transition()
340
+ .duration(DURATION)
341
+ .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)
342
+ .attr('y', d => labelPosition(d))
343
+ .text(d =>
344
+ d.segments
345
+ .reduce((sum, seg) => sum + seg.value, 0)
346
+ .toLocaleString(),
347
+ );
348
+ } else {
349
+ totalLabels
350
+ .attr('x', d => (xScale(d.name) ?? 0) + xScale.bandwidth() / 2)
351
+ .attr('y', d => labelPosition(d))
352
+ .text(d =>
353
+ d.segments
354
+ .reduce((sum, seg) => sum + seg.value, 0)
355
+ .toLocaleString(),
356
+ );
357
+ }
358
+ }
359
+
360
+ render() {
361
+ const keys = this._getSegmentKeys();
362
+ const colorScale = this._getColorScale(keys);
363
+ const colorMap = this._getColorMap(keys, colorScale);
364
+
365
+ const legendItems = keys.map(key => ({
366
+ name: this._getSegmentLabel(key),
367
+ color: colorMap.get(key) ?? colorScale(key),
368
+ }));
369
+
370
+ return html`
371
+ <div class="chart-frame">
372
+ <svg role="img" aria-label="Stacked bar chart">
373
+ <g class="chart-container">
374
+ <g class="y-grid"></g>
375
+ <g class="bars"></g>
376
+ <g class="x-axis"></g>
377
+ <g class="value-labels"></g>
378
+ </g>
379
+ </svg>
380
+ ${this.showLegend && legendItems.length
381
+ ? html`<div class="legend" role="list">
382
+ ${legendItems.map(
383
+ item => html`<span class="legend-item" role="listitem">
384
+ <span
385
+ class="swatch"
386
+ style=${styleMap({ background: item.color })}
387
+ ></span>
388
+ <span>${item.name}</span>
389
+ </span>`,
390
+ )}
391
+ </div>`
392
+ : null}
393
+ </div>
394
+ `;
395
+ }
396
+ }
397
+
398
+ declare global {
399
+ interface HTMLElementTagNameMap {
400
+ 'wc-chart-stacked-bar': ChartStackedBar;
401
+ }
402
+ }
@@ -0,0 +1,2 @@
1
+ export { ChartBar } from './chart-bar.js';
2
+ export { ChartStackedBar } from './chart-stacked-bar.js';
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@ export { DatePicker } from './date-picker/index.js';
22
22
  export { TimePicker } from './time-picker/index.js';
23
23
  export { Textarea } from './textarea/index.js';
24
24
  export { Switch } from './switch/index.js';
25
+ export { Checkbox } from './checkbox/index.js';
25
26
  export { Spinner } from './spinner/index.js';
26
27
  export { Container } from './container/index.js';
27
28
 
@@ -36,8 +37,12 @@ export { CodeEditor } from './code-editor/index.js';
36
37
  export { Image } from './image/index.js';
37
38
  export { Tab, TabGroup, TabPanel, Tabs } from './tabs/index.js';
38
39
  export { Slider } from './slider/index.js';
40
+ export { ChartDonut } from './chart-donut/index.js';
39
41
  export { ChartDoughnut } from './chart-doughnut/index.js';
40
42
  export { ChartPie } from './chart-pie/index.js';
43
+ export { ChartBar, ChartStackedBar } from './chart-bar/index.js';
41
44
  export { Table } from './table/index.js';
42
45
  export { Pagination } from './pagination/index.js';
43
46
  export { TreeView, TreeNode } from './tree-view/index.js';
47
+ export { Card } from './card/index.js';
48
+ export { Snackbar } from './snackbar/index.js';
@@ -8,7 +8,7 @@ import colorStyles from './menu-item-colors.scss';
8
8
  * @label Menu Item
9
9
  * @tag wc-menu-item
10
10
  * @rawTag menu-item
11
- * @parentRawTag menu-list
11
+ * @parentRawTag menu
12
12
  * @summary An item in a menu list.
13
13
  * @tags navigation
14
14
  *
@@ -51,6 +51,8 @@ import { Slider } from './slider/slider.js';
51
51
  import { Table } from './table/table.js';
52
52
  import { Pagination } from './pagination/pagination.js';
53
53
  import { TreeView } from './tree-view/tree-view.js';
54
+ import { Card } from './card/card.js';
55
+ import { Snackbar } from './snackbar/snackbar.js';
54
56
 
55
57
  const distDirectory = `${import.meta.url}/..`;
56
58
  await loadCSS(`${distDirectory}/assets/styles.css`);
@@ -135,6 +137,9 @@ const loaderConfig: LoaderConfig = {
135
137
  'wc-chip': {
136
138
  CustomElementClass: Chip,
137
139
  },
140
+ 'wc-card': {
141
+ CustomElementClass: Card,
142
+ },
138
143
  'wc-tag': {
139
144
  CustomElementClass: Tag,
140
145
  },
@@ -226,12 +231,21 @@ const loaderConfig: LoaderConfig = {
226
231
  'wc-tree-node': {
227
232
  CustomElementClass: TreeView.Node,
228
233
  },
234
+ 'wc-snackbar': {
235
+ CustomElementClass: Snackbar,
236
+ },
229
237
  'wc-chart-doughnut': {
230
238
  importPath: `${distDirectory}/chart-doughnut.js`,
231
239
  },
232
240
  'wc-chart-pie': {
233
241
  importPath: `${distDirectory}/chart-pie.js`,
234
242
  },
243
+ 'wc-chart-bar': {
244
+ importPath: `${distDirectory}/chart-bar.js`,
245
+ },
246
+ 'wc-chart-stacked-bar': {
247
+ importPath: `${distDirectory}/chart-stacked-bar.js`,
248
+ },
235
249
  },
236
250
  };
237
251
 
@@ -0,0 +1,29 @@
1
+ <!doctype html>
2
+ <html lang='en-GB'>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <meta name='viewport' content='width=device-width, initial-scale=1.0, viewport-fit=cover' />
6
+ <link rel='stylesheet' href='/dist/assets/styles/tokens.css' />
7
+ <style>
8
+ body {
9
+ background: #fafafa;
10
+ padding: 2rem;
11
+ display: grid;
12
+ gap: 1rem;
13
+ }
14
+ </style>
15
+ </head>
16
+ <body>
17
+ <wc-snackbar open message="File archived" action-label="Undo"></wc-snackbar>
18
+ <wc-snackbar open multiline show-close-icon>
19
+ Network connection was lost. Please try again when you are back online.
20
+ </wc-snackbar>
21
+
22
+ <script type='module'>
23
+ import { Snackbar, Icon } from '/dist/index.js';
24
+
25
+ window.customElements.define('wc-snackbar', Snackbar);
26
+ window.customElements.define('wc-icon', Icon);
27
+ </script>
28
+ </body>
29
+ </html>
@@ -0,0 +1 @@
1
+ export { Snackbar } from './snackbar.js';
@@ -0,0 +1,73 @@
1
+ @use "../../scss/mixin";
2
+
3
+ @include mixin.base-styles;
4
+
5
+ :host {
6
+ display: inline-flex;
7
+ max-width: 42rem;
8
+ min-width: 21.5rem;
9
+
10
+ --snackbar-container-color: var(--color-inverse-surface);
11
+ --snackbar-label-text-color: var(--color-inverse-on-surface);
12
+ --snackbar-action-text-color: var(--color-inverse-primary);
13
+ --snackbar-close-icon-color: var(--color-inverse-on-surface);
14
+ --snackbar-border-radius: var(--shape-corner-extra-small);
15
+ }
16
+
17
+ .snackbar {
18
+ @include mixin.get-typography(body-medium);
19
+ align-items: center;
20
+ background-color: var(--snackbar-container-color);
21
+ border-radius: var(--snackbar-border-radius);
22
+ color: var(--snackbar-label-text-color);
23
+ display: inline-flex;
24
+ gap: var(--spacing-100);
25
+ min-height: 3rem;
26
+ opacity: 0;
27
+ padding: var(--spacing-100) var(--spacing-200);
28
+ pointer-events: none;
29
+ transform: translateY(0.5rem);
30
+ transition: opacity var(--duration-short2) var(--easing-standard),
31
+ transform var(--duration-short2) var(--easing-standard);
32
+ }
33
+
34
+ .snackbar.open {
35
+ opacity: 1;
36
+ pointer-events: auto;
37
+ transform: translateY(0);
38
+ }
39
+
40
+ .label {
41
+ flex: 1 1 auto;
42
+ color: inherit;
43
+ }
44
+
45
+ .action,
46
+ .close {
47
+ @include mixin.get-typography(label-large);
48
+ align-items: center;
49
+ background: transparent;
50
+ border: none;
51
+ color: var(--snackbar-action-text-color);
52
+ cursor: pointer;
53
+ display: inline-flex;
54
+ justify-content: center;
55
+ margin: 0;
56
+ min-height: 2rem;
57
+ min-width: 2rem;
58
+ padding: 0 var(--spacing-100);
59
+ }
60
+
61
+ .close {
62
+ color: var(--snackbar-close-icon-color);
63
+ padding: 0;
64
+ }
65
+
66
+ .close wc-icon {
67
+ --icon-size: 1.125rem;
68
+ color: inherit;
69
+ }
70
+
71
+ .snackbar.multiline {
72
+ align-items: flex-start;
73
+ }