react-restyle-components 0.4.39 → 0.4.41
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/lib/index.js +3 -1
- package/lib/src/core-components/index.js +1 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/Accordion.js +15 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionContext.js +6 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.js +39 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/Header.js +39 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/elements.js +94 -57
- package/lib/src/core-components/src/components/Accordion/AccordionSection/hooks/useCurrentAccordionIndex.js +13 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/index.js +3 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/types.js +9 -1
- package/lib/src/core-components/src/components/Accordion/Collapsible/Collapsible2.component.js +249 -1
- package/lib/src/core-components/src/components/Action/types.js +8 -1
- package/lib/src/core-components/src/components/AlertBanner/AlertBanner.js +45 -1
- package/lib/src/core-components/src/components/AlertBanner/elements.js +120 -45
- package/lib/src/core-components/src/components/AlertBanner/index.js +2 -1
- package/lib/src/core-components/src/components/AlertBanner/types.js +10 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-group-by-multiple-select-multiple-fields-display/auto-complete-filter-group-by-multiple-select-multiple-fields-display.component.js +334 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multi-select-multi-fields-display-drag-drop/auto-complete-filter-multi-select-multi-fields-display-drag-drop.component.js +229 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multi-select-selected-top-display/auto-complete-filter-multi-select-selected-top-display.component.js +174 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.js +129 -2
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-single-select/auto-complete-filter-single-select.component.js +55 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.js +308 -2
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-group-by/auto-complete-group-by.component.js +115 -1
- package/lib/src/core-components/src/components/AutoComplete/autocomplete/autocomplete.js +442 -2
- package/lib/src/core-components/src/components/AutoComplete/index.js +8 -1
- package/lib/src/core-components/src/components/Avatar/Avatar.js +148 -14
- package/lib/src/core-components/src/components/Badge/Badge.js +25 -2
- package/lib/src/core-components/src/components/Badge/InnerBadge/Inline.js +25 -1
- package/lib/src/core-components/src/components/Badge/InnerBadge/InnerBadge.js +25 -1
- package/lib/src/core-components/src/components/Badge/InnerBadge/elements.js +78 -32
- package/lib/src/core-components/src/components/Badge/InnerBadge/index.js +1 -1
- package/lib/src/core-components/src/components/Badge/index.js +1 -1
- package/lib/src/core-components/src/components/Badge/types.js +5 -1
- package/lib/src/core-components/src/components/Breadcrumb/Breadcrumb.js +83 -1
- package/lib/src/core-components/src/components/Breadcrumb/elements.js +166 -94
- package/lib/src/core-components/src/components/Breadcrumb/index.js +3 -1
- package/lib/src/core-components/src/components/Breadcrumb/types.js +3 -1
- package/lib/src/core-components/src/components/Button/button.component.js +18 -1
- package/lib/src/core-components/src/components/Button/buttonGroup/buttonGroup.component.js +4 -1
- package/lib/src/core-components/src/components/Button/index.js +2 -1
- package/lib/src/core-components/src/components/Button/types.js +1 -1
- package/lib/src/core-components/src/components/Chip/Chip.js +64 -1
- package/lib/src/core-components/src/components/Chip/elements.js +148 -48
- package/lib/src/core-components/src/components/Chip/index.js +2 -1
- package/lib/src/core-components/src/components/Chip/types.js +4 -1
- package/lib/src/core-components/src/components/Divider/Divider.js +25 -1
- package/lib/src/core-components/src/components/Divider/elements.js +68 -31
- package/lib/src/core-components/src/components/Divider/index.js +2 -1
- package/lib/src/core-components/src/components/Divider/types.js +4 -1
- package/lib/src/core-components/src/components/DynamicGrid/DynamicGrid.js +147 -1
- package/lib/src/core-components/src/components/DynamicGrid/GridContainer.js +24 -17
- package/lib/src/core-components/src/components/DynamicGrid/elements.js +162 -100
- package/lib/src/core-components/src/components/DynamicGrid/index.js +3 -1
- package/lib/src/core-components/src/components/DynamicGrid/types.js +28 -1
- package/lib/src/core-components/src/components/DynamicGrid/utils.js +193 -1
- package/lib/src/core-components/src/components/FormField/FormField.js +103 -1
- package/lib/src/core-components/src/components/FormField/components/CheckboxGroupInput.js +37 -1
- package/lib/src/core-components/src/components/FormField/components/CheckboxInput.js +8 -1
- package/lib/src/core-components/src/components/FormField/components/CssMultilineInput.js +192 -1
- package/lib/src/core-components/src/components/FormField/components/DatePickerInput.js +99 -1
- package/lib/src/core-components/src/components/FormField/components/DropdownInput.js +70 -1
- package/lib/src/core-components/src/components/FormField/components/OtpInput.js +81 -1
- package/lib/src/core-components/src/components/FormField/components/PasswordInput.js +40 -1
- package/lib/src/core-components/src/components/FormField/components/PinInput.js +75 -1
- package/lib/src/core-components/src/components/FormField/components/RadioInput.js +54 -1
- package/lib/src/core-components/src/components/FormField/components/TextDropdownInput.js +94 -1
- package/lib/src/core-components/src/components/FormField/components/ToggleInput.js +36 -1
- package/lib/src/core-components/src/components/FormField/components/index.js +11 -1
- package/lib/src/core-components/src/components/FormField/css-properties.js +161 -1
- package/lib/src/core-components/src/components/FormField/index.js +2 -1
- package/lib/src/core-components/src/components/Icon/Icon.js +79 -1
- package/lib/src/core-components/src/components/Icon/index.js +2 -1
- package/lib/src/core-components/src/components/Icon/types.js +9 -1
- package/lib/src/core-components/src/components/Loader/loader.component.js +215 -2
- package/lib/src/core-components/src/components/Masonry/Masonry.js +73 -1
- package/lib/src/core-components/src/components/Masonry/elements.js +46 -29
- package/lib/src/core-components/src/components/Masonry/hooks.js +100 -1
- package/lib/src/core-components/src/components/Masonry/index.js +3 -1
- package/lib/src/core-components/src/components/Masonry/types.js +1 -1
- package/lib/src/core-components/src/components/Modal/BasicModal/modal.component.js +116 -1
- package/lib/src/core-components/src/components/Modal/index.js +2 -1
- package/lib/src/core-components/src/components/Modal/modal-confirm/modal-confirm.component.js +147 -1
- package/lib/src/core-components/src/components/Picker/color-picker/color-picker.component.js +12 -1
- package/lib/src/core-components/src/components/Picker/color-picker-modal/color-picker-modal.component.js +40 -1
- package/lib/src/core-components/src/components/Picker/index.js +2 -1
- package/lib/src/core-components/src/components/Selection/index.js +4 -1
- package/lib/src/core-components/src/components/Selection/multi-select/multi-select.component.js +49 -1
- package/lib/src/core-components/src/components/Selection/multi-select-with-field/multi-select-with-field.component.js +58 -1
- package/lib/src/core-components/src/components/Selection/multi-selection-dropdown/multi-selection-dropdown.component.js +43 -1
- package/lib/src/core-components/src/components/Selection/single-select/single-select.component.js +87 -1
- package/lib/src/core-components/src/components/Skeleton/Skeleton.js +51 -1
- package/lib/src/core-components/src/components/Skeleton/elements.js +143 -54
- package/lib/src/core-components/src/components/Skeleton/index.js +2 -1
- package/lib/src/core-components/src/components/Skeleton/types.js +4 -1
- package/lib/src/core-components/src/components/SpeedDial/SpeedDial.js +128 -1
- package/lib/src/core-components/src/components/SpeedDial/elements.js +132 -62
- package/lib/src/core-components/src/components/SpeedDial/index.js +2 -1
- package/lib/src/core-components/src/components/SpeedDial/types.js +3 -1
- package/lib/src/core-components/src/components/Stepper2/stepper.component.js +139 -1
- package/lib/src/core-components/src/components/Switch/Switch.js +26 -1
- package/lib/src/core-components/src/components/Switch/elements.js +103 -34
- package/lib/src/core-components/src/components/Switch/index.js +2 -1
- package/lib/src/core-components/src/components/Switch/types.js +3 -1
- package/lib/src/core-components/src/components/Table/Table.js +1357 -1
- package/lib/src/core-components/src/components/Table/columnReorder.d.ts +128 -0
- package/lib/src/core-components/src/components/Table/columnReorder.js +530 -0
- package/lib/src/core-components/src/components/Table/columnResize.d.ts +99 -0
- package/lib/src/core-components/src/components/Table/columnResize.js +399 -0
- package/lib/src/core-components/src/components/Table/elements.d.ts +9 -1
- package/lib/src/core-components/src/components/Table/elements.js +324 -155
- package/lib/src/core-components/src/components/Table/filters.js +555 -30
- package/lib/src/core-components/src/components/Table/hooks.js +536 -2
- package/lib/src/core-components/src/components/Table/index.d.ts +4 -0
- package/lib/src/core-components/src/components/Table/index.js +6 -1
- package/lib/src/core-components/src/components/Table/types.d.ts +58 -0
- package/lib/src/core-components/src/components/Table/types.js +1 -1
- package/lib/src/core-components/src/components/Tabs/tabs.component.js +22 -1
- package/lib/src/core-components/src/components/Tags1/Tags.component.js +118 -1
- package/lib/src/core-components/src/components/Tags1/types.js +20 -1
- package/lib/src/core-components/src/components/Timer1/timer.component.js +76 -1
- package/lib/src/core-components/src/components/Toast/Toast.js +50 -1
- package/lib/src/core-components/src/components/Toast/elements.js +122 -41
- package/lib/src/core-components/src/components/Toast/index.js +2 -1
- package/lib/src/core-components/src/components/Toast/types.js +9 -1
- package/lib/src/core-components/src/components/Tooltip/Tooltip.js +200 -1
- package/lib/src/core-components/src/components/Tooltip/elements.js +117 -55
- package/lib/src/core-components/src/components/Tooltip/index.js +2 -1
- package/lib/src/core-components/src/components/Tooltip/types.js +17 -1
- package/lib/src/core-components/src/components/Tooltip/utils.js +140 -1
- package/lib/src/core-components/src/components/TreeSelect/TreeSelect.js +303 -1
- package/lib/src/core-components/src/components/TreeSelect/elements.js +216 -117
- package/lib/src/core-components/src/components/TreeSelect/hooks.js +252 -1
- package/lib/src/core-components/src/components/TreeSelect/index.js +3 -1
- package/lib/src/core-components/src/components/TreeSelect/types.js +1 -1
- package/lib/src/core-components/src/components/ag-grid/AgGrid.d.ts +11 -0
- package/lib/src/core-components/src/components/ag-grid/AgGrid.js +733 -0
- package/lib/src/core-components/src/components/ag-grid/elements.d.ts +246 -0
- package/lib/src/core-components/src/components/ag-grid/elements.js +1156 -0
- package/lib/src/core-components/src/components/ag-grid/hooks.d.ts +196 -0
- package/lib/src/core-components/src/components/ag-grid/hooks.js +943 -0
- package/lib/src/core-components/src/components/ag-grid/index.d.ts +9 -0
- package/lib/src/core-components/src/components/ag-grid/index.js +13 -0
- package/lib/src/core-components/src/components/ag-grid/types.d.ts +1367 -0
- package/lib/src/core-components/src/components/ag-grid/types.js +6 -0
- package/lib/src/core-components/src/components/index.d.ts +1 -0
- package/lib/src/core-components/src/components/index.js +31 -1
- package/lib/src/core-components/src/components/pdf/pdf-images.components.js +7 -1
- package/lib/src/core-components/src/components/pdf/pdf-table.components.js +48 -5
- package/lib/src/core-components/src/components/pdf/pdf-typography.components.js +70 -1
- package/lib/src/core-components/src/components/pdf/pdf-wrapped-view.components.js +50 -1
- package/lib/src/core-components/src/core-components/Avatar.js +33 -4
- package/lib/src/core-components/src/core-components/CoreButton/CoreButton.js +10 -1
- package/lib/src/core-components/src/core-components/CoreButton/elements.js +176 -67
- package/lib/src/core-components/src/core-components/CoreButton/index.js +3 -1
- package/lib/src/core-components/src/core-components/CoreButton/types.js +6 -1
- package/lib/src/core-components/src/core-components/CoreButton/utils.js +12 -1
- package/lib/src/core-components/src/core-components/Divider/Divider.js +19 -4
- package/lib/src/core-components/src/core-components/Divider/index.js +1 -1
- package/lib/src/core-components/src/core-components/SelectionCardStrip/index.js +1 -1
- package/lib/src/core-components/src/core-components/SelectionCardStrip/selectionCardStrip.js +33 -10
- package/lib/src/core-components/src/core-components/StateLayer.js +5 -3
- package/lib/src/core-components/src/core-components/ToggleCore/elements.js +50 -25
- package/lib/src/core-components/src/core-components/ToggleCore/index.js +2 -1
- package/lib/src/core-components/src/core-components/ToggleCore/toggleCore.js +14 -1
- package/lib/src/core-components/src/core-components/atoms/Input/Input.js +22 -1
- package/lib/src/core-components/src/core-components/atoms/Label/Label.js +21 -1
- package/lib/src/core-components/src/core-components/atoms/Textarea/Textarea.js +19 -1
- package/lib/src/core-components/src/core-components/index.js +3 -1
- package/lib/src/core-components/src/helpers/constants.js +11 -1
- package/lib/src/core-components/src/hooks/index.js +1 -1
- package/lib/src/core-components/src/hooks/outside.hook.js +28 -1
- package/lib/src/core-components/src/index.js +12 -1
- package/lib/src/core-components/src/tc.global.css +16 -3
- package/lib/src/core-components/src/tc.module.css +2 -2
- package/lib/src/core-components/src/utils/abstracts/breakpoints/index.js +28 -1
- package/lib/src/core-components/src/utils/abstracts/colors/index.js +49 -1
- package/lib/src/core-components/src/utils/abstracts/index.js +5 -1
- package/lib/src/core-components/src/utils/abstracts/space/index.js +26 -1
- package/lib/src/core-components/src/utils/abstracts/theme/ThemeBoundary.js +8 -1
- package/lib/src/core-components/src/utils/abstracts/theme/default-themes.js +30 -1
- package/lib/src/core-components/src/utils/abstracts/theme/index.js +3 -1
- package/lib/src/core-components/src/utils/abstracts/theme/theme.js +30 -1
- package/lib/src/core-components/src/utils/abstracts/theme/types.js +1 -1
- package/lib/src/core-components/src/utils/abstracts/theme/useTheme.js +17 -1
- package/lib/src/core-components/src/utils/abstracts/typography/index.js +25 -1
- package/lib/src/core-components/src/utils/context/DefaultsProvider.js +8 -1
- package/lib/src/core-components/src/utils/context/InternalProvider.js +24 -1
- package/lib/src/core-components/src/utils/context/index.js +2 -1
- package/lib/src/core-components/src/utils/designTokens.js +125 -1
- package/lib/src/core-components/src/utils/helpers/attachSubComponents.js +23 -1
- package/lib/src/core-components/src/utils/helpers/flattenChildren.js +11 -1
- package/lib/src/core-components/src/utils/helpers/getChildByType.js +3 -1
- package/lib/src/core-components/src/utils/helpers/index.js +5 -1
- package/lib/src/core-components/src/utils/helpers/isComponentType.js +16 -1
- package/lib/src/core-components/src/utils/helpers/separateChildrenByType.js +12 -1
- package/lib/src/core-components/src/utils/hooks/index.js +18 -1
- package/lib/src/core-components/src/utils/hooks/useClickOutside.js +18 -1
- package/lib/src/core-components/src/utils/hooks/useCombinedRefs.js +17 -1
- package/lib/src/core-components/src/utils/hooks/useDebouncedCallback.js +12 -1
- package/lib/src/core-components/src/utils/hooks/useDebouncedValue.js +20 -1
- package/lib/src/core-components/src/utils/hooks/useDeprecation.js +40 -1
- package/lib/src/core-components/src/utils/hooks/useDeviceDetect.js +10 -1
- package/lib/src/core-components/src/utils/hooks/useDeviceForm.js +24 -1
- package/lib/src/core-components/src/utils/hooks/useDisableBodyScroll.js +16 -1
- package/lib/src/core-components/src/utils/hooks/useHoverState.js +36 -1
- package/lib/src/core-components/src/utils/hooks/useId.js +7 -1
- package/lib/src/core-components/src/utils/hooks/useIsBrowser.js +11 -1
- package/lib/src/core-components/src/utils/hooks/useMediaQuery.js +16 -1
- package/lib/src/core-components/src/utils/hooks/useOverflow.js +22 -1
- package/lib/src/core-components/src/utils/hooks/useSafeLayoutEffect.js +5 -1
- package/lib/src/core-components/src/utils/hooks/useScrollingUp.js +18 -1
- package/lib/src/core-components/src/utils/hooks/useTrapFocus.js +30 -1
- package/lib/src/core-components/src/utils/hooks/useWindowDimensions.js +23 -1
- package/lib/src/core-components/src/utils/index.js +9 -1
- package/lib/src/core-components/src/utils/stories/Wrappers.js +23 -8
- package/lib/src/core-components/src/utils/stories/cleanProps.js +5 -1
- package/lib/src/core-components/src/utils/stories/index.js +4 -1
- package/lib/src/core-components/src/utils/stories/sleep.js +4 -1
- package/lib/src/core-components/src/utils/stories/view-ports.js +50 -1
- package/lib/src/core-components/src/utils/styling/calcWidthOfColumns.js +5 -1
- package/lib/src/core-components/src/utils/styling/createGridContainer.js +12 -6
- package/lib/src/core-components/src/utils/styling/createTransition.js +7 -2
- package/lib/src/core-components/src/utils/styling/forwardProps.js +10 -1
- package/lib/src/core-components/src/utils/styling/index.js +5 -1
- package/lib/src/core-components/src/utils/styling/pxToRem.js +6 -1
- package/lib/src/core-components/src/utils/testing/getComputedStyle.js +3 -1
- package/lib/src/core-components/src/utils/testing/index.js +1 -1
- package/lib/src/core-components/src/utils/utility.util.js +14 -1
- package/lib/src/core-components/tailwind.config.js +233 -1
- package/lib/src/core-hooks/index.js +3 -1
- package/lib/src/core-hooks/src/useClickOutside/useClickOutside.hook.js +46 -1
- package/lib/src/core-hooks/src/useDebounce/useDebounce.hook.js +30 -1
- package/lib/src/core-hooks/src/usePreventEKey/usePreventEKey.hook.js +8 -1
- package/lib/src/core-utils/index.js +7 -1
- package/lib/src/core-utils/src/calculation/calculation.util.js +89 -1
- package/lib/src/core-utils/src/colors/color.util.js +15 -1
- package/lib/src/core-utils/src/convert/numberToWords/numToWords.util.js +145 -1
- package/lib/src/core-utils/src/convert/typography/camelCaseToTitleCase.util.js +5 -1
- package/lib/src/core-utils/src/form-helper/form-helper.util.js +82 -1
- package/lib/src/core-utils/src/index.js +7 -1
- package/lib/src/core-utils/src/utility/utility.util.js +12 -1
- package/lib/src/core-utils/src/uuid/uuid.util.js +8 -1
- package/package.json +1 -1
|
@@ -1 +1,193 @@
|
|
|
1
|
-
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { gapSizeValues, gapSizes, } from './types';
|
|
3
|
+
// Breakpoint values in pixels
|
|
4
|
+
const BREAKPOINTS = {
|
|
5
|
+
xs: 0,
|
|
6
|
+
sm: 375,
|
|
7
|
+
md: 768,
|
|
8
|
+
lg: 1024,
|
|
9
|
+
xl: 1280,
|
|
10
|
+
'2xl': 1440,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Convert pixels to rem
|
|
14
|
+
*/
|
|
15
|
+
export const pxToRem = (px) => px / 16;
|
|
16
|
+
/**
|
|
17
|
+
* Convert rem to pixels
|
|
18
|
+
*/
|
|
19
|
+
export const remToPx = (rem) => rem * 16;
|
|
20
|
+
/**
|
|
21
|
+
* Get gap value from GapSize or LegacyGapSize
|
|
22
|
+
*/
|
|
23
|
+
export const getGapValue = (gap) => {
|
|
24
|
+
if (typeof gap === 'number') {
|
|
25
|
+
return gapSizes[gap] || gapSizes[1];
|
|
26
|
+
}
|
|
27
|
+
return gapSizeValues[gap] || gapSizeValues.md;
|
|
28
|
+
};
|
|
29
|
+
const moduloColumns = (columns, modulo) => Math.floor(columns / modulo) * modulo;
|
|
30
|
+
export const calcColumns = ({ minWidth, elementWidth, gap, modulo, maxColumns, scrollHint = 0, }) => {
|
|
31
|
+
if (elementWidth === 0)
|
|
32
|
+
return 1;
|
|
33
|
+
const gapSize = parseFloat(gap);
|
|
34
|
+
const elementWidthInRem = pxToRem(elementWidth);
|
|
35
|
+
const columns = Math.min(Math.floor((elementWidthInRem + gapSize - minWidth * scrollHint) /
|
|
36
|
+
(minWidth + gapSize)), maxColumns);
|
|
37
|
+
return Math.max(1, moduloColumns(columns, modulo));
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Get responsive columns based on window width
|
|
41
|
+
*/
|
|
42
|
+
export const getResponsiveColumns = (responsiveColumns, windowWidth) => {
|
|
43
|
+
let columns = 1;
|
|
44
|
+
if (responsiveColumns.xs !== undefined && windowWidth >= BREAKPOINTS.xs) {
|
|
45
|
+
columns = responsiveColumns.xs;
|
|
46
|
+
}
|
|
47
|
+
if (responsiveColumns.sm !== undefined && windowWidth >= BREAKPOINTS.sm) {
|
|
48
|
+
columns = responsiveColumns.sm;
|
|
49
|
+
}
|
|
50
|
+
if (responsiveColumns.md !== undefined && windowWidth >= BREAKPOINTS.md) {
|
|
51
|
+
columns = responsiveColumns.md;
|
|
52
|
+
}
|
|
53
|
+
if (responsiveColumns.lg !== undefined && windowWidth >= BREAKPOINTS.lg) {
|
|
54
|
+
columns = responsiveColumns.lg;
|
|
55
|
+
}
|
|
56
|
+
if (responsiveColumns.xl !== undefined && windowWidth >= BREAKPOINTS.xl) {
|
|
57
|
+
columns = responsiveColumns.xl;
|
|
58
|
+
}
|
|
59
|
+
if (responsiveColumns['2xl'] !== undefined && windowWidth >= BREAKPOINTS['2xl']) {
|
|
60
|
+
columns = responsiveColumns['2xl'];
|
|
61
|
+
}
|
|
62
|
+
return columns;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Hook to get current window width
|
|
66
|
+
*/
|
|
67
|
+
export const useWindowWidth = () => {
|
|
68
|
+
const [width, setWidth] = useState(typeof window !== 'undefined' ? window.innerWidth : 1024);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (typeof window === 'undefined')
|
|
71
|
+
return;
|
|
72
|
+
const handleResize = () => {
|
|
73
|
+
setWidth(window.innerWidth);
|
|
74
|
+
};
|
|
75
|
+
window.addEventListener('resize', handleResize);
|
|
76
|
+
return () => window.removeEventListener('resize', handleResize);
|
|
77
|
+
}, []);
|
|
78
|
+
return width;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Hook to observe element resize
|
|
82
|
+
*/
|
|
83
|
+
export const useElementResize = (ref, callback) => {
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const element = ref.current;
|
|
86
|
+
if (!element)
|
|
87
|
+
return;
|
|
88
|
+
// Initial size
|
|
89
|
+
callback(element.clientWidth, element.clientHeight);
|
|
90
|
+
if (!window.ResizeObserver)
|
|
91
|
+
return;
|
|
92
|
+
const observer = new ResizeObserver((entries) => {
|
|
93
|
+
window.requestAnimationFrame(() => {
|
|
94
|
+
const entry = entries[0];
|
|
95
|
+
if (entry) {
|
|
96
|
+
callback(entry.contentRect.width, entry.contentRect.height);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
observer.observe(element);
|
|
101
|
+
return () => observer.disconnect();
|
|
102
|
+
}, [ref, callback]);
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Hook to handle keyboard focus scrolling in scroll mode
|
|
106
|
+
*/
|
|
107
|
+
export const useScrollToKeyboardFocus = (ref, scroll) => {
|
|
108
|
+
const scrollToFocused = useCallback((keyboardEvent) => {
|
|
109
|
+
const { target } = keyboardEvent;
|
|
110
|
+
if (target instanceof HTMLElement &&
|
|
111
|
+
scroll?.enabled &&
|
|
112
|
+
keyboardEvent.key === 'Tab') {
|
|
113
|
+
target.scrollIntoView({
|
|
114
|
+
inline: 'center',
|
|
115
|
+
block: 'nearest',
|
|
116
|
+
behavior: scroll.smoothScroll !== false ? 'smooth' : 'auto',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}, [scroll]);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const element = ref.current;
|
|
122
|
+
if (!element)
|
|
123
|
+
return;
|
|
124
|
+
element.addEventListener('keyup', scrollToFocused);
|
|
125
|
+
return () => {
|
|
126
|
+
element.removeEventListener('keyup', scrollToFocused);
|
|
127
|
+
};
|
|
128
|
+
}, [scrollToFocused, ref]);
|
|
129
|
+
};
|
|
130
|
+
export const useScrollNavigation = (ref, itemCount, columns) => {
|
|
131
|
+
const [scrollState, setScrollState] = useState({
|
|
132
|
+
canScrollLeft: false,
|
|
133
|
+
canScrollRight: true,
|
|
134
|
+
currentPage: 0,
|
|
135
|
+
});
|
|
136
|
+
const totalPages = Math.ceil(itemCount / columns);
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
const element = ref.current;
|
|
139
|
+
if (!element)
|
|
140
|
+
return;
|
|
141
|
+
const handleScroll = () => {
|
|
142
|
+
const { scrollLeft, scrollWidth, clientWidth } = element;
|
|
143
|
+
const canScrollLeft = scrollLeft > 0;
|
|
144
|
+
const canScrollRight = scrollLeft + clientWidth < scrollWidth - 1;
|
|
145
|
+
const currentPage = Math.round(scrollLeft / clientWidth);
|
|
146
|
+
setScrollState({ canScrollLeft, canScrollRight, currentPage });
|
|
147
|
+
};
|
|
148
|
+
element.addEventListener('scroll', handleScroll);
|
|
149
|
+
handleScroll(); // Initial check
|
|
150
|
+
return () => element.removeEventListener('scroll', handleScroll);
|
|
151
|
+
}, [ref]);
|
|
152
|
+
const scrollTo = useCallback((index) => {
|
|
153
|
+
const element = ref.current;
|
|
154
|
+
if (!element)
|
|
155
|
+
return;
|
|
156
|
+
const { clientWidth } = element;
|
|
157
|
+
element.scrollTo({
|
|
158
|
+
left: index * clientWidth,
|
|
159
|
+
behavior: 'smooth',
|
|
160
|
+
});
|
|
161
|
+
}, [ref]);
|
|
162
|
+
const scrollLeft = useCallback(() => {
|
|
163
|
+
if (scrollState.currentPage > 0) {
|
|
164
|
+
scrollTo(scrollState.currentPage - 1);
|
|
165
|
+
}
|
|
166
|
+
}, [scrollState.currentPage, scrollTo]);
|
|
167
|
+
const scrollRight = useCallback(() => {
|
|
168
|
+
if (scrollState.currentPage < totalPages - 1) {
|
|
169
|
+
scrollTo(scrollState.currentPage + 1);
|
|
170
|
+
}
|
|
171
|
+
}, [scrollState.currentPage, totalPages, scrollTo]);
|
|
172
|
+
return {
|
|
173
|
+
...scrollState,
|
|
174
|
+
totalPages,
|
|
175
|
+
scrollTo,
|
|
176
|
+
scrollLeft,
|
|
177
|
+
scrollRight,
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Get item count from children
|
|
182
|
+
*/
|
|
183
|
+
export const getItemCount = (children) => {
|
|
184
|
+
if (!children)
|
|
185
|
+
return 0;
|
|
186
|
+
if (Array.isArray(children))
|
|
187
|
+
return children.filter(Boolean).length;
|
|
188
|
+
return 1;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Generate unique ID for accessibility
|
|
192
|
+
*/
|
|
193
|
+
export const generateGridId = () => `grid-${Math.random().toString(36).substr(2, 9)}`;
|
|
@@ -1 +1,103 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Input } from '../../core-components/atoms/Input/Input';
|
|
4
|
+
import { Textarea, } from '../../core-components/atoms/Textarea/Textarea';
|
|
5
|
+
import { PasswordInput, ToggleInput, RadioInput, CheckboxInput, CheckboxGroupInput, DatePickerInput, DropdownInput, TextDropdownInput, PinInput, OtpInput, CssMultilineInput, } from './components';
|
|
6
|
+
// Re-export all FormField components for direct use
|
|
7
|
+
export { PasswordInput, ToggleInput, RadioInput, CheckboxInput, CheckboxGroupInput, DatePickerInput, DropdownInput, TextDropdownInput, PinInput, OtpInput, CssMultilineInput, } from './components';
|
|
8
|
+
export const Label = (props) => (_jsx(_Fragment, { children: _jsx("label", { htmlFor: props.htmlFor, className: `${props.hasError ? 'text-red-400' : 'text-gray-700'} block text-3xs font-medium mb-1`, style: { ...props.style }, children: props.children }) }));
|
|
9
|
+
export const InputWrapper = (props) => (_jsxs("div", { className: props.className, ref: props.ref, children: [_jsx(Label, { htmlFor: props.id || '', hasError: props.hasError, style: { ...props.style }, children: _jsx("span", { className: "dark:text-white", children: props.label }) }), props.children] }));
|
|
10
|
+
export const FormField = React.forwardRef(({ label, error, hasError, id, labelProps, required, type = 'text', showPasswordToggle, radioOptions, checkboxLabel, checkboxOptions, isToggleLabel = true, dateFormat = 'yyyy-MM-dd', dropdownItems = [], allowCustomInput = true, pinLength = 12, otpLength = 6, pinValue = [], pinErrorMsg, pinDefaultMsg, cssProperties, onReset, onMoreInfo, value, onChange, onValueChange, onBlur, onValueBlur, disabled, children, ...props }, ref) => {
|
|
11
|
+
const fieldId = id || `field-${Math.random().toString(36).substr(2, 9)}`;
|
|
12
|
+
const isTextarea = type === 'textarea';
|
|
13
|
+
const isToggle = type === 'toggle';
|
|
14
|
+
const isRadio = type === 'radio';
|
|
15
|
+
const isCheckbox = type === 'checkbox';
|
|
16
|
+
const isCheckboxGroup = type === 'checkbox-group';
|
|
17
|
+
const isDatePicker = type === 'date-picker';
|
|
18
|
+
const isInputDropdown = type === 'input-dropdown';
|
|
19
|
+
const isTextInputDropdown = type === 'text-input-dropdown';
|
|
20
|
+
const isInputPin = type === 'input-pin';
|
|
21
|
+
const isInputOtp = type === 'input-otp';
|
|
22
|
+
const isCssMultiline = type === 'css-multiline';
|
|
23
|
+
const isPassword = type === 'password';
|
|
24
|
+
const isInputWrapper = type === 'input-wrapper';
|
|
25
|
+
// Calculate effective error: use error message if provided, otherwise use hasError for styling
|
|
26
|
+
const effectiveError = error || (hasError ? ' ' : undefined);
|
|
27
|
+
// Handle checkbox change
|
|
28
|
+
const handleCheckboxChange = (e) => {
|
|
29
|
+
if (onChange) {
|
|
30
|
+
onChange(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
// Render toggle switch
|
|
34
|
+
if (isToggle) {
|
|
35
|
+
return (_jsx(ToggleInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, disabled: disabled, isToggleLabel: isToggleLabel, labelProps: labelProps, className: props.className, ...props }));
|
|
36
|
+
}
|
|
37
|
+
// Render radio buttons
|
|
38
|
+
if (isRadio && radioOptions) {
|
|
39
|
+
return (_jsx(RadioInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, disabled: disabled, radioOptions: radioOptions, name: props.name, className: props.className, labelProps: labelProps, ...props }));
|
|
40
|
+
}
|
|
41
|
+
// Render checkbox
|
|
42
|
+
if (isCheckbox) {
|
|
43
|
+
return (_jsx(CheckboxInput, { ref: ref, id: fieldId, label: label, checkboxLabel: checkboxLabel, error: effectiveError, required: required, value: value, onChange: handleCheckboxChange, disabled: disabled, name: props.name, labelProps: labelProps, ...props }));
|
|
44
|
+
}
|
|
45
|
+
// Render checkbox group
|
|
46
|
+
if (isCheckboxGroup && checkboxOptions) {
|
|
47
|
+
return (_jsx(CheckboxGroupInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, disabled: disabled, checkboxOptions: checkboxOptions, className: props.className, labelProps: labelProps, ...props }));
|
|
48
|
+
}
|
|
49
|
+
// Render date picker
|
|
50
|
+
if (isDatePicker) {
|
|
51
|
+
return (_jsx(DatePickerInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, disabled: disabled, dateFormat: dateFormat, placeholder: props.placeholder, className: props.className, labelProps: labelProps, ...props }));
|
|
52
|
+
}
|
|
53
|
+
// Render input dropdown
|
|
54
|
+
if (isInputDropdown) {
|
|
55
|
+
return (_jsx(DropdownInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, disabled: disabled, dropdownItems: dropdownItems, placeholder: props.placeholder, name: props.name, className: props.className, labelProps: labelProps, ...props }));
|
|
56
|
+
}
|
|
57
|
+
// Render text input dropdown
|
|
58
|
+
if (isTextInputDropdown) {
|
|
59
|
+
return (_jsx(TextDropdownInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, onBlur: props.onBlur, disabled: disabled, dropdownItems: dropdownItems, allowCustomInput: allowCustomInput, placeholder: props.placeholder, name: props.name, className: props.className, labelProps: labelProps, ...props }));
|
|
60
|
+
}
|
|
61
|
+
// Render input PIN
|
|
62
|
+
if (isInputPin) {
|
|
63
|
+
return (_jsx(PinInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: pinValue, onChange: onChange, disabled: disabled, pinLength: pinLength, pinErrorMsg: pinErrorMsg, pinDefaultMsg: pinDefaultMsg, className: props.className, labelProps: labelProps, ...props }));
|
|
64
|
+
}
|
|
65
|
+
// Render input OTP
|
|
66
|
+
if (isInputOtp) {
|
|
67
|
+
return (_jsx(OtpInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: pinValue, onChange: onChange, disabled: disabled, otpLength: otpLength, pinErrorMsg: pinErrorMsg, pinDefaultMsg: pinDefaultMsg, className: props.className, labelProps: labelProps, ...props }));
|
|
68
|
+
}
|
|
69
|
+
// Render CSS Multiline
|
|
70
|
+
if (isCssMultiline) {
|
|
71
|
+
return (_jsx(CssMultilineInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, disabled: disabled, cssProperties: cssProperties, onReset: onReset, onMoreInfo: onMoreInfo, placeholder: props.placeholder, className: props.className, labelProps: labelProps, ...props }));
|
|
72
|
+
}
|
|
73
|
+
// Render InputWrapper
|
|
74
|
+
if (isInputWrapper) {
|
|
75
|
+
return (_jsxs(InputWrapper, { id: fieldId, label: label, className: props.className, hasError: !!error || !!hasError, style: props.style, ref: ref, children: [children || (_jsx("input", { id: fieldId, type: "text", value: value, onChange: onChange, onFocus: props.onFocus, onBlur: props.onBlur, disabled: disabled, placeholder: props.placeholder, name: props.name, autoComplete: props.autoComplete, autoFocus: props.autoFocus, readOnly: props.readOnly, maxLength: props.maxLength, minLength: props.minLength, tabIndex: props.tabIndex, "aria-label": props['aria-label'], "aria-describedby": props['aria-describedby'], "aria-invalid": props['aria-invalid'], "aria-required": props['aria-required'], style: {
|
|
76
|
+
width: '100%',
|
|
77
|
+
padding: '8px 12px',
|
|
78
|
+
border: error || hasError ? '1px solid #ef4444' : '1px solid #d1d5db',
|
|
79
|
+
borderRadius: '6px',
|
|
80
|
+
fontSize: '14px',
|
|
81
|
+
} })), error && (_jsx("div", { style: {
|
|
82
|
+
color: '#ef4444',
|
|
83
|
+
fontSize: '12px',
|
|
84
|
+
marginTop: '4px',
|
|
85
|
+
}, children: error }))] }));
|
|
86
|
+
}
|
|
87
|
+
// Render textarea - use Textarea atom component
|
|
88
|
+
if (isTextarea) {
|
|
89
|
+
return (_jsx(Textarea, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, onValueChange: onValueChange, onBlur: onBlur, onValueBlur: onValueBlur, ...labelProps, ...props }));
|
|
90
|
+
}
|
|
91
|
+
// Render standard input - use Input atom component
|
|
92
|
+
// For password without toggle, use Input atom
|
|
93
|
+
if (isPassword && !showPasswordToggle) {
|
|
94
|
+
return (_jsx(Input, { ref: ref, id: fieldId, type: type, label: label, error: effectiveError, required: required, value: value, onChange: onChange, onValueChange: onValueChange, onBlur: onBlur, onValueBlur: onValueBlur, ...labelProps, ...props }));
|
|
95
|
+
}
|
|
96
|
+
// For password with toggle, use PasswordInput component
|
|
97
|
+
if (isPassword && showPasswordToggle) {
|
|
98
|
+
return (_jsx(PasswordInput, { ref: ref, id: fieldId, label: label, error: effectiveError, required: required, value: value, onChange: onChange, onValueChange: onValueChange, onBlur: onBlur, onValueBlur: onValueBlur, disabled: disabled, labelProps: labelProps, ...props }));
|
|
99
|
+
}
|
|
100
|
+
// Render standard input - use Input atom component
|
|
101
|
+
return (_jsx(Input, { ref: ref, id: fieldId, type: type, label: label, error: effectiveError, required: required, value: value, onChange: onChange, onValueChange: onValueChange, onBlur: onBlur, onValueBlur: onValueBlur, ...labelProps, ...props }));
|
|
102
|
+
});
|
|
103
|
+
FormField.displayName = 'FormField';
|
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useState, useEffect } from 'react';
|
|
3
|
+
import { Label } from '../../../core-components/atoms/Label/Label';
|
|
4
|
+
import { Icon } from '../../Icon/Icon';
|
|
5
|
+
import s from '../../../tc.module.css';
|
|
6
|
+
import { cn } from '../../../utils';
|
|
7
|
+
export const CheckboxGroupInput = React.forwardRef(({ id, label, error, required, value, onChange, disabled, checkboxOptions = [], className, labelProps, ...props }, ref) => {
|
|
8
|
+
const [checkboxList, setCheckboxList] = useState(checkboxOptions);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (checkboxOptions) {
|
|
11
|
+
setCheckboxList(checkboxOptions);
|
|
12
|
+
}
|
|
13
|
+
}, [checkboxOptions]);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (value) {
|
|
16
|
+
setCheckboxList(value);
|
|
17
|
+
}
|
|
18
|
+
}, [value]);
|
|
19
|
+
const handleCheckboxGroupChange = (index) => {
|
|
20
|
+
const result = checkboxList.map((e, i) => {
|
|
21
|
+
if (i === index)
|
|
22
|
+
return { ...e, checked: !e.checked };
|
|
23
|
+
else
|
|
24
|
+
return { ...e };
|
|
25
|
+
});
|
|
26
|
+
setCheckboxList(result);
|
|
27
|
+
if (onChange) {
|
|
28
|
+
onChange(result.filter((item) => item.checked));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return (_jsxs("div", { className: cn(s['w-full'], className), children: [_jsx(Label, { label: label, required: required, ...labelProps, children: checkboxList?.map((item, index) => (_jsxs("div", { className: cn(s['flex'], s['flex-row'], s['items-center'], s['mb-2'], className), onClick: () => {
|
|
32
|
+
if (!disabled) {
|
|
33
|
+
handleCheckboxGroupChange(index);
|
|
34
|
+
}
|
|
35
|
+
}, children: [_jsx("div", { className: cn(s['flex'], s['gap-2']), children: item.checked ? (_jsx(Icon, { nameIcon: "ImCheckboxChecked" })) : (_jsx(Icon, { nameIcon: "ImCheckboxUnchecked" })) }), _jsx("span", { className: cn(s['text-sm'], s['font-medium'], s['ml-2'], disabled && s['cursor-not-allowed'], !disabled && s['cursor-pointer']), children: item?.title })] }, index))) }), error && (_jsx("p", { className: cn(s['mt-1'], s['text-sm'], s['text-red-600'], s['dark:text-red-400']), children: error }))] }));
|
|
36
|
+
});
|
|
37
|
+
CheckboxGroupInput.displayName = 'CheckboxGroupInput';
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import s from '../../../tc.module.css';
|
|
4
|
+
import { cn } from '../../../utils';
|
|
5
|
+
export const CheckboxInput = React.forwardRef(({ id, label, checkboxLabel, error, required, value, onChange, disabled, name, className, labelProps, ...props }, ref) => {
|
|
6
|
+
return (_jsxs("div", { className: cn(s['w-full'], className), children: [_jsxs("div", { className: cn(s['flex'], s['items-center'], s['gap-2']), children: [_jsx("input", { ref: ref, type: "checkbox", id: id, name: name, checked: value, onChange: onChange, disabled: disabled, className: cn(s['w-4'], s['h-4'], s['text-blue-600'], s['bg-gray-100'], s['border-gray-300'], s['focus:ring-blue-500'], s['dark:focus:ring-blue-600'], s['dark:ring-offset-gray-800'], s['focus:ring-2'], s['dark:bg-gray-700'], s['dark:border-gray-600'], className), ...props }), (checkboxLabel || label) && (_jsx("label", { htmlFor: id, className: cn(s['cursor-pointer']), children: checkboxLabel || label }))] }), error && (_jsx("p", { className: cn(s['mt-1'], s['text-sm'], s['text-red-600'], s['dark:text-red-400']), children: error }))] }));
|
|
7
|
+
});
|
|
8
|
+
CheckboxInput.displayName = 'CheckboxInput';
|
|
@@ -1 +1,192 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import { Textarea } from '../../../core-components/atoms/Textarea/Textarea';
|
|
4
|
+
import { Icon } from '../../Icon/Icon';
|
|
5
|
+
import s from '../../../tc.module.css';
|
|
6
|
+
import { cn } from '../../../utils';
|
|
7
|
+
import { properties as defaultCssProperties } from '../css-properties';
|
|
8
|
+
// Helper function to map CSS properties to array format
|
|
9
|
+
const mapToArray = (arr) => {
|
|
10
|
+
const res = [];
|
|
11
|
+
arr.forEach(function (obj, index) {
|
|
12
|
+
const key = Object.keys(obj)[0];
|
|
13
|
+
const value = key;
|
|
14
|
+
res.push([value, obj[key]]);
|
|
15
|
+
});
|
|
16
|
+
return res;
|
|
17
|
+
};
|
|
18
|
+
export const CssMultilineInput = React.forwardRef(({ id, label, error, required, value, onChange, onBlur, disabled, cssProperties, onReset, onMoreInfo, placeholder = "fontSize: 12,backgroundColor:'#000000'", className, labelProps, ...props }, ref) => {
|
|
19
|
+
const [isCssListOpen, setIsCssListOpen] = useState(false);
|
|
20
|
+
const [cssPropertiesList, setCssPropertiesList] = useState(cssProperties || mapToArray(defaultCssProperties));
|
|
21
|
+
const cssValueRef = useRef(value || '');
|
|
22
|
+
const cssWrapperRef = useRef(null);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (cssProperties) {
|
|
25
|
+
setCssPropertiesList(cssProperties);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
setCssPropertiesList(mapToArray(defaultCssProperties));
|
|
29
|
+
}
|
|
30
|
+
}, [cssProperties]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (value !== undefined) {
|
|
33
|
+
cssValueRef.current = value;
|
|
34
|
+
}
|
|
35
|
+
}, [value]);
|
|
36
|
+
// Outside click handler
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
function handleClickOutside(event) {
|
|
39
|
+
if (cssWrapperRef.current &&
|
|
40
|
+
!cssWrapperRef.current.contains(event.target) &&
|
|
41
|
+
isCssListOpen) {
|
|
42
|
+
setIsCssListOpen(false);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
46
|
+
return () => {
|
|
47
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
48
|
+
};
|
|
49
|
+
}, [isCssListOpen]);
|
|
50
|
+
const handleCssFilter = (css) => {
|
|
51
|
+
const props = cssProperties || mapToArray(defaultCssProperties);
|
|
52
|
+
if (css.length === 0) {
|
|
53
|
+
setCssPropertiesList(props);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const matchString = css.split(/,\s*/);
|
|
57
|
+
const lastPart = matchString[matchString.length - 1];
|
|
58
|
+
const key = lastPart.split(':')[0]?.split("'")[0]?.trim();
|
|
59
|
+
const filtered = props.filter((item) => item[0]?.startsWith(key || ''));
|
|
60
|
+
setCssPropertiesList(filtered);
|
|
61
|
+
};
|
|
62
|
+
const handleCssChange = (css) => {
|
|
63
|
+
cssValueRef.current = css;
|
|
64
|
+
handleCssFilter(css);
|
|
65
|
+
};
|
|
66
|
+
// Handle onChange - support both event and value patterns
|
|
67
|
+
const handleChange = (e) => {
|
|
68
|
+
const css = e.target.value;
|
|
69
|
+
handleCssChange(css);
|
|
70
|
+
setIsCssListOpen(true);
|
|
71
|
+
if (onChange) {
|
|
72
|
+
// Support both patterns:
|
|
73
|
+
// 1. Standard React: onChange={(e) => { const val = e.target.value; ... }}
|
|
74
|
+
// 2. Custom: onChange={(value) => { ... value ... }}
|
|
75
|
+
// Check if onChange expects a string (custom pattern) by examining function signature
|
|
76
|
+
// If parameter name suggests it expects a value (not 'e' or 'event'), call with value
|
|
77
|
+
// Otherwise, call with event (standard React pattern)
|
|
78
|
+
try {
|
|
79
|
+
const funcStr = onChange.toString();
|
|
80
|
+
const paramMatch = funcStr.match(/\(([^)]+)\)/);
|
|
81
|
+
if (paramMatch) {
|
|
82
|
+
const param = paramMatch[1].trim();
|
|
83
|
+
// If parameter is not 'e', 'event', or starts with 'e:', it might expect value
|
|
84
|
+
if (param &&
|
|
85
|
+
param !== 'e' &&
|
|
86
|
+
param !== 'event' &&
|
|
87
|
+
!param.startsWith('e:')) {
|
|
88
|
+
// Custom pattern - call with value
|
|
89
|
+
onChange(css);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// Standard React pattern - call with event
|
|
93
|
+
onChange(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Default to standard React pattern
|
|
98
|
+
onChange(e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
// If calling with value fails, try with event
|
|
103
|
+
try {
|
|
104
|
+
onChange(e);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// If both fail, call with value as fallback
|
|
108
|
+
onChange(css);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
// Handle onBlur - support both event and value patterns
|
|
114
|
+
const handleBlur = (e) => {
|
|
115
|
+
if (onBlur) {
|
|
116
|
+
const css = e.target.value;
|
|
117
|
+
// Similar logic for onBlur
|
|
118
|
+
try {
|
|
119
|
+
const funcStr = onBlur.toString();
|
|
120
|
+
const paramMatch = funcStr.match(/\(([^)]+)\)/);
|
|
121
|
+
if (paramMatch) {
|
|
122
|
+
const param = paramMatch[1].trim();
|
|
123
|
+
if (param &&
|
|
124
|
+
param !== 'e' &&
|
|
125
|
+
param !== 'event' &&
|
|
126
|
+
!param.startsWith('e:')) {
|
|
127
|
+
onBlur(css);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
onBlur(e);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
onBlur(e);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
// If calling with value fails, try with event
|
|
139
|
+
try {
|
|
140
|
+
onBlur(e);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// If both fail, call with value as fallback
|
|
144
|
+
onBlur(css);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const handleReset = () => {
|
|
150
|
+
const styles = cssValueRef.current.split(',').filter(Boolean);
|
|
151
|
+
if (styles.length > 0) {
|
|
152
|
+
styles.pop();
|
|
153
|
+
cssValueRef.current = styles.join(',') + (styles.length ? ',' : '');
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
cssValueRef.current = '';
|
|
157
|
+
}
|
|
158
|
+
if (onReset) {
|
|
159
|
+
onReset(cssValueRef.current);
|
|
160
|
+
}
|
|
161
|
+
if (onChange) {
|
|
162
|
+
// When resetting, we call onChange with the value directly (custom pattern)
|
|
163
|
+
// since we don't have an event object
|
|
164
|
+
onChange(cssValueRef.current);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
return (_jsxs("div", { className: cn(s['flex'], s['flex-col'], s['w-full'], s['relative'], className), ref: cssWrapperRef, children: [_jsxs("div", { className: cn(s['flex'], s['absolute'], s['gap-2'], s['right-2'], s['z-10']), children: [onReset && (_jsx(Icon, { nameIcon: "MdLockReset", propsIcon: { color: '#000000', size: 24 }, onClick: handleReset })), onMoreInfo && (_jsx(Icon, { nameIcon: "MdInfoOutline", propsIcon: { color: '#000000', size: 24 }, onClick: onMoreInfo }))] }), _jsx(Textarea, { ref: ref, id: id, label: label, error: error, required: required, placeholder: placeholder, value: cssValueRef.current, onChange: handleChange, onBlur: handleBlur, onKeyUp: () => setIsCssListOpen(true), disabled: disabled, ...labelProps, ...props }), isCssListOpen && cssPropertiesList.length > 0 && (_jsx("div", { children: _jsx("ul", { className: cn(s['flex'], s['flex-col'], s['bg-black'], s['text-white'], s['overflow-y-scroll'], s['w-full']), style: { maxHeight: 'calc(100vh - 20vh)' }, children: cssPropertiesList?.map((item, index) => (_jsxs("li", { className: cn(s['flex'], s['gap-4'], s['p-2']), children: [_jsx("span", { className: cn(s['underline']), children: item[0] }), item[1]?.map((prop, propIndex) => (_jsxs("li", { className: cn(s['flex'], s['bg-slate-800'], s['rounded-md'], s['items-center'], s['cursor-pointer']), onClick: () => {
|
|
168
|
+
let existsString = cssValueRef.current?.split(',');
|
|
169
|
+
if (cssValueRef.current.includes(',')) {
|
|
170
|
+
existsString = existsString.map((item) => {
|
|
171
|
+
if (item?.includes(':'))
|
|
172
|
+
return item;
|
|
173
|
+
});
|
|
174
|
+
if (prop != 'number')
|
|
175
|
+
existsString.push(`${item[0]}:'${prop}',`);
|
|
176
|
+
else
|
|
177
|
+
existsString.push(`${item[0]}:1,`);
|
|
178
|
+
cssValueRef.current = existsString
|
|
179
|
+
.join(',')
|
|
180
|
+
.replaceAll(',,', ',');
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
if (prop != 'number')
|
|
184
|
+
cssValueRef.current = `${item[0]}:'${prop}',`;
|
|
185
|
+
else {
|
|
186
|
+
cssValueRef.current = `${item[0]}:1,`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
handleCssFilter(existsString.join(''));
|
|
190
|
+
}, children: [' ', prop, ' '] }, propIndex)))] }, index))) }) })), error && (_jsx("p", { className: cn(s['mt-1'], s['text-sm'], s['text-red-600'], s['dark:text-red-400']), children: error }))] }));
|
|
191
|
+
});
|
|
192
|
+
CssMultilineInput.displayName = 'CssMultilineInput';
|