Utils

Utils are functions that take a single parameter and return Style Objects.

Creating shorthand properties

hypergood.config.ts
import type { CSS } from "@hypergood/css"

export const styleConfig = {
  utils: {
    gridCols: (columnCount: number) => ({
      gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))`,
    }),
  }
} satisfies StyleConfig
Row.tsx
function Row(props) {
  return (
    <div 
      {...props} 
      css={{
        gridCols: 4,
      }} 
    />
  )
}
Output (simplified)
.description {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

Creating macros

hypergood.config.ts
import type { CSS } from "@hypergood/css"

export const styleConfig = {
  utils: {
    lineClamp: (lines: number) => ({
      overflow: "hidden",
      display: "-webkit-box",
      "-webkit-box-orient": "vertical"
      "-webkit-line-clamp": lines,
    }),
  }
} satisfies StyleConfig
Description.tsx
function Description(props) {
  return (
    <div 
      {...props} 
      css={{
        lineClamp: 3,
      }} 
    />
  )
}
Output (simplified)
.description {
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

Using CSS as a parameter

hypergood.config.ts
import type { CSS } from "@hypergood/css"

export const styleConfig = {
  utils: {
    darkMode: (css: CSS) => ({
      '&[data-theme="dark"], [data-theme="dark"] &': css,
    }),
  }
} satisfies StyleConfig
Card.tsx
function Card(props) {
  return (
    <div 
      {...props} 
      css={{
        backgroundColor: 'white',
        darkMode: {
          backgroundColor: 'black',
        },
      }} 
    />
  )
}
Output (simplififed)
.button {
  background-color: white;
}
.button[data-theme="dark"], [data-theme="dark"] .button {
  background-color: black;
}