A simple stack system inspired by SwiftUI for React.
npm install react-swiftstacksA simple, flexible stack layout system for React inspired by SwiftUI. Build complex layouts with clean, declarative
components.
``bash`
npm install react-swiftstacks
or
`bash`
yarn add react-swiftstacks
- 🎯 SwiftUI-inspired API - Familiar design patterns from SwiftUI
- 📦 Three Layout Components - HStack, VStack, and ZStack
- 🎨 Flexible Styling - Works with standard CSS, CSS modules, and inline styles
- 📏 Built-in Spacing Scale - Consistent spacing tokens out of the box
- 🔧 Fully Typed - Written in TypeScript with complete type definitions
- 🪶 Lightweight - Minimal bundle size with zero dependencies
`jsx
import {HStack, VStack, ZStack} from "react-swiftstacks";
function App() {
return (
Welcome
);
}
`
A horizontal stack that arranges its children in a horizontal line.
A vertical stack that arranges its children in a vertical line.
A z-axis stack that overlays its children on top of each other.
All stack components accept standard div attributes like className and style, plus the following props:
- gap: SpacingKey | number | stringZStack
- Controls the space between children. (Not available on )align
- : 'start' | 'center' | 'end' | 'stretch'VStack
- Controls alignment on the cross-axis (perpendicular to the stack direction)
- In : controls horizontal alignment (left/center/right)HStack
- In : controls vertical alignment (top/center/bottom)stretch
- ( is the default for VStack)justify
- : 'start' | 'center' | 'end' | 'between' | 'around'VStack
- Controls alignment on the main-axis (along the stack direction)
- In : controls vertical alignment (top/center/bottom)HStack
- In : controls horizontal alignment (left/center/right)textAlign
- : 'left' | 'center' | 'right'text-align
- Sets the property for the stack, inherited by all childrenmargin
- : SpacingKey | number | stringpadding
- Sets the margin around the component
- : SpacingKey | number | stringflexGrow
- Sets the padding inside the component
- : booleanZStack
- Allows the stack to grow and fill available space (Not available on )
- wrap: boolean
- Allows children to wrap to the next line if they exceed the container width
- center: boolean
- A shortcut to center all children both horizontally and vertically within the stack
These props follow CSS flexbox semantics, not SwiftUI semantics. This can feel counterintuitive at first:
- align → maps to align-items (cross-axis)justify
- → maps to justify-content (main-axis)
Quick Reference:
| Component | align controls | justify controls |VStack
|-----------|---------------------|---------------------|
| | Horizontal (x-axis) | Vertical (y-axis) |HStack
| | Vertical (y-axis) | Horizontal (x-axis) |
Why this way? To maintain consistency with CSS flexbox standards, making it easier to integrate with the broader web
ecosystem. Once you internalize the axis model, it becomes second nature.
The gap, margin, and padding props can accept a spacing key for standardized sizing.
- xs: '0.25rem' (4px)sm
- : '0.5rem' (8px)md
- : '1rem' (16px)lg
- : '1.5rem' (24px)xl
- : '2rem' (32px)
`jsx
import {HStack, VStack, ZStack} from "react-swiftstacks";
export const ProfileCard = () => (
align="center" // Centers horizontally (cross-axis in VStack)
justify="start" // Aligns to top (main-axis in VStack)
padding="lg"
style={{width: "300px", border: "1px solid #ccc", borderRadius: "8px"}}
>
align="center" // Centers vertically (cross-axis in HStack)
style={{width: "100%"}}
>
John Doe
![]()
src="/avatar.png"
alt="avatar"
style={{borderRadius: "50%", width: "100px", height: "100px"}}
/>
Bio: Building cool things with React.
);
``
MIT © Ednan Rogério Frizzera Filho