@synerise/ds-utils 1.7.0 → 1.7.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/CHANGELOG.md +4 -0
- package/dist/doubleClickListener/doubleClickListener.d.ts +1 -1
- package/dist/doubleClickListener/doubleClickListener.js +8 -9
- package/dist/focusWithArrowKeys/focusWithArrowKeys.d.ts +1 -1
- package/dist/focusWithArrowKeys/focusWithArrowKeys.js +24 -22
- package/dist/getInitials/getInitials.js +7 -11
- package/dist/getPopupContainer/getPopupContainer.js +9 -5
- package/dist/getPopupContainer/index.js +5 -1
- package/dist/hexToRgba/hexToRgba.js +8 -6
- package/dist/index.js +64 -28
- package/dist/modules.d.js +1 -0
- package/dist/modules.d.ts +1 -0
- package/dist/omitKeys/omitKeys.js +4 -6
- package/dist/regex/regex.js +3 -3
- package/dist/renderWithHighlight/renderWithHighlight.d.ts +1 -1
- package/dist/renderWithHighlight/renderWithHighlight.js +13 -20
- package/dist/selectColorByLetter/selectColorByLetter.js +17 -15
- package/dist/toCamelCase/toCamelCase.js +4 -14
- package/dist/types/types.d.ts +2 -2
- package/dist/types/types.js +1 -1
- package/dist/useBreakpoint/useBreakpoint.js +29 -28
- package/dist/useCombinedRefs/useCombinedRefs.d.ts +1 -1
- package/dist/useCombinedRefs/useCombinedRefs.js +9 -10
- package/dist/useDelimiterEscape/useDelimiterEscape.js +34 -62
- package/dist/useElementInView/useElementInView.d.ts +2 -2
- package/dist/useElementInView/useElementInView.js +16 -17
- package/dist/useIsMounted/useIsMounted.d.ts +1 -1
- package/dist/useIsMounted/useIsMounted.js +9 -6
- package/dist/useKeyboardShortcuts/useKeyboardShortcuts.js +11 -8
- package/dist/useLatestRef/index.js +4 -1
- package/dist/useLatestRef/useLatestRef.d.ts +1 -1
- package/dist/useLatestRef/useLatestRef.js +8 -5
- package/dist/useOnClickOutside/useOnClickOutside.d.ts +1 -1
- package/dist/useOnClickOutside/useOnClickOutside.js +19 -33
- package/dist/useOverscrollBlock/useOverscrollBlock.d.ts +1 -1
- package/dist/useOverscrollBlock/useOverscrollBlock.js +18 -16
- package/dist/usePrevious/usePrevious.js +6 -4
- package/dist/useResize/useResize.d.ts +1 -1
- package/dist/useResize/useResize.js +19 -25
- package/dist/useResizeObserver/useResizeObserver.d.ts +1 -1
- package/dist/useResizeObserver/useResizeObserver.js +16 -16
- package/dist/useResizeToFit/useResizeToFit.d.ts +1 -1
- package/dist/useResizeToFit/useResizeToFit.js +17 -14
- package/dist/useScrollContain/useScrollContain.d.ts +1 -1
- package/dist/useScrollContain/useScrollContain.js +13 -10
- package/dist/useSearchResults/index.js +8 -2
- package/dist/useSearchResults/search.utils.d.ts +1 -1
- package/dist/useSearchResults/search.utils.js +11 -13
- package/dist/useSearchResults/types.js +1 -1
- package/dist/useSearchResults/useSearchResults.d.ts +1 -1
- package/dist/useSearchResults/useSearchResults.js +29 -38
- package/dist/useStableId/useStableId.js +9 -11
- package/dist/useStickyScroll/useStickyScroll.d.ts +1 -1
- package/dist/useStickyScroll/useStickyScroll.js +33 -33
- package/dist/useTraceUpdate/index.js +10 -10
- package/package.json +4 -4
- package/dist/doubleClickListener/__specs__/doubleClickListener.spec.d.ts +0 -1
- package/dist/focusWithArrowKeys/__specs__/focusWithArrowKeys.spec.d.ts +0 -1
- package/dist/getInitials/__specs__/getInitials.spec.d.ts +0 -1
- package/dist/getPopupContainer/getPopupContainer.spec.d.ts +0 -1
- package/dist/regex/__specs__/regex.spec.d.ts +0 -1
- package/dist/selectColorByLetter/selectColorByLetter.spec.d.ts +0 -1
- package/dist/toCamelCase/__specs__/toCamelCase.spec.d.ts +0 -1
- package/dist/useDelimiterEscape/__specs__/useDelimiterEscape.spec.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.7.1](https://github.com/synerise/synerise-design/compare/@synerise/ds-utils@1.7.0...@synerise/ds-utils@1.7.1) (2026-03-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-utils
|
|
9
|
+
|
|
6
10
|
# [1.7.0](https://github.com/synerise/synerise-design/compare/@synerise/ds-utils@1.6.0...@synerise/ds-utils@1.7.0) (2026-03-20)
|
|
7
11
|
|
|
8
12
|
### Features
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { default as React } from 'react';
|
|
2
2
|
declare function doubleClickListener<T>(onClick: (e: React.SyntheticEvent<T>) => void, onDblClick: (e: React.SyntheticEvent<T>) => void, delay?: number): React.ReactEventHandler<T>;
|
|
3
3
|
export default doubleClickListener;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
function doubleClickListener(onClick, onDblClick, delay) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
var timeout;
|
|
7
|
-
return function (event) {
|
|
1
|
+
const DEFAULT_DELAY = 250;
|
|
2
|
+
function doubleClickListener(onClick, onDblClick, delay = DEFAULT_DELAY) {
|
|
3
|
+
let timeout;
|
|
4
|
+
return (event) => {
|
|
8
5
|
if (!timeout) {
|
|
9
|
-
timeout = setTimeout(
|
|
6
|
+
timeout = setTimeout(() => {
|
|
10
7
|
onClick(event);
|
|
11
8
|
timeout = null;
|
|
12
9
|
}, delay);
|
|
@@ -17,4 +14,6 @@ function doubleClickListener(onClick, onDblClick, delay) {
|
|
|
17
14
|
}
|
|
18
15
|
};
|
|
19
16
|
}
|
|
20
|
-
export
|
|
17
|
+
export {
|
|
18
|
+
doubleClickListener as default
|
|
19
|
+
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
const hasFocusableElementInside = (element, query) => {
|
|
2
2
|
return element.querySelectorAll(query).length > 0;
|
|
3
3
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (keyDownEvent.key ===
|
|
4
|
+
const focusWithArrowKeys = (keyDownEvent, focusableItemClass, fallback) => {
|
|
5
|
+
const selector = `.${focusableItemClass}`;
|
|
6
|
+
const focusableElementsNodeList = document.querySelectorAll(selector);
|
|
7
|
+
const focusableElements = Array.from(focusableElementsNodeList);
|
|
8
|
+
const activeElement = document.activeElement;
|
|
9
|
+
const activeElementIndex = focusableElements.indexOf(activeElement);
|
|
10
|
+
const isItemFocused = activeElement && activeElement.classList.contains(focusableItemClass);
|
|
11
|
+
if (keyDownEvent.key === "ArrowDown") {
|
|
12
12
|
keyDownEvent.preventDefault();
|
|
13
|
-
|
|
13
|
+
let elementToFocusOn;
|
|
14
14
|
if (isItemFocused) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const nextSibling = activeElement.nextElementSibling;
|
|
16
|
+
const hasFocusableChildren = hasFocusableElementInside(activeElement, selector);
|
|
17
17
|
elementToFocusOn = nextSibling !== null && hasFocusableChildren ? nextSibling : focusableElements[activeElementIndex + 1];
|
|
18
18
|
} else {
|
|
19
|
-
elementToFocusOn = document.querySelector(
|
|
19
|
+
elementToFocusOn = document.querySelector(`.${focusableItemClass}`);
|
|
20
20
|
}
|
|
21
21
|
if (elementToFocusOn) {
|
|
22
22
|
elementToFocusOn.focus();
|
|
@@ -25,24 +25,26 @@ var focusWithArrowKeys = function focusWithArrowKeys(keyDownEvent, focusableItem
|
|
|
25
25
|
}
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
if (keyDownEvent.key ===
|
|
28
|
+
if (keyDownEvent.key === "ArrowUp") {
|
|
29
29
|
keyDownEvent.preventDefault();
|
|
30
|
-
|
|
30
|
+
let elementToFocusOn;
|
|
31
31
|
if (isItemFocused) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const prevSibling = activeElement.previousElementSibling;
|
|
33
|
+
elementToFocusOn = prevSibling !== null && hasFocusableElementInside(prevSibling, selector) ? prevSibling : focusableElements[activeElementIndex - 1];
|
|
34
34
|
} else {
|
|
35
|
-
|
|
35
|
+
elementToFocusOn = focusableElements[focusableElements.length - 1];
|
|
36
36
|
}
|
|
37
|
-
if (
|
|
38
|
-
|
|
37
|
+
if (elementToFocusOn) {
|
|
38
|
+
elementToFocusOn.focus();
|
|
39
39
|
} else {
|
|
40
40
|
fallback();
|
|
41
41
|
}
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
if (keyDownEvent.key ===
|
|
44
|
+
if (keyDownEvent.key === "Enter") {
|
|
45
45
|
activeElement && activeElement.click();
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
export
|
|
48
|
+
export {
|
|
49
|
+
focusWithArrowKeys as default
|
|
50
|
+
};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var fName = typeof firstname === 'string' ? firstname : '';
|
|
9
|
-
var lName = typeof lastname === 'string' ? lastname : '';
|
|
10
|
-
return ("" + (fName[0] || '') + (lName[0] || '')).toUpperCase();
|
|
1
|
+
const getInitials = (firstname = "", lastname = "") => {
|
|
2
|
+
const fName = typeof firstname === "string" ? firstname : "";
|
|
3
|
+
const lName = typeof lastname === "string" ? lastname : "";
|
|
4
|
+
return `${fName[0] || ""}${lName[0] || ""}`.toUpperCase();
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
getInitials as default
|
|
11
8
|
};
|
|
12
|
-
export default getInitials;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
for (
|
|
1
|
+
function getClosest(elem, selector) {
|
|
2
|
+
for (let node = elem; node && node !== document.body; node = node.parentElement) {
|
|
3
3
|
if (node.matches(selector)) {
|
|
4
4
|
return node;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
return null;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
return trigger instanceof HTMLElement && getClosest(trigger,
|
|
11
|
-
}
|
|
9
|
+
function getPopupContainer(trigger) {
|
|
10
|
+
return trigger instanceof HTMLElement && getClosest(trigger, "[data-popup-container]") || document.body;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
getClosest,
|
|
14
|
+
getPopupContainer
|
|
15
|
+
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return
|
|
1
|
+
const hexToRgba = (hex, alpha) => {
|
|
2
|
+
const r = parseInt(hex.substring(1, 3), 16);
|
|
3
|
+
const g = parseInt(hex.substring(3, 5), 16);
|
|
4
|
+
const b = parseInt(hex.substring(5, 7), 16);
|
|
5
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
hexToRgba as default
|
|
6
9
|
};
|
|
7
|
-
export default hexToRgba;
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { default as default2 } from "./hexToRgba/hexToRgba.js";
|
|
2
|
+
import { default as default3 } from "./toCamelCase/toCamelCase.js";
|
|
3
|
+
import { useOnClickOutside } from "./useOnClickOutside/useOnClickOutside.js";
|
|
4
|
+
import { renderWithHighlight } from "./renderWithHighlight/renderWithHighlight.js";
|
|
5
|
+
import { useStableId } from "./useStableId/useStableId.js";
|
|
6
|
+
import { default as default4 } from "./selectColorByLetter/selectColorByLetter.js";
|
|
7
|
+
import { default as default5 } from "./focusWithArrowKeys/focusWithArrowKeys.js";
|
|
8
|
+
import { default as default6 } from "./regex/regex.js";
|
|
9
|
+
import { default as default7 } from "./doubleClickListener/doubleClickListener.js";
|
|
10
|
+
import { default as default8 } from "./useResize/useResize.js";
|
|
11
|
+
import { default as default9 } from "./useResizeObserver/useResizeObserver.js";
|
|
12
|
+
import { default as default10 } from "./useBreakpoint/useBreakpoint.js";
|
|
13
|
+
import { default as default11 } from "./useCombinedRefs/useCombinedRefs.js";
|
|
14
|
+
import { default as default12 } from "./usePrevious/usePrevious.js";
|
|
15
|
+
import { useIsMounted } from "./useIsMounted/useIsMounted.js";
|
|
16
|
+
import { default as default13 } from "./useElementInView/useElementInView.js";
|
|
17
|
+
import { default as default14 } from "./useOverscrollBlock/useOverscrollBlock.js";
|
|
18
|
+
import { default as default15 } from "./useResizeToFit/useResizeToFit.js";
|
|
19
|
+
import { useScrollContain } from "./useScrollContain/useScrollContain.js";
|
|
20
|
+
import { useStickyScroll } from "./useStickyScroll/useStickyScroll.js";
|
|
21
|
+
import { getActiveTabGroup, getGroupName, isItemInGroup } from "./useSearchResults/search.utils.js";
|
|
22
|
+
import { useSearchResults } from "./useSearchResults/useSearchResults.js";
|
|
23
|
+
import { useKeyboardShortcuts } from "./useKeyboardShortcuts/useKeyboardShortcuts.js";
|
|
24
|
+
import { omitKeys } from "./omitKeys/omitKeys.js";
|
|
25
|
+
import { useTraceUpdate } from "./useTraceUpdate/index.js";
|
|
26
|
+
import { getClosest, getPopupContainer } from "./getPopupContainer/getPopupContainer.js";
|
|
27
|
+
import { useLatestRef } from "./useLatestRef/useLatestRef.js";
|
|
28
|
+
import { useDelimiterEscape } from "./useDelimiterEscape/useDelimiterEscape.js";
|
|
29
|
+
const NOOP = () => {
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
NOOP,
|
|
33
|
+
default7 as doubleClickListener,
|
|
34
|
+
default6 as escapeRegEx,
|
|
35
|
+
default5 as focusWithArrowKeys,
|
|
36
|
+
getActiveTabGroup,
|
|
37
|
+
getClosest,
|
|
38
|
+
getGroupName,
|
|
39
|
+
getPopupContainer,
|
|
40
|
+
default2 as hexToRgba,
|
|
41
|
+
isItemInGroup,
|
|
42
|
+
omitKeys,
|
|
43
|
+
renderWithHighlight,
|
|
44
|
+
default4 as selectColorByLetter,
|
|
45
|
+
default3 as toCamelCase,
|
|
46
|
+
default10 as useBreakpoint,
|
|
47
|
+
default11 as useCombinedRefs,
|
|
48
|
+
useDelimiterEscape,
|
|
49
|
+
default13 as useElementInView,
|
|
50
|
+
useIsMounted,
|
|
51
|
+
useKeyboardShortcuts,
|
|
52
|
+
useLatestRef,
|
|
53
|
+
useOnClickOutside,
|
|
54
|
+
default14 as useOverscrollBlock,
|
|
55
|
+
default12 as usePrevious,
|
|
56
|
+
default8 as useResize,
|
|
57
|
+
default9 as useResizeObserver,
|
|
58
|
+
default15 as useResizeToFit,
|
|
59
|
+
useScrollContain,
|
|
60
|
+
useSearchResults,
|
|
61
|
+
useStableId,
|
|
62
|
+
useStickyScroll,
|
|
63
|
+
useTraceUpdate
|
|
64
|
+
};
|
package/dist/modules.d.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'latinize';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}));
|
|
6
|
-
};
|
|
1
|
+
const omitKeys = (keys, obj) => Object.fromEntries(Object.entries(obj).filter(([key]) => !keys.includes(key)));
|
|
2
|
+
export {
|
|
3
|
+
omitKeys
|
|
4
|
+
};
|
package/dist/regex/regex.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
export declare const renderWithHighlight: (name: string, highlight?: string, className?: string, testId?: string) => ReactNode;
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import escapeRegEx from
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
className = 'string-highlight';
|
|
6
|
-
}
|
|
7
|
-
if (testId === void 0) {
|
|
8
|
-
testId = 'string-highlight';
|
|
9
|
-
}
|
|
10
|
-
if (!highlight || highlight === '') {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import escapeRegEx from "../regex/regex.js";
|
|
3
|
+
const renderWithHighlight = (name, highlight, className = "string-highlight", testId = "string-highlight") => {
|
|
4
|
+
if (!highlight || highlight === "") {
|
|
11
5
|
return name;
|
|
12
6
|
}
|
|
13
|
-
|
|
7
|
+
const index = name.toLocaleLowerCase().indexOf(highlight.toLocaleLowerCase());
|
|
14
8
|
if (index === -1) {
|
|
15
9
|
return name;
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
key: name,
|
|
22
|
-
className: className,
|
|
23
|
-
"data-testid": testId
|
|
24
|
-
}, name.substring(startOfQuery, endOfQuery)), name.substring(endOfQuery, name.length)];
|
|
11
|
+
const escapedHighlight = escapeRegEx(highlight);
|
|
12
|
+
const startOfQuery = name.toLocaleLowerCase().search(escapedHighlight.toLowerCase());
|
|
13
|
+
const endOfQuery = startOfQuery + highlight.length;
|
|
14
|
+
const resultArray = [name.substring(0, startOfQuery), /* @__PURE__ */ jsx("span", { className, "data-testid": testId, children: name.substring(startOfQuery, endOfQuery) }, name), name.substring(endOfQuery, name.length)];
|
|
25
15
|
return resultArray;
|
|
26
|
-
};
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
renderWithHighlight
|
|
19
|
+
};
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import latinize from
|
|
2
|
-
import { theme } from
|
|
3
|
-
|
|
1
|
+
import latinize from "latinize";
|
|
2
|
+
import { theme } from "@synerise/ds-core";
|
|
3
|
+
const palette = ["blue", "cyan", "fern", "green", "orange", "yellow", "red", "mars", "pink", "violet", "purple"];
|
|
4
4
|
function getColorByLetter() {
|
|
5
|
-
|
|
6
|
-
for (
|
|
5
|
+
const colors = {};
|
|
6
|
+
for (let i = 0; i <= 25; i += 1) {
|
|
7
7
|
colors[String.fromCharCode(i + 65)] = palette[i % palette.length];
|
|
8
8
|
}
|
|
9
9
|
return colors;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const colorByLetter = getColorByLetter();
|
|
12
|
+
function getColor(colorString, forAvatar) {
|
|
13
13
|
if (!forAvatar) {
|
|
14
14
|
return theme.palette[colorString];
|
|
15
15
|
}
|
|
16
16
|
return {
|
|
17
|
-
color: colorString.split(
|
|
18
|
-
hue: colorString.split(
|
|
17
|
+
color: colorString.split("-")[0],
|
|
18
|
+
hue: colorString.split("-")[1]
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function selectColorByLetter(letter, forAvatar) {
|
|
22
|
-
|
|
23
|
-
forAvatar = false;
|
|
24
|
-
}
|
|
25
|
-
return typeof letter !== 'string' ? getColor('orange-500', forAvatar) : getColor((colorByLetter[latinize(letter.toUpperCase())] || 'orange') + "-500", forAvatar);
|
|
21
|
+
function selectColorByLetter(letter, forAvatar = false) {
|
|
22
|
+
return typeof letter !== "string" ? getColor("orange-500", forAvatar) : getColor(`${colorByLetter[latinize(letter.toUpperCase())] || "orange"}-500`, forAvatar);
|
|
26
23
|
}
|
|
27
|
-
export
|
|
24
|
+
export {
|
|
25
|
+
colorByLetter,
|
|
26
|
+
selectColorByLetter as default,
|
|
27
|
+
getColor,
|
|
28
|
+
palette
|
|
29
|
+
};
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// Removes any non alphanumeric characters
|
|
6
|
-
.replace(/[^\w\s]/g, '')
|
|
7
|
-
// Uppercases the first character in each group immediately following a space
|
|
8
|
-
// (delimited by spaces)
|
|
9
|
-
.replace(/ (.)/g, function ($1) {
|
|
10
|
-
return $1.toUpperCase();
|
|
11
|
-
})
|
|
12
|
-
// Removes spaces
|
|
13
|
-
.replace(/ /g, '');
|
|
14
|
-
});
|
|
1
|
+
const toCamelCase = (str) => str.toLowerCase().replace(/[-_]+/g, " ").replace(/[^\w\s]/g, "").replace(/ (.)/g, ($1) => $1.toUpperCase()).replace(/ /g, "");
|
|
2
|
+
export {
|
|
3
|
+
toCamelCase as default
|
|
4
|
+
};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* Allows creating a literal string union type with auto-completion in IDEs
|
|
4
4
|
*/
|
|
@@ -12,7 +12,7 @@ export type ExactlyOne<T, U> = (T & {
|
|
|
12
12
|
[K in keyof T]?: never;
|
|
13
13
|
});
|
|
14
14
|
export type DataAttributes = Record<`data-${string}`, string>;
|
|
15
|
-
export type WithHTMLAttributes<ElementType extends HTMLElement, BaseType
|
|
15
|
+
export type WithHTMLAttributes<ElementType extends HTMLElement, BaseType, ExtendType = HTMLAttributes<ElementType>> = BaseType & Omit<ExtendType, keyof BaseType> & DataAttributes;
|
|
16
16
|
export type DeepPartial<T> = T extends object ? {
|
|
17
17
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
18
18
|
} : T;
|
package/dist/types/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var BREAKPOINTS = {
|
|
1
|
+
import React from "react";
|
|
2
|
+
const BREAKPOINTS = {
|
|
4
3
|
xxl: {
|
|
5
4
|
max: Infinity,
|
|
6
5
|
min: 1601,
|
|
@@ -32,41 +31,43 @@ var BREAKPOINTS = {
|
|
|
32
31
|
columns: 4
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
const useBreakpoint = () => {
|
|
35
|
+
const [dimensions, setDimensions] = React.useState({
|
|
36
|
+
width: 0,
|
|
37
|
+
height: 0
|
|
38
|
+
});
|
|
39
|
+
const updateBreakPoint = React.useMemo(() => {
|
|
40
|
+
const {
|
|
41
|
+
width
|
|
42
|
+
} = dimensions;
|
|
43
|
+
const breakpointKey = Object.keys(BREAKPOINTS).filter((key) => {
|
|
45
44
|
return BREAKPOINTS[key].min <= width && BREAKPOINTS[key].max >= width;
|
|
46
45
|
})[0];
|
|
47
46
|
return {
|
|
48
|
-
breakpoint:
|
|
47
|
+
breakpoint: {
|
|
48
|
+
...BREAKPOINTS[breakpointKey],
|
|
49
49
|
name: breakpointKey
|
|
50
|
-
}
|
|
51
|
-
dimensions
|
|
50
|
+
},
|
|
51
|
+
dimensions
|
|
52
52
|
};
|
|
53
53
|
}, [dimensions]);
|
|
54
|
-
React.useEffect(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
var handleResize = function handleResize() {
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
const getDimensions = () => ({
|
|
56
|
+
width: window.innerWidth,
|
|
57
|
+
height: window.innerHeight
|
|
58
|
+
});
|
|
59
|
+
const handleResize = () => {
|
|
62
60
|
setDimensions(getDimensions());
|
|
63
61
|
};
|
|
64
62
|
setDimensions(getDimensions());
|
|
65
|
-
window.addEventListener(
|
|
66
|
-
return
|
|
67
|
-
window.removeEventListener(
|
|
63
|
+
window.addEventListener("resize", handleResize);
|
|
64
|
+
return () => {
|
|
65
|
+
window.removeEventListener("resize", handleResize);
|
|
68
66
|
};
|
|
69
67
|
}, [setDimensions]);
|
|
70
68
|
return updateBreakPoint;
|
|
71
69
|
};
|
|
72
|
-
export
|
|
70
|
+
export {
|
|
71
|
+
useBreakpoint as default,
|
|
72
|
+
useBreakpoint
|
|
73
|
+
};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var targetRef = React.useRef(null);
|
|
7
|
-
React.useEffect(function () {
|
|
8
|
-
refs.forEach(function (ref) {
|
|
1
|
+
import React from "react";
|
|
2
|
+
const useCombinedRefs = (...refs) => {
|
|
3
|
+
const targetRef = React.useRef(null);
|
|
4
|
+
React.useEffect(() => {
|
|
5
|
+
refs.forEach((ref) => {
|
|
9
6
|
if (!ref) {
|
|
10
7
|
return;
|
|
11
8
|
}
|
|
12
|
-
if (typeof ref ===
|
|
9
|
+
if (typeof ref === "function") {
|
|
13
10
|
ref(targetRef.current);
|
|
14
11
|
} else {
|
|
15
12
|
ref.current = targetRef.current;
|
|
@@ -18,4 +15,6 @@ var useCombinedRefs = function useCombinedRefs() {
|
|
|
18
15
|
}, [refs]);
|
|
19
16
|
return targetRef;
|
|
20
17
|
};
|
|
21
|
-
export
|
|
18
|
+
export {
|
|
19
|
+
useCombinedRefs as default
|
|
20
|
+
};
|