reshaped 3.0.8-rc.1 → 3.0.10
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 +9 -0
- package/bin/cli.js +0 -1
- package/dist/bundle.css +1 -1
- package/dist/bundle.d.ts +3 -1
- package/dist/bundle.js +10 -10
- package/dist/cjs/themes/_generator/utilities/color.d.ts +16 -0
- package/dist/cjs/themes/_generator/utilities/color.js +57 -7
- package/dist/cjs/themes/_generator/utilities/generateBackgroundColors.js +4 -0
- package/dist/cjs/themes/_generator/utilities/tests/color.test.js +73 -42
- package/dist/cjs/themes/index.d.ts +17 -0
- package/dist/cjs/themes/index.js +3 -0
- package/dist/cjs/types/config.d.ts +1 -0
- package/dist/components/Button/Button.module.css +1 -1
- package/dist/components/Button/tests/Button.stories.js +3 -1
- package/dist/components/Card/Card.module.css +1 -1
- package/dist/components/Checkbox/Checkbox.module.css +1 -1
- package/dist/components/Dismissible/Dismissible.module.css +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.d.ts +1 -0
- package/dist/components/DropdownMenu/DropdownMenu.js +1 -0
- package/dist/components/DropdownMenu/DropdownMenu.module.css +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.types.d.ts +1 -1
- package/dist/components/DropdownMenu/tests/DropdownMenu.stories.d.ts +1 -0
- package/dist/components/Modal/Modal.js +4 -3
- package/dist/components/Modal/tests/Modal.stories.js +1 -1
- package/dist/components/Overlay/Overlay.js +7 -7
- package/dist/components/Overlay/tests/Overlay.stories.js +3 -1
- package/dist/components/Popover/Popover.d.ts +2 -0
- package/dist/components/Popover/Popover.js +9 -3
- package/dist/components/Popover/Popover.types.d.ts +1 -1
- package/dist/components/Popover/tests/Popover.stories.d.ts +2 -0
- package/dist/components/Popover/tests/Popover.stories.js +16 -0
- package/dist/components/Radio/Radio.module.css +1 -1
- package/dist/components/Resizable/Resizable.d.ts +8 -0
- package/dist/components/Resizable/Resizable.js +149 -0
- package/dist/components/Resizable/Resizable.module.css +1 -0
- package/dist/components/Resizable/Resizable.types.d.ts +29 -0
- package/dist/components/Resizable/Resizable.types.js +1 -0
- package/dist/components/Resizable/index.d.ts +2 -0
- package/dist/components/Resizable/index.js +1 -0
- package/dist/components/Resizable/tests/Resizable.stories.d.ts +15 -0
- package/dist/components/Resizable/tests/Resizable.stories.js +58 -0
- package/dist/components/ScrollArea/ScrollArea.js +4 -4
- package/dist/components/Slider/Slider.module.css +1 -1
- package/dist/components/Slider/Slider.types.d.ts +2 -2
- package/dist/components/Slider/Slider.utilities.js +4 -4
- package/dist/components/Slider/SliderControlled.js +11 -9
- package/dist/components/Slider/SliderThumb.js +1 -1
- package/dist/components/Slider/tests/Slider.stories.js +4 -0
- package/dist/components/Switch/Switch.module.css +1 -1
- package/dist/components/Toast/Toast.types.d.ts +7 -6
- package/dist/components/Toast/index.d.ts +1 -1
- package/dist/components/Toast/useToast.d.ts +1 -1
- package/dist/components/Tooltip/tests/Tooltip.stories.js +31 -0
- package/dist/components/_private/Flyout/Flyout.context.d.ts +3 -1
- package/dist/components/_private/Flyout/Flyout.context.js +4 -1
- package/dist/components/_private/Flyout/Flyout.types.d.ts +1 -0
- package/dist/components/_private/Flyout/FlyoutContent.js +5 -7
- package/dist/components/_private/Flyout/FlyoutControlled.js +20 -14
- package/dist/components/_private/Flyout/FlyoutTrigger.js +3 -2
- package/dist/components/_private/Flyout/tests/Flyout.stories.d.ts +2 -7
- package/dist/components/_private/Flyout/tests/Flyout.stories.js +125 -49
- package/dist/components/_private/Portal/Portal.module.css +1 -1
- package/dist/hooks/_private/useOnClickOutside.js +5 -3
- package/dist/hooks/tests/useDrag.stories.d.ts +6 -0
- package/dist/hooks/tests/useDrag.stories.js +29 -0
- package/dist/hooks/useDrag.d.ts +17 -0
- package/dist/hooks/useDrag.js +116 -0
- package/dist/hooks/useHandlerRef.d.ts +8 -0
- package/dist/hooks/useHandlerRef.js +16 -0
- package/dist/hooks/useScrollLock.js +4 -3
- package/dist/hooks/useToggle.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/themes/_generator/tests/themes.stories.js +23 -0
- package/dist/themes/_generator/utilities/color.d.ts +16 -0
- package/dist/themes/_generator/utilities/color.js +54 -6
- package/dist/themes/_generator/utilities/generateBackgroundColors.js +4 -0
- package/dist/themes/index.d.ts +17 -0
- package/dist/themes/index.js +3 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/global.d.ts +1 -1
- package/package.json +1 -1
@@ -21,8 +21,8 @@ const useScrollLock = () => {
|
|
21
21
|
const [locked, setLocked] = React.useState(false);
|
22
22
|
const overflowStyleRef = React.useRef();
|
23
23
|
const isOverflowingRef = React.useRef(false);
|
24
|
-
const targetEl = document.body;
|
25
24
|
const lockScroll = React.useCallback(() => {
|
25
|
+
const targetEl = document.body;
|
26
26
|
const rect = targetEl.getBoundingClientRect();
|
27
27
|
isOverflowingRef.current = rect.left + rect.right < window.innerWidth;
|
28
28
|
overflowStyleRef.current = targetEl.style.overflow;
|
@@ -32,13 +32,14 @@ const useScrollLock = () => {
|
|
32
32
|
targetEl.style.paddingRight = `${scrollBarWidth}px`;
|
33
33
|
}
|
34
34
|
setLocked(true);
|
35
|
-
}, [setLocked, isOverflowingRef, overflowStyleRef
|
35
|
+
}, [setLocked, isOverflowingRef, overflowStyleRef]);
|
36
36
|
const unlockScroll = React.useCallback(() => {
|
37
|
+
const targetEl = document.body;
|
37
38
|
targetEl.style.overflow = overflowStyleRef.current || "";
|
38
39
|
if (isOverflowingRef.current)
|
39
40
|
targetEl.style.paddingRight = "";
|
40
41
|
setLocked(false);
|
41
|
-
}, [setLocked, isOverflowingRef, overflowStyleRef
|
42
|
+
}, [setLocked, isOverflowingRef, overflowStyleRef]);
|
42
43
|
return { scrollLocked: locked, lockScroll, unlockScroll };
|
43
44
|
};
|
44
45
|
export default useScrollLock;
|
package/dist/hooks/useToggle.js
CHANGED
@@ -11,6 +11,6 @@ const useToggle = (defaultValue) => {
|
|
11
11
|
const toggle = React.useCallback(() => {
|
12
12
|
setActive((active) => !active);
|
13
13
|
}, []);
|
14
|
-
return { active, activate, deactivate, toggle };
|
14
|
+
return React.useMemo(() => ({ active, activate, deactivate, toggle }), [activate, deactivate, toggle, active]);
|
15
15
|
};
|
16
16
|
export default useToggle;
|
package/dist/index.d.ts
CHANGED
@@ -75,6 +75,8 @@ export { default as RadioGroup } from "./components/RadioGroup";
|
|
75
75
|
export type { RadioGroupProps } from "./components/RadioGroup";
|
76
76
|
export { default as Reshaped } from "./components/Reshaped";
|
77
77
|
export type { ReshapedProps } from "./components/Reshaped";
|
78
|
+
export { default as Resizable } from "./components/Resizable";
|
79
|
+
export type { ResizableProps, ResizableItemProps, ResizableHandleProps, } from "./components/Resizable";
|
78
80
|
export { default as Scrim } from "./components/Scrim";
|
79
81
|
export type { ScrimProps } from "./components/Scrim";
|
80
82
|
export { default as ScrollArea } from "./components/ScrollArea";
|
@@ -102,7 +104,7 @@ export type { TextFieldProps } from "./components/TextField";
|
|
102
104
|
export { default as Timeline } from "./components/Timeline";
|
103
105
|
export type { TimelineProps, TimelineItemProps } from "./components/Timeline";
|
104
106
|
export { useToast, ToastProvider } from "./components/Toast";
|
105
|
-
export type { ToastProps, ToastProviderProps } from "./components/Toast";
|
107
|
+
export type { ToastProps, ToastProviderProps, ToastShowProps } from "./components/Toast";
|
106
108
|
export { default as Tooltip } from "./components/Tooltip";
|
107
109
|
export type { TooltipProps } from "./components/Tooltip";
|
108
110
|
export { default as View } from "./components/View";
|
package/dist/index.js
CHANGED
@@ -38,6 +38,7 @@ export { default as Progress } from "./components/Progress/index.js";
|
|
38
38
|
export { default as Radio } from "./components/Radio/index.js";
|
39
39
|
export { default as RadioGroup } from "./components/RadioGroup/index.js";
|
40
40
|
export { default as Reshaped } from "./components/Reshaped/index.js";
|
41
|
+
export { default as Resizable } from "./components/Resizable/index.js";
|
41
42
|
export { default as Scrim } from "./components/Scrim/index.js";
|
42
43
|
export { default as ScrollArea } from "./components/ScrollArea/index.js";
|
43
44
|
export { default as Select } from "./components/Select/index.js";
|
@@ -235,6 +235,20 @@ const onColorsCss = getThemeCSS("on-color", {
|
|
235
235
|
},
|
236
236
|
},
|
237
237
|
});
|
238
|
+
const onColorsCssApca = getThemeCSS("on-color-apca", {
|
239
|
+
color: {
|
240
|
+
backgroundPrimary: { hex: "#1abc9c", hexDark: "#16a085" },
|
241
|
+
backgroundPrimaryHighlighted: { hex: "#16a085", hexDark: "#1abc9c" },
|
242
|
+
},
|
243
|
+
}, {
|
244
|
+
colorContrastAlgorithm: "apca",
|
245
|
+
onColorValues: {
|
246
|
+
primary: {
|
247
|
+
hexLight: "#d1fae5",
|
248
|
+
hexDark: "#022c22",
|
249
|
+
},
|
250
|
+
},
|
251
|
+
});
|
238
252
|
export const onColors = () => (<Example>
|
239
253
|
<Example.Item title="custom on color values">
|
240
254
|
<style>{onColorsCss}</style>
|
@@ -245,4 +259,13 @@ export const onColors = () => (<Example>
|
|
245
259
|
</View>
|
246
260
|
</Theme>
|
247
261
|
</Example.Item>
|
262
|
+
<Example.Item title="custom on color values, apca">
|
263
|
+
<style>{onColorsCssApca}</style>
|
264
|
+
<Theme name="on-color-apca">
|
265
|
+
<View gap={2} direction="row">
|
266
|
+
<Button color="primary">Primary button</Button>
|
267
|
+
<Button color="critical">Critical button</Button>
|
268
|
+
</View>
|
269
|
+
</Theme>
|
270
|
+
</Example.Item>
|
248
271
|
</Example>);
|
@@ -81,9 +81,25 @@ export declare const getDarkModeColor: (hsl: HslColor) => {
|
|
81
81
|
};
|
82
82
|
export declare const getLuminanceDelta: (luminance: number) => number;
|
83
83
|
export declare function getRgbLuminance({ r, g, b }: RgbColor): number;
|
84
|
+
export declare const getOnColorWCAG: (args: {
|
85
|
+
bgHexColor: string;
|
86
|
+
lightHexColor?: string;
|
87
|
+
darkHexColor?: string;
|
88
|
+
}) => string;
|
89
|
+
export declare const getOnColorAPCA: (args: {
|
90
|
+
bgHexColor: string;
|
91
|
+
mode: "light" | "dark";
|
92
|
+
lightHexColor?: string;
|
93
|
+
darkHexColor?: string;
|
94
|
+
}) => string;
|
95
|
+
/**
|
96
|
+
* On color resolver
|
97
|
+
*/
|
84
98
|
export declare const getOnColor: (args: {
|
85
99
|
bgHexColor: string;
|
86
100
|
lightHexColor?: string;
|
87
101
|
darkHexColor?: string;
|
102
|
+
mode: "light" | "dark";
|
103
|
+
algorithm?: "wcag" | "apca";
|
88
104
|
}) => string;
|
89
105
|
export {};
|
@@ -301,29 +301,77 @@ export function getRgbLuminance({ r, g, b }) {
|
|
301
301
|
return Math.pow(y, 1 / 3) * 116 - 16;
|
302
302
|
}
|
303
303
|
}
|
304
|
+
/**
|
305
|
+
* WCAG contrast
|
306
|
+
*/
|
304
307
|
const RED = 0.2126;
|
305
308
|
const GREEN = 0.7152;
|
306
309
|
const BLUE = 0.0722;
|
307
310
|
const GAMMA = 2.4;
|
308
|
-
function
|
311
|
+
function luminanceWCAG(r, g, b) {
|
309
312
|
var a = [r, g, b].map((v) => {
|
310
313
|
v /= 255;
|
311
314
|
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, GAMMA);
|
312
315
|
});
|
313
316
|
return a[0] * RED + a[1] * GREEN + a[2] * BLUE;
|
314
317
|
}
|
315
|
-
function
|
316
|
-
var lum1 =
|
317
|
-
var lum2 =
|
318
|
+
function contrastWCAG(rgb1, rgb2) {
|
319
|
+
var lum1 = luminanceWCAG(...rgb1);
|
320
|
+
var lum2 = luminanceWCAG(...rgb2);
|
318
321
|
var brightest = Math.max(lum1, lum2);
|
319
322
|
var darkest = Math.min(lum1, lum2);
|
320
323
|
return (brightest + 0.05) / (darkest + 0.05);
|
321
324
|
}
|
322
|
-
export const
|
325
|
+
export const getOnColorWCAG = (args) => {
|
323
326
|
const { bgHexColor, lightHexColor = "#ffffff", darkHexColor = "#000000" } = args;
|
324
327
|
const bgRgb = hexToRgb(bgHexColor);
|
325
328
|
const lightRgb = hexToRgb(lightHexColor);
|
326
|
-
return
|
329
|
+
return contrastWCAG([bgRgb.r, bgRgb.g, bgRgb.b], [lightRgb.r, lightRgb.g, lightRgb.b]) > 4.5
|
327
330
|
? lightHexColor
|
328
331
|
: darkHexColor;
|
329
332
|
};
|
333
|
+
/**
|
334
|
+
* APCA contrast
|
335
|
+
*/
|
336
|
+
function luminanceAPCA({ r, g, b }) {
|
337
|
+
return (0.2126 * Math.pow(r / 255, 2.2) +
|
338
|
+
0.7152 * Math.pow(g / 255, 2.2) +
|
339
|
+
0.0722 * Math.pow(b / 255, 2.2));
|
340
|
+
}
|
341
|
+
function contrastAPCA(backgroundLuminance, textLuminance) {
|
342
|
+
// Calculate the contrast based on APCA
|
343
|
+
let Lc = textLuminance - backgroundLuminance;
|
344
|
+
return Math.abs(Lc); // Return the absolute value of contrast
|
345
|
+
}
|
346
|
+
export const getOnColorAPCA = (args) => {
|
347
|
+
const { bgHexColor, mode, lightHexColor = "#ffffff", darkHexColor = "#000000" } = args;
|
348
|
+
const bgHexAlpha = bgHexColor.slice(7);
|
349
|
+
const bgAlpha = bgHexAlpha ? Number((parseInt(bgHexAlpha, 16) / 255).toFixed(2)) : 1;
|
350
|
+
const bgColor = hexToRgb(bgHexColor.slice(0, 7));
|
351
|
+
const baseColor = mode === "light" ? { r: 255, g: 255, b: 255 } : { r: 0, g: 0, b: 0 };
|
352
|
+
const { r, g, b } = {
|
353
|
+
r: (1 - bgAlpha) * baseColor.r + bgAlpha * bgColor.r,
|
354
|
+
g: (1 - bgAlpha) * baseColor.g + bgAlpha * bgColor.g,
|
355
|
+
b: (1 - bgAlpha) * baseColor.b + bgAlpha * bgColor.b,
|
356
|
+
};
|
357
|
+
// Calculate luminance for background and for white & black
|
358
|
+
let backgroundLuminance = luminanceAPCA({ r, g, b });
|
359
|
+
let whiteLuminance = luminanceAPCA({ r: 255, g: 255, b: 255 });
|
360
|
+
let blackLuminance = luminanceAPCA({ r: 0, g: 0, b: 0 });
|
361
|
+
// Calculate contrast
|
362
|
+
let contrastWithWhite = contrastAPCA(backgroundLuminance, whiteLuminance);
|
363
|
+
let contrastWithBlack = contrastAPCA(backgroundLuminance, blackLuminance);
|
364
|
+
// Choose the color with higher contrast
|
365
|
+
return contrastWithWhite > contrastWithBlack ? lightHexColor : darkHexColor;
|
366
|
+
};
|
367
|
+
/**
|
368
|
+
* On color resolver
|
369
|
+
*/
|
370
|
+
export const getOnColor = (args) => {
|
371
|
+
if (args.algorithm === "apca") {
|
372
|
+
return getOnColorAPCA(args);
|
373
|
+
}
|
374
|
+
else {
|
375
|
+
return getOnColorWCAG(args);
|
376
|
+
}
|
377
|
+
};
|
@@ -29,10 +29,14 @@ const generateBackgroundColors = (definition, themeOptions) => {
|
|
29
29
|
};
|
30
30
|
const hex = getOnColor({
|
31
31
|
bgHexColor: bgToken.hex,
|
32
|
+
mode: "light",
|
33
|
+
algorithm: themeOptions?.colorContrastAlgorithm,
|
32
34
|
...onColorHexMap,
|
33
35
|
});
|
34
36
|
const hexDark = getOnColor({
|
35
37
|
bgHexColor: bgToken.hexDark || bgToken.hex,
|
38
|
+
mode: "dark",
|
39
|
+
algorithm: themeOptions?.colorContrastAlgorithm,
|
36
40
|
...onColorHexMap,
|
37
41
|
});
|
38
42
|
// eslint-disable-next-line no-param-reassign
|
package/dist/themes/index.d.ts
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
import type * as T from "./_generator/types";
|
2
2
|
import type { FullThemeDefinition } from "./_generator/tokens/types";
|
3
|
+
/**
|
4
|
+
* Exported types
|
5
|
+
*/
|
6
|
+
export type { FullThemeDefinition } from "./_generator/tokens/types";
|
7
|
+
export type { Name as ColorTokenName } from "./_generator/tokens/color/color.types";
|
8
|
+
export type { Name as DurationTokenName } from "./_generator/tokens/duration/duration.types";
|
9
|
+
export type { Name as EasingTokenName } from "./_generator/tokens/easing/easing.types";
|
10
|
+
export type { Name as FontTokenName } from "./_generator/tokens/font/font.types";
|
11
|
+
export type { Name as FontFamilyTokenName } from "./_generator/tokens/fontFamily/fontFamily.types";
|
12
|
+
export type { Name as FontWeightTokenName } from "./_generator/tokens/fontWeight/fontWeight.types";
|
13
|
+
export type { Name as RadiusTokenName } from "./_generator/tokens/radius/radius.types";
|
14
|
+
export type { Name as ShadowTokenName } from "./_generator/tokens/shadow/shadow.types";
|
15
|
+
export type { GeneratedName as UnitTokenName } from "./_generator/tokens/unit/unit.types";
|
16
|
+
export type { Name as ViewportTokenName } from "./_generator/tokens/viewport/viewport.types";
|
17
|
+
/**
|
18
|
+
* Exported runtime code
|
19
|
+
*/
|
3
20
|
export { default as baseThemeDefinition } from "./_generator/definitions/reshaped";
|
4
21
|
export declare const generateThemeColors: (options: {
|
5
22
|
primary: T.Color;
|
package/dist/themes/index.js
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
import transform from "./_generator/transform.js";
|
2
2
|
import generateColors from "./_generator/utilities/generateColors.js";
|
3
|
+
/**
|
4
|
+
* Exported runtime code
|
5
|
+
*/
|
3
6
|
export { default as baseThemeDefinition } from "./_generator/definitions/reshaped.js";
|
4
7
|
export const generateThemeColors = (options) => {
|
5
8
|
return generateColors(options);
|
package/dist/types/config.d.ts
CHANGED
package/dist/types/global.d.ts
CHANGED
@@ -2,7 +2,7 @@ import React from "react";
|
|
2
2
|
type ClassNameValue = string | null | undefined | false;
|
3
3
|
export type ClassName = ClassNameValue | ClassNameValue[] | ClassName[];
|
4
4
|
export type CSSVariable = `--${string}`;
|
5
|
-
export type StyleAttribute = React.CSSProperties | (React.CSSProperties & Record<CSSVariable, string | number>);
|
5
|
+
export type StyleAttribute = React.CSSProperties | (React.CSSProperties & Record<CSSVariable, string | number | undefined>);
|
6
6
|
type DataAttributes = {} | Record<`data-${string}`, string | boolean>;
|
7
7
|
export type Attributes<TagName extends keyof JSX.IntrinsicElements = "div"> = JSX.IntrinsicElements[TagName] & DataAttributes & {
|
8
8
|
style?: StyleAttribute;
|
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.0.
|
4
|
+
"version": "3.0.10",
|
5
5
|
"license": "MIT",
|
6
6
|
"email": "hello@reshaped.so",
|
7
7
|
"homepage": "https://reshaped.so",
|