@cloud-ru/uikit-product-mobile-fields 0.11.24
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/CHANGELOG.md +1300 -0
- package/LICENSE +201 -0
- package/README.md +8 -0
- package/package.json +66 -0
- package/src/components/AdaptiveField/AdaptiveField.tsx +88 -0
- package/src/components/AdaptiveField/index.ts +1 -0
- package/src/components/MobileFieldDate/MobileFieldDate.tsx +375 -0
- package/src/components/MobileFieldDate/constants.ts +33 -0
- package/src/components/MobileFieldDate/index.ts +2 -0
- package/src/components/MobileFieldDate/styles.module.scss +75 -0
- package/src/components/MobileFieldDate/types.ts +6 -0
- package/src/components/MobileFieldDate/utils.ts +49 -0
- package/src/components/MobileFieldSelect/MobileFieldSelect.tsx +18 -0
- package/src/components/MobileFieldSelect/MobileFieldSelectMultiple.tsx +331 -0
- package/src/components/MobileFieldSelect/MobileFieldSelectSingle.tsx +300 -0
- package/src/components/MobileFieldSelect/hooks.tsx +195 -0
- package/src/components/MobileFieldSelect/index.ts +13 -0
- package/src/components/MobileFieldSelect/legacy/components/Items/hooks.tsx +53 -0
- package/src/components/MobileFieldSelect/legacy/components/index.ts +1 -0
- package/src/components/MobileFieldSelect/legacy/hooks.ts +38 -0
- package/src/components/MobileFieldSelect/legacy/index.ts +3 -0
- package/src/components/MobileFieldSelect/legacy/utils.ts +176 -0
- package/src/components/MobileFieldSelect/styles.module.scss +176 -0
- package/src/components/MobileFieldSelect/types.ts +156 -0
- package/src/components/MobileFieldSelect/utils/extractFieldDecoratorProps.ts +35 -0
- package/src/components/MobileFieldSelect/utils/extractListProps.ts +30 -0
- package/src/components/MobileFieldSelect/utils/getArrowIcon.ts +15 -0
- package/src/components/MobileFieldSelect/utils/index.ts +6 -0
- package/src/components/MobileFieldSelect/utils/options.tsx +88 -0
- package/src/components/MobileFieldSelect/utils/typeGuards.ts +38 -0
- package/src/components/MobileFieldSelect/utils/updateItems.ts +121 -0
- package/src/components/index.ts +3 -0
- package/src/constants/allFields.ts +11 -0
- package/src/constants/dateFields.ts +127 -0
- package/src/constants/index.ts +2 -0
- package/src/helperComponents/ButtonCopyValue/ButtonCopyValue.tsx +79 -0
- package/src/helperComponents/ButtonCopyValue/helpers.tsx +19 -0
- package/src/helperComponents/ButtonCopyValue/index.ts +1 -0
- package/src/helperComponents/ButtonCopyValue/styles.module.scss +5 -0
- package/src/helperComponents/FieldContainerPrivate/FieldContainerPrivate.tsx +79 -0
- package/src/helperComponents/FieldContainerPrivate/index.ts +1 -0
- package/src/helperComponents/FieldContainerPrivate/styles.module.scss +131 -0
- package/src/helperComponents/ItemContent/ItemContent.tsx +37 -0
- package/src/helperComponents/ItemContent/index.ts +1 -0
- package/src/helperComponents/ItemContent/styles.module.scss +80 -0
- package/src/helperComponents/index.ts +3 -0
- package/src/hooks/dateHandlers/index.ts +3 -0
- package/src/hooks/dateHandlers/useDateField.ts +275 -0
- package/src/hooks/dateHandlers/useDateFieldHelpersForMode.ts +145 -0
- package/src/hooks/dateHandlers/useFocusHandlers.ts +46 -0
- package/src/hooks/dateHandlers/useHandlers.ts +15 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/styles.module.scss +17 -0
- package/src/hooks/useCopyButton.tsx +47 -0
- package/src/hooks/usePostfix.tsx +21 -0
- package/src/hooks/usePrefix.tsx +21 -0
- package/src/hooks/useValueControl.ts +15 -0
- package/src/index.ts +3 -0
- package/src/styles.module.scss +55 -0
- package/src/types/allFields.ts +9 -0
- package/src/types/dateFields.ts +14 -0
- package/src/types/index.ts +2 -0
- package/src/utils/adaptiveField.tsx +19 -0
- package/src/utils/dateFields.ts +75 -0
- package/src/utils/getValidationState.ts +6 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComponentType, forwardRef, RefAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
import { WithLayoutType } from '@cloud-ru/uikit-product-utils';
|
|
4
|
+
|
|
5
|
+
export function getAdaptiveFieldProps<T extends WithLayoutType<{ autoFocus?: boolean }>>({ layoutType, autoFocus }: T) {
|
|
6
|
+
const isMobile = layoutType === 'mobile';
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
autoFocus: isMobile ? false : autoFocus,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function withAdaptiveField<TProps extends { autoFocus?: boolean }, TRef = undefined>(
|
|
14
|
+
Component: ComponentType<TProps & RefAttributes<TRef>>,
|
|
15
|
+
) {
|
|
16
|
+
return forwardRef<TRef, WithLayoutType<TProps>>(function WithAdaptiveField(props, ref) {
|
|
17
|
+
return <Component {...props} {...getAdaptiveFieldProps(props)} ref={ref} />;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { SLOT_ORDER, SlotKey, SLOTS } from '../constants';
|
|
2
|
+
import { Mode, NoSecondsMode, TimeMode } from '../types';
|
|
3
|
+
|
|
4
|
+
export function getSlotKeyFromIndexHandler(mode: Mode | TimeMode | NoSecondsMode) {
|
|
5
|
+
return (index: number | null): SlotKey | undefined => {
|
|
6
|
+
if (index !== null) {
|
|
7
|
+
for (const key in SLOTS[mode]) {
|
|
8
|
+
if (index >= SLOTS[mode][key].start && index <= SLOTS[mode][key].end) {
|
|
9
|
+
return key as SlotKey;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getNextSlotKeyHandler(mode: Mode | TimeMode | NoSecondsMode) {
|
|
19
|
+
const order = SLOT_ORDER[mode];
|
|
20
|
+
|
|
21
|
+
return (slotKey: SlotKey | undefined) => {
|
|
22
|
+
const defaultIndex = order.length - 1;
|
|
23
|
+
const defaultSLot = order[defaultIndex];
|
|
24
|
+
const currentIndex = order.indexOf(slotKey as SlotKey);
|
|
25
|
+
return currentIndex === -1 || currentIndex === defaultIndex ? defaultSLot : order[currentIndex + 1];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getPrevSlotKeyHandler(mode: Mode | TimeMode | NoSecondsMode) {
|
|
30
|
+
const order = SLOT_ORDER[mode];
|
|
31
|
+
|
|
32
|
+
return (slotKey: SlotKey | undefined) => {
|
|
33
|
+
const defaultIndex = 0;
|
|
34
|
+
const defaultSLot = order[defaultIndex];
|
|
35
|
+
const currentIndex = order.indexOf(slotKey as SlotKey);
|
|
36
|
+
return currentIndex === -1 || currentIndex === defaultIndex ? defaultSLot : order[currentIndex - 1];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const DATE_STUB = new Date();
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Преобразует строковое значение поля FieldDate в тип Date
|
|
44
|
+
* @function helper
|
|
45
|
+
*/
|
|
46
|
+
export function parseDate(value: string) {
|
|
47
|
+
if (!value) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const splittedValue = value.split(', ');
|
|
52
|
+
const date = splittedValue[0];
|
|
53
|
+
let time = splittedValue[1];
|
|
54
|
+
|
|
55
|
+
let [day, month, year] = date.split('.').map(Number);
|
|
56
|
+
month -= 1;
|
|
57
|
+
|
|
58
|
+
if (date.includes(':')) {
|
|
59
|
+
time = date;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (time) {
|
|
63
|
+
if (isNaN(year) || isNaN(month) || isNaN(day)) {
|
|
64
|
+
year = DATE_STUB.getFullYear();
|
|
65
|
+
month = DATE_STUB.getMonth();
|
|
66
|
+
day = DATE_STUB.getDay();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const [hours = 0, minutes = 0, seconds = 0] = time.split(':').map(str => Number(str ?? 0));
|
|
70
|
+
|
|
71
|
+
return new Date(year, month, day, hours, minutes, seconds);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return new Date(year, month, day);
|
|
75
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { VALIDATION_STATE } from '../constants';
|
|
2
|
+
import { ValidationState } from '../types';
|
|
3
|
+
|
|
4
|
+
export function getValidationState({ validationState, error }: { validationState?: ValidationState; error?: string }) {
|
|
5
|
+
return error ? VALIDATION_STATE.Error : (validationState ?? VALIDATION_STATE.Default);
|
|
6
|
+
}
|