@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.
- package/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/assets/theme.js +19 -19
- package/dist/assets/tokens.css +1 -1
- package/dist/assets/tokens.css.map +1 -1
- package/dist/card-content.js +8 -7
- package/dist/card-content.js.map +1 -1
- package/dist/card.js +142 -98
- package/dist/card.js.map +1 -1
- package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
- package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
- package/dist/chart-area.js +78 -0
- package/dist/chart-area.js.map +1 -0
- package/dist/chart-bar.js +283 -213
- package/dist/chart-bar.js.map +1 -1
- package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
- package/dist/chart-base-C2qRMF48.js.map +1 -0
- package/dist/chart-doughnut.js +55 -287
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-line.js +626 -0
- package/dist/chart-line.js.map +1 -0
- package/dist/chart-pie.js +637 -195
- package/dist/chart-pie.js.map +1 -1
- package/dist/code-editor.js +704 -131
- package/dist/code-editor.js.map +1 -1
- package/dist/code-group.js +188 -0
- package/dist/code-group.js.map +1 -0
- package/dist/code-highlighter.js +895 -257
- package/dist/code-highlighter.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +1675 -222
- package/dist/custom-elements.json +13351 -3970
- package/dist/image.js +5 -1
- package/dist/image.js.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/loader-full.js +1 -1
- package/dist/loader.js +9 -3
- package/dist/loader.js.map +1 -1
- package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
- package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
- package/dist/path-CJ0Arqcy.js +166 -0
- package/dist/path-CJ0Arqcy.js.map +1 -0
- package/dist/snackbar.js +89 -34
- package/dist/snackbar.js.map +1 -1
- package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
- package/dist/src/__internal/chart/chart-base.d.ts +113 -0
- package/dist/src/__internal/chart/paths.d.ts +5 -0
- package/dist/src/__internal/chart/types.d.ts +42 -0
- package/dist/src/card/card-content.d.ts +2 -3
- package/dist/src/card/card.d.ts +31 -17
- package/dist/src/chart-area/chart-area.d.ts +54 -0
- package/dist/src/chart-area/index.d.ts +1 -0
- package/dist/src/chart-bar/chart-bar.d.ts +44 -33
- package/dist/src/chart-bar/index.d.ts +0 -1
- package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
- package/dist/src/chart-line/chart-line.d.ts +69 -0
- package/dist/src/chart-line/index.d.ts +1 -0
- package/dist/src/chart-pie/chart-pie.d.ts +63 -28
- package/dist/src/code-editor/code-editor.d.ts +52 -13
- package/dist/src/code-editor/editor-theme.d.ts +60 -0
- package/dist/src/code-highlighter/code-group.d.ts +52 -0
- package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
- package/dist/src/code-highlighter/index.d.ts +1 -0
- package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
- package/dist/src/code-highlighter/local.d.ts +4 -1
- package/dist/src/code-highlighter/token-colors.d.ts +8 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/snackbar/snackbar.d.ts +13 -1
- package/dist/src/toolbar/toolbar.d.ts +56 -51
- package/dist/table.js +9 -4
- package/dist/table.js.map +1 -1
- package/dist/test/chart.test.d.ts +1 -0
- package/dist/test/code-highlighter.test.d.ts +1 -0
- package/dist/token-colors-0TFHWbcq.js +81 -0
- package/dist/token-colors-0TFHWbcq.js.map +1 -0
- package/dist/toolbar.js +195 -184
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/readme.md +7 -6
- package/scss/_code-block.scss +139 -0
- package/scss/tokens.css +24 -0
- package/src/__internal/chart/cartesian-chart.ts +404 -0
- package/src/__internal/chart/chart-base.scss +252 -0
- package/src/__internal/chart/chart-base.ts +474 -0
- package/src/__internal/chart/paths.ts +28 -0
- package/src/__internal/chart/types.ts +49 -0
- package/src/card/card-content.ts +12 -9
- package/src/card/card.scss +66 -54
- package/src/card/card.ts +109 -73
- package/src/chart-area/chart-area.ts +82 -0
- package/src/chart-area/index.ts +1 -0
- package/src/chart-bar/chart-bar.ts +336 -250
- package/src/chart-bar/index.ts +0 -1
- package/src/chart-doughnut/chart-doughnut.ts +62 -262
- package/src/chart-doughnut/demo/index.html +14 -22
- package/src/chart-line/chart-line.scss +25 -0
- package/src/chart-line/chart-line.ts +346 -0
- package/src/chart-line/index.ts +1 -0
- package/src/chart-pie/chart-pie.scss +35 -16
- package/src/chart-pie/chart-pie.ts +282 -188
- package/src/chart-pie/demo/index.html +13 -21
- package/src/code-editor/code-editor.scss +132 -36
- package/src/code-editor/code-editor.ts +308 -88
- package/src/code-editor/demo/index.html +39 -12
- package/src/code-editor/editor-theme.ts +213 -0
- package/src/code-highlighter/code-group.scss +34 -0
- package/src/code-highlighter/code-group.ts +173 -0
- package/src/code-highlighter/code-highlighter.scss +226 -111
- package/src/code-highlighter/code-highlighter.ts +554 -199
- package/src/code-highlighter/demo/index.html +68 -4
- package/src/code-highlighter/index.ts +1 -0
- package/src/code-highlighter/line-ranges.ts +81 -0
- package/src/code-highlighter/local.ts +9 -3
- package/src/code-highlighter/token-colors.ts +42 -0
- package/src/index.ts +4 -2
- package/src/loader.ts +8 -2
- package/src/snackbar/demo/index.html +39 -4
- package/src/snackbar/snackbar.scss +27 -10
- package/src/snackbar/snackbar.ts +80 -37
- package/src/table/table.scss +7 -1
- package/src/table/table.ts +4 -3
- package/src/toolbar/toolbar-colors.scss +6 -7
- package/src/toolbar/toolbar.scss +35 -106
- package/src/toolbar/toolbar.ts +180 -80
- package/dist/array-D5vjT2Xm.js +0 -14
- package/dist/array-D5vjT2Xm.js.map +0 -1
- package/dist/chart-bar-D5dGFJfK.js.map +0 -1
- package/dist/chart-stacked-bar.js +0 -403
- package/dist/chart-stacked-bar.js.map +0 -1
- package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
- package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
- package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
- package/dist/pie-Dz0IDiPt.js +0 -537
- package/dist/pie-Dz0IDiPt.js.map +0 -1
- package/dist/pierre-dark-DFWl0m-C.js +0 -4
- package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
- package/dist/pierre-light-BEkAPImt.js +0 -4
- package/dist/pierre-light-BEkAPImt.js.map +0 -1
- package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
- package/dist/src/code-highlighter/constants.d.ts +0 -1
- package/dist/transform-DSwFSqzD.js.map +0 -1
- package/src/chart-bar/chart-bar.scss +0 -58
- package/src/chart-bar/chart-stacked-bar.ts +0 -398
- package/src/chart-doughnut/chart-donut.scss +0 -37
- package/src/code-highlighter/constants.ts +0 -117
- /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
|
@@ -14,17 +14,81 @@
|
|
|
14
14
|
|
|
15
15
|
<style>
|
|
16
16
|
body {
|
|
17
|
-
|
|
17
|
+
display: grid;
|
|
18
|
+
gap: 1.5rem;
|
|
19
|
+
max-width: 48rem;
|
|
20
|
+
margin: 2rem auto;
|
|
21
|
+
padding: 0 1rem;
|
|
22
|
+
background: var(--color-surface);
|
|
23
|
+
color: var(--color-on-surface);
|
|
24
|
+
font-family: var(--font-family-sans, sans-serif);
|
|
18
25
|
}
|
|
19
26
|
</style>
|
|
20
27
|
</head>
|
|
21
28
|
<body>
|
|
22
|
-
<
|
|
29
|
+
<button
|
|
30
|
+
type="button"
|
|
31
|
+
onclick="document.documentElement.dataset.theme = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'"
|
|
32
|
+
>
|
|
33
|
+
Toggle dark theme
|
|
34
|
+
</button>
|
|
35
|
+
|
|
36
|
+
<wc-code-highlighter language="javascript">
|
|
23
37
|
<pre><code>
|
|
24
38
|
const helloWorld = () => alert ('Hello World!');
|
|
25
39
|
export { helloWorld };
|
|
26
|
-
</code></pre>
|
|
27
|
-
</
|
|
40
|
+
</code></pre>
|
|
41
|
+
</wc-code-highlighter>
|
|
42
|
+
|
|
43
|
+
<wc-code-highlighter
|
|
44
|
+
language="javascript"
|
|
45
|
+
label="src/math.js"
|
|
46
|
+
line-numbers
|
|
47
|
+
start-line="41"
|
|
48
|
+
highlight-lines="2"
|
|
49
|
+
wrap-toggle
|
|
50
|
+
format="false"
|
|
51
|
+
>
|
|
52
|
+
<wc-icon slot="icon" name="description"></wc-icon>
|
|
53
|
+
<pre><code>
|
|
54
|
+
export function clamp(value, min, max) {
|
|
55
|
+
return Math.min(Math.max(value, min), max);
|
|
56
|
+
}
|
|
57
|
+
</code></pre>
|
|
58
|
+
</wc-code-highlighter>
|
|
59
|
+
|
|
60
|
+
<wc-code-highlighter
|
|
61
|
+
language="css"
|
|
62
|
+
label="button.scss"
|
|
63
|
+
removed-lines="2"
|
|
64
|
+
added-lines="3"
|
|
65
|
+
format="false"
|
|
66
|
+
>
|
|
67
|
+
<pre><code>
|
|
68
|
+
.button {
|
|
69
|
+
border-radius: 4px;
|
|
70
|
+
border-radius: var(--shape-corner-full);
|
|
71
|
+
}
|
|
72
|
+
</code></pre>
|
|
73
|
+
</wc-code-highlighter>
|
|
74
|
+
|
|
75
|
+
<wc-code-highlighter
|
|
76
|
+
size="sm"
|
|
77
|
+
variant="error"
|
|
78
|
+
language="text"
|
|
79
|
+
label="Build failed"
|
|
80
|
+
>
|
|
81
|
+
<pre><code>
|
|
82
|
+
TypeError: Cannot read properties of undefined (reading 'map')
|
|
83
|
+
</code></pre>
|
|
84
|
+
</wc-code-highlighter>
|
|
85
|
+
|
|
86
|
+
<p>
|
|
87
|
+
Inline:
|
|
88
|
+
<wc-code-highlighter inline language="javascript"
|
|
89
|
+
>button.focus()</wc-code-highlighter
|
|
90
|
+
>
|
|
91
|
+
</p>
|
|
28
92
|
|
|
29
93
|
<script type="module" src="/dist/loader.js"></script>
|
|
30
94
|
</body>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type LineVariant = 'highlighted' | 'added' | 'removed';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses a line range list such as `"1, 3-5"` into 1-based line numbers.
|
|
5
|
+
* Blank or malformed parts are skipped; a reversed range such as `"5-3"` is read as `3-5`.
|
|
6
|
+
*/
|
|
7
|
+
export function parseLineRanges(value: string | null | undefined): Set<number> {
|
|
8
|
+
const lines = new Set<number>();
|
|
9
|
+
if (!value) return lines;
|
|
10
|
+
|
|
11
|
+
for (const part of value.split(',')) {
|
|
12
|
+
const match = part.trim().match(/^(\d+)(?:\s*-\s*(\d+))?$/);
|
|
13
|
+
if (match) {
|
|
14
|
+
const start = Number(match[1]);
|
|
15
|
+
const end = match[2] === undefined ? start : Number(match[2]);
|
|
16
|
+
const from = Math.max(1, Math.min(start, end));
|
|
17
|
+
const to = Math.max(start, end);
|
|
18
|
+
for (let line = from; line <= to; line += 1) lines.add(line);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return lines;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Maps 1-based line numbers to their variant. Where ranges overlap,
|
|
26
|
+
* `removed` wins over `added`, and `added` wins over `highlighted`.
|
|
27
|
+
*/
|
|
28
|
+
export function buildLineVariants(ranges: {
|
|
29
|
+
highlighted?: string | null;
|
|
30
|
+
added?: string | null;
|
|
31
|
+
removed?: string | null;
|
|
32
|
+
}): Map<number, LineVariant> {
|
|
33
|
+
const variants = new Map<number, LineVariant>();
|
|
34
|
+
const order: LineVariant[] = ['highlighted', 'added', 'removed'];
|
|
35
|
+
for (const variant of order) {
|
|
36
|
+
for (const line of parseLineRanges(ranges[variant])) {
|
|
37
|
+
variants.set(line, variant);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return variants;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Removes leading and trailing blank lines and the indentation common to
|
|
45
|
+
* every non-blank line, so indented markup reads as written.
|
|
46
|
+
*/
|
|
47
|
+
export function dedent(source: string): string {
|
|
48
|
+
const lines = source.replace(/\r\n?/g, '\n').split('\n');
|
|
49
|
+
while (lines.length && lines[0].trim() === '') lines.shift();
|
|
50
|
+
while (lines.length && lines[lines.length - 1].trim() === '') lines.pop();
|
|
51
|
+
|
|
52
|
+
let indent = Infinity;
|
|
53
|
+
for (const line of lines) {
|
|
54
|
+
if (line.trim() !== '') {
|
|
55
|
+
const leading = line.match(/^[ \t]*/)?.[0].length ?? 0;
|
|
56
|
+
indent = Math.min(indent, leading);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!Number.isFinite(indent) || indent === 0) return lines.join('\n');
|
|
60
|
+
return lines.map(line => line.slice(indent)).join('\n');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Decodes the entities `innerHTML` produces for text, ending with `&`. */
|
|
64
|
+
export function decodeEntities(source: string): string {
|
|
65
|
+
return source
|
|
66
|
+
.replace(/</g, '<')
|
|
67
|
+
.replace(/>/g, '>')
|
|
68
|
+
.replace(/"/g, '"')
|
|
69
|
+
.replace(/'/g, "'")
|
|
70
|
+
.replace(/ /g, ' ')
|
|
71
|
+
.replace(/&/g, '&');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Splits code into display lines, ignoring one trailing newline. */
|
|
75
|
+
export function splitLines(code: string): string[] {
|
|
76
|
+
const normalized = code.replace(/\r\n?/g, '\n');
|
|
77
|
+
const trimmed = normalized.endsWith('\n')
|
|
78
|
+
? normalized.slice(0, -1)
|
|
79
|
+
: normalized;
|
|
80
|
+
return trimmed.split('\n');
|
|
81
|
+
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export const locale: {
|
|
2
|
-
loading: string;
|
|
3
2
|
copyToClipboard: string;
|
|
4
3
|
copied: string;
|
|
5
4
|
copiedCode: string;
|
|
5
|
+
wrapLines: string;
|
|
6
|
+
unwrapLines: string;
|
|
7
|
+
showMore: string;
|
|
8
|
+
showLess: string;
|
|
6
9
|
} = {
|
|
7
|
-
loading: 'Loading code...',
|
|
8
10
|
copyToClipboard: 'Copy to clipboard',
|
|
9
11
|
copied: 'Copied',
|
|
10
|
-
copiedCode: 'Copied code',
|
|
12
|
+
copiedCode: 'Copied code to clipboard',
|
|
13
|
+
wrapLines: 'Wrap lines',
|
|
14
|
+
unwrapLines: 'Turn off line wrap',
|
|
15
|
+
showMore: 'Show more',
|
|
16
|
+
showLess: 'Show less',
|
|
11
17
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Syntax colors shared by wc-code-highlighter and wc-code-editor. Each is a CSS variable,
|
|
3
|
+
* `--code-highlighter-<name>`, that falls back to a Peacock color role, so light, dark and
|
|
4
|
+
* custom themes all follow the tokens, and one override restyles both components.
|
|
5
|
+
*/
|
|
6
|
+
export const TOKEN_DEFAULTS: Record<string, string> = {
|
|
7
|
+
foreground: 'var(--color-on-surface)',
|
|
8
|
+
background: 'transparent',
|
|
9
|
+
'token-constant': 'var(--color-orange)',
|
|
10
|
+
'token-string': 'var(--color-green)',
|
|
11
|
+
'token-comment': 'var(--color-on-surface-variant)',
|
|
12
|
+
'token-keyword': 'var(--color-purple)',
|
|
13
|
+
'token-parameter': 'var(--color-on-surface)',
|
|
14
|
+
'token-function': 'var(--color-blue)',
|
|
15
|
+
'token-string-expression': 'var(--color-green)',
|
|
16
|
+
'token-punctuation': 'var(--color-on-surface-variant)',
|
|
17
|
+
'token-link': 'var(--color-primary)',
|
|
18
|
+
'token-inserted': 'var(--color-green)',
|
|
19
|
+
'token-deleted': 'var(--color-red)',
|
|
20
|
+
'token-changed': 'var(--color-orange)',
|
|
21
|
+
'ansi-black': 'var(--color-on-surface)',
|
|
22
|
+
'ansi-red': 'var(--color-red)',
|
|
23
|
+
'ansi-green': 'var(--color-green)',
|
|
24
|
+
'ansi-yellow': 'var(--color-yellow)',
|
|
25
|
+
'ansi-blue': 'var(--color-blue)',
|
|
26
|
+
'ansi-magenta': 'var(--color-purple)',
|
|
27
|
+
'ansi-cyan': 'var(--color-tertiary)',
|
|
28
|
+
'ansi-white': 'var(--color-on-surface-variant)',
|
|
29
|
+
'ansi-bright-black': 'var(--color-on-surface-variant)',
|
|
30
|
+
'ansi-bright-red': 'var(--color-red)',
|
|
31
|
+
'ansi-bright-green': 'var(--color-green)',
|
|
32
|
+
'ansi-bright-yellow': 'var(--color-yellow)',
|
|
33
|
+
'ansi-bright-blue': 'var(--color-blue)',
|
|
34
|
+
'ansi-bright-magenta': 'var(--color-purple)',
|
|
35
|
+
'ansi-bright-cyan': 'var(--color-tertiary)',
|
|
36
|
+
'ansi-bright-white': 'var(--color-on-surface)',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** The CSS value for a syntax color: its public variable, falling back to the color role. */
|
|
40
|
+
export function tokenColor(name: string): string {
|
|
41
|
+
return `var(--code-highlighter-${name}, ${TOKEN_DEFAULTS[name]})`;
|
|
42
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -45,7 +45,7 @@ export { List, ListItem } from './list/index.js';
|
|
|
45
45
|
export { Timeline, TimelineItem } from './timeline/index.js';
|
|
46
46
|
export { Item } from './item/index.js';
|
|
47
47
|
|
|
48
|
-
export { CodeHighlighter } from './code-highlighter/index.js';
|
|
48
|
+
export { CodeHighlighter, CodeGroup } from './code-highlighter/index.js';
|
|
49
49
|
export { CodeEditor } from './code-editor/index.js';
|
|
50
50
|
export { HtmlEditor } from './html-editor/index.js';
|
|
51
51
|
export { MarkdownEditor } from './markdown-editor/index.js';
|
|
@@ -57,7 +57,9 @@ export { ColorPicker } from './color-picker/index.js';
|
|
|
57
57
|
export { ColorField } from './color-field/index.js';
|
|
58
58
|
export { ChartDoughnut } from './chart-doughnut/index.js';
|
|
59
59
|
export { ChartPie } from './chart-pie/index.js';
|
|
60
|
-
export { ChartBar
|
|
60
|
+
export { ChartBar } from './chart-bar/index.js';
|
|
61
|
+
export { ChartLine } from './chart-line/index.js';
|
|
62
|
+
export { ChartArea } from './chart-area/index.js';
|
|
61
63
|
export { Table } from './table/index.js';
|
|
62
64
|
export { Pagination } from './pagination/index.js';
|
|
63
65
|
export {
|
package/src/loader.ts
CHANGED
|
@@ -279,6 +279,9 @@ const loaderConfig: LoaderConfig = {
|
|
|
279
279
|
'wc-code-highlighter': {
|
|
280
280
|
importPath: `${distDirectory}/code-highlighter.js`,
|
|
281
281
|
},
|
|
282
|
+
'wc-code-group': {
|
|
283
|
+
importPath: `${distDirectory}/code-group.js`,
|
|
284
|
+
},
|
|
282
285
|
'wc-breadcrumb': {
|
|
283
286
|
CustomElementClass: Breadcrumb,
|
|
284
287
|
},
|
|
@@ -427,8 +430,11 @@ const loaderConfig: LoaderConfig = {
|
|
|
427
430
|
'wc-chart-bar': {
|
|
428
431
|
importPath: `${distDirectory}/chart-bar.js`,
|
|
429
432
|
},
|
|
430
|
-
'wc-chart-
|
|
431
|
-
importPath: `${distDirectory}/chart-
|
|
433
|
+
'wc-chart-line': {
|
|
434
|
+
importPath: `${distDirectory}/chart-line.js`,
|
|
435
|
+
},
|
|
436
|
+
'wc-chart-area': {
|
|
437
|
+
importPath: `${distDirectory}/chart-area.js`,
|
|
432
438
|
},
|
|
433
439
|
'wc-condition-builder': {
|
|
434
440
|
importPath: `${distDirectory}/condition-builder.js`,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset='utf-8'>
|
|
5
5
|
<meta name='viewport' content='width=device-width, initial-scale=1.0, viewport-fit=cover' />
|
|
6
|
-
<link rel='stylesheet' href='/dist/assets/
|
|
6
|
+
<link rel='stylesheet' href='/dist/assets/tokens.css' />
|
|
7
7
|
<style>
|
|
8
8
|
body {
|
|
9
9
|
background: #fafafa;
|
|
@@ -11,19 +11,54 @@
|
|
|
11
11
|
display: grid;
|
|
12
12
|
gap: 1rem;
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
/* A fixed bar with a very high z-index: the open snackbar must still draw above it. */
|
|
16
|
+
.cover {
|
|
17
|
+
position: fixed;
|
|
18
|
+
inset-inline: 0;
|
|
19
|
+
bottom: 0;
|
|
20
|
+
height: 6rem;
|
|
21
|
+
z-index: 2147483647;
|
|
22
|
+
background: #d0e4ff;
|
|
23
|
+
}
|
|
14
24
|
</style>
|
|
15
25
|
</head>
|
|
16
26
|
<body>
|
|
17
|
-
<wc-snackbar
|
|
18
|
-
<wc-snackbar
|
|
27
|
+
<wc-snackbar preview message="File archived" action-label="Undo"></wc-snackbar>
|
|
28
|
+
<wc-snackbar preview multiline show-close-icon>
|
|
19
29
|
Network connection was lost. Please try again when you are back online.
|
|
20
30
|
</wc-snackbar>
|
|
21
31
|
|
|
32
|
+
<div>
|
|
33
|
+
<wc-button id='show-snackbar'>Show snackbar</wc-button>
|
|
34
|
+
<wc-button id='open-modal' variant='outlined'>Open modal</wc-button>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div class='cover'></div>
|
|
38
|
+
|
|
39
|
+
<wc-snackbar id='live' message='Draft saved' action-label='Undo' show-close-icon duration='0'></wc-snackbar>
|
|
40
|
+
|
|
41
|
+
<wc-modal id='modal' heading='Edit profile'>
|
|
42
|
+
<p>Saving from inside the modal shows a snackbar above it.</p>
|
|
43
|
+
<wc-button slot='footer' id='save-in-modal'>Save</wc-button>
|
|
44
|
+
</wc-modal>
|
|
45
|
+
|
|
22
46
|
<script type='module'>
|
|
23
|
-
import { Snackbar, Icon } from '/dist/index.js';
|
|
47
|
+
import { Snackbar, Modal, Button, IconButton, Icon } from '/dist/index.js';
|
|
24
48
|
|
|
25
49
|
window.customElements.define('wc-snackbar', Snackbar);
|
|
50
|
+
window.customElements.define('wc-modal', Modal);
|
|
51
|
+
window.customElements.define('wc-button', Button);
|
|
52
|
+
window.customElements.define('wc-icon-button', IconButton);
|
|
26
53
|
window.customElements.define('wc-icon', Icon);
|
|
54
|
+
|
|
55
|
+
const snackbar = document.getElementById('live');
|
|
56
|
+
const modal = document.getElementById('modal');
|
|
57
|
+
snackbar.duration = 0;
|
|
58
|
+
|
|
59
|
+
document.getElementById('show-snackbar').addEventListener('click', () => snackbar.show());
|
|
60
|
+
document.getElementById('open-modal').addEventListener('click', () => modal.show());
|
|
61
|
+
document.getElementById('save-in-modal').addEventListener('click', () => snackbar.show());
|
|
27
62
|
</script>
|
|
28
63
|
</body>
|
|
29
64
|
</html>
|
|
@@ -27,13 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
:host {
|
|
30
|
-
display:
|
|
31
|
-
inset-block-end: calc(var(--snackbar-offset-bottom, 1rem) + env(safe-area-inset-bottom, 0px));
|
|
32
|
-
inset-inline: var(--snackbar-offset-inline, 1rem);
|
|
33
|
-
justify-content: center;
|
|
34
|
-
pointer-events: none;
|
|
35
|
-
position: fixed;
|
|
36
|
-
z-index: var(--snackbar-z-index, 1000);
|
|
30
|
+
display: contents;
|
|
37
31
|
|
|
38
32
|
--snackbar-container-color: var(--color-inverse-surface);
|
|
39
33
|
--snackbar-label-text-color: var(--color-inverse-on-surface);
|
|
@@ -42,6 +36,26 @@
|
|
|
42
36
|
--snackbar-border-radius: var(--shape-corner-extra-small);
|
|
43
37
|
}
|
|
44
38
|
|
|
39
|
+
// Fixed to the bottom of the viewport. While open it is a manual popover in the top layer,
|
|
40
|
+
// so these rules also undo the browser's default popover styles.
|
|
41
|
+
.layer {
|
|
42
|
+
background: transparent;
|
|
43
|
+
border: 0;
|
|
44
|
+
color: inherit;
|
|
45
|
+
display: flex;
|
|
46
|
+
height: auto;
|
|
47
|
+
inset: auto var(--snackbar-offset-inline, 1rem)
|
|
48
|
+
calc(var(--snackbar-offset-bottom, 1rem) + env(safe-area-inset-bottom, 0px));
|
|
49
|
+
justify-content: center;
|
|
50
|
+
margin: 0;
|
|
51
|
+
overflow: visible;
|
|
52
|
+
padding: 0;
|
|
53
|
+
pointer-events: none;
|
|
54
|
+
position: fixed;
|
|
55
|
+
width: auto;
|
|
56
|
+
z-index: var(--snackbar-z-index, 1000);
|
|
57
|
+
}
|
|
58
|
+
|
|
45
59
|
.snackbar {
|
|
46
60
|
@include mixin.get-typography(body-medium);
|
|
47
61
|
align-items: center;
|
|
@@ -93,9 +107,12 @@
|
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
:host([preview]) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
display: flex;
|
|
111
|
+
|
|
112
|
+
.layer {
|
|
113
|
+
position: relative;
|
|
114
|
+
inset: auto;
|
|
115
|
+
}
|
|
99
116
|
|
|
100
117
|
.snackbar {
|
|
101
118
|
display: inline-flex;
|
package/src/snackbar/snackbar.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement, html, nothing } from 'lit';
|
|
2
|
-
import { property, state } from 'lit/decorators.js';
|
|
2
|
+
import { property, query, state } from 'lit/decorators.js';
|
|
3
3
|
import { classMap } from 'lit/directives/class-map.js';
|
|
4
4
|
import styles from './snackbar.scss';
|
|
5
5
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
@@ -12,6 +12,11 @@ type SnackbarCloseReason = 'timeout' | 'dismiss' | 'action' | 'programmatic';
|
|
|
12
12
|
* @rawTag snackbar
|
|
13
13
|
* @summary Snackbars provide brief messages about app processes at the bottom of the screen.
|
|
14
14
|
*
|
|
15
|
+
* @overview
|
|
16
|
+
* <p>An open snackbar is shown as a manual popover, so it renders in the browser's top layer, above sticky
|
|
17
|
+
* headers, app bars and open modals whatever their <code>z-index</code>. Opening it again while it is
|
|
18
|
+
* visible brings it back in front of anything opened since.</p>
|
|
19
|
+
*
|
|
15
20
|
* @cssprop --snackbar-container-color - Container color for the snackbar.
|
|
16
21
|
* @cssprop --snackbar-label-text-color - Label text color for the snackbar.
|
|
17
22
|
* @cssprop --snackbar-action-text-color - Action text color.
|
|
@@ -19,7 +24,7 @@ type SnackbarCloseReason = 'timeout' | 'dismiss' | 'action' | 'programmatic';
|
|
|
19
24
|
* @cssprop --snackbar-border-radius - Border radius of the snackbar surface.
|
|
20
25
|
* @cssprop --snackbar-offset-inline - Inline offset from viewport edges.
|
|
21
26
|
* @cssprop --snackbar-offset-bottom - Bottom offset from viewport edge.
|
|
22
|
-
* @cssprop --snackbar-z-index - Stacking order for the snackbar.
|
|
27
|
+
* @cssprop --snackbar-z-index - Stacking order for the snackbar in browsers without the Popover API.
|
|
23
28
|
*
|
|
24
29
|
* @example
|
|
25
30
|
* ```html
|
|
@@ -60,6 +65,9 @@ export class Snackbar extends LitElement {
|
|
|
60
65
|
/** True while the exit animation is running before the snackbar fully closes. */
|
|
61
66
|
@state() private dismissing = false;
|
|
62
67
|
|
|
68
|
+
/** The positioned layer that is shown in the top layer as a popover. */
|
|
69
|
+
@query('.layer') private layer?: HTMLElement;
|
|
70
|
+
|
|
63
71
|
// ── Private fields ────────────────────────────────────────────────────────
|
|
64
72
|
|
|
65
73
|
/** Timer handle for the auto-hide timeout. */
|
|
@@ -68,9 +76,7 @@ export class Snackbar extends LitElement {
|
|
|
68
76
|
/** Timer handle for the exit animation duration timeout. */
|
|
69
77
|
private exitTimer: ReturnType<typeof setTimeout> | null = null;
|
|
70
78
|
|
|
71
|
-
private readonly handleGlobalSnackbarOpen = (
|
|
72
|
-
event: Event,
|
|
73
|
-
) => {
|
|
79
|
+
private readonly handleGlobalSnackbarOpen = (event: Event) => {
|
|
74
80
|
const { source } = (event as CustomEvent<{ source?: Snackbar }>).detail;
|
|
75
81
|
if (source && source !== this) {
|
|
76
82
|
this.hide();
|
|
@@ -92,10 +98,15 @@ export class Snackbar extends LitElement {
|
|
|
92
98
|
);
|
|
93
99
|
this.clearExitTimer();
|
|
94
100
|
this.clearTimer();
|
|
101
|
+
this.syncLayer();
|
|
95
102
|
super.disconnectedCallback();
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
protected updated(changedProperties: Map<string, unknown>) {
|
|
106
|
+
if (changedProperties.has('open') || changedProperties.has('preview')) {
|
|
107
|
+
this.syncLayer();
|
|
108
|
+
}
|
|
109
|
+
|
|
99
110
|
if (changedProperties.has('open')) {
|
|
100
111
|
if (this.open) {
|
|
101
112
|
document.dispatchEvent(
|
|
@@ -119,6 +130,8 @@ export class Snackbar extends LitElement {
|
|
|
119
130
|
return;
|
|
120
131
|
}
|
|
121
132
|
|
|
133
|
+
// Already open: move it back to the top of the top layer, above anything opened since.
|
|
134
|
+
this.syncLayer(true);
|
|
122
135
|
this.scheduleAutoHide();
|
|
123
136
|
}
|
|
124
137
|
|
|
@@ -191,6 +204,30 @@ export class Snackbar extends LitElement {
|
|
|
191
204
|
}
|
|
192
205
|
}
|
|
193
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Shows the layer in the top layer while the snackbar is open, and hides it otherwise.
|
|
209
|
+
* With `raise`, an already showing layer is shown again so it moves above newer top-layer elements.
|
|
210
|
+
*/
|
|
211
|
+
private syncLayer(raise = false) {
|
|
212
|
+
const { layer } = this;
|
|
213
|
+
if (
|
|
214
|
+
!layer ||
|
|
215
|
+
typeof layer.showPopover !== 'function' ||
|
|
216
|
+
!layer.hasAttribute('popover')
|
|
217
|
+
) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const shouldShow = this.open && !this.preview && this.isConnected;
|
|
222
|
+
const showing = layer.matches(':popover-open');
|
|
223
|
+
if (showing && (!shouldShow || raise)) {
|
|
224
|
+
layer.hidePopover();
|
|
225
|
+
}
|
|
226
|
+
if (shouldShow && (!showing || raise)) {
|
|
227
|
+
layer.showPopover();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
194
231
|
private scheduleAutoHide() {
|
|
195
232
|
this.clearTimer();
|
|
196
233
|
if (!this.open || this.duration <= 0) {
|
|
@@ -207,39 +244,45 @@ export class Snackbar extends LitElement {
|
|
|
207
244
|
this.actionLabel || this.showCloseIcon ? 'alert' : 'status';
|
|
208
245
|
|
|
209
246
|
return html`
|
|
210
|
-
<div
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
<
|
|
247
|
+
<div class="layer" popover=${this.preview ? nothing : 'manual'}>
|
|
248
|
+
<div
|
|
249
|
+
class=${classMap({
|
|
250
|
+
snackbar: true,
|
|
251
|
+
open: !this.preview && this.open,
|
|
252
|
+
preview: this.preview,
|
|
253
|
+
dismissing: this.dismissing,
|
|
254
|
+
multiline: this.multiline,
|
|
255
|
+
})}
|
|
256
|
+
role=${liveRole}
|
|
257
|
+
aria-live="polite"
|
|
258
|
+
@animationend=${this.handleAnimationEnd}
|
|
259
|
+
>
|
|
260
|
+
<div class="label">
|
|
261
|
+
<slot>${this.message}</slot>
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
${this.actionLabel
|
|
265
|
+
? html`<wc-button
|
|
266
|
+
class="action"
|
|
267
|
+
variant="text"
|
|
268
|
+
size="sm"
|
|
269
|
+
@click=${this.handleActionClick}
|
|
270
|
+
>
|
|
271
|
+
${this.actionLabel}
|
|
272
|
+
</wc-button>`
|
|
273
|
+
: nothing}
|
|
274
|
+
${this.showCloseIcon
|
|
275
|
+
? html`<wc-icon-button
|
|
276
|
+
class="close"
|
|
277
|
+
variant="text"
|
|
278
|
+
size="sm"
|
|
279
|
+
aria-label="Dismiss notification"
|
|
280
|
+
@click=${this.handleCloseClick}
|
|
281
|
+
>
|
|
282
|
+
<wc-icon name="close"></wc-icon>
|
|
283
|
+
</wc-icon-button>`
|
|
284
|
+
: nothing}
|
|
224
285
|
</div>
|
|
225
|
-
|
|
226
|
-
${this.actionLabel
|
|
227
|
-
? html`<wc-button class="action" variant='text' size='sm' @click=${this.handleActionClick}>
|
|
228
|
-
${this.actionLabel}
|
|
229
|
-
</wc-button>`
|
|
230
|
-
: nothing}
|
|
231
|
-
|
|
232
|
-
${this.showCloseIcon
|
|
233
|
-
? html`<wc-icon-button
|
|
234
|
-
class="close"
|
|
235
|
-
variant='text'
|
|
236
|
-
size='sm'
|
|
237
|
-
aria-label="Dismiss notification"
|
|
238
|
-
@click=${this.handleCloseClick}
|
|
239
|
-
>
|
|
240
|
-
<wc-icon name="close"></wc-icon>
|
|
241
|
-
</wc-icon-button>`
|
|
242
|
-
: nothing}
|
|
243
286
|
</div>
|
|
244
287
|
`;
|
|
245
288
|
}
|
package/src/table/table.scss
CHANGED
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
|
|
53
53
|
display: flex;
|
|
54
54
|
width: max-content;
|
|
55
|
-
|
|
55
|
+
// Fill the table when the columns are narrower, so the row dividers reach the edge.
|
|
56
|
+
min-width: max(100%, var(--_row-min-width, 0rem));
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
.columns {
|
|
@@ -268,6 +269,11 @@
|
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
271
|
|
|
272
|
+
// The footer's top border already closes the table, so the last row needs no divider.
|
|
273
|
+
.has-footer .body .row:last-child .cell {
|
|
274
|
+
border-bottom-color: transparent;
|
|
275
|
+
}
|
|
276
|
+
|
|
271
277
|
:host([striped]) .body .row:nth-child(even):not(.selected) {
|
|
272
278
|
--_cell-background: color-mix(
|
|
273
279
|
in srgb,
|
package/src/table/table.ts
CHANGED
|
@@ -712,7 +712,7 @@ export class Table extends LitElement {
|
|
|
712
712
|
class="row"
|
|
713
713
|
role="row"
|
|
714
714
|
aria-rowindex="1"
|
|
715
|
-
style="min-width: ${this.totalColumnsWidth}rem"
|
|
715
|
+
style="--_row-min-width: ${this.totalColumnsWidth}rem"
|
|
716
716
|
>
|
|
717
717
|
${this.renderRowGroups(columns, (entry, index) => {
|
|
718
718
|
const { column } = entry;
|
|
@@ -818,7 +818,7 @@ export class Table extends LitElement {
|
|
|
818
818
|
role="row"
|
|
819
819
|
aria-rowindex=${rowOffset + rowIndex + 2}
|
|
820
820
|
aria-selected=${selectable ? String(selected) : nothing}
|
|
821
|
-
style="min-width: ${this.totalColumnsWidth}rem"
|
|
821
|
+
style="--_row-min-width: ${this.totalColumnsWidth}rem"
|
|
822
822
|
>
|
|
823
823
|
${this.renderRowGroups(columns, (entry, index) => {
|
|
824
824
|
const { column } = entry;
|
|
@@ -879,7 +879,7 @@ export class Table extends LitElement {
|
|
|
879
879
|
<div
|
|
880
880
|
class="row skeleton-row"
|
|
881
881
|
role="row"
|
|
882
|
-
style="min-width: ${this.totalColumnsWidth}rem"
|
|
882
|
+
style="--_row-min-width: ${this.totalColumnsWidth}rem"
|
|
883
883
|
>
|
|
884
884
|
${this.renderRowGroups(
|
|
885
885
|
columns,
|
|
@@ -1001,6 +1001,7 @@ export class Table extends LitElement {
|
|
|
1001
1001
|
'scrolled-from-start': this.scrolledFromStart,
|
|
1002
1002
|
'scrolled-from-end': this.scrolledFromEnd,
|
|
1003
1003
|
'has-selection': this.selectedRowKeys.length > 0,
|
|
1004
|
+
'has-footer': this.paginate,
|
|
1004
1005
|
})}
|
|
1005
1006
|
>
|
|
1006
1007
|
${this.renderBulkBar(pageRows)}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
:host {
|
|
2
|
-
|
|
3
|
-
--toolbar-
|
|
4
|
-
--toolbar-title-color: var(--color-on-surface);
|
|
2
|
+
--toolbar-container-color: var(--color-surface-container-high);
|
|
3
|
+
--toolbar-content-color: var(--color-on-surface);
|
|
5
4
|
--toolbar-icon-color: var(--color-on-surface-variant);
|
|
6
5
|
|
|
7
6
|
/* Internal aliases used by styles */
|
|
8
7
|
--_toolbar-container-color: var(--toolbar-container-color);
|
|
9
|
-
--_toolbar-
|
|
8
|
+
--_toolbar-content-color: var(--toolbar-content-color);
|
|
10
9
|
--_toolbar-icon-color: var(--toolbar-icon-color);
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
/*
|
|
14
|
-
:host([variant='
|
|
15
|
-
--toolbar-container-color:
|
|
12
|
+
/* The flat toolbar takes on the surface it sits on. */
|
|
13
|
+
:host([variant='flat']) {
|
|
14
|
+
--toolbar-container-color: transparent;
|
|
16
15
|
}
|