@tsiky/components-r19 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/.prettierignore +4 -0
- package/.prettierrc +9 -0
- package/.storybook/main.ts +17 -0
- package/.storybook/preview.ts +21 -0
- package/.storybook/vitest.setup.ts +7 -0
- package/README.md +69 -0
- package/chart.ts +1 -0
- package/eslint.config.js +40 -0
- package/index.html +13 -0
- package/index.ts +33 -0
- package/package.json +63 -0
- package/public/vite.svg +1 -0
- package/src/App.css +42 -0
- package/src/App.tsx +12 -0
- package/src/assets/accessibility.png +0 -0
- package/src/assets/accessibility.svg +1 -0
- package/src/assets/addon-library.png +0 -0
- package/src/assets/assets.png +0 -0
- package/src/assets/avif-test-image.avif +0 -0
- package/src/assets/context.png +0 -0
- package/src/assets/discord.svg +1 -0
- package/src/assets/docs.png +0 -0
- package/src/assets/figma-plugin.png +0 -0
- package/src/assets/github.svg +1 -0
- package/src/assets/react.svg +1 -0
- package/src/assets/share.png +0 -0
- package/src/assets/styling.png +0 -0
- package/src/assets/testing.png +0 -0
- package/src/assets/theming.png +0 -0
- package/src/assets/tutorials.svg +1 -0
- package/src/assets/youtube.svg +1 -0
- package/src/components/AddItemModal/AddItemModal.module.css +72 -0
- package/src/components/AddItemModal/AddItemModal.tsx +82 -0
- package/src/components/AddItemModal/index.ts +1 -0
- package/src/components/Alert/Alert.css +54 -0
- package/src/components/Alert/Alert.stories.tsx +82 -0
- package/src/components/Alert/Alert.tsx +85 -0
- package/src/components/Alert/AlertContext.tsx +200 -0
- package/src/components/Alert/AlertModels.ts +34 -0
- package/src/components/Alert/index.ts +3 -0
- package/src/components/AnnouncementPanel/FlexRowContainer.css +17 -0
- package/src/components/AnnouncementPanel/FlexRowContainer.stories.tsx +329 -0
- package/src/components/AnnouncementPanel/FlexRowContainer.tsx +24 -0
- package/src/components/AnnouncementPanel/ListBox/CounterListBox.css +56 -0
- package/src/components/AnnouncementPanel/ListBox/CounterListBox.stories.tsx +292 -0
- package/src/components/AnnouncementPanel/ListBox/CounterListBox.tsx +106 -0
- package/src/components/AnnouncementPanel/ListBox/SimpleListBox.css +57 -0
- package/src/components/AnnouncementPanel/ListBox/SimpleListBox.stories.tsx +189 -0
- package/src/components/AnnouncementPanel/ListBox/SimpleListBox.tsx +138 -0
- package/src/components/AnnouncementPanel/ListBox/TrendListBox.css +61 -0
- package/src/components/AnnouncementPanel/ListBox/TrendListBox.stories.tsx +257 -0
- package/src/components/AnnouncementPanel/ListBox/TrendListBox.tsx +90 -0
- package/src/components/AnnouncementPanel/ListBox/index.ts +3 -0
- package/src/components/AnnouncementPanel/ListContentContainer.css +23 -0
- package/src/components/AnnouncementPanel/ListContentContainer.stories.tsx +212 -0
- package/src/components/AnnouncementPanel/ListContentContainer.tsx +33 -0
- package/src/components/AnnouncementPanel/index.ts +3 -0
- package/src/components/BandChart/index.tsx +282 -0
- package/src/components/Button/Button.module.css +165 -0
- package/src/components/Button/Button.stories.ts +132 -0
- package/src/components/Button/Button.tsx +55 -0
- package/src/components/Button/button.css +29 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/ChartContainer/ChartContainer.css +116 -0
- package/src/components/ChartContainer/ChartContainer.stories.tsx +159 -0
- package/src/components/ChartContainer/ChartContainer.tsx +155 -0
- package/src/components/ChartContainer/index.ts +1 -0
- package/src/components/Charts/area-chart-admission/AreaChartAdmission.stories.tsx +65 -0
- package/src/components/Charts/area-chart-admission/AreaChartAdmission.tsx +89 -0
- package/src/components/Charts/area-chart-admission/content.json +48 -0
- package/src/components/Charts/area-chart-hospitalisation/AreaChartHospitalisation.stories.tsx +141 -0
- package/src/components/Charts/area-chart-hospitalisation/AreaChartHospitalisation.tsx +262 -0
- package/src/components/Charts/area-chart-hospitalisation/content.json +55 -0
- package/src/components/Charts/bar-chart/BarChart.stories.tsx +50 -0
- package/src/components/Charts/bar-chart/BarChart.tsx +132 -0
- package/src/components/Charts/bar-chart/content.json +15 -0
- package/src/components/Charts/boxplot-chart/BoxPlotChart.stories.tsx +63 -0
- package/src/components/Charts/boxplot-chart/BoxPlotChart.tsx +114 -0
- package/src/components/Charts/boxplot-chart/boxUtils.ts +22 -0
- package/src/components/Charts/boxplot-chart/content.json +11 -0
- package/src/components/Charts/mixed-chart/MixedChart.stories.tsx +83 -0
- package/src/components/Charts/mixed-chart/MixedChart.tsx +625 -0
- package/src/components/Charts/mixed-chart/content.json +34 -0
- package/src/components/Charts/sankey-adaptation/sankey.tsx +70 -0
- package/src/components/Charts/sankey-chart/SankeyChart.stories.tsx +69 -0
- package/src/components/Charts/sankey-chart/SankeyChart.tsx +155 -0
- package/src/components/Charts/sankey-chart/content.json +15 -0
- package/src/components/Charts/stacked-column/StackedColumn.stories.tsx +72 -0
- package/src/components/Charts/stacked-column/StackedColumn.tsx +406 -0
- package/src/components/Charts/stacked-column/content.json +37 -0
- package/src/components/Charts/stacked-column-one-hundred-percent/StackedColumnOneHundredPercent.stories.tsx +43 -0
- package/src/components/Charts/stacked-column-one-hundred-percent/StackedColumnOneHundredPercent.tsx +75 -0
- package/src/components/Charts/stacked-column-one-hundred-percent/content.json +6 -0
- package/src/components/CircularProgress/CircularProgress.css +79 -0
- package/src/components/CircularProgress/CircularProgress.stories.tsx +251 -0
- package/src/components/CircularProgress/CircularProgress.tsx +101 -0
- package/src/components/CircularProgress/index.ts +2 -0
- package/src/components/Configure.mdx +369 -0
- package/src/components/DayStatCard/DayStatCard.css +50 -0
- package/src/components/DayStatCard/DayStatCard.stories.tsx +273 -0
- package/src/components/DayStatCard/DayStatCard.tsx +69 -0
- package/src/components/DayStatCard/index.ts +2 -0
- package/src/components/DraggableSwitcher/DraggableSwitcherButton.tsx +58 -0
- package/src/components/DraggableSwitcher/context/useDraggableSwitcher.tsx +45 -0
- package/src/components/DraggableSwitcher/index.ts +2 -0
- package/src/components/DropdownMenu/DropdownMenu.css +100 -0
- package/src/components/DropdownMenu/DropdownMenu.stories.tsx +174 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +106 -0
- package/src/components/DropdownMenu/index.ts +1 -0
- package/src/components/DynamicForm/DynamicFom.stories.ts +773 -0
- package/src/components/DynamicForm/DynamicForm.module.css +468 -0
- package/src/components/DynamicForm/DynamicForm.tsx +224 -0
- package/src/components/DynamicForm/index.ts +3 -0
- package/src/components/DynamicForm/tools/form-metadata.ts +82 -0
- package/src/components/DynamicForm/tools/validation.ts +168 -0
- package/src/components/DynamicInput/DynamicInput.module.css +126 -0
- package/src/components/DynamicInput/DynamicInput.stories.ts +350 -0
- package/src/components/DynamicInput/DynamicInput.tsx +144 -0
- package/src/components/DynamicInput/index.ts +2 -0
- package/src/components/DynamicInput/input/CheckboxInput.tsx +41 -0
- package/src/components/DynamicInput/input/ColorInput.tsx +46 -0
- package/src/components/DynamicInput/input/DateInput.tsx +57 -0
- package/src/components/DynamicInput/input/FileInput.tsx +174 -0
- package/src/components/DynamicInput/input/InputWrapper.tsx +26 -0
- package/src/components/DynamicInput/input/RadioInput.tsx +46 -0
- package/src/components/DynamicInput/input/RangeInput.tsx +46 -0
- package/src/components/DynamicInput/input/SelectInput.tsx +75 -0
- package/src/components/DynamicInput/input/TextInput.tsx +101 -0
- package/src/components/DynamicInput/input/TextareaInput.tsx +47 -0
- package/src/components/DynamicInput/input/assets/ColorInput.module.css +48 -0
- package/src/components/DynamicInput/input/assets/DateInput.module.css +83 -0
- package/src/components/DynamicInput/input/assets/FileInput.module.css +133 -0
- package/src/components/DynamicInput/input/assets/RangeInput.module.css +169 -0
- package/src/components/DynamicInput/input/assets/SelectInput.module.css +95 -0
- package/src/components/DynamicInput/input/index.ts +10 -0
- package/src/components/DynamicTable/AdvancedFilters.tsx +196 -0
- package/src/components/DynamicTable/ColumnSorter.tsx +185 -0
- package/src/components/DynamicTable/Pagination.tsx +115 -0
- package/src/components/DynamicTable/TableBody.tsx +42 -0
- package/src/components/DynamicTable/TableCell.tsx +30 -0
- package/src/components/DynamicTable/TableHeader.tsx +34 -0
- package/src/components/DynamicTable/TableRow.tsx +56 -0
- package/src/components/DynamicTable/TableauDynamic.stories.ts +1014 -0
- package/src/components/DynamicTable/TableauDynamique.module.css +1287 -0
- package/src/components/DynamicTable/TableauDynamique.tsx +154 -0
- package/src/components/DynamicTable/filters/BooleanFilter.tsx +30 -0
- package/src/components/DynamicTable/filters/DateFilter.tsx +28 -0
- package/src/components/DynamicTable/filters/DateRangeFilter.tsx +51 -0
- package/src/components/DynamicTable/filters/FilterRenderer.tsx +117 -0
- package/src/components/DynamicTable/filters/MultiSelectFilter.tsx +59 -0
- package/src/components/DynamicTable/filters/NumberFilter.tsx +37 -0
- package/src/components/DynamicTable/filters/OperatorFilter.tsx +64 -0
- package/src/components/DynamicTable/filters/SelectFilter.tsx +69 -0
- package/src/components/DynamicTable/filters/TextFilter.tsx +39 -0
- package/src/components/DynamicTable/filters/index.ts +9 -0
- package/src/components/DynamicTable/hooks/index.ts +2 -0
- package/src/components/DynamicTable/hooks/useAsyncActions.ts +36 -0
- package/src/components/DynamicTable/hooks/useFilters.ts +142 -0
- package/src/components/DynamicTable/hooks/useTableData.ts +216 -0
- package/src/components/DynamicTable/index.ts +11 -0
- package/src/components/DynamicTable/tools/filterTypes.ts +118 -0
- package/src/components/DynamicTable/tools/index.ts +3 -0
- package/src/components/DynamicTable/tools/tableConfig.ts +96 -0
- package/src/components/DynamicTable/tools/tableTypes.ts +63 -0
- package/src/components/EntryControl/EntryControl.module.css +218 -0
- package/src/components/EntryControl/EntryControl.stories.tsx +71 -0
- package/src/components/EntryControl/EntryControl.tsx +117 -0
- package/src/components/EntryControl/index.ts +2 -0
- package/src/components/Grid/Grid.stories.tsx +94 -0
- package/src/components/Grid/Grid.tsx +214 -0
- package/src/components/Grid/grid.css +285 -0
- package/src/components/Grid/index.ts +2 -0
- package/src/components/Header/Header.stories.tsx +164 -0
- package/src/components/Header/Header.tsx +59 -0
- package/src/components/Header/header.css +31 -0
- package/src/components/Header/index.ts +1 -0
- package/src/components/IconText/IconText..stories.tsx +135 -0
- package/src/components/IconText/IconText.css +43 -0
- package/src/components/IconText/IconText.tsx +43 -0
- package/src/components/IconText/index.ts +1 -0
- package/src/components/LanguageSelector/LanguageSelector.css +31 -0
- package/src/components/LanguageSelector/LanguageSelector.stories.tsx +38 -0
- package/src/components/LanguageSelector/LanguageSelector.tsx +37 -0
- package/src/components/LanguageSelector/index.ts +1 -0
- package/src/components/Logo/Logo.css +89 -0
- package/src/components/Logo/Logo.stories.tsx +79 -0
- package/src/components/Logo/Logo.tsx +22 -0
- package/src/components/Logo/index.ts +2 -0
- package/src/components/MetricsPanel/MetricsItem.tsx +128 -0
- package/src/components/MetricsPanel/MetricsPanel.module.css +636 -0
- package/src/components/MetricsPanel/MetricsPanel.stories.tsx +692 -0
- package/src/components/MetricsPanel/MetricsPanel.tsx +282 -0
- package/src/components/MetricsPanel/PanelHeader.tsx +19 -0
- package/src/components/MetricsPanel/SummaryCard.tsx +61 -0
- package/src/components/MetricsPanel/index.ts +4 -0
- package/src/components/MetricsPanel/renderers/CompactRenderer.tsx +125 -0
- package/src/components/MetricsPanel/renderers/ImageCard.tsx +62 -0
- package/src/components/MetricsPanel/renderers/PertinenceCard.tsx +55 -0
- package/src/components/MetricsPanel/tools/MetricsPanelTypes.ts +62 -0
- package/src/components/MetricsPanel/tools/chooseDefaultRender.ts +50 -0
- package/src/components/MetricsPanel/tools/colorUtils.ts +39 -0
- package/src/components/MetricsPanel/tools/index.ts +2 -0
- package/src/components/ModuleHeader/ModuleHeader.css +37 -0
- package/src/components/ModuleHeader/ModuleHeader.stories.tsx +37 -0
- package/src/components/ModuleHeader/ModuleHeader.tsx +42 -0
- package/src/components/ModuleHeader/index.ts +1 -0
- package/src/components/ModuleSideBar/ModuleSideBar.css +227 -0
- package/src/components/ModuleSideBar/ModuleSideBar.stories.tsx +40 -0
- package/src/components/ModuleSideBar/ModuleSideBar.tsx +155 -0
- package/src/components/ModuleSideBar/index.ts +1 -0
- package/src/components/NavBar/NavBar.css +58 -0
- package/src/components/NavBar/NavBar.stories.tsx +169 -0
- package/src/components/NavBar/NavBar.tsx +100 -0
- package/src/components/NavBar/NavContext.tsx +30 -0
- package/src/components/NavBar/index.ts +2 -0
- package/src/components/NavItem/NavItem.css +29 -0
- package/src/components/NavItem/NavItem.tsx +58 -0
- package/src/components/NavItem/index.ts +1 -0
- package/src/components/Page/Dashboard.tsx +93 -0
- package/src/components/Page/Page.stories.ts +33 -0
- package/src/components/Page/Page.tsx +73 -0
- package/src/components/Page/page.css +81 -0
- package/src/components/PerformanceCard/PerformanceCard.module.css +232 -0
- package/src/components/PerformanceCard/PerformanceCard.stories.tsx +441 -0
- package/src/components/PerformanceCard/PerformanceCard.tsx +198 -0
- package/src/components/PerformanceCard/defaultHistogramRenderer.tsx +32 -0
- package/src/components/PerformanceCard/tools/types.ts +50 -0
- package/src/components/PerformanceCard/tools/usePerformanceCard.ts +93 -0
- package/src/components/PeriodRange/PeriodRange.module.css +158 -0
- package/src/components/PeriodRange/PeriodRange.stories.tsx +66 -0
- package/src/components/PeriodRange/PeriodRange.tsx +130 -0
- package/src/components/PeriodSelect/PeriodSelect.module.css +65 -0
- package/src/components/PeriodSelect/PeriodSelect.stories.tsx +40 -0
- package/src/components/PeriodSelect/PeriodSelect.tsx +42 -0
- package/src/components/PeriodSelect/index.ts +1 -0
- package/src/components/ScrollableHorizontale/ScrollableHorizontale.css +40 -0
- package/src/components/ScrollableHorizontale/ScrollableHorizontale.stories.tsx +133 -0
- package/src/components/ScrollableHorizontale/ScrollableHorizontale.tsx +29 -0
- package/src/components/ScrollableHorizontale/index.ts +1 -0
- package/src/components/SearchBar/SearchBar.css +40 -0
- package/src/components/SearchBar/SearchBar.stories.tsx +36 -0
- package/src/components/SearchBar/SearchBar.tsx +30 -0
- package/src/components/SearchBar/index.ts +1 -0
- package/src/components/SectionTitle/SectionTitle.css +21 -0
- package/src/components/SectionTitle/SectionTitle.stories.tsx +39 -0
- package/src/components/SectionTitle/SectionTitle.tsx +18 -0
- package/src/components/SideComponent/PatientEditor.tsx +64 -0
- package/src/components/SideComponent/SideComponent.css +179 -0
- package/src/components/SideComponent/SideComponent.stories.tsx +547 -0
- package/src/components/SideComponent/SideComponent.tsx +243 -0
- package/src/components/SideComponent/hooks/useBodyScrollLock.ts +15 -0
- package/src/components/SideComponent/index.ts +2 -0
- package/src/components/SideComponent/portal.ts +11 -0
- package/src/components/SubNavBar/SubNavBar.tsx +41 -0
- package/src/components/SubNavBar/index.ts +1 -0
- package/src/components/Switcher/Switcher.css +65 -0
- package/src/components/Switcher/Switcher.stories.tsx +153 -0
- package/src/components/Switcher/Switcher.tsx +83 -0
- package/src/components/Switcher/index.ts +1 -0
- package/src/components/Title/Title.stories.tsx +18 -0
- package/src/components/Title/Title.tsx +26 -0
- package/src/components/Title/index.ts +1 -0
- package/src/components/TranslationKey/TranslationKey.css +272 -0
- package/src/components/TranslationKey/TranslationKey.stories.tsx +50 -0
- package/src/components/TranslationKey/TranslationKey.tsx +245 -0
- package/src/components/TranslationKey/index.ts +1 -0
- package/src/components/TrendItem/TrendItem.css +36 -0
- package/src/components/TrendItem/TrendItem.stories.tsx +276 -0
- package/src/components/TrendItem/TrendItem.tsx +46 -0
- package/src/components/TrendItem/index.ts +1 -0
- package/src/components/TrendList/TrendList.css +16 -0
- package/src/components/TrendList/TrendList.stories.tsx +337 -0
- package/src/components/TrendList/TrendList.tsx +45 -0
- package/src/components/TrendList/index.ts +1 -0
- package/src/components/theme/ThemeSwitcherButton.tsx +64 -0
- package/src/components/theme/context/ThemeContext.tsx +61 -0
- package/src/components/theme/context/index.ts +2 -0
- package/src/components/theme/context/useThemeSwitcher.ts +18 -0
- package/src/components/theme/index.ts +1 -0
- package/src/index.css +68 -0
- package/src/main.tsx +10 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.app.json +27 -0
- package/tsconfig.json +4 -0
- package/tsconfig.node.json +25 -0
- package/vite.config.ts +43 -0
- package/vitest.shims.d.ts +1 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* tools/form-metadata.ts */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import type { ComponentType } from 'react';
|
|
4
|
+
|
|
5
|
+
export interface FieldOption {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FieldValidation {
|
|
11
|
+
minLength?: number;
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
pattern?: string;
|
|
14
|
+
min?: number | string;
|
|
15
|
+
max?: number | string;
|
|
16
|
+
minDate?: string;
|
|
17
|
+
maxDate?: string;
|
|
18
|
+
acceptedTypes?: string;
|
|
19
|
+
maxFileSize?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type FieldType =
|
|
23
|
+
| 'text'
|
|
24
|
+
| 'email'
|
|
25
|
+
| 'number'
|
|
26
|
+
| 'select'
|
|
27
|
+
| 'checkbox'
|
|
28
|
+
| 'textarea'
|
|
29
|
+
| 'date'
|
|
30
|
+
| 'radio'
|
|
31
|
+
| 'file'
|
|
32
|
+
| 'month'
|
|
33
|
+
| 'week'
|
|
34
|
+
| 'time'
|
|
35
|
+
| 'datetime-local'
|
|
36
|
+
| 'color'
|
|
37
|
+
| 'range'
|
|
38
|
+
| 'url'
|
|
39
|
+
| 'password'
|
|
40
|
+
| 'section';
|
|
41
|
+
|
|
42
|
+
export interface FieldMetadata {
|
|
43
|
+
disabled: boolean | undefined;
|
|
44
|
+
name: string;
|
|
45
|
+
type: FieldType;
|
|
46
|
+
label: string;
|
|
47
|
+
placeholder?: string;
|
|
48
|
+
required?: boolean;
|
|
49
|
+
options?: FieldOption[];
|
|
50
|
+
validation?: FieldValidation;
|
|
51
|
+
gridCol?: number;
|
|
52
|
+
attributes?: {
|
|
53
|
+
multiple?: boolean;
|
|
54
|
+
accept?: string;
|
|
55
|
+
step?: number | string;
|
|
56
|
+
icon?: string;
|
|
57
|
+
iconComponent?: ComponentType<any>;
|
|
58
|
+
iconPosition?: 'suffix' | 'prefix';
|
|
59
|
+
showPasswordToggle?: boolean;
|
|
60
|
+
};
|
|
61
|
+
help?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface FormSchema {
|
|
65
|
+
title: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
fields: FieldMetadata[];
|
|
68
|
+
submitText?: string;
|
|
69
|
+
layout?: 'grid' | 'stack';
|
|
70
|
+
columns?: number;
|
|
71
|
+
submitIcon?: string;
|
|
72
|
+
submitIconPosition?: 'left' | 'right';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function getFormSchema(modelClass: any): FormSchema {
|
|
76
|
+
return {
|
|
77
|
+
title: modelClass._formTitle || 'Formulaire',
|
|
78
|
+
description: modelClass._formDescription,
|
|
79
|
+
fields: modelClass._fieldMetadata || [],
|
|
80
|
+
submitText: modelClass._submitText || 'Valider',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { FieldMetadata } from './form-metadata';
|
|
2
|
+
|
|
3
|
+
export interface ValidationResult {
|
|
4
|
+
isValid: boolean;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function validateRequired(value: unknown, field: FieldMetadata): ValidationResult | null {
|
|
9
|
+
if (!field.required) return null;
|
|
10
|
+
|
|
11
|
+
if (field.type === 'checkbox' && !value) {
|
|
12
|
+
return { isValid: false, error: `${field.label} est requis` };
|
|
13
|
+
}
|
|
14
|
+
if (!value || (typeof value === 'string' && value.trim() === '')) {
|
|
15
|
+
return { isValid: false, error: `${field.label} est requis` };
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isEmpty(value: unknown): boolean {
|
|
21
|
+
return !value || (typeof value === 'string' && value.trim() === '');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function validateEmail(value: string): ValidationResult | null {
|
|
25
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
26
|
+
if (!emailRegex.test(value)) {
|
|
27
|
+
return { isValid: false, error: "Format d'email invalide" };
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function validateUrl(value: string): ValidationResult | null {
|
|
33
|
+
const urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/;
|
|
34
|
+
if (!urlRegex.test(value)) {
|
|
35
|
+
return { isValid: false, error: "Format d'URL invalide" };
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function validateNumber(value: unknown, field: FieldMetadata): ValidationResult | null {
|
|
41
|
+
const numValue = Number(value);
|
|
42
|
+
if (isNaN(numValue)) {
|
|
43
|
+
return { isValid: false, error: 'Doit être un nombre valide' };
|
|
44
|
+
}
|
|
45
|
+
if (field.validation?.min !== undefined && numValue < Number(field.validation.min)) {
|
|
46
|
+
return { isValid: false, error: `Doit être ≥ ${field.validation.min}` };
|
|
47
|
+
}
|
|
48
|
+
if (field.validation?.max !== undefined && numValue > Number(field.validation.max)) {
|
|
49
|
+
return { isValid: false, error: `Doit être ≤ ${field.validation.max}` };
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
function validateDate(value: any, field: FieldMetadata): ValidationResult | null {
|
|
56
|
+
if (field.validation?.minDate && new Date(value) < new Date(field.validation.minDate)) {
|
|
57
|
+
return { isValid: false, error: `Doit être après ${field.validation.minDate}` };
|
|
58
|
+
}
|
|
59
|
+
if (field.validation?.maxDate && new Date(value) > new Date(field.validation.maxDate)) {
|
|
60
|
+
return { isValid: false, error: `Doit être avant ${field.validation.maxDate}` };
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function validateFile(value: File, field: FieldMetadata): ValidationResult | null {
|
|
66
|
+
if (field.validation?.acceptedTypes) {
|
|
67
|
+
const acceptedTypes = field.validation.acceptedTypes.split(',');
|
|
68
|
+
const fileType = value.type;
|
|
69
|
+
if (!acceptedTypes.some((type) => fileType.match(type.replace('*', '.*')))) {
|
|
70
|
+
return { isValid: false, error: `Type de fichier non supporté: ${fileType}` };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (field.validation?.maxFileSize && value.size > field.validation.maxFileSize) {
|
|
74
|
+
const maxSizeMB = field.validation.maxFileSize / (1024 * 1024);
|
|
75
|
+
return { isValid: false, error: `Fichier trop volumineux (max ${maxSizeMB}MB)` };
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function validateCommonRules(value: string, field: FieldMetadata): ValidationResult | null {
|
|
81
|
+
if (!field.validation) return null;
|
|
82
|
+
|
|
83
|
+
if (field.validation.minLength && value.length < field.validation.minLength) {
|
|
84
|
+
return { isValid: false, error: `Minimum ${field.validation.minLength} caractères` };
|
|
85
|
+
}
|
|
86
|
+
if (field.validation.maxLength && value.length > field.validation.maxLength) {
|
|
87
|
+
return { isValid: false, error: `Maximum ${field.validation.maxLength} caractères` };
|
|
88
|
+
}
|
|
89
|
+
if (field.validation.pattern) {
|
|
90
|
+
const regex = new RegExp(field.validation.pattern);
|
|
91
|
+
if (!regex.test(value)) {
|
|
92
|
+
return { isValid: false, error: 'Format invalide' };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
export function validateField(value: any, field: FieldMetadata): ValidationResult {
|
|
100
|
+
// Validation obligatoire
|
|
101
|
+
const requiredCheck = validateRequired(value, field);
|
|
102
|
+
if (requiredCheck) return requiredCheck;
|
|
103
|
+
|
|
104
|
+
// Si vide et non requis => valide
|
|
105
|
+
if (isEmpty(value)) return { isValid: true };
|
|
106
|
+
|
|
107
|
+
const stringValue = value.toString();
|
|
108
|
+
|
|
109
|
+
// Validation selon type
|
|
110
|
+
switch (field.type) {
|
|
111
|
+
case 'email': {
|
|
112
|
+
const res = validateEmail(stringValue);
|
|
113
|
+
if (res) return res;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case 'url': {
|
|
117
|
+
const res = validateUrl(stringValue);
|
|
118
|
+
if (res) return res;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case 'number': {
|
|
122
|
+
const res = validateNumber(value, field);
|
|
123
|
+
if (res) return res;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case 'date':
|
|
127
|
+
case 'month':
|
|
128
|
+
case 'week':
|
|
129
|
+
case 'time':
|
|
130
|
+
case 'datetime-local': {
|
|
131
|
+
const res = validateDate(value, field);
|
|
132
|
+
if (res) return res;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'file': {
|
|
136
|
+
const res = validateFile(value as File, field);
|
|
137
|
+
if (res) return res;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Validation commune
|
|
143
|
+
const commonCheck = validateCommonRules(stringValue, field);
|
|
144
|
+
if (commonCheck) return commonCheck;
|
|
145
|
+
|
|
146
|
+
return { isValid: true };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function validateForm(
|
|
150
|
+
data: Record<string, unknown>,
|
|
151
|
+
fields: FieldMetadata[]
|
|
152
|
+
): {
|
|
153
|
+
isValid: boolean;
|
|
154
|
+
errors: Record<string, string>;
|
|
155
|
+
} {
|
|
156
|
+
const errors: Record<string, string> = {};
|
|
157
|
+
let isValid = true;
|
|
158
|
+
|
|
159
|
+
for (const field of fields) {
|
|
160
|
+
const result = validateField(data[field.name], field);
|
|
161
|
+
if (!result.isValid) {
|
|
162
|
+
errors[field.name] = result.error!;
|
|
163
|
+
isValid = false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return { isValid, errors };
|
|
168
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/* DynamicInput.module.css */
|
|
2
|
+
.container {
|
|
3
|
+
padding: 20px;
|
|
4
|
+
background-color: #f5f5f5;
|
|
5
|
+
border-radius: 8px;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.fieldGroup {
|
|
9
|
+
margin-bottom: 1.5rem;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.fieldLabel {
|
|
13
|
+
display: block;
|
|
14
|
+
margin-bottom: 0.5rem;
|
|
15
|
+
font-weight: 500;
|
|
16
|
+
color: #212529;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.required::after {
|
|
20
|
+
content: ' *';
|
|
21
|
+
color: #dc3545;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.fieldInput {
|
|
25
|
+
width: 100%;
|
|
26
|
+
padding: 0.5rem 1rem;
|
|
27
|
+
border: 1px solid #6c757d;
|
|
28
|
+
border-radius: 0.375rem;
|
|
29
|
+
transition:
|
|
30
|
+
border-color 0.15s ease-in-out,
|
|
31
|
+
box-shadow 0.15s ease-in-out;
|
|
32
|
+
line-height: 1.5;
|
|
33
|
+
font-size: 1rem;
|
|
34
|
+
background-color: #f8f9fa;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.fieldInput:focus {
|
|
38
|
+
border-color: #0d6efd;
|
|
39
|
+
outline: 0;
|
|
40
|
+
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.fieldInvalid {
|
|
44
|
+
border-color: #dc3545;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.fieldValid {
|
|
48
|
+
border-color: #198754;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.fieldError {
|
|
52
|
+
display: block;
|
|
53
|
+
margin-top: 0.25rem;
|
|
54
|
+
font-size: 0.875rem;
|
|
55
|
+
color: #dc3545;
|
|
56
|
+
font-weight: 500;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Styles spécifiques pour les radios */
|
|
60
|
+
.radioGroup {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-direction: column;
|
|
63
|
+
gap: 0.5rem;
|
|
64
|
+
background-color: transparent;
|
|
65
|
+
padding: 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.radioGroup .form-check {
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: 0.5rem;
|
|
72
|
+
background-color: transparent;
|
|
73
|
+
margin-bottom: 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.radioGroup .form-check-label {
|
|
77
|
+
color: #212529;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Styles pour les checkboxes */
|
|
81
|
+
.checkboxGroup {
|
|
82
|
+
display: flex;
|
|
83
|
+
flex-direction: column;
|
|
84
|
+
gap: 0.5rem;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.checkboxGroup .form-check {
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
gap: 0.5rem;
|
|
91
|
+
margin-bottom: 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Styles spécifiques pour les selects */
|
|
95
|
+
.selectInput select {
|
|
96
|
+
appearance: none;
|
|
97
|
+
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
|
|
98
|
+
background-repeat: no-repeat;
|
|
99
|
+
background-position: right 0.75rem center;
|
|
100
|
+
background-size: 1rem;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* Styles pour les textareas */
|
|
104
|
+
.textareaInput textarea {
|
|
105
|
+
resize: vertical;
|
|
106
|
+
min-height: 100px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Styles pour les champs désactivés */
|
|
110
|
+
.fieldInput:disabled {
|
|
111
|
+
background-color: rgba(0, 0, 0, 0.05);
|
|
112
|
+
cursor: not-allowed;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Amélioration de l'accessibilité pour le focus */
|
|
116
|
+
.fieldInput:focus-visible {
|
|
117
|
+
outline: 2px solid #0d6efd;
|
|
118
|
+
outline-offset: 2px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* Styles pour la grille dans AllInputs */
|
|
122
|
+
.gridContainer {
|
|
123
|
+
display: grid;
|
|
124
|
+
gap: 20px;
|
|
125
|
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
126
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
// eslint-disable-next-line storybook/no-renderer-packages
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import { DynamicInput } from './DynamicInput';
|
|
5
|
+
import type { FieldMetadata, FieldType } from '../DynamicForm/tools/form-metadata';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof DynamicInput> = {
|
|
8
|
+
title: 'Components/DynamicInput',
|
|
9
|
+
component: DynamicInput,
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: 'padded',
|
|
12
|
+
},
|
|
13
|
+
tags: ['autodocs'],
|
|
14
|
+
argTypes: {
|
|
15
|
+
error: {
|
|
16
|
+
control: 'text',
|
|
17
|
+
description: 'Error message to display',
|
|
18
|
+
},
|
|
19
|
+
touched: {
|
|
20
|
+
control: 'boolean',
|
|
21
|
+
description: 'Whether the field has been touched',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
type Story = StoryObj<typeof DynamicInput>;
|
|
28
|
+
|
|
29
|
+
// Wrapper component pour gérer l'état
|
|
30
|
+
const DynamicInputWrapper: React.FC<{
|
|
31
|
+
field: FieldMetadata;
|
|
32
|
+
error?: string;
|
|
33
|
+
touched?: boolean;
|
|
34
|
+
}> = (args) => {
|
|
35
|
+
const [value, setValue] = useState<unknown>('');
|
|
36
|
+
|
|
37
|
+
return React.createElement(
|
|
38
|
+
'div',
|
|
39
|
+
{ style: { maxWidth: '400px' } },
|
|
40
|
+
React.createElement(DynamicInput, {
|
|
41
|
+
field: args.field,
|
|
42
|
+
value: value,
|
|
43
|
+
onChange: setValue,
|
|
44
|
+
onBlur: () => console.log('Blurred'),
|
|
45
|
+
error: args.error,
|
|
46
|
+
touched: args.touched,
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Helper function pour créer des fields avec toutes les propriétés requises
|
|
52
|
+
const createField = (
|
|
53
|
+
overrides: Partial<FieldMetadata> & { name: string; type: FieldType; label: string }
|
|
54
|
+
): FieldMetadata => ({
|
|
55
|
+
disabled: false,
|
|
56
|
+
required: false,
|
|
57
|
+
placeholder: '',
|
|
58
|
+
options: [],
|
|
59
|
+
validation: {},
|
|
60
|
+
attributes: {},
|
|
61
|
+
...overrides,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Stories pour les différents types de champs
|
|
65
|
+
export const Text: Story = {
|
|
66
|
+
render: (args) =>
|
|
67
|
+
React.createElement(DynamicInputWrapper, {
|
|
68
|
+
...args,
|
|
69
|
+
field: createField({
|
|
70
|
+
type: 'text',
|
|
71
|
+
name: 'textField',
|
|
72
|
+
label: 'Text Input',
|
|
73
|
+
placeholder: 'Entrez votre texte',
|
|
74
|
+
}),
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const Textarea: Story = {
|
|
79
|
+
render: (args) =>
|
|
80
|
+
React.createElement(DynamicInputWrapper, {
|
|
81
|
+
...args,
|
|
82
|
+
field: createField({
|
|
83
|
+
type: 'textarea',
|
|
84
|
+
name: 'textareaField',
|
|
85
|
+
label: 'Textarea Input',
|
|
86
|
+
placeholder: 'Entrez votre texte long',
|
|
87
|
+
}),
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const Select: Story = {
|
|
92
|
+
render: (args) =>
|
|
93
|
+
React.createElement(DynamicInputWrapper, {
|
|
94
|
+
...args,
|
|
95
|
+
field: createField({
|
|
96
|
+
type: 'select',
|
|
97
|
+
name: 'selectField',
|
|
98
|
+
label: 'Select Input',
|
|
99
|
+
options: [
|
|
100
|
+
{ value: 'opt1', label: 'Option 1' },
|
|
101
|
+
{ value: 'opt2', label: 'Option 2' },
|
|
102
|
+
{ value: 'opt3', label: 'Option 3' },
|
|
103
|
+
],
|
|
104
|
+
}),
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const Checkbox: Story = {
|
|
109
|
+
render: (args) =>
|
|
110
|
+
React.createElement(DynamicInputWrapper, {
|
|
111
|
+
...args,
|
|
112
|
+
field: createField({
|
|
113
|
+
type: 'checkbox',
|
|
114
|
+
name: 'checkboxField',
|
|
115
|
+
label: 'Checkbox Input',
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const Radio: Story = {
|
|
121
|
+
render: (args) =>
|
|
122
|
+
React.createElement(DynamicInputWrapper, {
|
|
123
|
+
...args,
|
|
124
|
+
field: createField({
|
|
125
|
+
type: 'radio',
|
|
126
|
+
name: 'radioField',
|
|
127
|
+
label: 'Radio Input',
|
|
128
|
+
options: [
|
|
129
|
+
{ value: 'opt1', label: 'Option 1' },
|
|
130
|
+
{ value: 'opt2', label: 'Option 2' },
|
|
131
|
+
],
|
|
132
|
+
}),
|
|
133
|
+
}),
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const File: Story = {
|
|
137
|
+
render: (args) =>
|
|
138
|
+
React.createElement(DynamicInputWrapper, {
|
|
139
|
+
...args,
|
|
140
|
+
field: createField({
|
|
141
|
+
type: 'file',
|
|
142
|
+
name: 'fileField',
|
|
143
|
+
label: 'File Input',
|
|
144
|
+
}),
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const DateInput: Story = {
|
|
149
|
+
render: (args) =>
|
|
150
|
+
React.createElement(DynamicInputWrapper, {
|
|
151
|
+
...args,
|
|
152
|
+
field: createField({
|
|
153
|
+
type: 'date',
|
|
154
|
+
name: 'dateField',
|
|
155
|
+
label: 'Date Input',
|
|
156
|
+
}),
|
|
157
|
+
}),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const DateTimeLocal: Story = {
|
|
161
|
+
render: (args) =>
|
|
162
|
+
React.createElement(DynamicInputWrapper, {
|
|
163
|
+
...args,
|
|
164
|
+
field: createField({
|
|
165
|
+
type: 'datetime-local',
|
|
166
|
+
name: 'datetimeField',
|
|
167
|
+
label: 'Date & Time Input',
|
|
168
|
+
}),
|
|
169
|
+
}),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export const Time: Story = {
|
|
173
|
+
render: (args) =>
|
|
174
|
+
React.createElement(DynamicInputWrapper, {
|
|
175
|
+
...args,
|
|
176
|
+
field: createField({
|
|
177
|
+
type: 'time',
|
|
178
|
+
name: 'timeField',
|
|
179
|
+
label: 'Time Input',
|
|
180
|
+
}),
|
|
181
|
+
}),
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export const Month: Story = {
|
|
185
|
+
render: (args) =>
|
|
186
|
+
React.createElement(DynamicInputWrapper, {
|
|
187
|
+
...args,
|
|
188
|
+
field: createField({
|
|
189
|
+
type: 'month',
|
|
190
|
+
name: 'monthField',
|
|
191
|
+
label: 'Month Input',
|
|
192
|
+
}),
|
|
193
|
+
}),
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export const Week: Story = {
|
|
197
|
+
render: (args) =>
|
|
198
|
+
React.createElement(DynamicInputWrapper, {
|
|
199
|
+
...args,
|
|
200
|
+
field: createField({
|
|
201
|
+
type: 'week',
|
|
202
|
+
name: 'weekField',
|
|
203
|
+
label: 'Week Input',
|
|
204
|
+
}),
|
|
205
|
+
}),
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export const Range: Story = {
|
|
209
|
+
render: (args) =>
|
|
210
|
+
React.createElement(DynamicInputWrapper, {
|
|
211
|
+
...args,
|
|
212
|
+
field: createField({
|
|
213
|
+
type: 'range',
|
|
214
|
+
name: 'rangeField',
|
|
215
|
+
label: 'Range Input',
|
|
216
|
+
validation: { min: 0, max: 100 },
|
|
217
|
+
}),
|
|
218
|
+
}),
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export const Color: Story = {
|
|
222
|
+
render: (args) =>
|
|
223
|
+
React.createElement(DynamicInputWrapper, {
|
|
224
|
+
...args,
|
|
225
|
+
field: createField({
|
|
226
|
+
type: 'color',
|
|
227
|
+
name: 'colorField',
|
|
228
|
+
label: 'Color Input',
|
|
229
|
+
}),
|
|
230
|
+
}),
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// Story avec état d'erreur
|
|
234
|
+
export const WithError: Story = {
|
|
235
|
+
render: (args) =>
|
|
236
|
+
React.createElement(DynamicInputWrapper, {
|
|
237
|
+
...args,
|
|
238
|
+
field: createField({
|
|
239
|
+
type: 'text',
|
|
240
|
+
name: 'errorField',
|
|
241
|
+
label: 'Input avec erreur',
|
|
242
|
+
}),
|
|
243
|
+
error: 'Ce champ est requis',
|
|
244
|
+
touched: true,
|
|
245
|
+
}),
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// Story avec état requis
|
|
249
|
+
export const Required: Story = {
|
|
250
|
+
render: (args) =>
|
|
251
|
+
React.createElement(DynamicInputWrapper, {
|
|
252
|
+
...args,
|
|
253
|
+
field: createField({
|
|
254
|
+
type: 'text',
|
|
255
|
+
name: 'requiredField',
|
|
256
|
+
label: 'Input requis',
|
|
257
|
+
required: true,
|
|
258
|
+
}),
|
|
259
|
+
}),
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// Story avec champ désactivé
|
|
263
|
+
export const Disabled: Story = {
|
|
264
|
+
render: (args) =>
|
|
265
|
+
React.createElement(DynamicInputWrapper, {
|
|
266
|
+
...args,
|
|
267
|
+
field: createField({
|
|
268
|
+
type: 'text',
|
|
269
|
+
name: 'disabledField',
|
|
270
|
+
label: 'Input désactivé',
|
|
271
|
+
disabled: true,
|
|
272
|
+
}),
|
|
273
|
+
}),
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// Story avec plusieurs champs pour démontrer différents types
|
|
277
|
+
export const AllInputs: Story = {
|
|
278
|
+
render: () => {
|
|
279
|
+
const [values, setValues] = useState<Record<string, unknown>>({});
|
|
280
|
+
|
|
281
|
+
const handleChange = (fieldName: string, value: unknown) => {
|
|
282
|
+
setValues((prev) => ({ ...prev, [fieldName]: value }));
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const fields = [
|
|
286
|
+
createField({
|
|
287
|
+
type: 'text',
|
|
288
|
+
name: 'textField',
|
|
289
|
+
label: 'Text Input',
|
|
290
|
+
placeholder: 'Entrez votre texte',
|
|
291
|
+
}),
|
|
292
|
+
createField({
|
|
293
|
+
type: 'textarea',
|
|
294
|
+
name: 'textareaField',
|
|
295
|
+
label: 'Textarea Input',
|
|
296
|
+
placeholder: 'Entrez votre texte long',
|
|
297
|
+
}),
|
|
298
|
+
createField({
|
|
299
|
+
type: 'select',
|
|
300
|
+
name: 'selectField',
|
|
301
|
+
label: 'Select Input',
|
|
302
|
+
options: [
|
|
303
|
+
{ value: 'opt1', label: 'Option 1' },
|
|
304
|
+
{ value: 'opt2', label: 'Option 2' },
|
|
305
|
+
{ value: 'opt3', label: 'Option 3' },
|
|
306
|
+
],
|
|
307
|
+
}),
|
|
308
|
+
createField({
|
|
309
|
+
type: 'date',
|
|
310
|
+
name: 'dateField',
|
|
311
|
+
label: 'Date Input',
|
|
312
|
+
}),
|
|
313
|
+
createField({
|
|
314
|
+
type: 'datetime-local',
|
|
315
|
+
name: 'datetimeField',
|
|
316
|
+
label: 'Date & Time Input',
|
|
317
|
+
}),
|
|
318
|
+
createField({
|
|
319
|
+
type: 'color',
|
|
320
|
+
name: 'colorField',
|
|
321
|
+
label: 'Color Input',
|
|
322
|
+
}),
|
|
323
|
+
createField({
|
|
324
|
+
type: 'range',
|
|
325
|
+
name: 'rangeField',
|
|
326
|
+
label: 'Range Input',
|
|
327
|
+
validation: { min: 0, max: 100 },
|
|
328
|
+
}),
|
|
329
|
+
];
|
|
330
|
+
|
|
331
|
+
return React.createElement(
|
|
332
|
+
'div',
|
|
333
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: '20px', maxWidth: '400px' } },
|
|
334
|
+
...fields.map((field) =>
|
|
335
|
+
React.createElement(
|
|
336
|
+
'div',
|
|
337
|
+
{ key: field.name },
|
|
338
|
+
React.createElement(DynamicInput, {
|
|
339
|
+
field: field,
|
|
340
|
+
value: values[field.name] || '',
|
|
341
|
+
onChange: (value) => handleChange(field.name, value),
|
|
342
|
+
onBlur: () => console.log('Blurred'),
|
|
343
|
+
error: undefined,
|
|
344
|
+
touched: false,
|
|
345
|
+
})
|
|
346
|
+
)
|
|
347
|
+
)
|
|
348
|
+
);
|
|
349
|
+
},
|
|
350
|
+
};
|