@redvars/peacock 3.15.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 (157) 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 +2278 -677
  31. package/dist/custom-elements.json +13962 -3690
  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/pagination.js +408 -110
  42. package/dist/pagination.js.map +1 -1
  43. package/dist/path-CJ0Arqcy.js +166 -0
  44. package/dist/path-CJ0Arqcy.js.map +1 -0
  45. package/dist/snackbar.js +89 -34
  46. package/dist/snackbar.js.map +1 -1
  47. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  48. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  49. package/dist/src/__internal/chart/paths.d.ts +5 -0
  50. package/dist/src/__internal/chart/types.d.ts +42 -0
  51. package/dist/src/card/card-content.d.ts +2 -3
  52. package/dist/src/card/card.d.ts +31 -17
  53. package/dist/src/chart-area/chart-area.d.ts +54 -0
  54. package/dist/src/chart-area/index.d.ts +1 -0
  55. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  56. package/dist/src/chart-bar/index.d.ts +0 -1
  57. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  58. package/dist/src/chart-line/chart-line.d.ts +69 -0
  59. package/dist/src/chart-line/index.d.ts +1 -0
  60. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  61. package/dist/src/code-editor/code-editor.d.ts +52 -13
  62. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  63. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  64. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  65. package/dist/src/code-highlighter/index.d.ts +1 -0
  66. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  67. package/dist/src/code-highlighter/local.d.ts +4 -1
  68. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  69. package/dist/src/index.d.ts +4 -2
  70. package/dist/src/pagination/page-items.d.ts +14 -0
  71. package/dist/src/pagination/pagination.d.ts +46 -7
  72. package/dist/src/snackbar/snackbar.d.ts +13 -1
  73. package/dist/src/table/table.d.ts +125 -27
  74. package/dist/src/toolbar/toolbar.d.ts +56 -51
  75. package/dist/table.js +1007 -338
  76. package/dist/table.js.map +1 -1
  77. package/dist/test/chart.test.d.ts +1 -0
  78. package/dist/test/code-highlighter.test.d.ts +1 -0
  79. package/dist/test/pagination.test.d.ts +1 -0
  80. package/dist/test/table.test.d.ts +1 -0
  81. package/dist/token-colors-0TFHWbcq.js +81 -0
  82. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  83. package/dist/toolbar.js +195 -184
  84. package/dist/toolbar.js.map +1 -1
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +1 -2
  87. package/readme.md +7 -6
  88. package/scss/_code-block.scss +139 -0
  89. package/scss/tokens.css +24 -0
  90. package/src/__internal/chart/cartesian-chart.ts +404 -0
  91. package/src/__internal/chart/chart-base.scss +252 -0
  92. package/src/__internal/chart/chart-base.ts +474 -0
  93. package/src/__internal/chart/paths.ts +28 -0
  94. package/src/__internal/chart/types.ts +49 -0
  95. package/src/card/card-content.ts +12 -9
  96. package/src/card/card.scss +66 -54
  97. package/src/card/card.ts +109 -73
  98. package/src/chart-area/chart-area.ts +82 -0
  99. package/src/chart-area/index.ts +1 -0
  100. package/src/chart-bar/chart-bar.ts +336 -250
  101. package/src/chart-bar/index.ts +0 -1
  102. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  103. package/src/chart-doughnut/demo/index.html +14 -22
  104. package/src/chart-line/chart-line.scss +25 -0
  105. package/src/chart-line/chart-line.ts +346 -0
  106. package/src/chart-line/index.ts +1 -0
  107. package/src/chart-pie/chart-pie.scss +35 -16
  108. package/src/chart-pie/chart-pie.ts +282 -188
  109. package/src/chart-pie/demo/index.html +13 -21
  110. package/src/code-editor/code-editor.scss +132 -36
  111. package/src/code-editor/code-editor.ts +308 -88
  112. package/src/code-editor/demo/index.html +39 -12
  113. package/src/code-editor/editor-theme.ts +213 -0
  114. package/src/code-highlighter/code-group.scss +34 -0
  115. package/src/code-highlighter/code-group.ts +173 -0
  116. package/src/code-highlighter/code-highlighter.scss +226 -111
  117. package/src/code-highlighter/code-highlighter.ts +554 -199
  118. package/src/code-highlighter/demo/index.html +68 -4
  119. package/src/code-highlighter/index.ts +1 -0
  120. package/src/code-highlighter/line-ranges.ts +81 -0
  121. package/src/code-highlighter/local.ts +9 -3
  122. package/src/code-highlighter/token-colors.ts +42 -0
  123. package/src/index.ts +4 -2
  124. package/src/loader.ts +8 -2
  125. package/src/pagination/page-items.ts +50 -0
  126. package/src/pagination/pagination.scss +159 -44
  127. package/src/pagination/pagination.ts +275 -74
  128. package/src/snackbar/demo/index.html +39 -4
  129. package/src/snackbar/snackbar.scss +27 -10
  130. package/src/snackbar/snackbar.ts +80 -37
  131. package/src/table/table.scss +337 -109
  132. package/src/table/table.ts +812 -272
  133. package/src/toolbar/toolbar-colors.scss +6 -7
  134. package/src/toolbar/toolbar.scss +35 -106
  135. package/src/toolbar/toolbar.ts +180 -80
  136. package/dist/array-D5vjT2Xm.js +0 -14
  137. package/dist/array-D5vjT2Xm.js.map +0 -1
  138. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  139. package/dist/chart-stacked-bar.js +0 -403
  140. package/dist/chart-stacked-bar.js.map +0 -1
  141. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  142. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  143. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  144. package/dist/pie-Dz0IDiPt.js +0 -537
  145. package/dist/pie-Dz0IDiPt.js.map +0 -1
  146. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  147. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  148. package/dist/pierre-light-BEkAPImt.js +0 -4
  149. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  150. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  151. package/dist/src/code-highlighter/constants.d.ts +0 -1
  152. package/dist/transform-DSwFSqzD.js.map +0 -1
  153. package/src/chart-bar/chart-bar.scss +0 -58
  154. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  155. package/src/chart-doughnut/chart-donut.scss +0 -37
  156. package/src/code-highlighter/constants.ts +0 -117
  157. /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
@@ -1,16 +1,15 @@
1
1
  :host {
2
- /* Docked toolbar */
3
- --toolbar-container-color: var(--color-surface-container);
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-title-color: var(--toolbar-title-color);
8
+ --_toolbar-content-color: var(--toolbar-content-color);
10
9
  --_toolbar-icon-color: var(--toolbar-icon-color);
11
10
  }
12
11
 
13
- /* Floating variant uses surface-container-high for a visible pill */
14
- :host([variant='floating']) {
15
- --toolbar-container-color: var(--color-surface-container-high);
12
+ /* The flat toolbar takes on the surface it sits on. */
13
+ :host([variant='flat']) {
14
+ --toolbar-container-color: transparent;
16
15
  }
@@ -3,13 +3,15 @@
3
3
  @include mixin.base-styles;
4
4
 
5
5
  :host {
6
- display: block;
6
+ display: inline-block;
7
+ vertical-align: middle;
7
8
  --toolbar-container-shape: var(--shape-corner-full);
8
- --toolbar-docked-container-shape: var(--shape-corner-extra-large) var(--shape-corner-extra-large) var(--shape-corner-none) var(--shape-corner-none);
9
- --toolbar-height: 5rem; /* 80dp - small/default docked */
10
- --toolbar-padding-inline: 0.75rem;
11
- --toolbar-gap: 0.5rem;
12
- --toolbar-shadow: none;
9
+ --toolbar-padding: 0.5rem;
10
+ --toolbar-gap: 0.25rem;
11
+ }
12
+
13
+ :host([orientation='vertical']) {
14
+ vertical-align: top;
13
15
  }
14
16
 
15
17
  /* ---- Shared toolbar base ---- */
@@ -17,15 +19,9 @@
17
19
  .toolbar {
18
20
  position: relative;
19
21
  display: flex;
20
- align-items: center;
21
- gap: var(--toolbar-gap);
22
- padding-inline: var(--toolbar-padding-inline);
23
- min-height: var(--toolbar-height);
24
- width: 100%;
25
22
  box-sizing: border-box;
26
- color: var(--_toolbar-title-color);
23
+ color: var(--_toolbar-content-color);
27
24
  --icon-color: var(--_toolbar-icon-color);
28
- box-shadow: var(--toolbar-shadow);
29
25
  }
30
26
 
31
27
  .toolbar-content {
@@ -33,6 +29,7 @@
33
29
  z-index: 1;
34
30
  display: flex;
35
31
  align-items: center;
32
+ gap: var(--toolbar-gap);
36
33
  min-width: 0;
37
34
  }
38
35
 
@@ -44,70 +41,36 @@
44
41
  z-index: 0;
45
42
  }
46
43
 
47
- /* ---- Docked variant ---- */
48
-
49
- .toolbar.variant-docked {
50
- width: 100%;
51
- padding-inline: var(--toolbar-padding-inline);
52
- padding-block-start: 0.5rem;
53
- padding-block-end: calc(0.5rem + env(safe-area-inset-bottom, 0px));
54
-
55
- .background {
56
- border-radius: var(--toolbar-docked-container-shape);
57
- }
58
-
59
- .toolbar-content {
60
- width: 100%;
61
- justify-content: space-between;
62
- gap: var(--toolbar-gap);
63
- overflow-x: auto;
64
- overflow-y: hidden;
65
- scrollbar-width: none;
66
-
67
- &::-webkit-scrollbar {
68
- display: none;
69
- }
70
- }
71
-
72
- ::slotted(*) {
73
- position: relative;
74
- z-index: 1;
75
- flex-shrink: 0;
76
- }
44
+ ::slotted(*) {
45
+ flex-shrink: 0;
46
+ }
77
47
 
78
- ::slotted(wc-icon-button) {
79
- --button-container-shape: var(--shape-corner-full);
80
- --button-container-shape-variant: round;
81
- }
48
+ ::slotted(wc-icon-button) {
49
+ --button-container-shape: var(--shape-corner-full);
50
+ --button-container-shape-variant: round;
51
+ }
82
52
 
83
- /* Size variants */
84
- &.size-sm {
85
- --toolbar-height: 5rem;
86
- }
53
+ /* ---- Orientation ---- */
87
54
 
88
- &.size-md {
89
- --toolbar-height: 6rem;
90
- }
55
+ .orientation-horizontal .toolbar-content {
56
+ flex-direction: row;
57
+ }
91
58
 
92
- &.size-lg {
93
- --toolbar-height: 7rem;
94
- }
59
+ .orientation-vertical .toolbar-content {
60
+ flex-direction: column;
61
+ }
95
62
 
96
- &.elevated {
97
- --toolbar-shadow: var(--elevation-level3);
98
- }
63
+ /* Dividers separate groups of actions: a short line across the toolbar's direction. */
64
+ ::slotted(wc-divider) {
65
+ align-self: stretch;
66
+ --divider-spacing: 0.25rem;
99
67
  }
100
68
 
101
69
  /* ---- Floating variant ---- */
102
70
 
103
71
  .toolbar.variant-floating {
104
- --toolbar-container-shape: var(--shape-corner-full);
105
-
72
+ padding: var(--toolbar-padding);
106
73
  border-radius: var(--toolbar-container-shape);
107
- width: auto;
108
- display: inline-flex;
109
- padding: 0.75rem;
110
- gap: 0.5rem;
111
74
 
112
75
  .elevation {
113
76
  --elevation-level: 3;
@@ -119,47 +82,13 @@
119
82
  border-radius: var(--toolbar-container-shape);
120
83
  }
121
84
 
122
- .toolbar-content {
123
- width: auto;
124
- gap: 0.5rem;
125
- }
126
-
127
- ::slotted(*) {
128
- position: relative;
129
- z-index: 1;
85
+ &.elevated .elevation {
86
+ --elevation-level: 4;
130
87
  }
88
+ }
131
89
 
132
- ::slotted(wc-icon-button) {
133
- --button-container-shape: var(--shape-corner-full);
134
- --button-container-shape-variant: round;
135
- }
136
-
137
- &.orientation-horizontal {
138
- min-height: auto;
139
- padding-block: 0.5rem;
140
- padding-inline: 0.75rem;
141
-
142
- .toolbar-content {
143
- flex-direction: row;
144
- align-items: center;
145
- }
146
- }
147
-
148
- &.orientation-vertical {
149
- min-height: auto;
150
- width: auto;
151
- padding-block: 0.75rem;
152
- padding-inline: 0.5rem;
153
-
154
- .toolbar-content {
155
- flex-direction: column;
156
- align-items: center;
157
- }
158
- }
90
+ /* ---- Flat variant ---- */
159
91
 
160
- &.elevated {
161
- .elevation {
162
- --elevation-level: 4;
163
- }
164
- }
92
+ .toolbar.variant-flat {
93
+ padding: 0;
165
94
  }
@@ -1,142 +1,242 @@
1
- import { LitElement, html } from 'lit';
1
+ import { LitElement, html, nothing } from 'lit';
2
2
  import { property } from 'lit/decorators.js';
3
3
  import { classMap } from 'lit/directives/class-map.js';
4
4
  import IndividualComponent from '@/IndividualComponent.js';
5
- import {
6
- type LegacySize,
7
- normalizeSize,
8
- type Size,
9
- } from '@/__internal/utils/size.js';
10
5
  import styles from './toolbar.scss';
11
6
  import colorStyles from './toolbar-colors.scss';
12
7
 
8
+ /** Slotted elements that separate groups and never take focus. */
9
+ const SEPARATOR_SELECTOR = 'wc-divider, hr, [role="separator"]';
10
+
13
11
  /**
14
12
  * @label Toolbar
15
13
  * @tag wc-toolbar
16
14
  * @rawTag toolbar
17
15
  *
18
- * @summary A toolbar / app bar for navigation and actions.
16
+ * @summary A group of related actions, such as editor formatting controls.
19
17
  * @overview
20
- * <p>The toolbar component implements the app bar pattern. It supports a
21
- * docked (attached) variant for bottom-panel navigation and a floating (detached pill-shaped)
22
- * variant. The floating variant supports both horizontal and vertical orientations.</p>
18
+ * <p>The toolbar groups related actions into one control. The <code>floating</code> variant
19
+ * (default) is an elevated pill that sits over content, such as a canvas or a selection. The
20
+ * <code>flat</code> variant has no container of its own, for embedding in existing chrome like a
21
+ * card or editor header. Both variants lay their actions out horizontally or vertically.</p>
22
+ *
23
+ * <p>Render actions directly as children. Use a <code>wc-divider</code> to separate groups of
24
+ * actions; in a horizontal toolbar give it the <code>vertical</code> attribute.</p>
23
25
  *
24
- * <p>Render toolbar actions directly as children of the component. The docked variant is
25
- * optimized for a horizontal action row, while the floating variant supports both horizontal
26
- * and vertical layouts.</p>
26
+ * <p>The toolbar follows the WAI-ARIA toolbar pattern: it is a single tab stop, and the arrow
27
+ * keys along its orientation move focus between actions (Home and End jump to the first and last).
28
+ * Disabled actions and dividers are skipped. Give the toolbar an <code>aria-label</code>.</p>
27
29
  *
28
30
  * @cssprop --toolbar-container-color - Background color of the toolbar.
29
- * @cssprop --toolbar-container-shape - Border radius of the toolbar. Relevant for the floating variant.
30
- * @cssprop --toolbar-height - Height of the toolbar (docked horizontal / floating horizontal).
31
- * @cssprop --toolbar-padding-inline - Inline padding of the toolbar.
32
- * @cssprop --toolbar-gap - Gap between toolbar sections.
33
- * @cssprop --toolbar-icon-color - Color of icon slots.
34
- * @cssprop --toolbar-title-color - Color of the title (default slot) text.
35
- * @cssprop --toolbar-shadow - Box-shadow of the toolbar.
31
+ * @cssprop --toolbar-container-shape - Border radius of the floating toolbar.
32
+ * @cssprop --toolbar-padding - Padding of the floating toolbar.
33
+ * @cssprop --toolbar-gap - Gap between toolbar actions.
34
+ * @cssprop --toolbar-icon-color - Color of icons inside the toolbar.
35
+ * @cssprop --toolbar-content-color - Color of text inside the toolbar.
36
36
  *
37
37
  * @example
38
38
  * ```html
39
- * <!-- Docked toolbar -->
40
- * <wc-toolbar>
41
- * <wc-icon-button variant="text" color="surface"><wc-icon name="home"></wc-icon></wc-icon-button>
42
- * <wc-icon-button variant="tonal"><wc-icon name="search"></wc-icon></wc-icon-button>
43
- * <wc-icon-button variant="text" color="surface"><wc-icon name="favorite"></wc-icon></wc-icon-button>
44
- * <wc-icon-button variant="text" color="surface"><wc-icon name="account_circle"></wc-icon></wc-icon-button>
39
+ * <!-- Floating toolbar -->
40
+ * <wc-toolbar aria-label="Formatting">
41
+ * <wc-icon-button variant="text" color="surface" aria-label="Undo"><wc-icon name="undo"></wc-icon></wc-icon-button>
42
+ * <wc-icon-button variant="text" color="surface" aria-label="Redo"><wc-icon name="redo"></wc-icon></wc-icon-button>
43
+ * <wc-divider vertical></wc-divider>
44
+ * <wc-icon-button variant="tonal" aria-label="Bold"><wc-icon name="format_bold"></wc-icon></wc-icon-button>
45
+ * <wc-icon-button variant="text" color="surface" aria-label="Italic"><wc-icon name="format_italic"></wc-icon></wc-icon-button>
45
46
  * </wc-toolbar>
46
47
  * ```
47
48
  *
48
49
  * @example
49
50
  * ```html
50
- * <!-- Floating horizontal toolbar -->
51
- * <wc-toolbar variant="floating" orientation="horizontal">
52
- * <wc-icon-button variant="tonal"><wc-icon name="home"></wc-icon></wc-icon-button>
53
- * <wc-icon-button variant="text"><wc-icon name="search"></wc-icon></wc-icon-button>
54
- * <wc-icon-button variant="text"><wc-icon name="favorite"></wc-icon></wc-icon-button>
51
+ * <!-- Vertical floating toolbar -->
52
+ * <wc-toolbar orientation="vertical" aria-label="Tools">
53
+ * <wc-icon-button variant="tonal" aria-label="Select"><wc-icon name="arrow_selector_tool"></wc-icon></wc-icon-button>
54
+ * <wc-icon-button variant="text" color="surface" aria-label="Draw"><wc-icon name="draw"></wc-icon></wc-icon-button>
55
+ * <wc-icon-button variant="text" color="surface" aria-label="Text"><wc-icon name="text_fields"></wc-icon></wc-icon-button>
55
56
  * </wc-toolbar>
56
57
  * ```
57
58
  *
58
59
  * @example
59
60
  * ```html
60
- * <!-- Floating vertical toolbar -->
61
- * <wc-toolbar variant="floating" orientation="vertical">
62
- * <wc-icon-button variant="tonal"><wc-icon name="home"></wc-icon></wc-icon-button>
63
- * <wc-icon-button variant="text"><wc-icon name="search"></wc-icon></wc-icon-button>
64
- * <wc-icon-button variant="text"><wc-icon name="favorite"></wc-icon></wc-icon-button>
61
+ * <!-- Flat toolbar inside existing chrome -->
62
+ * <wc-toolbar variant="flat" aria-label="Row actions">
63
+ * <wc-icon-button variant="text" color="surface" aria-label="Edit"><wc-icon name="edit"></wc-icon></wc-icon-button>
64
+ * <wc-icon-button variant="text" color="surface" aria-label="Delete"><wc-icon name="delete"></wc-icon></wc-icon-button>
65
65
  * </wc-toolbar>
66
66
  * ```
67
- * @tags display navigation
67
+ * @tags display
68
68
  */
69
69
  @IndividualComponent
70
70
  export class Toolbar extends LitElement {
71
+ // ── Static
71
72
  static styles = [styles, colorStyles];
72
73
 
73
- /**
74
- * Visual and layout variant of the toolbar.
75
- * - `"docked"`: A full-width bar attached to the edge of the screen (default).
76
- * - `"floating"`: A detached pill-shaped toolbar that floats over content.
77
- */
78
- @property({ type: String, reflect: true })
79
- variant: 'docked' | 'floating' = 'docked';
74
+ // ── Properties
80
75
 
81
76
  /**
82
- * Orientation of the toolbar content.
83
- * - `"horizontal"`: Items are laid out left to right (default).
84
- * - `"vertical"`: Items are stacked top to bottom. Primarily useful for the floating variant.
77
+ * Visual variant of the toolbar.
78
+ * - `"floating"`: An elevated pill that floats over content (default).
79
+ * - `"flat"`: No container, fill or elevation; for embedding in existing chrome.
85
80
  */
86
81
  @property({ type: String, reflect: true })
87
- orientation: 'horizontal' | 'vertical' = 'horizontal';
82
+ variant: 'floating' | 'flat' = 'floating';
88
83
 
89
84
  /**
90
- * Size of the docked toolbar.
91
- * - `"sm"`: 80dp height (default).
92
- * - `"md"`: 96dp height.
93
- * - `"lg"`: 112dp height.
94
- *
95
- * The long names `"small"`, `"medium"` and `"large"` still work but are deprecated.
85
+ * Orientation of the toolbar. It sets the layout direction and the arrow keys that move focus
86
+ * (Left/Right for horizontal, Up/Down for vertical).
96
87
  */
97
88
  @property({ type: String, reflect: true })
98
- size: Size | LegacySize = 'sm';
89
+ orientation: 'horizontal' | 'vertical' = 'horizontal';
99
90
 
100
91
  /**
101
- * Whether the toolbar is visually elevated (adds a shadow).
92
+ * Raises the floating toolbar to a higher elevation. Has no effect on the flat variant.
102
93
  */
103
94
  @property({ type: Boolean, reflect: true })
104
95
  elevated: boolean = false;
105
96
 
106
- override render() {
107
- const cssClasses = {
108
- toolbar: true,
109
- [`variant-${this.variant}`]: true,
110
- [`orientation-${this.orientation}`]: true,
111
- [`size-${normalizeSize(this.size, 'sm')}`]: true,
112
- elevated: this.elevated,
113
- };
97
+ // ── Private fields
114
98
 
115
- if (this.variant === 'floating') {
116
- return Toolbar.__renderFloating(cssClasses);
99
+ /** The item that holds the toolbar's single tab stop. */
100
+ private __activeItem: HTMLElement | null = null;
101
+
102
+ // ── Lifecycle
103
+
104
+ override connectedCallback() {
105
+ super.connectedCallback();
106
+ // The role lives on the host so the host's aria-label names the toolbar.
107
+ this.setAttribute('role', 'toolbar');
108
+ }
109
+
110
+ override firstUpdated() {
111
+ this.__syncTabStops();
112
+ }
113
+
114
+ override updated(changed: Map<string, unknown>) {
115
+ if (changed.has('orientation')) {
116
+ this.setAttribute('aria-orientation', this.orientation);
117
117
  }
118
+ }
118
119
 
119
- return Toolbar.__renderDocked(cssClasses);
120
+ // ── Private methods
121
+
122
+ /** Actions that can take focus, in slot order. */
123
+ private __getItems(): HTMLElement[] {
124
+ const slot = this.shadowRoot?.querySelector('slot');
125
+ if (!slot) return [];
126
+ return slot
127
+ .assignedElements({ flatten: true })
128
+ .filter(
129
+ (el): el is HTMLElement =>
130
+ el instanceof HTMLElement &&
131
+ !el.matches(SEPARATOR_SELECTOR) &&
132
+ !el.hasAttribute('disabled') &&
133
+ el.getAttribute('aria-disabled') !== 'true' &&
134
+ !el.hidden,
135
+ );
120
136
  }
121
137
 
122
- private static __renderDocked(cssClasses: Record<string, boolean>) {
123
- return html`
124
- <div class=${classMap(cssClasses)} role="toolbar">
125
- <div class="background"></div>
126
- <div class="toolbar-content">
127
- <slot></slot>
128
- </div>
129
- </div>
130
- `;
138
+ /** Gives the active item `tabindex="0"` and every other item `tabindex="-1"`. */
139
+ private __syncTabStops() {
140
+ const items = this.__getItems();
141
+ if (!this.__activeItem || !items.includes(this.__activeItem)) {
142
+ this.__activeItem = items[0] ?? null;
143
+ }
144
+ for (const item of items) {
145
+ item.tabIndex = item === this.__activeItem ? 0 : -1;
146
+ }
147
+ }
148
+
149
+ /** Makes `item` the tab stop and focuses it. */
150
+ private __focusItem(item: HTMLElement) {
151
+ this.__activeItem = item;
152
+ this.__syncTabStops();
153
+ item.focus();
154
+ }
155
+
156
+ /** Finds the toolbar item an event came from. */
157
+ private __itemFromEvent(event: Event, items: HTMLElement[]) {
158
+ return (
159
+ event
160
+ .composedPath()
161
+ .find((node): node is HTMLElement =>
162
+ items.includes(node as HTMLElement),
163
+ ) ?? null
164
+ );
131
165
  }
132
166
 
133
- private static __renderFloating(cssClasses: Record<string, boolean>) {
167
+ private __handleSlotChange = () => {
168
+ this.__syncTabStops();
169
+ };
170
+
171
+ private __handleFocusIn = (event: FocusEvent) => {
172
+ const item = this.__itemFromEvent(event, this.__getItems());
173
+ if (item && item !== this.__activeItem) {
174
+ this.__activeItem = item;
175
+ this.__syncTabStops();
176
+ }
177
+ };
178
+
179
+ private __handleKeyDown = (event: KeyboardEvent) => {
180
+ const items = this.__getItems();
181
+ if (items.length === 0) return;
182
+
183
+ const current = this.__itemFromEvent(event, items);
184
+ if (!current) return;
185
+
186
+ const index = items.indexOf(current);
187
+ let nextKey = 'ArrowDown';
188
+ let prevKey = 'ArrowUp';
189
+ if (this.orientation === 'horizontal') {
190
+ const rtl = getComputedStyle(this).direction === 'rtl';
191
+ nextKey = rtl ? 'ArrowLeft' : 'ArrowRight';
192
+ prevKey = rtl ? 'ArrowRight' : 'ArrowLeft';
193
+ }
194
+
195
+ let target: HTMLElement | undefined;
196
+ switch (event.key) {
197
+ case nextKey:
198
+ target = items[(index + 1) % items.length];
199
+ break;
200
+ case prevKey:
201
+ target = items[(index - 1 + items.length) % items.length];
202
+ break;
203
+ case 'Home':
204
+ [target] = items;
205
+ break;
206
+ case 'End':
207
+ target = items[items.length - 1];
208
+ break;
209
+ default:
210
+ return;
211
+ }
212
+
213
+ event.preventDefault();
214
+ if (target) this.__focusItem(target);
215
+ };
216
+
217
+ // ── Render
218
+
219
+ override render() {
220
+ const floating = this.variant === 'floating';
221
+ const cssClasses = {
222
+ toolbar: true,
223
+ [`variant-${this.variant}`]: true,
224
+ [`orientation-${this.orientation}`]: true,
225
+ elevated: floating && this.elevated,
226
+ };
227
+
134
228
  return html`
135
- <div class=${classMap(cssClasses)} role="toolbar">
136
- <wc-elevation class="elevation"></wc-elevation>
229
+ <div
230
+ class=${classMap(cssClasses)}
231
+ @keydown=${this.__handleKeyDown}
232
+ @focusin=${this.__handleFocusIn}
233
+ >
234
+ ${floating
235
+ ? html`<wc-elevation class="elevation"></wc-elevation>`
236
+ : nothing}
137
237
  <div class="background"></div>
138
238
  <div class="toolbar-content">
139
- <slot></slot>
239
+ <slot @slotchange=${this.__handleSlotChange}></slot>
140
240
  </div>
141
241
  </div>
142
242
  `;
@@ -1,14 +0,0 @@
1
- function constant(x) {
2
- return function constant() {
3
- return x;
4
- };
5
- }
6
-
7
- function array(x) {
8
- return typeof x === "object" && "length" in x
9
- ? x // Array, TypedArray, NodeList, array-like
10
- : Array.from(x); // Map, Set, iterable, string, or anything else
11
- }
12
-
13
- export { array as a, constant as c };
14
- //# sourceMappingURL=array-D5vjT2Xm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array-D5vjT2Xm.js","sources":["../node_modules/d3-shape/src/constant.js","../node_modules/d3-shape/src/array.js"],"sourcesContent":["export default function(x) {\n return function constant() {\n return x;\n };\n}\n","export var slice = Array.prototype.slice;\n\nexport default function(x) {\n return typeof x === \"object\" && \"length\" in x\n ? x // Array, TypedArray, NodeList, array-like\n : Array.from(x); // Map, Set, iterable, string, or anything else\n}\n"],"names":[],"mappings":"AAAe,iBAAQ,CAAC,CAAC,EAAE;AAC3B,EAAE,OAAO,SAAS,QAAQ,GAAG;AAC7B,IAAI,OAAO,CAAC;AACZ,EAAE,CAAC;AACH;;ACFe,cAAQ,CAAC,CAAC,EAAE;AAC3B,EAAE,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,QAAQ,IAAI;AAC9C,MAAM,CAAC;AACP,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB;;;;","x_google_ignoreList":[0,1]}