@wonderflow/react-components 2.18.4 → 2.18.8

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.
@@ -2,7 +2,7 @@
2
2
  list-style-type: none;
3
3
  padding: env(--space-8) 0 env(--space-8);
4
4
  background-color: var(--global-background);
5
- border: 1px solid var(--dimmed-0);
5
+ border: 1px solid var(--dimmed-1);
6
6
  border-radius: env(--radius-8);
7
7
  overflow: hidden;
8
8
  position: relative;
@@ -1,6 +1,6 @@
1
1
  import clsx from 'clsx';
2
- import React, { useState, Children, cloneElement } from 'react';
3
- import { useKey } from 'react-use';
2
+ import React, { useState, Children, cloneElement, useRef } from 'react';
3
+ import { useKey, useClickAway } from 'react-use';
4
4
  import { Dropdown as DropdownClass, PopUp } from './dropdown.module.css';
5
5
  import { useUIDSeed } from 'react-uid';
6
6
  import { useFocusWithin } from '@react-aria/interactions';
@@ -10,6 +10,7 @@ import { usePopperTooltip } from 'react-popper-tooltip';
10
10
  import { AnimatePresence, motion } from 'framer-motion';
11
11
  export const Dropdown = ({ className, children, trigger, offset = 8, placement = 'auto-start' }) => {
12
12
  const seedID = useUIDSeed();
13
+ const popupRef = useRef(null);
13
14
  const [isOpen, setIsOpen] = useState(false);
14
15
  const { getTooltipProps, setTooltipRef, setTriggerRef, visible } = usePopperTooltip({
15
16
  delayShow: 0,
@@ -19,9 +20,11 @@ export const Dropdown = ({ className, children, trigger, offset = 8, placement =
19
20
  closeOnTriggerHidden: true,
20
21
  onVisibleChange: setIsOpen,
21
22
  placement: placement,
22
- offset: [0, offset]
23
- }, {
24
- strategy: 'fixed'
23
+ offset: [0, offset],
24
+ closeOnOutsideClick: false
25
+ });
26
+ useClickAway(popupRef, () => {
27
+ setIsOpen(false);
25
28
  });
26
29
  const { focusWithinProps } = useFocusWithin({
27
30
  onFocusWithin: () => null,
@@ -29,7 +32,7 @@ export const Dropdown = ({ className, children, trigger, offset = 8, placement =
29
32
  onFocusWithinChange: () => null
30
33
  });
31
34
  useKey('Escape', () => setIsOpen(false));
32
- return (React.createElement("div", Object.assign({ className: clsx(DropdownClass, className) }, focusWithinProps),
35
+ return (React.createElement("div", Object.assign({ ref: popupRef, className: clsx(DropdownClass, className) }, focusWithinProps),
33
36
  Children.map(trigger, (child) => cloneElement(child, {
34
37
  ref: setTriggerRef,
35
38
  id: seedID('dropdown-trigger'),
package/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { Textfield } from './textfield';
13
13
  export { Snackbar } from './snackbar';
14
14
  export { ClampText } from './clamp-text';
15
15
  export { Checkbox, Radio, Toggle } from './selection-controls';
16
- export { ThemeProvider, ThemeContext, ThemeSwitch, useThemeContext } from './theme-switch';
16
+ export { ThemeSwitch } from './theme-switch';
17
17
  export { Elevator } from './elevator';
18
18
  export { Card } from './card';
19
19
  export { StarMeter } from './star-meter';
package/index.js CHANGED
@@ -13,7 +13,7 @@ export { Textfield } from './textfield';
13
13
  export { Snackbar } from './snackbar';
14
14
  export { ClampText } from './clamp-text';
15
15
  export { Checkbox, Radio, Toggle } from './selection-controls';
16
- export { ThemeProvider, ThemeContext, ThemeSwitch, useThemeContext } from './theme-switch';
16
+ export { ThemeSwitch } from './theme-switch';
17
17
  export { Elevator } from './elevator';
18
18
  export { Card } from './card';
19
19
  export { StarMeter } from './star-meter';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wonderflow/react-components",
3
3
  "description": "UI components from Wonderflow's Wanda design system",
4
- "version": "2.18.4",
4
+ "version": "2.18.8",
5
5
  "author": "Wonderflow",
6
6
  "license": "MIT",
7
7
  "main": "index.js",
@@ -63,7 +63,7 @@
63
63
  "clsx": "1.1.1",
64
64
  "flat": "5.0.2",
65
65
  "framer-motion": "4.1.17",
66
- "postcss": "8.3.7",
66
+ "postcss": "8.3.8",
67
67
  "react": ">=17.0.2",
68
68
  "react-dom": ">=17.0.2",
69
69
  "react-popper-tooltip": "4.3.0",
@@ -124,6 +124,6 @@
124
124
  "svgstore": "3.0.0-2",
125
125
  "typescript": "4.4.3",
126
126
  "typescript-plugin-css-modules": "3.4.0",
127
- "yargs": "17.2.0"
127
+ "yargs": "17.2.1"
128
128
  }
129
129
  }
@@ -2,5 +2,5 @@
2
2
  border: 0;
3
3
  margin: 0;
4
4
  block-size: 1px;
5
- border-bottom: 1px solid var(--dimmed-2);
5
+ border-bottom: 1px solid var(--dimmed-1);
6
6
  }
@@ -1,4 +1,2 @@
1
- export { ThemeProvider, ThemeContext } from './theme-provider';
2
- export { useThemeContext } from './use-theme-context';
3
1
  export { ThemeSwitch } from './theme-switch';
4
2
  export type { ThemeSwitchProps } from './theme-switch';
@@ -1,3 +1 @@
1
- export { ThemeProvider, ThemeContext } from './theme-provider';
2
- export { useThemeContext } from './use-theme-context';
3
1
  export { ThemeSwitch } from './theme-switch';
@@ -1,5 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { SelectProps } from '../select';
3
3
  import { Except } from 'type-fest';
4
- export declare type ThemeSwitchProps = Except<SelectProps, 'children'>;
5
- export declare const ThemeSwitch: ({ className, ...props }: ThemeSwitchProps) => JSX.Element;
4
+ export declare type ThemeSwitchProps = Except<SelectProps, 'children'> & {
5
+ currentTheme: string;
6
+ onChange: SelectProps['onChange'];
7
+ };
8
+ export declare const ThemeSwitch: ({ className, currentTheme, onChange }: ThemeSwitchProps) => JSX.Element;
@@ -1,31 +1,14 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import React, { useCallback } from 'react';
1
+ import React from 'react';
13
2
  import { Select } from '../select';
14
- import { useThemeContext } from './use-theme-context';
15
3
  import clsx from 'clsx';
16
- export const ThemeSwitch = (_a) => {
17
- var { className } = _a, props = __rest(_a, ["className"]);
18
- const { theme, setTheme } = useThemeContext();
19
- const changeTheme = useCallback((theme) => {
20
- setTheme(theme);
21
- }, [setTheme]);
4
+ export const ThemeSwitch = ({ className, currentTheme, onChange }) => {
22
5
  const icon = {
23
6
  light: 'sun-bright',
24
- auto: 'pc',
7
+ system: 'pc',
25
8
  dark: 'moon'
26
9
  };
27
- return (React.createElement(Select, Object.assign({ onChange: ({ currentTarget }) => changeTheme(currentTarget.value), value: theme, icon: theme ? icon[theme] : icon.auto, className: clsx(className), "aria-label": "Change color scheme" }, props),
10
+ return (React.createElement(Select, { onChange: onChange, icon: currentTheme === 'system' ? icon.system : icon[currentTheme], className: clsx(className), "aria-label": "Change color scheme" },
28
11
  React.createElement("option", { value: "light" }, "Light"),
29
- React.createElement("option", { value: "auto" }, "System"),
12
+ React.createElement("option", { value: "system" }, "System"),
30
13
  React.createElement("option", { value: "dark" }, "Dark")));
31
14
  };
package/themes/dark.css CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Fri, 24 Sep 2021 13:14:19 GMT
3
+ * Generated on Mon, 27 Sep 2021 10:42:49 GMT
4
4
  */
5
5
 
6
6
  :root {
package/themes/light.css CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Fri, 24 Sep 2021 13:14:19 GMT
3
+ * Generated on Mon, 27 Sep 2021 10:42:49 GMT
4
4
  */
5
5
 
6
6
  :root {
package/themes.css CHANGED
@@ -4,7 +4,7 @@
4
4
  color: var(--global-foreground);
5
5
  /**
6
6
  * Do not edit directly
7
- * Generated on Fri, 24 Sep 2021 13:14:19 GMT
7
+ * Generated on Mon, 27 Sep 2021 10:42:49 GMT
8
8
  */
9
9
 
10
10
 
@@ -51,7 +51,7 @@
51
51
  color: var(--global-foreground);
52
52
  /**
53
53
  * Do not edit directly
54
- * Generated on Fri, 24 Sep 2021 13:14:19 GMT
54
+ * Generated on Mon, 27 Sep 2021 10:42:49 GMT
55
55
  */
56
56
 
57
57
 
@@ -99,7 +99,7 @@
99
99
  color: var(--global-foreground);
100
100
  /**
101
101
  * Do not edit directly
102
- * Generated on Fri, 24 Sep 2021 13:14:19 GMT
102
+ * Generated on Mon, 27 Sep 2021 10:42:49 GMT
103
103
  */
104
104
 
105
105
 
@@ -1,13 +0,0 @@
1
- import React, { FunctionComponent } from 'react';
2
- export declare type ThemeType = 'light' | 'dark' | 'auto' | undefined;
3
- export declare type ThemeContextType = {
4
- theme: ThemeType;
5
- setTheme: React.Dispatch<React.SetStateAction<ThemeType>>;
6
- };
7
- declare type ThemeProviderProps = {
8
- theme?: ThemeType;
9
- persistState?: boolean;
10
- };
11
- export declare const ThemeContext: React.Context<ThemeContextType>;
12
- export declare const ThemeProvider: FunctionComponent<ThemeProviderProps>;
13
- export {};
@@ -1,23 +0,0 @@
1
- import React, { createContext, useState, useEffect } from 'react';
2
- export const ThemeContext = createContext({ theme: 'auto', setTheme: () => { } });
3
- export const ThemeProvider = ({ children, theme: initialTheme = 'auto', persistState = true }) => {
4
- const [theme, setTheme] = useState(initialTheme);
5
- const value = { theme, setTheme };
6
- useEffect(() => {
7
- if (persistState) {
8
- const persistedTheme = localStorage.getItem('theme');
9
- if (persistedTheme) {
10
- setTheme(persistedTheme);
11
- }
12
- }
13
- }, [persistState]);
14
- useEffect(() => {
15
- if (theme) {
16
- document.documentElement.dataset.theme = theme;
17
- if (persistState) {
18
- localStorage.setItem('theme', theme);
19
- }
20
- }
21
- }, [persistState, theme]);
22
- return React.createElement(ThemeContext.Provider, { value: value }, children);
23
- };
@@ -1 +0,0 @@
1
- export declare const useThemeContext: () => import("./theme-provider").ThemeContextType;
@@ -1,9 +0,0 @@
1
- import { useContext } from 'react';
2
- import { ThemeContext } from './theme-provider';
3
- export const useThemeContext = () => {
4
- const context = useContext(ThemeContext);
5
- if (!context) {
6
- throw new Error('To use `useThemeContext`, component must be within a ThemeProvider');
7
- }
8
- return context;
9
- };