UNPKG

7.41 kBJavaScriptView Raw
1/*!
2 * (C) Ionic http://ionicframework.com - MIT License
3 */
4import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
5import { b as getIonMode } from './ionic-global.js';
6import { s as safeCall } from './overlays.js';
7import { g as getClassMap } from './theme.js';
8import { d as defineCustomElement$a } from './checkbox.js';
9import { d as defineCustomElement$9 } from './icon.js';
10import { d as defineCustomElement$8 } from './item.js';
11import { d as defineCustomElement$7 } from './label.js';
12import { d as defineCustomElement$6 } from './list.js';
13import { d as defineCustomElement$5 } from './list-header.js';
14import { d as defineCustomElement$4 } from './note.js';
15import { d as defineCustomElement$3 } from './radio.js';
16import { d as defineCustomElement$2 } from './radio-group.js';
17import { d as defineCustomElement$1 } from './ripple-effect.js';
18
19const selectPopoverIosCss = ".sc-ion-select-popover-ios-h ion-list.sc-ion-select-popover-ios{margin-left:0;margin-right:0;margin-top:0;margin-bottom:0}ion-list-header.sc-ion-select-popover-ios,ion-label.sc-ion-select-popover-ios{margin-left:0;margin-right:0;margin-top:0;margin-bottom:0}";
20
21const selectPopoverMdCss = ".sc-ion-select-popover-md-h ion-list.sc-ion-select-popover-md{margin-left:0;margin-right:0;margin-top:0;margin-bottom:0}ion-list-header.sc-ion-select-popover-md,ion-label.sc-ion-select-popover-md{margin-left:0;margin-right:0;margin-top:0;margin-bottom:0}ion-list.sc-ion-select-popover-md ion-radio.sc-ion-select-popover-md{opacity:0}ion-item.sc-ion-select-popover-md{--inner-border-width:0}.item-radio-checked.sc-ion-select-popover-md{--background:rgba(var(--ion-color-primary-rgb, 56, 128, 255), 0.08);--background-focused:var(--ion-color-primary, #3880ff);--background-focused-opacity:0.2;--background-hover:var(--ion-color-primary, #3880ff);--background-hover-opacity:0.12}.item-checkbox-checked.sc-ion-select-popover-md{--background-activated:var(--ion-item-color, var(--ion-text-color, #000));--background-focused:var(--ion-item-color, var(--ion-text-color, #000));--background-hover:var(--ion-item-color, var(--ion-text-color, #000));--color:var(--ion-color-primary, #3880ff)}";
22
23const SelectPopover = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
24 constructor() {
25 super();
26 this.__registerHost();
27 /**
28 * An array of options for the popover
29 */
30 this.options = [];
31 }
32 onSelect(ev) {
33 this.setChecked(ev);
34 this.callOptionHandler(ev);
35 }
36 findOptionFromEvent(ev) {
37 const { options } = this;
38 return options.find(o => o.value === ev.target.value);
39 }
40 /**
41 * When an option is selected we need to get the value(s)
42 * of the selected option(s) and return it in the option
43 * handler
44 */
45 callOptionHandler(ev) {
46 const option = this.findOptionFromEvent(ev);
47 const values = this.getValues(ev);
48 if (option && option.handler) {
49 safeCall(option.handler, values);
50 }
51 }
52 /**
53 * This is required when selecting a radio that is already
54 * selected because it will not trigger the ionChange event
55 * but we still want to close the popover
56 */
57 rbClick(ev) {
58 this.callOptionHandler(ev);
59 }
60 setChecked(ev) {
61 const { multiple } = this;
62 const option = this.findOptionFromEvent(ev);
63 // this is a popover with checkboxes (multiple value select)
64 // we need to set the checked value for this option
65 if (multiple && option) {
66 option.checked = ev.detail.checked;
67 }
68 }
69 getValues(ev) {
70 const { multiple, options } = this;
71 if (multiple) {
72 // this is a popover with checkboxes (multiple value select)
73 // return an array of all the checked values
74 return options.filter(o => o.checked).map(o => o.value);
75 }
76 // this is a popover with radio buttons (single value select)
77 // return the value that was clicked, otherwise undefined
78 const option = this.findOptionFromEvent(ev);
79 return option ? option.value : undefined;
80 }
81 renderOptions(options) {
82 const { multiple } = this;
83 switch (multiple) {
84 case true: return this.renderCheckboxOptions(options);
85 default: return this.renderRadioOptions(options);
86 }
87 }
88 renderCheckboxOptions(options) {
89 return (options.map(option => h("ion-item", { class: getClassMap(option.cssClass) }, h("ion-checkbox", { slot: "start", value: option.value, disabled: option.disabled, checked: option.checked }), h("ion-label", null, option.text))));
90 }
91 renderRadioOptions(options) {
92 const checked = options.filter(o => o.checked).map(o => o.value)[0];
93 return (h("ion-radio-group", { value: checked }, options.map(option => h("ion-item", { class: getClassMap(option.cssClass) }, h("ion-label", null, option.text), h("ion-radio", { value: option.value, disabled: option.disabled, onClick: ev => this.rbClick(ev) })))));
94 }
95 render() {
96 const { header, message, options, subHeader } = this;
97 const hasSubHeaderOrMessage = subHeader !== undefined || message !== undefined;
98 return (h(Host, { class: getIonMode(this) }, h("ion-list", null, header !== undefined && h("ion-list-header", null, header), hasSubHeaderOrMessage &&
99 h("ion-item", null, h("ion-label", { class: "ion-text-wrap" }, subHeader !== undefined && h("h3", null, subHeader), message !== undefined && h("p", null, message))), this.renderOptions(options))));
100 }
101 static get style() { return {
102 ios: selectPopoverIosCss,
103 md: selectPopoverMdCss
104 }; }
105}, [34, "ion-select-popover", {
106 "header": [1],
107 "subHeader": [1, "sub-header"],
108 "message": [1],
109 "multiple": [4],
110 "options": [16]
111 }, [[0, "ionChange", "onSelect"]]]);
112function defineCustomElement() {
113 if (typeof customElements === "undefined") {
114 return;
115 }
116 const components = ["ion-select-popover", "ion-checkbox", "ion-icon", "ion-item", "ion-label", "ion-list", "ion-list-header", "ion-note", "ion-radio", "ion-radio-group", "ion-ripple-effect"];
117 components.forEach(tagName => { switch (tagName) {
118 case "ion-select-popover":
119 if (!customElements.get(tagName)) {
120 customElements.define(tagName, SelectPopover);
121 }
122 break;
123 case "ion-checkbox":
124 if (!customElements.get(tagName)) {
125 defineCustomElement$a();
126 }
127 break;
128 case "ion-icon":
129 if (!customElements.get(tagName)) {
130 defineCustomElement$9();
131 }
132 break;
133 case "ion-item":
134 if (!customElements.get(tagName)) {
135 defineCustomElement$8();
136 }
137 break;
138 case "ion-label":
139 if (!customElements.get(tagName)) {
140 defineCustomElement$7();
141 }
142 break;
143 case "ion-list":
144 if (!customElements.get(tagName)) {
145 defineCustomElement$6();
146 }
147 break;
148 case "ion-list-header":
149 if (!customElements.get(tagName)) {
150 defineCustomElement$5();
151 }
152 break;
153 case "ion-note":
154 if (!customElements.get(tagName)) {
155 defineCustomElement$4();
156 }
157 break;
158 case "ion-radio":
159 if (!customElements.get(tagName)) {
160 defineCustomElement$3();
161 }
162 break;
163 case "ion-radio-group":
164 if (!customElements.get(tagName)) {
165 defineCustomElement$2();
166 }
167 break;
168 case "ion-ripple-effect":
169 if (!customElements.get(tagName)) {
170 defineCustomElement$1();
171 }
172 break;
173 } });
174}
175
176export { SelectPopover as S, defineCustomElement as d };