Skip to content

Commit 90c3e1a

Browse files
committed
feat: introduce typed access for component-scoped css variables
1 parent d9d561e commit 90c3e1a

File tree

3 files changed

+82
-34
lines changed

3 files changed

+82
-34
lines changed

examples/stackflow-spa/src/activities/ActivityHome.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
import { VStack, useSnackbarAdapter } from "@seed-design/react";
1+
import { IconBellFill, IconPlusFill } from "@karrotmarket/react-monochrome-icon";
2+
import {
3+
ContextualFloatingButton,
4+
Fab,
5+
Float,
6+
PrefixIcon,
7+
VStack,
8+
useSnackbarAdapter,
9+
} from "@seed-design/react";
10+
import { AppScreenLayer } from "@seed-design/stackflow";
211
import { receive } from "@stackflow/compat-await-push";
312
import type { ActivityComponentType } from "@stackflow/react";
13+
import { useState } from "react";
414
import { List, ListItem, ListItemGroup } from "../components/List";
515
import { AppBar, AppBarMain } from "../seed-design/stackflow/AppBar";
616
import { AppScreen, AppScreenContent } from "../seed-design/stackflow/AppScreen";
@@ -26,6 +36,8 @@ const ActivityHome: ActivityComponentType = () => {
2636
const { dialogProps, setOpen } = useStepDialog();
2737
const snackbarAdapter = useSnackbarAdapter();
2838

39+
const [isFabExtended, setIsFabExtended] = useState(true);
40+
2941
return (
3042
<AppScreen>
3143
<AppBar>
@@ -160,6 +172,23 @@ const ActivityHome: ActivityComponentType = () => {
160172
/>
161173
</List>
162174
</AppScreenContent>
175+
<Float placement="bottom-center" offsetY="16px" zIndex={AppScreenLayer.vars.zIndex}>
176+
<ContextualFloatingButton>
177+
<PrefixIcon svg={<IconBellFill />} />
178+
알림 설정
179+
</ContextualFloatingButton>
180+
</Float>
181+
<Float
182+
placement="bottom-end"
183+
offsetX="16px"
184+
offsetY="16px"
185+
zIndex={AppScreenLayer.vars.zIndex}
186+
>
187+
<Fab.Root extended={isFabExtended} onClick={() => setIsFabExtended(!isFabExtended)}>
188+
<Fab.Icon svg={<IconPlusFill />} />
189+
<Fab.Label>글쓰기</Fab.Label>
190+
</Fab.Root>
191+
</Float>
163192
</AppScreen>
164193
);
165194
};

packages/stackflow/src/components/AppBar/AppBar.tsx

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,37 @@ export const AppBarPropsProvider = PropsProvider;
2121

2222
export interface AppBarProps extends AppBarVariantProps, AppBarPrimitive.RootProps {}
2323

24-
export const AppBarRoot = forwardRef<HTMLDivElement, AppBarProps>((props, ref) => {
25-
const contextProps = useProps();
26-
const [variantProps, otherProps] = appBar.splitVariantProps({ ...contextProps, ...props });
27-
28-
const classNames = appBar(variantProps);
29-
30-
return (
31-
<ClassNamesProvider value={classNames}>
32-
<MainPropsProvider
33-
value={{
34-
theme: variantProps.theme,
35-
transitionStyle: variantProps.transitionStyle,
36-
tone: variantProps.tone,
37-
}}
38-
>
39-
<AppBarPrimitive.Root
40-
ref={ref}
41-
{...mergeProps({ className: classNames.root }, otherProps)}
42-
/>
43-
</MainPropsProvider>
44-
</ClassNamesProvider>
45-
);
46-
});
47-
AppBarRoot.displayName = "AppBarRoot";
24+
export const AppBarRoot = Object.assign(
25+
forwardRef<HTMLDivElement, AppBarProps>((props, ref) => {
26+
const contextProps = useProps();
27+
const [variantProps, otherProps] = appBar.splitVariantProps({ ...contextProps, ...props });
28+
29+
const classNames = appBar(variantProps);
30+
31+
return (
32+
<ClassNamesProvider value={classNames}>
33+
<MainPropsProvider
34+
value={{
35+
theme: variantProps.theme,
36+
transitionStyle: variantProps.transitionStyle,
37+
tone: variantProps.tone,
38+
}}
39+
>
40+
<AppBarPrimitive.Root
41+
ref={ref}
42+
{...mergeProps({ className: classNames.root }, otherProps)}
43+
/>
44+
</MainPropsProvider>
45+
</ClassNamesProvider>
46+
);
47+
}),
48+
{
49+
displayName: "AppBarRoot",
50+
vars: {
51+
zIndex: "var(--z-index-app-bar)",
52+
},
53+
},
54+
);
4855

4956
export interface AppBarLeftProps extends AppBarPrimitive.LeftProps {}
5057

packages/stackflow/src/components/AppScreen/AppScreen.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,33 @@ AppScreenRoot.displayName = "AppScreenRoot";
4545

4646
export interface AppScreenDimProps extends AppScreenPrimitive.DimProps {}
4747

48-
export const AppScreenDim = withContext<HTMLDivElement, AppScreenDimProps>(
49-
AppScreenPrimitive.Dim,
50-
"dim",
48+
export const AppScreenDim = Object.assign(
49+
withContext<HTMLDivElement, AppScreenDimProps>(AppScreenPrimitive.Dim, "dim"),
50+
{
51+
vars: {
52+
zIndex: "var(--z-index-dim)",
53+
},
54+
},
5155
);
5256

5357
export interface AppScreenEdgeProps extends AppScreenPrimitive.EdgeProps {}
5458

55-
export const AppScreenEdge = withContext<HTMLDivElement, AppScreenEdgeProps>(
56-
AppScreenPrimitive.Edge,
57-
"edge",
59+
export const AppScreenEdge = Object.assign(
60+
withContext<HTMLDivElement, AppScreenEdgeProps>(AppScreenPrimitive.Edge, "edge"),
61+
{
62+
vars: {
63+
zIndex: "var(--z-index-edge)",
64+
},
65+
},
5866
);
5967

6068
export interface AppScreenLayerProps extends AppScreenPrimitive.LayerProps {}
6169

62-
export const AppScreenLayer = withContext<HTMLDivElement, AppScreenLayerProps>(
63-
AppScreenPrimitive.Layer,
64-
"layer",
70+
export const AppScreenLayer = Object.assign(
71+
withContext<HTMLDivElement, AppScreenLayerProps>(AppScreenPrimitive.Layer, "layer"),
72+
{
73+
vars: {
74+
zIndex: "var(--z-index-layer)",
75+
},
76+
},
6577
);

0 commit comments

Comments
 (0)