@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,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { render, screen } from "../../vitest";
|
|
3
|
-
import NumberInput from "./number-input";
|
|
4
|
-
|
|
5
|
-
describe("@refraktor/core/NumberInput", () => {
|
|
6
|
-
it("supports input wrapper props", async () => {
|
|
7
|
-
await render(
|
|
8
|
-
<NumberInput
|
|
9
|
-
label="Quantity"
|
|
10
|
-
description="Enter desired amount"
|
|
11
|
-
error="Quantity is required"
|
|
12
|
-
/>
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const input = screen.getByLabelText("Quantity");
|
|
16
|
-
|
|
17
|
-
expect(input).toHaveAttribute("type", "number");
|
|
18
|
-
expect(input).toHaveAttribute("aria-invalid", "true");
|
|
19
|
-
expect(screen.getByText("Enter desired amount")).toBeInTheDocument();
|
|
20
|
-
expect(screen.getByText("Quantity is required")).toBeInTheDocument();
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import { clamp, useId, useUncontrolled } from "@refraktor/utils";
|
|
2
|
-
import { useTheme } from "../../theme";
|
|
3
|
-
import {
|
|
4
|
-
createClassNamesConfig,
|
|
5
|
-
createComponentConfig,
|
|
6
|
-
factory,
|
|
7
|
-
useClassNames,
|
|
8
|
-
useProps
|
|
9
|
-
} from "../../utils";
|
|
10
|
-
import {
|
|
11
|
-
NumberInputClassNames,
|
|
12
|
-
NumberInputFactoryPayload,
|
|
13
|
-
NumberInputProps
|
|
14
|
-
} from "./number-input.types";
|
|
15
|
-
import { useCallback, useMemo, useRef } from "react";
|
|
16
|
-
import { ChevronIcon } from "../../icons";
|
|
17
|
-
import { InputWrapper } from "../input/input-wrapper";
|
|
18
|
-
import { InputField } from "../input/input-field";
|
|
19
|
-
import { getControlSize } from "./number-input.styles";
|
|
20
|
-
|
|
21
|
-
const isInterim = (value: string) =>
|
|
22
|
-
value === "" ||
|
|
23
|
-
value === "." ||
|
|
24
|
-
value === "-" ||
|
|
25
|
-
value === "-." ||
|
|
26
|
-
/^-?\d+\.?$/.test(value);
|
|
27
|
-
|
|
28
|
-
const toNumber = (value: string) => {
|
|
29
|
-
const num = parseFloat(value);
|
|
30
|
-
return Number.isNaN(num) ? undefined : num;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const formatValue = (num: number, precision?: number) => {
|
|
34
|
-
if (typeof precision === "number") {
|
|
35
|
-
const factor = Math.pow(10, precision);
|
|
36
|
-
const rounded = Math.round(num * factor) / factor;
|
|
37
|
-
return rounded.toFixed(precision);
|
|
38
|
-
}
|
|
39
|
-
return String(num);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
function decimalsCount(num: number): number {
|
|
43
|
-
const str = num.toString();
|
|
44
|
-
const decimalIndex = str.indexOf(".");
|
|
45
|
-
return decimalIndex === -1 ? 0 : str.length - decimalIndex - 1;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function addWithPrecision(
|
|
49
|
-
value: number,
|
|
50
|
-
step: number,
|
|
51
|
-
precision?: number
|
|
52
|
-
): number {
|
|
53
|
-
const decimals =
|
|
54
|
-
precision ?? Math.max(decimalsCount(value), decimalsCount(step));
|
|
55
|
-
const factor = Math.pow(10, decimals);
|
|
56
|
-
return Math.round(value * factor + step * factor) / factor;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const defaultProps = {
|
|
60
|
-
size: "md",
|
|
61
|
-
variant: "default",
|
|
62
|
-
radius: "default",
|
|
63
|
-
controlsPosition: "right",
|
|
64
|
-
step: 1,
|
|
65
|
-
defaultValue: 0
|
|
66
|
-
} satisfies Partial<NumberInputProps>;
|
|
67
|
-
|
|
68
|
-
const NumberInput = factory<NumberInputFactoryPayload>((_props, ref) => {
|
|
69
|
-
const { cx } = useTheme();
|
|
70
|
-
const {
|
|
71
|
-
id,
|
|
72
|
-
label,
|
|
73
|
-
description,
|
|
74
|
-
error,
|
|
75
|
-
required,
|
|
76
|
-
withAsterisk,
|
|
77
|
-
value,
|
|
78
|
-
defaultValue,
|
|
79
|
-
size,
|
|
80
|
-
onChange,
|
|
81
|
-
min,
|
|
82
|
-
max,
|
|
83
|
-
step,
|
|
84
|
-
precision,
|
|
85
|
-
controlsPosition,
|
|
86
|
-
disabled,
|
|
87
|
-
className,
|
|
88
|
-
classNames,
|
|
89
|
-
...props
|
|
90
|
-
} = useProps("NumberInput", defaultProps, _props);
|
|
91
|
-
const classes = useClassNames("NumberInput", classNames);
|
|
92
|
-
const _id = useId(id);
|
|
93
|
-
|
|
94
|
-
const [_value, setValue] = useUncontrolled({
|
|
95
|
-
value,
|
|
96
|
-
defaultValue,
|
|
97
|
-
finalValue: "",
|
|
98
|
-
onChange
|
|
99
|
-
});
|
|
100
|
-
const controlSizing = getControlSize(size);
|
|
101
|
-
|
|
102
|
-
const valueRef = useRef(_value);
|
|
103
|
-
valueRef.current = _value;
|
|
104
|
-
const holdTimer = useRef<any>(null);
|
|
105
|
-
const repeatTimer = useRef<any>(null);
|
|
106
|
-
|
|
107
|
-
const changeValue = useCallback(
|
|
108
|
-
(direction: "increment" | "decrement") => {
|
|
109
|
-
if (disabled) return;
|
|
110
|
-
|
|
111
|
-
const currentStr = String(valueRef.current ?? "");
|
|
112
|
-
const current = toNumber(currentStr);
|
|
113
|
-
const delta = direction === "increment" ? step : -step;
|
|
114
|
-
|
|
115
|
-
let next =
|
|
116
|
-
current === undefined
|
|
117
|
-
? addWithPrecision(0, delta, precision)
|
|
118
|
-
: addWithPrecision(current, delta, precision);
|
|
119
|
-
|
|
120
|
-
next = clamp(next, min, max);
|
|
121
|
-
|
|
122
|
-
const formatted = formatValue(next, precision);
|
|
123
|
-
setValue(formatted);
|
|
124
|
-
onChange?.(next);
|
|
125
|
-
},
|
|
126
|
-
[disabled, step, min, max, precision, onChange, setValue]
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
const startHold = (direction: "increment" | "decrement") => {
|
|
130
|
-
if (disabled) return;
|
|
131
|
-
|
|
132
|
-
changeValue(direction);
|
|
133
|
-
|
|
134
|
-
holdTimer.current = setInterval(() => {
|
|
135
|
-
repeatTimer.current = setTimeout(() => {
|
|
136
|
-
changeValue(direction);
|
|
137
|
-
}, 100);
|
|
138
|
-
}, 400);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const stopHold = () => {
|
|
142
|
-
if (holdTimer.current) clearInterval(holdTimer.current);
|
|
143
|
-
if (repeatTimer.current) clearTimeout(repeatTimer.current);
|
|
144
|
-
holdTimer.current = null;
|
|
145
|
-
repeatTimer.current = null;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const { canIncrement, canDecrement } = useMemo(() => {
|
|
149
|
-
if (disabled) return { canIncrement: false, canDecrement: false };
|
|
150
|
-
|
|
151
|
-
const current = toNumber(String(_value));
|
|
152
|
-
if (current === undefined)
|
|
153
|
-
return { canIncrement: true, canDecrement: true };
|
|
154
|
-
|
|
155
|
-
const canIncrement = max === undefined ? true : current < max;
|
|
156
|
-
const canDecrement = min === undefined ? true : current > min;
|
|
157
|
-
|
|
158
|
-
return { canIncrement, canDecrement };
|
|
159
|
-
}, [_value, min, max, disabled]);
|
|
160
|
-
|
|
161
|
-
const handleChange = useCallback(
|
|
162
|
-
(event: React.ChangeEvent<HTMLInputElement>) => {
|
|
163
|
-
if (disabled) return;
|
|
164
|
-
|
|
165
|
-
const value = event.target.value;
|
|
166
|
-
|
|
167
|
-
if (isInterim(value)) {
|
|
168
|
-
setValue(value);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const num = toNumber(value);
|
|
173
|
-
if (num === undefined) return;
|
|
174
|
-
|
|
175
|
-
setValue(value);
|
|
176
|
-
},
|
|
177
|
-
[disabled, setValue]
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
const handleBlur = useCallback(() => {
|
|
181
|
-
if (disabled) return;
|
|
182
|
-
|
|
183
|
-
const value = String(_value ?? "");
|
|
184
|
-
const num = toNumber(value);
|
|
185
|
-
|
|
186
|
-
if (num === undefined) {
|
|
187
|
-
if (min !== undefined) setValue(String(min));
|
|
188
|
-
else setValue("");
|
|
189
|
-
onChange?.("");
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const clamped = clamp(num, min, max);
|
|
194
|
-
const formatted = formatValue(clamped, precision);
|
|
195
|
-
setValue(formatted);
|
|
196
|
-
onChange?.(clamped);
|
|
197
|
-
}, [disabled, _value, min, max, precision, setValue, onChange]);
|
|
198
|
-
|
|
199
|
-
const handleKeyDown = useCallback(
|
|
200
|
-
(event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
201
|
-
if (disabled) return;
|
|
202
|
-
|
|
203
|
-
if (event.key === "ArrowUp") {
|
|
204
|
-
event.preventDefault();
|
|
205
|
-
changeValue("increment");
|
|
206
|
-
} else if (event.key === "ArrowDown") {
|
|
207
|
-
event.preventDefault();
|
|
208
|
-
changeValue("decrement");
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
[disabled, changeValue]
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
const handleWheel = useCallback(
|
|
215
|
-
(e: React.WheelEvent<HTMLInputElement>) => {
|
|
216
|
-
if (disabled) return;
|
|
217
|
-
if (document.activeElement !== e.currentTarget) return;
|
|
218
|
-
|
|
219
|
-
e.preventDefault();
|
|
220
|
-
if (e.deltaY < 0) changeValue("increment");
|
|
221
|
-
else if (e.deltaY > 0) changeValue("decrement");
|
|
222
|
-
},
|
|
223
|
-
[disabled, changeValue]
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
const controls = useMemo(() => {
|
|
227
|
-
if (controlsPosition === "none") return null;
|
|
228
|
-
|
|
229
|
-
return (
|
|
230
|
-
<div
|
|
231
|
-
className={cx(
|
|
232
|
-
"inline-flex h-full flex-col overflow-hidden border-[var(--refraktor-border)] text-[var(--refraktor-text)]",
|
|
233
|
-
controlsPosition === "left" ? "border-r" : "border-l",
|
|
234
|
-
classes.controls
|
|
235
|
-
)}
|
|
236
|
-
>
|
|
237
|
-
<button
|
|
238
|
-
type="button"
|
|
239
|
-
disabled={!canIncrement}
|
|
240
|
-
aria-disabled={!canIncrement}
|
|
241
|
-
data-disabled={!canIncrement}
|
|
242
|
-
className={cx(
|
|
243
|
-
"m-0 flex flex-1 items-center justify-center border-0 bg-transparent p-0 leading-none transition-colors",
|
|
244
|
-
controlSizing.width,
|
|
245
|
-
!canIncrement
|
|
246
|
-
? "opacity-50 cursor-not-allowed"
|
|
247
|
-
: "cursor-pointer hover:bg-[var(--refraktor-bg-hover)]",
|
|
248
|
-
classes.increment
|
|
249
|
-
)}
|
|
250
|
-
tabIndex={-1}
|
|
251
|
-
onMouseDown={(e) => {
|
|
252
|
-
if (!canIncrement) return;
|
|
253
|
-
e.preventDefault();
|
|
254
|
-
startHold("increment");
|
|
255
|
-
}}
|
|
256
|
-
onMouseUp={stopHold}
|
|
257
|
-
onMouseLeave={stopHold}
|
|
258
|
-
onTouchEnd={stopHold}
|
|
259
|
-
>
|
|
260
|
-
<ChevronIcon
|
|
261
|
-
direction="up"
|
|
262
|
-
size={controlSizing.iconSize}
|
|
263
|
-
className={cx("block", !canIncrement && "opacity-50")}
|
|
264
|
-
/>
|
|
265
|
-
</button>
|
|
266
|
-
|
|
267
|
-
<button
|
|
268
|
-
type="button"
|
|
269
|
-
disabled={!canDecrement}
|
|
270
|
-
aria-disabled={!canDecrement}
|
|
271
|
-
data-disabled={!canDecrement}
|
|
272
|
-
className={cx(
|
|
273
|
-
"m-0 flex flex-1 items-center justify-center border-0 bg-transparent p-0 leading-none transition-colors",
|
|
274
|
-
controlSizing.width,
|
|
275
|
-
!canDecrement
|
|
276
|
-
? "opacity-50 cursor-not-allowed"
|
|
277
|
-
: "cursor-pointer hover:bg-[var(--refraktor-bg-hover)]",
|
|
278
|
-
classes.decrement
|
|
279
|
-
)}
|
|
280
|
-
tabIndex={-1}
|
|
281
|
-
onMouseDown={(e) => {
|
|
282
|
-
if (!canDecrement) return;
|
|
283
|
-
e.preventDefault();
|
|
284
|
-
startHold("decrement");
|
|
285
|
-
}}
|
|
286
|
-
onMouseUp={stopHold}
|
|
287
|
-
onMouseLeave={stopHold}
|
|
288
|
-
onTouchEnd={stopHold}
|
|
289
|
-
>
|
|
290
|
-
<ChevronIcon
|
|
291
|
-
direction="down"
|
|
292
|
-
size={controlSizing.iconSize}
|
|
293
|
-
className={cx("block", !canDecrement && "opacity-50")}
|
|
294
|
-
/>
|
|
295
|
-
</button>
|
|
296
|
-
</div>
|
|
297
|
-
);
|
|
298
|
-
}, [controlsPosition, canIncrement, canDecrement, classes, controlSizing]);
|
|
299
|
-
|
|
300
|
-
const hasWrapper = label || description || error;
|
|
301
|
-
|
|
302
|
-
const field = (
|
|
303
|
-
<InputField
|
|
304
|
-
ref={ref}
|
|
305
|
-
id={_id}
|
|
306
|
-
type="number"
|
|
307
|
-
required={required}
|
|
308
|
-
error={!!error}
|
|
309
|
-
disabled={disabled}
|
|
310
|
-
size={size}
|
|
311
|
-
min={min}
|
|
312
|
-
max={max}
|
|
313
|
-
step={step}
|
|
314
|
-
value={_value}
|
|
315
|
-
onChange={handleChange}
|
|
316
|
-
onBlur={handleBlur}
|
|
317
|
-
onKeyDown={handleKeyDown}
|
|
318
|
-
onWheel={handleWheel}
|
|
319
|
-
leftSection={controlsPosition === "left" ? controls : undefined}
|
|
320
|
-
rightSection={controlsPosition === "right" ? controls : undefined}
|
|
321
|
-
className={className}
|
|
322
|
-
classNames={{
|
|
323
|
-
root: cx(
|
|
324
|
-
"px-0 gap-0 items-stretch overflow-hidden",
|
|
325
|
-
controlsPosition === "none"
|
|
326
|
-
? "px-2"
|
|
327
|
-
: controlsPosition === "left"
|
|
328
|
-
? "pr-2"
|
|
329
|
-
: "pl-2",
|
|
330
|
-
classes.root
|
|
331
|
-
),
|
|
332
|
-
leftSection: cx(
|
|
333
|
-
"h-full self-stretch",
|
|
334
|
-
controlsPosition === "left" && controlSizing.leftSpacing,
|
|
335
|
-
classes.leftSection
|
|
336
|
-
),
|
|
337
|
-
rightSection: cx(
|
|
338
|
-
"h-full self-stretch",
|
|
339
|
-
controlsPosition === "right" && controlSizing.rightSpacing,
|
|
340
|
-
classes.rightSection
|
|
341
|
-
),
|
|
342
|
-
...(classes as any)
|
|
343
|
-
}}
|
|
344
|
-
aria-describedby={
|
|
345
|
-
error
|
|
346
|
-
? `${_id}-error`
|
|
347
|
-
: description
|
|
348
|
-
? `${_id}-description`
|
|
349
|
-
: undefined
|
|
350
|
-
}
|
|
351
|
-
aria-disabled={disabled}
|
|
352
|
-
aria-valuemin={min}
|
|
353
|
-
aria-valuemax={max}
|
|
354
|
-
aria-valuenow={Number(_value)}
|
|
355
|
-
{...props}
|
|
356
|
-
/>
|
|
357
|
-
);
|
|
358
|
-
|
|
359
|
-
if (!hasWrapper) {
|
|
360
|
-
return field;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return (
|
|
364
|
-
<InputWrapper
|
|
365
|
-
label={label}
|
|
366
|
-
description={description}
|
|
367
|
-
error={error}
|
|
368
|
-
required={required}
|
|
369
|
-
withAsterisk={withAsterisk}
|
|
370
|
-
inputId={_id}
|
|
371
|
-
>
|
|
372
|
-
{field}
|
|
373
|
-
</InputWrapper>
|
|
374
|
-
);
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
NumberInput.displayName = "@refraktor/core/NumberInput";
|
|
378
|
-
NumberInput.configure = createComponentConfig<NumberInputProps>();
|
|
379
|
-
NumberInput.classNames = createClassNamesConfig<NumberInputClassNames>();
|
|
380
|
-
|
|
381
|
-
export default NumberInput;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createClassNamesConfig,
|
|
3
|
-
createComponentConfig,
|
|
4
|
-
FactoryPayload
|
|
5
|
-
} from "../../utils";
|
|
6
|
-
import { InputFieldClassNames, InputProps } from "../input";
|
|
7
|
-
|
|
8
|
-
export type NumberInputControlsPosition = "left" | "right" | "none";
|
|
9
|
-
|
|
10
|
-
export interface NumberInputClassNames extends InputFieldClassNames {
|
|
11
|
-
controls?: string;
|
|
12
|
-
increment?: string;
|
|
13
|
-
decrement?: string;
|
|
14
|
-
[key: string]: string | undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface _NumberInputProps {
|
|
18
|
-
/** Value (controlled) */
|
|
19
|
-
value?: string | number;
|
|
20
|
-
|
|
21
|
-
/** Default value (uncontrolled) */
|
|
22
|
-
defaultValue?: string | number;
|
|
23
|
-
|
|
24
|
-
/** Callback called when the value changes */
|
|
25
|
-
onChange?: (value: string | number) => void;
|
|
26
|
-
|
|
27
|
-
/** Minimum value */
|
|
28
|
-
min?: number;
|
|
29
|
-
|
|
30
|
-
/** Maximum value */
|
|
31
|
-
max?: number;
|
|
32
|
-
|
|
33
|
-
/** Step value */
|
|
34
|
-
step?: number;
|
|
35
|
-
|
|
36
|
-
/** Number of decimal places for the value */
|
|
37
|
-
precision?: number;
|
|
38
|
-
|
|
39
|
-
/** Position of the controls @default `right` */
|
|
40
|
-
controlsPosition?: NumberInputControlsPosition;
|
|
41
|
-
|
|
42
|
-
/** Used for styling different parts of the component */
|
|
43
|
-
classNames?: NumberInputClassNames;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type NumberInputProps = _NumberInputProps &
|
|
47
|
-
Omit<InputProps, "onChange" | "type" | keyof _NumberInputProps>;
|
|
48
|
-
|
|
49
|
-
export interface NumberInputFactoryPayload extends FactoryPayload {
|
|
50
|
-
props: NumberInputProps;
|
|
51
|
-
ref: HTMLInputElement;
|
|
52
|
-
compound: {
|
|
53
|
-
configure: ReturnType<typeof createComponentConfig<NumberInputProps>>;
|
|
54
|
-
classNames: ReturnType<
|
|
55
|
-
typeof createClassNamesConfig<NumberInputClassNames>
|
|
56
|
-
>;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { RefraktorSize } from "../../theme";
|
|
2
|
-
import { PaginationVariant } from "./pagination.types";
|
|
3
|
-
|
|
4
|
-
type PaginationSizeStyles = {
|
|
5
|
-
list: string;
|
|
6
|
-
item: string;
|
|
7
|
-
dots: string;
|
|
8
|
-
iconSize: number;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type PaginationVariantStyles = {
|
|
12
|
-
base: string;
|
|
13
|
-
active: string;
|
|
14
|
-
inactive: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const sizes: Record<RefraktorSize, PaginationSizeStyles> = {
|
|
18
|
-
xs: {
|
|
19
|
-
list: "gap-1",
|
|
20
|
-
item: "h-6 min-w-6 px-1.5 text-xs",
|
|
21
|
-
dots: "h-6 min-w-6 px-1 text-xs",
|
|
22
|
-
iconSize: 12
|
|
23
|
-
},
|
|
24
|
-
sm: {
|
|
25
|
-
list: "gap-1",
|
|
26
|
-
item: "h-7 min-w-7 px-2 text-xs",
|
|
27
|
-
dots: "h-7 min-w-7 px-1.5 text-xs",
|
|
28
|
-
iconSize: 14
|
|
29
|
-
},
|
|
30
|
-
md: {
|
|
31
|
-
list: "gap-1.5",
|
|
32
|
-
item: "h-8 min-w-8 px-2.5 text-sm",
|
|
33
|
-
dots: "h-8 min-w-8 px-2 text-sm",
|
|
34
|
-
iconSize: 16
|
|
35
|
-
},
|
|
36
|
-
lg: {
|
|
37
|
-
list: "gap-1.5",
|
|
38
|
-
item: "h-9 min-w-9 px-3 text-base",
|
|
39
|
-
dots: "h-9 min-w-9 px-2.5 text-base",
|
|
40
|
-
iconSize: 18
|
|
41
|
-
},
|
|
42
|
-
xl: {
|
|
43
|
-
list: "gap-2",
|
|
44
|
-
item: "h-10 min-w-10 px-3.5 text-lg",
|
|
45
|
-
dots: "h-10 min-w-10 px-3 text-lg",
|
|
46
|
-
iconSize: 20
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const variants: Record<PaginationVariant, PaginationVariantStyles> = {
|
|
51
|
-
default: {
|
|
52
|
-
base: "border border-transparent",
|
|
53
|
-
active:
|
|
54
|
-
"bg-[var(--refraktor-primary)] text-[var(--refraktor-primary-text)]",
|
|
55
|
-
inactive:
|
|
56
|
-
"bg-[var(--refraktor-bg)] text-[var(--refraktor-text)] hover:bg-[var(--refraktor-bg-hover)]"
|
|
57
|
-
},
|
|
58
|
-
filled: {
|
|
59
|
-
base: "border border-transparent",
|
|
60
|
-
active:
|
|
61
|
-
"bg-[var(--refraktor-primary)] text-[var(--refraktor-primary-text)]",
|
|
62
|
-
inactive:
|
|
63
|
-
"bg-[var(--refraktor-bg-subtle)] text-[var(--refraktor-text-secondary)] hover:bg-[var(--refraktor-bg-hover)] hover:text-[var(--refraktor-text)]"
|
|
64
|
-
},
|
|
65
|
-
outline: {
|
|
66
|
-
base: "border border-[var(--refraktor-border)]",
|
|
67
|
-
active:
|
|
68
|
-
"border-[var(--refraktor-primary)] bg-[var(--refraktor-primary)] text-[var(--refraktor-primary-text)]",
|
|
69
|
-
inactive:
|
|
70
|
-
"text-[var(--refraktor-text)] hover:border-[var(--refraktor-border-hover)] hover:bg-[var(--refraktor-bg-hover)]"
|
|
71
|
-
},
|
|
72
|
-
ghost: {
|
|
73
|
-
base: "border border-transparent bg-transparent",
|
|
74
|
-
active:
|
|
75
|
-
"bg-[var(--refraktor-bg-hover)] text-[var(--refraktor-primary)]",
|
|
76
|
-
inactive:
|
|
77
|
-
"text-[var(--refraktor-text-secondary)] hover:bg-[var(--refraktor-bg-hover)] hover:text-[var(--refraktor-text)]"
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const getSize = (size: RefraktorSize = "md") => sizes[size];
|
|
82
|
-
|
|
83
|
-
export const getVariant = (variant: PaginationVariant = "default") =>
|
|
84
|
-
variants[variant];
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
import { render as rtlRender } from "@testing-library/react";
|
|
3
|
-
import { describe, expect, it, vi } from "vitest";
|
|
4
|
-
import { render, screen, userEvent } from "../../vitest";
|
|
5
|
-
import { ThemeProvider } from "../../theme";
|
|
6
|
-
import Pagination from "./pagination";
|
|
7
|
-
|
|
8
|
-
describe("@refraktor/core/Pagination", () => {
|
|
9
|
-
it("renders active page and controls", async () => {
|
|
10
|
-
await render(<Pagination total={7} defaultValue={3} />);
|
|
11
|
-
|
|
12
|
-
expect(
|
|
13
|
-
screen.getByRole("button", { name: "Page 3, current page" })
|
|
14
|
-
).toHaveAttribute("aria-current", "page");
|
|
15
|
-
expect(
|
|
16
|
-
screen.getByRole("button", { name: "Go to previous page" })
|
|
17
|
-
).toBeInTheDocument();
|
|
18
|
-
expect(
|
|
19
|
-
screen.getByRole("button", { name: "Go to next page" })
|
|
20
|
-
).toBeInTheDocument();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("calls onChange when next button is clicked", async () => {
|
|
24
|
-
const user = userEvent.setup();
|
|
25
|
-
const onChange = vi.fn();
|
|
26
|
-
|
|
27
|
-
await render(<Pagination total={7} value={2} onChange={onChange} />);
|
|
28
|
-
|
|
29
|
-
await user.click(
|
|
30
|
-
screen.getByRole("button", { name: "Go to next page" })
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
expect(onChange).toHaveBeenCalledWith(3);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("supports controlled mode", async () => {
|
|
37
|
-
const user = userEvent.setup();
|
|
38
|
-
|
|
39
|
-
function Demo() {
|
|
40
|
-
const [page, setPage] = useState(1);
|
|
41
|
-
|
|
42
|
-
return <Pagination total={8} value={page} onChange={setPage} />;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
await render(<Demo />);
|
|
46
|
-
|
|
47
|
-
await user.click(screen.getByRole("button", { name: "Go to page 4" }));
|
|
48
|
-
|
|
49
|
-
expect(
|
|
50
|
-
screen.getByRole("button", { name: "Page 4, current page" })
|
|
51
|
-
).toHaveAttribute("aria-current", "page");
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("renders dots when the range is large", async () => {
|
|
55
|
-
await render(<Pagination total={20} defaultValue={10} />);
|
|
56
|
-
|
|
57
|
-
expect(screen.getAllByText("...")).toHaveLength(2);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("supports edge controls and disabled boundary states", async () => {
|
|
61
|
-
await render(<Pagination total={10} defaultValue={1} withEdges />);
|
|
62
|
-
|
|
63
|
-
expect(
|
|
64
|
-
screen.getByRole("button", { name: "Go to first page" })
|
|
65
|
-
).toBeDisabled();
|
|
66
|
-
expect(
|
|
67
|
-
screen.getByRole("button", { name: "Go to previous page" })
|
|
68
|
-
).toBeDisabled();
|
|
69
|
-
expect(
|
|
70
|
-
screen.getByRole("button", { name: "Go to next page" })
|
|
71
|
-
).not.toBeDisabled();
|
|
72
|
-
expect(
|
|
73
|
-
screen.getByRole("button", { name: "Go to last page" })
|
|
74
|
-
).not.toBeDisabled();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("hides when total is one and hideWithOnePage is true", () => {
|
|
78
|
-
const { container } = rtlRender(
|
|
79
|
-
<ThemeProvider>
|
|
80
|
-
<Pagination total={1} hideWithOnePage />
|
|
81
|
-
</ThemeProvider>
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
expect(container.firstChild).toBeNull();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("supports root and slot class names", async () => {
|
|
88
|
-
const { container } = await render(
|
|
89
|
-
<Pagination
|
|
90
|
-
total={20}
|
|
91
|
-
defaultValue={10}
|
|
92
|
-
className="custom-root"
|
|
93
|
-
classNames={{
|
|
94
|
-
list: "custom-list",
|
|
95
|
-
item: "custom-item",
|
|
96
|
-
page: "custom-page",
|
|
97
|
-
control: "custom-control",
|
|
98
|
-
dots: "custom-dots"
|
|
99
|
-
}}
|
|
100
|
-
/>
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
const root = container.firstElementChild as HTMLElement;
|
|
104
|
-
const list = root.querySelector("ul");
|
|
105
|
-
|
|
106
|
-
expect(root).toHaveClass("custom-root");
|
|
107
|
-
expect(list).toHaveClass("custom-list");
|
|
108
|
-
expect(root.querySelector("li")).toHaveClass("custom-item");
|
|
109
|
-
expect(root.querySelector('[data-active="true"]')).toHaveClass(
|
|
110
|
-
"custom-page"
|
|
111
|
-
);
|
|
112
|
-
expect(
|
|
113
|
-
screen.getByRole("button", { name: "Go to previous page" })
|
|
114
|
-
).toHaveClass("custom-control");
|
|
115
|
-
expect(screen.getAllByText("...")[0]).toHaveClass("custom-dots");
|
|
116
|
-
});
|
|
117
|
-
});
|