Effect UI Kit

Headless components for Effect UI.

Installation

  1. Set up the project

    Once per project: the packages, Tailwind CSS, the theme tokens and the cn helper. Follow Installation.

  2. Copy the component into your project

    The kit owns behaviour, ARIA and data attributes. This file is the look, written with Tailwind classes, and it is yours to change.

    src/ui/separator.ts
    import { Separator as KitSeparator, type SeparatorElement, type SeparatorProps } from "@effect/ui-kit"
    import { cn } from "#lib/cn"
    
    const base = "shrink-0 data-[orientation=horizontal]:w-full data-[orientation=vertical]:self-stretch"
    
    const rule = "data-[orientation=horizontal]:h-px data-[orientation=vertical]:min-h-[1em] data-[orientation=vertical]:w-px"
    
    const variants = {
      default: cn(rule, "bg-border"),
      strong: cn(rule, "bg-foreground"),
      brand: cn(rule, "bg-brand"),
      dashed: "border-dashed border-input data-[orientation=horizontal]:border-t data-[orientation=vertical]:border-l",
      label: "flex items-center gap-3 text-xs leading-none whitespace-nowrap text-muted-foreground " +
        "before:h-px before:flex-1 before:bg-border after:h-px after:flex-1 after:bg-border"
    } as const
    
    export type SeparatorVariant = keyof typeof variants
    
    /** The separator's classes, for another element that should look like one. */
    export const separatorVariants = (
      options: { readonly variant?: SeparatorVariant | undefined; readonly class?: string | undefined } = {}
    ): string => cn(base, variants[options.variant ?? "default"], options.class)
    
    /**
     * The kit's Separator with a look. A vertical one takes the height of the row
     * it sits in. With `variant: "label"` its children sit between two rules:
     * `Separator(h, { variant: "label" }).children("or")`.
     */
    export const Separator = <Msg, R = never>(
      h: { readonly div: SeparatorElement<Msg> },
      options: {
        readonly variant?: SeparatorVariant | undefined
        readonly class?: string | undefined
        readonly element?: SeparatorElement<Msg, R> | undefined
        readonly props?: SeparatorProps | undefined
      } = {}
    ): SeparatorElement<Msg, R> =>
      KitSeparator<Msg, R>(h, { element: options.element, props: options.props }).class(separatorVariants(options))
    
  3. Import it

    import { separatorVariants, Separator } from "#ui/separator"
    

Usage

Horizontal and vertical.ts
import { Html } from "@effect/ui/html"
import { Schema } from "effect"
import { Separator } from "#ui/separator"

export const SeparatorBasic = Html.component({
  name: "SeparatorBasic",
  model: Schema.Struct({}),
  message: Schema.Never
}).make({
  init: () => ({}),
  update: ($) => $.model,
  view: (h) =>
    h.div.class("flex w-full max-w-xs flex-col gap-4").children(
      h.div.children(
        h.h4.class("m-0 text-sm font-medium").children("Effect UI Kit"),
        h.p.class("m-0 text-[13px] text-muted-foreground").children("Headless components for Effect UI.")
      ),
      Separator(h),
      h.div.class("flex items-center gap-4 text-[13px] [&_a]:no-underline [&_a]:underline-offset-4 [&_a]:hover:underline")
        .children(
          h.a.attr("href", "#").children("Blog"),
          Separator(h, { props: { orientation: "vertical" } }),
          h.a.attr("href", "#").children("Docs"),
          Separator(h, { props: { orientation: "vertical" } }),
          h.a.attr("href", "#").children("Source")
        )
    )
})

Examples

In a toolbar

Vertical separators between groups of buttons take the row's height.

Pick a tool

With a label

With the label variant, the separator's own children sit between two rules.

Not signed in

Full-width rules between the groups of a menu-like list.

Pick an action

Variants

Four looks from the variant option, and a decorative rule that keeps the caller's role="none".

default
strong
dashed
brand
decorative, role="none"

Anatomy

The parts the view closure receives. Apply each one to an element of your own.

PartDescription
Separator(h, options)Returns one <div> builder: chain classes, attributes and children on it.
options.elementThe caller's h.div, to share the divider with another part. h.div when left out.

API reference

Props

PropTypeDescription
orientation"horizontal" | "vertical"The direction of the rule. "horizontal" by default.

Data attributes

AttributeDescription
data-orientation"horizontal" or "vertical".
role, aria-orientationrole="separator" with its orientation, unless the caller's element has role="none" or "presentation".

The components this page's file and examples import.

  • Button: A native button that can stay focusable while disabled.

effectcn is built with Effect UI and @effect/ui-kit. Not affiliated with Effectful Technologies.