@stackflow/plugin-basic-ui 0.21.3 → 1.0.0

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.
Files changed (39) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/IconBack.d.ts +1 -1
  3. package/dist/assets/IconClose.d.ts +1 -1
  4. package/dist/basicUIPlugin.d.ts +2 -2
  5. package/dist/components/AppBar.d.ts +5 -4
  6. package/dist/components/AppScreen.d.ts +2 -2
  7. package/dist/components/BottomSheet.d.ts +1 -1
  8. package/dist/components/Modal.d.ts +1 -1
  9. package/dist/hooks/useMaxWidth.d.ts +1 -1
  10. package/dist/hooks/useStyleEffect.d.ts +4 -4
  11. package/dist/hooks/useStyleEffectHide.d.ts +1 -1
  12. package/dist/index.css +57 -46
  13. package/dist/index.css.map +3 -3
  14. package/dist/index.js +342 -280
  15. package/dist/index.js.map +4 -4
  16. package/dist/index.mjs +320 -252
  17. package/dist/index.mjs.map +4 -4
  18. package/dist/theme.css.d.ts +2 -0
  19. package/dist/utils/index.d.ts +2 -0
  20. package/dist/utils/isBrowser.d.ts +5 -0
  21. package/dist/utils/isServer.d.ts +5 -0
  22. package/package.json +5 -5
  23. package/src/assets/IconBack.tsx +0 -2
  24. package/src/assets/IconClose.tsx +0 -2
  25. package/src/basicUIPlugin.tsx +7 -3
  26. package/src/components/AppBar.css.ts +9 -6
  27. package/src/components/AppBar.tsx +8 -2
  28. package/src/components/AppScreen.tsx +6 -3
  29. package/src/components/BottomSheet.tsx +2 -2
  30. package/src/components/Modal.tsx +2 -2
  31. package/src/hooks/useMaxWidth.ts +0 -1
  32. package/src/hooks/useStyleEffect.ts +8 -8
  33. package/src/hooks/useStyleEffectHide.ts +2 -3
  34. package/src/hooks/useStyleEffectOffset.ts +6 -5
  35. package/src/hooks/useStyleEffectSwipeBack.ts +7 -7
  36. package/src/theme.css.ts +5 -1
  37. package/src/utils/index.ts +2 -0
  38. package/src/utils/isBrowser.ts +9 -0
  39. package/src/utils/isServer.ts +7 -0
@@ -1,6 +1,6 @@
1
1
  import { useActions } from "@stackflow/react";
2
2
  import { assignInlineVars } from "@vanilla-extract/dynamic";
3
- import React, { useRef } from "react";
3
+ import { forwardRef, useRef } from "react";
4
4
 
5
5
  import { IconBack, IconClose } from "../assets";
6
6
  import { useGlobalOptions } from "../basicUIPlugin";
@@ -18,6 +18,7 @@ type AppBarProps = Partial<
18
18
  | "borderSize"
19
19
  | "height"
20
20
  | "heightTransitionDuration"
21
+ | "overflow"
21
22
  | "iconColor"
22
23
  | "textColor"
23
24
  | "backgroundColor"
@@ -49,7 +50,7 @@ type AppBarProps = Partial<
49
50
  modalPresentationStyle?: "fullScreen";
50
51
  onTopClick?: (e: React.MouseEvent) => void;
51
52
  };
52
- const AppBar = React.forwardRef<HTMLDivElement, AppBarProps>(
53
+ const AppBar = forwardRef<HTMLDivElement, AppBarProps>(
53
54
  (
54
55
  {
55
56
  title,
@@ -65,6 +66,8 @@ const AppBar = React.forwardRef<HTMLDivElement, AppBarProps>(
65
66
  borderColor,
66
67
  borderSize,
67
68
  height,
69
+ heightTransitionDuration,
70
+ overflow,
68
71
  backgroundColor,
69
72
  onTopClick,
70
73
  },
@@ -266,6 +269,9 @@ const AppBar = React.forwardRef<HTMLDivElement, AppBarProps>(
266
269
  [globalVars.appBar.borderColor]: borderColor,
267
270
  [globalVars.appBar.borderSize]: borderSize,
268
271
  [globalVars.appBar.height]: height,
272
+ [globalVars.appBar.heightTransitionDuration]:
273
+ heightTransitionDuration,
274
+ [globalVars.appBar.overflow]: overflow,
269
275
  [globalVars.appBar.backgroundColor]:
270
276
  backgroundColor || globalVars.backgroundColor,
271
277
  [appScreenCss.vars.appBar.center.mainWidth]: `${maxWidth}px`,
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useActions } from "@stackflow/react";
4
4
  import { assignInlineVars } from "@vanilla-extract/dynamic";
5
- import React, { createContext, useContext, useMemo, useRef } from "react";
5
+ import { createContext, useContext, useMemo, useRef } from "react";
6
6
 
7
7
  import { useGlobalOptions } from "../basicUIPlugin";
8
8
  import {
@@ -31,7 +31,10 @@ export function useAppScreen() {
31
31
  export type AppScreenProps = Partial<
32
32
  Pick<GlobalVars, "backgroundColor" | "dimBackgroundColor">
33
33
  > & {
34
- appBar?: Omit<PropOf<typeof AppBar>, "theme" | "ref" | "key">;
34
+ appBar?: Omit<
35
+ PropOf<typeof AppBar>,
36
+ "theme" | "modalPresentationStyle" | "ref" | "key"
37
+ >;
35
38
  preventSwipeBack?: boolean;
36
39
  modalPresentationStyle?: "fullScreen";
37
40
  children: React.ReactNode;
@@ -140,7 +143,7 @@ const AppScreen: React.FC<AppScreenProps> = ({
140
143
  [css.vars.transitionDuration]:
141
144
  transitionState === "enter-active" ||
142
145
  transitionState === "exit-active"
143
- ? `var(--stackflow-transition-duration)`
146
+ ? globalVars.transitionDuration
144
147
  : "0ms",
145
148
  }),
146
149
  )}
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useActions } from "@stackflow/react";
4
4
  import { assignInlineVars } from "@vanilla-extract/dynamic";
5
- import React, { useRef } from "react";
5
+ import { useRef } from "react";
6
6
 
7
7
  import { useLazy, useNullableActivity, useStyleEffect } from "../hooks";
8
8
  import type { GlobalVars } from "../theme.css";
@@ -83,7 +83,7 @@ const BottomSheet: React.FC<BottomSheetProps> = ({
83
83
  [css.vars.transitionDuration]:
84
84
  transitionState === "enter-active" ||
85
85
  transitionState === "exit-active"
86
- ? `var(--stackflow-transition-duration)`
86
+ ? globalVars.transitionDuration
87
87
  : "0ms",
88
88
  }),
89
89
  )}
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { useActions } from "@stackflow/react";
4
4
  import { assignInlineVars } from "@vanilla-extract/dynamic";
5
- import React, { useRef } from "react";
5
+ import { useRef } from "react";
6
6
 
7
7
  import { useLazy, useNullableActivity, useStyleEffect } from "../hooks";
8
8
  import type { GlobalVars } from "../theme.css";
@@ -83,7 +83,7 @@ const Modal: React.FC<ModalProps> = ({
83
83
  [css.vars.transitionDuration]:
84
84
  transitionState === "enter-active" ||
85
85
  transitionState === "exit-active"
86
- ? `var(--stackflow-transition-duration)`
86
+ ? globalVars.transitionDuration
87
87
  : "0ms",
88
88
  }),
89
89
  )}
@@ -1,4 +1,3 @@
1
- import type React from "react";
2
1
  import { useEffect, useState } from "react";
3
2
 
4
3
  import { listenResize, noop } from "../utils";
@@ -1,7 +1,7 @@
1
1
  import type { ActivityTransitionState } from "@stackflow/core";
2
- import type React from "react";
3
2
  import { useEffect } from "react";
4
3
 
4
+ import { noop } from "../utils";
5
5
  import { useNullableActivity } from "./useNullableActivity";
6
6
 
7
7
  const connections: {
@@ -14,17 +14,17 @@ const connections: {
14
14
  >;
15
15
  } = {};
16
16
 
17
- export function useStyleEffect({
17
+ export function useStyleEffect<T extends HTMLElement>({
18
18
  styleName,
19
19
  refs,
20
20
  effect,
21
21
  effectDeps,
22
22
  }: {
23
23
  styleName: string;
24
- refs: Array<React.RefObject<any>>;
24
+ refs: Array<React.RefObject<T>>;
25
25
  effect?: (params: {
26
26
  activityTransitionState: ActivityTransitionState;
27
- refs: Array<React.RefObject<HTMLElement>>;
27
+ refs: Array<React.RefObject<T>>;
28
28
  }) => (() => void) | void;
29
29
  effectDeps?: any[];
30
30
  }) {
@@ -32,7 +32,7 @@ export function useStyleEffect({
32
32
 
33
33
  useEffect(() => {
34
34
  if (!activity) {
35
- return () => {};
35
+ return noop;
36
36
  }
37
37
  if (!connections[styleName]) {
38
38
  connections[styleName] = new Map();
@@ -50,14 +50,14 @@ export function useStyleEffect({
50
50
 
51
51
  useEffect(() => {
52
52
  if (!activity) {
53
- return () => {};
53
+ return noop;
54
54
  }
55
55
  if (!effect) {
56
- return () => {};
56
+ return noop;
57
57
  }
58
58
 
59
59
  const refs = (() => {
60
- let arr: Array<React.RefObject<any>> = [];
60
+ let arr: Array<React.RefObject<T>> = [];
61
61
 
62
62
  for (let i = 1; i <= activity.zIndex; i += 1) {
63
63
  const connection = connections[styleName].get(activity.zIndex - i);
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable no-param-reassign */
2
2
 
3
- import type React from "react";
4
-
3
+ import { noop } from "../utils";
5
4
  import { useStyleEffect } from "./useStyleEffect";
6
5
 
7
6
  export function useStyleEffectHide({
@@ -45,7 +44,7 @@ export function useStyleEffectHide({
45
44
  default: {
46
45
  cleanup();
47
46
 
48
- return () => {};
47
+ return noop;
49
48
  }
50
49
  }
51
50
  }
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable no-param-reassign */
2
2
 
3
- import { listenOnce, requestNextFrame } from "../utils";
3
+ import { globalVars } from "../theme.css";
4
+ import { listenOnce, noop, requestNextFrame } from "../utils";
4
5
  import { useStyleEffect } from "./useStyleEffect";
5
6
 
6
7
  export const OFFSET_PX_ANDROID = 32;
@@ -51,7 +52,7 @@ export function useStyleEffectOffset({
51
52
  return;
52
53
  }
53
54
 
54
- ref.current.style.transition = `var(--stackflow-transition-duration)`;
55
+ ref.current.style.transition = globalVars.transitionDuration;
55
56
  ref.current.style.transform = transform;
56
57
  });
57
58
 
@@ -62,7 +63,7 @@ export function useStyleEffectOffset({
62
63
  };
63
64
  case "enter-active":
64
65
  default:
65
- return () => {};
66
+ return noop;
66
67
  }
67
68
  }
68
69
  case "exit-active":
@@ -71,10 +72,10 @@ export function useStyleEffectOffset({
71
72
  cleanup();
72
73
  });
73
74
 
74
- return () => {};
75
+ return noop;
75
76
  }
76
77
  default: {
77
- return () => {};
78
+ return noop;
78
79
  }
79
80
  }
80
81
  }
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable no-param-reassign */
2
2
 
3
- import { listenOnce } from "../utils";
3
+ import { globalVars } from "../theme.css";
4
+ import { listenOnce, noop } from "../utils";
4
5
  import { useStyleEffect } from "./useStyleEffect";
5
6
  import { OFFSET_PX_CUPERTINO } from "./useStyleEffectOffset";
6
7
 
@@ -27,11 +28,11 @@ export function useStyleEffectSwipeBack({
27
28
  effect: hasEffect
28
29
  ? ({ refs }) => {
29
30
  if (theme !== "cupertino") {
30
- return () => {};
31
+ return noop;
31
32
  }
32
33
 
33
34
  if (!dimRef.current || !edgeRef.current || !paperRef.current) {
34
- return () => {};
35
+ return noop;
35
36
  }
36
37
 
37
38
  const $dim = dimRef.current;
@@ -101,19 +102,18 @@ export function useStyleEffectSwipeBack({
101
102
  return new Promise((resolve) => {
102
103
  requestAnimationFrame(() => {
103
104
  $dim.style.opacity = `${swiped ? 0 : 1}`;
104
- $dim.style.transition = "var(--stackflow-transition-duration)";
105
+ $dim.style.transition = globalVars.transitionDuration;
105
106
 
106
107
  $paper.style.overflowY = "hidden";
107
108
  $paper.style.transform = `translateX(${swiped ? "100%" : "0"})`;
108
- $paper.style.transition =
109
- "var(--stackflow-transition-duration)";
109
+ $paper.style.transition = globalVars.transitionDuration;
110
110
 
111
111
  refs.forEach((ref) => {
112
112
  if (!ref.current) {
113
113
  return;
114
114
  }
115
115
 
116
- ref.current.style.transition = `var(--stackflow-transition-duration)`;
116
+ ref.current.style.transition = globalVars.transitionDuration;
117
117
  ref.current.style.transform = `translate3d(${
118
118
  swiped ? "0" : `-${OFFSET_PX_CUPERTINO / 16}rem`
119
119
  }, 0, 0)`;
package/src/theme.css.ts CHANGED
@@ -9,6 +9,7 @@ export const globalVars = createGlobalThemeContract(
9
9
  {
10
10
  backgroundColor: "background-color",
11
11
  dimBackgroundColor: "dim-background-color",
12
+ transitionDuration: "transition-duration",
12
13
  appBar: {
13
14
  borderColor: "app-bar-border-color",
14
15
  borderSize: "app-bar-border-size",
@@ -18,6 +19,7 @@ export const globalVars = createGlobalThemeContract(
18
19
  iconColor: "app-bar-icon-color",
19
20
  textColor: "app-bar-text-color",
20
21
  backgroundColor: "app-bar-background-color",
22
+ overflow: "app-bar-overflow",
21
23
  },
22
24
  bottomSheet: {
23
25
  borderRadius: "bottom-sheet-border-radius",
@@ -35,15 +37,17 @@ export type GlobalVars = InferVars<typeof globalVars>;
35
37
  const defaultVars = {
36
38
  backgroundColor: "#fff",
37
39
  dimBackgroundColor: "rgba(0, 0, 0, 0.15)",
40
+ transitionDuration: "0ms",
38
41
  appBar: {
39
42
  borderColor: "rgba(0, 0, 0, 0.07)",
40
43
  borderSize: "1px",
41
44
  height: "3.5rem",
42
- heightTransitionDuration: "275ms",
45
+ heightTransitionDuration: "0ms",
43
46
  minHeight: "3.5rem",
44
47
  iconColor: "#212124",
45
48
  textColor: "#212124",
46
49
  backgroundColor: "#fff",
50
+ overflow: "hidden",
47
51
  },
48
52
  bottomSheet: {
49
53
  borderRadius: "1rem",
@@ -1,5 +1,7 @@
1
1
  export * from "./compact";
2
2
  export * from "./compactMap";
3
+ export * from "./isBrowser";
4
+ export * from "./isServer";
3
5
  export * from "./last";
4
6
  export * from "./listenOnce";
5
7
  export * from "./listenResize";
@@ -0,0 +1,9 @@
1
+ import { isServer } from "./isServer";
2
+
3
+ /**
4
+ * @description
5
+ * 현재 JS 런타임이 브라우저 환경인지 확인해요.
6
+ */
7
+ export function isBrowser() {
8
+ return !isServer();
9
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @description
3
+ * 현재 JS 런타임이 서버 환경인지 확인해요.
4
+ */
5
+ export function isServer() {
6
+ return typeof window === "undefined";
7
+ }