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.
Files changed (154) hide show
  1. package/components/EzBaseComponent.ts +648 -0
  2. package/components/EzComponent.ts +89 -0
  3. package/components/EzInput.module.scss +183 -0
  4. package/components/EzInput.ts +104 -0
  5. package/components/EzLabel.ts +22 -0
  6. package/components/EzOutlet.ts +181 -0
  7. package/components/HtmlWrapper.ts +305 -0
  8. package/components/avatar/EzAvatar.module.scss +200 -0
  9. package/components/avatar/EzAvatar.ts +130 -0
  10. package/components/badge/EzBadge.module.scss +202 -0
  11. package/components/badge/EzBadge.ts +77 -0
  12. package/components/button/EzButton.module.scss +402 -0
  13. package/components/button/EzButton.ts +175 -0
  14. package/components/button/EzButtonGroup.ts +48 -0
  15. package/components/card/EzCard.module.scss +71 -0
  16. package/components/card/EzCard.ts +120 -0
  17. package/components/chart/EzBarChart.ts +47 -0
  18. package/components/chart/EzChart.module.scss +14 -0
  19. package/components/chart/EzChart.ts +279 -0
  20. package/components/chart/EzDoughnutChart.ts +47 -0
  21. package/components/chart/EzLineChart.ts +53 -0
  22. package/components/checkbox/EzCheckbox.module.scss +145 -0
  23. package/components/checkbox/EzCheckbox.ts +115 -0
  24. package/components/dataview/EzDataView.module.scss +115 -0
  25. package/components/dataview/EzDataView.ts +355 -0
  26. package/components/dataview/modes/EzDataViewCards.ts +322 -0
  27. package/components/dataview/modes/EzDataViewGrid.ts +76 -0
  28. package/components/datepicker/EzDatePicker.module.scss +348 -0
  29. package/components/datepicker/EzDatePicker.ts +519 -0
  30. package/components/dialog/EzDialog.module.scss +180 -0
  31. package/components/dropdown/EzDropdown.module.scss +107 -0
  32. package/components/dropdown/EzDropdown.ts +235 -0
  33. package/components/feed/EzActivityFeed.module.scss +90 -0
  34. package/components/feed/EzActivityFeed.ts +78 -0
  35. package/components/form/EzForm.ts +364 -0
  36. package/components/form/EzValidators.test.js +421 -0
  37. package/components/form/EzValidators.ts +202 -0
  38. package/components/grid/EzGrid.scss +88 -0
  39. package/components/grid/EzGrid.ts +1085 -0
  40. package/components/grid/EzGridContainer.ts +104 -0
  41. package/components/grid/body/EzGridBody.scss +283 -0
  42. package/components/grid/body/EzGridBody.ts +549 -0
  43. package/components/grid/body/EzGridCell.ts +211 -0
  44. package/components/grid/body/EzGridRow.ts +196 -0
  45. package/components/grid/filter/EzGridFilters.scss +78 -0
  46. package/components/grid/filter/EzGridFilters.ts +285 -0
  47. package/components/grid/footer/EzGridFooter.scss +136 -0
  48. package/components/grid/footer/EzGridFooter.ts +448 -0
  49. package/components/grid/header/EzGridHeader.scss +199 -0
  50. package/components/grid/header/EzGridHeader.ts +430 -0
  51. package/components/grid/query/EzGridQuery.ts +81 -0
  52. package/components/grid/state/EzGridColumns.ts +155 -0
  53. package/components/grid/state/EzGridController.ts +470 -0
  54. package/components/grid/state/EzGridLifecycle.ts +136 -0
  55. package/components/grid/state/EzGridNormalizers.test.js +273 -0
  56. package/components/grid/state/EzGridNormalizers.ts +162 -0
  57. package/components/grid/state/EzGridParts.ts +233 -0
  58. package/components/grid/state/EzGridPersistence.ts +140 -0
  59. package/components/grid/state/EzGridRemote.test.js +573 -0
  60. package/components/grid/state/EzGridRemote.ts +335 -0
  61. package/components/grid/state/EzGridSelection.ts +231 -0
  62. package/components/grid/state/EzGridSort.ts +286 -0
  63. package/components/grid/title/EzGridActionBar.ts +98 -0
  64. package/components/grid/title/EzGridTitle.ts +114 -0
  65. package/components/grid/title/EzGridTitleBar.scss +65 -0
  66. package/components/grid/title/EzGridTitleBar.ts +87 -0
  67. package/components/grid/types.ts +607 -0
  68. package/components/panel/EzPanel.module.scss +133 -0
  69. package/components/panel/EzPanel.ts +147 -0
  70. package/components/radio/EzRadio.module.scss +190 -0
  71. package/components/radio/EzRadio.ts +149 -0
  72. package/components/select/EzSelect.module.scss +153 -0
  73. package/components/select/EzSelect.ts +238 -0
  74. package/components/skeleton/EzSkeleton.module.scss +95 -0
  75. package/components/skeleton/EzSkeleton.ts +70 -0
  76. package/components/store/EzStore.ts +344 -0
  77. package/components/switch/EzSwitch.module.scss +164 -0
  78. package/components/switch/EzSwitch.ts +117 -0
  79. package/components/tabs/EzTabPanel.module.scss +181 -0
  80. package/components/tabs/EzTabPanel.ts +402 -0
  81. package/components/textarea/EzTextarea.module.scss +131 -0
  82. package/components/textarea/EzTextarea.ts +161 -0
  83. package/components/timepicker/EzTimePicker.module.scss +282 -0
  84. package/components/timepicker/EzTimePicker.ts +540 -0
  85. package/components/toast/EzToast.module.scss +291 -0
  86. package/components/tooltip/EzTooltip.module.scss +124 -0
  87. package/components/tooltip/EzTooltip.ts +153 -0
  88. package/core/EzComponentTypes.ts +693 -0
  89. package/core/EzError.ts +63 -0
  90. package/core/EzModel.ts +268 -0
  91. package/core/EzTypes.ts +328 -0
  92. package/core/eventBus.ts +284 -0
  93. package/core/ez.ts +617 -0
  94. package/core/loader.ts +725 -0
  95. package/core/renderer.ts +1010 -0
  96. package/core/router.ts +490 -0
  97. package/core/services.ts +124 -0
  98. package/core/state.ts +142 -0
  99. package/core/utils.ts +81 -0
  100. package/package.json +51 -0
  101. package/services/RouteUI.js +17 -0
  102. package/services/crypto.js +64 -0
  103. package/services/dialog.js +222 -0
  104. package/services/fetchApi.js +63 -0
  105. package/services/firebase.js +30 -0
  106. package/services/toast.js +214 -0
  107. package/template/doc/EzDocs.js +15 -0
  108. package/template/doc/EzDocs.module.scss +627 -0
  109. package/template/doc/EzDocsController.js +164 -0
  110. package/template/doc/data/activityfeed/EzActivityFeedDoc.js +42 -0
  111. package/template/doc/data/avatar/EzAvatarDoc.js +71 -0
  112. package/template/doc/data/badge/EzBadgeDoc.js +92 -0
  113. package/template/doc/data/button/EzButtonDoc.js +77 -0
  114. package/template/doc/data/buttongroup/EzButtonGroupDoc.js +102 -0
  115. package/template/doc/data/card/EzCardDoc.js +39 -0
  116. package/template/doc/data/chart/EzChartDoc.js +60 -0
  117. package/template/doc/data/checkbox/EzCheckboxDoc.js +67 -0
  118. package/template/doc/data/component/EzComponentDoc.js +34 -0
  119. package/template/doc/data/cssmodules/CSSModulesDoc.js +70 -0
  120. package/template/doc/data/datepicker/EzDatePickerDoc.js +126 -0
  121. package/template/doc/data/dialog/EzDialogDoc.js +217 -0
  122. package/template/doc/data/dropdown/EzDropdownDoc.js +178 -0
  123. package/template/doc/data/form/EzFormDoc.js +90 -0
  124. package/template/doc/data/grid/EzGridDoc.js +99 -0
  125. package/template/doc/data/input/EzInputDoc.js +92 -0
  126. package/template/doc/data/label/EzLabelDoc.js +40 -0
  127. package/template/doc/data/model/EzModelDoc.js +53 -0
  128. package/template/doc/data/outlet/EzOutletDoc.js +63 -0
  129. package/template/doc/data/panel/EzPanelDoc.js +214 -0
  130. package/template/doc/data/radio/EzRadioDoc.js +174 -0
  131. package/template/doc/data/router/EzRouterDoc.js +75 -0
  132. package/template/doc/data/select/EzSelectDoc.js +37 -0
  133. package/template/doc/data/skeleton/EzSkeletonDoc.js +149 -0
  134. package/template/doc/data/switch/EzSwitchDoc.js +82 -0
  135. package/template/doc/data/tabpanel/EzTabPanelDoc.js +44 -0
  136. package/template/doc/data/textarea/EzTextareaDoc.js +131 -0
  137. package/template/doc/data/timepicker/EzTimePickerDoc.js +107 -0
  138. package/template/doc/data/tooltip/EzTooltipDoc.js +193 -0
  139. package/template/doc/data/validators/EzValidatorsDoc.js +37 -0
  140. package/template/doc/sidebar/EzDocsSidebar.js +32 -0
  141. package/template/doc/sidebar/category/EzDocsCategory.js +33 -0
  142. package/template/doc/sidebar/item/EzDocsComponentItem.js +24 -0
  143. package/template/doc/viewer/EzDocsViewer.js +18 -0
  144. package/template/doc/viewer/codepanel/EzDocsCodePanel.js +51 -0
  145. package/template/doc/viewer/content/EzDocsContent.js +315 -0
  146. package/template/doc/viewer/header/EzDocsViewerHeader.js +46 -0
  147. package/template/doc/viewer/showcase/EzDocsShowcase.js +59 -0
  148. package/template/doc/viewer/showcase/EzDocsShowcaseSection.js +25 -0
  149. package/template/doc/viewer/showcase/EzDocsVariantItem.js +29 -0
  150. package/template/doc/welcome/EzDocsWelcome.js +48 -0
  151. package/themes/ez-theme.scss +179 -0
  152. package/themes/nature-fresh.scss +169 -0
  153. package/types/global.d.ts +21 -0
  154. package/utils/cssModules.js +81 -0
@@ -0,0 +1,279 @@
1
+ import { EzBaseComponent, EzBaseComponentConfig } from '../EzBaseComponent.js';
2
+ import styles from './EzChart.module.scss';
3
+
4
+ declare const ez: {
5
+ registerComponent(name: string, component: unknown): void;
6
+ };
7
+
8
+ declare const Chart: new (canvas: HTMLCanvasElement, config: ChartConfiguration) => ChartInstance;
9
+
10
+ interface ChartInstance {
11
+ data: ChartData;
12
+ update(): void;
13
+ destroy(): void;
14
+ }
15
+
16
+ interface ChartData {
17
+ labels?: string[];
18
+ datasets?: ChartDataset[];
19
+ }
20
+
21
+ interface ChartDataset {
22
+ data?: number[];
23
+ backgroundColor?: string | string[];
24
+ borderColor?: string;
25
+ borderWidth?: number;
26
+ tension?: number;
27
+ fill?: boolean;
28
+ pointRadius?: number;
29
+ pointHoverRadius?: number;
30
+ borderRadius?: number;
31
+ borderSkipped?: boolean | string;
32
+ [key: string]: unknown;
33
+ }
34
+
35
+ interface ChartConfiguration {
36
+ type: string;
37
+ data: ChartData;
38
+ options?: ChartOptions;
39
+ }
40
+
41
+ interface ChartOptions {
42
+ responsive?: boolean;
43
+ maintainAspectRatio?: boolean;
44
+ plugins?: {
45
+ legend?: {
46
+ display?: boolean;
47
+ position?: string;
48
+ labels?: {
49
+ color?: string;
50
+ font?: { size?: number; family?: string };
51
+ padding?: number;
52
+ usePointStyle?: boolean;
53
+ };
54
+ };
55
+ tooltip?: {
56
+ backgroundColor?: string;
57
+ titleColor?: string;
58
+ bodyColor?: string;
59
+ padding?: number;
60
+ cornerRadius?: number;
61
+ titleFont?: { size?: number };
62
+ bodyFont?: { size?: number };
63
+ };
64
+ };
65
+ scales?: {
66
+ x?: {
67
+ ticks?: { color?: string };
68
+ grid?: { color?: string; drawBorder?: boolean };
69
+ };
70
+ y?: {
71
+ ticks?: { color?: string };
72
+ grid?: { color?: string; drawBorder?: boolean };
73
+ beginAtZero?: boolean;
74
+ };
75
+ };
76
+ cutout?: string;
77
+ [key: string]: unknown;
78
+ }
79
+
80
+ interface ThemeColors {
81
+ primary: string;
82
+ primaryLight: string;
83
+ accent: string;
84
+ success: string;
85
+ warning: string;
86
+ danger: string;
87
+ text: string;
88
+ border: string;
89
+ palette: string[];
90
+ }
91
+
92
+ let chartJsLoaded = false;
93
+ let chartJsLoading: Promise<void> | null = null;
94
+
95
+ export interface EzChartConfig extends EzBaseComponentConfig {
96
+ type?: string;
97
+ data?: ChartData;
98
+ options?: ChartOptions;
99
+ height?: number | string;
100
+ showLegend?: boolean;
101
+ legendPosition?: string;
102
+ labels?: string[];
103
+ datasets?: ChartDataset[];
104
+ values?: number[];
105
+ colors?: string[];
106
+ datasetOptions?: Record<string, unknown>;
107
+ }
108
+
109
+ export class EzChart extends EzBaseComponent {
110
+ declare config: EzChartConfig;
111
+
112
+ protected _chart: ChartInstance | null = null;
113
+ protected _el: HTMLElement | null = null;
114
+ protected _canvas: HTMLCanvasElement | null = null;
115
+
116
+ constructor(config: EzChartConfig = {}) {
117
+ super(config);
118
+ this.config = config;
119
+ }
120
+
121
+ async render(): Promise<HTMLElement> {
122
+ await this._ensureChartJs();
123
+
124
+ const { height = 280, cls = '' } = this.config;
125
+
126
+ const el = document.createElement('div');
127
+ el.className = `${styles.container} ${cls}`.trim();
128
+ if (height) {
129
+ el.style.height = typeof height === 'number' ? `${height}px` : height;
130
+ }
131
+
132
+ const canvas = document.createElement('canvas');
133
+ el.appendChild(canvas);
134
+
135
+ this.applyStyles(el);
136
+
137
+ requestAnimationFrame(() => {
138
+ this._initChart(canvas);
139
+ });
140
+
141
+ this._el = el;
142
+ this._canvas = canvas;
143
+ return el;
144
+ }
145
+
146
+ protected async _ensureChartJs(): Promise<void> {
147
+ if (chartJsLoaded) return;
148
+
149
+ if (chartJsLoading) {
150
+ await chartJsLoading;
151
+ return;
152
+ }
153
+
154
+ chartJsLoading = new Promise((resolve, reject) => {
155
+ const script = document.createElement('script');
156
+ script.src = 'https://cdn.jsdelivr.net/npm/chart.js';
157
+ script.onload = () => {
158
+ chartJsLoaded = true;
159
+ resolve();
160
+ };
161
+ script.onerror = () => {
162
+ reject(new Error('[EzChart] Failed to load Chart.js'));
163
+ };
164
+ document.head.appendChild(script);
165
+ });
166
+
167
+ await chartJsLoading;
168
+ }
169
+
170
+ protected _getThemeColors(): ThemeColors {
171
+ const root = getComputedStyle(document.documentElement);
172
+ return {
173
+ primary: root.getPropertyValue('--ez-primary').trim() || '#005871',
174
+ primaryLight: root.getPropertyValue('--ez-primary-light').trim() || 'rgba(0, 88, 113, 0.1)',
175
+ accent: root.getPropertyValue('--ez-accent').trim() || '#2E5283',
176
+ success: '#059669',
177
+ warning: '#d97706',
178
+ danger: '#dc2626',
179
+ text: root.getPropertyValue('--ez-text-secondary').trim() || '#64748b',
180
+ border: root.getPropertyValue('--ez-border').trim() || '#e2e8f0',
181
+ palette: ['#005871', '#98DDDF', '#2E5283', '#E3BD33', '#059669', '#d97706']
182
+ };
183
+ }
184
+
185
+ protected _initChart(canvas: HTMLCanvasElement): void {
186
+ const { type, data, options = {} } = this.config;
187
+
188
+ if (!type || !data) {
189
+ console.warn('[EzChart] type and data are required');
190
+ return;
191
+ }
192
+
193
+ const theme = this._getThemeColors();
194
+ const defaultOptions = this._getDefaultOptions(type, theme);
195
+ const mergedOptions = this._deepMerge(defaultOptions, options);
196
+
197
+ this._chart = new Chart(canvas, {
198
+ type,
199
+ data,
200
+ options: mergedOptions
201
+ });
202
+ }
203
+
204
+ protected _getDefaultOptions(type: string, theme: ThemeColors): ChartOptions {
205
+ const baseOptions: ChartOptions = {
206
+ responsive: true,
207
+ maintainAspectRatio: false,
208
+ plugins: {
209
+ legend: {
210
+ display: this.config.showLegend ?? (type === 'doughnut' || type === 'pie'),
211
+ position: this.config.legendPosition || 'bottom',
212
+ labels: {
213
+ color: theme.text,
214
+ font: { size: 12, family: 'inherit' },
215
+ padding: 16,
216
+ usePointStyle: true
217
+ }
218
+ },
219
+ tooltip: {
220
+ backgroundColor: 'rgba(0, 0, 0, 0.8)',
221
+ titleColor: '#ffffff',
222
+ bodyColor: '#ffffff',
223
+ padding: 12,
224
+ cornerRadius: 8,
225
+ titleFont: { size: 13 },
226
+ bodyFont: { size: 12 }
227
+ }
228
+ }
229
+ };
230
+
231
+ if (type !== 'doughnut' && type !== 'pie' && type !== 'polarArea' && type !== 'radar') {
232
+ baseOptions.scales = {
233
+ x: {
234
+ ticks: { color: theme.text },
235
+ grid: { color: theme.border, drawBorder: false }
236
+ },
237
+ y: {
238
+ ticks: { color: theme.text },
239
+ grid: { color: theme.border, drawBorder: false },
240
+ beginAtZero: true
241
+ }
242
+ };
243
+ }
244
+
245
+ return baseOptions;
246
+ }
247
+
248
+ protected _deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown> {
249
+ const result: Record<string, unknown> = { ...target };
250
+ for (const key in source) {
251
+ if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
252
+ result[key] = this._deepMerge(
253
+ (result[key] as Record<string, unknown>) || {},
254
+ source[key] as Record<string, unknown>
255
+ );
256
+ } else {
257
+ result[key] = source[key];
258
+ }
259
+ }
260
+ return result;
261
+ }
262
+
263
+ updateData(newData: ChartData): void {
264
+ if (this._chart) {
265
+ this._chart.data = newData;
266
+ this._chart.update();
267
+ }
268
+ }
269
+
270
+ destroy(): void {
271
+ if (this._chart) {
272
+ this._chart.destroy();
273
+ this._chart = null;
274
+ }
275
+ super.destroy();
276
+ }
277
+ }
278
+
279
+ ez.registerComponent('EzChart', EzChart);
@@ -0,0 +1,47 @@
1
+ import { EzChart, EzChartConfig } from './EzChart.js';
2
+
3
+ declare const ez: {
4
+ registerComponent(name: string, component: unknown): void;
5
+ };
6
+
7
+ export interface EzDoughnutChartConfig extends EzChartConfig {
8
+ labels?: string[];
9
+ values?: number[];
10
+ colors?: string[];
11
+ datasetOptions?: Record<string, unknown>;
12
+ }
13
+
14
+ export class EzDoughnutChart extends EzChart {
15
+ constructor(config: EzDoughnutChartConfig = {}) {
16
+ const doughnutDefaults: EzChartConfig = {
17
+ type: 'doughnut',
18
+ showLegend: true,
19
+ legendPosition: 'bottom',
20
+ ...config,
21
+ options: {
22
+ cutout: '65%',
23
+ ...config.options
24
+ }
25
+ };
26
+
27
+ if (doughnutDefaults.labels && doughnutDefaults.values) {
28
+ doughnutDefaults.data = {
29
+ labels: doughnutDefaults.labels,
30
+ datasets: [{
31
+ data: doughnutDefaults.values,
32
+ backgroundColor: doughnutDefaults.colors || ['#005871', '#98DDDF', '#2E5283', '#E3BD33', '#059669', '#d97706'],
33
+ borderWidth: 0,
34
+ ...doughnutDefaults.datasetOptions
35
+ }]
36
+ };
37
+ delete doughnutDefaults.labels;
38
+ delete doughnutDefaults.values;
39
+ delete doughnutDefaults.colors;
40
+ delete doughnutDefaults.datasetOptions;
41
+ }
42
+
43
+ super(doughnutDefaults);
44
+ }
45
+ }
46
+
47
+ ez.registerComponent('EzDoughnutChart', EzDoughnutChart);
@@ -0,0 +1,53 @@
1
+ import { EzChart, EzChartConfig } from './EzChart.js';
2
+
3
+ declare const ez: {
4
+ registerComponent(name: string, component: unknown): void;
5
+ };
6
+
7
+ interface LineDataset {
8
+ data?: number[];
9
+ label?: string;
10
+ tension?: number;
11
+ fill?: boolean;
12
+ borderWidth?: number;
13
+ pointRadius?: number;
14
+ pointHoverRadius?: number;
15
+ backgroundColor?: string;
16
+ borderColor?: string;
17
+ [key: string]: unknown;
18
+ }
19
+
20
+ export interface EzLineChartConfig extends EzChartConfig {
21
+ labels?: string[];
22
+ datasets?: LineDataset[];
23
+ }
24
+
25
+ export class EzLineChart extends EzChart {
26
+ constructor(config: EzLineChartConfig = {}) {
27
+ const lineDefaults: EzChartConfig = {
28
+ type: 'line',
29
+ showLegend: (config.datasets?.length || 0) > 1,
30
+ ...config
31
+ };
32
+
33
+ if (lineDefaults.labels && lineDefaults.datasets) {
34
+ lineDefaults.data = {
35
+ labels: lineDefaults.labels,
36
+ datasets: lineDefaults.datasets.map((ds) => ({
37
+ tension: 0.4,
38
+ fill: true,
39
+ borderWidth: 2,
40
+ pointRadius: 3,
41
+ pointHoverRadius: 5,
42
+ ...ds
43
+ }))
44
+ };
45
+ delete lineDefaults.labels;
46
+ delete lineDefaults.datasets;
47
+ }
48
+
49
+ super(lineDefaults);
50
+ }
51
+ }
52
+
53
+ ez.registerComponent('EzLineChart', EzLineChart);
@@ -0,0 +1,145 @@
1
+ .checkbox {
2
+ display: inline-flex;
3
+ align-items: center;
4
+ gap: 8px;
5
+ cursor: pointer;
6
+ user-select: none;
7
+ }
8
+
9
+ .input {
10
+ position: absolute;
11
+ opacity: 0;
12
+ width: 0;
13
+ height: 0;
14
+ pointer-events: none;
15
+ }
16
+
17
+ .box {
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ flex-shrink: 0;
22
+
23
+ width: 18px;
24
+ height: 18px;
25
+
26
+ background: var(--ez-input-bg, #ffffff);
27
+ border: 2px solid var(--ez-border, #cbd5e1);
28
+ border-radius: var(--ez-radius-sm, 4px);
29
+
30
+ transition: all 0.15s ease;
31
+ }
32
+
33
+ .check {
34
+ font-size: 10px;
35
+ color: #ffffff;
36
+ opacity: 0;
37
+ transform: scale(0.5);
38
+ transition: all 0.15s ease;
39
+ }
40
+
41
+ // Checked state
42
+ .input:checked + .box {
43
+ background: var(--ez-primary, #2563eb);
44
+ border-color: var(--ez-primary, #2563eb);
45
+
46
+ .check {
47
+ opacity: 1;
48
+ transform: scale(1);
49
+ }
50
+ }
51
+
52
+ // Focus state
53
+ .input:focus-visible + .box {
54
+ box-shadow: 0 0 0 2px var(--ez-primary-light, rgba(37, 99, 235, 0.3));
55
+ }
56
+
57
+ // Hover state
58
+ .checkbox:hover:not(.disabled) .box {
59
+ border-color: var(--ez-primary, #2563eb);
60
+ }
61
+
62
+ .label {
63
+ font-size: 14px;
64
+ color: var(--ez-text-primary, #1e293b);
65
+ }
66
+
67
+ // Disabled state
68
+ .disabled {
69
+ cursor: not-allowed;
70
+ pointer-events: none;
71
+ opacity: 0.5;
72
+
73
+ .box {
74
+ background: var(--ez-surface-primary, #f1f5f9);
75
+ }
76
+
77
+ .input:checked + .box {
78
+ background: var(--ez-primary, #2563eb);
79
+ opacity: 0.6;
80
+ }
81
+
82
+ .label {
83
+ color: var(--ez-text-tertiary, #94a3b8);
84
+ }
85
+ }
86
+
87
+ // Sizes
88
+ .sm {
89
+ gap: 6px;
90
+
91
+ .box {
92
+ width: 14px;
93
+ height: 14px;
94
+ border-radius: 3px;
95
+ }
96
+
97
+ .check {
98
+ font-size: 8px;
99
+ }
100
+
101
+ .label {
102
+ font-size: 13px;
103
+ }
104
+ }
105
+
106
+ .lg {
107
+ gap: 10px;
108
+
109
+ .box {
110
+ width: 22px;
111
+ height: 22px;
112
+ border-radius: 5px;
113
+ }
114
+
115
+ .check {
116
+ font-size: 12px;
117
+ }
118
+
119
+ .label {
120
+ font-size: 15px;
121
+ }
122
+ }
123
+
124
+ // Error state
125
+ .hasError {
126
+ .box {
127
+ border-color: var(--ez-danger, #dc2626);
128
+ }
129
+
130
+ .input:checked + .box {
131
+ background: var(--ez-danger, #dc2626);
132
+ border-color: var(--ez-danger, #dc2626);
133
+ }
134
+ }
135
+
136
+ .fieldError {
137
+ display: none;
138
+ font-size: 12px;
139
+ color: var(--ez-danger, #dc2626);
140
+ margin-left: auto;
141
+ }
142
+
143
+ .fieldErrorVisible {
144
+ display: block;
145
+ }
@@ -0,0 +1,115 @@
1
+ import styles from './EzCheckbox.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 EzCheckboxConfig extends EzBaseComponentConfig {
8
+ size?: 'sm' | 'lg';
9
+ disabled?: boolean;
10
+ value?: boolean;
11
+ name?: string;
12
+ formData?: string;
13
+ label?: string;
14
+ }
15
+
16
+ export class EzCheckbox extends EzBaseComponent {
17
+ declare config: EzCheckboxConfig;
18
+
19
+ private _wrapper: HTMLLabelElement | null = null;
20
+ private _input: HTMLInputElement | null = null;
21
+ private _error: HTMLDivElement | null = null;
22
+
23
+ render(): HTMLLabelElement {
24
+ const cfg = this.config;
25
+
26
+ const wrapper = document.createElement('label');
27
+ wrapper.className = cls(
28
+ 'checkbox',
29
+ cfg.size,
30
+ cfg.disabled && 'disabled'
31
+ );
32
+
33
+ const input = document.createElement('input');
34
+ input.type = 'checkbox';
35
+ input.className = cls('input');
36
+ input.checked = !!cfg.value;
37
+
38
+ if (cfg.disabled) input.disabled = true;
39
+ if (cfg.name) input.name = cfg.name;
40
+
41
+ if (cfg.name && cfg.formData) {
42
+ this.config.bind = `${cfg.formData}.${cfg.name}`;
43
+ }
44
+
45
+ const box = document.createElement('span');
46
+ box.className = cls('box');
47
+
48
+ const check = document.createElement('i');
49
+ check.className = cls('check', 'fa-solid fa-check');
50
+ box.appendChild(check);
51
+
52
+ this.applyCommonBindings(input);
53
+
54
+ const onChange = this._createOnChangeHandler();
55
+
56
+ input.addEventListener('change', e => {
57
+ if (onChange) {
58
+ onChange((e.target as HTMLInputElement).checked);
59
+ }
60
+ });
61
+
62
+ wrapper.appendChild(input);
63
+ wrapper.appendChild(box);
64
+
65
+ if (cfg.label) {
66
+ const label = document.createElement('span');
67
+ label.className = cls('label');
68
+ label.textContent = cfg.label;
69
+ wrapper.appendChild(label);
70
+ }
71
+
72
+ const error = document.createElement('div');
73
+ error.className = cls('fieldError');
74
+ wrapper.appendChild(error);
75
+
76
+ this._wrapper = wrapper;
77
+ this._input = input;
78
+ this._error = error;
79
+
80
+ return wrapper;
81
+ }
82
+
83
+ getValue(): boolean {
84
+ return this._input?.checked ?? false;
85
+ }
86
+
87
+ setValue(value: boolean): void {
88
+ if (this._input) {
89
+ this._input.checked = !!value;
90
+ }
91
+ }
92
+
93
+ toggle(): void {
94
+ if (this._input && !this._input.disabled) {
95
+ this._input.checked = !this._input.checked;
96
+ this._input.dispatchEvent(new Event('change', { bubbles: true }));
97
+ }
98
+ }
99
+
100
+ showError(message: string): void {
101
+ if (this._wrapper && this._error) {
102
+ this._wrapper.classList.add(cls('hasError'));
103
+ this._error.classList.add(cls('fieldErrorVisible'));
104
+ this._error.textContent = message;
105
+ }
106
+ }
107
+
108
+ clearError(): void {
109
+ if (this._wrapper && this._error) {
110
+ this._wrapper.classList.remove(cls('hasError'));
111
+ this._error.classList.remove(cls('fieldErrorVisible'));
112
+ this._error.textContent = '';
113
+ }
114
+ }
115
+ }