@gravitee/ui-components 3.25.3-typescript-ad6021f → 3.25.3-typescript-bfd8f67
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/package.json +5 -8
- package/src/atoms/gv-autocomplete.js +1 -461
- package/src/atoms/gv-button.js +1 -410
- package/src/atoms/gv-checkbox.js +1 -187
- package/src/atoms/gv-date-picker-calendar.js +1 -894
- package/src/atoms/gv-date-picker-cell.js +1 -190
- package/src/atoms/gv-date-picker.js +1 -671
- package/src/atoms/gv-file-upload.js +1 -367
- package/src/atoms/gv-icon.js +1 -103
- package/src/atoms/gv-image.js +1 -144
- package/src/atoms/gv-input-message.js +1 -84
- package/src/atoms/gv-input.js +1 -561
- package/src/atoms/gv-link.js +1 -210
- package/src/atoms/gv-message.js +1 -128
- package/src/atoms/gv-metric.js +1 -117
- package/src/atoms/gv-relative-time.js +1 -156
- package/src/atoms/gv-select-native.js +1 -388
- package/src/atoms/gv-select.js +1 -437
- package/src/atoms/gv-spinner.js +1 -57
- package/src/atoms/gv-state.js +1 -130
- package/src/atoms/gv-switch.js +1 -243
- package/src/atoms/gv-tag.js +1 -168
- package/src/atoms/gv-text.js +1 -168
- package/src/charts/gv-chart-bar.js +1 -103
- package/src/charts/gv-chart-gauge.js +1 -100
- package/src/charts/gv-chart-histogram.js +1 -83
- package/src/charts/gv-chart-line.js +1 -224
- package/src/charts/gv-chart-map.js +1 -112
- package/src/charts/gv-chart-pie.js +1 -91
- package/src/index.js +1 -77
- package/src/lib/cron-expression.js +1 -205
- package/src/lib/date.js +1 -44
- package/src/lib/events.js +1 -26
- package/src/lib/http-client-schema-form.js +1 -67
- package/src/lib/http.js +1 -237
- package/src/lib/i18n.js +1 -103
- package/src/lib/item.js +1 -118
- package/src/lib/properties.js +1 -189
- package/src/lib/schema-form.js +1 -44
- package/src/lib/studio.js +1 -141
- package/src/lib/style.js +1 -41
- package/src/lib/text-format.js +1 -69
- package/src/lib/theme.js +1 -63
- package/src/lib/utils.js +1 -111
- package/src/mixins/chart-element.js +1 -165
- package/src/mixins/input-element.js +1 -144
- package/src/mixins/item-resource.js +1 -120
- package/src/mixins/keyboard-element.js +1 -69
- package/src/mixins/update-after-browser.js +1 -30
- package/src/mixins/with-resize-observer.js +1 -68
- package/src/mixins/with-skeleton-attribute.js +1 -112
- package/src/molecules/gv-card-full.js +1 -218
- package/src/molecules/gv-card-list.js +1 -113
- package/src/molecules/gv-card.js +1 -133
- package/src/molecules/gv-category-list.js +1 -60
- package/src/molecules/gv-category.js +1 -170
- package/src/molecules/gv-code.js +1 -359
- package/src/molecules/gv-confirm.js +1 -188
- package/src/molecules/gv-cron-editor.js +1 -710
- package/src/molecules/gv-dropdown-menu.js +1 -116
- package/src/molecules/gv-expandable.js +1 -122
- package/src/molecules/gv-expression-language.js +1 -270
- package/src/molecules/gv-identity-picture.js +1 -148
- package/src/molecules/gv-list.js +1 -227
- package/src/molecules/gv-metrics.js +1 -162
- package/src/molecules/gv-modal.js +1 -213
- package/src/molecules/gv-nav.js +1 -196
- package/src/molecules/gv-option.js +1 -242
- package/src/molecules/gv-plans.js +1 -429
- package/src/molecules/gv-popover.js +1 -351
- package/src/molecules/gv-promote.js +1 -209
- package/src/molecules/gv-rating-list.js +1 -365
- package/src/molecules/gv-rating.js +1 -253
- package/src/molecules/gv-row-expandable.js +1 -45
- package/src/molecules/gv-row.js +1 -210
- package/src/molecules/gv-stats.js +1 -121
- package/src/molecules/gv-stepper.js +1 -288
- package/src/molecules/gv-table.js +1 -685
- package/src/molecules/gv-tree.js +1 -250
- package/src/organisms/gv-documentation.js +1 -215
- package/src/organisms/gv-header.js +1 -288
- package/src/organisms/gv-http-client.js +1 -275
- package/src/organisms/gv-menu.js +1 -263
- package/src/organisms/gv-newsletter-subscription.js +1 -271
- package/src/organisms/gv-pagination.js +1 -198
- package/src/organisms/gv-properties.js +1 -920
- package/src/organisms/gv-resizable-views.js +1 -396
- package/src/organisms/gv-resources.js +1 -535
- package/src/organisms/gv-schema-form-array.js +1 -250
- package/src/organisms/gv-schema-form-control-object.js +1 -154
- package/src/organisms/gv-schema-form-control.js +1 -443
- package/src/organisms/gv-schema-form.js +1 -751
- package/src/organisms/gv-tabs.js +1 -210
- package/src/organisms/gv-user-menu.js +1 -314
- package/src/organisms/gv-vertical-menu.js +1 -123
- package/src/policy-studio/gv-flow-step.js +1 -464
- package/src/policy-studio/gv-flow.js +1 -621
- package/src/policy-studio/gv-policy-studio-menu.js +1 -750
- package/src/policy-studio/gv-policy-studio.js +1 -1842
- package/src/styles/empty.js +1 -36
- package/src/styles/input.js +1 -263
- package/src/styles/link.js +1 -32
- package/src/styles/shapes.js +1 -17
- package/src/styles/skeleton.js +1 -53
- package/src/styles/zoom.js +1 -40
- package/src/theme/gv-theme.js +1 -203
- package/wc/gv-autocomplete.js +1 -1
- package/wc/gv-button.js +1 -1
- package/wc/gv-card-full.js +1 -1
- package/wc/gv-card-list.js +1 -1
- package/wc/gv-card.js +1 -1
- package/wc/gv-category-list.js +1 -1
- package/wc/gv-category.js +1 -1
- package/wc/gv-chart-bar.js +1 -1
- package/wc/gv-chart-gauge.js +1 -1
- package/wc/gv-chart-histogram.js +1 -1
- package/wc/gv-chart-line.js +1 -1
- package/wc/gv-chart-map.js +1 -1
- package/wc/gv-chart-pie.js +1 -1
- package/wc/gv-checkbox.js +1 -1
- package/wc/gv-code.js +1 -1
- package/wc/gv-confirm.js +1 -1
- package/wc/gv-cron-editor.js +1 -1
- package/wc/gv-date-picker-calendar.js +1 -1
- package/wc/gv-date-picker-cell.js +1 -1
- package/wc/gv-date-picker.js +1 -1
- package/wc/gv-documentation.js +1 -1
- package/wc/gv-dropdown-menu.js +1 -1
- package/wc/gv-expandable.js +1 -1
- package/wc/gv-expression-language.js +1 -1
- package/wc/gv-file-upload.js +1 -1
- package/wc/gv-flow-step.js +1 -1
- package/wc/gv-flow.js +1 -1
- package/wc/gv-header.js +1 -1
- package/wc/gv-http-client.js +1 -1
- package/wc/gv-icon.js +1 -1
- package/wc/gv-identity-picture.js +1 -1
- package/wc/gv-image.js +1 -1
- package/wc/gv-input-message.js +1 -1
- package/wc/gv-input.js +1 -1
- package/wc/gv-link.js +1 -1
- package/wc/gv-list.js +1 -1
- package/wc/gv-menu.js +1 -1
- package/wc/gv-message.js +1 -1
- package/wc/gv-metric.js +1 -1
- package/wc/gv-metrics.js +1 -1
- package/wc/gv-modal.js +1 -1
- package/wc/gv-nav.js +1 -1
- package/wc/gv-newsletter-subscription.js +1 -1
- package/wc/gv-option.js +1 -1
- package/wc/gv-pagination.js +1 -1
- package/wc/gv-plans.js +1 -1
- package/wc/gv-policy-studio-menu.js +1 -1
- package/wc/gv-policy-studio.js +1 -1
- package/wc/gv-popover.js +1 -1
- package/wc/gv-promote.js +1 -1
- package/wc/gv-properties.js +1 -1
- package/wc/gv-rating-list.js +1 -1
- package/wc/gv-rating.js +1 -1
- package/wc/gv-relative-time.js +1 -1
- package/wc/gv-resizable-views.js +1 -1
- package/wc/gv-resources.js +1 -1
- package/wc/gv-row-expandable.js +1 -1
- package/wc/gv-row.js +1 -1
- package/wc/gv-schema-form-array.js +1 -1
- package/wc/gv-schema-form-control-object.js +1 -1
- package/wc/gv-schema-form-control.js +1 -1
- package/wc/gv-schema-form.js +1 -1
- package/wc/gv-select-native.js +1 -1
- package/wc/gv-select.js +1 -1
- package/wc/gv-spinner.js +1 -1
- package/wc/gv-state.js +1 -1
- package/wc/gv-stats.js +1 -1
- package/wc/gv-stepper.js +1 -1
- package/wc/gv-switch.js +1 -1
- package/wc/gv-table.js +1 -1
- package/wc/gv-tabs.js +1 -1
- package/wc/gv-tag.js +1 -1
- package/wc/gv-text.js +1 -1
- package/wc/gv-theme.js +1 -1
- package/wc/gv-tree.js +1 -1
- package/wc/gv-user-menu.js +1 -1
- package/wc/gv-vertical-menu.js +1 -1
- package/CHANGELOG.md +0 -1292
- package/LICENSE.txt +0 -202
- package/README.md +0 -195
- package/src/.eslintrc.js +0 -19
- package/src/theme/definition.json +0 -1762
package/src/molecules/gv-nav.js
CHANGED
|
@@ -1,196 +1 @@
|
|
|
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 { LitElement, html, css } from 'lit';
|
|
17
|
-
import { repeat } from 'lit/directives/repeat';
|
|
18
|
-
import '../atoms/gv-link';
|
|
19
|
-
import { until } from 'lit/directives/until';
|
|
20
|
-
import { isSameRoutes } from '../lib/utils';
|
|
21
|
-
import { dispatchCustomEvent } from '../lib/events';
|
|
22
|
-
import { classMap } from 'lit/directives/class-map';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A main nav
|
|
26
|
-
*
|
|
27
|
-
* ## Details
|
|
28
|
-
* * has @theme facet
|
|
29
|
-
*
|
|
30
|
-
* @fires gv-nav:click - Custom event when nav item is clicked
|
|
31
|
-
*
|
|
32
|
-
* @attr {Array<{active: Boolean, icon: String, path: String, title: Promise<String>, target: String}>} routes - definition of routes
|
|
33
|
-
*/
|
|
34
|
-
export class GvNav extends LitElement {
|
|
35
|
-
static get properties() {
|
|
36
|
-
return {
|
|
37
|
-
routes: { type: Array },
|
|
38
|
-
_routes: { type: Array },
|
|
39
|
-
small: { type: Boolean },
|
|
40
|
-
_compact: { type: Boolean, attribute: false },
|
|
41
|
-
vertical: { type: Boolean, reflect: true },
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static get styles() {
|
|
46
|
-
return [
|
|
47
|
-
// language=CSS
|
|
48
|
-
css`
|
|
49
|
-
nav {
|
|
50
|
-
position: relative;
|
|
51
|
-
transition: all 150ms ease-in-out;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
gv-link {
|
|
55
|
-
--gv-link--ta: end;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.vertical {
|
|
59
|
-
display: flex;
|
|
60
|
-
flex-direction: column;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.vertical gv-link {
|
|
64
|
-
width: 100%;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.compact {
|
|
68
|
-
--gv-link-a--ph: 10px;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
#shadowLink {
|
|
72
|
-
position: absolute;
|
|
73
|
-
display: inline-flex;
|
|
74
|
-
opacity: 0.5;
|
|
75
|
-
top: 0;
|
|
76
|
-
left: 0;
|
|
77
|
-
transition: transform 250ms ease-in-out, width 250ms;
|
|
78
|
-
}
|
|
79
|
-
`,
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_onClick(event) {
|
|
84
|
-
event.stopPropagation();
|
|
85
|
-
const { detail } = event;
|
|
86
|
-
const { title, target } = detail;
|
|
87
|
-
if (target === '_blank') {
|
|
88
|
-
dispatchCustomEvent(this, 'click', detail);
|
|
89
|
-
} else {
|
|
90
|
-
if (!this._isLocked) {
|
|
91
|
-
this._isLocked = true;
|
|
92
|
-
let nextIndex = 0;
|
|
93
|
-
this._routes.forEach((route, index) => {
|
|
94
|
-
if (route.title === title) {
|
|
95
|
-
route.active = true;
|
|
96
|
-
nextIndex = index;
|
|
97
|
-
} else {
|
|
98
|
-
delete route.active;
|
|
99
|
-
}
|
|
100
|
-
return route;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const activeLink = this.shadowRoot.querySelector('gv-link[active]');
|
|
104
|
-
const nextLink = this.shadowRoot.querySelectorAll('gv-link')[nextIndex];
|
|
105
|
-
if (activeLink) {
|
|
106
|
-
const shadowLink = activeLink.cloneNode(true);
|
|
107
|
-
const { height, width } = activeLink.getBoundingClientRect();
|
|
108
|
-
|
|
109
|
-
shadowLink.id = 'shadowLink';
|
|
110
|
-
shadowLink.style.top = `${activeLink.offsetTop}px`;
|
|
111
|
-
shadowLink.style.left = `${activeLink.offsetLeft}px`;
|
|
112
|
-
shadowLink.style.width = `${width}px`;
|
|
113
|
-
shadowLink.style.height = `${height}px`;
|
|
114
|
-
|
|
115
|
-
activeLink.removeAttribute('active');
|
|
116
|
-
activeLink.style.height = `${height}px`;
|
|
117
|
-
|
|
118
|
-
this.shadowRoot.querySelector('nav').prepend(shadowLink);
|
|
119
|
-
const left = nextLink.offsetLeft - activeLink.offsetLeft;
|
|
120
|
-
const top = nextLink.offsetTop - activeLink.offsetTop;
|
|
121
|
-
|
|
122
|
-
shadowLink.style.transform = `translate(${left}px,${top}px)`;
|
|
123
|
-
|
|
124
|
-
setTimeout(() => {
|
|
125
|
-
nextLink.setAttribute('active', true);
|
|
126
|
-
this.shadowRoot.querySelector('nav').removeChild(shadowLink);
|
|
127
|
-
this._isLocked = false;
|
|
128
|
-
dispatchCustomEvent(this, 'click', detail);
|
|
129
|
-
}, 250);
|
|
130
|
-
} else {
|
|
131
|
-
nextLink.setAttribute('active', true);
|
|
132
|
-
this._isLocked = false;
|
|
133
|
-
dispatchCustomEvent(this, 'click', detail);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
constructor() {
|
|
140
|
-
super();
|
|
141
|
-
/** @protected */
|
|
142
|
-
this._routes = [];
|
|
143
|
-
this.vertical = false;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
set routes(routes) {
|
|
147
|
-
if (routes) {
|
|
148
|
-
Promise.resolve(routes).then((_routes) => {
|
|
149
|
-
if (!isSameRoutes(this._routes, _routes)) {
|
|
150
|
-
this._routes = _routes;
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
_getLink(route, index) {
|
|
157
|
-
return Promise.resolve(route)
|
|
158
|
-
.then((_route) => {
|
|
159
|
-
return html` <gv-link
|
|
160
|
-
@gv-link:click=${this._onClick}
|
|
161
|
-
.active="${_route.active}"
|
|
162
|
-
.icon="${_route.icon}"
|
|
163
|
-
.path="${_route.path}"
|
|
164
|
-
.target="${_route.target}"
|
|
165
|
-
?small="${this.small}"
|
|
166
|
-
.title="${_route.title}"
|
|
167
|
-
.help="${until(_route.help, null)}"
|
|
168
|
-
?vertical="${this.vertical}"
|
|
169
|
-
></gv-link>`;
|
|
170
|
-
})
|
|
171
|
-
.catch(() => {
|
|
172
|
-
delete this._routes[index];
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
updated(_changedProperties) {
|
|
177
|
-
if (_changedProperties.has('_routes')) {
|
|
178
|
-
this._compact = this._routes && this._routes.length > 5;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
render() {
|
|
183
|
-
if (this._routes) {
|
|
184
|
-
return html`<nav class="${classMap({ compact: this._compact, vertical: this.vertical })}">
|
|
185
|
-
${repeat(
|
|
186
|
-
this._routes,
|
|
187
|
-
(route) => route,
|
|
188
|
-
(route, index) => until(this._getLink(route, index), html`<gv-link skeleton .vertical="${this.vertical}"></gv-link>`),
|
|
189
|
-
)}
|
|
190
|
-
</nav>`;
|
|
191
|
-
}
|
|
192
|
-
return html``;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
window.customElements.define('gv-nav', GvNav);
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvNav=void 0;const t=require("lit"),e=require("lit/directives/repeat");require("../atoms/gv-link");const i=require("lit/directives/until"),s=require("../lib/utils"),o=require("../lib/events"),l=require("lit/directives/class-map");class r extends t.LitElement{static get properties(){return{routes:{type:Array},_routes:{type:Array},small:{type:Boolean},_compact:{type:Boolean,attribute:!1},vertical:{type:Boolean,reflect:!0}}}static get styles(){return[t.css`nav{position:relative;transition:all 150ms ease-in-out}gv-link{--gv-link--ta:end}.vertical{display:flex;flex-direction:column}.vertical gv-link{width:100%}.compact{--gv-link-a--ph:10px}#shadowLink{position:absolute;display:inline-flex;opacity:.5;top:0;left:0;transition:transform 250ms ease-in-out,width 250ms}`]}_onClick(t){t.stopPropagation();const{detail:e}=t,{title:i,target:s}=e;if("_blank"===s)(0,o.dispatchCustomEvent)(this,"click",e);else if(!this._isLocked){this._isLocked=!0;let t=0;this._routes.forEach(((e,s)=>(e.title===i?(e.active=!0,t=s):delete e.active,e)));const s=this.shadowRoot.querySelector("gv-link[active]"),l=this.shadowRoot.querySelectorAll("gv-link")[t];if(s){const t=s.cloneNode(!0),{height:i,width:r}=s.getBoundingClientRect();t.id="shadowLink",t.style.top=`${s.offsetTop}px`,t.style.left=`${s.offsetLeft}px`,t.style.width=`${r}px`,t.style.height=`${i}px`,s.removeAttribute("active"),s.style.height=`${i}px`,this.shadowRoot.querySelector("nav").prepend(t);const a=l.offsetLeft-s.offsetLeft,n=l.offsetTop-s.offsetTop;t.style.transform=`translate(${a}px,${n}px)`,setTimeout((()=>{l.setAttribute("active",!0),this.shadowRoot.querySelector("nav").removeChild(t),this._isLocked=!1,(0,o.dispatchCustomEvent)(this,"click",e)}),250)}else l.setAttribute("active",!0),this._isLocked=!1,(0,o.dispatchCustomEvent)(this,"click",e)}}constructor(){super(),this._routes=[],this.vertical=!1}set routes(t){t&&Promise.resolve(t).then((t=>{(0,s.isSameRoutes)(this._routes,t)||(this._routes=t)}))}_getLink(e,s){return Promise.resolve(e).then((e=>t.html`<gv-link @gv-link:click="${this._onClick}" .active="${e.active}" .icon="${e.icon}" .path="${e.path}" .target="${e.target}" ?small="${this.small}" .title="${e.title}" .help="${(0,i.until)(e.help,null)}" ?vertical="${this.vertical}"></gv-link>`)).catch((()=>{delete this._routes[s]}))}updated(t){t.has("_routes")&&(this._compact=this._routes&&this._routes.length>5)}render(){return this._routes?t.html`<nav class="${(0,l.classMap)({compact:this._compact,vertical:this.vertical})}">${(0,e.repeat)(this._routes,(t=>t),((e,s)=>(0,i.until)(this._getLink(e,s),t.html`<gv-link skeleton .vertical="${this.vertical}"></gv-link>`)))}</nav>`:t.html``}}exports.GvNav=r,window.customElements.define("gv-nav",r);
|
|
@@ -1,242 +1 @@
|
|
|
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 { css, LitElement, html } from 'lit';
|
|
17
|
-
import '../atoms/gv-button';
|
|
18
|
-
import { repeat } from 'lit/directives/repeat';
|
|
19
|
-
import { classMap } from 'lit/directives/class-map';
|
|
20
|
-
import { dispatchCustomEvent } from '../lib/events';
|
|
21
|
-
import { ifDefined } from 'lit/directives/if-defined';
|
|
22
|
-
import { styleMap } from 'lit/directives/style-map';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Option component
|
|
26
|
-
*
|
|
27
|
-
* ## Details
|
|
28
|
-
* * has @theme facet
|
|
29
|
-
*
|
|
30
|
-
* @attr {Array<{id, title, icon?, active?, description?, label?}>} options - An array of options.
|
|
31
|
-
* @attr {String|Array} value - Selected value id, array with multiple option ids.
|
|
32
|
-
* @attr {Boolean} multiple - If true, can choose several option
|
|
33
|
-
* @attr {Boolean} reverse - If true, title and description are reversed.
|
|
34
|
-
* @attr {Boolean} small - If true, use small button for options
|
|
35
|
-
* @attr {Boolean} outlined - If true, use outlined button for options
|
|
36
|
-
*
|
|
37
|
-
* @cssprop {Color} [--gv-option--bgc=var(--gv-theme-neutral-color-dark, #bfbfbf)] - Background color
|
|
38
|
-
* @cssprop {Length} [--gv-option--bdrs=0.15rem] - Border radius
|
|
39
|
-
* @cssprop {Length} [--gv-option-button--maw=200px] - Button max width
|
|
40
|
-
* @cssprop {Length} [--gv-option-icon--s=64px] - Icon size
|
|
41
|
-
*/
|
|
42
|
-
export class GvOption extends LitElement {
|
|
43
|
-
static get properties() {
|
|
44
|
-
return {
|
|
45
|
-
options: { type: Array },
|
|
46
|
-
_options: { type: Array, attribute: false },
|
|
47
|
-
_hasDescription: { type: Array, attribute: false },
|
|
48
|
-
value: { type: String, reflect: true },
|
|
49
|
-
multiple: { type: Boolean },
|
|
50
|
-
reverse: { type: Boolean },
|
|
51
|
-
small: { type: Boolean },
|
|
52
|
-
outlined: { type: Boolean },
|
|
53
|
-
disabled: { type: Boolean, reflect: true },
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static get styles() {
|
|
58
|
-
return [
|
|
59
|
-
// language=CSS
|
|
60
|
-
css`
|
|
61
|
-
:host {
|
|
62
|
-
box-sizing: border-box;
|
|
63
|
-
display: inline-block;
|
|
64
|
-
--gv-button--p: 5px;
|
|
65
|
-
margin: 0.2rem;
|
|
66
|
-
--bdrs: var(--gv-option--bdrs, 0.15rem);
|
|
67
|
-
--maw: var(--gv-option-button--maw, 200px);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
.box.description {
|
|
71
|
-
display: grid;
|
|
72
|
-
grid-gap: 0.5rem;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
gv-button {
|
|
76
|
-
margin: 0;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
gv-button.description {
|
|
80
|
-
flex: 1 1 var(--maw);
|
|
81
|
-
max-width: var(--maw);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
gv-button:not(.description) {
|
|
85
|
-
margin: 0;
|
|
86
|
-
--gv-button--bdrs: 0;
|
|
87
|
-
--gv-button--bgc: var(--gv-option--bgc, var(--gv-theme-neutral-color-dark, #bfbfbf));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
gv-button:not(.description).entry {
|
|
91
|
-
--gv-button--bdrs: var(--bdrs) 0 0 var(--bdrs);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
gv-button:not(.description).exit {
|
|
95
|
-
--gv-button--bdrs: 0 var(--bdrs) var(--bdrs) 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.content {
|
|
99
|
-
white-space: pre-line;
|
|
100
|
-
--gv-icon--s: var(--gv-option-icon--s, 64px);
|
|
101
|
-
display: flex;
|
|
102
|
-
flex-direction: column;
|
|
103
|
-
align-items: center;
|
|
104
|
-
height: 100%;
|
|
105
|
-
text-transform: none;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
gv-image {
|
|
109
|
-
height: 64px;
|
|
110
|
-
width: 64px;
|
|
111
|
-
--gv-image--of: fill;
|
|
112
|
-
display: inline-flex;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.reverse .content {
|
|
116
|
-
flex-direction: column-reverse;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
.title {
|
|
120
|
-
font-size: var(--gv-theme-font-size-l, 18px);
|
|
121
|
-
font-weight: bold;
|
|
122
|
-
margin: 0.5rem 0;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
gv-button.description {
|
|
126
|
-
margin: 0.5rem;
|
|
127
|
-
}
|
|
128
|
-
`,
|
|
129
|
-
];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
constructor() {
|
|
133
|
-
super();
|
|
134
|
-
this.multiple = false;
|
|
135
|
-
this.reverse = false;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
_onClick(option) {
|
|
139
|
-
this.setValue(option);
|
|
140
|
-
dispatchCustomEvent(this, 'select', option);
|
|
141
|
-
this.dispatchEvent(new Event('input'), { bubbles: true, cancelable: true });
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async performUpdate() {
|
|
145
|
-
this.shadowRoot.querySelectorAll('gv-button').forEach((btn) => btn.performUpdate());
|
|
146
|
-
return super.performUpdate();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
setValue(option) {
|
|
150
|
-
if (option) {
|
|
151
|
-
if (this.multiple) {
|
|
152
|
-
if (this.value.includes(option.id)) {
|
|
153
|
-
this.value = this.value.filter((optId) => {
|
|
154
|
-
return optId !== option.id;
|
|
155
|
-
});
|
|
156
|
-
} else {
|
|
157
|
-
this.value = [...this.value, option.id];
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
this.value = option.id;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
set options(options) {
|
|
166
|
-
if (options) {
|
|
167
|
-
Promise.all(options).then((_options) => {
|
|
168
|
-
this._options = _options;
|
|
169
|
-
this._hasDescription = this._options.find((opt) => opt.description != null) != null;
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
isActive(option) {
|
|
175
|
-
if (this.value) {
|
|
176
|
-
if (this.multiple) {
|
|
177
|
-
return this.value.includes(option.id);
|
|
178
|
-
} else {
|
|
179
|
-
return this.value === option.id;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
_renderOption(option, index) {
|
|
186
|
-
const isActive = this.isActive(option);
|
|
187
|
-
const outlined = this.outlined || (!isActive && this._hasDescription);
|
|
188
|
-
return html`<gv-button
|
|
189
|
-
.icon=${ifDefined(!this._hasDescription ? option.icon : null)}
|
|
190
|
-
.iconRight=${ifDefined(!option.icon && option.iconRight ? option.iconRight : null)}
|
|
191
|
-
.title="${ifDefined(option.title)}"
|
|
192
|
-
.primary="${isActive}"
|
|
193
|
-
.small="${this.small}"
|
|
194
|
-
.disabled="${option.disabled || this.disabled}"
|
|
195
|
-
@click="${this._onClick.bind(this, option)}"
|
|
196
|
-
.outlined="${outlined}"
|
|
197
|
-
class="${classMap({
|
|
198
|
-
active: isActive,
|
|
199
|
-
entry: index === 0,
|
|
200
|
-
exit: index === this._options.length - 1,
|
|
201
|
-
description: option.description != null,
|
|
202
|
-
})}"
|
|
203
|
-
>
|
|
204
|
-
${!this._hasDescription
|
|
205
|
-
? option.title != null
|
|
206
|
-
? option.label || option.title
|
|
207
|
-
: ''
|
|
208
|
-
: html`<div class="content">
|
|
209
|
-
${option.icon
|
|
210
|
-
? html`<gv-icon shape="${option.icon}"></gv-icon>`
|
|
211
|
-
: option.image
|
|
212
|
-
? html`<gv-image src="${option.image}"></gv-image>`
|
|
213
|
-
: ''}
|
|
214
|
-
<div class="title">${option.title}</div>
|
|
215
|
-
<div class="description-content" .innerHTML="${option.description}"></div>
|
|
216
|
-
</div>`}
|
|
217
|
-
</gv-button>`;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
render() {
|
|
221
|
-
if (this._options) {
|
|
222
|
-
const classes = {
|
|
223
|
-
box: true,
|
|
224
|
-
description: this._hasDescription,
|
|
225
|
-
reverse: this.reverse,
|
|
226
|
-
};
|
|
227
|
-
return html`<div
|
|
228
|
-
class="${classMap(classes)}"
|
|
229
|
-
style="${styleMap({ 'grid-template-columns': `repeat(${this._options.length}, auto)` })}"
|
|
230
|
-
>
|
|
231
|
-
${repeat(
|
|
232
|
-
this._options,
|
|
233
|
-
(option) => option,
|
|
234
|
-
(option, index) => html`${this._renderOption(option, index)}`,
|
|
235
|
-
)}
|
|
236
|
-
</div>`;
|
|
237
|
-
}
|
|
238
|
-
return html``;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
window.customElements.define('gv-option', GvOption);
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvOption=void 0;const t=require("lit");require("../atoms/gv-button");const e=require("lit/directives/repeat"),i=require("lit/directives/class-map"),s=require("../lib/events"),n=require("lit/directives/if-defined"),r=require("lit/directives/style-map");class o extends t.LitElement{static get properties(){return{options:{type:Array},_options:{type:Array,attribute:!1},_hasDescription:{type:Array,attribute:!1},value:{type:String,reflect:!0},multiple:{type:Boolean},reverse:{type:Boolean},small:{type:Boolean},outlined:{type:Boolean},disabled:{type:Boolean,reflect:!0}}}static get styles(){return[t.css`:host{box-sizing:border-box;display:inline-block;--gv-button--p:5px;margin:.2rem;--bdrs:var(--gv-option--bdrs, 0.15rem);--maw:var(--gv-option-button--maw, 200px)}.box.description{display:grid;grid-gap:.5rem}gv-button{margin:0}gv-button.description{flex:1 1 var(--maw);max-width:var(--maw)}gv-button:not(.description){margin:0;--gv-button--bdrs:0;--gv-button--bgc:var(--gv-option--bgc, var(--gv-theme-neutral-color-dark, #bfbfbf))}gv-button:not(.description).entry{--gv-button--bdrs:var(--bdrs) 0 0 var(--bdrs)}gv-button:not(.description).exit{--gv-button--bdrs:0 var(--bdrs) var(--bdrs) 0}.content{white-space:pre-line;--gv-icon--s:var(--gv-option-icon--s, 64px);display:flex;flex-direction:column;align-items:center;height:100%;text-transform:none}gv-image{height:64px;width:64px;--gv-image--of:fill;display:inline-flex}.reverse .content{flex-direction:column-reverse}.title{font-size:var(--gv-theme-font-size-l,18px);font-weight:700;margin:.5rem 0}gv-button.description{margin:.5rem}`]}constructor(){super(),this.multiple=!1,this.reverse=!1}_onClick(t){this.setValue(t),(0,s.dispatchCustomEvent)(this,"select",t),this.dispatchEvent(new Event("input"),{bubbles:!0,cancelable:!0})}async performUpdate(){return this.shadowRoot.querySelectorAll("gv-button").forEach((t=>t.performUpdate())),super.performUpdate()}setValue(t){t&&(this.multiple?this.value.includes(t.id)?this.value=this.value.filter((e=>e!==t.id)):this.value=[...this.value,t.id]:this.value=t.id)}set options(t){t&&Promise.all(t).then((t=>{this._options=t,this._hasDescription=null!=this._options.find((t=>null!=t.description))}))}isActive(t){return!!this.value&&(this.multiple?this.value.includes(t.id):this.value===t.id)}_renderOption(e,s){const r=this.isActive(e),o=this.outlined||!r&&this._hasDescription;return t.html`<gv-button .icon="${(0,n.ifDefined)(this._hasDescription?null:e.icon)}" .iconRight="${(0,n.ifDefined)(!e.icon&&e.iconRight?e.iconRight:null)}" .title="${(0,n.ifDefined)(e.title)}" .primary="${r}" .small="${this.small}" .disabled="${e.disabled||this.disabled}" @click="${this._onClick.bind(this,e)}" .outlined="${o}" class="${(0,i.classMap)({active:r,entry:0===s,exit:s===this._options.length-1,description:null!=e.description})}">${this._hasDescription?t.html`<div class="content">${e.icon?t.html`<gv-icon shape="${e.icon}"></gv-icon>`:e.image?t.html`<gv-image src="${e.image}"></gv-image>`:""}<div class="title">${e.title}</div><div class="description-content" .innerHTML="${e.description}"></div></div>`:null!=e.title?e.label||e.title:""}</gv-button>`}render(){if(this._options){const s={box:!0,description:this._hasDescription,reverse:this.reverse};return t.html`<div class="${(0,i.classMap)(s)}" style="${(0,r.styleMap)({"grid-template-columns":`repeat(${this._options.length}, auto)`})}">${(0,e.repeat)(this._options,(t=>t),((e,i)=>t.html`${this._renderOption(e,i)}`))}</div>`}return t.html``}}exports.GvOption=o,window.customElements.define("gv-option",o);
|