@m3e/button-group 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 +132 -0
- package/cem.config.mjs +16 -0
- package/demo/index.html +95 -0
- package/dist/css-custom-data.json +87 -0
- package/dist/custom-elements.json +279 -0
- package/dist/html-custom-data.json +28 -0
- package/dist/index.js +467 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +245 -0
- package/dist/index.min.js.map +1 -0
- package/dist/src/ButtonGroupElement.d.ts +97 -0
- package/dist/src/ButtonGroupElement.d.ts.map +1 -0
- package/dist/src/ButtonGroupSize.d.ts +3 -0
- package/dist/src/ButtonGroupSize.d.ts.map +1 -0
- package/dist/src/ButtonGroupVariant.d.ts +3 -0
- package/dist/src/ButtonGroupVariant.d.ts.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +52 -0
- package/rollup.config.js +32 -0
- package/src/ButtonGroupElement.ts +385 -0
- package/src/ButtonGroupSize.ts +2 -0
- package/src/ButtonGroupVariant.ts +2 -0
- package/src/index.ts +3 -0
- package/tsconfig.json +9 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* Copyright (c) 2025 matraic
|
|
4
|
+
* See LICENSE file in the project root for full license text.
|
|
5
|
+
*/
|
|
6
|
+
import { LitElement, html, css } from 'lit';
|
|
7
|
+
import { Role, PressedController, DesignToken, isSelectedMixin } from '@m3e/core';
|
|
8
|
+
|
|
9
|
+
/******************************************************************************
|
|
10
|
+
Copyright (c) Microsoft Corporation.
|
|
11
|
+
|
|
12
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
13
|
+
purpose with or without fee is hereby granted.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
16
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
17
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
18
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
19
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
20
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
21
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
22
|
+
***************************************************************************** */
|
|
23
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function __decorate(decorators, target, key, desc) {
|
|
27
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
29
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
30
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
34
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
35
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
36
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
40
|
+
var e = new Error(message);
|
|
41
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @license
|
|
46
|
+
* Copyright 2017 Google LLC
|
|
47
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
48
|
+
*/
|
|
49
|
+
const t$1=t=>(e,o)=>{ void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @license
|
|
53
|
+
* Copyright 2019 Google LLC
|
|
54
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
55
|
+
*/
|
|
56
|
+
const t=globalThis,e$3=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),o$3=new WeakMap;let n$2 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$3&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$2=t=>new n$2("string"==typeof t?t:t+"",void 0,s),S=(s,o)=>{if(e$3)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$1=e$3?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$2(e)})(t):t;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @license
|
|
60
|
+
* Copyright 2017 Google LLC
|
|
61
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
62
|
+
*/const{is:i,defineProperty:e$2,getOwnPropertyDescriptor:h,getOwnPropertyNames:r$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$1}=Object,a=globalThis,c=a.trustedTypes,l=c?c.emptyScript:"",p=a.reactiveElementPolyfillSupport,d=(t,s)=>t,u={toAttribute(t,s){switch(s){case Boolean:t=t?l:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f=(t,s)=>!i(t,s),b={attribute:true,type:String,converter:u,reflect:false,useDefault:false,hasChanged:f};Symbol.metadata??=Symbol("metadata"),a.litPropertyMetadata??=new WeakMap;class y extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=b){if(s.state&&(s.attribute=false),this._$Ei(),this.prototype.hasOwnProperty(t)&&((s=Object.create(s)).wrapped=true),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),h=this.getPropertyDescriptor(t,i,s);void 0!==h&&e$2(this.prototype,t,h);}}static getPropertyDescriptor(t,s,i){const{get:e,set:r}=h(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get:e,set(s){const h=e?.call(this);r?.call(this,s),this.requestUpdate(t,h,i);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??b}static _$Ei(){if(this.hasOwnProperty(d("elementProperties")))return;const t=n$1(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d("finalized")))return;if(this.finalized=true,this._$Ei(),this.hasOwnProperty(d("properties"))){const t=this.properties,s=[...r$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$1(s));}else void 0!==s&&i.push(c$1(s));return i}static _$Eu(t,s){const i=s.attribute;return false===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=false,this.hasUpdated=false,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(true),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$ET(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&true===i.reflect){const h=(void 0!==i.converter?.toAttribute?i.converter:u).toAttribute(s,i.type);this._$Em=t,null==h?this.removeAttribute(e):this.setAttribute(e,h),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),h="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u;this._$Em=e;const r=h.fromAttribute(s,t.type);this[e]=r??this._$Ej?.get(e)??r,this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){const e=this.constructor,h=this[t];if(i??=e.getPropertyOptions(t),!((i.hasChanged??f)(h,s)||i.useDefault&&i.reflect&&h===this._$Ej?.get(t)&&!this.hasAttribute(e._$Eu(t,i))))return;this.C(t,s,i);} false===this.isUpdatePending&&(this._$ES=this._$EP());}C(t,s,{useDefault:i,reflect:e,wrapped:h},r){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,r??s??this[t]),true!==h||void 0!==r)||(this._$AL.has(t)||(this.hasUpdated||i||(s=void 0),this._$AL.set(t,s)),true===e&&this._$Em!==t&&(this._$Eq??=new Set).add(t));}async _$EP(){this.isUpdatePending=true;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t){const{wrapped:t}=i,e=this[s];true!==t||this._$AL.has(s)||void 0===e||this.C(s,void 0,i,e);}}let t=false;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EM();}catch(s){throw t=false,this._$EM(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=true,this.firstUpdated(t)),this.updated(t);}_$EM(){this._$AL=new Map,this.isUpdatePending=false;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return true}update(t){this._$Eq&&=this._$Eq.forEach((t=>this._$ET(t,this[t]))),this._$EM();}updated(t){}firstUpdated(t){}}y.elementStyles=[],y.shadowRootOptions={mode:"open"},y[d("elementProperties")]=new Map,y[d("finalized")]=new Map,p?.({ReactiveElement:y}),(a.reactiveElementVersions??=[]).push("2.1.1");
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @license
|
|
66
|
+
* Copyright 2017 Google LLC
|
|
67
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
68
|
+
*/const o$1={attribute:true,type:String,converter:u,reflect:false,hasChanged:f},r=(t=o$1,e,r)=>{const{kind:n,metadata:i}=r;let s=globalThis.litPropertyMetadata.get(i);if(void 0===s&&globalThis.litPropertyMetadata.set(i,s=new Map),"setter"===n&&((t=Object.create(t)).wrapped=true),s.set(r.name,t),"accessor"===n){const{name:o}=r;return {set(r){const n=e.get.call(this);e.set.call(this,r),this.requestUpdate(o,n,t);},init(e){return void 0!==e&&this.C(o,void 0,t,e),e}}}if("setter"===n){const{name:o}=r;return function(r){const n=this[o];e.call(this,r),this.requestUpdate(o,n,t);}}throw Error("Unsupported decorator location: "+n)};function n(t){return (e,o)=>"object"==typeof o?r(t,e,o):((t,e,o)=>{const r=e.hasOwnProperty(o);return e.constructor.createProperty(o,t),r?Object.getOwnPropertyDescriptor(e,o):void 0})(t,e,o)}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @license
|
|
72
|
+
* Copyright 2017 Google LLC
|
|
73
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
74
|
+
*/
|
|
75
|
+
const e$1=(e,t,c)=>(c.configurable=true,c.enumerable=true,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @license
|
|
79
|
+
* Copyright 2017 Google LLC
|
|
80
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
81
|
+
*/function e(e,r){return (n,s,i)=>{const o=t=>t.renderRoot?.querySelector(e)??null;return e$1(n,s,{get(){return o(this)}})}}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @license
|
|
85
|
+
* Copyright 2021 Google LLC
|
|
86
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
87
|
+
*/function o(o){return (e,n)=>{const{slot:r,selector:s}=o??{},c="slot"+(r?`[name=${r}]`:":not([name])");return e$1(e,n,{get(){const t=this.renderRoot?.querySelector(c),e=t?.assignedElements(o)??[];return void 0===s?e:e.filter((t=>t.matches(s)))}})}}
|
|
88
|
+
|
|
89
|
+
var _M3eButtonGroupElement_instances, _M3eButtonGroupElement_pressedController, _M3eButtonGroupElement_updateButtons, _M3eButtonGroupElement_handleChange;
|
|
90
|
+
/**
|
|
91
|
+
* @summary
|
|
92
|
+
* Organizes buttons and adds interactions between them.
|
|
93
|
+
*
|
|
94
|
+
* @description
|
|
95
|
+
* The `m3e-button-group` component arranges multiple buttons into a unified, expressive layout,
|
|
96
|
+
* supporting both `standard` and `connected` variants. It enables seamless, accessible grouping
|
|
97
|
+
* of actions, adapts to various sizes, and ensures consistent spacing, shape, and alignment.
|
|
98
|
+
* Designed according to Material 3 principles, it empowers users to interact with related actions
|
|
99
|
+
* in a visually harmonious and intuitive way.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* The following example illustrates a standard button group.
|
|
103
|
+
* ``` html
|
|
104
|
+
* <m3e-button-group>
|
|
105
|
+
* <m3e-icon-button variant="tonal" toggle><m3e-icon name="format_bold"></m3e-icon></m3e-icon-button>
|
|
106
|
+
* <m3e-icon-button variant="tonal" toggle><m3e-icon name="format_italic"></m3e-icon></m3e-icon-button>
|
|
107
|
+
* <m3e-icon-button variant="tonal" toggle><m3e-icon name="format_underlined"></m3e-icon></m3e-icon-button>
|
|
108
|
+
* </m3e-button-group>
|
|
109
|
+
* ```
|
|
110
|
+
* @example
|
|
111
|
+
* The next example illustrates a connected button group.
|
|
112
|
+
* ```html
|
|
113
|
+
* <m3e-button-group variant="connected">
|
|
114
|
+
* <m3e-button variant="tonal" shape="square" toggle>Start</m3e-button>
|
|
115
|
+
* <m3e-button variant="tonal" shape="square" toggle>Directions</m3e-button>
|
|
116
|
+
* <m3e-button variant="tonal" shape="square" toggle>Share</m3e-button>
|
|
117
|
+
* </m3e-button-group>
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @tag m3e-button-group
|
|
121
|
+
*
|
|
122
|
+
* @slot - Renders the buttons of the group.
|
|
123
|
+
*
|
|
124
|
+
* @attr multi - Whether multiple toggle buttons can be selected.
|
|
125
|
+
* @attr size - The size of the group.
|
|
126
|
+
* @attr variant - The appearance variant of the group.
|
|
127
|
+
*
|
|
128
|
+
* @cssprop --m3e-standard-button-group-extra-small-spacing - Spacing between buttons in standard variant, extra-small size.
|
|
129
|
+
* @cssprop --m3e-standard-button-group-small-spacing - Spacing between buttons in standard variant, small size.
|
|
130
|
+
* @cssprop --m3e-standard-button-group-medium-spacing - Spacing between buttons in standard variant, medium size.
|
|
131
|
+
* @cssprop --m3e-standard-button-group-large-spacing - Spacing between buttons in standard variant, large size.
|
|
132
|
+
* @cssprop --m3e-standard-button-group-extra-large-spacing - Spacing between buttons in standard variant, extra-large size.
|
|
133
|
+
* @cssprop --m3e-connected-button-group-spacing - Spacing between buttons in connected variant.
|
|
134
|
+
* @cssprop --m3e-connected-button-group-extra-small-inner-shape - Corner shape for connected variant, extra-small size.
|
|
135
|
+
* @cssprop --m3e-connected-button-group-extra-small-inner-pressed-shape - Pressed corner shape for connected variant, extra-small size.
|
|
136
|
+
* @cssprop --m3e-connected-button-group-small-inner-shape - Corner shape for connected variant, small size.
|
|
137
|
+
* @cssprop --m3e-connected-button-group-small-inner-pressed-shape - Pressed corner shape for connected variant, small size.
|
|
138
|
+
* @cssprop --m3e-connected-button-group-medium-inner-shape - Corner shape for connected variant, medium size.
|
|
139
|
+
* @cssprop --m3e-connected-button-group-medium-inner-pressed-shape - Pressed corner shape for connected variant, medium size.
|
|
140
|
+
* @cssprop --m3e-connected-button-group-large-inner-shape - Corner shape for connected variant, large size.
|
|
141
|
+
* @cssprop --m3e-connected-button-group-large-inner-pressed-shape - Pressed corner shape for connected variant, large size.
|
|
142
|
+
* @cssprop --m3e-connected-button-group-extra-large-inner-shape - Corner shape for connected variant, extra-large size.
|
|
143
|
+
* @cssprop --m3e-connected-button-group-extra-large-inner-pressed-shape - Pressed corner shape for connected variant, extra-large size.
|
|
144
|
+
*/
|
|
145
|
+
let M3eButtonGroupElement = class M3eButtonGroupElement extends Role(LitElement, "group") {
|
|
146
|
+
constructor() {
|
|
147
|
+
super(...arguments);
|
|
148
|
+
_M3eButtonGroupElement_instances.add(this);
|
|
149
|
+
/** @private */ _M3eButtonGroupElement_pressedController.set(this, new PressedController(this, {
|
|
150
|
+
target: null,
|
|
151
|
+
capture: true,
|
|
152
|
+
isPressedKey: (key) => key === " " || key === "Enter",
|
|
153
|
+
callback: (pressed) => {
|
|
154
|
+
if (!this._base)
|
|
155
|
+
return;
|
|
156
|
+
if (!pressed || this.variant === "connected") {
|
|
157
|
+
this._base.style.removeProperty("--_button-group-width");
|
|
158
|
+
this._base.classList.remove("pressed");
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
this._base.classList.add("pressed");
|
|
162
|
+
this._base.style.setProperty("--_button-group-width", `${this._base.getBoundingClientRect().width}px`);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
}));
|
|
166
|
+
/**
|
|
167
|
+
* The appearance variant of the group.
|
|
168
|
+
* @default "standard"
|
|
169
|
+
*/
|
|
170
|
+
this.variant = "standard";
|
|
171
|
+
/**
|
|
172
|
+
* The size of the group.
|
|
173
|
+
* @default "small"
|
|
174
|
+
*/
|
|
175
|
+
this.size = "small";
|
|
176
|
+
/**
|
|
177
|
+
* Whether multiple toggle buttons can be selected.
|
|
178
|
+
* @default false
|
|
179
|
+
*/
|
|
180
|
+
this.multi = false;
|
|
181
|
+
}
|
|
182
|
+
/** @inheritdoc */
|
|
183
|
+
disconnectedCallback() {
|
|
184
|
+
super.disconnectedCallback();
|
|
185
|
+
this._base?.style.removeProperty("--_button-group-width");
|
|
186
|
+
this._base?.classList.remove("pressed");
|
|
187
|
+
}
|
|
188
|
+
/** @inheritdoc */
|
|
189
|
+
update(changedProperties) {
|
|
190
|
+
super.update(changedProperties);
|
|
191
|
+
if (changedProperties.has("multi") || changedProperties.has("variant")) {
|
|
192
|
+
__classPrivateFieldGet(this, _M3eButtonGroupElement_instances, "m", _M3eButtonGroupElement_updateButtons).call(this);
|
|
193
|
+
}
|
|
194
|
+
if (changedProperties.has("variant")) {
|
|
195
|
+
this._base?.style.removeProperty("--_button-group-width");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** @inheritdoc */
|
|
199
|
+
render() {
|
|
200
|
+
return html `<div class="base">
|
|
201
|
+
<slot @slotchange="${__classPrivateFieldGet(this, _M3eButtonGroupElement_instances, "m", _M3eButtonGroupElement_updateButtons)}" @change="${__classPrivateFieldGet(this, _M3eButtonGroupElement_instances, "m", _M3eButtonGroupElement_handleChange)}"></slot>
|
|
202
|
+
</div>`;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
_M3eButtonGroupElement_pressedController = new WeakMap();
|
|
206
|
+
_M3eButtonGroupElement_instances = new WeakSet();
|
|
207
|
+
_M3eButtonGroupElement_updateButtons = function _M3eButtonGroupElement_updateButtons() {
|
|
208
|
+
for (const target of __classPrivateFieldGet(this, _M3eButtonGroupElement_pressedController, "f").targets) {
|
|
209
|
+
__classPrivateFieldGet(this, _M3eButtonGroupElement_pressedController, "f").unobserve(target);
|
|
210
|
+
}
|
|
211
|
+
const canToggle = [...this.buttons].some((x) => x.toggle);
|
|
212
|
+
this.role = canToggle && !this.multi ? "radiogroup" : "group";
|
|
213
|
+
const buttonRole = this.role === "radiogroup" ? "radio" : "button";
|
|
214
|
+
for (const button of this.buttons) {
|
|
215
|
+
__classPrivateFieldGet(this, _M3eButtonGroupElement_pressedController, "f").observe(button);
|
|
216
|
+
button.classList.toggle("-connected", this.variant === "connected");
|
|
217
|
+
button.classList.add("-grouped");
|
|
218
|
+
if (button.role !== buttonRole && button.toggle) {
|
|
219
|
+
const checked = !button.toggle ? null : button.selected ? "true" : "false";
|
|
220
|
+
button.role = buttonRole;
|
|
221
|
+
if (button.role === "button") {
|
|
222
|
+
button.ariaPressed = checked;
|
|
223
|
+
button.ariaChecked = null;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
button.ariaChecked = checked;
|
|
227
|
+
button.ariaPressed = null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
_M3eButtonGroupElement_handleChange = function _M3eButtonGroupElement_handleChange(e) {
|
|
233
|
+
if (this.multi || !(e.target instanceof HTMLElement))
|
|
234
|
+
return;
|
|
235
|
+
if (e.target.tagName === "M3E-BUTTON" || e.target.tagName === "M3E-ICON-BUTTON") {
|
|
236
|
+
if (!isSelectedMixin(e.target) || !e.target.selected) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
for (const button of this.buttons) {
|
|
240
|
+
if (button === e.target || !button.selected)
|
|
241
|
+
continue;
|
|
242
|
+
button.selected = false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
/** The styles of the element. */
|
|
247
|
+
M3eButtonGroupElement.styles = css `
|
|
248
|
+
:host {
|
|
249
|
+
display: flex;
|
|
250
|
+
vertical-align: middle;
|
|
251
|
+
flex-wrap: nowrap;
|
|
252
|
+
align-items: center;
|
|
253
|
+
}
|
|
254
|
+
.base {
|
|
255
|
+
display: flex;
|
|
256
|
+
vertical-align: middle;
|
|
257
|
+
flex-wrap: nowrap;
|
|
258
|
+
align-items: center;
|
|
259
|
+
}
|
|
260
|
+
:host([variant="standard"]) {
|
|
261
|
+
justify-content: center;
|
|
262
|
+
}
|
|
263
|
+
:host([variant="connected"]) .base {
|
|
264
|
+
flex: 1 1 auto;
|
|
265
|
+
}
|
|
266
|
+
:host([variant="standard"]) .base {
|
|
267
|
+
width: fit-content;
|
|
268
|
+
flex: none;
|
|
269
|
+
}
|
|
270
|
+
:host([variant="standard"]) .base.pressed {
|
|
271
|
+
justify-content: space-between;
|
|
272
|
+
width: var(--_button-group-width);
|
|
273
|
+
}
|
|
274
|
+
:host([variant="standard"][size="extra-small"]) .base {
|
|
275
|
+
column-gap: var(--m3e-standard-button-group-extra-small-spacing, 1.125rem);
|
|
276
|
+
}
|
|
277
|
+
:host([variant="standard"][size="small"]) .base {
|
|
278
|
+
column-gap: var(--m3e-standard-button-group-small-spacing, 0.75rem);
|
|
279
|
+
}
|
|
280
|
+
:host([variant="standard"][size="medium"]).base {
|
|
281
|
+
column-gap: var(--m3e-standard-button-group-medium-spacing, 0.5rem);
|
|
282
|
+
}
|
|
283
|
+
:host([variant="standard"][size="large"]) .base {
|
|
284
|
+
column-gap: var(--m3e-standard-button-group-large-spacing, 0.5rem);
|
|
285
|
+
}
|
|
286
|
+
:host([variant="standard"][size="extra-large"]) .base {
|
|
287
|
+
column-gap: var(--m3e-standard-button-group-extra-large-spacing, 0.5rem);
|
|
288
|
+
}
|
|
289
|
+
:host([variant="connected"]) .base {
|
|
290
|
+
column-gap: var(--m3e-connected-button-group-spacing, 0.125rem);
|
|
291
|
+
}
|
|
292
|
+
:host([variant="connected"][size="extra-small"]) ::slotted(:first-child[size="extra-small"]),
|
|
293
|
+
:host([variant="connected"][size="extra-small"])
|
|
294
|
+
::slotted(:not(:first-child):not(:last-child)[size="extra-small"]) {
|
|
295
|
+
--_button-rounded-end-shape: var(
|
|
296
|
+
--m3e-connected-button-group-extra-small-inner-shape,
|
|
297
|
+
${DesignToken.shape.corner.small}
|
|
298
|
+
);
|
|
299
|
+
--_button-square-end-shape: var(
|
|
300
|
+
--m3e-connected-button-group-extra-small-inner-shape,
|
|
301
|
+
${DesignToken.shape.corner.small}
|
|
302
|
+
);
|
|
303
|
+
--_button-square-end-pressed-shape: var(
|
|
304
|
+
--m3e-connected-button-group-extra-small-inner-pressed-shape,
|
|
305
|
+
${DesignToken.shape.corner.extraSmall}
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
:host([variant="connected"][size="extra-small"]) ::slotted(:last-child[size="extra-small"]),
|
|
309
|
+
:host([variant="connected"][size="extra-small"])
|
|
310
|
+
::slotted(:not(:first-child):not(:last-child)[size="extra-small"]) {
|
|
311
|
+
--_button-rounded-start-shape: var(
|
|
312
|
+
--m3e-connected-button-group-extra-small-inner-shape,
|
|
313
|
+
${DesignToken.shape.corner.small}
|
|
314
|
+
);
|
|
315
|
+
--_button-square-start-shape: var(
|
|
316
|
+
--m3e-connected-button-group-extra-small-inner-shape,
|
|
317
|
+
${DesignToken.shape.corner.small}
|
|
318
|
+
);
|
|
319
|
+
--_button-square-start-pressed-shape: var(
|
|
320
|
+
--m3e-connected-button-group-extra-small-inner-pressed-shape,
|
|
321
|
+
${DesignToken.shape.corner.extraSmall}
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
:host([variant="connected"][size="small"]) ::slotted(:first-child[size="small"]),
|
|
325
|
+
:host([variant="connected"][size="small"]) ::slotted(:not(:first-child):not(:last-child)[size="small"]) {
|
|
326
|
+
--_button-rounded-end-shape: var(
|
|
327
|
+
--m3e-connected-button-group-small-inner-shape,
|
|
328
|
+
${DesignToken.shape.corner.small}
|
|
329
|
+
);
|
|
330
|
+
--_button-square-end-shape: var(
|
|
331
|
+
--m3e-connected-button-group-small-inner-shape,
|
|
332
|
+
${DesignToken.shape.corner.small}
|
|
333
|
+
);
|
|
334
|
+
--_button-end-shape-pressed-morph: var(
|
|
335
|
+
--m3e-connected-button-group-small-inner-pressed-shape,
|
|
336
|
+
${DesignToken.shape.corner.extraSmall}
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
:host([variant="connected"][size="small"]) ::slotted(:last-child[size="small"]),
|
|
340
|
+
:host([variant="connected"][size="small"]) ::slotted(:not(:first-child):not(:last-child)[size="small"]) {
|
|
341
|
+
--_button-rounded-start-shape: var(
|
|
342
|
+
--m3e-connected-button-group-small-inner-shape,
|
|
343
|
+
${DesignToken.shape.corner.small}
|
|
344
|
+
);
|
|
345
|
+
--_button-square-start-shape: var(
|
|
346
|
+
--m3e-connected-button-group-small-inner-shape,
|
|
347
|
+
${DesignToken.shape.corner.small}
|
|
348
|
+
);
|
|
349
|
+
--_button-start-shape-pressed-morph: var(
|
|
350
|
+
--m3e-connected-button-group-small-inner-pressed-shape,
|
|
351
|
+
${DesignToken.shape.corner.extraSmall}
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
:host([variant="connected"][size="medium"]) ::slotted(:first-child[size="medium"]),
|
|
355
|
+
:host([variant="connected"][size="medium"]) ::slotted(:not(:first-child):not(:last-child)[size="medium"]) {
|
|
356
|
+
--_button-rounded-end-shape: var(
|
|
357
|
+
--m3e-connected-button-group-medium-inner-shape,
|
|
358
|
+
${DesignToken.shape.corner.small}
|
|
359
|
+
);
|
|
360
|
+
--_button-square-end-shape: var(
|
|
361
|
+
--m3e-connected-button-group-medium-inner-shape,
|
|
362
|
+
${DesignToken.shape.corner.small}
|
|
363
|
+
);
|
|
364
|
+
--_button-square-end-pressed-shape: var(
|
|
365
|
+
--m3e-connected-button-group-medium-inner-pressed-shape,
|
|
366
|
+
${DesignToken.shape.corner.extraSmall}
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
:host([variant="connected"][size="medium"]) ::slotted(:last-child[size="medium"]),
|
|
370
|
+
:host([variant="connected"][size="medium"]) ::slotted(:not(:first-child):not(:last-child)[size="medium"]) {
|
|
371
|
+
--_button-rounded-start-shape: var(
|
|
372
|
+
--m3e-connected-button-group-medium-inner-shape,
|
|
373
|
+
${DesignToken.shape.corner.small}
|
|
374
|
+
);
|
|
375
|
+
--_button-square-start-shape: var(
|
|
376
|
+
--m3e-connected-button-group-medium-inner-shape,
|
|
377
|
+
${DesignToken.shape.corner.small}
|
|
378
|
+
);
|
|
379
|
+
--_button-square-start-pressed-shape: var(
|
|
380
|
+
--m3e-connected-button-group-medium-inner-pressed-shape,
|
|
381
|
+
${DesignToken.shape.corner.extraSmall}
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
:host([variant="connected"][size="large"]) ::slotted(:first-child[size="large"]),
|
|
385
|
+
:host([variant="connected"][size="large"]) ::slotted(:not(:first-child):not(:last-child)[size="large"]) {
|
|
386
|
+
--_button-rounded-end-shape: var(
|
|
387
|
+
--m3e-connected-button-group-large-inner-shape,
|
|
388
|
+
${DesignToken.shape.corner.large}
|
|
389
|
+
);
|
|
390
|
+
--_button-square-end-shape: var(
|
|
391
|
+
--m3e-connected-button-group-large-inner-shape,
|
|
392
|
+
${DesignToken.shape.corner.large}
|
|
393
|
+
);
|
|
394
|
+
--_button-square-end-pressed-shape: var(
|
|
395
|
+
--m3e-connected-button-group-large-inner-pressed-shape,
|
|
396
|
+
${DesignToken.shape.corner.medium}
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
:host([variant="connected"][size="large"]) ::slotted(:last-child[size="large"]),
|
|
400
|
+
:host([variant="connected"][size="large"]) ::slotted(:not(:first-child):not(:last-child)[size="large"]) {
|
|
401
|
+
--_button-rounded-start-shape: var(
|
|
402
|
+
--m3e-connected-button-group-large-inner-shape,
|
|
403
|
+
${DesignToken.shape.corner.large}
|
|
404
|
+
);
|
|
405
|
+
--_button-square-start-shape: var(
|
|
406
|
+
--m3e-connected-button-group-large-inner-shape,
|
|
407
|
+
${DesignToken.shape.corner.large}
|
|
408
|
+
);
|
|
409
|
+
--_button-square-start-pressed-shape: var(
|
|
410
|
+
--m3e-connected-button-group-large-inner-pressed-shape,
|
|
411
|
+
${DesignToken.shape.corner.medium}
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
:host([variant="connected"][size="extra-large"]) ::slotted(:first-child[size="extra-large"]),
|
|
415
|
+
:host([variant="connected"][size="extra-large"])
|
|
416
|
+
::slotted(:not(:first-child):not(:last-child)[size="extra-large"]) {
|
|
417
|
+
--_button-rounded-end-shape: var(
|
|
418
|
+
--m3e-connected-button-group-extra-large-inner-shape,
|
|
419
|
+
${DesignToken.shape.corner.largeIncreased}
|
|
420
|
+
);
|
|
421
|
+
--_button-square-end-shape: var(
|
|
422
|
+
--m3e-connected-button-group-extra-large-inner-shape,
|
|
423
|
+
${DesignToken.shape.corner.largeIncreased}
|
|
424
|
+
);
|
|
425
|
+
--_button-square-end-pressed-shape: var(
|
|
426
|
+
--m3e-connected-button-group-extra-large-inner-pressed-shape,
|
|
427
|
+
${DesignToken.shape.corner.large}
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
:host([variant="connected"][size="extra-large"]) ::slotted(:last-child[size="extra-large"]),
|
|
431
|
+
:host([variant="connected"][size="extra-large"])
|
|
432
|
+
::slotted(:not(:first-child):not(:last-child)[size="extra-large"]) {
|
|
433
|
+
--_button-rounded-start-shape: var(
|
|
434
|
+
--m3e-connected-button-group-extra-large-inner-shape,
|
|
435
|
+
${DesignToken.shape.corner.largeIncreased}
|
|
436
|
+
);
|
|
437
|
+
--_button-square-start-shape: var(
|
|
438
|
+
--m3e-connected-button-group-extra-large-inner-shape,
|
|
439
|
+
${DesignToken.shape.corner.largeIncreased}
|
|
440
|
+
);
|
|
441
|
+
--_button-square-start-pressed-shape: var(
|
|
442
|
+
--m3e-connected-button-group-extra-large-inner-pressed-shape,
|
|
443
|
+
${DesignToken.shape.corner.large}
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
`;
|
|
447
|
+
__decorate([
|
|
448
|
+
e(".base")
|
|
449
|
+
], M3eButtonGroupElement.prototype, "_base", void 0);
|
|
450
|
+
__decorate([
|
|
451
|
+
n({ reflect: true })
|
|
452
|
+
], M3eButtonGroupElement.prototype, "variant", void 0);
|
|
453
|
+
__decorate([
|
|
454
|
+
n({ reflect: true })
|
|
455
|
+
], M3eButtonGroupElement.prototype, "size", void 0);
|
|
456
|
+
__decorate([
|
|
457
|
+
n({ type: Boolean })
|
|
458
|
+
], M3eButtonGroupElement.prototype, "multi", void 0);
|
|
459
|
+
__decorate([
|
|
460
|
+
o({ slot: "", selector: "m3e-button,m3e-icon-button", flatten: true })
|
|
461
|
+
], M3eButtonGroupElement.prototype, "buttons", void 0);
|
|
462
|
+
M3eButtonGroupElement = __decorate([
|
|
463
|
+
t$1("m3e-button-group")
|
|
464
|
+
], M3eButtonGroupElement);
|
|
465
|
+
|
|
466
|
+
export { M3eButtonGroupElement };
|
|
467
|
+
//# sourceMappingURL=index.js.map
|