@gravitee/ui-components 3.25.3-typescript-50960c3 → 3.25.3-typescript-9d19b68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/package.json +5 -13
  2. package/src/atoms/gv-autocomplete.js +422 -1
  3. package/src/atoms/gv-button.js +397 -1
  4. package/src/atoms/gv-checkbox.js +178 -1
  5. package/src/atoms/gv-date-picker-calendar.js +812 -1
  6. package/src/atoms/gv-date-picker-cell.js +174 -1
  7. package/src/atoms/gv-date-picker.js +638 -1
  8. package/src/atoms/gv-file-upload.js +348 -1
  9. package/src/atoms/gv-icon.js +93 -1
  10. package/src/atoms/gv-image.js +135 -1
  11. package/src/atoms/gv-input-message.js +78 -1
  12. package/src/atoms/gv-input.js +508 -1
  13. package/src/atoms/gv-link.js +204 -1
  14. package/src/atoms/gv-message.js +133 -1
  15. package/src/atoms/gv-metric.js +112 -1
  16. package/src/atoms/gv-relative-time.js +143 -1
  17. package/src/atoms/gv-select-native.js +363 -1
  18. package/src/atoms/gv-select.js +413 -1
  19. package/src/atoms/gv-spinner.js +54 -1
  20. package/src/atoms/gv-state.js +125 -1
  21. package/src/atoms/gv-switch.js +235 -1
  22. package/src/atoms/gv-tag.js +162 -1
  23. package/src/atoms/gv-text.js +160 -1
  24. package/src/charts/gv-chart-bar.js +101 -1
  25. package/src/charts/gv-chart-gauge.js +92 -1
  26. package/src/charts/gv-chart-histogram.js +78 -1
  27. package/src/charts/gv-chart-line.js +218 -1
  28. package/src/charts/gv-chart-map.js +111 -1
  29. package/src/charts/gv-chart-pie.js +89 -1
  30. package/src/index.js +77 -1
  31. package/src/lib/cron-expression.js +176 -1
  32. package/src/lib/date.js +43 -1
  33. package/src/lib/events.js +26 -1
  34. package/src/lib/http-client-schema-form.js +67 -1
  35. package/src/lib/http.js +237 -1
  36. package/src/lib/i18n.js +93 -1
  37. package/src/lib/item.js +110 -1
  38. package/src/lib/properties.js +171 -1
  39. package/src/lib/schema-form.js +39 -1
  40. package/src/lib/studio.js +144 -1
  41. package/src/lib/style.js +39 -1
  42. package/src/lib/text-format.js +65 -1
  43. package/src/lib/theme.js +60 -1
  44. package/src/lib/utils.js +106 -1
  45. package/src/mixins/chart-element.js +153 -1
  46. package/src/mixins/input-element.js +136 -1
  47. package/src/mixins/item-resource.js +102 -1
  48. package/src/mixins/keyboard-element.js +62 -1
  49. package/src/mixins/update-after-browser.js +30 -1
  50. package/src/mixins/with-resize-observer.js +62 -1
  51. package/src/mixins/with-skeleton-attribute.js +109 -1
  52. package/src/molecules/gv-card-full.js +209 -1
  53. package/src/molecules/gv-card-list.js +101 -1
  54. package/src/molecules/gv-card.js +130 -1
  55. package/src/molecules/gv-category-list.js +56 -1
  56. package/src/molecules/gv-category.js +163 -1
  57. package/src/molecules/gv-code.js +334 -1
  58. package/src/molecules/gv-confirm.js +175 -1
  59. package/src/molecules/gv-cron-editor.js +685 -1
  60. package/src/molecules/gv-dropdown-menu.js +108 -1
  61. package/src/molecules/gv-expandable.js +116 -1
  62. package/src/molecules/gv-expression-language.js +263 -1
  63. package/src/molecules/gv-identity-picture.js +139 -1
  64. package/src/molecules/gv-list.js +214 -1
  65. package/src/molecules/gv-metrics.js +147 -1
  66. package/src/molecules/gv-modal.js +203 -1
  67. package/src/molecules/gv-nav.js +180 -1
  68. package/src/molecules/gv-option.js +230 -1
  69. package/src/molecules/gv-plans.js +400 -1
  70. package/src/molecules/gv-popover.js +323 -1
  71. package/src/molecules/gv-promote.js +203 -1
  72. package/src/molecules/gv-rating-list.js +341 -1
  73. package/src/molecules/gv-rating.js +234 -1
  74. package/src/molecules/gv-row-expandable.js +42 -1
  75. package/src/molecules/gv-row.js +205 -1
  76. package/src/molecules/gv-stats.js +110 -1
  77. package/src/molecules/gv-stepper.js +274 -1
  78. package/src/molecules/gv-table.js +644 -1
  79. package/src/molecules/gv-tree.js +238 -1
  80. package/src/organisms/gv-documentation.js +205 -1
  81. package/src/organisms/gv-header.js +276 -1
  82. package/src/organisms/gv-http-client.js +258 -1
  83. package/src/organisms/gv-menu.js +258 -1
  84. package/src/organisms/gv-newsletter-subscription.js +258 -1
  85. package/src/organisms/gv-pagination.js +179 -1
  86. package/src/organisms/gv-properties.js +860 -1
  87. package/src/organisms/gv-resizable-views.js +371 -1
  88. package/src/organisms/gv-resources.js +496 -1
  89. package/src/organisms/gv-schema-form-array.js +237 -1
  90. package/src/organisms/gv-schema-form-control-object.js +141 -1
  91. package/src/organisms/gv-schema-form-control.js +419 -1
  92. package/src/organisms/gv-schema-form.js +700 -1
  93. package/src/organisms/gv-tabs.js +201 -1
  94. package/src/organisms/gv-user-menu.js +298 -1
  95. package/src/organisms/gv-vertical-menu.js +119 -1
  96. package/src/policy-studio/gv-flow-step.js +443 -1
  97. package/src/policy-studio/gv-flow.js +595 -1
  98. package/src/policy-studio/gv-policy-studio-menu.js +689 -1
  99. package/src/policy-studio/gv-policy-studio.js +1712 -1
  100. package/src/styles/empty.js +35 -1
  101. package/src/styles/input.js +262 -1
  102. package/src/styles/link.js +31 -1
  103. package/src/styles/shapes.js +17 -1
  104. package/src/styles/skeleton.js +52 -1
  105. package/src/styles/zoom.js +39 -1
  106. package/src/theme/gv-theme.js +197 -1
  107. package/wc/gv-autocomplete.js +1 -1
  108. package/wc/gv-button.js +1 -1
  109. package/wc/gv-card-full.js +1 -1
  110. package/wc/gv-card-list.js +1 -1
  111. package/wc/gv-card.js +1 -1
  112. package/wc/gv-category-list.js +1 -1
  113. package/wc/gv-category.js +1 -1
  114. package/wc/gv-chart-bar.js +1 -1
  115. package/wc/gv-chart-gauge.js +1 -1
  116. package/wc/gv-chart-histogram.js +1 -1
  117. package/wc/gv-chart-line.js +1 -1
  118. package/wc/gv-chart-map.js +1 -1
  119. package/wc/gv-chart-pie.js +1 -1
  120. package/wc/gv-checkbox.js +1 -1
  121. package/wc/gv-code.js +1 -1
  122. package/wc/gv-confirm.js +1 -1
  123. package/wc/gv-cron-editor.js +1 -1
  124. package/wc/gv-date-picker-calendar.js +1 -1
  125. package/wc/gv-date-picker-cell.js +1 -1
  126. package/wc/gv-date-picker.js +1 -1
  127. package/wc/gv-documentation.js +1 -1
  128. package/wc/gv-dropdown-menu.js +1 -1
  129. package/wc/gv-expandable.js +1 -1
  130. package/wc/gv-expression-language.js +1 -1
  131. package/wc/gv-file-upload.js +1 -1
  132. package/wc/gv-flow-step.js +1 -1
  133. package/wc/gv-flow.js +1 -1
  134. package/wc/gv-header.js +1 -1
  135. package/wc/gv-http-client.js +1 -1
  136. package/wc/gv-icon.js +1 -1
  137. package/wc/gv-identity-picture.js +1 -1
  138. package/wc/gv-image.js +1 -1
  139. package/wc/gv-input-message.js +1 -1
  140. package/wc/gv-input.js +1 -1
  141. package/wc/gv-link.js +1 -1
  142. package/wc/gv-list.js +1 -1
  143. package/wc/gv-menu.js +1 -1
  144. package/wc/gv-message.js +1 -1
  145. package/wc/gv-metric.js +1 -1
  146. package/wc/gv-metrics.js +1 -1
  147. package/wc/gv-modal.js +1 -1
  148. package/wc/gv-nav.js +1 -1
  149. package/wc/gv-newsletter-subscription.js +1 -1
  150. package/wc/gv-option.js +1 -1
  151. package/wc/gv-pagination.js +1 -1
  152. package/wc/gv-plans.js +1 -1
  153. package/wc/gv-policy-studio-menu.js +1 -1
  154. package/wc/gv-policy-studio.js +1 -1
  155. package/wc/gv-popover.js +1 -1
  156. package/wc/gv-promote.js +1 -1
  157. package/wc/gv-properties.js +1 -1
  158. package/wc/gv-rating-list.js +1 -1
  159. package/wc/gv-rating.js +1 -1
  160. package/wc/gv-relative-time.js +1 -1
  161. package/wc/gv-resizable-views.js +1 -1
  162. package/wc/gv-resources.js +1 -1
  163. package/wc/gv-row-expandable.js +1 -1
  164. package/wc/gv-row.js +1 -1
  165. package/wc/gv-schema-form-array.js +1 -1
  166. package/wc/gv-schema-form-control-object.js +1 -1
  167. package/wc/gv-schema-form-control.js +1 -1
  168. package/wc/gv-schema-form.js +1 -1
  169. package/wc/gv-select-native.js +1 -1
  170. package/wc/gv-select.js +1 -1
  171. package/wc/gv-spinner.js +1 -1
  172. package/wc/gv-state.js +1 -1
  173. package/wc/gv-stats.js +1 -1
  174. package/wc/gv-stepper.js +1 -1
  175. package/wc/gv-switch.js +1 -1
  176. package/wc/gv-table.js +1 -1
  177. package/wc/gv-tabs.js +1 -1
  178. package/wc/gv-tag.js +1 -1
  179. package/wc/gv-text.js +1 -1
  180. package/wc/gv-theme.js +1 -1
  181. package/wc/gv-tree.js +1 -1
  182. package/wc/gv-user-menu.js +1 -1
  183. package/wc/gv-vertical-menu.js +1 -1
@@ -1 +1,363 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvSelectNative=void 0;const e=require("lit/directives/class-map"),t=require("lit/directives/if-defined"),i=require("lit/directives/repeat"),l=require("lit"),s=require("../styles/skeleton"),n=require("../styles/link"),a=require("../styles/input"),r=require("../lib/events"),o=require("../mixins/input-element"),c=require("../lib/i18n");class p extends((0,o.InputElement)(l.LitElement)){static get properties(){return{...super.properties,options:{type:Array},_options:{type:Array,attribute:!1},large:{type:Boolean},medium:{type:Boolean},small:{type:Boolean},value:{type:String|Array},label:{type:String},title:{type:String},name:{type:String},placeholder:{type:String},description:{type:String},multiple:{type:Boolean,reflect:!0}}}static get styles(){return[...super.styles,s.skeleton,a.input,n.link,l.css`.box{--bdc:var(--gv-select--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));--c:var(--gv-select--c, var(--gv-theme-font-color-dark, #262626));--bgc:var(--gv-select--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));--bgc-list:var(--gv-select--list-bgc, var(--gv-select--bgc, var(--gv-theme-neutral-color-lightest, #ffffff)));--hover-bgc:var(--gv-select-hover--bgc, var(--gv-theme-color-light, #86c3d0));--selected-bgc:var(--gv-select-selected--bgc, var(--gv-theme-neutral-color-light, #efefef));position:relative;color:var(--c)}:host([readonly]) div,:host([readonly]) input,:host([readonly]) input:read-only:hover{user-select:auto;cursor:text}input:read-only:hover{cursor:pointer}label{color:var(--c)}.multiple .input,select{background-image:linear-gradient(45deg,transparent 50%,var(--c) 50%),linear-gradient(135deg,var(--c) 50%,transparent 50%),linear-gradient(to right,#ccc,#ccc);background-position:calc(100% - 17px) calc(1em + 2px),calc(100% - 12px) calc(1em + 2px),calc(100% - 2.5em) .5em;background-size:5px 5px,5px 5px,1px 1.5em;background-repeat:no-repeat;-webkit-appearance:none;appearance:none;background-color:var(--bgc)}.multiple .input{padding-right:35px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.multiple gv-icon{display:none}.multiple.not-empty :not(.show) .input{background-image:none,linear-gradient(155deg,var(--c) 0,transparent 0),linear-gradient(to right,#ccc,#ccc)}.multiple.not-empty gv-icon{display:block}.small .multiple .input{padding-right:30px}.small select,.small.multiple .input{background-position:calc(100% - 16px) calc(.8em),calc(100% - 11px) calc(.8em),calc(100% - 2.5em) .5em;background-size:5px 5px,5px 5px,1px 1em}.multiple select{opacity:0;position:absolute;left:0;top:0;max-height:var(--input-medium--h)}.multiple .show{min-height:75px}.multiple .show select{opacity:1;z-index:1000;max-height:300px}gv-icon{--gv-icon--s:19px}.medium gv-icon{--gv-icon--s:14px}.small gv-icon{--gv-icon--s:11px}`]}constructor(){super(),this._options=[{label:"",value:"",disabled:!1,title:null}]}getInputElement(){return this.shadowRoot.querySelector("select")}async firstUpdated(e){super.firstUpdated(e),await new Promise((e=>setTimeout(e,0)));const t=this.getInputElement();t&&(t.addEventListener("input",this._onInput.bind(this)),this.multiple&&(t.addEventListener("mousedown",this._onEnter.bind(this)),t.addEventListener("focus",this._onEnter.bind(this)),t.addEventListener("mouseleave",this._onLeave.bind(this)),t.addEventListener("blur",this._onLeave.bind(this))))}willUpdate(e){e.has("value")&&this.updateState(this.value)}updateState(e){if(super.updateState(e),e&&this._options&&this.valid){if(this.multiple){if(this.required&&this.setValidity(0===e.length,"field is required"),e.length>0&&this.valid){const t=this._options.map((e=>e.value));this.setValidity(!e.some((e=>t.includes(e))),"value is not included in the possible values")}}else this.setValidity(this.required&&null==this._options.find((t=>t.value===e)),"value is not included in the possible values");this.invalid=!this.valid}}_onEnter(e){const t=this.getInputElement();t.parentNode.classList.contains("show")||(e.stopPropagation(),e.preventDefault(),t.parentNode.classList.add("show"))}_onLeave(){this.getInputElement().parentNode.classList.remove("show")}_onInput(e){if(e.stopPropagation(),this.multiple){const e=this.getInputElement().querySelectorAll("option:checked");this.value=Array.from(e).map((e=>e.value))}else this.value=e.target.value;this.updateState(this.value),(0,r.dispatchCustomEvent)(this,"select",this.value),(0,r.dispatchCustomEvent)(this,"input",this.value),this.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0}))}_onClear(){Array.from(this.getInputElement().querySelectorAll("option:checked")).forEach((e=>e.removeAttribute("checked"))),this.value=[],(0,r.dispatchCustomEvent)(this,"select",this.value),(0,r.dispatchCustomEvent)(this,"input",this.value),this.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0}))}set options(e){e&&(this._options=e.map((e=>"object"!=typeof e?{value:e,label:e}:e.label?e:{value:e.value,label:e.value})))}selectedLabel(){if(null!=this.value){const e=this._options.filter((e=>this.isSelected(e)));if(e)return e.map((e=>e.label)).join(", ")}return""}renderSelect(){const e=this.selectedLabel();if(this.readonly)return l.html`<input id="${this._id}" type="text" .name="${(0,t.ifDefined)(this.name)}" .title="${(0,t.ifDefined)(e||this.title||this.label)}" .required="${this.required}" aria-required="${!!this.required}" .placeholder="${(0,t.ifDefined)(this.placeholder)}" .value="${e}" readonly="readonly">`;if(this.multiple){const s=this._options?this._options.length*(this.small?20:25):50;return l.html`<input class="input" type="text" .name="${(0,t.ifDefined)(this.name)}" .title="${(0,t.ifDefined)(e||this.title||this.label)}" .required="${this.required}" aria-required="${!!this.required}" .placeholder="${(0,t.ifDefined)(this.placeholder)}" .value="${e}" readonly="readonly"> <select class="input" id="${this._id}" .name="${(0,t.ifDefined)(this.name)}" .title="${(0,t.ifDefined)(e||this.title||this.label)}" .required="${this.required}" aria-required="${!!this.required}" ?disabled="${this.disabled||this.skeleton}" .placeholder="${(0,t.ifDefined)(this.placeholder)}" multiple="multiple" .size="${this._options.length}" style="height:${s}">${this._options&&(0,i.repeat)(this._options,(e=>e),(e=>l.html`<option value="${e.value||""}" ?selected="${this.isSelected(e)}">${e.label}</option>`))}</select><div class="box-icon box-icon-clear"><gv-icon class="link" shape="code:error" title="${(0,c.i18n)("gv-input.clear")}" @click="${this._onClear}"></gv-icon></div>`}return l.html`<select class="input" id="${this._id}" .name="${(0,t.ifDefined)(this.name)}" .title="${(0,t.ifDefined)(e||this.title||this.label)}" .required="${this.required}" aria-required="${!!this.required}" ?disabled="${this.disabled||this.skeleton}" .placeholder="${(0,t.ifDefined)(this.placeholder)}">${this._options&&(0,i.repeat)(this._options,(e=>e),(e=>l.html`<option value="${e.value||""}" ?selected="${this.isSelected(e)}">${e.label}</option>`))}</select>`}render(){const t={box:!0,large:this.large,medium:this.medium||!this.large&&!this.small,small:this.small,skeleton:this.skeleton,required:this.required,multiple:this.multiple,"not-empty":this._options&&this.multiple&&this.value&&this.value.length>0};return l.html`<div class="${(0,e.classMap)(t)}"><div class="box-input">${this.renderLabel()} ${this.renderSelect()}</div></div>${null!=this.description?l.html`<div class="description" .innerHTML="${this.description}"></div>`:""}`}isSelected(e){return this.multiple?this.value&&this.value.includes(e.value):""+this.value==""+e.value}}exports.GvSelectNative=p,window.customElements.define("gv-select-native",p);
1
+ /*
2
+ * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { classMap } from 'lit/directives/class-map';
17
+ import { ifDefined } from 'lit/directives/if-defined';
18
+ import { repeat } from 'lit/directives/repeat';
19
+ import { css, html, LitElement } from 'lit';
20
+ import { skeleton } from '../styles/skeleton';
21
+ import { link } from '../styles/link';
22
+ import { input } from '../styles/input';
23
+ import { dispatchCustomEvent } from '../lib/events';
24
+ import { InputElement } from '../mixins/input-element';
25
+ import { i18n } from '../lib/i18n';
26
+ /**
27
+ * A select native component.
28
+ *
29
+ * @fires gv-select:select - Event when user select a value (deprecated, use gv-select:input)
30
+ * @fires gv-select:input - Event when user select a value
31
+ *
32
+ * @attr {Boolean} disabled - same as native select element `disabled` attribute
33
+ * @attr {Boolean} required - same as native select element `required` attribute
34
+ * @attr {Boolean} skeleton - enable skeleton screen UI pattern (loading hint)
35
+ * @attr {Array} options - the options of the select
36
+ * @attr {String | Array} value - the value of the select
37
+ * @attr {String} label - label of the select
38
+ * @attr {String} title - title of the select
39
+ * @attr {String} name - name of the select
40
+ * @attr {String} placeholder - an example value to display in the select when empty
41
+ * @attr {String} description - a description
42
+ * @attr {Boolean} multiple - enable multiple selection
43
+ *
44
+ * @cssprop {Color} [--gv-select--bgc=var(--gv-theme-neutral-color-lightest, #ffffff)] - Background color
45
+ * @cssprop {Color} [--gv-select--bdc=var(--gv-theme-neutral-color-dark, #d9d9d9)] - Border color
46
+ * @cssprop {Color} [--gv-select--c=var(--gv-theme-font-color-dark, #262626)] - Color
47
+ * @cssprop {Color} [--gv-select-hover--bgc=var(--gv-theme-color-light, #86c3d0)] - Hover background color
48
+ * @cssprop {Color} [--gv-select-selected--bgc=var(--gv-theme-neutral-color-light, #efefef)] - Selected background color
49
+ */
50
+ export class GvSelectNative extends InputElement(LitElement) {
51
+ static get properties() {
52
+ return {
53
+ ...super.properties,
54
+ options: { type: Array },
55
+ _options: { type: Array, attribute: false },
56
+ large: { type: Boolean },
57
+ medium: { type: Boolean },
58
+ small: { type: Boolean },
59
+ value: { type: String | Array },
60
+ label: { type: String },
61
+ title: { type: String },
62
+ name: { type: String },
63
+ placeholder: { type: String },
64
+ description: { type: String },
65
+ multiple: { type: Boolean, reflect: true },
66
+ };
67
+ }
68
+ static get styles() {
69
+ return [
70
+ ...super.styles,
71
+ skeleton,
72
+ input,
73
+ link,
74
+ // language=CSS
75
+ css `
76
+ .box {
77
+ --bdc: var(--gv-select--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));
78
+ --c: var(--gv-select--c, var(--gv-theme-font-color-dark, #262626));
79
+ --bgc: var(--gv-select--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));
80
+ --bgc-list: var(--gv-select--list-bgc, var(--gv-select--bgc, var(--gv-theme-neutral-color-lightest, #ffffff)));
81
+ --hover-bgc: var(--gv-select-hover--bgc, var(--gv-theme-color-light, #86c3d0));
82
+ --selected-bgc: var(--gv-select-selected--bgc, var(--gv-theme-neutral-color-light, #efefef));
83
+ position: relative;
84
+ color: var(--c);
85
+ }
86
+
87
+ :host([readonly]) div,
88
+ :host([readonly]) input,
89
+ :host([readonly]) input:read-only:hover {
90
+ user-select: auto;
91
+ cursor: text;
92
+ }
93
+
94
+ input:read-only:hover {
95
+ cursor: pointer;
96
+ }
97
+
98
+ label {
99
+ color: var(--c);
100
+ }
101
+
102
+ select,
103
+ .multiple .input {
104
+ background-image: linear-gradient(45deg, transparent 50%, var(--c) 50%), linear-gradient(135deg, var(--c) 50%, transparent 50%),
105
+ linear-gradient(to right, #ccc, #ccc);
106
+ background-position: calc(100% - 17px) calc(1em + 2px), calc(100% - 12px) calc(1em + 2px), calc(100% - 2.5em) 0.5em;
107
+ background-size: 5px 5px, 5px 5px, 1px 1.5em;
108
+ background-repeat: no-repeat;
109
+ -webkit-appearance: none;
110
+ appearance: none;
111
+ background-color: var(--bgc);
112
+ }
113
+
114
+ .multiple .input {
115
+ padding-right: 35px;
116
+ text-overflow: ellipsis;
117
+ white-space: nowrap;
118
+ overflow: hidden;
119
+ }
120
+
121
+ .multiple gv-icon {
122
+ display: none;
123
+ }
124
+
125
+ .multiple.not-empty :not(.show) .input {
126
+ background-image: none, linear-gradient(155deg, var(--c) 0%, transparent 0%), linear-gradient(to right, #ccc, #ccc);
127
+ }
128
+ .multiple.not-empty gv-icon {
129
+ display: block;
130
+ }
131
+
132
+ .small .multiple .input {
133
+ padding-right: 30px;
134
+ }
135
+
136
+ .small select,
137
+ .small.multiple .input {
138
+ background-position: calc(100% - 16px) calc(0.8em), calc(100% - 11px) calc(0.8em), calc(100% - 2.5em) 0.5em;
139
+ background-size: 5px 5px, 5px 5px, 1px 1em;
140
+ }
141
+
142
+ .multiple select {
143
+ opacity: 0;
144
+ position: absolute;
145
+ left: 0;
146
+ top: 0;
147
+ max-height: var(--input-medium--h);
148
+ }
149
+
150
+ .multiple .show {
151
+ min-height: 75px;
152
+ }
153
+
154
+ .multiple .show select {
155
+ opacity: 1;
156
+ z-index: 1000;
157
+ max-height: 300px;
158
+ }
159
+
160
+ gv-icon {
161
+ --gv-icon--s: 19px;
162
+ }
163
+
164
+ .medium gv-icon {
165
+ --gv-icon--s: 14px;
166
+ }
167
+
168
+ .small gv-icon {
169
+ --gv-icon--s: 11px;
170
+ }
171
+ `,
172
+ ];
173
+ }
174
+ constructor() {
175
+ super();
176
+ this._options = [{ label: '', value: '', disabled: false, title: null }];
177
+ }
178
+ getInputElement() {
179
+ return this.shadowRoot.querySelector('select');
180
+ }
181
+ async firstUpdated(changedProperties) {
182
+ super.firstUpdated(changedProperties);
183
+ // Give the browser a chance to paint
184
+ await new Promise((resolve) => setTimeout(resolve, 0));
185
+ const input = this.getInputElement();
186
+ if (input) {
187
+ input.addEventListener('input', this._onInput.bind(this));
188
+ if (this.multiple) {
189
+ input.addEventListener('mousedown', this._onEnter.bind(this));
190
+ input.addEventListener('focus', this._onEnter.bind(this));
191
+ input.addEventListener('mouseleave', this._onLeave.bind(this));
192
+ input.addEventListener('blur', this._onLeave.bind(this));
193
+ }
194
+ }
195
+ }
196
+ willUpdate(changedProperties) {
197
+ if (changedProperties.has('value')) {
198
+ this.updateState(this.value);
199
+ }
200
+ }
201
+ updateState(value) {
202
+ super.updateState(value);
203
+ if (value && this._options && this.valid) {
204
+ if (this.multiple) {
205
+ if (this.required) {
206
+ this.setValidity(value.length === 0, 'field is required');
207
+ }
208
+ if (value.length > 0 && this.valid) {
209
+ const possibleValues = this._options.map((o) => o.value);
210
+ this.setValidity(!value.some((v) => possibleValues.includes(v)), 'value is not included in the possible values');
211
+ }
212
+ }
213
+ else {
214
+ this.setValidity(this.required && this._options.find((option) => option.value === value) == null, 'value is not included in the possible values');
215
+ }
216
+ this.invalid = !this.valid;
217
+ }
218
+ }
219
+ _onEnter(e) {
220
+ const input = this.getInputElement();
221
+ if (!input.parentNode.classList.contains('show')) {
222
+ e.stopPropagation();
223
+ e.preventDefault();
224
+ input.parentNode.classList.add('show');
225
+ }
226
+ }
227
+ _onLeave() {
228
+ this.getInputElement().parentNode.classList.remove('show');
229
+ }
230
+ _onInput(e) {
231
+ e.stopPropagation();
232
+ if (this.multiple) {
233
+ const options = this.getInputElement().querySelectorAll('option:checked');
234
+ this.value = Array.from(options).map((o) => o.value);
235
+ }
236
+ else {
237
+ this.value = e.target.value;
238
+ }
239
+ this.updateState(this.value);
240
+ dispatchCustomEvent(this, 'select', this.value);
241
+ dispatchCustomEvent(this, 'input', this.value);
242
+ this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
243
+ }
244
+ _onClear() {
245
+ Array.from(this.getInputElement().querySelectorAll('option:checked')).forEach((option) => option.removeAttribute('checked'));
246
+ this.value = [];
247
+ dispatchCustomEvent(this, 'select', this.value);
248
+ dispatchCustomEvent(this, 'input', this.value);
249
+ this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
250
+ }
251
+ set options(options) {
252
+ if (options) {
253
+ this._options = options.map((option) => {
254
+ if (typeof option !== 'object') {
255
+ return { value: option, label: option };
256
+ }
257
+ else if (!option.label) {
258
+ return { value: option.value, label: option.value };
259
+ }
260
+ return option;
261
+ });
262
+ }
263
+ }
264
+ selectedLabel() {
265
+ if (this.value != null) {
266
+ const elements = this._options.filter((o) => this.isSelected(o));
267
+ if (elements) {
268
+ return elements.map((e) => e.label).join(', ');
269
+ }
270
+ }
271
+ return '';
272
+ }
273
+ renderSelect() {
274
+ const selectedLabel = this.selectedLabel();
275
+ if (this.readonly) {
276
+ return html `
277
+ <input
278
+ id=${this._id}
279
+ type="text"
280
+ .name=${ifDefined(this.name)}
281
+ .title=${ifDefined(selectedLabel || this.title || this.label)}
282
+ .required=${this.required}
283
+ aria-required=${!!this.required}
284
+ .placeholder=${ifDefined(this.placeholder)}
285
+ .value=${selectedLabel}
286
+ readonly="readonly"
287
+ />
288
+ `;
289
+ }
290
+ else if (this.multiple) {
291
+ const height = this._options ? this._options.length * (this.small ? 20 : 25) : 50;
292
+ return html `
293
+ <input
294
+ class="input"
295
+ type="text"
296
+ .name=${ifDefined(this.name)}
297
+ .title=${ifDefined(selectedLabel || this.title || this.label)}
298
+ .required=${this.required}
299
+ aria-required=${!!this.required}
300
+ .placeholder=${ifDefined(this.placeholder)}
301
+ .value=${selectedLabel}
302
+ readonly="readonly"
303
+ />
304
+ <select
305
+ class="input"
306
+ id=${this._id}
307
+ .name=${ifDefined(this.name)}
308
+ .title=${ifDefined(selectedLabel || this.title || this.label)}
309
+ .required=${this.required}
310
+ aria-required=${!!this.required}
311
+ ?disabled=${this.disabled || this.skeleton}
312
+ .placeholder=${ifDefined(this.placeholder)}
313
+ multiple
314
+ .size="${this._options.length}"
315
+ style="height: ${height}px"
316
+ >
317
+ ${this._options &&
318
+ repeat(this._options, (option) => option, (option) => html ` <option value="${option.value || ''}" ?selected="${this.isSelected(option)}">${option.label}</option> `)}
319
+ </select>
320
+ <div class="box-icon box-icon-clear">
321
+ <gv-icon class="link" shape="code:error" title="${i18n('gv-input.clear')}" @click="${this._onClear}"></gv-icon>
322
+ </div>
323
+ `;
324
+ }
325
+ else {
326
+ return html `<select
327
+ class="input"
328
+ id=${this._id}
329
+ .name=${ifDefined(this.name)}
330
+ .title=${ifDefined(selectedLabel || this.title || this.label)}
331
+ .required=${this.required}
332
+ aria-required=${!!this.required}
333
+ ?disabled=${this.disabled || this.skeleton}
334
+ .placeholder=${ifDefined(this.placeholder)}
335
+ >
336
+ ${this._options &&
337
+ repeat(this._options, (option) => option, (option) => html ` <option value="${option.value || ''}" ?selected="${this.isSelected(option)}">${option.label}</option>`)}
338
+ </select>`;
339
+ }
340
+ }
341
+ render() {
342
+ const classes = {
343
+ box: true,
344
+ large: this.large,
345
+ medium: this.medium || (!this.large && !this.small),
346
+ small: this.small,
347
+ skeleton: this.skeleton,
348
+ required: this.required,
349
+ multiple: this.multiple,
350
+ 'not-empty': this._options && this.multiple && this.value && this.value.length > 0,
351
+ };
352
+ return html `
353
+ <div class="${classMap(classes)}">
354
+ <div class="box-input">${this.renderLabel()} ${this.renderSelect()}</div>
355
+ </div>
356
+ ${this.description != null ? html `<div class="description" .innerHTML="${this.description}"></div>` : ''}
357
+ `;
358
+ }
359
+ isSelected(option) {
360
+ return this.multiple ? this.value && this.value.includes(option.value) : '' + this.value === '' + option.value;
361
+ }
362
+ }
363
+ window.customElements.define('gv-select-native', GvSelectNative);