reshaped 3.10.0-canary.6 → 3.10.0-canary.7
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/dist/bundle.d.ts +4 -11
- package/dist/bundle.js +2 -2
- package/dist/components/Accordion/Accordion.types.d.ts +3 -2
- package/dist/components/Accordion/AccordionControlled.js +1 -2
- package/dist/components/Accordion/AccordionTrigger.js +1 -1
- package/dist/components/ActionBar/ActionBar.js +1 -1
- package/dist/components/ActionBar/ActionBar.types.d.ts +3 -2
- package/dist/components/Actionable/Actionable.d.ts +2 -2
- package/dist/components/Actionable/Actionable.js +1 -1
- package/dist/components/Actionable/Actionable.types.d.ts +1 -1
- package/dist/components/Actionable/index.d.ts +1 -1
- package/dist/components/Alert/Alert.types.d.ts +3 -2
- package/dist/components/Autocomplete/Autocomplete.js +1 -3
- package/dist/components/Avatar/Avatar.js +1 -1
- package/dist/components/Avatar/Avatar.types.d.ts +5 -4
- package/dist/components/Badge/Badge.js +1 -1
- package/dist/components/Badge/Badge.types.d.ts +4 -4
- package/dist/components/Badge/BadgeContainer.js +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.types.d.ts +3 -3
- package/dist/components/Button/Button.js +1 -1
- package/dist/components/Button/Button.types.d.ts +3 -2
- package/dist/components/Button/ButtonGroup.js +1 -1
- package/dist/components/Calendar/CalendarDate.js +1 -1
- package/dist/components/Calendar/useCalendarKeyboardNavigation.js +1 -1
- package/dist/components/Card/Card.d.ts +6 -14
- package/dist/components/Card/Card.js +1 -1
- package/dist/components/Card/Card.types.d.ts +4 -3
- package/dist/components/Carousel/Carousel.js +2 -4
- package/dist/components/Carousel/Carousel.types.d.ts +3 -2
- package/dist/components/Carousel/CarouselControl.js +1 -2
- package/dist/components/Checkbox/Checkbox.js +1 -2
- package/dist/components/Checkbox/Checkbox.types.d.ts +4 -3
- package/dist/components/Container/Container.js +1 -1
- package/dist/components/Container/Container.types.d.ts +3 -2
- package/dist/components/ContextMenu/ContextMenu.js +1 -2
- package/dist/components/Dismissible/Dismissible.js +1 -1
- package/dist/components/Dismissible/Dismissible.types.d.ts +3 -3
- package/dist/components/Divider/Divider.js +1 -1
- package/dist/components/Divider/Divider.types.d.ts +3 -2
- package/dist/components/DropdownMenu/DropdownMenu.js +1 -3
- package/dist/components/FileUpload/FileUpload.js +1 -2
- package/dist/components/FileUpload/FileUpload.types.d.ts +4 -3
- package/dist/components/Flyout/Flyout.types.d.ts +6 -6
- package/dist/components/Flyout/FlyoutContent.js +1 -2
- package/dist/components/Flyout/FlyoutControlled.js +2 -6
- package/dist/components/Flyout/useFlyout.d.ts +2 -2
- package/dist/components/Flyout/useFlyout.js +2 -2
- package/dist/components/Flyout/utilities/safeArea.d.ts +2 -2
- package/dist/components/Grid/Grid.js +1 -1
- package/dist/components/Grid/Grid.types.d.ts +5 -4
- package/dist/components/Hidden/Hidden.js +1 -1
- package/dist/components/HiddenInput/HiddenInput.js +1 -1
- package/dist/components/HiddenInput/HiddenInput.types.d.ts +3 -2
- package/dist/components/Hotkey/Hotkey.js +1 -1
- package/dist/components/Hotkey/Hotkey.types.d.ts +3 -3
- package/dist/components/Icon/Icon.js +1 -1
- package/dist/components/Icon/Icon.types.d.ts +3 -2
- package/dist/components/Image/Image.js +1 -1
- package/dist/components/Image/Image.types.d.ts +5 -4
- package/dist/components/Link/Link.js +1 -1
- package/dist/components/Loader/Loader.js +1 -1
- package/dist/components/Loader/Loader.types.d.ts +3 -2
- package/dist/components/MenuItem/MenuItem.js +1 -1
- package/dist/components/MenuItem/MenuItem.types.d.ts +3 -2
- package/dist/components/Modal/Modal.js +2 -3
- package/dist/components/Modal/Modal.types.d.ts +4 -3
- package/dist/components/NumberField/NumberFieldControlled.js +1 -2
- package/dist/components/Overlay/Overlay.js +4 -10
- package/dist/components/Overlay/Overlay.types.d.ts +3 -3
- package/dist/components/Pagination/Pagination.types.d.ts +3 -3
- package/dist/components/PinField/PinField.types.d.ts +4 -3
- package/dist/components/PinField/PinFieldControlled.js +1 -1
- package/dist/components/Popover/Popover.js +1 -1
- package/dist/components/Progress/Progress.js +1 -1
- package/dist/components/Progress/Progress.types.d.ts +3 -3
- package/dist/components/ProgressIndicator/ProgressIndicator.js +1 -1
- package/dist/components/ProgressIndicator/ProgressIndicator.types.d.ts +3 -3
- package/dist/components/Radio/Radio.js +1 -1
- package/dist/components/Radio/Radio.types.d.ts +4 -3
- package/dist/components/RadioGroup/RadioGroup.types.d.ts +3 -2
- package/dist/components/Reshaped/Reshaped.js +4 -11
- package/dist/components/Reshaped/Reshaped.types.d.ts +3 -2
- package/dist/components/Resizable/Resizable.js +1 -1
- package/dist/components/Resizable/ResizableHandle.js +1 -1
- package/dist/components/Scrim/Scrim.js +1 -1
- package/dist/components/Scrim/Scrim.types.d.ts +4 -4
- package/dist/components/ScrollArea/ScrollArea.js +2 -4
- package/dist/components/ScrollArea/ScrollArea.types.d.ts +5 -3
- package/dist/components/Select/Select.types.d.ts +5 -4
- package/dist/components/Select/SelectNative.js +1 -1
- package/dist/components/Select/SelectRoot.js +1 -1
- package/dist/components/Skeleton/Skeleton.js +1 -1
- package/dist/components/Skeleton/Skeleton.types.d.ts +3 -3
- package/dist/components/Slider/Slider.types.d.ts +3 -3
- package/dist/components/Slider/SliderControlled.js +2 -4
- package/dist/components/Slider/SliderThumb.js +1 -1
- package/dist/components/Stepper/Stepper.types.d.ts +5 -4
- package/dist/components/Switch/Switch.js +1 -1
- package/dist/components/Switch/Switch.types.d.ts +4 -3
- package/dist/components/Table/Table.js +1 -1
- package/dist/components/Table/Table.types.d.ts +12 -12
- package/dist/components/Tabs/Tabs.types.d.ts +6 -6
- package/dist/components/Tabs/TabsItem.js +2 -3
- package/dist/components/Tabs/TabsList.js +1 -4
- package/dist/components/Tabs/TabsPanel.js +2 -2
- package/dist/components/Text/Text.js +1 -1
- package/dist/components/Text/Text.types.d.ts +3 -2
- package/dist/components/TextArea/TextArea.js +1 -1
- package/dist/components/TextArea/TextArea.types.d.ts +5 -4
- package/dist/components/TextField/TextField.js +1 -1
- package/dist/components/TextField/TextField.types.d.ts +4 -3
- package/dist/components/Theme/GlobalColorMode.js +1 -1
- package/dist/components/Theme/Theme.js +1 -2
- package/dist/components/Theme/Theme.types.d.ts +2 -1
- package/dist/components/Timeline/Timeline.js +1 -1
- package/dist/components/Timeline/Timeline.types.d.ts +5 -5
- package/dist/components/Toast/Toast.types.d.ts +3 -3
- package/dist/components/Toast/ToastContainer.js +2 -3
- package/dist/components/Toast/ToastRegion.js +2 -2
- package/dist/components/ToggleButton/ToggleButtonUncontrolled.js +1 -1
- package/dist/components/ToggleButtonGroup/ToggleButtonGroupControlled.js +1 -1
- package/dist/components/View/View.js +1 -1
- package/dist/components/View/View.types.d.ts +5 -4
- package/dist/components/_private/Aligner/Aligner.js +1 -1
- package/dist/components/_private/Aligner/Aligner.types.d.ts +3 -3
- package/dist/components/_private/Expandable/Expandable.js +2 -2
- package/dist/components/_private/Expandable/Expandable.types.d.ts +2 -2
- package/dist/components/_private/Portal/Portal.js +1 -2
- package/dist/hooks/_private/useDrag.js +2 -4
- package/dist/hooks/_private/useFadeSide.js +2 -3
- package/dist/hooks/_private/useSingletonViewport.d.ts +10 -0
- package/dist/hooks/_private/useSingletonViewport.js +52 -0
- package/dist/hooks/useResponsiveClientValue.js +15 -53
- package/dist/hooks/useViewport.d.ts +2 -0
- package/dist/hooks/useViewport.js +6 -0
- package/dist/index.d.ts +4 -11
- package/dist/index.js +2 -10
- package/dist/styles/mixin.d.ts +2 -2
- package/dist/styles/types.d.ts +2 -1
- package/dist/tests/ThemesPlayground.js +1 -1
- package/dist/types/global.d.ts +0 -15
- package/dist/utilities/props.d.ts +2 -1
- package/package.json +2 -2
- package/dist/core/Actionable/Actionable.d.ts +0 -4
- package/dist/core/Actionable/Actionable.js +0 -73
- package/dist/core/Actionable/Actionable.types.d.ts +0 -34
- package/dist/core/Actionable/Actionable.types.js +0 -1
- package/dist/core/Actionable/index.d.ts +0 -2
- package/dist/core/Actionable/index.js +0 -1
- package/dist/hooks/_private/useSingletonEnvironment.d.ts +0 -9
- package/dist/hooks/_private/useSingletonEnvironment.js +0 -33
- package/dist/hooks/_private/useSingletonHotkeys.d.ts +0 -35
- package/dist/hooks/_private/useSingletonHotkeys.js +0 -191
- package/dist/hooks/_private/useSingletonKeyboardMode.d.ts +0 -13
- package/dist/hooks/_private/useSingletonKeyboardMode.js +0 -58
- package/dist/hooks/useHandlerRef.d.ts +0 -8
- package/dist/hooks/useHandlerRef.js +0 -16
- package/dist/hooks/useHotkeys.d.ts +0 -11
- package/dist/hooks/useHotkeys.js +0 -27
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +0 -3
- package/dist/hooks/useIsomorphicLayoutEffect.js +0 -4
- package/dist/hooks/useKeyboardArrowNavigation.d.ts +0 -9
- package/dist/hooks/useKeyboardArrowNavigation.js +0 -62
- package/dist/hooks/useKeyboardMode.d.ts +0 -7
- package/dist/hooks/useKeyboardMode.js +0 -13
- package/dist/hooks/useOnClickOutside.d.ts +0 -5
- package/dist/hooks/useOnClickOutside.js +0 -63
- package/dist/hooks/useRTL.d.ts +0 -2
- package/dist/hooks/useRTL.js +0 -7
- package/dist/hooks/useScrollLock.d.ts +0 -10
- package/dist/hooks/useScrollLock.js +0 -25
- package/dist/hooks/useToggle.d.ts +0 -7
- package/dist/hooks/useToggle.js +0 -19
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Attributes, ClassName } from "@reshaped/headless";
|
|
1
2
|
import type React from "react";
|
|
2
3
|
import type * as TStyles from "../../styles/types";
|
|
3
4
|
import type * as G from "../../types/global";
|
|
@@ -93,9 +94,9 @@ export type Props<TagName extends keyof React.JSX.IntrinsicElements | void = voi
|
|
|
93
94
|
/** Add transition for the properties */
|
|
94
95
|
animated?: boolean;
|
|
95
96
|
/** Additional classname for the root element */
|
|
96
|
-
className?:
|
|
97
|
+
className?: ClassName;
|
|
97
98
|
/** Additional attributes for the root element */
|
|
98
|
-
attributes?:
|
|
99
|
+
attributes?: Attributes<TagName>;
|
|
99
100
|
} & Pick<ItemProps, "grow" | "shrink">;
|
|
100
101
|
export type ItemProps<TagName extends keyof React.JSX.IntrinsicElements | void = void> = {
|
|
101
102
|
/** Flex order of the item inside the parent */
|
|
@@ -111,9 +112,9 @@ export type ItemProps<TagName extends keyof React.JSX.IntrinsicElements | void =
|
|
|
111
112
|
/** Render as a different element */
|
|
112
113
|
as?: TagName extends keyof React.JSX.IntrinsicElements ? TagName : keyof React.JSX.IntrinsicElements;
|
|
113
114
|
/** Additional attributes for the root element */
|
|
114
|
-
attributes?:
|
|
115
|
+
attributes?: Attributes<TagName>;
|
|
115
116
|
/** Additional classname for the root element */
|
|
116
|
-
className?:
|
|
117
|
+
className?: ClassName;
|
|
117
118
|
/** Node for inserting the item content */
|
|
118
119
|
children?: React.ReactNode;
|
|
119
120
|
};
|
|
@@ -7,7 +7,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
7
7
|
* It relies on using a data-rs-aligner-target attribute in other components and works based
|
|
8
8
|
* on the --rs-p, --rs-p-v and --rs-p-h css variables
|
|
9
9
|
*/
|
|
10
|
-
import { classNames } from "@reshaped/
|
|
10
|
+
import { classNames } from "@reshaped/headless";
|
|
11
11
|
import s from "./Aligner.module.css";
|
|
12
12
|
const Aligner = (props) => {
|
|
13
13
|
const { side: passedSide = "all", children, className, attributes } = props;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { ClassName, Attributes } from "@reshaped/headless";
|
|
2
2
|
type Side = "start" | "end" | "top" | "bottom" | "inline" | "block" | "all";
|
|
3
3
|
export type Props = {
|
|
4
4
|
/** Node for inserting children components */
|
|
@@ -8,8 +8,8 @@ export type Props = {
|
|
|
8
8
|
*/
|
|
9
9
|
side?: Side | Side[];
|
|
10
10
|
/** Additional classname for the root element */
|
|
11
|
-
className?:
|
|
11
|
+
className?: ClassName;
|
|
12
12
|
/** Additional attributes for the root element */
|
|
13
|
-
attributes?:
|
|
13
|
+
attributes?: Attributes<"div">;
|
|
14
14
|
};
|
|
15
15
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { useIsomorphicLayoutEffect } from "@reshaped/headless";
|
|
4
|
+
import { classNames } from "@reshaped/headless";
|
|
4
5
|
import React from "react";
|
|
5
|
-
import useIsomorphicLayoutEffect from "../../../hooks/useIsomorphicLayoutEffect.js";
|
|
6
6
|
import { onNextFrame } from "../../../utilities/animation.js";
|
|
7
7
|
import s from "./Expandable.module.css";
|
|
8
8
|
const Expandable = (props) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
2
|
+
import type { Attributes } from "@reshaped/headless";
|
|
3
3
|
export type ContentProps = {
|
|
4
4
|
active?: boolean;
|
|
5
5
|
children?: React.ReactNode;
|
|
6
|
-
attributes?:
|
|
6
|
+
attributes?: Attributes<"div">;
|
|
7
7
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useIsomorphicLayoutEffect, useToggle } from "@reshaped/headless";
|
|
3
4
|
import React from "react";
|
|
4
5
|
import ReactDOM from "react-dom";
|
|
5
6
|
import Theme from "../../Theme/index.js";
|
|
6
|
-
import useIsomorphicLayoutEffect from "../../../hooks/useIsomorphicLayoutEffect.js";
|
|
7
|
-
import useToggle from "../../../hooks/useToggle.js";
|
|
8
7
|
import s from "./Portal.module.css";
|
|
9
8
|
const PortalScopeContext = React.createContext({});
|
|
10
9
|
export const usePortalScope = () => {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useHotkeys, useHandlerRef, useToggle } from "@reshaped/headless";
|
|
3
|
+
import { disableScroll, enableScroll } from "@reshaped/headless/internal";
|
|
3
4
|
import React from "react";
|
|
4
5
|
import * as keys from "../../constants/keys.js";
|
|
5
|
-
import useHandlerRef from "../useHandlerRef.js";
|
|
6
|
-
import useHotkeys from "../useHotkeys.js";
|
|
7
|
-
import useToggle from "../useToggle.js";
|
|
8
6
|
const useDrag = (cb, options) => {
|
|
9
7
|
const { disabled, containerRef: passedContainerRef, orientation = "all" } = options || {};
|
|
10
8
|
const cbRef = useHandlerRef(cb);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useIsomorphicLayoutEffect, useRTL } from "@reshaped/headless";
|
|
3
|
+
import { rafThrottle } from "@reshaped/headless/internal";
|
|
3
4
|
import React from "react";
|
|
4
|
-
import useIsomorphicLayoutEffect from "../useIsomorphicLayoutEffect.js";
|
|
5
|
-
import useRTL from "../useRTL.js";
|
|
6
5
|
const useFadeSide = (scrollableRef, options = {}) => {
|
|
7
6
|
const { disabled } = options;
|
|
8
7
|
const [rtl] = useRTL();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type * as G from "../../types/global";
|
|
3
|
+
export declare const SingletonViewportProvider: React.FC<{
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
defaultViewport?: G.Viewport;
|
|
6
|
+
}>;
|
|
7
|
+
declare const useSingletonViewport: () => {
|
|
8
|
+
viewport: G.Viewport;
|
|
9
|
+
};
|
|
10
|
+
export default useSingletonViewport;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useIsomorphicLayoutEffect } from "@reshaped/headless";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import defaultBreakpoints from "../../constants/breakpoints.js";
|
|
6
|
+
const SingletonViewportContext = React.createContext({
|
|
7
|
+
viewport: "s",
|
|
8
|
+
});
|
|
9
|
+
export const SingletonViewportProvider = (props) => {
|
|
10
|
+
const { children, defaultViewport = "s" } = props;
|
|
11
|
+
const [viewport, setViewport] = React.useState(defaultViewport);
|
|
12
|
+
useIsomorphicLayoutEffect(() => {
|
|
13
|
+
const rootThemeEl = document.querySelector("[data-rs-theme]");
|
|
14
|
+
const rootStyle = rootThemeEl && window.getComputedStyle(rootThemeEl);
|
|
15
|
+
/**
|
|
16
|
+
* We generate variables for the viewport breakpoints in the themes
|
|
17
|
+
* We use them here in case they're custom and fallback to the default values
|
|
18
|
+
* in case there is no SSR passing the data-rs-theme attribute
|
|
19
|
+
*/
|
|
20
|
+
const breakpoints = {
|
|
21
|
+
m: (rootStyle && Number(rootStyle.getPropertyValue("--rs-viewport-m-min"))) ||
|
|
22
|
+
defaultBreakpoints.m,
|
|
23
|
+
l: (rootStyle && Number(rootStyle.getPropertyValue("--rs-viewport-l-min"))) ||
|
|
24
|
+
defaultBreakpoints.l,
|
|
25
|
+
xl: (rootStyle && Number(rootStyle.getPropertyValue("--rs-viewport-xl-min"))) ||
|
|
26
|
+
defaultBreakpoints.xl,
|
|
27
|
+
};
|
|
28
|
+
const mediaQueries = {
|
|
29
|
+
s: `(max-width: ${breakpoints.m - 1}px)`,
|
|
30
|
+
m: `(min-width: ${breakpoints.m}px) and (max-width: ${breakpoints.l - 1}px)`,
|
|
31
|
+
l: `(min-width: ${breakpoints.l}px) and (max-width: ${breakpoints.xl - 1}px)`,
|
|
32
|
+
xl: `(min-width: ${breakpoints.xl}px)`,
|
|
33
|
+
};
|
|
34
|
+
const viewports = Object.keys(mediaQueries);
|
|
35
|
+
const matchers = viewports.map((viewport) => {
|
|
36
|
+
const mq = window.matchMedia(mediaQueries[viewport]);
|
|
37
|
+
return { mq, handler: () => mq.matches && setViewport(viewport) };
|
|
38
|
+
});
|
|
39
|
+
matchers.forEach(({ handler, mq }) => {
|
|
40
|
+
handler();
|
|
41
|
+
mq.addEventListener("change", handler);
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
matchers.forEach(({ handler, mq }) => {
|
|
45
|
+
mq.removeEventListener("change", handler);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
return (_jsx(SingletonViewportContext.Provider, { value: { viewport }, children: children }));
|
|
50
|
+
};
|
|
51
|
+
const useSingletonViewport = () => React.useContext(SingletonViewportContext);
|
|
52
|
+
export default useSingletonViewport;
|
|
@@ -1,57 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { SingletonEnvironmentContext } from "./_private/useSingletonEnvironment.js";
|
|
5
|
-
import useIsomorphicLayoutEffect from "./useIsomorphicLayoutEffect.js";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import useViewport from "./useViewport.js";
|
|
6
4
|
const useResponsiveClientValue = (value) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
l: (rootStyle && Number(rootStyle.getPropertyValue("--rs-viewport-l-min"))) ||
|
|
21
|
-
defaultBreakpoints.l,
|
|
22
|
-
xl: (rootStyle && Number(rootStyle.getPropertyValue("--rs-viewport-xl-min"))) ||
|
|
23
|
-
defaultBreakpoints.xl,
|
|
24
|
-
};
|
|
25
|
-
const mediaQueries = {
|
|
26
|
-
s: `(max-width: ${breakpoints.m - 1}px)`,
|
|
27
|
-
m: `(min-width: ${breakpoints.m}px) and (max-width: ${breakpoints.l - 1}px)`,
|
|
28
|
-
l: `(min-width: ${breakpoints.l}px) and (max-width: ${breakpoints.xl - 1}px)`,
|
|
29
|
-
xl: `(min-width: ${breakpoints.xl}px)`,
|
|
30
|
-
};
|
|
31
|
-
const viewports = Object.keys(mediaQueries);
|
|
32
|
-
const matchers = viewports.map((viewport) => {
|
|
33
|
-
const mq = window.matchMedia(mediaQueries[viewport]);
|
|
34
|
-
return { mq, handler: () => mq.matches && setViewport(viewport) };
|
|
35
|
-
});
|
|
36
|
-
matchers.forEach(({ handler, mq }) => {
|
|
37
|
-
handler();
|
|
38
|
-
mq.addEventListener("change", handler);
|
|
39
|
-
});
|
|
40
|
-
return () => {
|
|
41
|
-
matchers.forEach(({ handler, mq }) => {
|
|
42
|
-
mq.removeEventListener("change", handler);
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
}, []);
|
|
46
|
-
if (typeof value !== "object" || value === null || !("s" in value)) {
|
|
47
|
-
return value;
|
|
48
|
-
}
|
|
49
|
-
if (viewport === "xl")
|
|
50
|
-
return value.xl ?? value.l ?? value.m ?? value.s;
|
|
51
|
-
if (viewport === "l")
|
|
52
|
-
return value.l ?? value.m ?? value.s;
|
|
53
|
-
if (viewport === "m")
|
|
54
|
-
return value.m ?? value.s;
|
|
55
|
-
return value.s;
|
|
5
|
+
const viewport = useViewport();
|
|
6
|
+
return useMemo(() => {
|
|
7
|
+
if (typeof value !== "object" || value === null || !("s" in value)) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
if (viewport === "xl")
|
|
11
|
+
return value.xl ?? value.l ?? value.m ?? value.s;
|
|
12
|
+
if (viewport === "l")
|
|
13
|
+
return value.l ?? value.m ?? value.s;
|
|
14
|
+
if (viewport === "m")
|
|
15
|
+
return value.m ?? value.s;
|
|
16
|
+
return value.s;
|
|
17
|
+
}, [viewport, value]);
|
|
56
18
|
};
|
|
57
19
|
export default useResponsiveClientValue;
|
package/dist/index.d.ts
CHANGED
|
@@ -131,28 +131,21 @@ export type { ViewProps, ViewItemProps } from "./components/View";
|
|
|
131
131
|
/**
|
|
132
132
|
* Hooks
|
|
133
133
|
*/
|
|
134
|
+
export { useHotkeys, useIsomorphicLayoutEffect, useRTL, useKeyboardArrowNavigation, useKeyboardMode, useHandlerRef, useOnClickOutside, useScrollLock, useToggle, } from "@reshaped/headless";
|
|
134
135
|
export { useFormControl } from "./components/FormControl";
|
|
135
136
|
export { default as Theme, useTheme, type ThemeProps } from "./components/Theme";
|
|
136
|
-
export { default as useHandlerRef } from "./hooks/useHandlerRef";
|
|
137
|
-
export { default as useHotkeys } from "./hooks/useHotkeys";
|
|
138
|
-
export { default as useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect";
|
|
139
|
-
export { default as useKeyboardMode } from "./hooks/useKeyboardMode";
|
|
140
|
-
export { default as useKeyboardArrowNavigation } from "./hooks/useKeyboardArrowNavigation";
|
|
141
|
-
export { default as useOnClickOutside } from "./hooks/useOnClickOutside";
|
|
142
137
|
export { default as useResponsiveClientValue } from "./hooks/useResponsiveClientValue";
|
|
143
|
-
export { default as useRTL } from "./hooks/useRTL";
|
|
144
|
-
export { default as useScrollLock } from "./hooks/useScrollLock";
|
|
145
|
-
export { default as useToggle } from "./hooks/useToggle";
|
|
146
138
|
/**
|
|
147
139
|
* Utility functions
|
|
148
140
|
*/
|
|
149
141
|
export { responsivePropDependency } from "./utilities/props";
|
|
150
|
-
export { TrapFocus, classNames } from "@reshaped/
|
|
142
|
+
export { TrapFocus, classNames } from "@reshaped/headless";
|
|
151
143
|
/**
|
|
152
144
|
* Types
|
|
153
145
|
*/
|
|
146
|
+
export type { Attributes } from "@reshaped/headless";
|
|
154
147
|
export type { ReshapedConfig } from "./types/config";
|
|
155
|
-
export type { Responsive,
|
|
148
|
+
export type { Responsive, ColorMode } from "./types/global";
|
|
156
149
|
/**
|
|
157
150
|
* Dev utilities
|
|
158
151
|
*/
|
package/dist/index.js
CHANGED
|
@@ -69,23 +69,15 @@ export { default as View } from "./components/View/index.js";
|
|
|
69
69
|
/**
|
|
70
70
|
* Hooks
|
|
71
71
|
*/
|
|
72
|
+
export { useHotkeys, useIsomorphicLayoutEffect, useRTL, useKeyboardArrowNavigation, useKeyboardMode, useHandlerRef, useOnClickOutside, useScrollLock, useToggle, } from "@reshaped/headless";
|
|
72
73
|
export { useFormControl } from "./components/FormControl/index.js";
|
|
73
74
|
export { default as Theme, useTheme } from "./components/Theme/index.js";
|
|
74
|
-
export { default as useHandlerRef } from "./hooks/useHandlerRef.js";
|
|
75
|
-
export { default as useHotkeys } from "./hooks/useHotkeys.js";
|
|
76
|
-
export { default as useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect.js";
|
|
77
|
-
export { default as useKeyboardMode } from "./hooks/useKeyboardMode.js";
|
|
78
|
-
export { default as useKeyboardArrowNavigation } from "./hooks/useKeyboardArrowNavigation.js";
|
|
79
|
-
export { default as useOnClickOutside } from "./hooks/useOnClickOutside.js";
|
|
80
75
|
export { default as useResponsiveClientValue } from "./hooks/useResponsiveClientValue.js";
|
|
81
|
-
export { default as useRTL } from "./hooks/useRTL.js";
|
|
82
|
-
export { default as useScrollLock } from "./hooks/useScrollLock.js";
|
|
83
|
-
export { default as useToggle } from "./hooks/useToggle.js";
|
|
84
76
|
/**
|
|
85
77
|
* Utility functions
|
|
86
78
|
*/
|
|
87
79
|
export { responsivePropDependency } from "./utilities/props.js";
|
|
88
|
-
export { TrapFocus, classNames } from "@reshaped/
|
|
80
|
+
export { TrapFocus, classNames } from "@reshaped/headless";
|
|
89
81
|
/**
|
|
90
82
|
* Dev utilities
|
|
91
83
|
*/
|
package/dist/styles/mixin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ClassName } from "@reshaped/headless";
|
|
1
2
|
import type { Mixin } from "./types";
|
|
2
|
-
import type * as G from "../types/global";
|
|
3
3
|
export declare const resolveMixin: (mixin: Mixin) => {
|
|
4
4
|
variables: React.CSSProperties;
|
|
5
|
-
classNames:
|
|
5
|
+
classNames: ClassName[];
|
|
6
6
|
};
|
package/dist/styles/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import * as G from "../types/global";
|
|
3
|
+
import type { ClassName } from "@reshaped/headless";
|
|
3
4
|
type Unit = number;
|
|
4
5
|
type Literal = string;
|
|
5
6
|
type Size = Literal | Unit;
|
|
@@ -26,7 +27,7 @@ export type BorderColor = "neutral" | "neutral-faded" | "critical" | "critical-f
|
|
|
26
27
|
*/
|
|
27
28
|
export type StyleResolver<Value> = (value?: G.Responsive<Value>) => {
|
|
28
29
|
variables?: React.CSSProperties;
|
|
29
|
-
classNames?:
|
|
30
|
+
classNames?: ClassName;
|
|
30
31
|
};
|
|
31
32
|
export type Mixin = {
|
|
32
33
|
align?: G.Responsive<Align>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useToggle } from "@reshaped/headless";
|
|
2
3
|
import React from "react";
|
|
3
4
|
import Alert from "../components/Alert/index.js";
|
|
4
5
|
import Avatar from "../components/Avatar/index.js";
|
|
@@ -18,7 +19,6 @@ import Table from "../components/Table/index.js";
|
|
|
18
19
|
import Text from "../components/Text/index.js";
|
|
19
20
|
import TextField from "../components/TextField/index.js";
|
|
20
21
|
import View from "../components/View/index.js";
|
|
21
|
-
import useToggle from "../hooks/useToggle.js";
|
|
22
22
|
import IconChevronDown from "../icons/ChevronDown.js";
|
|
23
23
|
import IconChevronRight from "../icons/ChevronRight.js";
|
|
24
24
|
import IconZap from "../icons/Zap.js";
|
package/dist/types/global.d.ts
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* DOM
|
|
4
|
-
*/
|
|
5
|
-
type ClassNameValue = string | null | undefined | false;
|
|
6
|
-
export type ClassName = ClassNameValue | ClassNameValue[] | ClassName[];
|
|
7
|
-
export type CSSVariable = `--${string}`;
|
|
8
|
-
export type StyleAttribute = React.CSSProperties | (React.CSSProperties & Record<CSSVariable, string | number | undefined>);
|
|
9
|
-
type DataAttributes = object | Record<`data-${string}`, string | boolean>;
|
|
10
|
-
export type Attributes<TagName extends keyof React.JSX.IntrinsicElements | void = void> = (TagName extends keyof React.JSX.IntrinsicElements ? React.JSX.IntrinsicElements[TagName] : React.HTMLAttributes<HTMLElement>) & DataAttributes & {
|
|
11
|
-
style?: StyleAttribute;
|
|
12
|
-
};
|
|
13
2
|
export type Viewport = "s" | "m" | "l" | "xl";
|
|
14
3
|
export type ResponsiveOnly<T> = {
|
|
15
4
|
[key in Viewport]?: T;
|
|
16
5
|
};
|
|
17
6
|
export type Responsive<T> = T | ResponsiveOnly<T>;
|
|
18
|
-
export type Coordinates = {
|
|
19
|
-
x: number;
|
|
20
|
-
y: number;
|
|
21
|
-
};
|
|
22
7
|
/**
|
|
23
8
|
* Form handlers
|
|
24
9
|
*/
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { CSSVariable } from "@reshaped/headless";
|
|
1
2
|
import type * as G from "../types/global";
|
|
2
3
|
type Value = string | boolean | number | undefined;
|
|
3
4
|
type ClassNameResolver = string | ((value: Value) => string);
|
|
4
5
|
export declare const responsiveClassNames: <V extends G.Responsive<Value>>(s: Record<string, string>, className: ClassNameResolver, value: V, options?: {
|
|
5
6
|
excludeValueFromClassName?: boolean;
|
|
6
7
|
}) => string[];
|
|
7
|
-
export declare const responsiveVariables: <V extends Value = Value>(variableName:
|
|
8
|
+
export declare const responsiveVariables: <V extends Value = Value>(variableName: CSSVariable, value?: G.Responsive<V>) => Record<CSSVariable, V>;
|
|
8
9
|
export declare const responsivePropDependency: <Result, T>(prop: G.Responsive<T>, resolver: (value: T, key: G.Viewport) => Result) => Result;
|
|
9
10
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reshaped",
|
|
3
3
|
"description": "Professionally crafted design system in React & Figma for building products of any scale and complexity",
|
|
4
|
-
"version": "3.10.0-canary.
|
|
4
|
+
"version": "3.10.0-canary.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"email": "hello@reshaped.so",
|
|
7
7
|
"homepage": "https://reshaped.so",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"csstype": "3.1.3",
|
|
92
92
|
"culori": "4.0.2",
|
|
93
93
|
"postcss-custom-media": "11.0.6",
|
|
94
|
-
"@reshaped/
|
|
94
|
+
"@reshaped/headless": "3.10.0-canary.7"
|
|
95
95
|
},
|
|
96
96
|
"scripts": {
|
|
97
97
|
"clean": "bash ./bin/clean.sh",
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { classNames } from "@reshaped/utilities";
|
|
4
|
-
import { forwardRef } from "react";
|
|
5
|
-
import * as keys from "../../constants/keys.js";
|
|
6
|
-
const Actionable = forwardRef((props, ref) => {
|
|
7
|
-
const { children, render, href, onClick, type, disabled, as, stopPropagation, className, attributes, } = props;
|
|
8
|
-
const rootAttributes = { ...attributes };
|
|
9
|
-
const hasClickHandler = onClick || attributes?.onClick;
|
|
10
|
-
const hasFocusHandler = attributes?.onFocus || attributes?.onBlur;
|
|
11
|
-
const isLink = Boolean(href || attributes?.href);
|
|
12
|
-
// Including attributes ref for the cases when event listeners are added through it
|
|
13
|
-
// To make sure it doesn't render a span
|
|
14
|
-
const isButton = Boolean(hasClickHandler || hasFocusHandler || type || attributes?.ref);
|
|
15
|
-
const renderedAsButton = !isLink && isButton && (!as || as === "button");
|
|
16
|
-
// Using any here to let TS save on type resolving, otherwise TS throws an error due to the type complexity
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
let TagName;
|
|
19
|
-
if (isLink) {
|
|
20
|
-
TagName = "a";
|
|
21
|
-
rootAttributes.href = disabled ? undefined : href || attributes?.href;
|
|
22
|
-
}
|
|
23
|
-
else if (renderedAsButton) {
|
|
24
|
-
TagName = "button";
|
|
25
|
-
rootAttributes.type = type || attributes?.type || "button";
|
|
26
|
-
rootAttributes.disabled = disabled || attributes?.disabled;
|
|
27
|
-
}
|
|
28
|
-
else if (isButton) {
|
|
29
|
-
const isFocusable = as === "label";
|
|
30
|
-
const simulateButton = !isFocusable || hasClickHandler || hasFocusHandler;
|
|
31
|
-
TagName = as || "span";
|
|
32
|
-
rootAttributes.role = simulateButton ? "button" : undefined;
|
|
33
|
-
rootAttributes.tabIndex = simulateButton ? 0 : undefined;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
TagName = as || "span";
|
|
37
|
-
}
|
|
38
|
-
const handlePress = (event) => {
|
|
39
|
-
if (disabled)
|
|
40
|
-
return;
|
|
41
|
-
if (stopPropagation)
|
|
42
|
-
event.stopPropagation();
|
|
43
|
-
onClick?.(event);
|
|
44
|
-
attributes?.onClick?.(event);
|
|
45
|
-
};
|
|
46
|
-
const handleKeyDown = (event) => {
|
|
47
|
-
const isSpace = event.key === keys.SPACE;
|
|
48
|
-
const isEnter = event.key === keys.ENTER;
|
|
49
|
-
if (!isSpace && !isEnter)
|
|
50
|
-
return;
|
|
51
|
-
if (rootAttributes.role !== "button")
|
|
52
|
-
return;
|
|
53
|
-
if (stopPropagation)
|
|
54
|
-
event.stopPropagation();
|
|
55
|
-
event.preventDefault();
|
|
56
|
-
handlePress(event);
|
|
57
|
-
};
|
|
58
|
-
const tagAttributes = {
|
|
59
|
-
ref: ref,
|
|
60
|
-
// rootAttributes can receive ref from Flyout
|
|
61
|
-
...rootAttributes,
|
|
62
|
-
className: classNames(className),
|
|
63
|
-
onClick: handlePress,
|
|
64
|
-
onKeyDown: handleKeyDown,
|
|
65
|
-
"aria-disabled": disabled ? true : undefined,
|
|
66
|
-
children: children,
|
|
67
|
-
};
|
|
68
|
-
if (render)
|
|
69
|
-
return render(tagAttributes);
|
|
70
|
-
return _jsx(TagName, { ...tagAttributes });
|
|
71
|
-
});
|
|
72
|
-
Actionable.displayName = "Actionable";
|
|
73
|
-
export default Actionable;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type React from "react";
|
|
2
|
-
import type * as G from "../../types/global";
|
|
3
|
-
export type AttributesRef = React.RefObject<HTMLButtonElement | null>;
|
|
4
|
-
type Attributes = G.Attributes<"button"> & Omit<React.JSX.IntrinsicElements["a"], keyof G.Attributes<"button">> & {
|
|
5
|
-
ref?: AttributesRef;
|
|
6
|
-
};
|
|
7
|
-
export type RenderAttributes = G.Attributes<"a"> & {
|
|
8
|
-
ref: React.RefObject<HTMLAnchorElement | null>;
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
};
|
|
11
|
-
export type Props = {
|
|
12
|
-
/** Node for inserting the content */
|
|
13
|
-
children?: React.ReactNode;
|
|
14
|
-
/** Render a custom root element, useful for integrating with routers */
|
|
15
|
-
render?: (attributes: RenderAttributes) => React.ReactNode;
|
|
16
|
-
/** Callback when clicked, renders it as a button tag if href is not provided */
|
|
17
|
-
onClick?: (e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => void;
|
|
18
|
-
/** URL, renders it as an anchor tag */
|
|
19
|
-
href?: string;
|
|
20
|
-
/** Type attribute, renders it as a button tag */
|
|
21
|
-
type?: React.ButtonHTMLAttributes<HTMLButtonElement>["type"];
|
|
22
|
-
/** Disable from user interaction */
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
/** Prevent the event from bubbling up to the parent */
|
|
25
|
-
stopPropagation?: boolean;
|
|
26
|
-
/** Render as a different element */
|
|
27
|
-
as?: keyof React.JSX.IntrinsicElements;
|
|
28
|
-
/** Additional classname for the root element */
|
|
29
|
-
className?: G.ClassName;
|
|
30
|
-
/** Additional attributes for the root element */
|
|
31
|
-
attributes?: Attributes;
|
|
32
|
-
};
|
|
33
|
-
export type Ref = HTMLButtonElement | HTMLAnchorElement;
|
|
34
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Actionable.js";
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type * as G from "../../types/global";
|
|
3
|
-
type Context = {
|
|
4
|
-
rtl: [boolean, (state: boolean) => void];
|
|
5
|
-
defaultViewport: G.Viewport;
|
|
6
|
-
};
|
|
7
|
-
export declare const SingletonEnvironmentContext: React.Context<Context>;
|
|
8
|
-
export declare const useSingletonEnvironment: (defaultRTL?: boolean) => [boolean, React.Dispatch<React.SetStateAction<boolean>>];
|
|
9
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import useIsomorphicLayoutEffect from "../useIsomorphicLayoutEffect.js";
|
|
3
|
-
export const SingletonEnvironmentContext = React.createContext({
|
|
4
|
-
rtl: [false, () => { }],
|
|
5
|
-
defaultViewport: "s",
|
|
6
|
-
});
|
|
7
|
-
export const useSingletonEnvironment = (defaultRTL) => {
|
|
8
|
-
const state = React.useState(defaultRTL || false);
|
|
9
|
-
const [isRTL, setRTL] = state;
|
|
10
|
-
/**
|
|
11
|
-
* Handle changing dir attribute directly
|
|
12
|
-
*/
|
|
13
|
-
useIsomorphicLayoutEffect(() => {
|
|
14
|
-
const observer = new MutationObserver((mutations) => {
|
|
15
|
-
mutations.forEach((mutation) => {
|
|
16
|
-
if (mutation.attributeName !== "dir")
|
|
17
|
-
return;
|
|
18
|
-
const nextRTL = mutation.target.dir === "rtl";
|
|
19
|
-
if (isRTL !== nextRTL)
|
|
20
|
-
setRTL(nextRTL);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
observer.observe(document.documentElement, { attributes: true });
|
|
24
|
-
return () => observer.disconnect();
|
|
25
|
-
}, [isRTL]);
|
|
26
|
-
/**
|
|
27
|
-
* Handle setRTL usage
|
|
28
|
-
*/
|
|
29
|
-
useIsomorphicLayoutEffect(() => {
|
|
30
|
-
document.documentElement.setAttribute("dir", isRTL ? "rtl" : "ltr");
|
|
31
|
-
}, [isRTL]);
|
|
32
|
-
return state;
|
|
33
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* Types
|
|
4
|
-
*/
|
|
5
|
-
type Callback = (e?: KeyboardEvent) => void;
|
|
6
|
-
type PressedMap = Map<string, KeyboardEvent>;
|
|
7
|
-
export type Hotkeys = Record<string, Callback | null>;
|
|
8
|
-
type HotkeyOptions = {
|
|
9
|
-
preventDefault?: boolean;
|
|
10
|
-
};
|
|
11
|
-
type Context = {
|
|
12
|
-
isPressed: (key: string) => boolean;
|
|
13
|
-
addHotkeys: (hotkeys: Hotkeys, ref: React.RefObject<HTMLElement | null>, options?: HotkeyOptions) => (() => void) | undefined;
|
|
14
|
-
};
|
|
15
|
-
type HotkeyData = {
|
|
16
|
-
callback: Callback;
|
|
17
|
-
ref: React.RefObject<HTMLElement | null>;
|
|
18
|
-
options: HotkeyOptions;
|
|
19
|
-
};
|
|
20
|
-
export declare class HotkeyStore {
|
|
21
|
-
hotkeyMap: Record<string, Set<HotkeyData>>;
|
|
22
|
-
getSize: () => number;
|
|
23
|
-
bindHotkeys: (hotkeys: Hotkeys, ref: React.RefObject<HTMLElement | null>, options: HotkeyOptions) => void;
|
|
24
|
-
unbindHotkeys: (hotkeys: Hotkeys) => void;
|
|
25
|
-
handleKeyDown: (pressedMap: PressedMap, e: KeyboardEvent) => void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Components / Hooks
|
|
29
|
-
*/
|
|
30
|
-
export declare const HotkeyContext: React.Context<Context>;
|
|
31
|
-
export declare const SingletonHotkeysProvider: React.FC<{
|
|
32
|
-
children: React.ReactNode;
|
|
33
|
-
}>;
|
|
34
|
-
declare const useSingletonHotkeys: () => Context;
|
|
35
|
-
export default useSingletonHotkeys;
|