Headless Components Design
takanorip / 20201218 / UIT紅白歌合戦
Self Introduction
CSS in JS…?
We don’t want to write CSS anymore
Headless UI
import { useState } from 'react'
import { Switch } from '@headlessui/react'
function NotificationsToggle() {
const [enabled, setEnabled] = useState(false)
return (
<Switch
checked={enabled}
onChange={setEnabled}
className={`${
enabled ? 'bg-blue-600' : 'bg-gray-200'
} relative inline-flex h-6 rounded-full w-8`}
>
<span className="sr-only">Enable notifications</span>
<span
className={`${
enabled ? 'translate-x-4' : 'translate-x-0'
} inline-block w-4 h-4 transform bg-white rounded-full`}
/>
</Switch>
)
}
tailwindcss
“A utility-first CSS framework packed with classes”
<div class="p-6 max-w-sm mx-auto bg-white rounded-xl shadow-md flex items-center">
<div class="flex-shrink-0">
<img class="h-12 w-12" src="/img/logo.svg" alt="ChitChat Logo">
</div>
<div>
<div class="text-xl font-medium text-black">ChitChat</div>
<p class="text-gray-500">You have a new message!</p>
</div>
</div>
Issues in Components Design
What do we do when the style boundary and the function boundary are slightly different?
Let’s make Original Headless UI?
Current Design System
Basic Components with style
Organism Components
Headless Design System
Original utility-first CSS
Original Function Components
Design tokens -> Utility-first CSS