ZeroCSS Quick Reference
ZeroCSS Quick Import
Section titled “ZeroCSS Quick Import”// Traditional imports (current stable)import { zero } from "@streamplace/components";{ atoms, bg, text, m, mt, mr, mb, ml, mx, my, p, pt, pr, pb, pl, px, py, w, h, r, layout, borders, flex, gap} = zero
Common Patterns
Section titled “Common Patterns”Flex Layout
Section titled “Flex Layout”// Traditional importsstyle={[layout.flex.row, layout.flex.center]}style={[layout.flex.column, layout.flex.spaceBetween]}style={[flex.values[1]]}
// ZeroCSS namespacestyle={[zero.layout.flex.row, zero.layout.flex.center]}style={[zero.layout.flex.column, zero.layout.flex.spaceBetween]}style={[zero.flex.values[1]]}
Spacing
Section titled “Spacing”// Marginm[4]; // all sides: 16pxmt[2]; // top: 8pxmx[3]; // horizontal: 12pxmy[4]; // vertical: 16px
// Paddingp[4]; // all sides: 16pxpt[2]; // top: 8pxpx[3]; // horizontal: 12pxpy[4]; // vertical: 16px
// Gap (React Native 0.71+)gap.all[4]; // gap: 16pxgap.row[2]; // rowGap: 8pxgap.column[3]; // columnGap: 12px
Colors
Section titled “Colors”// Backgroundbg.white; // whitebg.gray[100]; // light graybg.primary[500]; // brand primarybg.destructive[500]; // error red
// Texttext.gray[900]; // dark texttext.primary[600]; // primary texttext.white; // white text
// Bordersborders.color.gray[300]; // border colorborders.width.thin; // 1px border
Sizing
Section titled “Sizing”// Fixed sizesw[10]; // width: 40pxh[20]; // height: 80px
// Percentagew.percent[100]; // width: 100%h.percent[50]; // height: 50%
// Min/maxsizes.minWidth[20]; // minWidth: 80pxsizes.maxHeight[64]; // maxHeight: 256px
Positioning
Section titled “Positioning”// Absolute positioninglayout.position.absolute;position.top[4]; // top: 16pxposition.right[0]; // right: 0pxposition.bottom[2]; // bottom: 8pxposition.left[4]; // left: 16px
// Common layoutslayouts.fullScreen; // fill entire screenlayouts.centered; // centered contentlayouts.overlay; // modal overlay
Borders & Radius
Section titled “Borders & Radius”// Border radiusr[2]; // borderRadius: 8px
// Bordersborders.width.thin; // borderWidth: 1pxborders.style.solid; // borderStyle: solidborders.color.gray[300]; // borderColor: #d4d4d4
// Directional bordersborders.top.width.thin; // borderTopWidth: 1pxborders.bottom.color.gray[200]; // borderBottomColor: #e5e5e5
Spacing Scale
Section titled “Spacing Scale”spacing[0]; // 0pxspacing[1]; // 4pxspacing[2]; // 8pxspacing[3]; // 12pxspacing[4]; // 16pxspacing[5]; // 20pxspacing[6]; // 24pxspacing[8]; // 32pxspacing[10]; // 40pxspacing[12]; // 48pxspacing[16]; // 64pxspacing[20]; // 80px
Color Palette
Section titled “Color Palette”Grayscale
Section titled “Grayscale”gray[50]; // #fafafa (lightest)gray[100]; // #f5f5f5gray[200]; // #e5e5e5gray[300]; // #d4d4d4gray[400]; // #a3a3a3gray[500]; // #737373gray[600]; // #525252gray[700]; // #404040gray[800]; // #262626gray[900]; // #171717 (darkest)
Primary Colors
Section titled “Primary Colors”primary[100]; // #dbeafe (light)primary[500]; // #3b82f6 (main)primary[700]; // #1d4ed8 (dark)
Semantic Colors
Section titled “Semantic Colors”success[500]; // #22c55ewarning[500]; // #f59e0bdestructive[500]; // #ef4444
Component Examples
Section titled “Component Examples”// Traditional imports<View style={[ bg.white, borders.width.thin, borders.color.gray[200], r[2], p[4], shadows.sm]} />
// ZeroCSS namespace<View style={[ zero.bg.white, zero.borders.width.thin, zero.borders.color.gray[200], zero.r[2], zero.p[4], zero.shadows.sm]} />
Button
Section titled “Button”// Traditional imports<Pressable style={[ layout.flex.center, bg.primary[500], px[4], py[2], r[1]]}> <Text style={[text.white]}>Button</Text></Pressable>
// ZeroCSS namespace<Pressable style={[ zero.layout.flex.center, zero.bg.primary[500], zero.px[4], zero.py[2], zero.r[1]]}> <Text style={[zero.text.white]}>Button</Text></Pressable>
<View style={[layouts.overlay]}> <View style={[bg.white, r[3], p[6], mx[4], shadows.xl]}> {/* Modal content */} </View></View>
List Item
Section titled “List Item”<View style={[ layout.flex.row, layout.flex.spaceBetween, layout.flex.alignCenter, px[4], py[3], borders.bottom.width.thin, borders.bottom.color.gray[200], ]}> <Text>Item</Text> <Text style={[text.gray[500]]}>Value</Text></View>
Header
Section titled “Header”<View style={[ layout.flex.row, layout.flex.spaceBetween, layout.flex.alignCenter, bg.white, px[4], py[3], borders.bottom.width.thin, borders.bottom.color.gray[200], ]}> <Text style={[text.gray[900], fontSize.lg]}>Title</Text> <Pressable> <Text style={[text.primary[600]]}>Action</Text> </Pressable></View>
ZeroCSS Responsive Usage
Section titled “ZeroCSS Responsive Usage”// Traditional importimport { responsiveValue } from "@streamplace/components";import { useWindowDimensions } from "react-native";
// ZeroCSS namespaceimport * as zero from "@streamplace/components/zero";
const { width } = useWindowDimensions();
// Traditional usageconst padding = responsiveValue( { sm: 8, md: 16, lg: 24, xl: 32, default: 8, }, width,);
// ZeroCSS namespace usageconst padding = zero.responsiveValue( { sm: 8, md: 16, lg: 24, xl: 32, default: 8, }, width,);
ZeroCSS Platform Specific
Section titled “ZeroCSS Platform Specific”// Traditional importimport { platformStyle } from "@streamplace/components";
// ZeroCSS namespaceimport * as zero from "@streamplace/components/zero";
// Traditional usageconst shadowStyles = platformStyle({ ios: { shadowColor: "#000", shadowOffset: { width: 0, height: 2 } }, android: { elevation: 4 }, web: { boxShadow: "0 2px 4px rgba(0,0,0,0.1)" }, default: {},});
// ZeroCSS namespace usageconst shadowStyles = zero.platformStyle({ ios: { shadowColor: "#000", shadowOffset: { width: 0, height: 2 } }, android: { elevation: 4 }, web: { boxShadow: "0 2px 4px rgba(0,0,0,0.1)" }, default: {},});
ZeroCSS Animation Support
Section titled “ZeroCSS Animation Support”import Animated, { useAnimatedStyle } from "react-native-reanimated";
const animatedStyle = useAnimatedStyle(() => ({ opacity: opacity.value,}));
<Animated.View style={[bg.white, p[4], r[2], animatedStyle]} />;
Debugging Tips
Section titled “Debugging Tips”- Check style order: Later styles override earlier ones
- Use arrays:
[style1, style2, conditionalStyle]
- Inspect with Flipper: Use React Native Debugger
- Test on device: Simulator styles may differ
Performance Tips
Section titled “Performance Tips”- Cache style arrays: Don’t create new arrays each render
- Use conditional arrays:
[baseStyles, ...(condition ? activeStyles : [])]
- Prefer ZeroCSS atoms: They’re pre-optimized and cached
- Avoid dynamic styles: Use conditional arrays instead
ZeroCSS Theme Usage
Section titled “ZeroCSS Theme Usage”Theme Provider Setup
Section titled “Theme Provider Setup”import { ThemeProvider } from "@streamplace/components";
<ThemeProvider defaultTheme="system"> <YourApp /></ThemeProvider>;
Using Theme Hook
Section titled “Using Theme Hook”import { useTheme } from "@streamplace/components";
function ThemedComponent() { const { theme, isDark, setTheme } = useTheme();
return ( <View style={{ backgroundColor: theme.colors.background, padding: theme.spacing[4], }} > <Text style={{ color: theme.colors.text }}> Theme: {isDark ? "Dark" : "Light"} </Text> </View> );}
Theme-Aware Styles
Section titled “Theme-Aware Styles”import { createThemedStyles } from "@streamplace/components";
const useStyles = createThemedStyles((theme) => ({ button: { backgroundColor: theme.colors.primary, borderRadius: theme.borderRadius.md, padding: theme.spacing[3], },}));
function Button() { const styles = useStyles(); return <Pressable style={styles.button} />;}
Theme Switching
Section titled “Theme Switching”function ThemeToggle() { const { currentTheme, setTheme, toggleTheme } = useTheme();
return ( <Pressable onPress={toggleTheme}> <Text>Current: {currentTheme}</Text> </Pressable> );}
Custom Theme Injection
Section titled “Custom Theme Injection”Custom Theme Provider
Section titled “Custom Theme Provider”import { createContext, useContext, useMemo, useState } from "react";import { useColorScheme } from "react-native";import { ThemeProvider as BaseThemeProvider } from "@streamplace/components";
const CustomThemeContext = createContext(null);
export function CustomThemeProvider({ children, lightTheme, darkTheme, defaultTheme = "system",}) { const systemColorScheme = useColorScheme(); const [currentTheme, setCurrentTheme] = useState(defaultTheme);
const activeTheme = useMemo(() => { const isDark = currentTheme === "dark" || (currentTheme === "system" && systemColorScheme === "dark"); return isDark ? darkTheme : lightTheme; }, [currentTheme, systemColorScheme, lightTheme, darkTheme]);
const value = { theme: activeTheme, isDark: activeTheme === darkTheme, currentTheme, setTheme: setCurrentTheme, };
return ( <CustomThemeContext.Provider value={value}> <BaseThemeProvider defaultTheme={currentTheme}> {children} </BaseThemeProvider> </CustomThemeContext.Provider> );}
export function useCustomTheme() { return useContext(CustomThemeContext);}
Using Custom Themes
Section titled “Using Custom Themes”const myLightTheme = { colors: { primary: "#ff6b6b", background: "#fff" }, spacing: { /* custom spacing */ },};
const myDarkTheme = { colors: { primary: "#ff8787", background: "#1a1a1a" }, spacing: { /* custom spacing */ },};
function App() { return ( <CustomThemeProvider lightTheme={myLightTheme} darkTheme={myDarkTheme}> <YourApp /> </CustomThemeProvider> );}
function Component() { const { theme, isDark } = useCustomTheme();
return ( <View style={{ backgroundColor: theme.colors.background, borderColor: theme.colors.primary, }} > <Text>Custom theme active!</Text> </View> );}