ezfw-core 1.0.0
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/components/EzBaseComponent.ts +648 -0
- package/components/EzComponent.ts +89 -0
- package/components/EzInput.module.scss +183 -0
- package/components/EzInput.ts +104 -0
- package/components/EzLabel.ts +22 -0
- package/components/EzOutlet.ts +181 -0
- package/components/HtmlWrapper.ts +305 -0
- package/components/avatar/EzAvatar.module.scss +200 -0
- package/components/avatar/EzAvatar.ts +130 -0
- package/components/badge/EzBadge.module.scss +202 -0
- package/components/badge/EzBadge.ts +77 -0
- package/components/button/EzButton.module.scss +402 -0
- package/components/button/EzButton.ts +175 -0
- package/components/button/EzButtonGroup.ts +48 -0
- package/components/card/EzCard.module.scss +71 -0
- package/components/card/EzCard.ts +120 -0
- package/components/chart/EzBarChart.ts +47 -0
- package/components/chart/EzChart.module.scss +14 -0
- package/components/chart/EzChart.ts +279 -0
- package/components/chart/EzDoughnutChart.ts +47 -0
- package/components/chart/EzLineChart.ts +53 -0
- package/components/checkbox/EzCheckbox.module.scss +145 -0
- package/components/checkbox/EzCheckbox.ts +115 -0
- package/components/dataview/EzDataView.module.scss +115 -0
- package/components/dataview/EzDataView.ts +355 -0
- package/components/dataview/modes/EzDataViewCards.ts +322 -0
- package/components/dataview/modes/EzDataViewGrid.ts +76 -0
- package/components/datepicker/EzDatePicker.module.scss +348 -0
- package/components/datepicker/EzDatePicker.ts +519 -0
- package/components/dialog/EzDialog.module.scss +180 -0
- package/components/dropdown/EzDropdown.module.scss +107 -0
- package/components/dropdown/EzDropdown.ts +235 -0
- package/components/feed/EzActivityFeed.module.scss +90 -0
- package/components/feed/EzActivityFeed.ts +78 -0
- package/components/form/EzForm.ts +364 -0
- package/components/form/EzValidators.test.js +421 -0
- package/components/form/EzValidators.ts +202 -0
- package/components/grid/EzGrid.scss +88 -0
- package/components/grid/EzGrid.ts +1085 -0
- package/components/grid/EzGridContainer.ts +104 -0
- package/components/grid/body/EzGridBody.scss +283 -0
- package/components/grid/body/EzGridBody.ts +549 -0
- package/components/grid/body/EzGridCell.ts +211 -0
- package/components/grid/body/EzGridRow.ts +196 -0
- package/components/grid/filter/EzGridFilters.scss +78 -0
- package/components/grid/filter/EzGridFilters.ts +285 -0
- package/components/grid/footer/EzGridFooter.scss +136 -0
- package/components/grid/footer/EzGridFooter.ts +448 -0
- package/components/grid/header/EzGridHeader.scss +199 -0
- package/components/grid/header/EzGridHeader.ts +430 -0
- package/components/grid/query/EzGridQuery.ts +81 -0
- package/components/grid/state/EzGridColumns.ts +155 -0
- package/components/grid/state/EzGridController.ts +470 -0
- package/components/grid/state/EzGridLifecycle.ts +136 -0
- package/components/grid/state/EzGridNormalizers.test.js +273 -0
- package/components/grid/state/EzGridNormalizers.ts +162 -0
- package/components/grid/state/EzGridParts.ts +233 -0
- package/components/grid/state/EzGridPersistence.ts +140 -0
- package/components/grid/state/EzGridRemote.test.js +573 -0
- package/components/grid/state/EzGridRemote.ts +335 -0
- package/components/grid/state/EzGridSelection.ts +231 -0
- package/components/grid/state/EzGridSort.ts +286 -0
- package/components/grid/title/EzGridActionBar.ts +98 -0
- package/components/grid/title/EzGridTitle.ts +114 -0
- package/components/grid/title/EzGridTitleBar.scss +65 -0
- package/components/grid/title/EzGridTitleBar.ts +87 -0
- package/components/grid/types.ts +607 -0
- package/components/panel/EzPanel.module.scss +133 -0
- package/components/panel/EzPanel.ts +147 -0
- package/components/radio/EzRadio.module.scss +190 -0
- package/components/radio/EzRadio.ts +149 -0
- package/components/select/EzSelect.module.scss +153 -0
- package/components/select/EzSelect.ts +238 -0
- package/components/skeleton/EzSkeleton.module.scss +95 -0
- package/components/skeleton/EzSkeleton.ts +70 -0
- package/components/store/EzStore.ts +344 -0
- package/components/switch/EzSwitch.module.scss +164 -0
- package/components/switch/EzSwitch.ts +117 -0
- package/components/tabs/EzTabPanel.module.scss +181 -0
- package/components/tabs/EzTabPanel.ts +402 -0
- package/components/textarea/EzTextarea.module.scss +131 -0
- package/components/textarea/EzTextarea.ts +161 -0
- package/components/timepicker/EzTimePicker.module.scss +282 -0
- package/components/timepicker/EzTimePicker.ts +540 -0
- package/components/toast/EzToast.module.scss +291 -0
- package/components/tooltip/EzTooltip.module.scss +124 -0
- package/components/tooltip/EzTooltip.ts +153 -0
- package/core/EzComponentTypes.ts +693 -0
- package/core/EzError.ts +63 -0
- package/core/EzModel.ts +268 -0
- package/core/EzTypes.ts +328 -0
- package/core/eventBus.ts +284 -0
- package/core/ez.ts +617 -0
- package/core/loader.ts +725 -0
- package/core/renderer.ts +1010 -0
- package/core/router.ts +490 -0
- package/core/services.ts +124 -0
- package/core/state.ts +142 -0
- package/core/utils.ts +81 -0
- package/package.json +51 -0
- package/services/RouteUI.js +17 -0
- package/services/crypto.js +64 -0
- package/services/dialog.js +222 -0
- package/services/fetchApi.js +63 -0
- package/services/firebase.js +30 -0
- package/services/toast.js +214 -0
- package/template/doc/EzDocs.js +15 -0
- package/template/doc/EzDocs.module.scss +627 -0
- package/template/doc/EzDocsController.js +164 -0
- package/template/doc/data/activityfeed/EzActivityFeedDoc.js +42 -0
- package/template/doc/data/avatar/EzAvatarDoc.js +71 -0
- package/template/doc/data/badge/EzBadgeDoc.js +92 -0
- package/template/doc/data/button/EzButtonDoc.js +77 -0
- package/template/doc/data/buttongroup/EzButtonGroupDoc.js +102 -0
- package/template/doc/data/card/EzCardDoc.js +39 -0
- package/template/doc/data/chart/EzChartDoc.js +60 -0
- package/template/doc/data/checkbox/EzCheckboxDoc.js +67 -0
- package/template/doc/data/component/EzComponentDoc.js +34 -0
- package/template/doc/data/cssmodules/CSSModulesDoc.js +70 -0
- package/template/doc/data/datepicker/EzDatePickerDoc.js +126 -0
- package/template/doc/data/dialog/EzDialogDoc.js +217 -0
- package/template/doc/data/dropdown/EzDropdownDoc.js +178 -0
- package/template/doc/data/form/EzFormDoc.js +90 -0
- package/template/doc/data/grid/EzGridDoc.js +99 -0
- package/template/doc/data/input/EzInputDoc.js +92 -0
- package/template/doc/data/label/EzLabelDoc.js +40 -0
- package/template/doc/data/model/EzModelDoc.js +53 -0
- package/template/doc/data/outlet/EzOutletDoc.js +63 -0
- package/template/doc/data/panel/EzPanelDoc.js +214 -0
- package/template/doc/data/radio/EzRadioDoc.js +174 -0
- package/template/doc/data/router/EzRouterDoc.js +75 -0
- package/template/doc/data/select/EzSelectDoc.js +37 -0
- package/template/doc/data/skeleton/EzSkeletonDoc.js +149 -0
- package/template/doc/data/switch/EzSwitchDoc.js +82 -0
- package/template/doc/data/tabpanel/EzTabPanelDoc.js +44 -0
- package/template/doc/data/textarea/EzTextareaDoc.js +131 -0
- package/template/doc/data/timepicker/EzTimePickerDoc.js +107 -0
- package/template/doc/data/tooltip/EzTooltipDoc.js +193 -0
- package/template/doc/data/validators/EzValidatorsDoc.js +37 -0
- package/template/doc/sidebar/EzDocsSidebar.js +32 -0
- package/template/doc/sidebar/category/EzDocsCategory.js +33 -0
- package/template/doc/sidebar/item/EzDocsComponentItem.js +24 -0
- package/template/doc/viewer/EzDocsViewer.js +18 -0
- package/template/doc/viewer/codepanel/EzDocsCodePanel.js +51 -0
- package/template/doc/viewer/content/EzDocsContent.js +315 -0
- package/template/doc/viewer/header/EzDocsViewerHeader.js +46 -0
- package/template/doc/viewer/showcase/EzDocsShowcase.js +59 -0
- package/template/doc/viewer/showcase/EzDocsShowcaseSection.js +25 -0
- package/template/doc/viewer/showcase/EzDocsVariantItem.js +29 -0
- package/template/doc/welcome/EzDocsWelcome.js +48 -0
- package/themes/ez-theme.scss +179 -0
- package/themes/nature-fresh.scss +169 -0
- package/types/global.d.ts +21 -0
- package/utils/cssModules.js +81 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// ==========================================================
|
|
2
|
+
// EzSelect - CSS Module
|
|
3
|
+
// ==========================================================
|
|
4
|
+
|
|
5
|
+
.select {
|
|
6
|
+
position: relative;
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
min-width: 80px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// ----------------------------------------------------------
|
|
12
|
+
// Trigger button
|
|
13
|
+
// ----------------------------------------------------------
|
|
14
|
+
.selectTrigger {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: space-between;
|
|
18
|
+
gap: 8px;
|
|
19
|
+
|
|
20
|
+
width: 100%;
|
|
21
|
+
padding: 6px 10px;
|
|
22
|
+
|
|
23
|
+
font-family: inherit;
|
|
24
|
+
font-size: 13px;
|
|
25
|
+
font-weight: 500;
|
|
26
|
+
color: var(--ez-text-primary, #1e293b);
|
|
27
|
+
text-align: left;
|
|
28
|
+
|
|
29
|
+
background: var(--ez-surface-secondary, #ffffff);
|
|
30
|
+
border: 1px solid var(--ez-border-primary, #e2e8f0);
|
|
31
|
+
border-radius: var(--ez-radius-sm, 4px);
|
|
32
|
+
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
outline: none;
|
|
35
|
+
|
|
36
|
+
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
37
|
+
|
|
38
|
+
&:hover {
|
|
39
|
+
border-color: var(--ez-text-tertiary, #94a3b8);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&:focus {
|
|
43
|
+
border-color: var(--ez-primary, #2563eb);
|
|
44
|
+
box-shadow: 0 0 0 2px var(--ez-primary-light, rgba(37, 99, 235, 0.15));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.selectTriggerText {
|
|
49
|
+
flex: 1;
|
|
50
|
+
overflow: hidden;
|
|
51
|
+
text-overflow: ellipsis;
|
|
52
|
+
white-space: nowrap;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.isPlaceholder {
|
|
56
|
+
color: var(--ez-text-tertiary, #94a3b8);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.selectArrow {
|
|
60
|
+
font-size: 10px;
|
|
61
|
+
color: var(--ez-text-tertiary, #94a3b8);
|
|
62
|
+
transition: transform 0.2s ease;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ----------------------------------------------------------
|
|
66
|
+
// Dropdown
|
|
67
|
+
// ----------------------------------------------------------
|
|
68
|
+
.selectDropdown {
|
|
69
|
+
position: absolute;
|
|
70
|
+
top: calc(100% + 4px);
|
|
71
|
+
left: 0;
|
|
72
|
+
right: 0;
|
|
73
|
+
z-index: 1000;
|
|
74
|
+
|
|
75
|
+
max-height: 200px;
|
|
76
|
+
overflow-y: auto;
|
|
77
|
+
|
|
78
|
+
background: var(--ez-surface-secondary, #ffffff);
|
|
79
|
+
border: 1px solid var(--ez-border-primary, #e2e8f0);
|
|
80
|
+
border-radius: var(--ez-radius-sm, 4px);
|
|
81
|
+
box-shadow: var(--ez-shadow-md, 0 4px 12px rgba(0, 0, 0, 0.1));
|
|
82
|
+
|
|
83
|
+
opacity: 0;
|
|
84
|
+
visibility: hidden;
|
|
85
|
+
transform: translateY(-8px);
|
|
86
|
+
|
|
87
|
+
transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ----------------------------------------------------------
|
|
91
|
+
// Option items
|
|
92
|
+
// ----------------------------------------------------------
|
|
93
|
+
.selectOption {
|
|
94
|
+
padding: 8px 12px;
|
|
95
|
+
|
|
96
|
+
font-size: 13px;
|
|
97
|
+
color: var(--ez-text-primary, #1e293b);
|
|
98
|
+
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
|
|
101
|
+
transition: background-color 0.1s ease;
|
|
102
|
+
|
|
103
|
+
&:hover {
|
|
104
|
+
background-color: var(--ez-surface-primary, #f1f5f9);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
&:first-child {
|
|
108
|
+
border-radius: var(--ez-radius-sm, 4px) var(--ez-radius-sm, 4px) 0 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&:last-child {
|
|
112
|
+
border-radius: 0 0 var(--ez-radius-sm, 4px) var(--ez-radius-sm, 4px);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.isSelected {
|
|
117
|
+
background-color: var(--ez-primary-light, rgba(37, 99, 235, 0.1));
|
|
118
|
+
color: var(--ez-primary, #2563eb);
|
|
119
|
+
font-weight: 500;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ----------------------------------------------------------
|
|
123
|
+
// Open state
|
|
124
|
+
// ----------------------------------------------------------
|
|
125
|
+
.isOpen {
|
|
126
|
+
.selectTrigger {
|
|
127
|
+
border-color: var(--ez-primary, #2563eb);
|
|
128
|
+
box-shadow: 0 0 0 2px var(--ez-primary-light, rgba(37, 99, 235, 0.15));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.selectArrow {
|
|
132
|
+
transform: rotate(180deg);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.selectDropdown {
|
|
136
|
+
opacity: 1;
|
|
137
|
+
visibility: visible;
|
|
138
|
+
transform: translateY(0);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ----------------------------------------------------------
|
|
143
|
+
// Dropup state (opens upward)
|
|
144
|
+
// ----------------------------------------------------------
|
|
145
|
+
.isDropup {
|
|
146
|
+
.selectDropdown {
|
|
147
|
+
transform: translateY(8px);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
&.isOpen .selectDropdown {
|
|
151
|
+
transform: translateY(0);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import styles from './EzSelect.module.scss';
|
|
2
|
+
import { cx } from '../../utils/cssModules.js';
|
|
3
|
+
import { EzBaseComponent, EzBaseComponentConfig } from '../EzBaseComponent.js';
|
|
4
|
+
|
|
5
|
+
const cls = cx(styles);
|
|
6
|
+
|
|
7
|
+
export interface SelectOption {
|
|
8
|
+
value: string | number;
|
|
9
|
+
label: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface EzSelectConfig extends EzBaseComponentConfig {
|
|
13
|
+
options?: (SelectOption | string | number)[];
|
|
14
|
+
value?: string | number | null;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
onSelect?: (value: string | number) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class EzSelect extends EzBaseComponent {
|
|
20
|
+
declare config: EzSelectConfig;
|
|
21
|
+
declare el: HTMLDivElement;
|
|
22
|
+
|
|
23
|
+
options: (SelectOption | string | number)[];
|
|
24
|
+
value: string | number | null;
|
|
25
|
+
placeholder: string;
|
|
26
|
+
onSelect: ((value: string | number) => void) | null;
|
|
27
|
+
|
|
28
|
+
private _isOpen: boolean = false;
|
|
29
|
+
private _trigger: HTMLButtonElement | null = null;
|
|
30
|
+
private _triggerText: HTMLSpanElement | null = null;
|
|
31
|
+
private _dropdown: HTMLDivElement | null = null;
|
|
32
|
+
private _outsideClickHandler: ((e: MouseEvent) => void) | null = null;
|
|
33
|
+
|
|
34
|
+
constructor(config: EzSelectConfig = {}) {
|
|
35
|
+
super(config);
|
|
36
|
+
|
|
37
|
+
this.options = config.options || [];
|
|
38
|
+
this.value = config.value ?? null;
|
|
39
|
+
this.placeholder = config.placeholder || 'Select...';
|
|
40
|
+
this.onSelect = config.onSelect || null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
render(): HTMLDivElement {
|
|
44
|
+
this.el = document.createElement('div');
|
|
45
|
+
this.el.className = cls('select');
|
|
46
|
+
|
|
47
|
+
if (this.config.cls) {
|
|
48
|
+
const clsValue = this.config.cls;
|
|
49
|
+
if (Array.isArray(clsValue)) {
|
|
50
|
+
clsValue.forEach(c => c && this.el.classList.add(c));
|
|
51
|
+
} else if (typeof clsValue === 'string') {
|
|
52
|
+
this.el.classList.add(clsValue);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this._trigger = document.createElement('button');
|
|
57
|
+
this._trigger.type = 'button';
|
|
58
|
+
this._trigger.className = cls('selectTrigger');
|
|
59
|
+
|
|
60
|
+
this._triggerText = document.createElement('span');
|
|
61
|
+
this._triggerText.className = cls('selectTriggerText');
|
|
62
|
+
this._trigger.appendChild(this._triggerText);
|
|
63
|
+
|
|
64
|
+
const arrow = document.createElement('span');
|
|
65
|
+
arrow.className = cls('selectArrow');
|
|
66
|
+
arrow.innerHTML = '▾';
|
|
67
|
+
this._trigger.appendChild(arrow);
|
|
68
|
+
|
|
69
|
+
this.el.appendChild(this._trigger);
|
|
70
|
+
|
|
71
|
+
this._dropdown = document.createElement('div');
|
|
72
|
+
this._dropdown.className = cls('selectDropdown');
|
|
73
|
+
|
|
74
|
+
this._buildOptions();
|
|
75
|
+
this.el.appendChild(this._dropdown);
|
|
76
|
+
|
|
77
|
+
this._updateDisplay();
|
|
78
|
+
this._bindEvents();
|
|
79
|
+
|
|
80
|
+
return this.el;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private _buildOptions(): void {
|
|
84
|
+
if (!this._dropdown) return;
|
|
85
|
+
this._dropdown.innerHTML = '';
|
|
86
|
+
|
|
87
|
+
this.options.forEach(opt => {
|
|
88
|
+
const item = document.createElement('div');
|
|
89
|
+
item.className = cls('selectOption');
|
|
90
|
+
|
|
91
|
+
const value = typeof opt === 'object' ? opt.value : opt;
|
|
92
|
+
const label = typeof opt === 'object' ? opt.label : String(opt);
|
|
93
|
+
|
|
94
|
+
item.dataset.value = String(value);
|
|
95
|
+
item.textContent = label;
|
|
96
|
+
|
|
97
|
+
if (value === this.value) {
|
|
98
|
+
item.classList.add(cls('isSelected'));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
item.addEventListener('click', (e) => {
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
this._selectOption(value);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
this._dropdown!.appendChild(item);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private _updateDisplay(): void {
|
|
111
|
+
if (!this._triggerText) return;
|
|
112
|
+
|
|
113
|
+
const selectedOpt = this.options.find(opt => {
|
|
114
|
+
const value = typeof opt === 'object' ? opt.value : opt;
|
|
115
|
+
return value === this.value;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (selectedOpt) {
|
|
119
|
+
const label = typeof selectedOpt === 'object' ? selectedOpt.label : String(selectedOpt);
|
|
120
|
+
this._triggerText.textContent = label;
|
|
121
|
+
this._triggerText.classList.remove(cls('isPlaceholder'));
|
|
122
|
+
} else {
|
|
123
|
+
this._triggerText.textContent = this.placeholder;
|
|
124
|
+
this._triggerText.classList.add(cls('isPlaceholder'));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private _selectOption(value: string | number): void {
|
|
129
|
+
this.value = value;
|
|
130
|
+
this._updateDisplay();
|
|
131
|
+
this._buildOptions();
|
|
132
|
+
this._close();
|
|
133
|
+
|
|
134
|
+
if (typeof this.onSelect === 'function') {
|
|
135
|
+
this.onSelect(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private _bindEvents(): void {
|
|
140
|
+
if (!this._trigger) return;
|
|
141
|
+
|
|
142
|
+
this._trigger.addEventListener('click', (e) => {
|
|
143
|
+
e.stopPropagation();
|
|
144
|
+
this._isOpen ? this._close() : this._open();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
this._outsideClickHandler = (e: MouseEvent) => {
|
|
148
|
+
if (!this.el.contains(e.target as Node)) {
|
|
149
|
+
this._close();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
document.addEventListener('click', this._outsideClickHandler);
|
|
154
|
+
|
|
155
|
+
this._trigger.addEventListener('keydown', (e) => {
|
|
156
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
this._isOpen ? this._close() : this._open();
|
|
159
|
+
} else if (e.key === 'Escape') {
|
|
160
|
+
this._close();
|
|
161
|
+
} else if (e.key === 'ArrowDown') {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
this._selectNext();
|
|
164
|
+
} else if (e.key === 'ArrowUp') {
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
this._selectPrev();
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private _open(): void {
|
|
172
|
+
this._isOpen = true;
|
|
173
|
+
this.el.classList.add(cls('isOpen'));
|
|
174
|
+
this._trigger?.setAttribute('aria-expanded', 'true');
|
|
175
|
+
this._positionDropdown();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private _positionDropdown(): void {
|
|
179
|
+
if (!this._trigger || !this._dropdown) return;
|
|
180
|
+
|
|
181
|
+
const rect = this._trigger.getBoundingClientRect();
|
|
182
|
+
const dropdownHeight = this._dropdown.scrollHeight || 200;
|
|
183
|
+
const viewportHeight = window.innerHeight;
|
|
184
|
+
const spaceBelow = viewportHeight - rect.bottom;
|
|
185
|
+
const spaceAbove = rect.top;
|
|
186
|
+
|
|
187
|
+
this._dropdown.style.position = 'fixed';
|
|
188
|
+
this._dropdown.style.left = `${rect.left}px`;
|
|
189
|
+
this._dropdown.style.width = `${rect.width}px`;
|
|
190
|
+
|
|
191
|
+
if (spaceBelow < dropdownHeight && spaceAbove > spaceBelow) {
|
|
192
|
+
this._dropdown.style.bottom = `${viewportHeight - rect.top + 4}px`;
|
|
193
|
+
this._dropdown.style.top = 'auto';
|
|
194
|
+
this.el.classList.add(cls('isDropup'));
|
|
195
|
+
} else {
|
|
196
|
+
this._dropdown.style.top = `${rect.bottom + 4}px`;
|
|
197
|
+
this._dropdown.style.bottom = 'auto';
|
|
198
|
+
this.el.classList.remove(cls('isDropup'));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private _close(): void {
|
|
203
|
+
this._isOpen = false;
|
|
204
|
+
this.el.classList.remove(cls('isOpen'));
|
|
205
|
+
this.el.classList.remove(cls('isDropup'));
|
|
206
|
+
this._trigger?.setAttribute('aria-expanded', 'false');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private _selectNext(): void {
|
|
210
|
+
const values = this.options.map(opt => typeof opt === 'object' ? opt.value : opt);
|
|
211
|
+
const currentIndex = values.indexOf(this.value as string | number);
|
|
212
|
+
const nextIndex = currentIndex < values.length - 1 ? currentIndex + 1 : 0;
|
|
213
|
+
this._selectOption(values[nextIndex]);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private _selectPrev(): void {
|
|
217
|
+
const values = this.options.map(opt => typeof opt === 'object' ? opt.value : opt);
|
|
218
|
+
const currentIndex = values.indexOf(this.value as string | number);
|
|
219
|
+
const prevIndex = currentIndex > 0 ? currentIndex - 1 : values.length - 1;
|
|
220
|
+
this._selectOption(values[prevIndex]);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
setValue(value: string | number): void {
|
|
224
|
+
this.value = value;
|
|
225
|
+
this._updateDisplay();
|
|
226
|
+
this._buildOptions();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
getValue(): string | number | null {
|
|
230
|
+
return this.value;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
destroy(): void {
|
|
234
|
+
if (this._outsideClickHandler) {
|
|
235
|
+
document.removeEventListener('click', this._outsideClickHandler);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
.skeletonGroup {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 8px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.skeleton {
|
|
8
|
+
display: block;
|
|
9
|
+
background: linear-gradient(
|
|
10
|
+
90deg,
|
|
11
|
+
#cbd5e1 25%,
|
|
12
|
+
#e2e8f0 50%,
|
|
13
|
+
#cbd5e1 75%
|
|
14
|
+
);
|
|
15
|
+
background-size: 200% 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Variants
|
|
19
|
+
.text {
|
|
20
|
+
height: 16px;
|
|
21
|
+
width: 100%;
|
|
22
|
+
border-radius: var(--ez-radius-sm, 4px);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.title {
|
|
26
|
+
height: 24px;
|
|
27
|
+
width: 60%;
|
|
28
|
+
border-radius: var(--ez-radius-sm, 4px);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.circle {
|
|
32
|
+
width: 40px;
|
|
33
|
+
height: 40px;
|
|
34
|
+
border-radius: 50%;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.rect {
|
|
38
|
+
width: 100%;
|
|
39
|
+
height: 100px;
|
|
40
|
+
border-radius: var(--ez-radius-md, 6px);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.rounded {
|
|
44
|
+
border-radius: var(--ez-radius-lg, 8px);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Pulse animation (shimmer effect)
|
|
48
|
+
.pulse {
|
|
49
|
+
animation: shimmer 1.5s infinite;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@keyframes shimmer {
|
|
53
|
+
0% {
|
|
54
|
+
background-position: 200% 0;
|
|
55
|
+
}
|
|
56
|
+
100% {
|
|
57
|
+
background-position: -200% 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Wave animation
|
|
62
|
+
.wave {
|
|
63
|
+
position: relative;
|
|
64
|
+
overflow: hidden;
|
|
65
|
+
|
|
66
|
+
&::after {
|
|
67
|
+
content: '';
|
|
68
|
+
position: absolute;
|
|
69
|
+
top: 0;
|
|
70
|
+
left: 0;
|
|
71
|
+
right: 0;
|
|
72
|
+
bottom: 0;
|
|
73
|
+
background: linear-gradient(
|
|
74
|
+
90deg,
|
|
75
|
+
transparent,
|
|
76
|
+
rgba(255, 255, 255, 0.4),
|
|
77
|
+
transparent
|
|
78
|
+
);
|
|
79
|
+
animation: wave 1.5s linear infinite;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@keyframes wave {
|
|
84
|
+
0% {
|
|
85
|
+
transform: translateX(-100%);
|
|
86
|
+
}
|
|
87
|
+
100% {
|
|
88
|
+
transform: translateX(100%);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// No animation
|
|
93
|
+
.none {
|
|
94
|
+
animation: none;
|
|
95
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import styles from './EzSkeleton.module.scss';
|
|
2
|
+
import { cx } from '../../utils/cssModules.js';
|
|
3
|
+
import { EzBaseComponent, EzBaseComponentConfig } from '../EzBaseComponent.js';
|
|
4
|
+
|
|
5
|
+
const cls = cx(styles);
|
|
6
|
+
|
|
7
|
+
export interface EzSkeletonConfig extends EzBaseComponentConfig {
|
|
8
|
+
variant?: 'text' | 'circle' | 'rectangular';
|
|
9
|
+
animation?: 'pulse' | 'wave' | 'none';
|
|
10
|
+
width?: number | string;
|
|
11
|
+
height?: number | string;
|
|
12
|
+
size?: number;
|
|
13
|
+
count?: number;
|
|
14
|
+
gap?: number | string;
|
|
15
|
+
rounded?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class EzSkeleton extends EzBaseComponent {
|
|
19
|
+
declare config: EzSkeletonConfig;
|
|
20
|
+
|
|
21
|
+
render(): HTMLElement {
|
|
22
|
+
const cfg = this.config;
|
|
23
|
+
|
|
24
|
+
if (cfg.count && cfg.count > 1) {
|
|
25
|
+
const wrapper = document.createElement('div');
|
|
26
|
+
wrapper.className = cls('skeletonGroup');
|
|
27
|
+
|
|
28
|
+
if (cfg.gap) {
|
|
29
|
+
wrapper.style.gap = typeof cfg.gap === 'number' ? `${cfg.gap}px` : cfg.gap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < cfg.count; i++) {
|
|
33
|
+
const skeleton = this._createSkeleton(cfg);
|
|
34
|
+
wrapper.appendChild(skeleton);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return wrapper;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return this._createSkeleton(cfg);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private _createSkeleton(cfg: EzSkeletonConfig): HTMLElement {
|
|
44
|
+
const skeleton = document.createElement('div');
|
|
45
|
+
skeleton.className = cls(
|
|
46
|
+
'skeleton',
|
|
47
|
+
cfg.variant || 'text',
|
|
48
|
+
cfg.animation || 'pulse',
|
|
49
|
+
cfg.rounded && 'rounded'
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (cfg.width) {
|
|
53
|
+
skeleton.style.width = typeof cfg.width === 'number' ? `${cfg.width}px` : cfg.width;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (cfg.height) {
|
|
57
|
+
skeleton.style.height = typeof cfg.height === 'number' ? `${cfg.height}px` : cfg.height;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (cfg.variant === 'circle') {
|
|
61
|
+
const size = cfg.size || 40;
|
|
62
|
+
skeleton.style.width = `${size}px`;
|
|
63
|
+
skeleton.style.height = `${size}px`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.applyStyles(skeleton);
|
|
67
|
+
|
|
68
|
+
return skeleton;
|
|
69
|
+
}
|
|
70
|
+
}
|