Skip to content

Commit d1f8e29

Browse files
feat(plugin-basic-ui): remove div wrapper in plugin-basic-ui
1 parent 46ac359 commit d1f8e29

File tree

5 files changed

+111
-104
lines changed

5 files changed

+111
-104
lines changed

extensions/plugin-basic-ui/src/basicUIPlugin.css.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {
22
createGlobalTheme,
33
createGlobalThemeContract,
4-
createTheme,
54
} from "@vanilla-extract/css";
6-
import { recipe } from "@vanilla-extract/recipes";
75

86
const GLOBAL_VARS = {
97
backgroundColor: "background-color",
@@ -81,13 +79,6 @@ const cupertinoValues: GlobalVars = {
8179
},
8280
};
8381

84-
export const android = createTheme(globalVars, {
85-
...androidValues,
86-
});
87-
export const cupertino = createTheme(globalVars, {
88-
...cupertinoValues,
89-
});
90-
9182
createGlobalTheme(
9283
":root[data-stackflow-plugin-basic-ui-theme=cupertino]",
9384
globalVars,
@@ -98,18 +89,3 @@ createGlobalTheme(
9889
globalVars,
9990
androidValues,
10091
);
101-
102-
export const stackWrapper = recipe({
103-
base: {},
104-
variants: {
105-
theme: {
106-
android,
107-
cupertino,
108-
},
109-
loading: {
110-
true: {
111-
pointerEvents: "none",
112-
},
113-
},
114-
},
115-
});

extensions/plugin-basic-ui/src/basicUIPlugin.tsx

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { assignInlineVars } from "@vanilla-extract/dynamic";
33
import { createContext, useContext } from "react";
44

55
import * as css from "./basicUIPlugin.css";
6+
import { RootStyles } from "./components/RootStyles";
67
import type { RecursivePartial } from "./utils";
7-
import { compact, compactMap, isBrowser } from "./utils";
8+
import { compactMap } from "./utils";
89

910
type BasicUIPluginOptions = RecursivePartial<css.GlobalVars> & {
1011
theme: "android" | "cupertino";
@@ -50,46 +51,46 @@ export const basicUIPlugin: (
5051
const _options =
5152
typeof options === "function" ? options({ initialContext }) : options;
5253

54+
/**
55+
* Assign CSS Variables
56+
*/
57+
const styles: { [key: string]: string | undefined } = assignInlineVars(
58+
compactMap({
59+
[css.globalVars.backgroundColor]: _options.backgroundColor,
60+
[css.globalVars.dimBackgroundColor]: _options.dimBackgroundColor,
61+
[css.globalVars.transitionDuration]: `${stack.transitionDuration}ms`,
62+
[css.globalVars.computedTransitionDuration]:
63+
stack.globalTransitionState === "loading"
64+
? `${stack.transitionDuration}ms`
65+
: "0ms",
66+
[css.globalVars.appBar.borderColor]: _options.appBar?.borderColor,
67+
[css.globalVars.appBar.borderSize]: _options.appBar?.borderSize,
68+
[css.globalVars.appBar.height]: _options.appBar?.height,
69+
[css.globalVars.appBar.iconColor]: _options.appBar?.iconColor,
70+
[css.globalVars.appBar.textColor]: _options.appBar?.textColor,
71+
[css.globalVars.appBar.minSafeAreaInsetTop]:
72+
_options.appBar?.minSafeAreaInsetTop,
73+
[css.globalVars.bottomSheet.borderRadius]:
74+
_options.bottomSheet?.borderRadius,
75+
[css.globalVars.modal.borderRadius]: _options.modal?.borderRadius,
76+
}),
77+
);
78+
79+
/**
80+
* Prevent pointer events when transitioning
81+
*/
82+
styles["pointer-events"] =
83+
stack.globalTransitionState === "loading" ? "none" : "auto";
84+
5385
return (
5486
<GlobalOptionsProvider
5587
value={{
5688
...options,
5789
theme: initialContext?.theme ?? _options.theme,
5890
}}
5991
>
60-
<div
61-
className={compact([
62-
css.stackWrapper({
63-
theme: initialContext?.theme ?? _options.theme,
64-
loading: stack.globalTransitionState === "loading",
65-
}),
66-
_options.rootClassName,
67-
]).join(" ")}
68-
style={assignInlineVars(
69-
compactMap({
70-
[css.globalVars.backgroundColor]: _options.backgroundColor,
71-
[css.globalVars.dimBackgroundColor]: _options.dimBackgroundColor,
72-
[css.globalVars.transitionDuration]:
73-
`${stack.transitionDuration}ms`,
74-
[css.globalVars.computedTransitionDuration]:
75-
stack.globalTransitionState === "loading"
76-
? `${stack.transitionDuration}ms`
77-
: "0ms",
78-
[css.globalVars.appBar.borderColor]: _options.appBar?.borderColor,
79-
[css.globalVars.appBar.borderSize]: _options.appBar?.borderSize,
80-
[css.globalVars.appBar.height]: _options.appBar?.height,
81-
[css.globalVars.appBar.iconColor]: _options.appBar?.iconColor,
82-
[css.globalVars.appBar.textColor]: _options.appBar?.textColor,
83-
[css.globalVars.appBar.minSafeAreaInsetTop]:
84-
_options.appBar?.minSafeAreaInsetTop,
85-
[css.globalVars.bottomSheet.borderRadius]:
86-
_options.bottomSheet?.borderRadius,
87-
[css.globalVars.modal.borderRadius]: _options.modal?.borderRadius,
88-
}),
89-
)}
90-
>
91-
{stack.render()}
92-
</div>
92+
<RootStyles theme={_options.theme} styles={styles} />
93+
{stack.render()}
9394
</GlobalOptionsProvider>
9495
);
9596
},

extensions/plugin-basic-ui/src/components/AppBar.css.ts

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { style } from "@vanilla-extract/css";
22
import { recipe } from "@vanilla-extract/recipes";
33

4-
import { android, cupertino, globalVars } from "../basicUIPlugin.css";
4+
import { globalVars } from "../basicUIPlugin.css";
55
import { f } from "../styles";
66
import {
77
background,
@@ -40,17 +40,18 @@ export const appBar = recipe({
4040
zIndex: vars.zIndexes.appBar,
4141
transition: transitions(appBarCommonTransition),
4242
selectors: {
43-
[`${cupertino} &`]: {
43+
":root[data-stackflow-plugin-basic-ui-theme=cupertino] &": {
4444
position: "absolute",
4545
},
46-
[`${cupertino} ${exitActive} &`]: {
47-
transform: "translate3d(100%, 0, 0)",
48-
transition: transitions({
49-
...appBarCommonTransition,
50-
transform: "0s",
51-
}),
52-
},
53-
[`${android} &`]: {
46+
[`:root[data-stackflow-plugin-basic-ui-theme=cupertino] ${exitActive} &`]:
47+
{
48+
transform: "translate3d(100%, 0, 0)",
49+
transition: transitions({
50+
...appBarCommonTransition,
51+
transform: "0s",
52+
}),
53+
},
54+
":root[data-stackflow-plugin-basic-ui-theme=android] &": {
5455
opacity: 0,
5556
transform: "translate3d(0, 10rem, 0)",
5657
transition: transitions({
@@ -60,8 +61,8 @@ export const appBar = recipe({
6061
}),
6162
},
6263
[`
63-
${android} ${enterActive} &,
64-
${android} ${enterDone} &
64+
:root[data-stackflow-plugin-basic-ui-theme=android] ${enterActive} &,
65+
:root[data-stackflow-plugin-basic-ui-theme=android] ${enterDone} &
6566
`]: {
6667
opacity: 1,
6768
transform: "translate3d(0, 0, 0)",
@@ -78,7 +79,7 @@ export const appBar = recipe({
7879
modalPresentationStyle: {
7980
fullScreen: {
8081
selectors: {
81-
[`${cupertino} &`]: {
82+
":root[data-stackflow-plugin-basic-ui-theme=cupertino] &": {
8283
transform: "translate3d(0, 100vh, 0)",
8384
transition: transitions({
8485
...appBarCommonTransition,
@@ -87,36 +88,38 @@ export const appBar = recipe({
8788
}),
8889
},
8990
[`
90-
${cupertino} ${enterActive} &,
91-
${cupertino} ${enterDone} &
91+
:root[data-stackflow-plugin-basic-ui-theme=cupertino] ${enterActive} &,
92+
:root[data-stackflow-plugin-basic-ui-theme=cupertino] ${enterDone} &
9293
`]: {
9394
transform: "translate3d(0, 0, 0)",
9495
},
95-
[`${cupertino} ${exitActive} &`]: {
96-
transform: "translate3d(0, 100vh, 0)",
97-
transition: transitions({
98-
...appBarCommonTransition,
99-
transform: vars.transitionDuration,
100-
opacity: vars.transitionDuration,
101-
}),
102-
},
96+
[`:root[data-stackflow-plugin-basic-ui-theme=cupertino] ${exitActive} &`]:
97+
{
98+
transform: "translate3d(0, 100vh, 0)",
99+
transition: transitions({
100+
...appBarCommonTransition,
101+
transform: vars.transitionDuration,
102+
opacity: vars.transitionDuration,
103+
}),
104+
},
103105
},
104106
},
105107
},
106108
activityEnterStyle: {
107109
slideInLeft: {
108110
selectors: {
109-
[`${android} &`]: {
111+
":root[data-stackflow-plugin-basic-ui-theme=android] &": {
110112
opacity: 1,
111113
transform: "translate3d(0, 0, 0)",
112114
},
113-
[`${android} ${exitActive} &`]: {
114-
transform: "translate3d(100%, 0, 0)",
115-
transition: transitions({
116-
...appBarCommonTransition,
117-
transform: "0s",
118-
}),
119-
},
115+
[`:root[data-stackflow-plugin-basic-ui-theme=android] ${exitActive} &`]:
116+
{
117+
transform: "translate3d(100%, 0, 0)",
118+
transition: transitions({
119+
...appBarCommonTransition,
120+
transform: "0s",
121+
}),
122+
},
120123
},
121124
},
122125
},
@@ -189,7 +192,7 @@ export const centerMain = recipe({
189192
color: globalVars.appBar.textColorTransitionDuration,
190193
}),
191194
selectors: {
192-
[`${android} &`]: {
195+
":root[data-stackflow-plugin-basic-ui-theme=android] &": {
193196
width: "100%",
194197
justifyContent: "flex-start",
195198
paddingLeft: "1rem",
@@ -198,7 +201,7 @@ export const centerMain = recipe({
198201
fontWeight: "bold",
199202
boxSizing: "border-box",
200203
},
201-
[`${cupertino} &`]: {
204+
":root[data-stackflow-plugin-basic-ui-theme=cupertino] &": {
202205
position: "absolute",
203206
display: "flex",
204207
alignItems: "center",
@@ -221,7 +224,7 @@ export const centerMain = recipe({
221224
hasLeft: {
222225
true: {
223226
selectors: {
224-
[`${android} &`]: {
227+
":root[data-stackflow-plugin-basic-ui-theme=android] &": {
225228
paddingLeft: "0.375rem",
226229
},
227230
},
@@ -243,7 +246,7 @@ export const centerMainEdge = style([
243246
display: "none",
244247
width: vars.appBar.center.mainWidth,
245248
selectors: {
246-
[`${cupertino} &`]: {
249+
":root[data-stackflow-plugin-basic-ui-theme=cupertino] &": {
247250
display: "block",
248251
},
249252
},
@@ -273,7 +276,7 @@ export const right = style([
273276
display: "none",
274277
},
275278
selectors: {
276-
[`${android} &`]: {
279+
":root[data-stackflow-plugin-basic-ui-theme=android] &": {
277280
padding: "0 0.5rem 0 0",
278281
},
279282
},

extensions/plugin-basic-ui/src/components/AppScreen.css.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createThemeContract, style } from "@vanilla-extract/css";
22
import { recipe } from "@vanilla-extract/recipes";
33

4-
import { android, cupertino, globalVars } from "../basicUIPlugin.css";
4+
import { globalVars } from "../basicUIPlugin.css";
55
import { f } from "../styles";
66

77
export const vars = createThemeContract({
@@ -59,7 +59,7 @@ export const dim = style([
5959
opacity: 0,
6060
zIndex: vars.zIndexes.dim,
6161
selectors: {
62-
[`${android} &`]: {
62+
":root[data-stackflow-plugin-basic-ui-theme=android] &": {
6363
height: "10rem",
6464
background: `linear-gradient(${globalVars.dimBackgroundColor}, rgba(0, 0, 0, 0))`,
6565
},
@@ -92,22 +92,22 @@ export const paper = recipe({
9292
},
9393
zIndex: vars.zIndexes.paper,
9494
selectors: {
95-
[`${cupertino} &`]: {
95+
":root[data-stackflow-plugin-basic-ui-theme=cupertino] &": {
9696
transform: "translate3d(100%, 0, 0)",
9797
},
9898
[`
99-
${cupertino} ${enterActive} &,
100-
${cupertino} ${enterDone} &
99+
:root[data-stackflow-plugin-basic-ui-theme=cupertino] ${enterActive} &,
100+
:root[data-stackflow-plugin-basic-ui-theme=cupertino] ${enterDone} &
101101
`]: {
102102
transform: "translate3d(0, 0, 0)",
103103
},
104-
[`${android} &`]: {
104+
":root[data-stackflow-plugin-basic-ui-theme=android] &": {
105105
opacity: 0,
106106
transform: "translate3d(0, 10rem, 0)",
107107
},
108108
[`
109-
${android} ${enterActive} &,
110-
${android} ${enterDone} &
109+
:root[data-stackflow-plugin-basic-ui-theme=android] ${enterActive} &,
110+
:root[data-stackflow-plugin-basic-ui-theme=android] ${enterDone} &
111111
`]: {
112112
opacity: 1,
113113
transform: "translate3d(0, 0, 0)",
@@ -146,7 +146,7 @@ export const paper = recipe({
146146
modalPresentationStyle: {
147147
fullScreen: {
148148
selectors: {
149-
[`${cupertino} &`]: {
149+
":root[data-stackflow-plugin-basic-ui-theme=cupertino] &": {
150150
transform: "translate3d(0, 100%, 0)",
151151
},
152152
},
@@ -155,7 +155,7 @@ export const paper = recipe({
155155
activityEnterStyle: {
156156
slideInLeft: {
157157
selectors: {
158-
[`${android} &`]: {
158+
":root[data-stackflow-plugin-basic-ui-theme=android] &": {
159159
transform: "translate3d(50%, 0, 0)",
160160
},
161161
},
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useLayoutEffect } from "react";
2+
3+
export type RootStylesProps = {
4+
theme: "android" | "cupertino";
5+
styles: {
6+
[cssVarName: string]: string | undefined;
7+
};
8+
};
9+
export function RootStyles({ theme, styles }: RootStylesProps) {
10+
useLayoutEffect(() => {
11+
const root = document.querySelector(":root") as HTMLHtmlElement;
12+
13+
if (!root) {
14+
return;
15+
}
16+
17+
for (const [key, value] of Object.entries(styles)) {
18+
if (value) {
19+
root.style.setProperty(key, value);
20+
}
21+
}
22+
23+
root.dataset.stackflowPluginBasicUiTheme = theme;
24+
}, [styles, theme]);
25+
26+
return null;
27+
}

0 commit comments

Comments
 (0)