| name | tile |
| description | Chainable React styling library. Use when writing React components with tile-css. |
Tile - Chainable Styling Library
Tile provides chainable methods for styling React components.
Docs: ./docs/
Quick Reference
import { View, Frame, HStack, VStack, Grid, style } from 'tile-css'
Factory Functions
| Factory | Purpose | Example |
|---|
View(tag?) | Basic styled component | View('button').bg('blue').element() |
style() | Reusable style chain (for variants, hover) | style().bg('red') |
Frame(w?, h?, align?) | Centered flex container | Frame(200, 200).element() |
HStack(w?, h?) | Horizontal flex | HStack().gap(20).element() |
VStack(w?, h?) | Vertical flex | VStack().gap(10).element() |
Grid(opts) | CSS Grid | Grid({ columns: 3, gap: 10 }).element() |
Core Methods
Size & Layout
.size(w, h?)
.width(w, {max?, min?})
.height(h, {max?, min?})
.aspect(ratio)
Flex
.flex()
.hstack()
.vstack()
.center()
.align({ x, y })
.gap(n)
Grid
.grid({ columns, rows, gap })
.columns(3)
.columns('1fr 2fr')
Colors
.fg('color')
.bg('color')
.bg({ url, size, position })
.color({ fg, bg, border })
Spacing
.padding(n)
.padding({ x: 20, y: 10 })
.padding({ left: 10, right: 20 })
.margin(n)
.margin({ x: 'auto' })
Border & Outline
.border(width, { color, style })
.border({ top: 1, color: 'red' })
.round(n)
.round({ topLeft: 5 })
.outline(width, { color, offset })
Text
.sans(size, { weight, color, leading, tracking })
.mono(size, opts?)
.serif(size, opts?)
.text({ size, weight, align, case, decoration })
.ellipsis()
Position
.absolute(x, y)
.pin(x, y)
.relative()
.zIndex(n)
.opacity(n)
Selectors (State Styles)
.onHover(style().bg('darkblue'))
.onFocus(style().outline('2px solid blue'))
.onActive(style().scale(0.95))
.before(style().content('"*"'))
.after(style().content('→'))
.select('& > p', style().color('gray'))
.attr('disabled', style().opacity(0.5))
.attr('data-state', { eq: 'active' }, style().bg('blue'))
Variants (Conditional Styles)
.variant('selected', true, style().bg('blue'))
.variant('compact', true, style().padding(4))
.variant('size', 'large', style().padding(40))
.variant('size', 'small', style().padding(10))
Responsive
.mobile(style().width('100%'))
.desktop(style().maxWidth(1200))
.media('(min-width: 768px)', style().padding(40))
Transitions & Transforms
.transition(duration?, props?)
.rotate(45)
.scale(1.5)
.translate(x, y)
Scroll
.scroll({ x: true, y: false })
.overflow('hidden')
.overflow({ x: 'auto', y: 'scroll' })
Common Patterns
Basic Component
const Button = View('button')
.padding({ x: 16, y: 8 })
.bg('rgba(11, 153, 255, 1)')
.fg('white')
.sans(14, { weight: 500 })
.round(6)
.border(0)
.cursor('pointer')
.onHover(style().bg('rgba(43, 166, 255, 1)'))
.element()
With Variants
const TableRow = Grid({ columns: '50px 1fr 100px' })
.sans(12)
.cursor('pointer')
.fg('rgba(221, 235, 241, 0.6)')
.border({ bottom: 1, color: 'rgba(255, 255, 255, 0.05)' })
.onHover(style().bg('rgba(225, 231, 241, 0.05)'))
.variant('selected', true,
style()
.bg('rgba(11, 153, 255, 0.15)')
.fg('rgba(221, 235, 241, 0.9)')
)
.variant('header', true,
style()
.sans(11, { weight: 500 })
.bg('rgba(225, 231, 241, 0.03)')
.cursor('default')
)
.variant('compact', true, style().grid({ columns: '40px 1fr 70px' }))
.selection(false)
.element()
Styled Existing Component
const StyledInput = View(TextField)
.width('100%')
.padding(12)
.round(8)
.element()
Key Differences from CSS-in-JS
- Chain must end with
.element() to create the React component
- Use
style() for nested styles (hover, variants, selectors)
- Numbers are pixels by default -
.size(100) = 100px
x/y shorthand for horizontal/vertical - .padding({ x: 20 })
- Variants are props -
.variant('active', true, ...) → <Comp active />
Common Mistakes
❌ Forgetting .element():
const Bad = View().bg('red')
const Good = View().bg('red').element()
❌ Using raw CSS in hover:
.onHover({ backgroundColor: 'blue' })
.onHover(style().bg('blue'))
❌ Wrong variant syntax:
.variant(true, 'selected', style().bg('blue'))
.variant('selected', true, style().bg('blue'))
Mobile Styling Patterns
const ResponsiveCard = View()
.padding(20)
.mobile(style()
.padding(10)
.width('100%')
)
.element()
const DesktopOnly = View()
.mobile(style().display('none'))
.element()
Reference
Full docs in ./docs/:
reference.md - Complete API reference
selectors.md - Hover, focus, attribute selectors
responsive.md - Media queries and breakpoints
grid.md - CSS Grid layouts
flex.md - Flexbox layouts