Utilities
The helpers Glyph components are built with, for building your own themed components.
Status: stable. Category: Patterns.
import { Utilities } from '@glyphui/ui'
Exports: cn, tv, useComponentConfig, useControllableState, useMediaQuery, useScrolled.
Notes
- tv is tailwind-variants preconfigured with Glyph merge rules; use it for your own component styles.
- useComponentConfig applies a theme's per-component defaults and classes to your component.
Example: cn
Joins classes and resolves Tailwind conflicts, including Glyph type tokens.
import { cn } from '@glyphui/ui'
export default function Example() {
const merged = cn(
'text-h1 text-muted-foreground px-2',
'text-small text-foreground',
false && 'hidden',
)
return (
<div className="grid gap-2">
<code className="font-mono text-caption text-muted-foreground">{merged}</code>
<p className={merged}>Later classes win: small, foreground text.</p>
</div>
)
}
Example: Hooks
import { Text, useControllableState, useMediaQuery } from '@glyphui/ui'
export default function Example() {
const wide = useMediaQuery('(min-width: 48rem)')
const [count, setCount] = useControllableState({ defaultValue: 0 })
return (
<div className="grid gap-2">
<Text size="small">Viewport is {wide ? 'wide' : 'narrow'} (useMediaQuery).</Text>
<button
type="button"
className="justify-self-start rounded-md border border-border px-3 py-1.5 text-small"
onClick={() => setCount((c) => c + 1)}
>
Clicked {count} times (useControllableState)
</button>
</div>
)
}
Live page: https://glyphui.xyz/components/utilities