@stackflow/plugin-basic-ui 0.14.1 → 0.14.3
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/basicUIPlugin.d.ts +10 -4
- package/dist/components/AppBar.d.ts +1 -1
- package/dist/components/BottomSheet.d.ts +1 -0
- package/dist/components/Modal.d.ts +1 -0
- package/dist/hooks/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +4 -4
- package/dist/utils/RecursivePartial.d.ts +3 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +3 -3
- package/src/basicUIPlugin.tsx +20 -9
- package/src/components/AppBar.tsx +23 -10
- package/src/components/AppScreen.tsx +17 -8
- package/src/components/BottomSheet.tsx +10 -2
- package/src/components/Modal.tsx +10 -2
- package/src/hooks/index.ts +0 -1
- package/src/utils/RecursivePartial.ts +5 -0
- package/src/utils/index.ts +1 -0
- package/dist/hooks/useTheme.d.ts +0 -3
- package/src/hooks/useTheme.ts +0 -9
|
@@ -3,7 +3,8 @@ import { assignInlineVars } from "@vanilla-extract/dynamic";
|
|
|
3
3
|
import React, { useRef } from "react";
|
|
4
4
|
|
|
5
5
|
import { IconBack, IconClose } from "../assets";
|
|
6
|
-
import {
|
|
6
|
+
import { useGlobalOptions } from "../basicUIPlugin";
|
|
7
|
+
import { useMaxWidth } from "../hooks";
|
|
7
8
|
import type { GlobalVars } from "../theme.css";
|
|
8
9
|
import { globalVars } from "../theme.css";
|
|
9
10
|
import { compactMap, noop } from "../utils";
|
|
@@ -30,7 +31,7 @@ type AppBarProps = Partial<
|
|
|
30
31
|
closeButton?:
|
|
31
32
|
| {
|
|
32
33
|
renderIcon?: () => React.ReactNode;
|
|
33
|
-
onClick
|
|
34
|
+
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
34
35
|
}
|
|
35
36
|
| {
|
|
36
37
|
render?: () => React.ReactNode;
|
|
@@ -59,14 +60,14 @@ const AppBar = React.forwardRef<HTMLDivElement, AppBarProps>(
|
|
|
59
60
|
const actions = useActions();
|
|
60
61
|
const activity = useActivity();
|
|
61
62
|
|
|
62
|
-
const
|
|
63
|
+
const globalOptions = useGlobalOptions();
|
|
63
64
|
|
|
64
65
|
const centerRef = useRef<any>(null);
|
|
65
66
|
|
|
66
67
|
const { maxWidth } = useMaxWidth({
|
|
67
68
|
outerRef: ref,
|
|
68
69
|
innerRef: centerRef,
|
|
69
|
-
enable: theme === "cupertino",
|
|
70
|
+
enable: globalOptions.theme === "cupertino",
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
const onBackClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
@@ -79,14 +80,14 @@ const AppBar = React.forwardRef<HTMLDivElement, AppBarProps>(
|
|
|
79
80
|
}
|
|
80
81
|
};
|
|
81
82
|
|
|
82
|
-
const
|
|
83
|
+
const isRoot =
|
|
83
84
|
activity.zIndex === 0 ||
|
|
84
85
|
(activity.zIndex === 1 &&
|
|
85
86
|
activity.transitionState === "enter-active" &&
|
|
86
87
|
activity.pushedBy.name === "Replaced");
|
|
87
88
|
|
|
88
89
|
const renderBackButton = () => {
|
|
89
|
-
if (
|
|
90
|
+
if (isRoot) {
|
|
90
91
|
return null;
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -117,11 +118,21 @@ const AppBar = React.forwardRef<HTMLDivElement, AppBarProps>(
|
|
|
117
118
|
);
|
|
118
119
|
};
|
|
119
120
|
|
|
121
|
+
const onCloseClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
122
|
+
if (closeButton && "onClick" in closeButton && closeButton.onClick) {
|
|
123
|
+
closeButton.onClick(e);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!e.defaultPrevented) {
|
|
127
|
+
globalOptions.appBar?.closeButton?.onClick?.(e);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
120
131
|
const renderCloseButton = () => {
|
|
121
|
-
if (!closeButton || !
|
|
132
|
+
if ((!closeButton && !globalOptions.appBar?.closeButton) || !isRoot) {
|
|
122
133
|
return null;
|
|
123
134
|
}
|
|
124
|
-
if ("render" in closeButton && closeButton.render) {
|
|
135
|
+
if (closeButton && "render" in closeButton && closeButton.render) {
|
|
125
136
|
return closeButton.render();
|
|
126
137
|
}
|
|
127
138
|
|
|
@@ -129,9 +140,11 @@ const AppBar = React.forwardRef<HTMLDivElement, AppBarProps>(
|
|
|
129
140
|
<button
|
|
130
141
|
type="button"
|
|
131
142
|
className={css.closeButton}
|
|
132
|
-
onClick={
|
|
143
|
+
onClick={onCloseClick}
|
|
133
144
|
>
|
|
134
|
-
{
|
|
145
|
+
{closeButton &&
|
|
146
|
+
"renderIcon" in closeButton &&
|
|
147
|
+
closeButton.renderIcon ? (
|
|
135
148
|
closeButton.renderIcon()
|
|
136
149
|
) : (
|
|
137
150
|
<IconClose />
|
|
@@ -4,12 +4,12 @@ import { useActions, useActivity } from "@stackflow/react";
|
|
|
4
4
|
import { assignInlineVars } from "@vanilla-extract/dynamic";
|
|
5
5
|
import React, { useRef } from "react";
|
|
6
6
|
|
|
7
|
+
import { useGlobalOptions } from "../basicUIPlugin";
|
|
7
8
|
import {
|
|
8
9
|
useLazy,
|
|
9
10
|
useStyleEffectHide,
|
|
10
11
|
useStyleEffectOffset,
|
|
11
12
|
useStyleEffectSwipeBack,
|
|
12
|
-
useTheme,
|
|
13
13
|
} from "../hooks";
|
|
14
14
|
import type { GlobalVars } from "../theme.css";
|
|
15
15
|
import { globalVars } from "../theme.css";
|
|
@@ -24,8 +24,13 @@ type AppScreenProps = Partial<
|
|
|
24
24
|
appBar?: Omit<PropOf<typeof AppBar>, "theme" | "ref" | "key">;
|
|
25
25
|
children: React.ReactNode;
|
|
26
26
|
};
|
|
27
|
-
const AppScreen: React.FC<AppScreenProps> = ({
|
|
28
|
-
|
|
27
|
+
const AppScreen: React.FC<AppScreenProps> = ({
|
|
28
|
+
backgroundColor,
|
|
29
|
+
dimBackgroundColor,
|
|
30
|
+
appBar,
|
|
31
|
+
children,
|
|
32
|
+
}) => {
|
|
33
|
+
const globalOptions = useGlobalOptions();
|
|
29
34
|
const activity = useActivity();
|
|
30
35
|
const { pop } = useActions();
|
|
31
36
|
|
|
@@ -40,12 +45,13 @@ const AppScreen: React.FC<AppScreenProps> = ({ appBar, children }) => {
|
|
|
40
45
|
hasEffect: true,
|
|
41
46
|
});
|
|
42
47
|
useStyleEffectOffset({
|
|
43
|
-
theme,
|
|
44
|
-
refs:
|
|
48
|
+
theme: globalOptions.theme,
|
|
49
|
+
refs:
|
|
50
|
+
globalOptions.theme === "cupertino" ? [paperRef] : [paperRef, appBarRef],
|
|
45
51
|
hasEffect: true,
|
|
46
52
|
});
|
|
47
53
|
useStyleEffectSwipeBack({
|
|
48
|
-
theme,
|
|
54
|
+
theme: globalOptions.theme,
|
|
49
55
|
dimRef,
|
|
50
56
|
edgeRef,
|
|
51
57
|
paperRef,
|
|
@@ -60,7 +66,8 @@ const AppScreen: React.FC<AppScreenProps> = ({ appBar, children }) => {
|
|
|
60
66
|
|
|
61
67
|
const zIndexBase = activity.zIndex * 5;
|
|
62
68
|
const zIndexDim = zIndexBase;
|
|
63
|
-
const zIndexPaper =
|
|
69
|
+
const zIndexPaper =
|
|
70
|
+
zIndexBase + (globalOptions.theme === "cupertino" && hasAppBar ? 1 : 3);
|
|
64
71
|
const zIndexEdge = zIndexBase + 4;
|
|
65
72
|
const zIndexAppBar = zIndexBase + 7;
|
|
66
73
|
|
|
@@ -72,6 +79,8 @@ const AppScreen: React.FC<AppScreenProps> = ({ appBar, children }) => {
|
|
|
72
79
|
})}
|
|
73
80
|
style={assignInlineVars(
|
|
74
81
|
compactMap({
|
|
82
|
+
[globalVars.backgroundColor]: backgroundColor,
|
|
83
|
+
[globalVars.dimBackgroundColor]: dimBackgroundColor,
|
|
75
84
|
[globalVars.appBar.height]: appBar?.height,
|
|
76
85
|
[css.vars.zIndexes.dim]: `${zIndexDim}`,
|
|
77
86
|
[css.vars.zIndexes.paper]: `${zIndexPaper}`,
|
|
@@ -95,7 +104,7 @@ const AppScreen: React.FC<AppScreenProps> = ({ appBar, children }) => {
|
|
|
95
104
|
>
|
|
96
105
|
{children}
|
|
97
106
|
</div>
|
|
98
|
-
{!isRoot && theme === "cupertino" && (
|
|
107
|
+
{!isRoot && globalOptions.theme === "cupertino" && (
|
|
99
108
|
<div className={css.edge({ hasAppBar })} ref={edgeRef} />
|
|
100
109
|
)}
|
|
101
110
|
{appBar && <AppBar {...appBar} ref={appBarRef} />}
|
|
@@ -14,12 +14,14 @@ type BottomSheetProps = Partial<
|
|
|
14
14
|
Pick<GlobalVars, "backgroundColor" | "dimBackgroundColor">
|
|
15
15
|
> &
|
|
16
16
|
Partial<GlobalVars["bottomSheet"]> & {
|
|
17
|
+
onOutsideClick?: React.MouseEventHandler;
|
|
17
18
|
children: React.ReactNode;
|
|
18
19
|
};
|
|
19
20
|
const BottomSheet: React.FC<BottomSheetProps> = ({
|
|
20
21
|
borderRadius = "1rem",
|
|
21
22
|
backgroundColor,
|
|
22
23
|
dimBackgroundColor,
|
|
24
|
+
onOutsideClick,
|
|
23
25
|
children,
|
|
24
26
|
}) => {
|
|
25
27
|
const activity = useActivity();
|
|
@@ -43,13 +45,19 @@ const BottomSheet: React.FC<BottomSheetProps> = ({
|
|
|
43
45
|
|
|
44
46
|
const popLock = useRef(false);
|
|
45
47
|
|
|
46
|
-
const onDimClick = () => {
|
|
48
|
+
const onDimClick: React.MouseEventHandler = (e) => {
|
|
49
|
+
onOutsideClick?.(e);
|
|
50
|
+
|
|
51
|
+
if (e.defaultPrevented) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
if (popLock.current) {
|
|
48
56
|
return;
|
|
49
57
|
}
|
|
58
|
+
popLock.current = true;
|
|
50
59
|
|
|
51
60
|
pop();
|
|
52
|
-
popLock.current = true;
|
|
53
61
|
};
|
|
54
62
|
const onPaperClick: React.MouseEventHandler = (e) => {
|
|
55
63
|
e.stopPropagation();
|
package/src/components/Modal.tsx
CHANGED
|
@@ -14,12 +14,14 @@ type ModalProps = Partial<
|
|
|
14
14
|
Pick<GlobalVars, "backgroundColor" | "dimBackgroundColor">
|
|
15
15
|
> &
|
|
16
16
|
Partial<GlobalVars["modal"]> & {
|
|
17
|
+
onOutsideClick?: React.MouseEventHandler;
|
|
17
18
|
children: React.ReactNode;
|
|
18
19
|
};
|
|
19
20
|
const Modal: React.FC<ModalProps> = ({
|
|
20
21
|
backgroundColor,
|
|
21
22
|
dimBackgroundColor,
|
|
22
23
|
borderRadius = "1rem",
|
|
24
|
+
onOutsideClick,
|
|
23
25
|
children,
|
|
24
26
|
}) => {
|
|
25
27
|
const activity = useActivity();
|
|
@@ -43,13 +45,19 @@ const Modal: React.FC<ModalProps> = ({
|
|
|
43
45
|
|
|
44
46
|
const popLock = useRef(false);
|
|
45
47
|
|
|
46
|
-
const onDimClick = () => {
|
|
48
|
+
const onDimClick: React.MouseEventHandler = (e) => {
|
|
49
|
+
onOutsideClick?.(e);
|
|
50
|
+
|
|
51
|
+
if (e.defaultPrevented) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
if (popLock.current) {
|
|
48
56
|
return;
|
|
49
57
|
}
|
|
58
|
+
popLock.current = true;
|
|
50
59
|
|
|
51
60
|
pop();
|
|
52
|
-
popLock.current = true;
|
|
53
61
|
};
|
|
54
62
|
const onPaperClick: React.MouseEventHandler = (e) => {
|
|
55
63
|
e.stopPropagation();
|
package/src/hooks/index.ts
CHANGED
package/src/utils/index.ts
CHANGED
package/dist/hooks/useTheme.d.ts
DELETED
package/src/hooks/useTheme.ts
DELETED