Skip to content

Commit 658c770

Browse files
feat(plugin-basic-ui): Allow css customization for components (#615)
1 parent 7db7958 commit 658c770

File tree

8 files changed

+44
-19
lines changed

8 files changed

+44
-19
lines changed

.changeset/tender-ghosts-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stackflow/plugin-basic-ui": minor
3+
---
4+
5+
Allow components style to be customized directly

.pnp.cjs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/plugin-basic-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"@vanilla-extract/css": "^1.15.3",
3737
"@vanilla-extract/dynamic": "^2.1.1",
3838
"@vanilla-extract/private": "^1.0.5",
39-
"@vanilla-extract/recipes": "^0.5.3"
39+
"@vanilla-extract/recipes": "^0.5.3",
40+
"clsx": "^2.1.1"
4041
},
4142
"devDependencies": {
4243
"@stackflow/core": "^1.2.0",

extensions/plugin-basic-ui/src/components/AppBar.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
useNullableActivity,
77
} from "@stackflow/react-ui-core";
88
import { assignInlineVars } from "@vanilla-extract/dynamic";
9+
import clsx from "clsx";
910
import { forwardRef, useRef } from "react";
1011
import { IconBack, IconClose } from "../assets";
1112
import { useGlobalOptions } from "../basicUIPlugin";
@@ -61,6 +62,7 @@ type AppBarProps = Partial<
6162
activityEnterStyle?: "slideInLeft";
6263
onTopClick?: (e: React.MouseEvent) => void;
6364
enterStyle?: "cover";
65+
className?: string;
6466
};
6567
const AppBar = forwardRef<HTMLDivElement, AppBarProps>(
6668
(
@@ -90,6 +92,7 @@ const AppBar = forwardRef<HTMLDivElement, AppBarProps>(
9092
backgroundImageTransitionDuration,
9193
onTopClick,
9294
enterStyle,
95+
className,
9396
},
9497
ref,
9598
) => {
@@ -280,12 +283,15 @@ const AppBar = forwardRef<HTMLDivElement, AppBarProps>(
280283
return (
281284
<div
282285
ref={ref}
283-
className={css.appBar({
284-
border,
285-
modalPresentationStyle,
286-
activityEnterStyle,
287-
enterStyle,
288-
})}
286+
className={clsx(
287+
css.appBar({
288+
border,
289+
modalPresentationStyle,
290+
activityEnterStyle,
291+
enterStyle,
292+
}),
293+
className,
294+
)}
289295
style={assignInlineVars(
290296
compactMap({
291297
[globalVars.appBar.iconColor]: iconColor,

extensions/plugin-basic-ui/src/components/AppScreen.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
useZIndexBase,
1212
} from "@stackflow/react-ui-core";
1313
import { assignInlineVars } from "@vanilla-extract/dynamic";
14+
import clsx from "clsx";
1415
import { createContext, useContext, useMemo, useRef } from "react";
1516
import { useGlobalOptions } from "../basicUIPlugin";
1617
import type { GlobalVars } from "../basicUIPlugin.css";
@@ -48,6 +49,7 @@ export type AppScreenProps = Partial<
4849
preventSwipeBack?: boolean;
4950
CUPERTINO_ONLY_modalPresentationStyle?: "fullScreen";
5051
ANDROID_ONLY_activityEnterStyle?: "slideInLeft";
52+
className?: string;
5153
children: React.ReactNode;
5254
};
5355
const AppScreen: React.FC<AppScreenProps> = ({
@@ -58,6 +60,7 @@ const AppScreen: React.FC<AppScreenProps> = ({
5860
preventSwipeBack,
5961
CUPERTINO_ONLY_modalPresentationStyle,
6062
ANDROID_ONLY_activityEnterStyle,
63+
className,
6164
children,
6265
}) => {
6366
const globalOptions = useGlobalOptions();
@@ -231,12 +234,7 @@ const AppScreen: React.FC<AppScreenProps> = ({
231234
>
232235
<div
233236
ref={appScreenRef}
234-
className={css.appScreen({
235-
transitionState:
236-
transitionState === "enter-done" || transitionState === "exit-done"
237-
? transitionState
238-
: lazyTransitionState,
239-
})}
237+
className={clsx(css.appScreen({ transitionState }), className)}
240238
style={assignInlineVars(
241239
compactMap({
242240
[globalVars.backgroundColor]: backgroundColor,

extensions/plugin-basic-ui/src/components/BottomSheet.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
useStyleEffect,
1010
useZIndexBase,
1111
} from "@stackflow/react-ui-core";
12+
import clsx from "clsx";
1213
import type { GlobalVars } from "../basicUIPlugin.css";
1314
import { globalVars } from "../basicUIPlugin.css";
1415
import { compactMap } from "../utils";
@@ -21,6 +22,7 @@ export type BottomSheetProps = Partial<
2122
paperRef?: React.Ref<HTMLDivElement>;
2223
onOutsideClick?: React.MouseEventHandler;
2324
children: React.ReactNode;
25+
className?: string;
2426
};
2527
const BottomSheet: React.FC<BottomSheetProps> = ({
2628
borderRadius = "1rem",
@@ -30,6 +32,7 @@ const BottomSheet: React.FC<BottomSheetProps> = ({
3032
paperRef,
3133
onOutsideClick,
3234
children,
35+
className,
3336
}) => {
3437
const activity = useNullableActivity();
3538
const { pop } = useActions();
@@ -80,9 +83,12 @@ const BottomSheet: React.FC<BottomSheetProps> = ({
8083

8184
return (
8285
<div
83-
className={css.container({
84-
transitionState: useLazy(transitionState),
85-
})}
86+
className={clsx(
87+
css.container({
88+
transitionState: useLazy(transitionState),
89+
}),
90+
className,
91+
)}
8692
ref={containerRef}
8793
style={assignInlineVars(
8894
compactMap({

extensions/plugin-basic-ui/src/components/Modal.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
useStyleEffect,
1010
useZIndexBase,
1111
} from "@stackflow/react-ui-core";
12+
import clsx from "clsx";
1213
import type { GlobalVars } from "../basicUIPlugin.css";
1314
import { globalVars } from "../basicUIPlugin.css";
1415
import { compactMap } from "../utils";
@@ -20,6 +21,7 @@ export type ModalProps = Partial<
2021
Partial<GlobalVars["modal"]> & {
2122
onOutsideClick?: React.MouseEventHandler;
2223
children: React.ReactNode;
24+
className?: string;
2325
};
2426
const Modal: React.FC<ModalProps> = ({
2527
backgroundColor,
@@ -29,6 +31,7 @@ const Modal: React.FC<ModalProps> = ({
2931
maxWidth,
3032
onOutsideClick,
3133
children,
34+
className,
3235
}) => {
3336
const activity = useNullableActivity();
3437
const { pop } = useActions();
@@ -79,9 +82,12 @@ const Modal: React.FC<ModalProps> = ({
7982

8083
return (
8184
<div
82-
className={css.container({
83-
transitionState: useLazy(transitionState),
84-
})}
85+
className={clsx(
86+
css.container({
87+
transitionState: useLazy(transitionState),
88+
}),
89+
className,
90+
)}
8591
ref={containerRef}
8692
style={assignInlineVars(
8793
compactMap({

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5298,6 +5298,7 @@ __metadata:
52985298
"@vanilla-extract/dynamic": "npm:^2.1.1"
52995299
"@vanilla-extract/private": "npm:^1.0.5"
53005300
"@vanilla-extract/recipes": "npm:^0.5.3"
5301+
clsx: "npm:^2.1.1"
53015302
esbuild: "npm:^0.23.0"
53025303
react: "npm:^18.3.1"
53035304
rimraf: "npm:^3.0.2"

0 commit comments

Comments
 (0)