@conveyorhq/arrow-ds 1.44.0 → 1.47.0
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/package.json +1 -1
- package/public/components/Icon/Icon.d.ts +1 -0
- package/public/components/Icon/Icon.js +5 -3
- package/public/components/ScrollSpy/ScrollSpy.d.ts +51 -18
- package/public/components/ScrollSpy/ScrollSpy.js +112 -77
- package/public/components/ScrollSpy/actions.d.ts +5 -0
- package/public/components/ScrollSpy/actions.js +11 -0
- package/public/components/ScrollSpy/index.d.ts +1 -0
- package/public/components/ScrollSpy/index.js +1 -0
- package/public/components/ScrollSpy/reducers.d.ts +6 -0
- package/public/components/ScrollSpy/reducers.js +23 -0
- package/public/components/ScrollSpy/selectors.d.ts +3 -0
- package/public/components/ScrollSpy/selectors.js +7 -0
- package/public/components/ScrollSpy/types.d.ts +11 -0
- package/public/components/ScrollSpy/types.js +7 -0
- package/public/components/Select/Select.d.ts +1 -0
- package/public/components/Select/Select.js +4 -4
- package/src/components/Icon/Icon.tsx +7 -4
- package/src/components/ScrollSpy/ScrollSpy.tsx +254 -195
- package/src/components/ScrollSpy/actions.ts +8 -0
- package/src/components/ScrollSpy/index.ts +1 -0
- package/src/components/ScrollSpy/reducers.ts +24 -0
- package/src/components/ScrollSpy/selectors.ts +5 -0
- package/src/components/ScrollSpy/types.ts +13 -0
- package/src/components/Select/Select.story.mdx +31 -1
- package/src/components/Select/Select.tsx +5 -0
package/package.json
CHANGED
|
@@ -94,6 +94,7 @@ const faForward_1 = require("@fortawesome/free-solid-svg-icons/faForward");
|
|
|
94
94
|
const faGripLines_1 = require("@fortawesome/free-solid-svg-icons/faGripLines");
|
|
95
95
|
const faGripLinesVertical_1 = require("@fortawesome/free-solid-svg-icons/faGripLinesVertical");
|
|
96
96
|
const faHashtag_1 = require("@fortawesome/free-solid-svg-icons/faHashtag");
|
|
97
|
+
const faHighlighter_1 = require("@fortawesome/free-solid-svg-icons/faHighlighter");
|
|
97
98
|
const faInfoCircle_1 = require("@fortawesome/free-solid-svg-icons/faInfoCircle");
|
|
98
99
|
const faKey_1 = require("@fortawesome/free-solid-svg-icons/faKey");
|
|
99
100
|
const faLayerGroup_1 = require("@fortawesome/free-solid-svg-icons/faLayerGroup");
|
|
@@ -118,8 +119,8 @@ const faScroll_1 = require("@fortawesome/free-solid-svg-icons/faScroll");
|
|
|
118
119
|
const faSearch_1 = require("@fortawesome/free-solid-svg-icons/faSearch");
|
|
119
120
|
const faShareAlt_1 = require("@fortawesome/free-solid-svg-icons/faShareAlt");
|
|
120
121
|
const faShieldAlt_1 = require("@fortawesome/free-solid-svg-icons/faShieldAlt");
|
|
121
|
-
const faSignOutAlt_1 = require("@fortawesome/free-solid-svg-icons/faSignOutAlt");
|
|
122
122
|
const faSignature_1 = require("@fortawesome/free-solid-svg-icons/faSignature");
|
|
123
|
+
const faSignOutAlt_1 = require("@fortawesome/free-solid-svg-icons/faSignOutAlt");
|
|
123
124
|
const faSlidersH_1 = require("@fortawesome/free-solid-svg-icons/faSlidersH");
|
|
124
125
|
const faSort_1 = require("@fortawesome/free-solid-svg-icons/faSort");
|
|
125
126
|
const faSortDown_1 = require("@fortawesome/free-solid-svg-icons/faSortDown");
|
|
@@ -140,16 +141,16 @@ const faTrash_1 = require("@fortawesome/free-solid-svg-icons/faTrash");
|
|
|
140
141
|
const faUnlock_1 = require("@fortawesome/free-solid-svg-icons/faUnlock");
|
|
141
142
|
const faUser_2 = require("@fortawesome/free-solid-svg-icons/faUser");
|
|
142
143
|
const faUserAstronaut_1 = require("@fortawesome/free-solid-svg-icons/faUserAstronaut");
|
|
144
|
+
const faUserFriends_1 = require("@fortawesome/free-solid-svg-icons/faUserFriends");
|
|
143
145
|
const faUserPlus_1 = require("@fortawesome/free-solid-svg-icons/faUserPlus");
|
|
144
146
|
const faUsers_1 = require("@fortawesome/free-solid-svg-icons/faUsers");
|
|
145
|
-
const faUserFriends_1 = require("@fortawesome/free-solid-svg-icons/faUserFriends");
|
|
146
147
|
const faUserShield_1 = require("@fortawesome/free-solid-svg-icons/faUserShield");
|
|
147
148
|
const svg_1 = require("./svg");
|
|
148
149
|
const status_1 = require("../../contexts/status");
|
|
149
150
|
const types_1 = require("../../types");
|
|
150
151
|
const utilities_1 = require("../../utilities");
|
|
151
152
|
const cn = utilities_1.bemHOF("Icon");
|
|
152
|
-
fontawesome_svg_core_1.library.add(faArchive_1.faArchive, faArrowDown_1.faArrowDown, faArrowLeft_1.faArrowLeft, faArrowRight_1.faArrowRight, faArrowUp_1.faArrowUp, faBackward_1.faBackward, faBan_1.faBan, faBatteryHalf_1.faBatteryHalf, faBed_1.faBed, faBell_1.faBell, faBolt_1.faBolt, faCalculator_1.faCalculator, faCalendar_1.faCalendar, faCaretDown_1.faCaretDown, faCaretLeft_1.faCaretLeft, faCaretRight_1.faCaretRight, faCaretUp_1.faCaretUp, faChartLine_1.faChartLine, faCheck_1.faCheck, faCheckCircle_2.faCheckCircle, faCheckCircle_1.faCheckCircle, faChevronDown_1.faChevronDown, faChevronLeft_1.faChevronLeft, faChevronRight_1.faChevronRight, faChevronUp_1.faChevronUp, faCircle_2.faCircle, faCircleNotch_1.faCircleNotch, faCircle_1.faCircle, faClipboard_1.faClipboard, faClock_1.faClock, faClock_2.faClock, faCog_1.faCog, faColumns_1.faColumns, faCommentAlt_1.faCommentAlt, faCompass_1.faCompass, faCompress_1.faCompress, faCrown_1.faCrown, faEllipsisH_1.faEllipsisH, faEllipsisV_1.faEllipsisV, faEnvelope_1.faEnvelope, faExclamationCircle_1.faExclamationCircle, faExclamationTriangle_1.faExclamationTriangle, faExpand_1.faExpand, faExternalLinkAlt_1.faExternalLinkAlt, faExternalLinkSquareAlt_1.faExternalLinkSquareAlt, faEye_1.faEye, faEyeSlash_1.faEyeSlash, faFastBackward_1.faFastBackward, faFastForward_1.faFastForward, faFileAlt_1.faFileAlt, faFileAlt_2.faFileAlt, faFileImport_1.faFileImport, faFileSignature_1.faFileSignature, faFilter_1.faFilter, faFlag_1.faFlag, faFolder_1.faFolder, faForward_1.faForward, faGripLines_1.faGripLines, faGripLinesVertical_1.faGripLinesVertical, faHashtag_1.faHashtag, faInfoCircle_1.faInfoCircle, faKey_1.faKey, faKeyboard_1.faKeyboard, faLayerGroup_1.faLayerGroup, faLevelUpAlt_1.faLevelUpAlt, faListUl_1.faListUl, faLock_1.faLock, faLongArrowAltRight_1.faLongArrowAltRight, faMagic_1.faMagic, faMapSigns_1.faMapSigns, faMinus_1.faMinus, faMousePointer_1.faMousePointer, faPaperclip_1.faPaperclip, faPause_1.faPause, faPen_1.faPen, faPlay_1.faPlay, faPlus_1.faPlus, faPlusCircle_1.faPlusCircle, faPooStorm_1.faPooStorm, faQuestion_1.faQuestion, faQuestionCircle_2.faQuestionCircle, faQuestionCircle_1.faQuestionCircle, faScroll_1.faScroll, faSearch_1.faSearch, faShareAlt_1.faShareAlt, faShieldAlt_1.faShieldAlt,
|
|
153
|
+
fontawesome_svg_core_1.library.add(faArchive_1.faArchive, faArrowDown_1.faArrowDown, faArrowLeft_1.faArrowLeft, faArrowRight_1.faArrowRight, faArrowUp_1.faArrowUp, faBackward_1.faBackward, faBan_1.faBan, faBatteryHalf_1.faBatteryHalf, faBed_1.faBed, faBell_1.faBell, faBolt_1.faBolt, faCalculator_1.faCalculator, faCalendar_1.faCalendar, faCaretDown_1.faCaretDown, faCaretLeft_1.faCaretLeft, faCaretRight_1.faCaretRight, faCaretUp_1.faCaretUp, faChartLine_1.faChartLine, faCheck_1.faCheck, faCheckCircle_2.faCheckCircle, faCheckCircle_1.faCheckCircle, faChevronDown_1.faChevronDown, faChevronLeft_1.faChevronLeft, faChevronRight_1.faChevronRight, faChevronUp_1.faChevronUp, faCircle_2.faCircle, faCircleNotch_1.faCircleNotch, faCircle_1.faCircle, faClipboard_1.faClipboard, faClock_1.faClock, faClock_2.faClock, faCog_1.faCog, faColumns_1.faColumns, faCommentAlt_1.faCommentAlt, faCompass_1.faCompass, faCompress_1.faCompress, faCrown_1.faCrown, faEllipsisH_1.faEllipsisH, faEllipsisV_1.faEllipsisV, faEnvelope_1.faEnvelope, faExclamationCircle_1.faExclamationCircle, faExclamationTriangle_1.faExclamationTriangle, faExpand_1.faExpand, faExternalLinkAlt_1.faExternalLinkAlt, faExternalLinkSquareAlt_1.faExternalLinkSquareAlt, faEye_1.faEye, faEyeSlash_1.faEyeSlash, faFastBackward_1.faFastBackward, faFastForward_1.faFastForward, faFileAlt_1.faFileAlt, faFileAlt_2.faFileAlt, faFileImport_1.faFileImport, faFileSignature_1.faFileSignature, faFilter_1.faFilter, faFlag_1.faFlag, faFolder_1.faFolder, faForward_1.faForward, faGripLines_1.faGripLines, faGripLinesVertical_1.faGripLinesVertical, faHashtag_1.faHashtag, faHighlighter_1.faHighlighter, faInfoCircle_1.faInfoCircle, faKey_1.faKey, faKeyboard_1.faKeyboard, faLayerGroup_1.faLayerGroup, faLevelUpAlt_1.faLevelUpAlt, faListUl_1.faListUl, faLock_1.faLock, faLongArrowAltRight_1.faLongArrowAltRight, faMagic_1.faMagic, faMapSigns_1.faMapSigns, faMinus_1.faMinus, faMousePointer_1.faMousePointer, faPaperclip_1.faPaperclip, faPause_1.faPause, faPen_1.faPen, faPlay_1.faPlay, faPlus_1.faPlus, faPlusCircle_1.faPlusCircle, faPooStorm_1.faPooStorm, faQuestion_1.faQuestion, faQuestionCircle_2.faQuestionCircle, faQuestionCircle_1.faQuestionCircle, faScroll_1.faScroll, faSearch_1.faSearch, faShareAlt_1.faShareAlt, faShieldAlt_1.faShieldAlt, faSignature_1.faSignature, faSignOutAlt_1.faSignOutAlt, faSlidersH_1.faSlidersH, faSort_1.faSort, faSortDown_1.faSortDown, faSortUp_1.faSortUp, faSpinner_1.faSpinner, faSquare_1.faSquare, faStar_1.faStar, faStar_2.faStar, faSync_1.faSync, faTasks_1.faTasks, faThLarge_1.faThLarge, faThumbsDown_1.faThumbsDown, faThumbsDown_2.faThumbsDown, faThumbsUp_1.faThumbsUp, faThumbsUp_2.faThumbsUp, faTicketAlt_1.faTicketAlt, faTimes_1.faTimes, faTimesCircle_1.faTimesCircle, faTimesCircle_2.faTimesCircle, faTools_1.faTools, faTrash_1.faTrash, faUnlock_1.faUnlock, faUser_2.faUser, faUserAstronaut_1.faUserAstronaut, faUserFriends_1.faUserFriends, faUserPlus_1.faUserPlus, faUser_1.faUser, faUsers_1.faUsers, faUserShield_1.faUserShield);
|
|
153
154
|
var CUSTOM_ICON_TYPE;
|
|
154
155
|
(function (CUSTOM_ICON_TYPE) {
|
|
155
156
|
CUSTOM_ICON_TYPE["ARROW_TO_BOTTOM"] = "arrow-to-bottom";
|
|
@@ -227,6 +228,7 @@ var ICON_TYPE;
|
|
|
227
228
|
ICON_TYPE["GRIP_LINES"] = "grip-lines";
|
|
228
229
|
ICON_TYPE["GRIP_LINES_VERTICAL"] = "grip-lines-vertical";
|
|
229
230
|
ICON_TYPE["HASHTAG"] = "hashtag";
|
|
231
|
+
ICON_TYPE["HIGHLIGHTER"] = "highlighter";
|
|
230
232
|
ICON_TYPE["INFO_CIRCLE"] = "info-circle";
|
|
231
233
|
ICON_TYPE["KEY"] = "key";
|
|
232
234
|
ICON_TYPE["KEYBOARD"] = "keyboard";
|
|
@@ -1,29 +1,46 @@
|
|
|
1
|
-
import React, { ReactNode,
|
|
1
|
+
import React, { ReactNode, MutableRefObject, Dispatch, HTMLAttributes, ReactElement, AnchorHTMLAttributes, MouseEvent, ChangeEvent, InputHTMLAttributes } from "react";
|
|
2
|
+
import { ScrollSpyState, ScrollSpyAction } from "./types";
|
|
3
|
+
export declare const ScrollSpyStateContext: React.Context<{
|
|
4
|
+
state: ScrollSpyState;
|
|
5
|
+
dispatch: Dispatch<ScrollSpyAction>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function useScrollSpyStateContext(): {
|
|
8
|
+
state: ScrollSpyState;
|
|
9
|
+
dispatch: React.Dispatch<ScrollSpyAction>;
|
|
10
|
+
};
|
|
2
11
|
declare type ScrollSpyContextType = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
currentPage: number;
|
|
6
|
-
setCurrentPage: Dispatch<SetStateAction<number>>;
|
|
12
|
+
id: string;
|
|
13
|
+
itemCount: number;
|
|
7
14
|
refList: MutableRefObject<HTMLElement[]>;
|
|
15
|
+
defaultIndex: number;
|
|
8
16
|
updateCurrentRef(index: number, refItem: HTMLElement): void;
|
|
9
17
|
scrollToRef(refToScrollTo: HTMLElement): void;
|
|
10
18
|
scrollToFirst(event: MouseEvent): void;
|
|
11
19
|
scrollToLast(event: MouseEvent): void;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
onInputKeyUp(event: KeyboardEvent<HTMLInputElement>): void;
|
|
15
|
-
onInputFocus(event: FocusEvent<HTMLInputElement>): void;
|
|
16
|
-
items: number;
|
|
17
|
-
id: string;
|
|
20
|
+
scrollToPage(page: number): void;
|
|
21
|
+
skipToPage(page: number): void;
|
|
18
22
|
};
|
|
19
|
-
export declare const ScrollSpyContext: Context<ScrollSpyContextType>;
|
|
23
|
+
export declare const ScrollSpyContext: React.Context<ScrollSpyContextType>;
|
|
20
24
|
export declare function useScrollSpyContext(): ScrollSpyContextType;
|
|
25
|
+
export declare type ScrollSpyInputUsePropsHookProps = {
|
|
26
|
+
className?: string;
|
|
27
|
+
onChange?(event: ChangeEvent<HTMLInputElement>): void;
|
|
28
|
+
};
|
|
29
|
+
export declare const useScrollSpyInputProps: ({ className, onChange, }: ScrollSpyInputUsePropsHookProps) => {
|
|
30
|
+
className: string;
|
|
31
|
+
type: string;
|
|
32
|
+
min: string;
|
|
33
|
+
max: number;
|
|
34
|
+
maxLength: number;
|
|
35
|
+
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
36
|
+
value: number;
|
|
37
|
+
};
|
|
21
38
|
export declare type ScrollSpyInputProps = InputHTMLAttributes<HTMLInputElement>;
|
|
22
|
-
export declare const ScrollSpyInput: React.ForwardRefExoticComponent<ScrollSpyInputProps & React.RefAttributes<HTMLInputElement
|
|
39
|
+
export declare const ScrollSpyInput: React.MemoExoticComponent<React.ForwardRefExoticComponent<ScrollSpyInputProps & React.RefAttributes<HTMLInputElement>>>;
|
|
23
40
|
export interface ScrollSpyPageProps extends HTMLAttributes<HTMLDivElement> {
|
|
24
41
|
children: ReactElement;
|
|
25
|
-
threshold: number | number[] | undefined;
|
|
26
42
|
index: number;
|
|
43
|
+
threshold?: number | number[] | undefined;
|
|
27
44
|
}
|
|
28
45
|
export declare type ScrollSpyPageUsePropsHookProps = {
|
|
29
46
|
index: number;
|
|
@@ -32,7 +49,7 @@ export declare type ScrollSpyPageUsePropsHookProps = {
|
|
|
32
49
|
export declare const useScrollSpyPageProps: ({ index, id }?: ScrollSpyPageUsePropsHookProps) => {
|
|
33
50
|
id: string;
|
|
34
51
|
};
|
|
35
|
-
export declare const ScrollSpyPage: React.ForwardRefExoticComponent<ScrollSpyPageProps & React.RefAttributes<HTMLDivElement
|
|
52
|
+
export declare const ScrollSpyPage: React.MemoExoticComponent<React.ForwardRefExoticComponent<ScrollSpyPageProps & React.RefAttributes<HTMLDivElement>>>;
|
|
36
53
|
export interface ScrollSpyAnchorProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
37
54
|
children: ReactNode;
|
|
38
55
|
index: number;
|
|
@@ -49,11 +66,27 @@ export declare const useScrollSpyAnchorProps: ({ index, id, href, onClick }?: Sc
|
|
|
49
66
|
onClick: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
50
67
|
isActive: boolean;
|
|
51
68
|
};
|
|
52
|
-
export declare const ScrollSpyAnchor: React.ForwardRefExoticComponent<ScrollSpyAnchorProps & React.RefAttributes<HTMLAnchorElement
|
|
69
|
+
export declare const ScrollSpyAnchor: React.MemoExoticComponent<React.ForwardRefExoticComponent<ScrollSpyAnchorProps & React.RefAttributes<HTMLAnchorElement>>>;
|
|
53
70
|
export declare type ScrollSpyRootProps = {
|
|
54
71
|
children: ReactNode | ((props: ScrollSpyContextType) => JSX.Element);
|
|
55
|
-
|
|
72
|
+
itemCount: number;
|
|
56
73
|
defaultIndex?: number;
|
|
57
74
|
};
|
|
58
|
-
export declare const ScrollSpyRoot: ({ children,
|
|
75
|
+
export declare const ScrollSpyRoot: React.MemoExoticComponent<({ children, itemCount, defaultIndex }: ScrollSpyRootProps) => JSX.Element>;
|
|
76
|
+
export declare const ScrollSpyStateProvider: ({ children, }: {
|
|
77
|
+
children: ReactNode;
|
|
78
|
+
}) => JSX.Element;
|
|
79
|
+
export declare const ScrollSpyReducers: {
|
|
80
|
+
reducer: (state: ScrollSpyState | undefined, action: ScrollSpyAction) => ScrollSpyState;
|
|
81
|
+
};
|
|
82
|
+
export declare const ScrollSpySelectors: {
|
|
83
|
+
selectCurrentIndex: (state: ScrollSpyState) => number;
|
|
84
|
+
selectCurrentPage: (state: ScrollSpyState) => number;
|
|
85
|
+
};
|
|
86
|
+
export declare const ScrollSpyActions: {
|
|
87
|
+
updateIndex: (index: number) => {
|
|
88
|
+
type: import("./types").ScrollSpyActionType;
|
|
89
|
+
index: number;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
59
92
|
export {};
|
|
@@ -22,30 +22,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ScrollSpyRoot = exports.ScrollSpyAnchor = exports.useScrollSpyAnchorProps = exports.ScrollSpyPage = exports.useScrollSpyPageProps = exports.ScrollSpyInput = exports.useScrollSpyContext = exports.ScrollSpyContext = void 0;
|
|
25
|
+
exports.ScrollSpyActions = exports.ScrollSpySelectors = exports.ScrollSpyReducers = exports.ScrollSpyStateProvider = exports.ScrollSpyRoot = exports.ScrollSpyAnchor = exports.useScrollSpyAnchorProps = exports.ScrollSpyPage = exports.useScrollSpyPageProps = exports.ScrollSpyInput = exports.useScrollSpyInputProps = exports.useScrollSpyContext = exports.ScrollSpyContext = exports.useScrollSpyStateContext = exports.ScrollSpyStateContext = void 0;
|
|
26
26
|
const react_1 = __importStar(require("react"));
|
|
27
27
|
const react_merge_refs_1 = __importDefault(require("react-merge-refs"));
|
|
28
28
|
const auto_id_1 = require("@reach/auto-id");
|
|
29
29
|
const classnames_1 = __importDefault(require("classnames"));
|
|
30
30
|
const utilities_1 = require("../../utilities");
|
|
31
31
|
const hooks_1 = require("../../hooks");
|
|
32
|
+
const reducers_1 = require("./reducers");
|
|
33
|
+
const selectors_1 = require("./selectors");
|
|
34
|
+
const actions_1 = require("./actions");
|
|
32
35
|
const cn = utilities_1.bemHOF("ScrollSpy");
|
|
36
|
+
const initialContextState = {
|
|
37
|
+
state: reducers_1.scrollSpyInitialState,
|
|
38
|
+
dispatch: () => { },
|
|
39
|
+
};
|
|
40
|
+
exports.ScrollSpyStateContext = react_1.createContext(initialContextState);
|
|
41
|
+
function useScrollSpyStateContext() {
|
|
42
|
+
const context = react_1.useContext(exports.ScrollSpyStateContext) || {
|
|
43
|
+
...initialContextState,
|
|
44
|
+
};
|
|
45
|
+
return context;
|
|
46
|
+
}
|
|
47
|
+
exports.useScrollSpyStateContext = useScrollSpyStateContext;
|
|
33
48
|
const defaultRootContext = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
currentPage: 1,
|
|
37
|
-
setCurrentPage: (index) => index,
|
|
49
|
+
id: "scroll-spy-1",
|
|
50
|
+
itemCount: 1,
|
|
38
51
|
refList: { current: [] },
|
|
52
|
+
defaultIndex: 0,
|
|
39
53
|
updateCurrentRef: () => { },
|
|
40
54
|
scrollToRef: () => { },
|
|
41
55
|
scrollToFirst: () => { },
|
|
42
56
|
scrollToLast: () => { },
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
onInputKeyUp: () => { },
|
|
46
|
-
onInputFocus: () => { },
|
|
47
|
-
items: 1,
|
|
48
|
-
id: "scroll-spy-1",
|
|
57
|
+
scrollToPage: () => { },
|
|
58
|
+
skipToPage: () => { },
|
|
49
59
|
};
|
|
50
60
|
exports.ScrollSpyContext = react_1.createContext(defaultRootContext);
|
|
51
61
|
function useScrollSpyContext() {
|
|
@@ -55,9 +65,38 @@ function useScrollSpyContext() {
|
|
|
55
65
|
return context;
|
|
56
66
|
}
|
|
57
67
|
exports.useScrollSpyContext = useScrollSpyContext;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
68
|
+
const useScrollSpyInputProps = ({ className, onChange, }) => {
|
|
69
|
+
const { dispatch, state } = useScrollSpyStateContext();
|
|
70
|
+
const { itemCount, skipToPage } = useScrollSpyContext();
|
|
71
|
+
const currentPage = selectors_1.selectCurrentPage(state);
|
|
72
|
+
const onChangeHandler = (event) => {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
event.stopPropagation();
|
|
75
|
+
const pageNumber = parseInt(event.target.value, 10);
|
|
76
|
+
const index = pageNumber - 1;
|
|
77
|
+
dispatch(actions_1.updateIndex(index));
|
|
78
|
+
if (pageNumber && pageNumber >= 1 && pageNumber <= itemCount) {
|
|
79
|
+
skipToPage(pageNumber);
|
|
80
|
+
}
|
|
81
|
+
if (onChange) {
|
|
82
|
+
onChange(event);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
className: classnames_1.default(cn({ e: "input" }), className),
|
|
87
|
+
type: "number",
|
|
88
|
+
min: "1",
|
|
89
|
+
max: itemCount,
|
|
90
|
+
maxLength: itemCount.toString().split("").length,
|
|
91
|
+
onChange: onChangeHandler,
|
|
92
|
+
value: currentPage,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
exports.useScrollSpyInputProps = useScrollSpyInputProps;
|
|
96
|
+
exports.ScrollSpyInput = react_1.memo(react_1.forwardRef(({ className, ...rest }, forwardedRef) => {
|
|
97
|
+
const props = exports.useScrollSpyInputProps({ className });
|
|
98
|
+
return react_1.default.createElement("input", Object.assign({ ref: forwardedRef }, props, rest));
|
|
99
|
+
}));
|
|
61
100
|
const useScrollSpyPageProps = ({ index, id } = { index: 0 }) => {
|
|
62
101
|
const { id: rootId } = useScrollSpyContext();
|
|
63
102
|
const pageId = `${rootId}-page-${index + 1}`;
|
|
@@ -66,125 +105,121 @@ const useScrollSpyPageProps = ({ index, id } = { index: 0 }) => {
|
|
|
66
105
|
};
|
|
67
106
|
};
|
|
68
107
|
exports.useScrollSpyPageProps = useScrollSpyPageProps;
|
|
69
|
-
exports.ScrollSpyPage = react_1.forwardRef(({ id: idProp, children, index, threshold = 0.5, ...rest }, forwardedRef) => {
|
|
108
|
+
exports.ScrollSpyPage = react_1.memo(react_1.forwardRef(({ id: idProp, children, index, threshold = 0.5, ...rest }, forwardedRef) => {
|
|
70
109
|
const ref = react_1.useRef(null);
|
|
71
110
|
const combinedRef = react_merge_refs_1.default([ref, forwardedRef]);
|
|
72
111
|
const isVisible = hooks_1.useIntersection(ref, {
|
|
73
112
|
threshold,
|
|
74
113
|
});
|
|
75
|
-
const {
|
|
114
|
+
const { dispatch } = useScrollSpyStateContext();
|
|
115
|
+
const { updateCurrentRef } = useScrollSpyContext();
|
|
76
116
|
const { id } = exports.useScrollSpyPageProps({ index, id: idProp });
|
|
77
|
-
const pageNumber = index + 1;
|
|
78
117
|
react_1.useEffect(() => {
|
|
79
118
|
if (ref && ref.current) {
|
|
80
119
|
updateCurrentRef(index, ref.current);
|
|
81
120
|
}
|
|
82
|
-
}
|
|
121
|
+
});
|
|
83
122
|
react_1.useEffect(() => {
|
|
84
123
|
if (isVisible) {
|
|
85
|
-
|
|
86
|
-
setCurrentPage(pageNumber);
|
|
124
|
+
dispatch(actions_1.updateIndex(index));
|
|
87
125
|
}
|
|
88
|
-
}, [isVisible
|
|
89
|
-
return (react_1.default.createElement(react_1.default.Fragment, null, react_1.
|
|
126
|
+
}, [isVisible]);
|
|
127
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, react_1.cloneElement(react_1.Children.only(children), {
|
|
90
128
|
...rest,
|
|
91
129
|
...children.props,
|
|
92
130
|
id,
|
|
93
131
|
ref: combinedRef,
|
|
94
132
|
})));
|
|
95
|
-
});
|
|
133
|
+
}));
|
|
96
134
|
const useScrollSpyAnchorProps = ({ index, id, href, onClick } = { index: 0 }) => {
|
|
97
|
-
const { id: rootId,
|
|
135
|
+
const { id: rootId, scrollToPage } = useScrollSpyContext();
|
|
98
136
|
const { id: pageId } = exports.useScrollSpyPageProps({ index });
|
|
99
137
|
const anchorId = `${rootId}-anchor-${index + 1}`;
|
|
138
|
+
const { state } = useScrollSpyStateContext();
|
|
139
|
+
const currentIndex = selectors_1.selectCurrentIndex(state);
|
|
140
|
+
const onClickHandler = (event) => {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
event.stopPropagation();
|
|
143
|
+
scrollToPage(index + 1);
|
|
144
|
+
if (onClick) {
|
|
145
|
+
onClick(event);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
100
148
|
return {
|
|
101
149
|
id: id || anchorId,
|
|
102
150
|
href: href || `#${pageId}`,
|
|
103
|
-
onClick:
|
|
104
|
-
event.preventDefault();
|
|
105
|
-
if (onClick)
|
|
106
|
-
onClick(event);
|
|
107
|
-
onAnchorClick(event, index);
|
|
108
|
-
},
|
|
151
|
+
onClick: onClickHandler,
|
|
109
152
|
isActive: currentIndex === index,
|
|
110
153
|
};
|
|
111
154
|
};
|
|
112
155
|
exports.useScrollSpyAnchorProps = useScrollSpyAnchorProps;
|
|
113
|
-
exports.ScrollSpyAnchor = react_1.forwardRef(({ id, children, onClick, index = 0, ...rest }, forwardedRef) => {
|
|
156
|
+
exports.ScrollSpyAnchor = react_1.memo(react_1.forwardRef(({ id, children, onClick, index = 0, ...rest }, forwardedRef) => {
|
|
114
157
|
const { isActive, ...anchorProps } = exports.useScrollSpyAnchorProps({
|
|
115
158
|
index,
|
|
116
159
|
id,
|
|
117
160
|
onClick,
|
|
118
161
|
});
|
|
119
162
|
return (react_1.default.createElement("a", Object.assign({ ref: forwardedRef }, anchorProps, rest), children));
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const defaultPageNumber = defaultIndex + 1;
|
|
123
|
-
const [currentIndex, setCurrentIndex] = react_1.useState(defaultIndex);
|
|
124
|
-
const [currentPage, setCurrentPage] = react_1.useState(defaultPageNumber);
|
|
163
|
+
}));
|
|
164
|
+
exports.ScrollSpyRoot = react_1.memo(({ children, itemCount, defaultIndex = 0 }) => {
|
|
125
165
|
const refList = react_1.useRef([]);
|
|
126
166
|
const id = `scroll-spy-${auto_id_1.useId()}`;
|
|
167
|
+
const prefersReducedMotion = hooks_1.usePrefersReducedMotion();
|
|
168
|
+
const scrollBehavior = prefersReducedMotion ? "auto" : "smooth";
|
|
127
169
|
react_1.useEffect(() => {
|
|
128
|
-
refList.current = refList.current.slice(0,
|
|
129
|
-
}, [
|
|
170
|
+
refList.current = refList.current.slice(0, itemCount);
|
|
171
|
+
}, [itemCount]);
|
|
130
172
|
const updateCurrentRef = (index, refItem) => {
|
|
131
173
|
refList.current[index] = refItem;
|
|
132
174
|
};
|
|
133
|
-
const scrollToRef = (refToScrollTo) => {
|
|
134
|
-
refToScrollTo.scrollIntoView({ behavior
|
|
175
|
+
const scrollToRef = (refToScrollTo, behavior = "smooth") => {
|
|
176
|
+
refToScrollTo.scrollIntoView({ behavior });
|
|
135
177
|
};
|
|
136
178
|
const scrollToFirst = (event) => {
|
|
137
179
|
event.stopPropagation();
|
|
138
|
-
scrollToRef(refList.current[0]);
|
|
180
|
+
scrollToRef(refList.current[0], scrollBehavior);
|
|
139
181
|
};
|
|
140
182
|
const scrollToLast = (event) => {
|
|
141
183
|
event.stopPropagation();
|
|
142
|
-
scrollToRef(refList.current[
|
|
184
|
+
scrollToRef(refList.current[itemCount - 1], scrollBehavior);
|
|
143
185
|
};
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
scrollToRef(refList.current[index]);
|
|
147
|
-
setCurrentPage(index + 1);
|
|
186
|
+
const scrollToPage = (page) => {
|
|
187
|
+
const index = page - 1;
|
|
188
|
+
scrollToRef(refList.current[index], scrollBehavior);
|
|
148
189
|
};
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
event.preventDefault();
|
|
153
|
-
const { value } = event.target;
|
|
154
|
-
const pageNumber = parseInt(value, 10);
|
|
155
|
-
const index = pageNumber - 1;
|
|
156
|
-
setCurrentPage(pageNumber);
|
|
157
|
-
if (pageNumber && pageNumber >= 1 && pageNumber <= items) {
|
|
158
|
-
scrollToRef(refList.current[index]);
|
|
159
|
-
}
|
|
190
|
+
const skipToPage = (page) => {
|
|
191
|
+
const index = page - 1;
|
|
192
|
+
scrollToRef(refList.current[index], "auto");
|
|
160
193
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const pageNumber = parseInt(value, 10);
|
|
166
|
-
const index = pageNumber - 1;
|
|
167
|
-
if (pageNumber && pageNumber >= 1 && pageNumber <= items) {
|
|
168
|
-
scrollToRef(refList.current[index]);
|
|
194
|
+
react_1.useEffect(() => {
|
|
195
|
+
const lastIndex = itemCount - 1;
|
|
196
|
+
if (defaultIndex > 0 && defaultIndex <= lastIndex) {
|
|
197
|
+
skipToPage(defaultIndex + 1);
|
|
169
198
|
}
|
|
170
|
-
};
|
|
199
|
+
}, [defaultIndex, itemCount]);
|
|
171
200
|
const context = {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
currentPage,
|
|
175
|
-
setCurrentPage,
|
|
201
|
+
id,
|
|
202
|
+
itemCount,
|
|
176
203
|
refList,
|
|
204
|
+
defaultIndex,
|
|
177
205
|
updateCurrentRef,
|
|
178
206
|
scrollToRef,
|
|
179
207
|
scrollToFirst,
|
|
180
208
|
scrollToLast,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
onInputKeyUp,
|
|
184
|
-
onInputFocus,
|
|
185
|
-
items,
|
|
186
|
-
id,
|
|
209
|
+
scrollToPage,
|
|
210
|
+
skipToPage,
|
|
187
211
|
};
|
|
188
212
|
return (react_1.default.createElement(exports.ScrollSpyContext.Provider, { value: context }, typeof children === "function" ? children(context) : children));
|
|
213
|
+
});
|
|
214
|
+
const ScrollSpyStateProvider = ({ children, }) => {
|
|
215
|
+
const [state, dispatch] = react_1.useReducer(reducers_1.reducer, {
|
|
216
|
+
index: 0,
|
|
217
|
+
page: 1,
|
|
218
|
+
});
|
|
219
|
+
const value = react_1.useMemo(() => ({ state, dispatch }), [state]);
|
|
220
|
+
return (react_1.default.createElement(exports.ScrollSpyStateContext.Provider, { value: value }, children));
|
|
189
221
|
};
|
|
190
|
-
exports.
|
|
222
|
+
exports.ScrollSpyStateProvider = ScrollSpyStateProvider;
|
|
223
|
+
exports.ScrollSpyReducers = { reducer: reducers_1.reducer };
|
|
224
|
+
exports.ScrollSpySelectors = { selectCurrentIndex: selectors_1.selectCurrentIndex, selectCurrentPage: selectors_1.selectCurrentPage };
|
|
225
|
+
exports.ScrollSpyActions = { updateIndex: actions_1.updateIndex };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateIndex = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const updateIndex = (index) => {
|
|
6
|
+
return {
|
|
7
|
+
type: types_1.ScrollSpyActionType.UPDATE,
|
|
8
|
+
index,
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.updateIndex = updateIndex;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reducer = exports.scrollSpyInitialState = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
exports.scrollSpyInitialState = {
|
|
6
|
+
index: 0,
|
|
7
|
+
page: 1,
|
|
8
|
+
};
|
|
9
|
+
const reducer = (state = exports.scrollSpyInitialState, action) => {
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case types_1.ScrollSpyActionType.UPDATE:
|
|
12
|
+
return state.index !== action.index
|
|
13
|
+
? {
|
|
14
|
+
...state,
|
|
15
|
+
index: action.index,
|
|
16
|
+
page: action.index + 1,
|
|
17
|
+
}
|
|
18
|
+
: state;
|
|
19
|
+
default:
|
|
20
|
+
return state;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.reducer = reducer;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectCurrentPage = exports.selectCurrentIndex = void 0;
|
|
4
|
+
const selectCurrentIndex = (state) => state.index;
|
|
5
|
+
exports.selectCurrentIndex = selectCurrentIndex;
|
|
6
|
+
const selectCurrentPage = (state) => state.page;
|
|
7
|
+
exports.selectCurrentPage = selectCurrentPage;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScrollSpyActionType = void 0;
|
|
4
|
+
var ScrollSpyActionType;
|
|
5
|
+
(function (ScrollSpyActionType) {
|
|
6
|
+
ScrollSpyActionType["UPDATE"] = "UPDATE";
|
|
7
|
+
})(ScrollSpyActionType = exports.ScrollSpyActionType || (exports.ScrollSpyActionType = {}));
|
|
@@ -110,7 +110,7 @@ const generateHardcodedProps = ({ controlHeight, menuInPortal, menuRef, componen
|
|
|
110
110
|
},
|
|
111
111
|
};
|
|
112
112
|
};
|
|
113
|
-
const SelectBase = ({ variant: variantProp = types_1.STATUS_VARIANT.DEFAULT, id: idProp, className, height: controlHeight = utilities_1.toNumber(tokens_1.tokens.height["10"]), menuInPortal = false, menuRef, components, optionsMessage, styles, ...rest }) => {
|
|
113
|
+
const SelectBase = ({ variant: variantProp = types_1.STATUS_VARIANT.DEFAULT, id: idProp, className, height: controlHeight = utilities_1.toNumber(tokens_1.tokens.height["10"]), menuInPortal = false, menuRef, components, optionsMessage, styles, selectRef, ...rest }) => {
|
|
114
114
|
const { variant: variantContext, id: idContext } = react_1.useContext(FormGroupContext_1.FormGroupContext);
|
|
115
115
|
const id = idContext || idProp;
|
|
116
116
|
const variant = variantContext || variantProp;
|
|
@@ -123,12 +123,12 @@ const SelectBase = ({ variant: variantProp = types_1.STATUS_VARIANT.DEFAULT, id:
|
|
|
123
123
|
optionsMessage,
|
|
124
124
|
});
|
|
125
125
|
if (rest.type === "async") {
|
|
126
|
-
return (react_1.default.createElement(async_1.default, Object.assign({ className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
|
|
126
|
+
return (react_1.default.createElement(async_1.default, Object.assign({ ref: selectRef, className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
|
|
127
127
|
}
|
|
128
128
|
if (rest.type === "creatable") {
|
|
129
|
-
return (react_1.default.createElement(creatable_1.default, Object.assign({ className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
|
|
129
|
+
return (react_1.default.createElement(creatable_1.default, Object.assign({ ref: selectRef, className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
|
|
130
130
|
}
|
|
131
|
-
return (react_1.default.createElement(react_select_1.default, Object.assign({ className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
|
|
131
|
+
return (react_1.default.createElement(react_select_1.default, Object.assign({ ref: selectRef, className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
|
|
132
132
|
};
|
|
133
133
|
const SelectAsync = (props) => {
|
|
134
134
|
return react_1.default.createElement(SelectBase, Object.assign({}, props, { type: "async" }));
|