@soyfri/shared-library 1.5.0 → 2.0.0-beta.1
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/build.js +75 -38
- package/dist/components/ActionMenu/ActionMenu.cjs +107 -0
- package/dist/components/ActionMenu/ActionMenu.cjs.map +1 -0
- package/dist/components/ActionMenu/ActionMenu.d.ts +60 -0
- package/dist/components/ActionMenu/ActionMenu.js +107 -0
- package/dist/components/ActionMenu/ActionMenu.js.map +1 -0
- package/dist/components/ActionMenu/index.d.ts +2 -0
- package/dist/components/ActionMenu.d.ts +6 -0
- package/dist/components/AppBar/AppBar.cjs +346 -0
- package/dist/components/AppBar/AppBar.cjs.map +1 -0
- package/dist/components/AppBar/AppBar.d.ts +55 -0
- package/dist/components/AppBar/AppBar.js +346 -0
- package/dist/components/AppBar/AppBar.js.map +1 -0
- package/dist/components/AppBar/AppBar.sx.d.ts +12 -0
- package/dist/components/AppBar/AppBarBrand.d.ts +31 -0
- package/dist/components/AppBar/AppBarContext.d.ts +18 -0
- package/dist/components/AppBar/AppBarMenuToggle.d.ts +39 -0
- package/dist/components/AppBar/AppBarUserMenu.d.ts +65 -0
- package/dist/components/AppBar/index.d.ts +12 -0
- package/dist/components/AppBar.d.ts +6 -0
- package/dist/components/Autocomplete/Autocomplete.cjs +259 -54
- package/dist/components/Autocomplete/Autocomplete.cjs.map +1 -1
- package/dist/components/Autocomplete/Autocomplete.d.ts +64 -9
- package/dist/components/Autocomplete/Autocomplete.definitions.d.ts +6 -0
- package/dist/components/Autocomplete/Autocomplete.helpers.d.ts +18 -0
- package/dist/components/Autocomplete/Autocomplete.js +261 -56
- package/dist/components/Autocomplete/Autocomplete.js.map +1 -1
- package/dist/components/Autocomplete/Autocomplete.sx.d.ts +7 -0
- package/dist/components/Autocomplete/Autocomplete.types.d.ts +1 -0
- package/dist/components/Autocomplete/_parts/AutocompleteChips.d.ts +19 -0
- package/dist/components/Autocomplete/_parts/AutocompleteLoader.d.ts +9 -0
- package/dist/components/Autocomplete/_parts/AutocompleteOption.d.ts +19 -0
- package/dist/components/Autocomplete/index.d.ts +2 -1
- package/dist/components/Autocomplete.d.ts +4 -0
- package/dist/components/Avatar/Avatar.cjs +116 -79
- package/dist/components/Avatar/Avatar.cjs.map +1 -1
- package/dist/components/Avatar/Avatar.d.ts +16 -2
- package/dist/components/Avatar/Avatar.definitions.d.ts +11 -0
- package/dist/components/Avatar/Avatar.js +117 -80
- package/dist/components/Avatar/Avatar.js.map +1 -1
- package/dist/components/Card/Card.cjs +168 -9
- package/dist/components/Card/Card.cjs.map +1 -1
- package/dist/components/Card/Card.d.ts +78 -8
- package/dist/components/Card/Card.js +170 -11
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Card/Card.sx.d.ts +17 -0
- package/dist/components/Card/index.d.ts +4 -1
- package/dist/components/Card.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.cjs +201 -3
- package/dist/components/DatePicker/DatePicker.cjs.map +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +47 -9
- package/dist/components/DatePicker/DatePicker.definitions.d.ts +1 -0
- package/dist/components/DatePicker/DatePicker.helpers.d.ts +7 -0
- package/dist/components/DatePicker/DatePicker.js +200 -2
- package/dist/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/components/DatePicker/DatePicker.sx.d.ts +9 -0
- package/dist/components/DatePicker/DatePicker.types.d.ts +1 -0
- package/dist/components/DatePicker/index.d.ts +2 -1
- package/dist/components/DatePicker.d.ts +4 -0
- package/dist/components/DateTimePicker/DateTimePicker.cjs +152 -138
- package/dist/components/DateTimePicker/DateTimePicker.cjs.map +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.d.ts +46 -9
- package/dist/components/DateTimePicker/DateTimePicker.definitions.d.ts +1 -0
- package/dist/components/DateTimePicker/DateTimePicker.helpers.d.ts +11 -0
- package/dist/components/DateTimePicker/DateTimePicker.js +152 -138
- package/dist/components/DateTimePicker/DateTimePicker.js.map +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.sx.d.ts +7 -0
- package/dist/components/DateTimePicker/DateTimePicker.types.d.ts +1 -0
- package/dist/components/DateTimePicker/index.d.ts +2 -1
- package/dist/components/DateTimePicker.d.ts +4 -0
- package/dist/components/Drawer/Drawer.cjs +271 -0
- package/dist/components/Drawer/Drawer.cjs.map +1 -0
- package/dist/components/Drawer/Drawer.d.ts +51 -0
- package/dist/components/Drawer/Drawer.js +271 -0
- package/dist/components/Drawer/Drawer.js.map +1 -0
- package/dist/components/Drawer/Drawer.sx.d.ts +23 -0
- package/dist/components/Drawer/DrawerContext.d.ts +18 -0
- package/dist/components/Drawer/DrawerItem.d.ts +35 -0
- package/dist/components/Drawer/index.d.ts +6 -0
- package/dist/components/Drawer.d.ts +6 -0
- package/dist/components/Icon/Icon.cjs +44 -3
- package/dist/components/Icon/Icon.cjs.map +1 -1
- package/dist/components/Icon/Icon.d.ts +34 -1
- package/dist/components/Icon/Icon.js +44 -3
- package/dist/components/Icon/Icon.js.map +1 -1
- package/dist/components/Input/Input.cjs +173 -3
- package/dist/components/Input/Input.cjs.map +1 -1
- package/dist/components/Input/Input.d.ts +20 -15
- package/dist/components/Input/Input.definitions.d.ts +5 -2
- package/dist/components/Input/Input.helpers.d.ts +14 -0
- package/dist/components/Input/Input.js +172 -2
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/Input/Input.sx.d.ts +8 -0
- package/dist/components/Input/Input.types.d.ts +1 -0
- package/dist/components/Input/index.d.ts +2 -1
- package/dist/components/Input.d.ts +4 -0
- package/dist/components/InputGroup/InputGroup.cjs +104 -91
- package/dist/components/InputGroup/InputGroup.cjs.map +1 -1
- package/dist/components/InputGroup/InputGroup.d.ts +37 -1
- package/dist/components/InputGroup/InputGroup.definitions.d.ts +6 -0
- package/dist/components/InputGroup/InputGroup.js +106 -93
- package/dist/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/components/Modal/Modal.cjs +226 -116
- package/dist/components/Modal/Modal.cjs.map +1 -1
- package/dist/components/Modal/Modal.d.ts +38 -2
- package/dist/components/Modal/Modal.js +227 -117
- package/dist/components/Modal/Modal.js.map +1 -1
- package/dist/components/Modal/ModalFooter.d.ts +9 -1
- package/dist/components/Modal/index.d.ts +5 -0
- package/dist/components/PageLoader/PageLoader.cjs +61 -0
- package/dist/components/PageLoader/PageLoader.cjs.map +1 -0
- package/dist/components/PageLoader/PageLoader.d.ts +38 -0
- package/dist/components/PageLoader/PageLoader.js +61 -0
- package/dist/components/PageLoader/PageLoader.js.map +1 -0
- package/dist/components/PageLoader/index.d.ts +2 -0
- package/dist/components/PageLoader.d.ts +6 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.cjs +79 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.cjs.map +1 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.d.ts +48 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.js +79 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.js.map +1 -0
- package/dist/components/ScrollTopButton/index.d.ts +4 -0
- package/dist/components/ScrollTopButton/scrollToTop.d.ts +29 -0
- package/dist/components/ScrollTopButton.d.ts +6 -0
- package/dist/components/Select/Select.cjs +446 -4
- package/dist/components/Select/Select.cjs.map +1 -1
- package/dist/components/Select/Select.d.ts +33 -13
- package/dist/components/Select/Select.definitions.d.ts +3 -0
- package/dist/components/Select/Select.helpers.d.ts +28 -0
- package/dist/components/Select/Select.js +445 -3
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/Select.sx.d.ts +7 -0
- package/dist/components/Select/Select.types.d.ts +1 -0
- package/dist/components/Select/_parts/SelectMenuItem.d.ts +20 -0
- package/dist/components/Select/_parts/SelectSearchHeader.d.ts +15 -0
- package/dist/components/Select/_parts/SelectValue.d.ts +22 -0
- package/dist/components/Select/index.d.ts +2 -1
- package/dist/components/Select.d.ts +4 -0
- package/dist/components/Stat/Stat.cjs +1 -1
- package/dist/components/Stat/Stat.js +1 -1
- package/dist/components/Stepper/Stepper.cjs +4 -1
- package/dist/components/Stepper/Stepper.cjs.map +1 -1
- package/dist/components/Stepper/Stepper.d.ts +5 -0
- package/dist/components/Stepper/Stepper.js +4 -1
- package/dist/components/Stepper/Stepper.js.map +1 -1
- package/dist/components/_shared/formField.sx.d.ts +33 -0
- package/dist/components/_shared/resolvePreset.d.ts +18 -0
- package/dist/formField.sx-CQ1mbk9M.cjs +76 -0
- package/dist/formField.sx-CQ1mbk9M.cjs.map +1 -0
- package/dist/formField.sx-DfVbMe0V.js +77 -0
- package/dist/formField.sx-DfVbMe0V.js.map +1 -0
- package/dist/hooks/Wizard/Wizard.cjs +7 -0
- package/dist/hooks/Wizard/Wizard.cjs.map +1 -0
- package/dist/hooks/Wizard/Wizard.js +7 -0
- package/dist/hooks/Wizard/Wizard.js.map +1 -0
- package/dist/hooks/Wizard/WizardContext.d.ts +67 -0
- package/dist/hooks/Wizard/index.d.ts +3 -0
- package/dist/hooks/Wizard/useWizard.d.ts +9 -0
- package/dist/hooks/Wizard.d.ts +2 -0
- package/dist/index.cjs +99 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +31 -2
- package/dist/index.js.map +1 -1
- package/dist/mui.d.ts +5 -0
- package/dist/resolvePreset-B-IB0ehH.js +15 -0
- package/dist/resolvePreset-B-IB0ehH.js.map +1 -0
- package/dist/resolvePreset-CT3kU-K2.cjs +14 -0
- package/dist/resolvePreset-CT3kU-K2.cjs.map +1 -0
- package/dist/styles.css +3 -112
- package/dist/theme/componentStyles.d.ts +32 -0
- package/dist/theme/tokens.d.ts +28 -0
- package/dist/useWizard-CWdIxZzX.cjs +94 -0
- package/dist/useWizard-CWdIxZzX.cjs.map +1 -0
- package/dist/useWizard-CWq--C3o.js +95 -0
- package/dist/useWizard-CWq--C3o.js.map +1 -0
- package/package.json +1 -1
- package/src/components/ActionMenu/ActionMenu.stories.tsx +230 -0
- package/src/components/ActionMenu/ActionMenu.tsx +174 -0
- package/src/components/ActionMenu/index.ts +2 -0
- package/src/components/AppBar/AppBar.stories.tsx +272 -0
- package/src/components/AppBar/AppBar.sx.ts +32 -0
- package/src/components/AppBar/AppBar.tsx +123 -0
- package/src/components/AppBar/AppBarBrand.tsx +120 -0
- package/src/components/AppBar/AppBarContext.ts +25 -0
- package/src/components/AppBar/AppBarMenuToggle.tsx +90 -0
- package/src/components/AppBar/AppBarUserMenu.tsx +217 -0
- package/src/components/AppBar/index.ts +25 -0
- package/src/components/Autocomplete/Autocomplete.definitions.ts +223 -0
- package/src/components/Autocomplete/Autocomplete.helpers.ts +60 -0
- package/src/components/Autocomplete/Autocomplete.stories.tsx +363 -2
- package/src/components/Autocomplete/Autocomplete.sx.ts +30 -0
- package/src/components/Autocomplete/Autocomplete.tsx +312 -90
- package/src/components/Autocomplete/Autocomplete.types.ts +13 -0
- package/src/components/Autocomplete/_parts/AutocompleteChips.tsx +55 -0
- package/src/components/Autocomplete/_parts/AutocompleteLoader.tsx +17 -0
- package/src/components/Autocomplete/_parts/AutocompleteOption.tsx +31 -0
- package/src/components/Autocomplete/index.ts +12 -1
- package/src/components/Avatar/Avatar.definitions.ts +162 -0
- package/src/components/Avatar/Avatar.stories.tsx +205 -1
- package/src/components/Avatar/Avatar.tsx +166 -103
- package/src/components/Card/Card.stories.tsx +205 -16
- package/src/components/Card/Card.sx.ts +104 -0
- package/src/components/Card/Card.tsx +191 -35
- package/src/components/Card/index.ts +9 -1
- package/src/components/DatePicker/DatePicker.definitions.ts +24 -1
- package/src/components/DatePicker/DatePicker.helpers.ts +24 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +29 -2
- package/src/components/DatePicker/DatePicker.sx.ts +33 -0
- package/src/components/DatePicker/DatePicker.tsx +163 -139
- package/src/components/DatePicker/DatePicker.types.ts +10 -0
- package/src/components/DatePicker/index.ts +9 -1
- package/src/components/DateTimePicker/DateTimePicker.definitions.ts +24 -0
- package/src/components/DateTimePicker/DateTimePicker.helpers.ts +38 -0
- package/src/components/DateTimePicker/DateTimePicker.stories.tsx +29 -1
- package/src/components/DateTimePicker/DateTimePicker.sx.ts +30 -0
- package/src/components/DateTimePicker/DateTimePicker.tsx +200 -166
- package/src/components/DateTimePicker/DateTimePicker.types.ts +10 -0
- package/src/components/DateTimePicker/index.ts +9 -1
- package/src/components/Drawer/Drawer.stories.tsx +270 -0
- package/src/components/Drawer/Drawer.sx.ts +106 -0
- package/src/components/Drawer/Drawer.tsx +214 -0
- package/src/components/Drawer/DrawerContext.ts +26 -0
- package/src/components/Drawer/DrawerItem.tsx +110 -0
- package/src/components/Drawer/index.ts +10 -0
- package/src/components/Flyout/Flyout.stories.tsx +26 -18
- package/src/components/Icon/Icon.stories.tsx +68 -1
- package/src/components/Icon/Icon.tsx +87 -6
- package/src/components/Input/Input.definitions.ts +74 -2
- package/src/components/Input/Input.helpers.ts +49 -0
- package/src/components/Input/Input.stories.tsx +116 -4
- package/src/components/Input/Input.sx.ts +42 -0
- package/src/components/Input/Input.tsx +117 -162
- package/src/components/Input/Input.types.ts +10 -0
- package/src/components/Input/index.ts +9 -1
- package/src/components/InputGroup/InputGroup.definitions.ts +158 -0
- package/src/components/InputGroup/InputGroup.stories.tsx +159 -28
- package/src/components/InputGroup/InputGroup.tsx +159 -116
- package/src/components/Modal/Modal.stories.tsx +434 -6
- package/src/components/Modal/Modal.tsx +303 -121
- package/src/components/Modal/ModalFooter.tsx +22 -12
- package/src/components/Modal/index.ts +6 -1
- package/src/components/PageLoader/PageLoader.stories.tsx +217 -0
- package/src/components/PageLoader/PageLoader.tsx +96 -0
- package/src/components/PageLoader/index.ts +2 -0
- package/src/components/ScrollTopButton/ScrollTopButton.stories.tsx +158 -0
- package/src/components/ScrollTopButton/ScrollTopButton.tsx +135 -0
- package/src/components/ScrollTopButton/index.ts +8 -0
- package/src/components/ScrollTopButton/scrollToTop.ts +37 -0
- package/src/components/Select/Select.definitions.ts +114 -0
- package/src/components/Select/Select.helpers.ts +71 -0
- package/src/components/Select/Select.stories.tsx +126 -8
- package/src/components/Select/Select.sx.ts +14 -0
- package/src/components/Select/Select.tsx +246 -285
- package/src/components/Select/Select.types.ts +15 -0
- package/src/components/Select/_parts/SelectMenuItem.tsx +40 -0
- package/src/components/Select/_parts/SelectSearchHeader.tsx +51 -0
- package/src/components/Select/_parts/SelectValue.tsx +96 -0
- package/src/components/Select/index.ts +14 -1
- package/src/components/Stepper/Stepper.tsx +17 -1
- package/src/components/Tooltip/Tooltip.stories.tsx +15 -3
- package/src/components/_shared/formField.sx.ts +118 -0
- package/src/components/_shared/resolvePreset.ts +35 -0
- package/src/hooks/Wizard/Wizard.stories.tsx +301 -0
- package/src/hooks/Wizard/WizardContext.tsx +166 -0
- package/src/hooks/Wizard/index.ts +6 -0
- package/src/hooks/Wizard/useWizard.ts +13 -0
- package/src/index.ts +17 -1
- package/src/mui.ts +44 -0
- package/src/theme/componentStyles.ts +47 -0
- package/src/theme/tokens.ts +43 -0
- package/dist/DatePicker-BSNboVhN.js +0 -201
- package/dist/DatePicker-BSNboVhN.js.map +0 -1
- package/dist/DatePicker-BoqxWAhj.cjs +0 -200
- package/dist/DatePicker-BoqxWAhj.cjs.map +0 -1
- package/dist/Input-DFHs7cJ_.js +0 -171
- package/dist/Input-DFHs7cJ_.js.map +0 -1
- package/dist/Input-c8MwNNPg.cjs +0 -170
- package/dist/Input-c8MwNNPg.cjs.map +0 -1
- package/dist/Select-BO2N56sm.cjs +0 -411
- package/dist/Select-BO2N56sm.cjs.map +0 -1
- package/dist/Select-BcLkyHSE.js +0 -412
- package/dist/Select-BcLkyHSE.js.map +0 -1
- package/dist/index.css +0 -3
|
@@ -1,165 +1,189 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
|
+
import type { SxProps, Theme } from '@mui/material';
|
|
3
|
+
import { useTheme } from '@mui/material/styles';
|
|
2
4
|
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
3
5
|
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
DatePicker as MuiDatePicker,
|
|
8
|
+
type DatePickerProps as MuiDatePickerProps,
|
|
9
|
+
} from '@mui/x-date-pickers/DatePicker';
|
|
5
10
|
import { DateValidationError } from '@mui/x-date-pickers/models';
|
|
6
11
|
import { Dayjs } from 'dayjs';
|
|
7
|
-
import {
|
|
8
|
-
import { Box, TextField } from '@mui/material';
|
|
12
|
+
import { Controller, type Control, type RegisterOptions } from 'react-hook-form';
|
|
9
13
|
import 'dayjs/locale/en-gb';
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
import { buildDatePickerSx } from './DatePicker.sx';
|
|
16
|
+
import { getDateValidationMessage } from './DatePicker.helpers';
|
|
17
|
+
import { resolvePreset } from '../_shared/resolvePreset';
|
|
18
|
+
|
|
19
|
+
// ── Tipos de dominio ─────────────────────────────────────────────────────
|
|
20
|
+
export type LabelPosition = 'outside' | 'floating';
|
|
21
|
+
export type DatePickerSize = 'small' | 'medium';
|
|
22
|
+
|
|
23
|
+
// ── Props base ───────────────────────────────────────────────────────────
|
|
24
|
+
export interface BaseDatePickerProps
|
|
25
|
+
extends Omit<MuiDatePickerProps, 'value' | 'onChange' | 'slotProps'> {
|
|
26
|
+
label?: string;
|
|
16
27
|
minDate?: Dayjs;
|
|
17
28
|
maxDate?: Dayjs;
|
|
18
29
|
disabled?: boolean;
|
|
19
30
|
readOnly?: boolean;
|
|
20
|
-
|
|
31
|
+
/** Border radius del input. Default: 10 */
|
|
32
|
+
borderRadius?: number | string;
|
|
33
|
+
/** "outside" = label arriba del campo (default). "floating" = label clásico MUI dentro del borde */
|
|
34
|
+
labelPosition?: LabelPosition;
|
|
35
|
+
/** Tamaño del TextField renderizado. Default: 'small' */
|
|
36
|
+
size?: DatePickerSize;
|
|
37
|
+
/** helperText pasado al TextField (se sobrescribe por el error de validación si hay). */
|
|
38
|
+
helperText?: string;
|
|
39
|
+
/** Error external override. */
|
|
40
|
+
error?: boolean;
|
|
41
|
+
/** sx que se mergea al TextField interno del picker. */
|
|
42
|
+
sx?: SxProps<Theme>;
|
|
43
|
+
className?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Nombre del preset de estilo registrado en `theme.styles.DatePicker`.
|
|
46
|
+
* - `"default"` (o ausente) = estilo built-in del paquete.
|
|
47
|
+
* - Cualquier otro string = mergea el preset encima del estilo built-in.
|
|
48
|
+
*/
|
|
49
|
+
preset?: string;
|
|
50
|
+
/** Locale para el adaptador dayjs. Default: 'en-gb'. */
|
|
51
|
+
adapterLocale?: string;
|
|
52
|
+
/** Passthrough a slotProps.textField. */
|
|
53
|
+
textFieldProps?: Record<string, any>;
|
|
54
|
+
/** Passthrough completo a slotProps del MuiDatePicker. */
|
|
55
|
+
slotProps?: MuiDatePickerProps['slotProps'];
|
|
21
56
|
}
|
|
22
57
|
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
minDate,
|
|
67
|
-
maxDate,
|
|
68
|
-
disabled,
|
|
69
|
-
readOnly,
|
|
70
|
-
slotProps,
|
|
71
|
-
...rest
|
|
72
|
-
}) => {
|
|
73
|
-
const [error, setError] = React.useState<DateValidationError | null>(null);
|
|
74
|
-
|
|
75
|
-
const errorMessage = useMemo(() => {
|
|
76
|
-
switch (error) {
|
|
77
|
-
case 'minDate':
|
|
78
|
-
case 'maxDate': {
|
|
79
|
-
return 'Fecha fuera del rango permitido';
|
|
80
|
-
}
|
|
81
|
-
case 'invalidDate': {
|
|
82
|
-
return 'Formato de fecha inválido';
|
|
83
|
-
}
|
|
84
|
-
case 'disableFuture': {
|
|
85
|
-
return 'No se permiten fechas futuras';
|
|
86
|
-
}
|
|
87
|
-
case 'disablePast': {
|
|
88
|
-
return 'No se permiten fechas pasadas';
|
|
89
|
-
}
|
|
90
|
-
default: {
|
|
91
|
-
return '';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}, [error]);
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="en-gb">
|
|
98
|
-
<Box
|
|
99
|
-
sx={{
|
|
100
|
-
width: '100%',
|
|
101
|
-
display: 'grid',
|
|
102
|
-
marginBottom: '10px',
|
|
103
|
-
marginTop: '10px'
|
|
104
|
-
}}
|
|
58
|
+
// ── Variantes discriminadas (RHF vs controlado) ──────────────────────────
|
|
59
|
+
export interface RHFDatePickerProps extends BaseDatePickerProps {
|
|
60
|
+
name: string;
|
|
61
|
+
control: Control<any>;
|
|
62
|
+
validation?: RegisterOptions;
|
|
63
|
+
selectedDate?: never;
|
|
64
|
+
onDateChange?: never;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ControlledDatePickerProps extends BaseDatePickerProps {
|
|
68
|
+
name?: string;
|
|
69
|
+
control?: never;
|
|
70
|
+
validation?: never;
|
|
71
|
+
selectedDate: Dayjs | null;
|
|
72
|
+
onDateChange: (date: Dayjs | null) => void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ── API pública final ────────────────────────────────────────────────────
|
|
76
|
+
export type DatePickerProps = RHFDatePickerProps | ControlledDatePickerProps;
|
|
77
|
+
|
|
78
|
+
export const DatePicker: React.FC<DatePickerProps> = (props) => {
|
|
79
|
+
const {
|
|
80
|
+
label,
|
|
81
|
+
minDate,
|
|
82
|
+
maxDate,
|
|
83
|
+
disabled,
|
|
84
|
+
readOnly,
|
|
85
|
+
borderRadius = 10,
|
|
86
|
+
labelPosition = 'outside',
|
|
87
|
+
size = 'small',
|
|
88
|
+
helperText,
|
|
89
|
+
error: errorProp,
|
|
90
|
+
sx,
|
|
91
|
+
className,
|
|
92
|
+
preset,
|
|
93
|
+
adapterLocale = 'en-gb',
|
|
94
|
+
textFieldProps,
|
|
95
|
+
slotProps: slotPropsProp,
|
|
96
|
+
...rest
|
|
97
|
+
} = props as ControlledDatePickerProps & {
|
|
98
|
+
control?: Control<any>;
|
|
99
|
+
validation?: RegisterOptions;
|
|
100
|
+
};
|
|
105
101
|
|
|
106
|
-
|
|
102
|
+
const [validationError, setValidationError] = React.useState<DateValidationError | null>(null);
|
|
103
|
+
|
|
104
|
+
const validationErrorMessage = useMemo(
|
|
105
|
+
() => getDateValidationMessage(validationError),
|
|
106
|
+
[validationError],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const theme = useTheme();
|
|
110
|
+
const presetSx = resolvePreset('DatePicker', preset, theme);
|
|
111
|
+
|
|
112
|
+
const mergedSx = [
|
|
113
|
+
buildDatePickerSx(borderRadius, labelPosition),
|
|
114
|
+
...(presetSx ? [presetSx] : []),
|
|
115
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const renderPicker = (
|
|
119
|
+
value: Dayjs | null,
|
|
120
|
+
onChange: (date: Dayjs | null) => void,
|
|
121
|
+
onBlur?: () => void,
|
|
122
|
+
inputRef?: React.Ref<any>,
|
|
123
|
+
rhfError?: boolean,
|
|
124
|
+
rhfHelperText?: string,
|
|
125
|
+
) => {
|
|
126
|
+
const finalError = rhfError || !!validationErrorMessage || !!errorProp;
|
|
127
|
+
const finalHelperText = rhfHelperText || validationErrorMessage || helperText;
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale={adapterLocale}>
|
|
107
131
|
<MuiDatePicker
|
|
108
132
|
label={label}
|
|
109
|
-
value={
|
|
110
|
-
onChange={
|
|
133
|
+
value={value}
|
|
134
|
+
onChange={onChange}
|
|
111
135
|
minDate={minDate}
|
|
112
136
|
maxDate={maxDate}
|
|
113
|
-
onError={
|
|
137
|
+
onError={setValidationError}
|
|
114
138
|
disabled={disabled}
|
|
115
139
|
readOnly={readOnly}
|
|
116
|
-
className=
|
|
117
|
-
sx={
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
'& .MuiPickersInputBase-root, .MuiPickersOutlinedInput-root': {
|
|
121
|
-
maxHeight: '28px',
|
|
122
|
-
borderRadius: '10px'
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
// 3. Sobreescribir el label para que esté centrado verticalmente
|
|
126
|
-
'& .MuiInputLabel-root': {
|
|
127
|
-
// El label se alinea con el padding del input base.
|
|
128
|
-
top: '50%',
|
|
129
|
-
transform: 'translate(14px, -50%)',
|
|
130
|
-
|
|
131
|
-
// Estilo para el label "encogido" cuando el input está lleno o en foco
|
|
132
|
-
'&.MuiInputLabel-shrink': {
|
|
133
|
-
transform: 'translate(1px, -200%) scale(0.75)', // Ajustar la posición para que se vea por encima del input
|
|
134
|
-
fontSize: '16px !important',
|
|
135
|
-
'> legend': {
|
|
136
|
-
display: 'none', // Ocultar el legend del outline
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
'& .MuiPickersInputBase-root > fieldset > legend':{
|
|
141
|
-
display: 'none', // Ocultar el legend del outline
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
}}
|
|
145
|
-
// 2. Usar 'slotProps' para pasar el componente estilizado al TextField
|
|
140
|
+
className={className}
|
|
141
|
+
sx={mergedSx}
|
|
146
142
|
slotProps={{
|
|
147
|
-
...
|
|
143
|
+
...slotPropsProp,
|
|
148
144
|
textField: {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
fullWidth: true,
|
|
146
|
+
size,
|
|
147
|
+
variant: 'outlined',
|
|
148
|
+
onBlur,
|
|
149
|
+
inputRef,
|
|
150
|
+
error: !!finalError,
|
|
151
|
+
helperText: finalHelperText,
|
|
152
|
+
...(slotPropsProp?.textField as Record<string, any> | undefined),
|
|
153
|
+
...textFieldProps,
|
|
154
|
+
} as any,
|
|
157
155
|
}}
|
|
158
|
-
{...rest}
|
|
156
|
+
{...(rest as any)}
|
|
159
157
|
/>
|
|
160
|
-
</
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
</LocalizationProvider>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// --- RHF mode ---
|
|
163
|
+
if ('control' in props && props.control) {
|
|
164
|
+
const { name, control, validation } = props as RHFDatePickerProps;
|
|
165
|
+
return (
|
|
166
|
+
<Controller
|
|
167
|
+
name={name}
|
|
168
|
+
control={control}
|
|
169
|
+
rules={validation}
|
|
170
|
+
render={({ field, fieldState: { error: fieldError } }) =>
|
|
171
|
+
renderPicker(
|
|
172
|
+
field.value ?? null,
|
|
173
|
+
field.onChange,
|
|
174
|
+
field.onBlur,
|
|
175
|
+
field.ref,
|
|
176
|
+
!!fieldError,
|
|
177
|
+
fieldError?.message,
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// --- Controlado ---
|
|
185
|
+
const { selectedDate, onDateChange } = props as ControlledDatePickerProps;
|
|
186
|
+
return renderPicker(selectedDate, onDateChange);
|
|
163
187
|
};
|
|
164
188
|
|
|
165
|
-
export default DatePicker;
|
|
189
|
+
export default DatePicker;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Re-export barrel para compatibilidad con imports antiguos.
|
|
2
|
+
// Los tipos ahora viven dentro de DatePicker.tsx.
|
|
3
|
+
export type {
|
|
4
|
+
LabelPosition,
|
|
5
|
+
DatePickerSize,
|
|
6
|
+
BaseDatePickerProps,
|
|
7
|
+
RHFDatePickerProps,
|
|
8
|
+
ControlledDatePickerProps,
|
|
9
|
+
DatePickerProps,
|
|
10
|
+
} from './DatePicker';
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export { default
|
|
1
|
+
export { DatePicker, default } from './DatePicker';
|
|
2
|
+
export type {
|
|
3
|
+
DatePickerProps,
|
|
4
|
+
BaseDatePickerProps,
|
|
5
|
+
RHFDatePickerProps,
|
|
6
|
+
ControlledDatePickerProps,
|
|
7
|
+
LabelPosition,
|
|
8
|
+
DatePickerSize,
|
|
9
|
+
} from './DatePicker.types';
|
|
@@ -207,6 +207,30 @@ export const DateTimePickerWithCustomButtonTextExample = () => {
|
|
|
207
207
|
};
|
|
208
208
|
`;
|
|
209
209
|
|
|
210
|
+
export const DateTimePickerEmptyWithMaskDefinition = `
|
|
211
|
+
import React, { useState } from 'react';
|
|
212
|
+
import { DateTimePicker } from './DateTimePicker'; // Ajusta la ruta si es necesario
|
|
213
|
+
import { Dayjs } from 'dayjs';
|
|
214
|
+
import { Box, Typography } from '@mui/material';
|
|
215
|
+
|
|
216
|
+
export const DateTimePickerEmptyWithMaskExample = () => {
|
|
217
|
+
const [selectedDateTime, setSelectedDateTime] = useState<Dayjs | null>(null);
|
|
218
|
+
return (
|
|
219
|
+
<Box sx={{ width: 300 }}>
|
|
220
|
+
<DateTimePicker
|
|
221
|
+
label="Fecha y Hora"
|
|
222
|
+
selectedDateTime={selectedDateTime}
|
|
223
|
+
onDateTimeChange={setSelectedDateTime}
|
|
224
|
+
inputFormat="DD/MM/YY HH:mm"
|
|
225
|
+
/>
|
|
226
|
+
<Typography sx={{ mt: 2 }} variant="caption" color="text.secondary">
|
|
227
|
+
Al estar vacío, el campo muestra la máscara del formato (DD/MM/AA HH:MM).
|
|
228
|
+
</Typography>
|
|
229
|
+
</Box>
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
`;
|
|
233
|
+
|
|
210
234
|
export const DateTimePickerWithCustomInputFormatDefinition = `
|
|
211
235
|
import React, { useState } from 'react';
|
|
212
236
|
import { DateTimePicker } from './DateTimePicker'; // Ajusta la ruta si es necesario
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { DateValidationError } from '@mui/x-date-pickers/models';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Traduce el error del DateTimePicker a un mensaje en español. Se usa
|
|
5
|
+
* internamente para poblar `helperText` cuando hay error de validación.
|
|
6
|
+
*/
|
|
7
|
+
export const getDateTimeValidationMessage = (
|
|
8
|
+
error: DateValidationError | null,
|
|
9
|
+
): string => {
|
|
10
|
+
switch (error) {
|
|
11
|
+
case 'minDate':
|
|
12
|
+
case 'maxDate':
|
|
13
|
+
case 'invalidDate':
|
|
14
|
+
return 'Formato de fecha/hora inválido';
|
|
15
|
+
case 'disableFuture':
|
|
16
|
+
return 'No se permiten fechas/horas futuras';
|
|
17
|
+
case 'disablePast':
|
|
18
|
+
return 'No se permiten fechas/horas pasadas';
|
|
19
|
+
default:
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Construye el `localeText` que MUI acepta para overridear los labels de los
|
|
26
|
+
* botones del popover (Cancel / OK / Clear).
|
|
27
|
+
*/
|
|
28
|
+
export const buildLocaleText = (
|
|
29
|
+
clearButtonText?: string,
|
|
30
|
+
cancelButtonText?: string,
|
|
31
|
+
acceptButtonText?: string,
|
|
32
|
+
): Record<string, string> => {
|
|
33
|
+
const text: Record<string, string> = {};
|
|
34
|
+
if (clearButtonText) text.clearButtonLabel = clearButtonText;
|
|
35
|
+
if (cancelButtonText) text.cancelButtonLabel = cancelButtonText;
|
|
36
|
+
if (acceptButtonText) text.okButtonLabel = acceptButtonText;
|
|
37
|
+
return text;
|
|
38
|
+
};
|
|
@@ -3,7 +3,6 @@ import React, { useState, useMemo } from 'react';
|
|
|
3
3
|
import {
|
|
4
4
|
Box,
|
|
5
5
|
Typography,
|
|
6
|
-
TextField, // Necesario para el renderizado del input
|
|
7
6
|
} from '@mui/material';
|
|
8
7
|
|
|
9
8
|
// Importaciones de @mui/x-date-pickers y dayjs
|
|
@@ -25,6 +24,7 @@ import {
|
|
|
25
24
|
DateTimePickerWithCustomButtonTextDefinition,
|
|
26
25
|
DateTimePickerWithButtonsDefinition,
|
|
27
26
|
DateTimePickerWithCustomInputFormatDefinition,
|
|
27
|
+
DateTimePickerEmptyWithMaskDefinition,
|
|
28
28
|
} from './DateTimePicker.definitions'; // Asegúrate de que esta ruta sea correcta
|
|
29
29
|
import { DateTimePicker } from './DateTimePicker';
|
|
30
30
|
|
|
@@ -203,6 +203,34 @@ const meta: Meta<typeof DateTimePicker> = {
|
|
|
203
203
|
}
|
|
204
204
|
};
|
|
205
205
|
|
|
206
|
+
export const DateTimePickerEmptyWithMask: Story = {
|
|
207
|
+
render: () => {
|
|
208
|
+
const [selectedDateTime, setSelectedDateTime] = useState<Dayjs | null>(null);
|
|
209
|
+
return (
|
|
210
|
+
<Box sx={{ width: 300 }}>
|
|
211
|
+
<DateTimePicker
|
|
212
|
+
label="Fecha y Hora"
|
|
213
|
+
selectedDateTime={selectedDateTime}
|
|
214
|
+
onDateTimeChange={setSelectedDateTime}
|
|
215
|
+
inputFormat="DD/MM/YY HH:mm"
|
|
216
|
+
/>
|
|
217
|
+
<Typography sx={{ mt: 2 }} variant="caption" color="text.secondary">
|
|
218
|
+
Al estar vacío, el campo muestra la máscara del formato (DD/MM/AA HH:MM).
|
|
219
|
+
</Typography>
|
|
220
|
+
</Box>
|
|
221
|
+
);
|
|
222
|
+
},
|
|
223
|
+
parameters: {
|
|
224
|
+
docs: {
|
|
225
|
+
description: {
|
|
226
|
+
story:
|
|
227
|
+
"DateTimePicker vacío. Al no haber valor seleccionado, cada sección del campo muestra su placeholder según el `inputFormat` (por ejemplo `DD/MM/AA HH:MM`), funcionando como máscara visual."
|
|
228
|
+
},
|
|
229
|
+
source: { code: DateTimePickerEmptyWithMaskDefinition.trim() }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
206
234
|
export const DateTimePickerSmallSize: Story = {
|
|
207
235
|
render: () => {
|
|
208
236
|
const [selectedDateTime, setSelectedDateTime] = useState<Dayjs | null>(dayjs());
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SxProps, Theme } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
import { buildFormFieldSx } from '../_shared/formField.sx';
|
|
4
|
+
import { FIELD_INPUT_PADDING_Y } from '../../theme/tokens';
|
|
5
|
+
import type { LabelPosition } from './DateTimePicker';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Builder de sx para el DateTimePicker. Mismo patrón que DatePicker.
|
|
9
|
+
* Usa `includePickersApi: true` para soportar la API nueva de MUI X v8.
|
|
10
|
+
*/
|
|
11
|
+
export const buildDateTimePickerSx = (
|
|
12
|
+
borderRadius: number | string,
|
|
13
|
+
labelPosition: LabelPosition,
|
|
14
|
+
): SxProps<Theme> =>
|
|
15
|
+
buildFormFieldSx({
|
|
16
|
+
borderRadius,
|
|
17
|
+
labelPosition,
|
|
18
|
+
includePickersApi: true,
|
|
19
|
+
extraOutsideSx: {
|
|
20
|
+
'& .MuiInputBase-input': {
|
|
21
|
+
paddingTop: FIELD_INPUT_PADDING_Y,
|
|
22
|
+
paddingBottom: FIELD_INPUT_PADDING_Y,
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
'& .MuiPickersInputBase-sectionsContainer': {
|
|
26
|
+
paddingTop: FIELD_INPUT_PADDING_Y,
|
|
27
|
+
paddingBottom: FIELD_INPUT_PADDING_Y,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|