@musecat/uikit 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +51 -0
- package/index.ts +78 -0
- package/package.json +103 -0
- package/packages/Components/Box/Box.tsx +173 -0
- package/packages/Components/Box/Box.types.ts +48 -0
- package/packages/Components/Button/Button.tsx +275 -0
- package/packages/Components/Button/Button.types.ts +44 -0
- package/packages/Components/Card/Card.default.tsx +180 -0
- package/packages/Components/Card/Card.foldable.tsx +383 -0
- package/packages/Components/Card/Card.module.scss +23 -0
- package/packages/Components/Card/Card.tsx +8 -0
- package/packages/Components/Card/Card.types.ts +91 -0
- package/packages/Components/Card/Card.utils.ts +66 -0
- package/packages/Components/Checkbox/Checkbox.module.scss +11 -0
- package/packages/Components/Checkbox/Checkbox.tsx +104 -0
- package/packages/Components/Checkbox/Checkbox.types.ts +24 -0
- package/packages/Components/CodeBox/CodeBox.copy.tsx +43 -0
- package/packages/Components/CodeBox/CodeBox.module.scss +72 -0
- package/packages/Components/CodeBox/CodeBox.tsx +91 -0
- package/packages/Components/CodeBox/CodeBox.types.ts +17 -0
- package/packages/Components/ContextMenu/ContextMenu.module.scss +8 -0
- package/packages/Components/ContextMenu/ContextMenu.options.tsx +126 -0
- package/packages/Components/ContextMenu/ContextMenu.tsx +381 -0
- package/packages/Components/ContextMenu/ContextMenu.types.ts +46 -0
- package/packages/Components/ContributionGraph/ContributionGraph.module.scss +42 -0
- package/packages/Components/ContributionGraph/ContributionGraph.tsx +454 -0
- package/packages/Components/ContributionGraph/ContributionGraph.types.ts +27 -0
- package/packages/Components/DatePicker/DatePicker.calendar.tsx +161 -0
- package/packages/Components/DatePicker/DatePicker.core.tsx +582 -0
- package/packages/Components/DatePicker/DatePicker.module.scss +26 -0
- package/packages/Components/DatePicker/DatePicker.tsx +786 -0
- package/packages/Components/DatePicker/DatePicker.types.ts +36 -0
- package/packages/Components/DatePicker/DatePicker.utils.ts +80 -0
- package/packages/Components/DatePicker/hooks/useCalendar.ts +61 -0
- package/packages/Components/DatePicker/hooks/useSelection.ts +208 -0
- package/packages/Components/Divider/Divider.tsx +46 -0
- package/packages/Components/Divider/Divider.types.ts +12 -0
- package/packages/Components/Header/Header.module.scss +74 -0
- package/packages/Components/Header/Header.tsx +47 -0
- package/packages/Components/Header/Header.types.ts +8 -0
- package/packages/Components/Icon/Icon.group.tsx +122 -0
- package/packages/Components/Icon/Icon.group.types.ts +20 -0
- package/packages/Components/Icon/Icon.tsx +341 -0
- package/packages/Components/Icon/Icon.types.ts +59 -0
- package/packages/Components/Icon/SVG/data.tsx +232 -0
- package/packages/Components/Input/Input.module.scss +5 -0
- package/packages/Components/Input/Input.tsx +87 -0
- package/packages/Components/Input/Input.types.ts +14 -0
- package/packages/Components/Label/Label.module.scss +19 -0
- package/packages/Components/Label/Label.tsx +115 -0
- package/packages/Components/Label/Label.types.ts +28 -0
- package/packages/Components/Layout/Layout.docs.module.scss +42 -0
- package/packages/Components/Layout/Layout.docs.tsx +150 -0
- package/packages/Components/Layout/Layout.docs.types.ts +18 -0
- package/packages/Components/Layout/Layout.module.scss +91 -0
- package/packages/Components/Layout/Layout.tsx +306 -0
- package/packages/Components/Layout/Layout.types.ts +71 -0
- package/packages/Components/Maps/OSM/MapOSM.module.scss +11 -0
- package/packages/Components/Maps/OSM/MapOSM.shared.ts +121 -0
- package/packages/Components/Maps/OSM/MapOSM.tsx +279 -0
- package/packages/Components/Maps/OSM/MapOSM.types.ts +18 -0
- package/packages/Components/Nav/Nav.module.scss +137 -0
- package/packages/Components/Nav/Nav.tsx +304 -0
- package/packages/Components/Nav/Nav.types.ts +32 -0
- package/packages/Components/Nav/hooks/useNavDrag.ts +374 -0
- package/packages/Components/Nav/hooks/useNavIndicator.ts +137 -0
- package/packages/Components/Pagination/Pagination.tsx +254 -0
- package/packages/Components/Pagination/Pagination.types.ts +18 -0
- package/packages/Components/Pill/Pill.tsx +127 -0
- package/packages/Components/Pill/Pill.types.ts +33 -0
- package/packages/Components/Profile/Profile.shared.ts +74 -0
- package/packages/Components/Profile/Profile.tsx +382 -0
- package/packages/Components/Profile/Profile.types.ts +55 -0
- package/packages/Components/Progress/Progress.module.scss +15 -0
- package/packages/Components/Progress/Progress.tsx +88 -0
- package/packages/Components/Progress/Progress.types.ts +22 -0
- package/packages/Components/Radio/Radio.module.scss +11 -0
- package/packages/Components/Radio/Radio.tsx +121 -0
- package/packages/Components/Radio/Radio.types.ts +20 -0
- package/packages/Components/Select/Select.keyboard.tsx +76 -0
- package/packages/Components/Select/Select.trigger.tsx +88 -0
- package/packages/Components/Select/Select.tsx +11 -0
- package/packages/Components/Select/Select.types.ts +38 -0
- package/packages/Components/Select/Select.utils.ts +84 -0
- package/packages/Components/Select/hooks/useSelectNavigation.ts +461 -0
- package/packages/Components/Select/hooks/useSelectSelection.ts +142 -0
- package/packages/Components/Select/hooks/useSelectState.ts +314 -0
- package/packages/Components/Select/select.control.tsx +228 -0
- package/packages/Components/Select/select.inner.tsx +312 -0
- package/packages/Components/Skeleton/Skeleton.tsx +30 -0
- package/packages/Components/Skeleton/Skeleton.types.ts +12 -0
- package/packages/Components/Spinner/Spinner.module.scss +78 -0
- package/packages/Components/Spinner/Spinner.tsx +125 -0
- package/packages/Components/Spinner/Spinner.types.ts +19 -0
- package/packages/Components/Text/Text.module.scss +7 -0
- package/packages/Components/Text/Text.tsx +49 -0
- package/packages/Components/Text/Text.types.ts +33 -0
- package/packages/Components/TimePicker/TimePicker.core.tsx +448 -0
- package/packages/Components/TimePicker/TimePicker.module.scss +30 -0
- package/packages/Components/TimePicker/TimePicker.tsx +511 -0
- package/packages/Components/TimePicker/TimePicker.types.ts +22 -0
- package/packages/Components/Timeline/Timeline.tsx +111 -0
- package/packages/Components/Timeline/Timeline.types.ts +23 -0
- package/packages/Components/Title/Title.tsx +305 -0
- package/packages/Components/Title/Title.types.ts +64 -0
- package/packages/Components/Toggle/Toggle.module.scss +32 -0
- package/packages/Components/Toggle/Toggle.tsx +272 -0
- package/packages/Components/Toggle/Toggle.types.ts +17 -0
- package/packages/Components/Tooltip/Tooltip.module.scss +44 -0
- package/packages/Components/Tooltip/Tooltip.tsx +340 -0
- package/packages/Components/Tooltip/Tooltip.types.ts +38 -0
- package/packages/Frameworks/Dialog/Dialog.background.tsx +88 -0
- package/packages/Frameworks/Dialog/Dialog.boot.tsx +32 -0
- package/packages/Frameworks/Dialog/Dialog.store.ts +199 -0
- package/packages/Frameworks/Dialog/Dialog.tsx +185 -0
- package/packages/Frameworks/Dialog/Dialog.types.ts +264 -0
- package/packages/Frameworks/Dialog/Dialog.utils.ts +22 -0
- package/packages/Frameworks/Dialog/contents/Dialog.footer.tsx +79 -0
- package/packages/Frameworks/Dialog/contents/Dialog.funnel.tsx +260 -0
- package/packages/Frameworks/Dialog/contents/Dialog.header.tsx +137 -0
- package/packages/Frameworks/Dialog/hooks/useDialogPosition.ts +298 -0
- package/packages/Frameworks/Dialog/hooks/useSheetDrag.ts +325 -0
- package/packages/Frameworks/Dialog/hooks/useSheetGeometry.ts +201 -0
- package/packages/Frameworks/Dialog/hooks/useSheetProgressive.ts +98 -0
- package/packages/Frameworks/Dialog/renderers/renderModal.tsx +228 -0
- package/packages/Frameworks/Dialog/renderers/renderPopover.tsx +220 -0
- package/packages/Frameworks/Dialog/renderers/renderSheet.tsx +571 -0
- package/packages/Frameworks/EdgeEffect/EdgeEffect.tsx +52 -0
- package/packages/Frameworks/EdgeEffect/EdgeEffect.types.ts +5 -0
- package/packages/Frameworks/Motion/Motion.presets.ts +49 -0
- package/packages/Frameworks/Pressable/Pressable.module.scss +19 -0
- package/packages/Frameworks/Pressable/Pressable.tsx +651 -0
- package/packages/Frameworks/Pressable/Pressable.types.ts +73 -0
- package/packages/Frameworks/Squircle/Squircle.tsx +263 -0
- package/packages/Frameworks/Squircle/Squircle.types.ts +15 -0
- package/packages/Frameworks/Theme/Radius.types.ts +55 -0
- package/packages/Frameworks/Theme/Theme.types.ts +325 -0
- package/packages/Frameworks/Toaster/Toaster.boot.tsx +47 -0
- package/packages/Frameworks/Toaster/Toaster.module.scss +168 -0
- package/packages/Frameworks/Toaster/Toaster.types.ts +13 -0
- package/packages/Frameworks/View/DNDView/DNDView.module.scss +8 -0
- package/packages/Frameworks/View/DNDView/DNDView.tsx +470 -0
- package/packages/Frameworks/View/DNDView/DNDView.types.ts +61 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.module.scss +59 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.tsx +386 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.types.ts +46 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.counter.tsx +27 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.footer.tsx +76 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.header.tsx +49 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.list.tsx +74 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.slide.tsx +71 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.tsx +175 -0
- package/packages/Frameworks/View/ImageView/Image.controls.tsx +39 -0
- package/packages/Frameworks/View/ImageView/Image.hooks.ts +82 -0
- package/packages/Frameworks/View/ImageView/Image.module.scss +7 -0
- package/packages/Frameworks/View/ImageView/Image.tsx +375 -0
- package/packages/Frameworks/View/ImageView/Image.types.ts +71 -0
- package/packages/Frameworks/View/ImageView/Image.utils.ts +79 -0
- package/packages/Frameworks/View/View.module.scss +34 -0
- package/packages/Frameworks/View/View.tsx +200 -0
- package/packages/Frameworks/View/View.types.ts +36 -0
- package/packages/Frameworks/_shared/Padding.types.ts +52 -0
- package/packages/Frameworks/_shared/StopParentInteraction.tsx +45 -0
- package/packages/Frameworks/_shared/Wind.types.ts +17 -0
- package/packages/Frameworks/_shared/bodyScrollLock.ts +127 -0
- package/packages/Frameworks/_shared/layer.constants.ts +8 -0
- package/packages/Frameworks/_shared/normalize.ts +39 -0
- package/packages/Frameworks/_shared/sizing.ts +55 -0
- package/packages/Frameworks/_shared/useControllableState.ts +29 -0
- package/packages/Styles/_animation.scss +42 -0
- package/packages/Styles/_color.scss +131 -0
- package/packages/Styles/_font.scss +30 -0
- package/packages/Styles/_icon.scss +782 -0
- package/packages/Styles/_importer.scss +9 -0
- package/packages/Styles/_system.scss +69 -0
- package/packages/Styles/_textstyle.scss +111 -0
- package/packages/Styles/_theme.scss +452 -0
- package/packages/Styles/_viewport-global.scss +99 -0
- package/packages/Styles/_viewport.scss +108 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
|
|
4
|
+
|
|
5
|
+
export function useNavIndicator(
|
|
6
|
+
committedSelectedIndex: number,
|
|
7
|
+
isDraggingSelection: boolean,
|
|
8
|
+
isReleasingSelection: boolean,
|
|
9
|
+
itemRefs: React.MutableRefObject<(HTMLElement | null)[]>,
|
|
10
|
+
indicatorRef: React.RefObject<HTMLDivElement | null>,
|
|
11
|
+
navRef: React.RefObject<HTMLDivElement | null>,
|
|
12
|
+
) {
|
|
13
|
+
const committedIndicatorStyleRef = useRef<React.CSSProperties | undefined>(
|
|
14
|
+
undefined,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const applyIndicatorStyle = useCallback(
|
|
18
|
+
(nextStyle?: React.CSSProperties) => {
|
|
19
|
+
const indicator = indicatorRef.current;
|
|
20
|
+
if (!indicator) return;
|
|
21
|
+
|
|
22
|
+
const left =
|
|
23
|
+
typeof nextStyle?.left === "number"
|
|
24
|
+
? nextStyle.left
|
|
25
|
+
: Number(nextStyle?.left ?? 0);
|
|
26
|
+
const width =
|
|
27
|
+
typeof nextStyle?.width === "number"
|
|
28
|
+
? nextStyle.width
|
|
29
|
+
: Number(nextStyle?.width ?? 0);
|
|
30
|
+
const opacity =
|
|
31
|
+
typeof nextStyle?.opacity === "number"
|
|
32
|
+
? nextStyle.opacity
|
|
33
|
+
: Number(nextStyle?.opacity ?? 0);
|
|
34
|
+
|
|
35
|
+
indicator.style.transform = `translate3d(${left}px, 0, 0) scale(var(--nav-indicator-scale, 1))`;
|
|
36
|
+
indicator.style.width = `${width}px`;
|
|
37
|
+
indicator.style.opacity = `${opacity}`;
|
|
38
|
+
},
|
|
39
|
+
[indicatorRef],
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
useLayoutEffect(() => {
|
|
43
|
+
const el =
|
|
44
|
+
committedSelectedIndex >= 0
|
|
45
|
+
? itemRefs.current[committedSelectedIndex]
|
|
46
|
+
: null;
|
|
47
|
+
|
|
48
|
+
if (el) {
|
|
49
|
+
const nextStyle = {
|
|
50
|
+
left: el.offsetLeft,
|
|
51
|
+
width: el.offsetWidth,
|
|
52
|
+
opacity: 1,
|
|
53
|
+
};
|
|
54
|
+
committedIndicatorStyleRef.current = nextStyle;
|
|
55
|
+
|
|
56
|
+
if (!isDraggingSelection && !isReleasingSelection) {
|
|
57
|
+
requestAnimationFrame(() => {
|
|
58
|
+
if (!isDraggingSelection && !isReleasingSelection) {
|
|
59
|
+
applyIndicatorStyle(nextStyle);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
const nextStyle = { left: 0, width: 0, opacity: 0 };
|
|
65
|
+
committedIndicatorStyleRef.current = nextStyle;
|
|
66
|
+
|
|
67
|
+
if (!isDraggingSelection && !isReleasingSelection) {
|
|
68
|
+
requestAnimationFrame(() => {
|
|
69
|
+
if (!isDraggingSelection && !isReleasingSelection) {
|
|
70
|
+
applyIndicatorStyle(nextStyle);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}, [
|
|
76
|
+
applyIndicatorStyle,
|
|
77
|
+
committedSelectedIndex,
|
|
78
|
+
isDraggingSelection,
|
|
79
|
+
isReleasingSelection,
|
|
80
|
+
itemRefs,
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const syncCommittedIndicator = () => {
|
|
85
|
+
const el =
|
|
86
|
+
committedSelectedIndex >= 0
|
|
87
|
+
? itemRefs.current[committedSelectedIndex]
|
|
88
|
+
: null;
|
|
89
|
+
|
|
90
|
+
if (el) {
|
|
91
|
+
const nextStyle = {
|
|
92
|
+
left: el.offsetLeft,
|
|
93
|
+
width: el.offsetWidth,
|
|
94
|
+
opacity: 1,
|
|
95
|
+
};
|
|
96
|
+
committedIndicatorStyleRef.current = nextStyle;
|
|
97
|
+
|
|
98
|
+
if (!isDraggingSelection && !isReleasingSelection) {
|
|
99
|
+
requestAnimationFrame(() => {
|
|
100
|
+
if (!isDraggingSelection && !isReleasingSelection) {
|
|
101
|
+
applyIndicatorStyle(nextStyle);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
syncCommittedIndicator();
|
|
109
|
+
window.addEventListener("resize", syncCommittedIndicator);
|
|
110
|
+
|
|
111
|
+
const resizeObserver =
|
|
112
|
+
typeof ResizeObserver !== "undefined"
|
|
113
|
+
? new ResizeObserver(() => syncCommittedIndicator())
|
|
114
|
+
: null;
|
|
115
|
+
|
|
116
|
+
if (resizeObserver) {
|
|
117
|
+
if (navRef.current) resizeObserver.observe(navRef.current);
|
|
118
|
+
itemRefs.current.forEach((item) => {
|
|
119
|
+
if (item) resizeObserver.observe(item);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return () => {
|
|
124
|
+
window.removeEventListener("resize", syncCommittedIndicator);
|
|
125
|
+
resizeObserver?.disconnect();
|
|
126
|
+
};
|
|
127
|
+
}, [
|
|
128
|
+
applyIndicatorStyle,
|
|
129
|
+
committedSelectedIndex,
|
|
130
|
+
isDraggingSelection,
|
|
131
|
+
isReleasingSelection,
|
|
132
|
+
itemRefs,
|
|
133
|
+
navRef,
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
return { applyIndicatorStyle, committedIndicatorStyleRef };
|
|
137
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useTimeout } from "@musecat/functionkit";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { Word } from "@/i18n/shared";
|
|
6
|
+
import Icon from "@/packages/Components/Icon/Icon";
|
|
7
|
+
import type { IconProps } from "@/packages/Components/Icon/Icon.types";
|
|
8
|
+
import type { PaginationProps } from "@/packages/Components/Pagination/Pagination.types";
|
|
9
|
+
import Text from "@/packages/Components/Text/Text";
|
|
10
|
+
import type { PressableProps } from "@/packages/Frameworks/Pressable/Pressable.types";
|
|
11
|
+
import View from "@/packages/Frameworks/View/View";
|
|
12
|
+
|
|
13
|
+
function clampPage(page: number, total: number) {
|
|
14
|
+
return Math.min(total, Math.max(1, page));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const INPUT_COMMIT_DELAY_MS = 350;
|
|
18
|
+
|
|
19
|
+
export default function Pagination({
|
|
20
|
+
page,
|
|
21
|
+
total,
|
|
22
|
+
onChange,
|
|
23
|
+
disabled = false,
|
|
24
|
+
previousLabel,
|
|
25
|
+
nextLabel,
|
|
26
|
+
navigationLabel,
|
|
27
|
+
getPageLabel,
|
|
28
|
+
className,
|
|
29
|
+
style,
|
|
30
|
+
themePreset,
|
|
31
|
+
background,
|
|
32
|
+
color,
|
|
33
|
+
themeInteractive,
|
|
34
|
+
border,
|
|
35
|
+
"data-color-mode": dataTheme,
|
|
36
|
+
}: PaginationProps) {
|
|
37
|
+
const t = Word();
|
|
38
|
+
const safeTotal = Math.max(1, Math.trunc(total) || 1);
|
|
39
|
+
const safePage = clampPage(Math.trunc(page) || 1, safeTotal);
|
|
40
|
+
const resolvedPreviousLabel = previousLabel ?? t.UIKit.ui.previous;
|
|
41
|
+
const resolvedNextLabel = nextLabel ?? t.UIKit.ui.next;
|
|
42
|
+
const resolvedNavigationLabel = navigationLabel ?? t.UIKit.ui.pagination;
|
|
43
|
+
const resolvedGetPageLabel =
|
|
44
|
+
getPageLabel ??
|
|
45
|
+
((value: number, isCurrent: boolean) =>
|
|
46
|
+
isCurrent
|
|
47
|
+
? t.UIKit.ui.currentPage.replace("{value}", String(value))
|
|
48
|
+
: t.UIKit.ui.goToPageItem.replace("{value}", String(value)));
|
|
49
|
+
const firstPageLabel = resolvedGetPageLabel(1, safePage === 1);
|
|
50
|
+
const lastPageLabel = resolvedGetPageLabel(safeTotal, safePage === safeTotal);
|
|
51
|
+
const [inputValue, setInputValue] = useState(String(safePage));
|
|
52
|
+
const inputWidth = `${Math.max(inputValue.length, 1)}ch`;
|
|
53
|
+
const handleChange = (nextPage: number) => {
|
|
54
|
+
if (disabled) return;
|
|
55
|
+
|
|
56
|
+
const resolvedPage = clampPage(nextPage, safeTotal);
|
|
57
|
+
if (resolvedPage === safePage) return;
|
|
58
|
+
onChange?.(resolvedPage);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const inputCommitTimer = useTimeout(
|
|
62
|
+
() => {
|
|
63
|
+
const nextPage = Number.parseInt(inputValue, 10);
|
|
64
|
+
if (Number.isFinite(nextPage)) {
|
|
65
|
+
handleChange(nextPage);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
INPUT_COMMIT_DELAY_MS,
|
|
69
|
+
{ enabled: false },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
setInputValue(String(safePage));
|
|
74
|
+
}, [safePage]);
|
|
75
|
+
|
|
76
|
+
useEffect(() => inputCommitTimer.clear, [inputCommitTimer]);
|
|
77
|
+
|
|
78
|
+
const commitInputValue = () => {
|
|
79
|
+
inputCommitTimer.clear();
|
|
80
|
+
|
|
81
|
+
const nextPage = Number.parseInt(inputValue, 10);
|
|
82
|
+
if (!Number.isFinite(nextPage)) {
|
|
83
|
+
setInputValue(String(safePage));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const resolvedPage = clampPage(nextPage, safeTotal);
|
|
87
|
+
setInputValue(String(resolvedPage));
|
|
88
|
+
handleChange(resolvedPage);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const scheduleInputCommit = (nextValue: string) => {
|
|
92
|
+
inputCommitTimer.clear();
|
|
93
|
+
if (disabled || !nextValue || nextValue === String(safePage)) return;
|
|
94
|
+
|
|
95
|
+
inputCommitTimer.start(INPUT_COMMIT_DELAY_MS);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
99
|
+
const nextValue = event.currentTarget.value.replace(/\D/g, "");
|
|
100
|
+
if (!nextValue) {
|
|
101
|
+
setInputValue("");
|
|
102
|
+
inputCommitTimer.clear();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const nextPage = Number.parseInt(nextValue, 10);
|
|
107
|
+
const resolvedValue = String(Math.min(nextPage, safeTotal));
|
|
108
|
+
setInputValue(resolvedValue);
|
|
109
|
+
scheduleInputCommit(resolvedValue);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
113
|
+
if (event.key === "Enter") {
|
|
114
|
+
commitInputValue();
|
|
115
|
+
event.currentTarget.blur();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function IconRender({
|
|
120
|
+
icon,
|
|
121
|
+
pressable,
|
|
122
|
+
}: {
|
|
123
|
+
icon: IconProps["icon"];
|
|
124
|
+
pressable: PressableProps;
|
|
125
|
+
}) {
|
|
126
|
+
return (
|
|
127
|
+
<Icon
|
|
128
|
+
box
|
|
129
|
+
boxOptions={{ padding: 12 }}
|
|
130
|
+
icon={icon}
|
|
131
|
+
themePreset={themePreset ?? "UIPrimary"}
|
|
132
|
+
background={background}
|
|
133
|
+
color={color}
|
|
134
|
+
themeInteractive={themeInteractive}
|
|
135
|
+
pressable={pressable}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<nav
|
|
142
|
+
aria-label={resolvedNavigationLabel}
|
|
143
|
+
data-color-mode={dataTheme}
|
|
144
|
+
className={className}
|
|
145
|
+
style={{
|
|
146
|
+
display: "flex",
|
|
147
|
+
alignItems: "center",
|
|
148
|
+
gap: "1.2rem",
|
|
149
|
+
width: "100%",
|
|
150
|
+
...style,
|
|
151
|
+
}}
|
|
152
|
+
role="group"
|
|
153
|
+
>
|
|
154
|
+
<IconRender
|
|
155
|
+
icon="iArrowKeyDoubleLeft"
|
|
156
|
+
pressable={{
|
|
157
|
+
onClick: () => handleChange(1),
|
|
158
|
+
disabled: disabled || safePage <= 1,
|
|
159
|
+
title: firstPageLabel,
|
|
160
|
+
"aria-label": firstPageLabel,
|
|
161
|
+
}}
|
|
162
|
+
/>
|
|
163
|
+
<IconRender
|
|
164
|
+
icon="iArrowKeyLeft"
|
|
165
|
+
pressable={{
|
|
166
|
+
onClick: () => handleChange(safePage - 1),
|
|
167
|
+
disabled: disabled || safePage <= 1,
|
|
168
|
+
title: resolvedPreviousLabel,
|
|
169
|
+
"aria-label": resolvedPreviousLabel,
|
|
170
|
+
}}
|
|
171
|
+
/>
|
|
172
|
+
<fieldset
|
|
173
|
+
style={{
|
|
174
|
+
width: "100%",
|
|
175
|
+
height: "100%",
|
|
176
|
+
border: 0,
|
|
177
|
+
marginInline: 0,
|
|
178
|
+
padding: 0,
|
|
179
|
+
minInlineSize: 0,
|
|
180
|
+
}}
|
|
181
|
+
aria-label={t.UIKit.ui.goToPage}
|
|
182
|
+
>
|
|
183
|
+
<label style={{ width: "100%", height: "100%" }}>
|
|
184
|
+
<View
|
|
185
|
+
themePreset={themePreset ?? "UIPrimary"}
|
|
186
|
+
radius="Circle"
|
|
187
|
+
alignItems="center"
|
|
188
|
+
justifyContent="center"
|
|
189
|
+
gap={12}
|
|
190
|
+
height="100%"
|
|
191
|
+
padding={[15, 8]}
|
|
192
|
+
fullWidth
|
|
193
|
+
>
|
|
194
|
+
<View alignItems="center" gap={0}>
|
|
195
|
+
<input
|
|
196
|
+
type="text"
|
|
197
|
+
inputMode="numeric"
|
|
198
|
+
pattern="[0-9]*"
|
|
199
|
+
value={inputValue}
|
|
200
|
+
disabled={disabled}
|
|
201
|
+
role="spinbutton"
|
|
202
|
+
aria-label={t.UIKit.ui.goToPage}
|
|
203
|
+
aria-valuemin={1}
|
|
204
|
+
aria-valuemax={safeTotal}
|
|
205
|
+
aria-valuenow={safePage}
|
|
206
|
+
onChange={handleInputChange}
|
|
207
|
+
onKeyDown={handleInputKeyDown}
|
|
208
|
+
style={
|
|
209
|
+
{
|
|
210
|
+
"--pagination-input-width": inputWidth,
|
|
211
|
+
textAlign: "center",
|
|
212
|
+
fontSize: "var(--font-headline-size)",
|
|
213
|
+
width: "calc(var(--pagination-input-width, 1ch) + 1.6rem)",
|
|
214
|
+
minWidth: "3.4rem",
|
|
215
|
+
maxWidth: "12rem",
|
|
216
|
+
} as React.CSSProperties
|
|
217
|
+
}
|
|
218
|
+
/>
|
|
219
|
+
<Text type="Headline" verticalTrim opacity={0.2} aria-hidden>
|
|
220
|
+
/
|
|
221
|
+
</Text>
|
|
222
|
+
</View>
|
|
223
|
+
<Text
|
|
224
|
+
type="Headline"
|
|
225
|
+
verticalTrim
|
|
226
|
+
opacity={0.4}
|
|
227
|
+
aria-label={lastPageLabel}
|
|
228
|
+
>
|
|
229
|
+
{safeTotal}
|
|
230
|
+
</Text>
|
|
231
|
+
</View>
|
|
232
|
+
</label>
|
|
233
|
+
</fieldset>
|
|
234
|
+
<IconRender
|
|
235
|
+
icon="iArrowKeyRight"
|
|
236
|
+
pressable={{
|
|
237
|
+
onClick: () => handleChange(safePage + 1),
|
|
238
|
+
disabled: disabled || safePage >= safeTotal,
|
|
239
|
+
title: resolvedNextLabel,
|
|
240
|
+
"aria-label": resolvedNextLabel,
|
|
241
|
+
}}
|
|
242
|
+
/>
|
|
243
|
+
<IconRender
|
|
244
|
+
icon="iArrowKeyDoubleRight"
|
|
245
|
+
pressable={{
|
|
246
|
+
onClick: () => handleChange(safeTotal),
|
|
247
|
+
disabled: disabled || safePage >= safeTotal,
|
|
248
|
+
title: lastPageLabel,
|
|
249
|
+
"aria-label": lastPageLabel,
|
|
250
|
+
}}
|
|
251
|
+
/>
|
|
252
|
+
</nav>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BorderProps,
|
|
3
|
+
ThemeSystemProps,
|
|
4
|
+
} from "@/packages/Frameworks/Theme/Theme.types";
|
|
5
|
+
|
|
6
|
+
export interface PaginationProps extends ThemeSystemProps, BorderProps {
|
|
7
|
+
"data-color-mode"?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
page: number;
|
|
11
|
+
total: number;
|
|
12
|
+
onChange?: (page: number) => void;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
previousLabel?: string;
|
|
15
|
+
nextLabel?: string;
|
|
16
|
+
navigationLabel?: string;
|
|
17
|
+
getPageLabel?: (page: number, isCurrent: boolean) => string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import Icon from "@/packages/Components/Icon/Icon";
|
|
3
|
+
import type { PillProps } from "@/packages/Components/Pill/Pill.types";
|
|
4
|
+
import Text from "@/packages/Components/Text/Text";
|
|
5
|
+
import Pressable from "@/packages/Frameworks/Pressable/Pressable";
|
|
6
|
+
|
|
7
|
+
export function Pill({
|
|
8
|
+
themePreset,
|
|
9
|
+
background,
|
|
10
|
+
color,
|
|
11
|
+
themeInteractive,
|
|
12
|
+
selected,
|
|
13
|
+
border,
|
|
14
|
+
radius,
|
|
15
|
+
shadow,
|
|
16
|
+
renderKey,
|
|
17
|
+
icon,
|
|
18
|
+
pressable,
|
|
19
|
+
disabled,
|
|
20
|
+
text,
|
|
21
|
+
iconSize,
|
|
22
|
+
padding,
|
|
23
|
+
paddingHorizontal,
|
|
24
|
+
paddingVertical,
|
|
25
|
+
checkedThemePreset,
|
|
26
|
+
gap,
|
|
27
|
+
textType,
|
|
28
|
+
textSize,
|
|
29
|
+
textWeight,
|
|
30
|
+
ellipsis,
|
|
31
|
+
rightIcon,
|
|
32
|
+
loading,
|
|
33
|
+
className,
|
|
34
|
+
style,
|
|
35
|
+
shouldWrapText = true,
|
|
36
|
+
"data-color-mode": dataColorMode,
|
|
37
|
+
}: PillProps) {
|
|
38
|
+
const isChecked = Boolean(selected || pressable?.checked);
|
|
39
|
+
const resolvedPreset =
|
|
40
|
+
themePreset ??
|
|
41
|
+
(isChecked ? (checkedThemePreset ?? "BaseFull") : "UIPrimary");
|
|
42
|
+
const resolvedSelected = selected ?? isChecked;
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
className: pressableClassName,
|
|
46
|
+
style: pressableStyle,
|
|
47
|
+
title: pressableTitle,
|
|
48
|
+
disabled: pressableDisabled,
|
|
49
|
+
...restPressable
|
|
50
|
+
} = pressable ?? {};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Pressable
|
|
54
|
+
data-color-mode={dataColorMode}
|
|
55
|
+
{...restPressable}
|
|
56
|
+
themePreset={resolvedPreset}
|
|
57
|
+
background={background}
|
|
58
|
+
color={color}
|
|
59
|
+
themeInteractive={themeInteractive}
|
|
60
|
+
selected={resolvedSelected}
|
|
61
|
+
border={border ?? "Base3TP1"}
|
|
62
|
+
radius={radius ?? "Regular"}
|
|
63
|
+
shadow={shadow}
|
|
64
|
+
disabled={disabled || loading || pressableDisabled}
|
|
65
|
+
className={clsx(className, pressableClassName)}
|
|
66
|
+
alignItems="center"
|
|
67
|
+
justifyContent="center"
|
|
68
|
+
height="max-content"
|
|
69
|
+
gap={gap ?? 4}
|
|
70
|
+
padding={padding ?? ".8rem 1rem"}
|
|
71
|
+
paddingHorizontal={paddingHorizontal}
|
|
72
|
+
paddingVertical={paddingVertical}
|
|
73
|
+
style={{
|
|
74
|
+
width: "max-content",
|
|
75
|
+
minWidth: "max-content",
|
|
76
|
+
textAlign: "center",
|
|
77
|
+
overflow: "hidden",
|
|
78
|
+
userSelect: "none",
|
|
79
|
+
WebkitUserSelect: "none",
|
|
80
|
+
...style,
|
|
81
|
+
...pressableStyle,
|
|
82
|
+
}}
|
|
83
|
+
title={pressableTitle}
|
|
84
|
+
>
|
|
85
|
+
{}
|
|
86
|
+
{icon && <Icon size={iconSize || 13} {...icon} />}
|
|
87
|
+
|
|
88
|
+
{}
|
|
89
|
+
{text && shouldWrapText ? (
|
|
90
|
+
<Text
|
|
91
|
+
type={textType || "Footnote"}
|
|
92
|
+
size={textSize}
|
|
93
|
+
weight={textWeight}
|
|
94
|
+
verticalTrim
|
|
95
|
+
style={
|
|
96
|
+
ellipsis
|
|
97
|
+
? {
|
|
98
|
+
display: "block",
|
|
99
|
+
overflow: "hidden",
|
|
100
|
+
textOverflow: "ellipsis",
|
|
101
|
+
whiteSpace: "nowrap",
|
|
102
|
+
minWidth: 0,
|
|
103
|
+
}
|
|
104
|
+
: undefined
|
|
105
|
+
}
|
|
106
|
+
>
|
|
107
|
+
{text}
|
|
108
|
+
</Text>
|
|
109
|
+
) : text ? (
|
|
110
|
+
text
|
|
111
|
+
) : null}
|
|
112
|
+
|
|
113
|
+
{}
|
|
114
|
+
{loading || rightIcon ? (
|
|
115
|
+
<Icon
|
|
116
|
+
size={iconSize || 12}
|
|
117
|
+
box
|
|
118
|
+
boxOptions={{ padding: ".2rem", margin: "-.2rem" }}
|
|
119
|
+
spinner={loading}
|
|
120
|
+
{...rightIcon}
|
|
121
|
+
/>
|
|
122
|
+
) : null}
|
|
123
|
+
</Pressable>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default Pill;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IconProps } from "@/packages/Components/Icon/Icon.types";
|
|
2
|
+
import type { TextProps } from "@/packages/Components/Text/Text.types";
|
|
3
|
+
import type { UIKitSizeValue } from "@/packages/Frameworks/_shared/sizing";
|
|
4
|
+
import type { PressableProps } from "@/packages/Frameworks/Pressable/Pressable.types";
|
|
5
|
+
import type { RadiusProps } from "@/packages/Frameworks/Theme/Radius.types";
|
|
6
|
+
import type {
|
|
7
|
+
BorderProps,
|
|
8
|
+
ThemeSystemProps,
|
|
9
|
+
} from "@/packages/Frameworks/Theme/Theme.types";
|
|
10
|
+
|
|
11
|
+
export interface PillProps extends ThemeSystemProps, RadiusProps, BorderProps {
|
|
12
|
+
"data-color-mode"?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: React.CSSProperties;
|
|
15
|
+
renderKey?: string;
|
|
16
|
+
icon?: IconProps;
|
|
17
|
+
pressable?: PressableProps;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
text?: React.ReactNode;
|
|
20
|
+
iconSize?: UIKitSizeValue;
|
|
21
|
+
padding?: UIKitSizeValue;
|
|
22
|
+
paddingHorizontal?: UIKitSizeValue;
|
|
23
|
+
paddingVertical?: UIKitSizeValue;
|
|
24
|
+
checkedThemePreset?: ThemeSystemProps["themePreset"];
|
|
25
|
+
gap?: UIKitSizeValue;
|
|
26
|
+
textType?: TextProps["type"];
|
|
27
|
+
textSize?: TextProps["size"];
|
|
28
|
+
textWeight?: TextProps["weight"];
|
|
29
|
+
ellipsis?: boolean;
|
|
30
|
+
rightIcon?: IconProps;
|
|
31
|
+
loading?: boolean;
|
|
32
|
+
shouldWrapText?: boolean;
|
|
33
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { IconProps } from "@/packages/Components/Icon/Icon.types";
|
|
2
|
+
import type { ProfileAvatarOptions } from "@/packages/Components/Profile/Profile.types";
|
|
3
|
+
import {
|
|
4
|
+
Size,
|
|
5
|
+
type UIKitSizeValue,
|
|
6
|
+
} from "@/packages/Frameworks/_shared/sizing";
|
|
7
|
+
|
|
8
|
+
const resolveFallbackAvatarIconSize = (
|
|
9
|
+
outerSize: UIKitSizeValue,
|
|
10
|
+
padding?: UIKitSizeValue,
|
|
11
|
+
): UIKitSizeValue => {
|
|
12
|
+
if (padding === undefined || padding === null || padding === "") {
|
|
13
|
+
return outerSize;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (
|
|
17
|
+
typeof outerSize === "number" &&
|
|
18
|
+
Number.isFinite(outerSize) &&
|
|
19
|
+
typeof padding === "number" &&
|
|
20
|
+
Number.isFinite(padding)
|
|
21
|
+
) {
|
|
22
|
+
return Math.max(0, outerSize - padding * 2);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const resolvedOuterSize = Size(outerSize);
|
|
26
|
+
const resolvedPadding = Size(padding);
|
|
27
|
+
|
|
28
|
+
if (!resolvedOuterSize || !resolvedPadding) {
|
|
29
|
+
return outerSize;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return `calc(${resolvedOuterSize} - (${resolvedPadding} * 2))`;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const getProfileAvatarIconProps = ({
|
|
36
|
+
avatar,
|
|
37
|
+
avatarLoading,
|
|
38
|
+
size,
|
|
39
|
+
imageWidth,
|
|
40
|
+
imageHeight,
|
|
41
|
+
fallbackPadding,
|
|
42
|
+
border,
|
|
43
|
+
background,
|
|
44
|
+
}: ProfileAvatarOptions): IconProps => {
|
|
45
|
+
if (avatar) {
|
|
46
|
+
return {
|
|
47
|
+
image: avatar,
|
|
48
|
+
imageLoading: avatarLoading,
|
|
49
|
+
box: true,
|
|
50
|
+
border: border ?? "None",
|
|
51
|
+
width: imageWidth || size,
|
|
52
|
+
height: imageHeight || size,
|
|
53
|
+
boxOptions: {
|
|
54
|
+
padding: 0,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const fallbackWidth = imageWidth || size;
|
|
60
|
+
const fallbackHeight = imageHeight || size;
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
icon: "iPerson",
|
|
64
|
+
box: true,
|
|
65
|
+
border,
|
|
66
|
+
width: fallbackWidth,
|
|
67
|
+
height: fallbackHeight,
|
|
68
|
+
size: resolveFallbackAvatarIconSize(fallbackWidth, fallbackPadding),
|
|
69
|
+
boxOptions: {
|
|
70
|
+
padding: fallbackPadding,
|
|
71
|
+
},
|
|
72
|
+
background,
|
|
73
|
+
};
|
|
74
|
+
};
|