@noya-app/noya-designsystem 0.1.13 → 0.1.15
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/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +13 -0
- package/dist/index.d.mts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +301 -244
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +323 -264
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/InputField.tsx +2 -2
- package/src/components/Popover.tsx +25 -24
- package/src/components/Select.tsx +42 -13
- package/src/components/Sortable.tsx +9 -1
- package/src/contexts/DesignSystemConfiguration.tsx +49 -15
- package/src/theme/light.ts +1 -1
package/package.json
CHANGED
|
@@ -62,6 +62,8 @@ const LabelContainer = styled.label<{
|
|
|
62
62
|
labelPosition: LabelPosition;
|
|
63
63
|
hasDropdown: boolean;
|
|
64
64
|
}>(({ theme, labelPosition, hasDropdown, pointerEvents }) => ({
|
|
65
|
+
...theme.textStyles.label,
|
|
66
|
+
fontWeight: "bold",
|
|
65
67
|
color: theme.colors.textDisabled,
|
|
66
68
|
position: "absolute",
|
|
67
69
|
top: 0,
|
|
@@ -71,8 +73,6 @@ const LabelContainer = styled.label<{
|
|
|
71
73
|
display: "flex",
|
|
72
74
|
alignItems: "center",
|
|
73
75
|
pointerEvents,
|
|
74
|
-
fontWeight: "bold",
|
|
75
|
-
fontSize: "60%",
|
|
76
76
|
userSelect: "none",
|
|
77
77
|
...(labelPosition === "start"
|
|
78
78
|
? { justifyContent: "flex-start", paddingLeft: "6px" }
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as PopoverPrimitive from
|
|
2
|
-
import React, { ComponentProps } from
|
|
3
|
-
import styled from
|
|
4
|
-
import { IconButton } from
|
|
1
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
2
|
+
import React, { ComponentProps } from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { IconButton } from "./IconButton";
|
|
5
5
|
|
|
6
|
-
type PopoverVariant =
|
|
6
|
+
type PopoverVariant = "normal" | "large";
|
|
7
7
|
|
|
8
8
|
const ContentElement = styled(PopoverPrimitive.Content)<{
|
|
9
9
|
variant?: PopoverVariant;
|
|
@@ -11,12 +11,12 @@ const ContentElement = styled(PopoverPrimitive.Content)<{
|
|
|
11
11
|
borderRadius: 4,
|
|
12
12
|
fontSize: 14,
|
|
13
13
|
backgroundColor: theme.colors.popover.background,
|
|
14
|
-
boxShadow:
|
|
15
|
-
maxHeight:
|
|
16
|
-
overflowY:
|
|
14
|
+
boxShadow: "0 2px 4px rgba(0,0,0,0.2), 0 0 12px rgba(0,0,0,0.1)",
|
|
15
|
+
maxHeight: "600px",
|
|
16
|
+
overflowY: "auto",
|
|
17
17
|
color: theme.colors.textMuted,
|
|
18
|
-
...(variant ===
|
|
19
|
-
...(variant ===
|
|
18
|
+
...(variant === "large" && { width: "680px" }),
|
|
19
|
+
...(variant === "normal" && { width: "240px" }),
|
|
20
20
|
zIndex: 1000,
|
|
21
21
|
}));
|
|
22
22
|
|
|
@@ -25,28 +25,28 @@ const ArrowElement = styled(PopoverPrimitive.Arrow)(({ theme }) => ({
|
|
|
25
25
|
}));
|
|
26
26
|
|
|
27
27
|
const PopoverClose = styled(PopoverPrimitive.Close)(({ theme }) => ({
|
|
28
|
-
all:
|
|
29
|
-
fontFamily:
|
|
30
|
-
borderRadius:
|
|
28
|
+
all: "unset",
|
|
29
|
+
fontFamily: "inherit",
|
|
30
|
+
borderRadius: "100%",
|
|
31
31
|
height: 25,
|
|
32
32
|
width: 25,
|
|
33
|
-
display:
|
|
34
|
-
alignItems:
|
|
35
|
-
justifyContent:
|
|
36
|
-
position:
|
|
33
|
+
display: "inline-flex",
|
|
34
|
+
alignItems: "center",
|
|
35
|
+
justifyContent: "center",
|
|
36
|
+
position: "absolute",
|
|
37
37
|
top: 5,
|
|
38
38
|
right: 5,
|
|
39
39
|
}));
|
|
40
40
|
|
|
41
41
|
interface Props
|
|
42
42
|
extends Pick<
|
|
43
|
-
ComponentProps<typeof PopoverPrimitive[
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
43
|
+
ComponentProps<(typeof PopoverPrimitive)["Content"]>,
|
|
44
|
+
| "onOpenAutoFocus"
|
|
45
|
+
| "onCloseAutoFocus"
|
|
46
|
+
| "onPointerDownOutside"
|
|
47
|
+
| "onInteractOutside"
|
|
48
|
+
| "onFocusOutside"
|
|
49
|
+
| "side"
|
|
50
50
|
> {
|
|
51
51
|
children: React.ReactNode;
|
|
52
52
|
trigger: React.ReactNode;
|
|
@@ -91,6 +91,7 @@ export function Popover({
|
|
|
91
91
|
onFocusOutside={onFocusOutside}
|
|
92
92
|
onPointerDownOutside={onPointerDownOutside}
|
|
93
93
|
collisionPadding={8}
|
|
94
|
+
arrowPadding={2}
|
|
94
95
|
// Don't propagate pointer down events to the canvas
|
|
95
96
|
onPointerDown={(event) => {
|
|
96
97
|
event.stopPropagation();
|
|
@@ -51,6 +51,15 @@ const createChevronSVGString = memoize(
|
|
|
51
51
|
`
|
|
52
52
|
);
|
|
53
53
|
|
|
54
|
+
const SelectContainer = styled.div<{ flex: CSSProperties["flex"] }>(
|
|
55
|
+
({ flex }) => ({
|
|
56
|
+
flex: flex ?? "1 1 0px",
|
|
57
|
+
display: "flex",
|
|
58
|
+
flexDirection: "row",
|
|
59
|
+
position: "relative",
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
|
|
54
63
|
const SelectElement = styled.select<{ flex: CSSProperties["flex"] }>(
|
|
55
64
|
({ theme, flex }) => ({
|
|
56
65
|
appearance: "none",
|
|
@@ -82,6 +91,21 @@ const SelectElement = styled.select<{ flex: CSSProperties["flex"] }>(
|
|
|
82
91
|
})
|
|
83
92
|
);
|
|
84
93
|
|
|
94
|
+
const SelectLabel = styled.label(({ theme }) => ({
|
|
95
|
+
...theme.textStyles.label,
|
|
96
|
+
color: theme.colors.textDisabled,
|
|
97
|
+
lineHeight: "19px",
|
|
98
|
+
position: "absolute",
|
|
99
|
+
inset: "0",
|
|
100
|
+
fontWeight: "bold",
|
|
101
|
+
fontSize: "60%",
|
|
102
|
+
pointerEvents: "none",
|
|
103
|
+
display: "flex",
|
|
104
|
+
alignItems: "center",
|
|
105
|
+
justifyContent: "end",
|
|
106
|
+
paddingRight: "24px",
|
|
107
|
+
}));
|
|
108
|
+
|
|
85
109
|
type ChildrenProps<T> =
|
|
86
110
|
| {
|
|
87
111
|
children: ReactNode;
|
|
@@ -96,12 +120,14 @@ type Props<T extends string> = ChildrenProps<T> & {
|
|
|
96
120
|
id: string;
|
|
97
121
|
flex?: CSSProperties["flex"];
|
|
98
122
|
value: T;
|
|
123
|
+
label?: string;
|
|
99
124
|
};
|
|
100
125
|
|
|
101
126
|
export const Select = memo(function Select<T extends string>({
|
|
102
127
|
id,
|
|
103
128
|
flex,
|
|
104
129
|
value,
|
|
130
|
+
label,
|
|
105
131
|
...rest
|
|
106
132
|
}: Props<T>) {
|
|
107
133
|
const options = "options" in rest ? rest.options : undefined;
|
|
@@ -136,19 +162,22 @@ export const Select = memo(function Select<T extends string>({
|
|
|
136
162
|
|
|
137
163
|
return (
|
|
138
164
|
<SelectContext.Provider value={contextValue}>
|
|
139
|
-
<
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
165
|
+
<SelectContainer flex={flex}>
|
|
166
|
+
<SelectElement
|
|
167
|
+
id={id}
|
|
168
|
+
flex={flex}
|
|
169
|
+
value={value}
|
|
170
|
+
onChange={useCallback(
|
|
171
|
+
(event: React.ChangeEvent<HTMLSelectElement>) =>
|
|
172
|
+
listeners.current.get(event.target.value)?.(),
|
|
173
|
+
[listeners]
|
|
174
|
+
)}
|
|
175
|
+
onPointerDown={(event) => event.stopPropagation()}
|
|
176
|
+
>
|
|
177
|
+
{optionElements}
|
|
178
|
+
</SelectElement>
|
|
179
|
+
</SelectContainer>
|
|
180
|
+
{label && <SelectLabel htmlFor={id}>{label}</SelectLabel>}
|
|
152
181
|
</SelectContext.Provider>
|
|
153
182
|
);
|
|
154
183
|
});
|
|
@@ -22,6 +22,7 @@ import React, {
|
|
|
22
22
|
Ref,
|
|
23
23
|
useCallback,
|
|
24
24
|
useContext,
|
|
25
|
+
useEffect,
|
|
25
26
|
useMemo,
|
|
26
27
|
useRef,
|
|
27
28
|
useState,
|
|
@@ -262,6 +263,12 @@ function SortableRoot({
|
|
|
262
263
|
[acceptsDrop, axis, keys, onMoveItem, position.x, position.y]
|
|
263
264
|
);
|
|
264
265
|
|
|
266
|
+
const [mounted, setMounted] = useState(false);
|
|
267
|
+
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
setMounted(true);
|
|
270
|
+
}, []);
|
|
271
|
+
|
|
265
272
|
return (
|
|
266
273
|
<SortableItemContext.Provider
|
|
267
274
|
value={useMemo(
|
|
@@ -285,7 +292,8 @@ function SortableRoot({
|
|
|
285
292
|
<SortableContext items={keys} strategy={verticalListSortingStrategy}>
|
|
286
293
|
{children}
|
|
287
294
|
</SortableContext>
|
|
288
|
-
{
|
|
295
|
+
{mounted &&
|
|
296
|
+
renderOverlay &&
|
|
289
297
|
createPortal(
|
|
290
298
|
<DragOverlay dropAnimation={null}>
|
|
291
299
|
{activeIndex !== undefined &&
|
|
@@ -1,35 +1,75 @@
|
|
|
1
|
-
import { PlatformName } from "@noya-app/noya-keymap";
|
|
1
|
+
import { getCurrentPlatform, PlatformName } from "@noya-app/noya-keymap";
|
|
2
2
|
import React, {
|
|
3
3
|
createContext,
|
|
4
4
|
memo,
|
|
5
5
|
ReactNode,
|
|
6
6
|
useContext,
|
|
7
|
+
useEffect,
|
|
7
8
|
useMemo,
|
|
9
|
+
useState,
|
|
8
10
|
} from "react";
|
|
9
11
|
import { ThemeProvider, useTheme } from "styled-components";
|
|
10
12
|
import { ToastProvider } from "../components/Toast";
|
|
11
13
|
import { Theme } from "../theme";
|
|
14
|
+
import * as lightTheme from "../theme/light";
|
|
12
15
|
import { DialogProvider } from "./DialogContext";
|
|
13
16
|
import { FloatingWindowProvider } from "./FloatingWindowContext";
|
|
14
17
|
|
|
18
|
+
export const DesignSystemThemeProvider = memo(
|
|
19
|
+
function DesignSystemThemeProvider({
|
|
20
|
+
children,
|
|
21
|
+
theme,
|
|
22
|
+
}: {
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
theme?: Theme;
|
|
25
|
+
}) {
|
|
26
|
+
const parentTheme = useTheme();
|
|
27
|
+
|
|
28
|
+
if (theme) {
|
|
29
|
+
return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
|
|
30
|
+
} else if (parentTheme) {
|
|
31
|
+
return children;
|
|
32
|
+
} else {
|
|
33
|
+
return <ThemeProvider theme={lightTheme}>{children}</ThemeProvider>;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
|
|
15
38
|
export type DesignSystemConfigurationContextValue = {
|
|
16
39
|
platform: PlatformName;
|
|
17
40
|
};
|
|
18
41
|
|
|
19
|
-
const DesignSystemConfigurationContext =
|
|
20
|
-
DesignSystemConfigurationContextValue
|
|
21
|
-
|
|
42
|
+
const DesignSystemConfigurationContext =
|
|
43
|
+
createContext<DesignSystemConfigurationContextValue>({
|
|
44
|
+
platform: "key",
|
|
45
|
+
});
|
|
22
46
|
|
|
23
47
|
export const DesignSystemConfigurationProvider = memo(
|
|
24
48
|
function DesignSystemConfigurationProvider({
|
|
25
49
|
children,
|
|
26
|
-
theme,
|
|
50
|
+
theme = lightTheme,
|
|
27
51
|
platform,
|
|
28
52
|
}: {
|
|
29
53
|
children: ReactNode;
|
|
30
|
-
theme
|
|
31
|
-
|
|
32
|
-
|
|
54
|
+
theme?: Theme;
|
|
55
|
+
platform?: PlatformName;
|
|
56
|
+
}) {
|
|
57
|
+
const [internalPlatform, setInternalPlatform] = useState<PlatformName>(
|
|
58
|
+
platform ?? "key"
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (platform !== undefined) return;
|
|
63
|
+
|
|
64
|
+
if (typeof navigator !== "undefined") {
|
|
65
|
+
setInternalPlatform(getCurrentPlatform(navigator));
|
|
66
|
+
}
|
|
67
|
+
}, [platform]);
|
|
68
|
+
|
|
69
|
+
const contextValue = useMemo(
|
|
70
|
+
() => ({ platform: platform ?? internalPlatform }),
|
|
71
|
+
[platform, internalPlatform]
|
|
72
|
+
);
|
|
33
73
|
|
|
34
74
|
return (
|
|
35
75
|
<DesignSystemConfigurationContext.Provider value={contextValue}>
|
|
@@ -46,13 +86,7 @@ export const DesignSystemConfigurationProvider = memo(
|
|
|
46
86
|
);
|
|
47
87
|
|
|
48
88
|
export function useDesignSystemConfiguration(): DesignSystemConfigurationContextValue {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!value) {
|
|
52
|
-
throw new Error("Missing DesignSystemConfigurationProvider");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return value;
|
|
89
|
+
return useContext(DesignSystemConfigurationContext);
|
|
56
90
|
}
|
|
57
91
|
|
|
58
92
|
export function useDesignSystemTheme() {
|