@refraktor/core 0.0.4 → 0.0.5
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/components/progress-circle/progress-circle.d.ts.map +1 -1
- package/build/components/progress-circle/progress-circle.js +6 -6
- package/build/components/progress-circle/progress-circle.styles.d.ts +2 -7
- package/build/components/progress-circle/progress-circle.styles.d.ts.map +1 -1
- package/build/components/progress-circle/progress-circle.styles.js +2 -23
- package/build/components/progress-circle/progress-circle.types.d.ts +4 -3
- package/build/components/progress-circle/progress-circle.types.d.ts.map +1 -1
- package/build/components/slider/slider.d.ts.map +1 -1
- package/build/components/slider/slider.js +69 -20
- package/build/components/tooltip/tooltip.js +1 -1
- package/build/style.css +2 -2
- package/package.json +30 -3
- package/.turbo/turbo-build.log +0 -4
- package/refraktor-core-0.0.1-alpha.0.tgz +0 -0
- package/src/components/accordion/accordion-control/accordion-control.tsx +0 -156
- package/src/components/accordion/accordion-control/index.ts +0 -1
- package/src/components/accordion/accordion-item/accordion-item.tsx +0 -40
- package/src/components/accordion/accordion-item/index.ts +0 -1
- package/src/components/accordion/accordion-panel/accordion-panel.tsx +0 -58
- package/src/components/accordion/accordion-panel/index.ts +0 -1
- package/src/components/accordion/accordion.context.ts +0 -93
- package/src/components/accordion/accordion.styles.ts +0 -60
- package/src/components/accordion/accordion.test.tsx +0 -174
- package/src/components/accordion/accordion.tsx +0 -203
- package/src/components/accordion/accordion.types.ts +0 -126
- package/src/components/accordion/index.ts +0 -17
- package/src/components/avatar/avatar-group/avatar-group.tsx +0 -73
- package/src/components/avatar/avatar-group/index.ts +0 -1
- package/src/components/avatar/avatar.styles.ts +0 -11
- package/src/components/avatar/avatar.tsx +0 -142
- package/src/components/avatar/avatar.types.ts +0 -86
- package/src/components/avatar/index.ts +0 -8
- package/src/components/badge/badge.styles.ts +0 -21
- package/src/components/badge/badge.tsx +0 -62
- package/src/components/badge/badge.types.ts +0 -40
- package/src/components/badge/index.ts +0 -2
- package/src/components/breadcrumbs/breadcrumbs.styles.ts +0 -55
- package/src/components/breadcrumbs/breadcrumbs.test.tsx +0 -136
- package/src/components/breadcrumbs/breadcrumbs.tsx +0 -199
- package/src/components/breadcrumbs/breadcrumbs.types.ts +0 -78
- package/src/components/breadcrumbs/breadcrumbs.utils.ts +0 -70
- package/src/components/breadcrumbs/index.ts +0 -6
- package/src/components/button/button.styles.ts +0 -28
- package/src/components/button/button.test.tsx +0 -57
- package/src/components/button/button.tsx +0 -110
- package/src/components/button/button.types.ts +0 -69
- package/src/components/button/index.ts +0 -2
- package/src/components/checkbox/checkbox-group/checkbox-group.tsx +0 -93
- package/src/components/checkbox/checkbox-group/index.ts +0 -1
- package/src/components/checkbox/checkbox.context.ts +0 -14
- package/src/components/checkbox/checkbox.styles.ts +0 -49
- package/src/components/checkbox/checkbox.test.tsx +0 -80
- package/src/components/checkbox/checkbox.tsx +0 -192
- package/src/components/checkbox/checkbox.types.ts +0 -125
- package/src/components/checkbox/index.ts +0 -10
- package/src/components/chip/chip-group/chip-group.tsx +0 -107
- package/src/components/chip/chip-group/index.ts +0 -1
- package/src/components/chip/chip.context.ts +0 -15
- package/src/components/chip/chip.styles.ts +0 -36
- package/src/components/chip/chip.test.tsx +0 -197
- package/src/components/chip/chip.tsx +0 -208
- package/src/components/chip/chip.types.ts +0 -134
- package/src/components/chip/index.ts +0 -10
- package/src/components/color-swatch/color-swatch.styles.ts +0 -11
- package/src/components/color-swatch/color-swatch.test.tsx +0 -80
- package/src/components/color-swatch/color-swatch.tsx +0 -84
- package/src/components/color-swatch/color-swatch.types.ts +0 -46
- package/src/components/color-swatch/index.ts +0 -2
- package/src/components/drawer/drawer-body/drawer-body.tsx +0 -29
- package/src/components/drawer/drawer-body/index.ts +0 -1
- package/src/components/drawer/drawer-close/drawer-close.tsx +0 -43
- package/src/components/drawer/drawer-close/index.ts +0 -1
- package/src/components/drawer/drawer-content/drawer-content.tsx +0 -135
- package/src/components/drawer/drawer-content/index.ts +0 -1
- package/src/components/drawer/drawer-header/drawer-header.tsx +0 -40
- package/src/components/drawer/drawer-header/index.ts +0 -1
- package/src/components/drawer/drawer-overlay/drawer-overlay.tsx +0 -87
- package/src/components/drawer/drawer-overlay/index.ts +0 -1
- package/src/components/drawer/drawer-root/drawer-root.tsx +0 -93
- package/src/components/drawer/drawer-root/index.ts +0 -1
- package/src/components/drawer/drawer.context.ts +0 -26
- package/src/components/drawer/drawer.styles.ts +0 -32
- package/src/components/drawer/drawer.test.tsx +0 -274
- package/src/components/drawer/drawer.tsx +0 -58
- package/src/components/drawer/drawer.types.ts +0 -192
- package/src/components/drawer/index.ts +0 -18
- package/src/components/drawer/use-drawer.ts +0 -94
- package/src/components/file-input/file-input.test.tsx +0 -134
- package/src/components/file-input/file-input.tsx +0 -224
- package/src/components/file-input/file-input.types.ts +0 -78
- package/src/components/file-input/file-input.utils.test.ts +0 -36
- package/src/components/file-input/file-input.utils.ts +0 -130
- package/src/components/file-input/index.ts +0 -2
- package/src/components/for/for.test.tsx +0 -66
- package/src/components/for/for.tsx +0 -53
- package/src/components/for/for.types.ts +0 -40
- package/src/components/for/index.ts +0 -2
- package/src/components/index.ts +0 -35
- package/src/components/input/index.ts +0 -2
- package/src/components/input/input-description/index.ts +0 -2
- package/src/components/input/input-description/input-description.tsx +0 -36
- package/src/components/input/input-error/index.ts +0 -2
- package/src/components/input/input-error/input-error.tsx +0 -36
- package/src/components/input/input-field/index.ts +0 -1
- package/src/components/input/input-field/input-field.styles.ts +0 -23
- package/src/components/input/input-field/input-field.tsx +0 -94
- package/src/components/input/input-label/index.ts +0 -2
- package/src/components/input/input-label/input-label.tsx +0 -47
- package/src/components/input/input-wrapper/index.ts +0 -2
- package/src/components/input/input-wrapper/input-wrapper.tsx +0 -43
- package/src/components/input/input.tsx +0 -71
- package/src/components/input/input.types.ts +0 -111
- package/src/components/loader/index.ts +0 -2
- package/src/components/loader/loader.tsx +0 -89
- package/src/components/loader/loader.types.ts +0 -33
- package/src/components/menu/index.ts +0 -24
- package/src/components/menu/menu-dropdown/index.ts +0 -1
- package/src/components/menu/menu-dropdown/menu-dropdown.tsx +0 -220
- package/src/components/menu/menu-item/index.ts +0 -1
- package/src/components/menu/menu-item/menu-item.tsx +0 -126
- package/src/components/menu/menu-label/index.ts +0 -1
- package/src/components/menu/menu-label/menu-label.tsx +0 -30
- package/src/components/menu/menu-separator/index.ts +0 -1
- package/src/components/menu/menu-separator/menu-separator.tsx +0 -28
- package/src/components/menu/menu-sub/index.ts +0 -1
- package/src/components/menu/menu-sub/menu-sub.tsx +0 -117
- package/src/components/menu/menu-sub-dropdown/index.ts +0 -1
- package/src/components/menu/menu-sub-dropdown/menu-sub-dropdown.tsx +0 -221
- package/src/components/menu/menu-sub-trigger/index.ts +0 -1
- package/src/components/menu/menu-sub-trigger/menu-sub-trigger.tsx +0 -164
- package/src/components/menu/menu-trigger/index.ts +0 -1
- package/src/components/menu/menu-trigger/menu-trigger.tsx +0 -98
- package/src/components/menu/menu.context.ts +0 -162
- package/src/components/menu/menu.test.tsx +0 -136
- package/src/components/menu/menu.tsx +0 -133
- package/src/components/menu/menu.types.ts +0 -291
- package/src/components/menu/use-menu.ts +0 -204
- package/src/components/modal/index.ts +0 -18
- package/src/components/modal/modal-body/index.ts +0 -1
- package/src/components/modal/modal-body/modal-body.tsx +0 -29
- package/src/components/modal/modal-close/index.ts +0 -1
- package/src/components/modal/modal-close/modal-close.tsx +0 -43
- package/src/components/modal/modal-content/index.ts +0 -1
- package/src/components/modal/modal-content/modal-content.tsx +0 -119
- package/src/components/modal/modal-header/index.ts +0 -1
- package/src/components/modal/modal-header/modal-header.tsx +0 -40
- package/src/components/modal/modal-overlay/index.ts +0 -1
- package/src/components/modal/modal-overlay/modal-overlay.tsx +0 -87
- package/src/components/modal/modal-root/index.ts +0 -1
- package/src/components/modal/modal-root/modal-root.tsx +0 -93
- package/src/components/modal/modal.context.ts +0 -26
- package/src/components/modal/modal.test.tsx +0 -316
- package/src/components/modal/modal.tsx +0 -58
- package/src/components/modal/modal.types.ts +0 -189
- package/src/components/modal/use-modal.ts +0 -94
- package/src/components/number-input/index.ts +0 -2
- package/src/components/number-input/number-input.styles.ts +0 -37
- package/src/components/number-input/number-input.test.tsx +0 -22
- package/src/components/number-input/number-input.tsx +0 -381
- package/src/components/number-input/number-input.types.ts +0 -58
- package/src/components/pagination/index.ts +0 -7
- package/src/components/pagination/pagination.styles.ts +0 -84
- package/src/components/pagination/pagination.test.tsx +0 -117
- package/src/components/pagination/pagination.tsx +0 -371
- package/src/components/pagination/pagination.types.ts +0 -95
- package/src/components/pagination/pagination.utils.ts +0 -88
- package/src/components/password-input/index.ts +0 -2
- package/src/components/password-input/password-input.test.tsx +0 -72
- package/src/components/password-input/password-input.tsx +0 -85
- package/src/components/password-input/password-input.types.ts +0 -30
- package/src/components/pin-input/index.ts +0 -2
- package/src/components/pin-input/pin-input.test.tsx +0 -149
- package/src/components/pin-input/pin-input.tsx +0 -473
- package/src/components/pin-input/pin-input.types.ts +0 -78
- package/src/components/popover/index.ts +0 -12
- package/src/components/popover/popover-dropdown/index.ts +0 -1
- package/src/components/popover/popover-dropdown/popover-dropdown.tsx +0 -94
- package/src/components/popover/popover-trigger/index.ts +0 -1
- package/src/components/popover/popover-trigger/popover-trigger.tsx +0 -49
- package/src/components/popover/popover.context.ts +0 -20
- package/src/components/popover/popover.tsx +0 -113
- package/src/components/popover/popover.types.ts +0 -137
- package/src/components/popover/use-popover.ts +0 -219
- package/src/components/portal/index.ts +0 -2
- package/src/components/portal/portal.test.tsx +0 -39
- package/src/components/portal/portal.tsx +0 -104
- package/src/components/portal/portal.types.ts +0 -31
- package/src/components/progress/index.ts +0 -2
- package/src/components/progress/progress.styles.ts +0 -25
- package/src/components/progress/progress.test.tsx +0 -107
- package/src/components/progress/progress.tsx +0 -93
- package/src/components/progress/progress.types.ts +0 -52
- package/src/components/progress-circle/index.ts +0 -5
- package/src/components/progress-circle/progress-circle.styles.ts +0 -31
- package/src/components/progress-circle/progress-circle.test.tsx +0 -140
- package/src/components/progress-circle/progress-circle.tsx +0 -124
- package/src/components/progress-circle/progress-circle.types.ts +0 -52
- package/src/components/radio/index.ts +0 -10
- package/src/components/radio/radio-group/index.ts +0 -1
- package/src/components/radio/radio-group/radio-group.tsx +0 -89
- package/src/components/radio/radio.context.ts +0 -14
- package/src/components/radio/radio.styles.ts +0 -49
- package/src/components/radio/radio.test.tsx +0 -75
- package/src/components/radio/radio.tsx +0 -173
- package/src/components/radio/radio.types.ts +0 -126
- package/src/components/scroll-area/index.ts +0 -6
- package/src/components/scroll-area/scroll-area.test.tsx +0 -72
- package/src/components/scroll-area/scroll-area.tsx +0 -70
- package/src/components/scroll-area/scroll-area.types.ts +0 -37
- package/src/components/segmented-control/index.ts +0 -6
- package/src/components/segmented-control/segmented-control.styles.ts +0 -37
- package/src/components/segmented-control/segmented-control.test.tsx +0 -170
- package/src/components/segmented-control/segmented-control.tsx +0 -255
- package/src/components/segmented-control/segmented-control.types.ts +0 -78
- package/src/components/select/index.ts +0 -20
- package/src/components/select/select-dropdown/index.ts +0 -1
- package/src/components/select/select-dropdown/select-dropdown.tsx +0 -299
- package/src/components/select/select-group/index.ts +0 -1
- package/src/components/select/select-group/select-group.tsx +0 -47
- package/src/components/select/select-item/index.ts +0 -1
- package/src/components/select/select-item/select-item.tsx +0 -157
- package/src/components/select/select-root/index.ts +0 -1
- package/src/components/select/select-root/select-root.tsx +0 -333
- package/src/components/select/select-trigger/index.ts +0 -1
- package/src/components/select/select-trigger/select-trigger.tsx +0 -123
- package/src/components/select/select.context.ts +0 -140
- package/src/components/select/select.test.tsx +0 -190
- package/src/components/select/select.tsx +0 -82
- package/src/components/select/select.types.ts +0 -272
- package/src/components/select/use-select.ts +0 -170
- package/src/components/slider/index.ts +0 -7
- package/src/components/slider/slider.styles.ts +0 -37
- package/src/components/slider/slider.tsx +0 -275
- package/src/components/slider/slider.types.ts +0 -82
- package/src/components/switch/index.ts +0 -2
- package/src/components/switch/switch.styles.ts +0 -31
- package/src/components/switch/switch.tsx +0 -132
- package/src/components/switch/switch.types.ts +0 -62
- package/src/components/table/index.ts +0 -24
- package/src/components/table/table-body/index.ts +0 -1
- package/src/components/table/table-body/table-body.tsx +0 -37
- package/src/components/table/table-caption/index.ts +0 -1
- package/src/components/table/table-caption/table-caption.tsx +0 -32
- package/src/components/table/table-cell/index.ts +0 -1
- package/src/components/table/table-cell/table-cell.tsx +0 -33
- package/src/components/table/table-head/index.ts +0 -1
- package/src/components/table/table-head/table-head.tsx +0 -29
- package/src/components/table/table-header-cell/index.ts +0 -1
- package/src/components/table/table-header-cell/table-header-cell.tsx +0 -33
- package/src/components/table/table-row/index.ts +0 -1
- package/src/components/table/table-row/table-row.tsx +0 -30
- package/src/components/table/table.context.ts +0 -18
- package/src/components/table/table.styles.ts +0 -62
- package/src/components/table/table.test.tsx +0 -145
- package/src/components/table/table.tsx +0 -91
- package/src/components/table/table.types.ts +0 -145
- package/src/components/tabs/index.ts +0 -18
- package/src/components/tabs/tabs-list/index.ts +0 -1
- package/src/components/tabs/tabs-list/tabs-list.tsx +0 -42
- package/src/components/tabs/tabs-panel/index.ts +0 -1
- package/src/components/tabs/tabs-panel/tabs-panel.tsx +0 -58
- package/src/components/tabs/tabs-tab/index.ts +0 -1
- package/src/components/tabs/tabs-tab/tabs-tab.tsx +0 -210
- package/src/components/tabs/tabs.context.ts +0 -88
- package/src/components/tabs/tabs.styles.ts +0 -92
- package/src/components/tabs/tabs.test.tsx +0 -167
- package/src/components/tabs/tabs.tsx +0 -137
- package/src/components/tabs/tabs.types.ts +0 -128
- package/src/components/textarea/index.ts +0 -2
- package/src/components/textarea/textarea-field/index.ts +0 -1
- package/src/components/textarea/textarea-field/textarea-field.styles.ts +0 -34
- package/src/components/textarea/textarea-field/textarea-field.tsx +0 -96
- package/src/components/textarea/textarea.tsx +0 -64
- package/src/components/textarea/textarea.types.ts +0 -80
- package/src/components/timeline/index.ts +0 -11
- package/src/components/timeline/timeline-item/index.ts +0 -1
- package/src/components/timeline/timeline-item/timeline-item.tsx +0 -158
- package/src/components/timeline/timeline.context.ts +0 -21
- package/src/components/timeline/timeline.styles.ts +0 -135
- package/src/components/timeline/timeline.test.tsx +0 -150
- package/src/components/timeline/timeline.tsx +0 -124
- package/src/components/timeline/timeline.types.ts +0 -91
- package/src/components/tooltip/index.ts +0 -8
- package/src/components/tooltip/tooltip.tsx +0 -164
- package/src/components/tooltip/tooltip.types.ts +0 -104
- package/src/components/tooltip/use-tooltip.ts +0 -200
- package/src/components/transition/index.ts +0 -11
- package/src/components/transition/transition.test.tsx +0 -126
- package/src/components/transition/transition.tsx +0 -441
- package/src/components/transition/transition.types.ts +0 -97
- package/src/components/transition/transitions.ts +0 -140
- package/src/icons/check.tsx +0 -25
- package/src/icons/chevron.tsx +0 -46
- package/src/icons/eye-off.tsx +0 -30
- package/src/icons/eye.tsx +0 -24
- package/src/icons/index.ts +0 -7
- package/src/icons/minus.tsx +0 -24
- package/src/icons/types.ts +0 -9
- package/src/icons/user.tsx +0 -18
- package/src/icons/x.tsx +0 -35
- package/src/index.ts +0 -5
- package/src/style.css +0 -334
- package/src/theme/ThemeProvider/ThemeProvider.tsx +0 -111
- package/src/theme/ThemeProvider/context.ts +0 -7
- package/src/theme/ThemeProvider/generateVariables.test.ts +0 -49
- package/src/theme/ThemeProvider/generateVariables.ts +0 -124
- package/src/theme/ThemeProvider/index.ts +0 -3
- package/src/theme/ThemeProvider/types.ts +0 -37
- package/src/theme/createTheme/createTheme.ts +0 -41
- package/src/theme/createTheme/index.ts +0 -7
- package/src/theme/createTheme/types.ts +0 -62
- package/src/theme/defaults/colors.ts +0 -203
- package/src/theme/defaults/settings.ts +0 -8
- package/src/theme/index.ts +0 -4
- package/src/theme/types.ts +0 -31
- package/src/theme/utils/get-radius.ts +0 -23
- package/src/theme/utils/get-shade.ts +0 -16
- package/src/theme/utils/index.ts +0 -3
- package/src/theme/utils/use-theme.ts +0 -27
- package/src/utils/configs/create-config.ts +0 -15
- package/src/utils/configs/index.ts +0 -3
- package/src/utils/configs/use-class-names.ts +0 -41
- package/src/utils/configs/use-props.ts +0 -55
- package/src/utils/cx/index.ts +0 -6
- package/src/utils/factory/factory.ts +0 -23
- package/src/utils/factory/index.ts +0 -14
- package/src/utils/factory/types.ts +0 -92
- package/src/utils/index.ts +0 -3
- package/src/vitest/index.ts +0 -1
- package/src/vitest/setup.tsx +0 -20
- package/src/vitest/utils.tsx +0 -59
- package/tsconfig.json +0 -13
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.js +0 -19
|
@@ -1,473 +0,0 @@
|
|
|
1
|
-
import { useId, useUncontrolled } from "@refraktor/utils";
|
|
2
|
-
import { useCallback, useMemo, useRef } from "react";
|
|
3
|
-
import { useTheme } from "../../theme";
|
|
4
|
-
import {
|
|
5
|
-
createClassNamesConfig,
|
|
6
|
-
createComponentConfig,
|
|
7
|
-
factory,
|
|
8
|
-
useClassNames,
|
|
9
|
-
useProps
|
|
10
|
-
} from "../../utils";
|
|
11
|
-
import { getVariant } from "../input/input-field/input-field.styles";
|
|
12
|
-
import { InputWrapper } from "../input/input-wrapper";
|
|
13
|
-
import {
|
|
14
|
-
PinInputCharacterSet,
|
|
15
|
-
PinInputClassNames,
|
|
16
|
-
PinInputFactoryPayload,
|
|
17
|
-
PinInputProps,
|
|
18
|
-
PinInputTransform
|
|
19
|
-
} from "./pin-input.types";
|
|
20
|
-
|
|
21
|
-
const CHARACTER_SET_PATTERNS: Record<PinInputCharacterSet, RegExp> = {
|
|
22
|
-
numeric: /^[0-9]$/,
|
|
23
|
-
alphabetic: /^[A-Za-z]$/,
|
|
24
|
-
alphanumeric: /^[A-Za-z0-9]$/,
|
|
25
|
-
all: /^.$/
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const CELL_SIZES = {
|
|
29
|
-
xs: "h-7 w-7 text-[10px]",
|
|
30
|
-
sm: "h-8 w-8 text-xs",
|
|
31
|
-
md: "h-10 w-10 text-sm",
|
|
32
|
-
lg: "h-12 w-12 text-base",
|
|
33
|
-
xl: "h-14 w-14 text-lg"
|
|
34
|
-
} as const;
|
|
35
|
-
|
|
36
|
-
const defaultProps = {
|
|
37
|
-
length: 6,
|
|
38
|
-
variant: "default",
|
|
39
|
-
size: "md",
|
|
40
|
-
radius: "default",
|
|
41
|
-
mask: false,
|
|
42
|
-
characterSet: "numeric",
|
|
43
|
-
transform: "none",
|
|
44
|
-
ariaLabelPrefix: "Character",
|
|
45
|
-
autoComplete: "one-time-code"
|
|
46
|
-
} satisfies Partial<PinInputProps>;
|
|
47
|
-
|
|
48
|
-
function normalizeLength(value: number | undefined): number {
|
|
49
|
-
const length = Number.isFinite(value) ? Math.trunc(value as number) : 6;
|
|
50
|
-
return Math.max(1, length);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function transformCharacter(
|
|
54
|
-
char: string,
|
|
55
|
-
transform: PinInputTransform
|
|
56
|
-
): string {
|
|
57
|
-
if (transform === "uppercase") {
|
|
58
|
-
return char.toUpperCase();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (transform === "lowercase") {
|
|
62
|
-
return char.toLowerCase();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return char;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function isAllowedCharacter(
|
|
69
|
-
char: string,
|
|
70
|
-
characterSet: PinInputCharacterSet,
|
|
71
|
-
characterPattern?: RegExp
|
|
72
|
-
): boolean {
|
|
73
|
-
const pattern = characterPattern ?? CHARACTER_SET_PATTERNS[characterSet];
|
|
74
|
-
pattern.lastIndex = 0;
|
|
75
|
-
return pattern.test(char);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function toSanitizedChars(
|
|
79
|
-
value: string,
|
|
80
|
-
options: {
|
|
81
|
-
characterSet: PinInputCharacterSet;
|
|
82
|
-
characterPattern?: RegExp;
|
|
83
|
-
transform: PinInputTransform;
|
|
84
|
-
}
|
|
85
|
-
): string[] {
|
|
86
|
-
const result: string[] = [];
|
|
87
|
-
|
|
88
|
-
for (const rawChar of value) {
|
|
89
|
-
const transformedChar = transformCharacter(rawChar, options.transform);
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
transformedChar &&
|
|
93
|
-
isAllowedCharacter(
|
|
94
|
-
transformedChar,
|
|
95
|
-
options.characterSet,
|
|
96
|
-
options.characterPattern
|
|
97
|
-
)
|
|
98
|
-
) {
|
|
99
|
-
result.push(transformedChar);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function toCellArray(
|
|
107
|
-
value: string,
|
|
108
|
-
length: number,
|
|
109
|
-
options: {
|
|
110
|
-
characterSet: PinInputCharacterSet;
|
|
111
|
-
characterPattern?: RegExp;
|
|
112
|
-
transform: PinInputTransform;
|
|
113
|
-
}
|
|
114
|
-
): string[] {
|
|
115
|
-
const chars = toSanitizedChars(value, options).slice(0, length);
|
|
116
|
-
|
|
117
|
-
return Array.from({ length }, (_, index) => chars[index] ?? "");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function normalizeCells(cells: string[] | undefined, length: number): string[] {
|
|
121
|
-
return Array.from({ length }, (_, index) => cells?.[index] ?? "");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const PinInput = factory<PinInputFactoryPayload>((_props, ref) => {
|
|
125
|
-
const { cx, getRadius } = useTheme();
|
|
126
|
-
const {
|
|
127
|
-
id,
|
|
128
|
-
label,
|
|
129
|
-
description,
|
|
130
|
-
error,
|
|
131
|
-
required,
|
|
132
|
-
withAsterisk,
|
|
133
|
-
length,
|
|
134
|
-
value,
|
|
135
|
-
defaultValue,
|
|
136
|
-
onChange,
|
|
137
|
-
onComplete,
|
|
138
|
-
mask,
|
|
139
|
-
characterSet,
|
|
140
|
-
characterPattern,
|
|
141
|
-
transform,
|
|
142
|
-
ariaLabelPrefix,
|
|
143
|
-
name,
|
|
144
|
-
variant,
|
|
145
|
-
size,
|
|
146
|
-
radius,
|
|
147
|
-
disabled,
|
|
148
|
-
className,
|
|
149
|
-
classNames,
|
|
150
|
-
inputMode,
|
|
151
|
-
autoComplete,
|
|
152
|
-
placeholder,
|
|
153
|
-
...props
|
|
154
|
-
} = useProps("PinInput", defaultProps, _props);
|
|
155
|
-
|
|
156
|
-
const classes = useClassNames<PinInputClassNames>("PinInput", classNames);
|
|
157
|
-
const _id = useId(id);
|
|
158
|
-
|
|
159
|
-
const resolvedLength = normalizeLength(length);
|
|
160
|
-
const sanitizingOptions = useMemo(
|
|
161
|
-
() => ({
|
|
162
|
-
characterSet,
|
|
163
|
-
characterPattern,
|
|
164
|
-
transform
|
|
165
|
-
}),
|
|
166
|
-
[characterSet, characterPattern, transform]
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
const emptyCells = useMemo(
|
|
170
|
-
() => Array.from({ length: resolvedLength }, () => ""),
|
|
171
|
-
[resolvedLength]
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
const [_valueCells, setValueCells] = useUncontrolled<string[]>({
|
|
175
|
-
value:
|
|
176
|
-
value === undefined
|
|
177
|
-
? undefined
|
|
178
|
-
: toCellArray(String(value), resolvedLength, sanitizingOptions),
|
|
179
|
-
defaultValue:
|
|
180
|
-
defaultValue === undefined
|
|
181
|
-
? undefined
|
|
182
|
-
: toCellArray(
|
|
183
|
-
String(defaultValue),
|
|
184
|
-
resolvedLength,
|
|
185
|
-
sanitizingOptions
|
|
186
|
-
),
|
|
187
|
-
finalValue: emptyCells,
|
|
188
|
-
onChange: (nextCells) => onChange?.(nextCells.join(""))
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const chars = useMemo(
|
|
192
|
-
() => normalizeCells(_valueCells, resolvedLength),
|
|
193
|
-
[_valueCells, resolvedLength]
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
const charsRef = useRef(chars);
|
|
197
|
-
charsRef.current = chars;
|
|
198
|
-
|
|
199
|
-
const completedValueRef = useRef<string | null>(null);
|
|
200
|
-
const inputRefs = useRef<Array<HTMLInputElement | null>>([]);
|
|
201
|
-
|
|
202
|
-
const hasWrapper = label || description || error;
|
|
203
|
-
const describedBy = error
|
|
204
|
-
? `${_id}-error`
|
|
205
|
-
: description
|
|
206
|
-
? `${_id}-description`
|
|
207
|
-
: undefined;
|
|
208
|
-
|
|
209
|
-
const resolvedInputMode =
|
|
210
|
-
inputMode ?? (characterSet === "numeric" ? "numeric" : "text");
|
|
211
|
-
|
|
212
|
-
const emitValue = useCallback(
|
|
213
|
-
(nextChars: string[]) => {
|
|
214
|
-
setValueCells(nextChars);
|
|
215
|
-
|
|
216
|
-
const nextValue = nextChars.join("");
|
|
217
|
-
|
|
218
|
-
if (!nextChars.includes("")) {
|
|
219
|
-
if (completedValueRef.current !== nextValue) {
|
|
220
|
-
onComplete?.(nextValue);
|
|
221
|
-
completedValueRef.current = nextValue;
|
|
222
|
-
}
|
|
223
|
-
} else {
|
|
224
|
-
completedValueRef.current = null;
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
[onComplete, setValueCells]
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
const focusCell = useCallback(
|
|
231
|
-
(index: number) => {
|
|
232
|
-
if (index < 0 || index >= resolvedLength) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
setTimeout(() => {
|
|
237
|
-
const input = inputRefs.current[index];
|
|
238
|
-
if (!input) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
input.focus();
|
|
243
|
-
input.select();
|
|
244
|
-
}, 0);
|
|
245
|
-
},
|
|
246
|
-
[resolvedLength]
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
const fillFromIndex = useCallback(
|
|
250
|
-
(index: number, incoming: string[]) => {
|
|
251
|
-
const next = [...charsRef.current];
|
|
252
|
-
let writeIndex = index;
|
|
253
|
-
|
|
254
|
-
for (const char of incoming) {
|
|
255
|
-
if (writeIndex >= resolvedLength) {
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
next[writeIndex] = char;
|
|
260
|
-
writeIndex += 1;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
emitValue(next);
|
|
264
|
-
|
|
265
|
-
if (writeIndex < resolvedLength) {
|
|
266
|
-
focusCell(writeIndex);
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
focusCell(resolvedLength - 1);
|
|
271
|
-
},
|
|
272
|
-
[emitValue, focusCell, resolvedLength]
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
const handleCellChange = useCallback(
|
|
276
|
-
(index: number, event: React.ChangeEvent<HTMLInputElement>) => {
|
|
277
|
-
if (disabled) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const incoming = toSanitizedChars(
|
|
282
|
-
event.currentTarget.value,
|
|
283
|
-
sanitizingOptions
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
if (incoming.length === 0) {
|
|
287
|
-
if (event.currentTarget.value !== "") {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const next = [...charsRef.current];
|
|
292
|
-
next[index] = "";
|
|
293
|
-
emitValue(next);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (incoming.length === 1) {
|
|
298
|
-
const next = [...charsRef.current];
|
|
299
|
-
next[index] = incoming[0];
|
|
300
|
-
emitValue(next);
|
|
301
|
-
|
|
302
|
-
if (index < resolvedLength - 1) {
|
|
303
|
-
focusCell(index + 1);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
fillFromIndex(index, incoming);
|
|
310
|
-
},
|
|
311
|
-
[
|
|
312
|
-
disabled,
|
|
313
|
-
sanitizingOptions,
|
|
314
|
-
emitValue,
|
|
315
|
-
resolvedLength,
|
|
316
|
-
focusCell,
|
|
317
|
-
fillFromIndex
|
|
318
|
-
]
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
const handlePaste = useCallback(
|
|
322
|
-
(index: number, event: React.ClipboardEvent<HTMLInputElement>) => {
|
|
323
|
-
event.preventDefault();
|
|
324
|
-
|
|
325
|
-
if (disabled) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const incoming = toSanitizedChars(
|
|
330
|
-
event.clipboardData.getData("text"),
|
|
331
|
-
sanitizingOptions
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
if (incoming.length === 0) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
fillFromIndex(index, incoming);
|
|
339
|
-
},
|
|
340
|
-
[disabled, sanitizingOptions, fillFromIndex]
|
|
341
|
-
);
|
|
342
|
-
|
|
343
|
-
const handleKeyDown = useCallback(
|
|
344
|
-
(index: number, event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
345
|
-
if (disabled) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (event.key === "ArrowLeft") {
|
|
350
|
-
event.preventDefault();
|
|
351
|
-
focusCell(index - 1);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
if (event.key === "ArrowRight") {
|
|
356
|
-
event.preventDefault();
|
|
357
|
-
focusCell(index + 1);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (event.key === "Home") {
|
|
362
|
-
event.preventDefault();
|
|
363
|
-
focusCell(0);
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (event.key === "End") {
|
|
368
|
-
event.preventDefault();
|
|
369
|
-
focusCell(resolvedLength - 1);
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (event.key === "Backspace") {
|
|
374
|
-
event.preventDefault();
|
|
375
|
-
const next = [...charsRef.current];
|
|
376
|
-
|
|
377
|
-
if (next[index]) {
|
|
378
|
-
next[index] = "";
|
|
379
|
-
emitValue(next);
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (index > 0) {
|
|
384
|
-
next[index - 1] = "";
|
|
385
|
-
emitValue(next);
|
|
386
|
-
focusCell(index - 1);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
if (event.key === "Delete") {
|
|
393
|
-
event.preventDefault();
|
|
394
|
-
const next = [...charsRef.current];
|
|
395
|
-
next[index] = "";
|
|
396
|
-
emitValue(next);
|
|
397
|
-
}
|
|
398
|
-
},
|
|
399
|
-
[disabled, emitValue, focusCell, resolvedLength]
|
|
400
|
-
);
|
|
401
|
-
|
|
402
|
-
const field = (
|
|
403
|
-
<div
|
|
404
|
-
ref={ref}
|
|
405
|
-
className={cx(
|
|
406
|
-
"flex w-full items-center gap-2",
|
|
407
|
-
className,
|
|
408
|
-
classes.root
|
|
409
|
-
)}
|
|
410
|
-
>
|
|
411
|
-
{chars.map((char, index) => (
|
|
412
|
-
<input
|
|
413
|
-
key={`${_id}-cell-${index}`}
|
|
414
|
-
{...props}
|
|
415
|
-
id={`${_id}-${index}`}
|
|
416
|
-
ref={(node) => {
|
|
417
|
-
inputRefs.current[index] = node;
|
|
418
|
-
}}
|
|
419
|
-
type={mask ? "password" : "text"}
|
|
420
|
-
inputMode={resolvedInputMode}
|
|
421
|
-
autoComplete={index === 0 ? autoComplete : "off"}
|
|
422
|
-
maxLength={resolvedLength}
|
|
423
|
-
value={char}
|
|
424
|
-
disabled={disabled}
|
|
425
|
-
required={required && index === 0}
|
|
426
|
-
placeholder={placeholder}
|
|
427
|
-
aria-invalid={error ? true : undefined}
|
|
428
|
-
aria-describedby={describedBy}
|
|
429
|
-
aria-label={`${ariaLabelPrefix} ${index + 1} of ${resolvedLength}`}
|
|
430
|
-
className={cx(
|
|
431
|
-
"flex-none text-center font-medium tabular-nums outline-none transition-colors",
|
|
432
|
-
"focus:border-[var(--refraktor-primary)]",
|
|
433
|
-
getVariant(variant),
|
|
434
|
-
getRadius(radius),
|
|
435
|
-
CELL_SIZES[size],
|
|
436
|
-
error && "border-[var(--refraktor-colors-red-6)]",
|
|
437
|
-
disabled && "cursor-not-allowed opacity-50",
|
|
438
|
-
classes.cell
|
|
439
|
-
)}
|
|
440
|
-
onChange={(event) => handleCellChange(index, event)}
|
|
441
|
-
onKeyDown={(event) => handleKeyDown(index, event)}
|
|
442
|
-
onPaste={(event) => handlePaste(index, event)}
|
|
443
|
-
onFocus={(event) => event.currentTarget.select()}
|
|
444
|
-
/>
|
|
445
|
-
))}
|
|
446
|
-
|
|
447
|
-
{name && <input type="hidden" name={name} value={chars.join("")} />}
|
|
448
|
-
</div>
|
|
449
|
-
);
|
|
450
|
-
|
|
451
|
-
if (!hasWrapper) {
|
|
452
|
-
return field;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return (
|
|
456
|
-
<InputWrapper
|
|
457
|
-
label={label}
|
|
458
|
-
description={description}
|
|
459
|
-
error={error}
|
|
460
|
-
required={required}
|
|
461
|
-
withAsterisk={withAsterisk}
|
|
462
|
-
inputId={`${_id}-0`}
|
|
463
|
-
>
|
|
464
|
-
{field}
|
|
465
|
-
</InputWrapper>
|
|
466
|
-
);
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
PinInput.displayName = "@refraktor/core/PinInput";
|
|
470
|
-
PinInput.configure = createComponentConfig<PinInputProps>();
|
|
471
|
-
PinInput.classNames = createClassNamesConfig<PinInputClassNames>();
|
|
472
|
-
|
|
473
|
-
export default PinInput;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createClassNamesConfig,
|
|
3
|
-
createComponentConfig,
|
|
4
|
-
FactoryPayload
|
|
5
|
-
} from "../../utils";
|
|
6
|
-
import { InputProps } from "../input";
|
|
7
|
-
|
|
8
|
-
export type PinInputCharacterSet =
|
|
9
|
-
| "numeric"
|
|
10
|
-
| "alphabetic"
|
|
11
|
-
| "alphanumeric"
|
|
12
|
-
| "all";
|
|
13
|
-
|
|
14
|
-
export type PinInputTransform = "none" | "uppercase" | "lowercase";
|
|
15
|
-
|
|
16
|
-
export type PinInputClassNames = {
|
|
17
|
-
root?: string;
|
|
18
|
-
cell?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export interface _PinInputProps {
|
|
22
|
-
/** OTP length @default `6` */
|
|
23
|
-
length?: number;
|
|
24
|
-
|
|
25
|
-
/** Value (controlled) */
|
|
26
|
-
value?: string;
|
|
27
|
-
|
|
28
|
-
/** Default value (uncontrolled) */
|
|
29
|
-
defaultValue?: string;
|
|
30
|
-
|
|
31
|
-
/** Callback called whenever the code value changes */
|
|
32
|
-
onChange?: (value: string) => void;
|
|
33
|
-
|
|
34
|
-
/** Callback called when all cells are filled */
|
|
35
|
-
onComplete?: (value: string) => void;
|
|
36
|
-
|
|
37
|
-
/** Masks entered characters @default `false` */
|
|
38
|
-
mask?: boolean;
|
|
39
|
-
|
|
40
|
-
/** Character set filter @default `numeric` */
|
|
41
|
-
characterSet?: PinInputCharacterSet;
|
|
42
|
-
|
|
43
|
-
/** Optional custom character pattern (overrides characterSet) */
|
|
44
|
-
characterPattern?: RegExp;
|
|
45
|
-
|
|
46
|
-
/** Character transform @default `none` */
|
|
47
|
-
transform?: PinInputTransform;
|
|
48
|
-
|
|
49
|
-
/** Accessible label prefix for each cell @default `Character` */
|
|
50
|
-
ariaLabelPrefix?: string;
|
|
51
|
-
|
|
52
|
-
/** Hidden input name for form submission */
|
|
53
|
-
name?: string;
|
|
54
|
-
|
|
55
|
-
/** Used for styling different parts of the component */
|
|
56
|
-
classNames?: PinInputClassNames;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type PinInputProps = _PinInputProps &
|
|
60
|
-
Omit<
|
|
61
|
-
InputProps,
|
|
62
|
-
| "type"
|
|
63
|
-
| "value"
|
|
64
|
-
| "defaultValue"
|
|
65
|
-
| "onChange"
|
|
66
|
-
| "leftSection"
|
|
67
|
-
| "rightSection"
|
|
68
|
-
| "maxLength"
|
|
69
|
-
>;
|
|
70
|
-
|
|
71
|
-
export interface PinInputFactoryPayload extends FactoryPayload {
|
|
72
|
-
props: PinInputProps;
|
|
73
|
-
ref: HTMLDivElement;
|
|
74
|
-
compound: {
|
|
75
|
-
configure: ReturnType<typeof createComponentConfig<PinInputProps>>;
|
|
76
|
-
classNames: ReturnType<typeof createClassNamesConfig<PinInputClassNames>>;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { default as Popover } from "./popover";
|
|
2
|
-
export { PopoverTrigger } from "./popover-trigger";
|
|
3
|
-
export { PopoverDropdown } from "./popover-dropdown";
|
|
4
|
-
export type {
|
|
5
|
-
PopoverProps,
|
|
6
|
-
PopoverTriggerProps,
|
|
7
|
-
PopoverDropdownProps,
|
|
8
|
-
PopoverClassNames,
|
|
9
|
-
PopoverPositioning,
|
|
10
|
-
PopoverMiddlewares,
|
|
11
|
-
PopoverTrigger as PopoverTriggerType
|
|
12
|
-
} from "./popover.types";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as PopoverDropdown } from "./popover-dropdown";
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { useTheme } from "../../../theme";
|
|
2
|
-
import { factory } from "../../../utils";
|
|
3
|
-
import { PopoverDropdownFactoryPayload } from "../popover.types";
|
|
4
|
-
import { usePopoverContext } from "../popover.context";
|
|
5
|
-
import { Transition } from "../../transition";
|
|
6
|
-
import {
|
|
7
|
-
FloatingArrow,
|
|
8
|
-
FloatingFocusManager,
|
|
9
|
-
FloatingPortal
|
|
10
|
-
} from "@floating-ui/react";
|
|
11
|
-
|
|
12
|
-
const PopoverDropdown = factory<PopoverDropdownFactoryPayload>(
|
|
13
|
-
({ children, className, style, ...props }, ref) => {
|
|
14
|
-
const { cx, getRadius } = useTheme();
|
|
15
|
-
const {
|
|
16
|
-
popover,
|
|
17
|
-
showArrow,
|
|
18
|
-
radius,
|
|
19
|
-
withinPortal,
|
|
20
|
-
transitionProps,
|
|
21
|
-
getStyles
|
|
22
|
-
} = usePopoverContext();
|
|
23
|
-
|
|
24
|
-
const dropdownContent = (
|
|
25
|
-
<Transition
|
|
26
|
-
transition="fade"
|
|
27
|
-
duration={200}
|
|
28
|
-
mounted={popover.opened}
|
|
29
|
-
style={{ position: "relative", zIndex: 1000 }}
|
|
30
|
-
{...transitionProps}
|
|
31
|
-
>
|
|
32
|
-
<div
|
|
33
|
-
ref={(node) => {
|
|
34
|
-
popover.refs.setFloating(node);
|
|
35
|
-
|
|
36
|
-
if (typeof ref === "function") {
|
|
37
|
-
ref(node);
|
|
38
|
-
} else if (ref) {
|
|
39
|
-
ref.current = node;
|
|
40
|
-
}
|
|
41
|
-
}}
|
|
42
|
-
role="dialog"
|
|
43
|
-
aria-modal="true"
|
|
44
|
-
style={{
|
|
45
|
-
...popover.floatingStyles,
|
|
46
|
-
zIndex: 1000,
|
|
47
|
-
...style
|
|
48
|
-
}}
|
|
49
|
-
className={cx(
|
|
50
|
-
"z-50 p-2 bg-[var(--refraktor-bg)] text-[var(--refraktor-text)] shadow-md text-sm border-0",
|
|
51
|
-
getRadius(radius),
|
|
52
|
-
getStyles("dropdown"),
|
|
53
|
-
className
|
|
54
|
-
)}
|
|
55
|
-
{...popover.getFloatingProps()}
|
|
56
|
-
{...props}
|
|
57
|
-
>
|
|
58
|
-
{children}
|
|
59
|
-
|
|
60
|
-
{showArrow && (
|
|
61
|
-
<FloatingArrow
|
|
62
|
-
ref={popover.arrowRef}
|
|
63
|
-
context={popover.context}
|
|
64
|
-
width={10}
|
|
65
|
-
height={5}
|
|
66
|
-
className={cx(
|
|
67
|
-
"fill-[var(--refraktor-bg)]",
|
|
68
|
-
getStyles("arrow")
|
|
69
|
-
)}
|
|
70
|
-
/>
|
|
71
|
-
)}
|
|
72
|
-
</div>
|
|
73
|
-
</Transition>
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
const wrappedContent = popover.opened ? (
|
|
77
|
-
<FloatingFocusManager context={popover.context} modal={false}>
|
|
78
|
-
{dropdownContent}
|
|
79
|
-
</FloatingFocusManager>
|
|
80
|
-
) : (
|
|
81
|
-
dropdownContent
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
if (withinPortal) {
|
|
85
|
-
return <FloatingPortal>{wrappedContent}</FloatingPortal>;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return wrappedContent;
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
PopoverDropdown.displayName = "@refraktor/core/Popover.Dropdown";
|
|
93
|
-
|
|
94
|
-
export default PopoverDropdown;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as PopoverTrigger } from "./popover-trigger";
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { cloneElement, isValidElement, ComponentProps } from "react";
|
|
2
|
-
import { useTheme } from "../../../theme";
|
|
3
|
-
import { factory } from "../../../utils";
|
|
4
|
-
import { PopoverTriggerFactoryPayload } from "../popover.types";
|
|
5
|
-
import { usePopoverContext } from "../popover.context";
|
|
6
|
-
|
|
7
|
-
const PopoverTrigger = factory<PopoverTriggerFactoryPayload>(
|
|
8
|
-
({ children, className, ...props }, ref) => {
|
|
9
|
-
const { cx } = useTheme();
|
|
10
|
-
const { popover, getStyles } = usePopoverContext();
|
|
11
|
-
|
|
12
|
-
const triggerElement = isValidElement(children)
|
|
13
|
-
? cloneElement(children as any, {
|
|
14
|
-
ref: (node: HTMLElement | null) => {
|
|
15
|
-
popover.refs.setReference(node);
|
|
16
|
-
|
|
17
|
-
const childRef = (children as any).ref;
|
|
18
|
-
if (typeof childRef === "function") {
|
|
19
|
-
childRef(node);
|
|
20
|
-
} else if (childRef) {
|
|
21
|
-
childRef.current = node;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (typeof ref === "function") {
|
|
25
|
-
ref(node as HTMLDivElement);
|
|
26
|
-
} else if (ref) {
|
|
27
|
-
ref.current = node as HTMLDivElement;
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
...popover.getReferenceProps({
|
|
31
|
-
...(children.props as ComponentProps<any>)
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
: children;
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<div
|
|
38
|
-
className={cx("inline-block", getStyles("trigger"), className)}
|
|
39
|
-
{...props}
|
|
40
|
-
>
|
|
41
|
-
{triggerElement}
|
|
42
|
-
</div>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
PopoverTrigger.displayName = "@refraktor/core/Popover.Trigger";
|
|
48
|
-
|
|
49
|
-
export default PopoverTrigger;
|