UNPKG

35.8 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5const index = require('./index-a0a08b2a.js');
6const ionicGlobal = require('./ionic-global-06f21c1a.js');
7const helpers = require('./helpers-d381ec4d.js');
8const theme = require('./theme-30b7a575.js');
9
10const segmentIosCss = ":host{--ripple-color:currentColor;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;display:-ms-flexbox;display:flex;position:relative;-ms-flex-align:stretch;align-items:stretch;-ms-flex-pack:center;justify-content:center;width:100%;background:var(--background);font-family:var(--ion-font-family, inherit);text-align:center;contain:paint;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}:host(.segment-scrollable){-ms-flex-pack:start;justify-content:start;width:auto;overflow-x:auto}:host(.segment-scrollable::-webkit-scrollbar){display:none}:host{--background:rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.065);border-radius:8px;overflow:hidden;z-index:0}:host(.ion-color){background:rgba(var(--ion-color-base-rgb), 0.065)}:host(.in-toolbar){margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;width:auto}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){:host(.in-toolbar){margin-left:unset;margin-right:unset;-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto}}:host(.in-toolbar:not(.ion-color)){background:var(--ion-toolbar-segment-background, var(--background))}:host(.in-toolbar-color:not(.ion-color)){background:rgba(var(--ion-color-contrast-rgb), 0.11)}";
11
12const segmentMdCss = ":host{--ripple-color:currentColor;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;display:-ms-flexbox;display:flex;position:relative;-ms-flex-align:stretch;align-items:stretch;-ms-flex-pack:center;justify-content:center;width:100%;background:var(--background);font-family:var(--ion-font-family, inherit);text-align:center;contain:paint;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}:host(.segment-scrollable){-ms-flex-pack:start;justify-content:start;width:auto;overflow-x:auto}:host(.segment-scrollable::-webkit-scrollbar){display:none}:host{--background:transparent}:host(.segment-scrollable) ::slotted(ion-segment-button){min-width:auto}";
13
14const Segment = class {
15 constructor(hostRef) {
16 index.registerInstance(this, hostRef);
17 this.ionChange = index.createEvent(this, "ionChange", 7);
18 this.ionSelect = index.createEvent(this, "ionSelect", 7);
19 this.ionStyle = index.createEvent(this, "ionStyle", 7);
20 this.didInit = false;
21 this.activated = false;
22 /**
23 * If `true`, the user cannot interact with the segment.
24 */
25 this.disabled = false;
26 /**
27 * If `true`, the segment buttons will overflow and the user can swipe to see them.
28 * In addition, this will disable the gesture to drag the indicator between the buttons
29 * in order to swipe to see hidden buttons.
30 */
31 this.scrollable = false;
32 /**
33 * If `true`, users will be able to swipe between segment buttons to activate them.
34 */
35 this.swipeGesture = true;
36 this.onClick = (ev) => {
37 const current = ev.target;
38 const previous = this.checked;
39 // If the current element is a segment then that means
40 // the user tried to swipe to a segment button and
41 // click a segment button at the same time so we should
42 // not update the checked segment button
43 if (current.tagName === 'ION-SEGMENT') {
44 return;
45 }
46 this.value = current.value;
47 if (this.scrollable || !this.swipeGesture) {
48 if (previous) {
49 this.checkButton(previous, current);
50 }
51 else {
52 this.setCheckedClasses();
53 }
54 }
55 this.checked = current;
56 };
57 }
58 colorChanged(value, oldValue) {
59 /**
60 * If color is set after not having
61 * previously been set (or vice versa),
62 * we need to emit style so the segment-buttons
63 * can apply their color classes properly.
64 */
65 if ((oldValue === undefined && value !== undefined) ||
66 (oldValue !== undefined && value === undefined)) {
67 this.emitStyle();
68 }
69 }
70 swipeGestureChanged() {
71 this.gestureChanged();
72 }
73 valueChanged(value, oldValue) {
74 this.ionSelect.emit({ value });
75 if (oldValue !== '' || this.didInit) {
76 if (!this.activated) {
77 this.ionChange.emit({ value });
78 }
79 else {
80 this.valueAfterGesture = value;
81 }
82 }
83 }
84 disabledChanged() {
85 this.gestureChanged();
86 const buttons = this.getButtons();
87 for (const button of buttons) {
88 button.disabled = this.disabled;
89 }
90 }
91 gestureChanged() {
92 if (this.gesture) {
93 this.gesture.enable(!this.scrollable && !this.disabled && this.swipeGesture);
94 }
95 }
96 connectedCallback() {
97 this.emitStyle();
98 }
99 componentWillLoad() {
100 this.emitStyle();
101 }
102 async componentDidLoad() {
103 this.setCheckedClasses();
104 this.gesture = (await Promise.resolve().then(function () { return require('./index-a1dd5c93.js'); })).createGesture({
105 el: this.el,
106 gestureName: 'segment',
107 gesturePriority: 100,
108 threshold: 0,
109 passive: false,
110 onStart: ev => this.onStart(ev),
111 onMove: ev => this.onMove(ev),
112 onEnd: ev => this.onEnd(ev),
113 });
114 this.gestureChanged();
115 if (this.disabled) {
116 this.disabledChanged();
117 }
118 this.didInit = true;
119 }
120 onStart(detail) {
121 this.activate(detail);
122 }
123 onMove(detail) {
124 this.setNextIndex(detail);
125 }
126 onEnd(detail) {
127 this.setActivated(false);
128 const checkedValidButton = this.setNextIndex(detail, true);
129 detail.event.stopImmediatePropagation();
130 if (checkedValidButton) {
131 this.addRipple(detail);
132 }
133 const value = this.valueAfterGesture;
134 if (value !== undefined) {
135 this.ionChange.emit({ value });
136 this.valueAfterGesture = undefined;
137 }
138 }
139 getButtons() {
140 return Array.from(this.el.querySelectorAll('ion-segment-button'));
141 }
142 /**
143 * The gesture blocks the segment button ripple. This
144 * function adds the ripple based on the checked segment
145 * and where the cursor ended.
146 */
147 addRipple(detail) {
148 const useRippleEffect = ionicGlobal.config.getBoolean('animated', true) && ionicGlobal.config.getBoolean('rippleEffect', true);
149 if (!useRippleEffect) {
150 return;
151 }
152 const buttons = this.getButtons();
153 const checked = buttons.find(button => button.value === this.value);
154 const root = checked.shadowRoot || checked;
155 const ripple = root.querySelector('ion-ripple-effect');
156 if (!ripple) {
157 return;
158 }
159 const { x, y } = helpers.pointerCoord(detail.event);
160 ripple.addRipple(x, y).then(remove => remove());
161 }
162 /*
163 * Activate both the segment and the buttons
164 * due to a bug with ::slotted in Safari
165 */
166 setActivated(activated) {
167 const buttons = this.getButtons();
168 buttons.forEach(button => {
169 if (activated) {
170 button.classList.add('segment-button-activated');
171 }
172 else {
173 button.classList.remove('segment-button-activated');
174 }
175 });
176 this.activated = activated;
177 }
178 activate(detail) {
179 const clicked = detail.event.target;
180 const buttons = this.getButtons();
181 const checked = buttons.find(button => button.value === this.value);
182 // Make sure we are only checking for activation on a segment button
183 // since disabled buttons will get the click on the segment
184 if (clicked.tagName !== 'ION-SEGMENT-BUTTON') {
185 return;
186 }
187 // If there are no checked buttons, set the current button to checked
188 if (!checked) {
189 this.value = clicked.value;
190 this.setCheckedClasses();
191 }
192 // If the gesture began on the clicked button with the indicator
193 // then we should activate the indicator
194 if (this.value === clicked.value) {
195 this.setActivated(true);
196 }
197 }
198 getIndicator(button) {
199 const root = button.shadowRoot || button;
200 return root.querySelector('.segment-button-indicator');
201 }
202 checkButton(previous, current) {
203 const previousIndicator = this.getIndicator(previous);
204 const currentIndicator = this.getIndicator(current);
205 if (previousIndicator === null || currentIndicator === null) {
206 return;
207 }
208 const previousClientRect = previousIndicator.getBoundingClientRect();
209 const currentClientRect = currentIndicator.getBoundingClientRect();
210 const widthDelta = previousClientRect.width / currentClientRect.width;
211 const xPosition = previousClientRect.left - currentClientRect.left;
212 // Scale the indicator width to match the previous indicator width
213 // and translate it on top of the previous indicator
214 const transform = `translate3d(${xPosition}px, 0, 0) scaleX(${widthDelta})`;
215 index.writeTask(() => {
216 // Remove the transition before positioning on top of the previous indicator
217 currentIndicator.classList.remove('segment-button-indicator-animated');
218 currentIndicator.style.setProperty('transform', transform);
219 // Force a repaint to ensure the transform happens
220 currentIndicator.getBoundingClientRect();
221 // Add the transition to move the indicator into place
222 currentIndicator.classList.add('segment-button-indicator-animated');
223 // Remove the transform to slide the indicator back to the button clicked
224 currentIndicator.style.setProperty('transform', '');
225 });
226 this.value = current.value;
227 this.setCheckedClasses();
228 }
229 setCheckedClasses() {
230 const buttons = this.getButtons();
231 const index = buttons.findIndex(button => button.value === this.value);
232 const next = index + 1;
233 // Keep track of the currently checked button
234 this.checked = buttons.find(button => button.value === this.value);
235 for (const button of buttons) {
236 button.classList.remove('segment-button-after-checked');
237 }
238 if (next < buttons.length) {
239 buttons[next].classList.add('segment-button-after-checked');
240 }
241 }
242 setNextIndex(detail, isEnd = false) {
243 const isRTL = document.dir === 'rtl';
244 const activated = this.activated;
245 const buttons = this.getButtons();
246 const index = buttons.findIndex(button => button.value === this.value);
247 const previous = buttons[index];
248 let current;
249 let nextIndex;
250 if (index === -1) {
251 return;
252 }
253 // Get the element that the touch event started on in case
254 // it was the checked button, then we will move the indicator
255 const rect = previous.getBoundingClientRect();
256 const left = rect.left;
257 const width = rect.width;
258 // Get the element that the gesture is on top of based on the currentX of the
259 // gesture event and the Y coordinate of the starting element, since the gesture
260 // can move up and down off of the segment
261 const currentX = detail.currentX;
262 const previousY = rect.top + (rect.height / 2);
263 const nextEl = document.elementFromPoint(currentX, previousY);
264 const decreaseIndex = isRTL ? currentX > (left + width) : currentX < left;
265 const increaseIndex = isRTL ? currentX < left : currentX > (left + width);
266 // If the indicator is currently activated then we have started the gesture
267 // on top of the checked button so we need to slide the indicator
268 // by checking the button next to it as we move
269 if (activated && !isEnd) {
270 // Decrease index, move left in LTR & right in RTL
271 if (decreaseIndex) {
272 const newIndex = index - 1;
273 if (newIndex >= 0) {
274 nextIndex = newIndex;
275 }
276 // Increase index, moves right in LTR & left in RTL
277 }
278 else if (increaseIndex) {
279 if (activated && !isEnd) {
280 const newIndex = index + 1;
281 if (newIndex < buttons.length) {
282 nextIndex = newIndex;
283 }
284 }
285 }
286 if (nextIndex !== undefined && !buttons[nextIndex].disabled) {
287 current = buttons[nextIndex];
288 }
289 }
290 // If the indicator is not activated then we will just set the indicator
291 // to the element where the gesture ended
292 if (!activated && isEnd) {
293 current = nextEl;
294 }
295 /* tslint:disable-next-line */
296 if (current != null) {
297 /**
298 * If current element is ion-segment then that means
299 * user tried to select a disabled ion-segment-button,
300 * and we should not update the ripple.
301 */
302 if (current.tagName === 'ION-SEGMENT') {
303 return false;
304 }
305 if (previous !== current) {
306 this.checkButton(previous, current);
307 }
308 }
309 return true;
310 }
311 emitStyle() {
312 this.ionStyle.emit({
313 'segment': true
314 });
315 }
316 render() {
317 const mode = ionicGlobal.getIonMode(this);
318 return (index.h(index.Host, { role: "tablist", onClick: this.onClick, class: theme.createColorClasses(this.color, {
319 [mode]: true,
320 'in-toolbar': theme.hostContext('ion-toolbar', this.el),
321 'in-toolbar-color': theme.hostContext('ion-toolbar[color]', this.el),
322 'segment-activated': this.activated,
323 'segment-disabled': this.disabled,
324 'segment-scrollable': this.scrollable
325 }) }, index.h("slot", null)));
326 }
327 get el() { return index.getElement(this); }
328 static get watchers() { return {
329 "color": ["colorChanged"],
330 "swipeGesture": ["swipeGestureChanged"],
331 "value": ["valueChanged"],
332 "disabled": ["disabledChanged"]
333 }; }
334};
335Segment.style = {
336 ios: segmentIosCss,
337 md: segmentMdCss
338};
339
340const segmentButtonIosCss = ":host{--color:initial;--color-hover:var(--color);--color-checked:var(--color);--color-disabled:var(--color);--padding-start:0;--padding-end:0;--padding-top:0;--padding-bottom:0;border-radius:var(--border-radius);display:-ms-flexbox;display:flex;position:relative;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-direction:column;flex-direction:column;height:auto;background:var(--background);color:var(--color);text-decoration:none;text-overflow:ellipsis;white-space:nowrap;-webkit-font-kerning:none;font-kerning:none;cursor:pointer}.button-native{border-radius:0;font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit;margin-left:var(--margin-start);margin-right:var(--margin-end);margin-top:var(--margin-top);margin-bottom:var(--margin-bottom);padding-left:var(--padding-start);padding-right:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);display:-ms-flexbox;display:flex;position:relative;-ms-flex-direction:inherit;flex-direction:inherit;-ms-flex-positive:1;flex-grow:1;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:100%;min-width:inherit;max-width:inherit;height:auto;min-height:inherit;max-height:inherit;-webkit-transition:var(--transition);transition:var(--transition);border:none;outline:none;background:transparent;contain:content;pointer-events:none;overflow:hidden;z-index:2}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.button-native{margin-left:unset;margin-right:unset;-webkit-margin-start:var(--margin-start);margin-inline-start:var(--margin-start);-webkit-margin-end:var(--margin-end);margin-inline-end:var(--margin-end)}}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.button-native{padding-left:unset;padding-right:unset;-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end)}}.button-native::after{left:0;right:0;top:0;bottom:0;position:absolute;content:\"\";opacity:0}.button-inner{display:-ms-flexbox;display:flex;position:relative;-ms-flex-flow:inherit;flex-flow:inherit;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:100%;height:100%;z-index:1}:host(.segment-button-checked){background:var(--background-checked);color:var(--color-checked)}:host(.segment-button-disabled){cursor:default;pointer-events:none}:host(.ion-focused) .button-native{color:var(--color-focused)}:host(.ion-focused) .button-native::after{background:var(--background-focused);opacity:var(--background-focused-opacity)}:host(:focus){outline:none}@media (any-hover: hover){:host(:hover) .button-native{color:var(--color-hover)}:host(:hover) .button-native::after{background:var(--background-hover);opacity:var(--background-hover-opacity)}:host(.segment-button-checked:hover) .button-native{color:var(--color-checked)}}::slotted(ion-icon){-ms-flex-negative:0;flex-shrink:0;-ms-flex-order:-1;order:-1;pointer-events:none}::slotted(ion-label){display:block;-ms-flex-item-align:center;align-self:center;line-height:22px;text-overflow:ellipsis;white-space:nowrap;-webkit-box-sizing:border-box;box-sizing:border-box;pointer-events:none}:host(.segment-button-layout-icon-top) .button-native{-ms-flex-direction:column;flex-direction:column}:host(.segment-button-layout-icon-start) .button-native{-ms-flex-direction:row;flex-direction:row}:host(.segment-button-layout-icon-end) .button-native{-ms-flex-direction:row-reverse;flex-direction:row-reverse}:host(.segment-button-layout-icon-bottom) .button-native{-ms-flex-direction:column-reverse;flex-direction:column-reverse}:host(.segment-button-layout-icon-hide) ::slotted(ion-icon){display:none}:host(.segment-button-layout-label-hide) ::slotted(ion-label){display:none}ion-ripple-effect{color:var(--ripple-color, var(--color-checked))}.segment-button-indicator{-webkit-transform-origin:left;transform-origin:left;position:absolute;opacity:0;-webkit-box-sizing:border-box;box-sizing:border-box;will-change:transform, opacity;pointer-events:none}.segment-button-indicator-background{width:100%;height:var(--indicator-height);-webkit-transform:var(--indicator-transform);transform:var(--indicator-transform);-webkit-box-shadow:var(--indicator-box-shadow);box-shadow:var(--indicator-box-shadow);pointer-events:none}.segment-button-indicator-animated{-webkit-transition:var(--indicator-transition);transition:var(--indicator-transition)}:host(.segment-button-checked) .segment-button-indicator{opacity:1}@media (prefers-reduced-motion: reduce){.segment-button-indicator-background{-webkit-transform:none;transform:none}.segment-button-indicator-animated{-webkit-transition:none;transition:none}}:host{--background:none;--background-checked:none;--background-hover:none;--background-hover-opacity:0;--background-focused:none;--background-focused-opacity:0;--border-radius:7px;--border-width:1px;--border-color:rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.12);--border-style:solid;--indicator-box-shadow:0 0 5px rgba(0, 0, 0, 0.16);--indicator-color:var(--ion-color-step-350, var(--ion-background-color, #fff));--indicator-height:100%;--indicator-transition:transform 260ms cubic-bezier(0.4, 0, 0.2, 1);--indicator-transform:none;--transition:100ms all linear;--padding-top:0;--padding-end:13px;--padding-bottom:0;--padding-start:13px;margin-top:2px;margin-bottom:2px;position:relative;-ms-flex-preferred-size:0;flex-basis:0;-ms-flex-direction:row;flex-direction:row;min-width:70px;min-height:28px;-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);font-size:13px;font-weight:450;line-height:37px}:host::before{margin-left:0;margin-right:0;margin-top:5px;margin-bottom:5px;-webkit-transition:160ms opacity ease-in-out;transition:160ms opacity ease-in-out;-webkit-transition-delay:100ms;transition-delay:100ms;border-left:var(--border-width) var(--border-style) var(--border-color);content:\"\";opacity:1;will-change:opacity}:host(:first-of-type)::before{border-left-color:transparent}:host(.segment-button-disabled){opacity:0.3}::slotted(ion-icon){font-size:24px}:host(.segment-button-layout-icon-start) ::slotted(ion-label){margin-left:2px;margin-right:0}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){:host(.segment-button-layout-icon-start) ::slotted(ion-label){margin-left:unset;margin-right:unset;-webkit-margin-start:2px;margin-inline-start:2px;-webkit-margin-end:0;margin-inline-end:0}}:host(.segment-button-layout-icon-end) ::slotted(ion-label){margin-left:0;margin-right:2px}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){:host(.segment-button-layout-icon-end) ::slotted(ion-label){margin-left:unset;margin-right:unset;-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:2px;margin-inline-end:2px}}.segment-button-indicator{padding-left:2px;padding-right:2px;left:0;right:0;top:0;bottom:0}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.segment-button-indicator{padding-left:unset;padding-right:unset;-webkit-padding-start:2px;padding-inline-start:2px;-webkit-padding-end:2px;padding-inline-end:2px}}.segment-button-indicator-background{border-radius:var(--border-radius);background:var(--indicator-color)}.segment-button-indicator-background{-webkit-transition:var(--indicator-transition);transition:var(--indicator-transition)}:host(.segment-button-checked)::before,:host(.segment-button-after-checked)::before{opacity:0}:host(.segment-button-checked){z-index:-1}:host(.segment-button-activated){--indicator-transform:scale(0.95)}:host(.ion-focused) .button-native{opacity:0.7}@media (any-hover: hover){:host(:hover) .button-native{opacity:0.5}:host(.segment-button-checked:hover) .button-native{opacity:1}}:host(.in-segment-color){background:none;color:var(--ion-text-color, #000)}:host(.in-segment-color) .segment-button-indicator-background{background:var(--ion-color-step-350, var(--ion-background-color, #fff))}@media (any-hover: hover){:host(.in-segment-color:hover) .button-native,:host(.in-segment-color.segment-button-checked:hover) .button-native{color:var(--ion-text-color, #000)}}:host(.in-toolbar:not(.in-segment-color)){--background-checked:var(--ion-toolbar-segment-background-checked, none);--color:var(--ion-toolbar-segment-color, var(--ion-toolbar-color), initial);--color-checked:var(--ion-toolbar-segment-color-checked, var(--ion-toolbar-color), initial);--indicator-color:var(--ion-toolbar-segment-indicator-color, var(--ion-color-step-350, var(--ion-background-color, #fff)))}:host(.in-toolbar-color) .segment-button-indicator-background{background:#fff}:host(.in-toolbar-color:not(.in-segment-color)) .button-native{color:var(--ion-color-contrast)}:host(.in-toolbar-color.segment-button-checked:not(.in-segment-color)) .button-native{color:var(--ion-color-base)}@media (any-hover: hover){:host(.in-toolbar-color:not(.in-segment-color):hover) .button-native{color:var(--ion-color-contrast)}:host(.in-toolbar-color.segment-button-checked:not(.in-segment-color):hover) .button-native{color:var(--ion-color-base)}}";
341
342const segmentButtonMdCss = ":host{--color:initial;--color-hover:var(--color);--color-checked:var(--color);--color-disabled:var(--color);--padding-start:0;--padding-end:0;--padding-top:0;--padding-bottom:0;border-radius:var(--border-radius);display:-ms-flexbox;display:flex;position:relative;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-direction:column;flex-direction:column;height:auto;background:var(--background);color:var(--color);text-decoration:none;text-overflow:ellipsis;white-space:nowrap;-webkit-font-kerning:none;font-kerning:none;cursor:pointer}.button-native{border-radius:0;font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit;margin-left:var(--margin-start);margin-right:var(--margin-end);margin-top:var(--margin-top);margin-bottom:var(--margin-bottom);padding-left:var(--padding-start);padding-right:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);display:-ms-flexbox;display:flex;position:relative;-ms-flex-direction:inherit;flex-direction:inherit;-ms-flex-positive:1;flex-grow:1;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:100%;min-width:inherit;max-width:inherit;height:auto;min-height:inherit;max-height:inherit;-webkit-transition:var(--transition);transition:var(--transition);border:none;outline:none;background:transparent;contain:content;pointer-events:none;overflow:hidden;z-index:2}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.button-native{margin-left:unset;margin-right:unset;-webkit-margin-start:var(--margin-start);margin-inline-start:var(--margin-start);-webkit-margin-end:var(--margin-end);margin-inline-end:var(--margin-end)}}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.button-native{padding-left:unset;padding-right:unset;-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end)}}.button-native::after{left:0;right:0;top:0;bottom:0;position:absolute;content:\"\";opacity:0}.button-inner{display:-ms-flexbox;display:flex;position:relative;-ms-flex-flow:inherit;flex-flow:inherit;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:100%;height:100%;z-index:1}:host(.segment-button-checked){background:var(--background-checked);color:var(--color-checked)}:host(.segment-button-disabled){cursor:default;pointer-events:none}:host(.ion-focused) .button-native{color:var(--color-focused)}:host(.ion-focused) .button-native::after{background:var(--background-focused);opacity:var(--background-focused-opacity)}:host(:focus){outline:none}@media (any-hover: hover){:host(:hover) .button-native{color:var(--color-hover)}:host(:hover) .button-native::after{background:var(--background-hover);opacity:var(--background-hover-opacity)}:host(.segment-button-checked:hover) .button-native{color:var(--color-checked)}}::slotted(ion-icon){-ms-flex-negative:0;flex-shrink:0;-ms-flex-order:-1;order:-1;pointer-events:none}::slotted(ion-label){display:block;-ms-flex-item-align:center;align-self:center;line-height:22px;text-overflow:ellipsis;white-space:nowrap;-webkit-box-sizing:border-box;box-sizing:border-box;pointer-events:none}:host(.segment-button-layout-icon-top) .button-native{-ms-flex-direction:column;flex-direction:column}:host(.segment-button-layout-icon-start) .button-native{-ms-flex-direction:row;flex-direction:row}:host(.segment-button-layout-icon-end) .button-native{-ms-flex-direction:row-reverse;flex-direction:row-reverse}:host(.segment-button-layout-icon-bottom) .button-native{-ms-flex-direction:column-reverse;flex-direction:column-reverse}:host(.segment-button-layout-icon-hide) ::slotted(ion-icon){display:none}:host(.segment-button-layout-label-hide) ::slotted(ion-label){display:none}ion-ripple-effect{color:var(--ripple-color, var(--color-checked))}.segment-button-indicator{-webkit-transform-origin:left;transform-origin:left;position:absolute;opacity:0;-webkit-box-sizing:border-box;box-sizing:border-box;will-change:transform, opacity;pointer-events:none}.segment-button-indicator-background{width:100%;height:var(--indicator-height);-webkit-transform:var(--indicator-transform);transform:var(--indicator-transform);-webkit-box-shadow:var(--indicator-box-shadow);box-shadow:var(--indicator-box-shadow);pointer-events:none}.segment-button-indicator-animated{-webkit-transition:var(--indicator-transition);transition:var(--indicator-transition)}:host(.segment-button-checked) .segment-button-indicator{opacity:1}@media (prefers-reduced-motion: reduce){.segment-button-indicator-background{-webkit-transform:none;transform:none}.segment-button-indicator-animated{-webkit-transition:none;transition:none}}:host{--background:none;--background-checked:none;--background-hover:var(--color-checked);--background-focused:var(--color-checked);--background-activated-opacity:0;--background-focused-opacity:.12;--background-hover-opacity:.04;--color:rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.6);--color-checked:var(--ion-color-primary, #3880ff);--indicator-box-shadow:none;--indicator-color:var(--color-checked);--indicator-height:2px;--indicator-transition:transform 250ms cubic-bezier(0.4, 0, 0.2, 1);--indicator-transform:none;--padding-top:0;--padding-end:16px;--padding-bottom:0;--padding-start:16px;--transition:color 0.15s linear 0s, opacity 0.15s linear 0s;min-width:90px;max-width:360px;min-height:48px;border-width:var(--border-width);border-style:var(--border-style);border-color:var(--border-color);font-size:14px;font-weight:500;letter-spacing:0.06em;line-height:40px;text-transform:uppercase}:host(.segment-button-disabled){opacity:0.3}:host(.in-segment-color){background:none;color:rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.6)}:host(.in-segment-color) ion-ripple-effect{color:var(--ion-color-base)}:host(.in-segment-color) .segment-button-indicator-background{background:var(--ion-color-base)}:host(.in-segment-color.segment-button-checked) .button-native{color:var(--ion-color-base)}:host(.in-segment-color.ion-focused) .button-native::after{background:var(--ion-color-base)}@media (any-hover: hover){:host(.in-segment-color:hover) .button-native{color:rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.6)}:host(.in-segment-color:hover) .button-native::after{background:var(--ion-color-base)}:host(.in-segment-color.segment-button-checked:hover) .button-native{color:var(--ion-color-base)}}:host(.in-toolbar:not(.in-segment-color)){--background:var(--ion-toolbar-segment-background, none);--background-checked:var(--ion-toolbar-segment-background-checked, none);--color:var(--ion-toolbar-segment-color, rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.6));--color-checked:var(--ion-toolbar-segment-color-checked, var(--ion-color-primary, #3880ff));--indicator-color:var(--ion-toolbar-segment-color-checked, var(--color-checked))}:host(.in-toolbar-color:not(.in-segment-color)) .button-native{color:rgba(var(--ion-color-contrast-rgb), 0.6)}:host(.in-toolbar-color.segment-button-checked:not(.in-segment-color)) .button-native{color:var(--ion-color-contrast)}@media (any-hover: hover){:host(.in-toolbar-color:not(.in-segment-color)) .button-native::after{background:var(--ion-color-contrast)}}::slotted(ion-icon){margin-top:12px;margin-bottom:12px;font-size:24px}::slotted(ion-label){margin-top:12px;margin-bottom:12px}:host(.segment-button-layout-icon-top) ::slotted(ion-label),:host(.segment-button-layout-icon-bottom) ::slotted(ion-icon){margin-top:0}:host(.segment-button-layout-icon-top) ::slotted(ion-icon),:host(.segment-button-layout-icon-bottom) ::slotted(ion-label){margin-bottom:0}:host(.segment-button-layout-icon-start) ::slotted(ion-label){margin-left:8px;margin-right:0}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){:host(.segment-button-layout-icon-start) ::slotted(ion-label){margin-left:unset;margin-right:unset;-webkit-margin-start:8px;margin-inline-start:8px;-webkit-margin-end:0;margin-inline-end:0}}:host(.segment-button-layout-icon-end) ::slotted(ion-label){margin-left:0;margin-right:8px}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){:host(.segment-button-layout-icon-end) ::slotted(ion-label){margin-left:unset;margin-right:unset;-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:8px;margin-inline-end:8px}}:host(.segment-button-has-icon-only) ::slotted(ion-icon){margin-top:12px;margin-bottom:12px}:host(.segment-button-has-label-only) ::slotted(ion-label){margin-top:12px;margin-bottom:12px}.segment-button-indicator{left:0;right:0;bottom:0}.segment-button-indicator-background{background:var(--indicator-color)}:host(.in-toolbar:not(.in-segment-color)) .segment-button-indicator-background{background:var(--ion-toolbar-segment-indicator-color, var(--indicator-color))}:host(.in-toolbar-color:not(.in-segment-color)) .segment-button-indicator-background{background:var(--ion-color-contrast)}";
343
344let ids = 0;
345const SegmentButton = class {
346 constructor(hostRef) {
347 index.registerInstance(this, hostRef);
348 this.segmentEl = null;
349 this.checked = false;
350 /**
351 * If `true`, the user cannot interact with the segment button.
352 */
353 this.disabled = false;
354 /**
355 * Set the layout of the text and icon in the segment.
356 */
357 this.layout = 'icon-top';
358 /**
359 * The type of the button.
360 */
361 this.type = 'button';
362 /**
363 * The value of the segment button.
364 */
365 this.value = 'ion-sb-' + (ids++);
366 this.updateStyle = () => {
367 index.forceUpdate(this);
368 };
369 this.updateState = () => {
370 if (this.segmentEl) {
371 this.checked = this.segmentEl.value === this.value;
372 }
373 };
374 }
375 connectedCallback() {
376 const segmentEl = this.segmentEl = this.el.closest('ion-segment');
377 if (segmentEl) {
378 this.updateState();
379 helpers.addEventListener(segmentEl, 'ionSelect', this.updateState);
380 helpers.addEventListener(segmentEl, 'ionStyle', this.updateStyle);
381 }
382 }
383 disconnectedCallback() {
384 const segmentEl = this.segmentEl;
385 if (segmentEl) {
386 helpers.removeEventListener(segmentEl, 'ionSelect', this.updateState);
387 helpers.removeEventListener(segmentEl, 'ionStyle', this.updateStyle);
388 this.segmentEl = null;
389 }
390 }
391 get hasLabel() {
392 return !!this.el.querySelector('ion-label');
393 }
394 get hasIcon() {
395 return !!this.el.querySelector('ion-icon');
396 }
397 get tabIndex() {
398 if (this.disabled) {
399 return -1;
400 }
401 const hasTabIndex = this.el.hasAttribute('tabindex');
402 if (hasTabIndex) {
403 return this.el.getAttribute('tabindex');
404 }
405 return 0;
406 }
407 render() {
408 const { checked, type, disabled, hasIcon, hasLabel, layout, segmentEl, tabIndex } = this;
409 const mode = ionicGlobal.getIonMode(this);
410 const hasSegmentColor = () => segmentEl !== null && segmentEl.color !== undefined;
411 return (index.h(index.Host, { role: "tab", "aria-selected": checked ? 'true' : 'false', "aria-disabled": disabled ? 'true' : null, tabIndex: tabIndex, class: {
412 [mode]: true,
413 'in-toolbar': theme.hostContext('ion-toolbar', this.el),
414 'in-toolbar-color': theme.hostContext('ion-toolbar[color]', this.el),
415 'in-segment': theme.hostContext('ion-segment', this.el),
416 'in-segment-color': hasSegmentColor(),
417 'segment-button-has-label': hasLabel,
418 'segment-button-has-icon': hasIcon,
419 'segment-button-has-label-only': hasLabel && !hasIcon,
420 'segment-button-has-icon-only': hasIcon && !hasLabel,
421 'segment-button-disabled': disabled,
422 'segment-button-checked': checked,
423 [`segment-button-layout-${layout}`]: true,
424 'ion-activatable': true,
425 'ion-activatable-instant': true,
426 'ion-focusable': true,
427 } }, index.h("button", { type: type, tabIndex: -1, class: "button-native", part: "native", disabled: disabled }, index.h("span", { class: "button-inner" }, index.h("slot", null)), mode === 'md' && index.h("ion-ripple-effect", null)), index.h("div", { part: "indicator", class: {
428 'segment-button-indicator': true,
429 'segment-button-indicator-animated': true
430 } }, index.h("div", { part: "indicator-background", class: "segment-button-indicator-background" }))));
431 }
432 get el() { return index.getElement(this); }
433};
434SegmentButton.style = {
435 ios: segmentButtonIosCss,
436 md: segmentButtonMdCss
437};
438
439exports.ion_segment = Segment;
440exports.ion_segment_button = SegmentButton;