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,133 @@
|
|
|
1
|
+
.panel {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
background: var(--ez-surface-secondary, #ffffff);
|
|
5
|
+
border: 1px solid var(--ez-border, #e2e8f0);
|
|
6
|
+
border-radius: var(--ez-radius-lg, 12px);
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.header {
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
gap: 12px;
|
|
14
|
+
padding: 14px 20px;
|
|
15
|
+
background: var(--ez-surface-primary, #f8fafc);
|
|
16
|
+
border-bottom: 1px solid var(--ez-border, #e2e8f0);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.icon {
|
|
20
|
+
font-size: 18px;
|
|
21
|
+
color: var(--ez-primary, #005871);
|
|
22
|
+
width: 24px;
|
|
23
|
+
text-align: center;
|
|
24
|
+
flex-shrink: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.title {
|
|
28
|
+
font-size: 15px;
|
|
29
|
+
font-weight: 600;
|
|
30
|
+
color: var(--ez-text-primary, #1e293b);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.badge {
|
|
34
|
+
font-size: 12px;
|
|
35
|
+
font-weight: 500;
|
|
36
|
+
color: var(--ez-text-tertiary, #94a3b8);
|
|
37
|
+
background: var(--ez-surface-secondary, #ffffff);
|
|
38
|
+
padding: 2px 8px;
|
|
39
|
+
border-radius: 10px;
|
|
40
|
+
border: 1px solid var(--ez-border, #e2e8f0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.spacer {
|
|
44
|
+
flex: 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.tools {
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: 8px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.toggle {
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
width: 28px;
|
|
58
|
+
height: 28px;
|
|
59
|
+
padding: 0;
|
|
60
|
+
background: transparent;
|
|
61
|
+
border: none;
|
|
62
|
+
border-radius: var(--ez-radius-sm, 4px);
|
|
63
|
+
color: var(--ez-text-tertiary, #94a3b8);
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
transition: all 0.15s ease;
|
|
66
|
+
|
|
67
|
+
&:hover {
|
|
68
|
+
background: var(--ez-surface-tertiary, #e2e8f0);
|
|
69
|
+
color: var(--ez-text-primary, #1e293b);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
i {
|
|
73
|
+
transition: transform 0.2s ease;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.body {
|
|
78
|
+
padding: 16px 20px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.noPadding .body {
|
|
82
|
+
padding: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Variants
|
|
86
|
+
.elevated {
|
|
87
|
+
border: none;
|
|
88
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.flat {
|
|
92
|
+
border: none;
|
|
93
|
+
background: var(--ez-surface-primary, #f8fafc);
|
|
94
|
+
|
|
95
|
+
.header {
|
|
96
|
+
background: transparent;
|
|
97
|
+
border-bottom-color: var(--ez-border-light, #f1f5f9);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.outlined {
|
|
102
|
+
background: transparent;
|
|
103
|
+
|
|
104
|
+
.header {
|
|
105
|
+
background: transparent;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Collapsible state
|
|
110
|
+
.collapsible {
|
|
111
|
+
.toggle i {
|
|
112
|
+
transform: rotate(0deg);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.collapsed {
|
|
117
|
+
.toggle i {
|
|
118
|
+
transform: rotate(-90deg);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.body {
|
|
122
|
+
display: none;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Hover effect
|
|
127
|
+
.panel {
|
|
128
|
+
transition: box-shadow 0.2s ease;
|
|
129
|
+
|
|
130
|
+
&:hover {
|
|
131
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import styles from './EzPanel.module.scss';
|
|
2
|
+
import { cx } from '../../utils/cssModules.js';
|
|
3
|
+
import { EzBaseComponent, EzBaseComponentConfig } from '../EzBaseComponent.js';
|
|
4
|
+
|
|
5
|
+
declare const ez: {
|
|
6
|
+
_createChildElements(items: unknown[], controller: string | null, state: unknown, css?: string | null): Promise<Node[]>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const cls = cx(styles);
|
|
10
|
+
|
|
11
|
+
interface ToolConfig {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface EzPanelConfig extends EzBaseComponentConfig {
|
|
16
|
+
title?: string;
|
|
17
|
+
icon?: string;
|
|
18
|
+
badge?: string | number;
|
|
19
|
+
variant?: string;
|
|
20
|
+
noPadding?: boolean;
|
|
21
|
+
collapsible?: boolean;
|
|
22
|
+
collapsed?: boolean;
|
|
23
|
+
tools?: ToolConfig[];
|
|
24
|
+
items?: unknown[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class EzPanel extends EzBaseComponent {
|
|
28
|
+
declare config: EzPanelConfig;
|
|
29
|
+
|
|
30
|
+
private _panel: HTMLElement | null = null;
|
|
31
|
+
private _body: HTMLElement | null = null;
|
|
32
|
+
|
|
33
|
+
async render(): Promise<HTMLElement> {
|
|
34
|
+
const cfg = this.config;
|
|
35
|
+
|
|
36
|
+
const panel = document.createElement('div');
|
|
37
|
+
panel.className = cls(
|
|
38
|
+
'panel',
|
|
39
|
+
cfg.variant,
|
|
40
|
+
cfg.noPadding && 'noPadding',
|
|
41
|
+
cfg.collapsible && 'collapsible',
|
|
42
|
+
cfg.collapsed && 'collapsed'
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (cfg.title || cfg.icon || cfg.tools || cfg.badge !== undefined) {
|
|
46
|
+
const header = document.createElement('div');
|
|
47
|
+
header.className = cls('header');
|
|
48
|
+
|
|
49
|
+
if (cfg.icon) {
|
|
50
|
+
const icon = document.createElement('i');
|
|
51
|
+
icon.className = cls('icon', cfg.icon);
|
|
52
|
+
header.appendChild(icon);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (cfg.title) {
|
|
56
|
+
const title = document.createElement('span');
|
|
57
|
+
title.className = cls('title');
|
|
58
|
+
title.textContent = cfg.title;
|
|
59
|
+
header.appendChild(title);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (cfg.badge !== undefined) {
|
|
63
|
+
const badge = document.createElement('span');
|
|
64
|
+
badge.className = cls('badge');
|
|
65
|
+
badge.textContent = String(cfg.badge);
|
|
66
|
+
header.appendChild(badge);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const spacer = document.createElement('span');
|
|
70
|
+
spacer.className = cls('spacer');
|
|
71
|
+
header.appendChild(spacer);
|
|
72
|
+
|
|
73
|
+
if (cfg.tools && cfg.tools.length > 0) {
|
|
74
|
+
const tools = document.createElement('div');
|
|
75
|
+
tools.className = cls('tools');
|
|
76
|
+
|
|
77
|
+
const toolEls = await ez._createChildElements(
|
|
78
|
+
cfg.tools,
|
|
79
|
+
cfg.controller || null,
|
|
80
|
+
null,
|
|
81
|
+
(cfg.css as string) || null
|
|
82
|
+
);
|
|
83
|
+
for (const toolEl of toolEls) {
|
|
84
|
+
if (toolEl instanceof Node) {
|
|
85
|
+
tools.appendChild(toolEl);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
header.appendChild(tools);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (cfg.collapsible) {
|
|
92
|
+
const toggle = document.createElement('button');
|
|
93
|
+
toggle.type = 'button';
|
|
94
|
+
toggle.className = cls('toggle');
|
|
95
|
+
toggle.innerHTML = '<i class="fa-solid fa-chevron-down"></i>';
|
|
96
|
+
toggle.addEventListener('click', () => this.toggleCollapse());
|
|
97
|
+
header.appendChild(toggle);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
panel.appendChild(header);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const body = document.createElement('div');
|
|
104
|
+
body.className = cls('body');
|
|
105
|
+
|
|
106
|
+
if (cfg.items && cfg.items.length > 0) {
|
|
107
|
+
const children = await ez._createChildElements(
|
|
108
|
+
cfg.items,
|
|
109
|
+
cfg.controller || null,
|
|
110
|
+
null,
|
|
111
|
+
(cfg.css as string) || null
|
|
112
|
+
);
|
|
113
|
+
for (const child of children) {
|
|
114
|
+
if (child instanceof Node) {
|
|
115
|
+
body.appendChild(child);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
panel.appendChild(body);
|
|
121
|
+
|
|
122
|
+
this._panel = panel;
|
|
123
|
+
this._body = body;
|
|
124
|
+
|
|
125
|
+
this.applyStyles(panel);
|
|
126
|
+
|
|
127
|
+
return panel;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
toggleCollapse(): void {
|
|
131
|
+
if (this._panel) {
|
|
132
|
+
this._panel.classList.toggle(cls('collapsed'));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
expand(): void {
|
|
137
|
+
if (this._panel) {
|
|
138
|
+
this._panel.classList.remove(cls('collapsed'));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
collapse(): void {
|
|
143
|
+
if (this._panel) {
|
|
144
|
+
this._panel.classList.add(cls('collapsed'));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
.radioGroup {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 8px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.horizontal {
|
|
8
|
+
flex-direction: row;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
gap: 16px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.radio {
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: 8px;
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
user-select: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.input {
|
|
22
|
+
position: absolute;
|
|
23
|
+
opacity: 0;
|
|
24
|
+
width: 0;
|
|
25
|
+
height: 0;
|
|
26
|
+
pointer-events: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.circle {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
flex-shrink: 0;
|
|
34
|
+
|
|
35
|
+
width: 18px;
|
|
36
|
+
height: 18px;
|
|
37
|
+
|
|
38
|
+
background: var(--ez-input-bg, #ffffff);
|
|
39
|
+
border: 2px solid var(--ez-border, #cbd5e1);
|
|
40
|
+
border-radius: 50%;
|
|
41
|
+
|
|
42
|
+
transition: all 0.15s ease;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.dot {
|
|
46
|
+
width: 8px;
|
|
47
|
+
height: 8px;
|
|
48
|
+
|
|
49
|
+
background: #ffffff;
|
|
50
|
+
border-radius: 50%;
|
|
51
|
+
|
|
52
|
+
opacity: 0;
|
|
53
|
+
transform: scale(0);
|
|
54
|
+
transition: all 0.15s ease;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Checked state
|
|
58
|
+
.input:checked + .circle {
|
|
59
|
+
background: var(--ez-primary, #2563eb);
|
|
60
|
+
border-color: var(--ez-primary, #2563eb);
|
|
61
|
+
|
|
62
|
+
.dot {
|
|
63
|
+
opacity: 1;
|
|
64
|
+
transform: scale(1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Focus state
|
|
69
|
+
.input:focus-visible + .circle {
|
|
70
|
+
box-shadow: 0 0 0 2px var(--ez-primary-light, rgba(37, 99, 235, 0.3));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Hover state
|
|
74
|
+
.radio:hover:not(.disabled) .circle {
|
|
75
|
+
border-color: var(--ez-primary, #2563eb);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.label {
|
|
79
|
+
font-size: 14px;
|
|
80
|
+
color: var(--ez-text-primary, #1e293b);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Disabled state (on individual radio)
|
|
84
|
+
.radio.disabled {
|
|
85
|
+
cursor: not-allowed;
|
|
86
|
+
pointer-events: none;
|
|
87
|
+
opacity: 0.5;
|
|
88
|
+
|
|
89
|
+
.circle {
|
|
90
|
+
background: var(--ez-surface-primary, #f1f5f9);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.input:checked + .circle {
|
|
94
|
+
background: var(--ez-primary, #2563eb);
|
|
95
|
+
opacity: 0.6;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.label {
|
|
99
|
+
color: var(--ez-text-tertiary, #94a3b8);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Disabled state (on group)
|
|
104
|
+
.radioGroup.disabled {
|
|
105
|
+
.radio {
|
|
106
|
+
cursor: not-allowed;
|
|
107
|
+
pointer-events: none;
|
|
108
|
+
opacity: 0.5;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.circle {
|
|
112
|
+
background: var(--ez-surface-primary, #f1f5f9);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.input:checked + .circle {
|
|
116
|
+
background: var(--ez-primary, #2563eb);
|
|
117
|
+
opacity: 0.6;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.label {
|
|
121
|
+
color: var(--ez-text-tertiary, #94a3b8);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Sizes
|
|
126
|
+
.sm {
|
|
127
|
+
gap: 6px;
|
|
128
|
+
|
|
129
|
+
.radio {
|
|
130
|
+
gap: 6px;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.circle {
|
|
134
|
+
width: 14px;
|
|
135
|
+
height: 14px;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.dot {
|
|
139
|
+
width: 6px;
|
|
140
|
+
height: 6px;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.label {
|
|
144
|
+
font-size: 13px;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.lg {
|
|
149
|
+
gap: 10px;
|
|
150
|
+
|
|
151
|
+
.radio {
|
|
152
|
+
gap: 10px;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.circle {
|
|
156
|
+
width: 22px;
|
|
157
|
+
height: 22px;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.dot {
|
|
161
|
+
width: 10px;
|
|
162
|
+
height: 10px;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.label {
|
|
166
|
+
font-size: 15px;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Error state
|
|
171
|
+
.hasError {
|
|
172
|
+
.circle {
|
|
173
|
+
border-color: var(--ez-danger, #dc2626);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.input:checked + .circle {
|
|
177
|
+
background: var(--ez-danger, #dc2626);
|
|
178
|
+
border-color: var(--ez-danger, #dc2626);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.fieldError {
|
|
183
|
+
display: none;
|
|
184
|
+
font-size: 12px;
|
|
185
|
+
color: var(--ez-danger, #dc2626);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.fieldErrorVisible {
|
|
189
|
+
display: block;
|
|
190
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import styles from './EzRadio.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 RadioOption {
|
|
8
|
+
value: string | number;
|
|
9
|
+
label: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface EzRadioConfig extends EzBaseComponentConfig {
|
|
14
|
+
size?: 'sm' | 'lg';
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
value?: string | number;
|
|
17
|
+
name?: string;
|
|
18
|
+
formData?: string;
|
|
19
|
+
options?: (RadioOption | string | number)[];
|
|
20
|
+
layout?: 'vertical' | 'horizontal';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class EzRadio extends EzBaseComponent {
|
|
24
|
+
declare config: EzRadioConfig;
|
|
25
|
+
|
|
26
|
+
private _wrapper: HTMLDivElement | null = null;
|
|
27
|
+
private _inputs: HTMLInputElement[] = [];
|
|
28
|
+
private _error: HTMLDivElement | null = null;
|
|
29
|
+
|
|
30
|
+
render(): HTMLDivElement {
|
|
31
|
+
const cfg = this.config;
|
|
32
|
+
const options = cfg.options || [];
|
|
33
|
+
|
|
34
|
+
const wrapper = document.createElement('div');
|
|
35
|
+
wrapper.className = cls(
|
|
36
|
+
'radioGroup',
|
|
37
|
+
cfg.size,
|
|
38
|
+
cfg.disabled && 'disabled',
|
|
39
|
+
cfg.layout === 'horizontal' && 'horizontal'
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (cfg.name && cfg.formData) {
|
|
43
|
+
this.config.bind = `${cfg.formData}.${cfg.name}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const onChange = this._createOnChangeHandler();
|
|
47
|
+
const groupName = cfg.name || `radio-${Date.now()}`;
|
|
48
|
+
|
|
49
|
+
this._inputs = [];
|
|
50
|
+
|
|
51
|
+
options.forEach((option) => {
|
|
52
|
+
const optValue = typeof option === 'object' ? option.value : option;
|
|
53
|
+
const optLabel = typeof option === 'object' ? option.label : String(option);
|
|
54
|
+
const optDisabled = typeof option === 'object' ? option.disabled : false;
|
|
55
|
+
|
|
56
|
+
const label = document.createElement('label');
|
|
57
|
+
label.className = cls(
|
|
58
|
+
'radio',
|
|
59
|
+
(cfg.disabled || optDisabled) && 'disabled'
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const input = document.createElement('input');
|
|
63
|
+
input.type = 'radio';
|
|
64
|
+
input.className = cls('input');
|
|
65
|
+
input.name = groupName;
|
|
66
|
+
input.value = String(optValue);
|
|
67
|
+
input.checked = cfg.value === optValue;
|
|
68
|
+
|
|
69
|
+
if (cfg.disabled || optDisabled) input.disabled = true;
|
|
70
|
+
|
|
71
|
+
const circle = document.createElement('span');
|
|
72
|
+
circle.className = cls('circle');
|
|
73
|
+
|
|
74
|
+
const dot = document.createElement('span');
|
|
75
|
+
dot.className = cls('dot');
|
|
76
|
+
circle.appendChild(dot);
|
|
77
|
+
|
|
78
|
+
input.addEventListener('change', e => {
|
|
79
|
+
if ((e.target as HTMLInputElement).checked && onChange) {
|
|
80
|
+
onChange(optValue);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
label.appendChild(input);
|
|
85
|
+
label.appendChild(circle);
|
|
86
|
+
|
|
87
|
+
const text = document.createElement('span');
|
|
88
|
+
text.className = cls('label');
|
|
89
|
+
text.textContent = optLabel;
|
|
90
|
+
label.appendChild(text);
|
|
91
|
+
|
|
92
|
+
wrapper.appendChild(label);
|
|
93
|
+
this._inputs.push(input);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (this.config.bind) {
|
|
97
|
+
const binding = this._resolveBinding();
|
|
98
|
+
if (binding) {
|
|
99
|
+
let value: unknown = binding.controller.state;
|
|
100
|
+
for (const key of binding.path) {
|
|
101
|
+
value = (value as Record<string, unknown>)?.[key];
|
|
102
|
+
}
|
|
103
|
+
if (value !== undefined) {
|
|
104
|
+
this._inputs.forEach(input => {
|
|
105
|
+
input.checked = input.value === String(value);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const error = document.createElement('div');
|
|
112
|
+
error.className = cls('fieldError');
|
|
113
|
+
wrapper.appendChild(error);
|
|
114
|
+
|
|
115
|
+
this._wrapper = wrapper;
|
|
116
|
+
this._error = error;
|
|
117
|
+
|
|
118
|
+
return wrapper;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
getValue(): string | null {
|
|
122
|
+
const checked = this._inputs?.find(i => i.checked);
|
|
123
|
+
return checked?.value ?? null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
setValue(value: string | number): void {
|
|
127
|
+
if (this._inputs) {
|
|
128
|
+
this._inputs.forEach(input => {
|
|
129
|
+
input.checked = input.value === String(value);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
showError(message: string): void {
|
|
135
|
+
if (this._wrapper && this._error) {
|
|
136
|
+
this._wrapper.classList.add(cls('hasError'));
|
|
137
|
+
this._error.classList.add(cls('fieldErrorVisible'));
|
|
138
|
+
this._error.textContent = message;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
clearError(): void {
|
|
143
|
+
if (this._wrapper && this._error) {
|
|
144
|
+
this._wrapper.classList.remove(cls('hasError'));
|
|
145
|
+
this._error.classList.remove(cls('fieldErrorVisible'));
|
|
146
|
+
this._error.textContent = '';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|