@m3e/split-button 1.0.0-rc.1
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/LICENSE +22 -0
- package/README.md +159 -0
- package/cem.config.mjs +16 -0
- package/demo/index.html +179 -0
- package/dist/css-custom-data.json +207 -0
- package/dist/custom-elements.json +447 -0
- package/dist/html-custom-data.json +23 -0
- package/dist/index.js +562 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +292 -0
- package/dist/index.min.js.map +1 -0
- package/dist/src/SplitButtonElement.d.ts +107 -0
- package/dist/src/SplitButtonElement.d.ts.map +1 -0
- package/dist/src/SplitButtonVariant.d.ts +3 -0
- package/dist/src/SplitButtonVariant.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +51 -0
- package/rollup.config.js +32 -0
- package/src/SplitButtonElement.ts +488 -0
- package/src/SplitButtonVariant.ts +2 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
|
2
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
3
|
+
|
|
4
|
+
import { DesignToken, HoverController, PressedController, Role } from "@m3e/core";
|
|
5
|
+
import { M3eButtonElement, ButtonSize } from "@m3e/button";
|
|
6
|
+
import { M3eIconButtonElement } from "@m3e/icon-button";
|
|
7
|
+
|
|
8
|
+
import { SplitButtonVariant } from "./SplitButtonVariant";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @summary
|
|
12
|
+
* A button used to show an action with a menu of related actions.
|
|
13
|
+
*
|
|
14
|
+
* @description
|
|
15
|
+
* The `m3e-split-button` component presents a primary action alongside a menu of related actions,
|
|
16
|
+
* uniting two buttons in a single expressive surface. Designed for Material 3, it supports `elevated`,
|
|
17
|
+
* `filled`, `tonal`, and `outlined` variants, and adapts to all button sizes. The leading button triggers
|
|
18
|
+
* the main action, while the trailing icon button reveals additional options, enabling efficient workflows
|
|
19
|
+
* and clear visual hierarchy. The split button ensures accessible, adaptive, and visually harmonious
|
|
20
|
+
* interactions, reflecting Material 3’s principles of clarity, flexibility, and expressive design.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* The following example illustrates use of the `m3e-split-button` to combine the `m3e-button`,
|
|
24
|
+
* `m3e-icon-button`, and `m3e-menu` components into a split button.
|
|
25
|
+
*
|
|
26
|
+
* ```html
|
|
27
|
+
* <m3e-split-button>
|
|
28
|
+
* <m3e-button slot="leading-button">
|
|
29
|
+
* <m3e-icon slot="icon" name="edit"></m3e-icon>Edit
|
|
30
|
+
* </m3e-button>
|
|
31
|
+
* <m3e-icon-button slot="trailing-button">
|
|
32
|
+
* <m3e-icon name="keyboard_arrow_down"></m3e-icon>
|
|
33
|
+
* <m3e-menu-trigger for="menu1"></m3e-menu-trigger>
|
|
34
|
+
* </m3e-icon-button>
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @tag m3e-split-button
|
|
38
|
+
*
|
|
39
|
+
* @slot leading-button - The leading button used to perform the primary action.
|
|
40
|
+
* @slot trailing-button - The trailing icon button used to open a menu of related actions.
|
|
41
|
+
*
|
|
42
|
+
* @attr variant - The appearance variant of the button.
|
|
43
|
+
* @attr size - The size of the button.
|
|
44
|
+
*
|
|
45
|
+
* @cssprop --m3e-split-button-extra-small-trailing-button-unselected-leading-space - Leading space for the trailing button (extra-small, unselected).
|
|
46
|
+
* @cssprop --m3e-split-button-extra-small-trailing-button-unselected-trailing-space - Trailing space for the trailing button (extra-small, unselected).
|
|
47
|
+
* @cssprop --m3e-split-button-small-trailing-button-unselected-leading-space - Leading space for the trailing button (small, unselected).
|
|
48
|
+
* @cssprop --m3e-split-button-small-trailing-button-unselected-trailing-space - Trailing space for the trailing button (small, unselected).
|
|
49
|
+
* @cssprop --m3e-split-button-medium-trailing-button-unselected-leading-space - Leading space for the trailing button (medium, unselected).
|
|
50
|
+
* @cssprop --m3e-split-button-medium-trailing-button-unselected-trailing-space - Trailing space for the trailing button (medium, unselected).
|
|
51
|
+
* @cssprop --m3e-split-button-large-trailing-button-unselected-leading-space - Leading space for the trailing button (large, unselected).
|
|
52
|
+
* @cssprop --m3e-split-button-large-trailing-button-unselected-trailing-space - Trailing space for the trailing button (large, unselected).
|
|
53
|
+
* @cssprop --m3e-split-button-extra-large-trailing-button-unselected-leading-space - Leading space for the trailing button (extra-large, unselected).
|
|
54
|
+
* @cssprop --m3e-split-button-extra-large-trailing-button-unselected-trailing-space - Trailing space for the trailing button (extra-large, unselected).
|
|
55
|
+
* @cssprop --m3e-split-button-extra-small-trailing-button-selected-leading-space - Leading space for the trailing button (extra-small, selected).
|
|
56
|
+
* @cssprop --m3e-split-button-extra-small-trailing-button-selected-trailing-space - Trailing space for the trailing button (extra-small, selected).
|
|
57
|
+
* @cssprop --m3e-split-button-small-trailing-button-selected-leading-space - Leading space for the trailing button (small, selected).
|
|
58
|
+
* @cssprop --m3e-split-button-small-trailing-button-selected-trailing-space - Trailing space for the trailing button (small, selected).
|
|
59
|
+
* @cssprop --m3e-split-button-medium-trailing-button-selected-leading-space - Leading space for the trailing button (medium, selected).
|
|
60
|
+
* @cssprop --m3e-split-button-medium-trailing-button-selected-trailing-space - Trailing space for the trailing button (medium, selected).
|
|
61
|
+
* @cssprop --m3e-split-button-large-trailing-button-selected-leading-space - Leading space for the trailing button (large, selected).
|
|
62
|
+
* @cssprop --m3e-split-button-large-trailing-button-selected-trailing-space - Trailing space for the trailing button (large, selected).
|
|
63
|
+
* @cssprop --m3e-split-button-extra-large-trailing-button-selected-leading-space - Leading space for the trailing button (extra-large, selected).
|
|
64
|
+
* @cssprop --m3e-split-button-extra-large-trailing-button-selected-trailing-space - Trailing space for the trailing button (extra-large, selected).
|
|
65
|
+
* @cssprop --m3e-split-button-extra-small-inner-corner-size - Inner corner size for the leading/trailing button (extra-small).
|
|
66
|
+
* @cssprop --m3e-split-button-small-inner-corner-size - Inner corner size for the leading/trailing button (small).
|
|
67
|
+
* @cssprop --m3e-split-button-medium-inner-corner-size - Inner corner size for the leading/trailing button (medium).
|
|
68
|
+
* @cssprop --m3e-split-button-large-inner-corner-size - Inner corner size for the leading/trailing button (large).
|
|
69
|
+
* @cssprop --m3e-split-button-extra-large-inner-corner-size - Inner corner size for the leading/trailing button (extra-large).
|
|
70
|
+
* @cssprop --m3e-split-button-extra-small-inner-corner-hover-size - Inner corner size on hover (extra-small).
|
|
71
|
+
* @cssprop --m3e-split-button-small-inner-corner-hover-size - Inner corner size on hover (small).
|
|
72
|
+
* @cssprop --m3e-split-button-medium-inner-corner-hover-size - Inner corner size on hover (medium).
|
|
73
|
+
* @cssprop --m3e-split-button-large-inner-corner-hover-size - Inner corner size on hover (large).
|
|
74
|
+
* @cssprop --m3e-split-button-extra-large-inner-corner-hover-size - Inner corner size on hover (extra-large).
|
|
75
|
+
* @cssprop --m3e-split-button-extra-small-inner-corner-pressed-size - Inner corner size on press (extra-small).
|
|
76
|
+
* @cssprop --m3e-split-button-small-inner-corner-pressed-size - Inner corner size on press (small).
|
|
77
|
+
* @cssprop --m3e-split-button-medium-inner-corner-pressed-size - Inner corner size on press (medium).
|
|
78
|
+
* @cssprop --m3e-split-button-large-inner-corner-pressed-size - Inner corner size on press (large).
|
|
79
|
+
* @cssprop --m3e-split-button-extra-large-inner-corner-pressed-size - Inner corner size on press (extra-large).
|
|
80
|
+
* @cssprop --m3e-split-button-extra-small-between-spacing - Spacing between leading and trailing buttons (extra-small).
|
|
81
|
+
* @cssprop --m3e-split-button-small-between-spacing - Spacing between leading and trailing buttons (small).
|
|
82
|
+
* @cssprop --m3e-split-button-medium-between-spacing - Spacing between leading and trailing buttons (medium).
|
|
83
|
+
* @cssprop --m3e-split-button-large-between-spacing - Spacing between leading and trailing buttons (large).
|
|
84
|
+
* @cssprop --m3e-split-button-extra-large-between-spacing - Spacing between leading and trailing buttons (extra-large).
|
|
85
|
+
*/
|
|
86
|
+
@customElement("m3e-split-button")
|
|
87
|
+
export class M3eSplitButtonElement extends Role(LitElement, "group") {
|
|
88
|
+
/** The styles of the element. */
|
|
89
|
+
static override styles: CSSResultGroup = css`
|
|
90
|
+
:host {
|
|
91
|
+
display: inline-flex;
|
|
92
|
+
vertical-align: middle;
|
|
93
|
+
}
|
|
94
|
+
::slotted([slot="leading-button"]) {
|
|
95
|
+
flex: 1 1 auto;
|
|
96
|
+
min-width: 0;
|
|
97
|
+
--_button-start-shape-pressed-morph: var(--_leading-button-shape, ${DesignToken.shape.corner.full});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
::slotted([slot="trailing-button"]:not([aria-expanded="true"])) {
|
|
101
|
+
--m3e-icon-button-extra-small-default-leading-space: var(
|
|
102
|
+
--m3e-split-button-extra-small-trailing-button-unselected-leading-space,
|
|
103
|
+
0.75rem
|
|
104
|
+
);
|
|
105
|
+
--m3e-icon-button-extra-small-default-trailing-space: var(
|
|
106
|
+
--m3e-split-button-extra-small-trailing-button-unselected-trailing-space,
|
|
107
|
+
0.875rem
|
|
108
|
+
);
|
|
109
|
+
--m3e-icon-button-small-default-leading-space: var(
|
|
110
|
+
--m3e-split-button-small-trailing-button-unselected-leading-space,
|
|
111
|
+
0.75rem
|
|
112
|
+
);
|
|
113
|
+
--m3e-icon-button-small-default-trailing-space: var(
|
|
114
|
+
--m3e-split-button-small-trailing-button-unselected-trailing-space,
|
|
115
|
+
0.875rem
|
|
116
|
+
);
|
|
117
|
+
--m3e-icon-button-medium-default-leading-space: var(
|
|
118
|
+
--m3e-split-button-medium-trailing-button-unselected-leading-space,
|
|
119
|
+
0.8125rem
|
|
120
|
+
);
|
|
121
|
+
--m3e-icon-button-medium-default-trailing-space: var(
|
|
122
|
+
--m3e-split-button-medium-trailing-button-unselected-trailing-space,
|
|
123
|
+
1.0625rem
|
|
124
|
+
);
|
|
125
|
+
--m3e-icon-button-large-default-leading-space: var(
|
|
126
|
+
--m3e-split-button-large-trailing-button-unselected-leading-space,
|
|
127
|
+
1.625rem
|
|
128
|
+
);
|
|
129
|
+
--m3e-icon-button-large-default-trailing-space: var(
|
|
130
|
+
--m3e-split-button-large-trailing-button-unselected-trailing-space,
|
|
131
|
+
2rem
|
|
132
|
+
);
|
|
133
|
+
--m3e-icon-button-extra-large-default-leading-space: var(
|
|
134
|
+
--m3e-split-button-extra-large-trailing-button-unselected-leading-space,
|
|
135
|
+
2.3125rem
|
|
136
|
+
);
|
|
137
|
+
--m3e-icon-button-extra-large-default-trailing-space: var(
|
|
138
|
+
--m3e-split-button-extra-large-trailing-button-unselected-trailing-space,
|
|
139
|
+
3.0625rem
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
::slotted([slot="trailing-button"][aria-expanded="true"]) {
|
|
144
|
+
--m3e-icon-button-extra-small-default-leading-space: var(
|
|
145
|
+
--m3e-split-button-extra-small-trailing-button-selected-leading-space,
|
|
146
|
+
0.8125rem
|
|
147
|
+
);
|
|
148
|
+
--m3e-icon-button-extra-small-default-trailing-space: var(
|
|
149
|
+
--m3e-split-button-extra-small-trailing-button-selected-trailing-space,
|
|
150
|
+
0.8125rem
|
|
151
|
+
);
|
|
152
|
+
--m3e-icon-button-small-default-leading-space: var(
|
|
153
|
+
--m3e-split-button-small-trailing-button-selected-leading-space,
|
|
154
|
+
0.8125rem
|
|
155
|
+
);
|
|
156
|
+
--m3e-icon-button-small-default-trailing-space: var(
|
|
157
|
+
--m3e-split-button-small-trailing-button-selected-trailing-space,
|
|
158
|
+
0.8125rem
|
|
159
|
+
);
|
|
160
|
+
--m3e-icon-button-medium-default-leading-space: var(
|
|
161
|
+
--m3e-split-button-medium-trailing-button-selected-leading-space,
|
|
162
|
+
0.9375rem
|
|
163
|
+
);
|
|
164
|
+
--m3e-icon-button-medium-default-trailing-space: var(
|
|
165
|
+
--m3e-split-button-medium-trailing-button-selected-trailing-space,
|
|
166
|
+
0.9375rem
|
|
167
|
+
);
|
|
168
|
+
--m3e-icon-button-large-default-leading-space: var(
|
|
169
|
+
--m3e-split-button-large-trailing-button-selected-leading-space,
|
|
170
|
+
1.8125rem
|
|
171
|
+
);
|
|
172
|
+
--m3e-icon-button-large-default-trailing-space: var(
|
|
173
|
+
--m3e-split-button-large-trailing-button-selected-trailing-space,
|
|
174
|
+
1.8125rem
|
|
175
|
+
);
|
|
176
|
+
--m3e-icon-button-extra-large-default-leading-space: var(
|
|
177
|
+
--m3e-split-button-extra-large-trailing-button-selected-leading-space,
|
|
178
|
+
2.6875rem
|
|
179
|
+
);
|
|
180
|
+
--m3e-icon-button-extra-large-default-trailing-space: var(
|
|
181
|
+
--m3e-split-button-extra-large-trailing-button-selected-trailing-space,
|
|
182
|
+
2.6875rem
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
::slotted([slot="leading-button"]:not(:hover)),
|
|
187
|
+
::slotted([slot="leading-button"]:disabled),
|
|
188
|
+
::slotted([slot="leading-button"][disabled-interactive]) {
|
|
189
|
+
--m3e-connected-button-group-extra-small-inner-shape: var(
|
|
190
|
+
--m3e-split-button-extra-small-inner-corner-size,
|
|
191
|
+
${DesignToken.shape.corner.extraSmall}
|
|
192
|
+
);
|
|
193
|
+
--m3e-connected-button-group-small-inner-shape: var(
|
|
194
|
+
--m3e-split-button-small-inner-corner-size,
|
|
195
|
+
${DesignToken.shape.corner.extraSmall}
|
|
196
|
+
);
|
|
197
|
+
--m3e-connected-button-group-medium-inner-shape: var(
|
|
198
|
+
--m3e-split-button-medium-inner-corner-size,
|
|
199
|
+
${DesignToken.shape.corner.extraSmall}
|
|
200
|
+
);
|
|
201
|
+
--m3e-connected-button-group-large-inner-shape: var(
|
|
202
|
+
--m3e-split-button-large-inner-corner-size,
|
|
203
|
+
${DesignToken.shape.corner.small}
|
|
204
|
+
);
|
|
205
|
+
--m3e-connected-button-group-extra-large-inner-shape: var(
|
|
206
|
+
--m3e-split-button-extra-large-inner-corner-size,
|
|
207
|
+
${DesignToken.shape.corner.medium}
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
::slotted([slot="leading-button"]:hover:not(:disabled):not([disabled-interactive])),
|
|
211
|
+
::slotted([slot="trailing-button"]:not([aria-expanded="true"]):hover:not(:disabled):not([disabled-interactive])) {
|
|
212
|
+
--m3e-connected-button-group-extra-small-inner-shape: var(
|
|
213
|
+
--m3e-split-button-extra-small-inner-corner-hover-size,
|
|
214
|
+
${DesignToken.shape.corner.small}
|
|
215
|
+
);
|
|
216
|
+
--m3e-connected-button-group-small-inner-shape: var(
|
|
217
|
+
--m3e-split-button-small-inner-corner-hover-size,
|
|
218
|
+
${DesignToken.shape.corner.medium}
|
|
219
|
+
);
|
|
220
|
+
--m3e-connected-button-group-medium-inner-shape: var(
|
|
221
|
+
--m3e-split-button-medium-inner-corner-hover-size,
|
|
222
|
+
${DesignToken.shape.corner.medium}
|
|
223
|
+
);
|
|
224
|
+
--m3e-connected-button-group-large-inner-shape: var(
|
|
225
|
+
--m3e-split-button-large-inner-corner-hover-size,
|
|
226
|
+
${DesignToken.shape.corner.largeIncreased}
|
|
227
|
+
);
|
|
228
|
+
--m3e-connected-button-group-extra-large-inner-shape: var(
|
|
229
|
+
--m3e-split-button-extra-large-inner-corner-hover-size,
|
|
230
|
+
${DesignToken.shape.corner.largeIncreased}
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
::slotted([slot="leading-button"]),
|
|
235
|
+
::slotted([slot="trailing-button"]) {
|
|
236
|
+
--m3e-connected-button-group-extra-small-inner-pressed-shape: var(
|
|
237
|
+
--m3e-split-button-extra-small-inner-corner-pressed-size,
|
|
238
|
+
${DesignToken.shape.corner.small}
|
|
239
|
+
);
|
|
240
|
+
--m3e-connected-button-group-small-inner-pressed-shape: var(
|
|
241
|
+
--m3e-split-button-small-inner-corner-pressed-size,
|
|
242
|
+
${DesignToken.shape.corner.medium}
|
|
243
|
+
);
|
|
244
|
+
--m3e-connected-button-group-medium-inner-pressed-shape: var(
|
|
245
|
+
--m3e-split-button-medium-inner-corner-pressed-size,
|
|
246
|
+
${DesignToken.shape.corner.medium}
|
|
247
|
+
);
|
|
248
|
+
--m3e-connected-button-group-large-inner-pressed-shape: var(
|
|
249
|
+
--m3e-split-button-large-inner-corner-pressed-size,
|
|
250
|
+
${DesignToken.shape.corner.largeIncreased}
|
|
251
|
+
);
|
|
252
|
+
--m3e-connected-button-group-extra-large-inner-pressed-shape: var(
|
|
253
|
+
--m3e-split-button-extra-large-inner-corner-pressed-size,
|
|
254
|
+
${DesignToken.shape.corner.largeIncreased}
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
::slotted([slot="trailing-button"]:not([aria-expanded="true"]):not(:hover)),
|
|
259
|
+
::slotted([slot="trailing-button"]:disabled),
|
|
260
|
+
::slotted([slot="trailing-button"][disabled-interactive]) {
|
|
261
|
+
--m3e-connected-button-group-extra-small-inner-shape: var(
|
|
262
|
+
--m3e-split-button-extra-small-inner-corner-size,
|
|
263
|
+
${DesignToken.shape.corner.extraSmall}
|
|
264
|
+
);
|
|
265
|
+
--m3e-connected-button-group-small-inner-shape: var(
|
|
266
|
+
--m3e-split-button-small-inner-corner-size,
|
|
267
|
+
${DesignToken.shape.corner.extraSmall}
|
|
268
|
+
);
|
|
269
|
+
--m3e-connected-button-group-medium-inner-shape: var(
|
|
270
|
+
--m3e-split-button-medium-inner-corner-size,
|
|
271
|
+
${DesignToken.shape.corner.extraSmall}
|
|
272
|
+
);
|
|
273
|
+
--m3e-connected-button-group-large-inner-shape: var(
|
|
274
|
+
--m3e-split-button-large-inner-corner-size,
|
|
275
|
+
${DesignToken.shape.corner.small}
|
|
276
|
+
);
|
|
277
|
+
--m3e-connected-button-group-extra-large-inner-shape: var(
|
|
278
|
+
--m3e-split-button-extra-large-inner-corner-size,
|
|
279
|
+
${DesignToken.shape.corner.medium}
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
::slotted([slot="trailing-button"][aria-expanded="true"]) {
|
|
284
|
+
--_icon-button-icon-transform: rotate(180deg);
|
|
285
|
+
--_button-rounded-start-shape: var(--_trailing-button-shape, ${DesignToken.shape.corner.full});
|
|
286
|
+
--_button-rounded-end-shape: var(--_trailing-button-shape, ${DesignToken.shape.corner.full});
|
|
287
|
+
}
|
|
288
|
+
::slotted([slot="trailing-button"]) {
|
|
289
|
+
--_button-end-shape-pressed-morph: var(--_trailing-button-shape, ${DesignToken.shape.corner.full});
|
|
290
|
+
}
|
|
291
|
+
.base {
|
|
292
|
+
--m3e-icon-button-extra-small-icon-size: calc(
|
|
293
|
+
var(--m3e-spit-button-extra-small-trailing-button-icon-size, 1.375rem) + ${DesignToken.density.calc(0)}
|
|
294
|
+
);
|
|
295
|
+
--m3e-button-extra-small-icon-size: calc(
|
|
296
|
+
var(--m3e-spit-button-extra-small-trailing-button-icon-size, 1.375rem) + ${DesignToken.density.calc(0)}
|
|
297
|
+
);
|
|
298
|
+
--m3e-icon-button-small-icon-size: calc(
|
|
299
|
+
var(--m3e-spit-button-small-trailing-button-icon-size, 1.375rem) + ${DesignToken.density.calc(-1)}
|
|
300
|
+
);
|
|
301
|
+
--m3e-button-small-icon-size: calc(
|
|
302
|
+
var(--m3e-spit-button-small-trailing-button-icon-size, 1.375rem) + ${DesignToken.density.calc(-1)}
|
|
303
|
+
);
|
|
304
|
+
--m3e-icon-button-medium-icon-size: calc(
|
|
305
|
+
var(--m3e-spit-button-medium-trailing-button-icon-size, 1.625rem) + ${DesignToken.density.calc(-2)}
|
|
306
|
+
);
|
|
307
|
+
--m3e-button-medium-icon-size: calc(
|
|
308
|
+
var(--m3e-spit-button-medium-trailing-button-icon-size, 1.625rem) + ${DesignToken.density.calc(-2)}
|
|
309
|
+
);
|
|
310
|
+
--m3e-icon-button-large-icon-size: calc(
|
|
311
|
+
var(--m3e-spit-button-large-trailing-button-icon-size, 2.375rem) + ${DesignToken.density.calc(-3)}
|
|
312
|
+
);
|
|
313
|
+
--m3e-button-large-icon-size: calc(
|
|
314
|
+
var(--m3e-spit-button-large-trailing-button-icon-size, 2.375rem) + ${DesignToken.density.calc(-3)}
|
|
315
|
+
);
|
|
316
|
+
--m3e-icon-button-extra-large-icon-size: calc(
|
|
317
|
+
var(--m3e-spit-button-extra-large-trailing-button-icon-size, 3.125rem) + ${DesignToken.density.calc(-3)}
|
|
318
|
+
);
|
|
319
|
+
--m3e-button-extra-large-icon-size: calc(
|
|
320
|
+
var(--m3e-spit-button-extra-large-trailing-button-icon-size, 3.125rem) + ${DesignToken.density.calc(-3)}
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
:host([size="extra-small"]) .base {
|
|
324
|
+
--m3e-connected-button-group-spacing: var(--m3e-split-button-extra-small-between-spacing, 0.125rem);
|
|
325
|
+
}
|
|
326
|
+
:host([size="small"]) .base {
|
|
327
|
+
--m3e-connected-button-group-spacing: var(--m3e-split-button-small-between-spacing, 0.125rem);
|
|
328
|
+
}
|
|
329
|
+
:host([size="medium"]).base {
|
|
330
|
+
--m3e-connected-button-group-spacing: var(--m3e-split-button-medium-between-spacing, 0.125rem);
|
|
331
|
+
}
|
|
332
|
+
:host([size="large"]) .base {
|
|
333
|
+
--m3e-connected-button-group-spacing: var(--m3e-split-button-large-between-spacing, 0.125rem);
|
|
334
|
+
}
|
|
335
|
+
:host([size="extra-large"]) .base {
|
|
336
|
+
--m3e-connected-button-group-spacing: var(--m3e-split-button-extra-large-between-spacing, 0.125rem);
|
|
337
|
+
}
|
|
338
|
+
`;
|
|
339
|
+
|
|
340
|
+
@query(".base") private readonly _base?: HTMLElement;
|
|
341
|
+
|
|
342
|
+
/** @private */ #leadingButton?: M3eButtonElement;
|
|
343
|
+
/** @private */ #trailingButton?: M3eIconButtonElement;
|
|
344
|
+
/** @private */ #trailingButtonHover = false;
|
|
345
|
+
|
|
346
|
+
/** @private */ readonly #pressedController = new PressedController(this, {
|
|
347
|
+
target: null,
|
|
348
|
+
capture: true,
|
|
349
|
+
isPressedKey: (key) => key === " " || key === "Enter",
|
|
350
|
+
callback: (pressed, _, target) => {
|
|
351
|
+
switch (target) {
|
|
352
|
+
case this.#leadingButton:
|
|
353
|
+
this.#updateLeadingButtonShape(pressed);
|
|
354
|
+
break;
|
|
355
|
+
case this.#trailingButton:
|
|
356
|
+
this.#updateTrailingButtonShape(pressed || this.#trailingButtonHover);
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
/** @private */ readonly #hoverController = new HoverController(this, {
|
|
363
|
+
target: null,
|
|
364
|
+
callback: (hovering, target) => {
|
|
365
|
+
switch (target) {
|
|
366
|
+
case this.#trailingButton:
|
|
367
|
+
if (!this.#trailingButton?.disabled && !this.#trailingButton?.disabledInteractive) {
|
|
368
|
+
this.#trailingButtonHover = hovering;
|
|
369
|
+
this.#updateTrailingButtonShape(hovering);
|
|
370
|
+
}
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* The appearance variant of the button.
|
|
378
|
+
* @default "filled"
|
|
379
|
+
*/
|
|
380
|
+
@property({ reflect: true }) variant: SplitButtonVariant = "filled";
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* The size of the button.
|
|
384
|
+
* @default "small"
|
|
385
|
+
*/
|
|
386
|
+
@property({ reflect: true }) size: ButtonSize = "small";
|
|
387
|
+
|
|
388
|
+
/** @inheritdoc */
|
|
389
|
+
protected override update(changedProperties: PropertyValues<this>): void {
|
|
390
|
+
super.update(changedProperties);
|
|
391
|
+
|
|
392
|
+
if (changedProperties.has("variant")) {
|
|
393
|
+
this.#updateButtons();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** @inheritdoc */
|
|
398
|
+
protected override render(): unknown {
|
|
399
|
+
return html`<m3e-button-group class="base" role="none" variant="connected" size="${this.size}">
|
|
400
|
+
<slot name="leading-button" @slotchange="${this.#handleLeadingSlotChange}"></slot>
|
|
401
|
+
<slot name="trailing-button" @slotchange="${this.#handleTrailingSlotChange}"></slot>
|
|
402
|
+
</m3e-button-group>`;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** @private */
|
|
406
|
+
#handleLeadingSlotChange(e: Event): void {
|
|
407
|
+
if (this.#leadingButton) {
|
|
408
|
+
this.#pressedController.unobserve(this.#leadingButton);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
this.#leadingButton = (<HTMLSlotElement>e.target)
|
|
412
|
+
.assignedElements({ flatten: true })
|
|
413
|
+
.find((x) => x instanceof M3eButtonElement);
|
|
414
|
+
|
|
415
|
+
if (this.#leadingButton) {
|
|
416
|
+
this.#pressedController.observe(this.#leadingButton);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
this.#updateButtons();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** @private */
|
|
423
|
+
#handleTrailingSlotChange(e: Event): void {
|
|
424
|
+
if (this.#trailingButton) {
|
|
425
|
+
this.#pressedController.unobserve(this.#trailingButton);
|
|
426
|
+
this.#hoverController.unobserve(this.#trailingButton);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
this.#trailingButton = (<HTMLSlotElement>e.target)
|
|
430
|
+
.assignedElements({ flatten: true })
|
|
431
|
+
.find((x) => x instanceof M3eIconButtonElement);
|
|
432
|
+
|
|
433
|
+
if (this.#trailingButton) {
|
|
434
|
+
this.#pressedController.observe(this.#trailingButton);
|
|
435
|
+
this.#hoverController.observe(this.#trailingButton);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
this.#updateButtons();
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** @private */
|
|
442
|
+
#updateButtons(): void {
|
|
443
|
+
if (this.#leadingButton) {
|
|
444
|
+
this.#leadingButton.variant = this.variant;
|
|
445
|
+
this.#leadingButton.size = this.size;
|
|
446
|
+
this.#leadingButton.shape = "rounded";
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (this.#trailingButton) {
|
|
450
|
+
this.#trailingButton.width = "default";
|
|
451
|
+
this.#trailingButton.shape = "rounded";
|
|
452
|
+
this.#trailingButton.setAttribute("variant", this.variant);
|
|
453
|
+
this.#trailingButton.size = this.size;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** @private */
|
|
458
|
+
#updateLeadingButtonShape(update: boolean): void {
|
|
459
|
+
if (update && this.#leadingButton) {
|
|
460
|
+
this.#updateButtonShape(this.#leadingButton, "--_leading-button-shape");
|
|
461
|
+
} else {
|
|
462
|
+
this._base?.style.removeProperty("--_leading-button-shape");
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** @private */
|
|
467
|
+
#updateTrailingButtonShape(update: boolean): void {
|
|
468
|
+
if (update && this.#trailingButton) {
|
|
469
|
+
this.#updateButtonShape(this.#trailingButton, "--_trailing-button-shape");
|
|
470
|
+
} else {
|
|
471
|
+
this._base?.style.removeProperty("--_trailing-button-shape");
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** @private */
|
|
476
|
+
#updateButtonShape(button: HTMLElement, property: string): void {
|
|
477
|
+
const adjustedShape = button.clientHeight / 2;
|
|
478
|
+
if (adjustedShape) {
|
|
479
|
+
this._base?.style.setProperty(property, `${adjustedShape}px`);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
declare global {
|
|
485
|
+
interface HTMLElementTagNameMap {
|
|
486
|
+
"m3e-split-button": M3eSplitButtonElement;
|
|
487
|
+
}
|
|
488
|
+
}
|
package/src/index.ts
ADDED