Authoring surface

Open in playground

import { reset } from "@cssints/reset" with { type: "cssints" };
import * as css from "cssints" with { type: "cssints" };
import { CSS } from "cssints" with { type: "cssints" };

import { page, row, stack } from "./stack.ts" with { type: "cssints" };

reset();

// Names are the CSS properties in camelCase, plus a few short ones (p, m, bg). A bare number is a step of 0.25rem in padding,
// margin, gap and inset, and a plain number elsewhere. flex() and grid() chain their container properties.
const frame = css.cn(page, css.maxWidth("32rem"), css.marginInline("auto"));
const panel = css.cn(
  stack,
  css.padding(CSS.rem(1), CSS.rem(1.5)),
  css.border("1px solid", "#d4d8e1"),
  css.borderRadius("12px"),
  css.bg("#fafbfd"),
  css.color("#0f172a"),
);
const person = css.cn(row, css.minHeight("3rem"));
const avatar = css.cn(
  css.width("2.5rem"),
  css.height("2.5rem"),
  css.borderRadius("50%"),
  css.bg("#c7d2fe"),
  css.color("#1e1b4b"),
  css.flex().alignItems("center").justifyContent("center"),
  css.fontWeight(700),
);
const grid = css.cn(
  css.grid().templateColumns("repeat(3, 1fr)").gap(2),
  css.textAlign("center"),
  css.fontSize("0.875rem"),
);
const cell = css.cn(
  css.p(2),
  css.bg("white"),
  css.color("#0f172a"),
  css.border("1px solid", "#e5e7eb"),
  css.opacity(0.9),
);

const people = ["Ada", "Grace", "Linus"];

export default function App() {
  return (
    <div className={frame}>
      <section className={panel}>
        <h2 className={css.cn(css.margin("0"), css.fontSize("1.125rem"))}>Team</h2>
        {people.map((name) => (
          <div className={person}>
            <span className={avatar}>{name[0]}</span>
            <span>{name}</span>
          </div>
        ))}
      </section>
      <section className={grid}>
        <span className={cell}>p(2)</span>
        <span className={cell}>opacity(0.9)</span>
        <span className={cell}>gap(2)</span>
      </section>
    </div>
  );
}
import * as css from "cssints" with { type: "cssints" };

// Styles can live in a module of their own: import it with the attribute, as cssints itself.
export const stack = css.flex().direction("column").gap(3);
export const row = css.flex().alignItems("center").gap(3);
export const page = css.cn(css.flex().direction("column").gap(6), css.p(6));
// stack.ts
import * as import csscss from "cssints" with { type: "cssints" };

export const const stack: (gap: number) => css.Chain<css.FlexMethods>stack = (gap: numbergap: number) => import csscss.
const flex: css.Layout
() => css.Chain<css.FlexMethods> (+1 overload)
The layout context: sets `display` and chains its container properties.
flex
().direction: <readonly ["column"]>(parts_0: "column") => css.Chain<css.FlexMethods>
`row | row-reverse | column | column-reverse`. Chrome 29, Edge 12, Firefox 22, Safari 9, iOS 9, Android 29. [MDN](https://developer.mozilla.org/docs/Web/CSS/flex-direction)
direction
("column").gap: <readonly [number]>(parts_0: number) => css.Chain<css.FlexMethods>
`<'row-gap'> <'column-gap'>?`. Chrome 57, Edge 16, Firefox 52, Safari 10.1, iOS 10.3, Android 57. [MDN](https://developer.mozilla.org/docs/Web/CSS/gap)
gap
(gap: numbergap);
// elsewhere: import { stack } from "./stack.ts" with { type: "cssints" }; ... className={stack(4)}