Headless Philosophy
What is Headless?
Headless components separate logic from presentation.
Instead of providing a complete UI component with predefined styles, a headless library gives you the logic, state management, and behavior - leaving the visual presentation entirely up to you.
The Problem with Traditional Calendar Libraries
Traditional calendar libraries come with built-in UI:
// Traditional approach - UI is bundled
import Calendar from 'some-calendar-lib';
<Calendar
theme="dark" // Limited theme options
primaryColor="blue" // Restricted customization
borderRadius="8px" // Can't match your design system
/>Problems:
- ๐จ Design constraints - Canโt fully match your design system
- ๐ฆ Bundle bloat - Shipping CSS you donโt use
- ๐ง Override hell - Fighting with
!importantto customize - ๐ซ Framework lock-in - Doesnโt work with your CSS solution
The Headless Approach
With @h6s/calendar, you get pure logic:
// Headless approach - you control everything
import { useCalendar } from '@h6s/calendar';
const { headers, body, navigation } = useCalendar();
// Build YOUR calendar with YOUR styling
<YourCustomCalendar
data={body}
onNavigate={navigation}
className={yourStyles}
/>Benefits:
- โ Complete design freedom - Match any design system perfectly
- โ Lightweight - No CSS bundle, just logic
- โ Flexible - Use any styling solution (Tailwind, CSS Modules, styled-components, etc.)
- โ Framework agnostic - Works anywhere React works
Separation of Concerns
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Application โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Presentation Layer (Your Control) โ
โ โข Styling (Tailwind/CSS/etc) โ
โ โข Markup structure โ
โ โข Visual design โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Logic Layer (@h6s/calendar) โ
โ โข Date calculations โ
โ โข State management โ
โ โข Navigation logic โ
โ โข Calendar data structure โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโThe logic layer is stable and well-tested. The presentation layer is entirely yours to customize.
Real-World Example
Letโs see how the same hook works with different styling solutions:
With Tailwind CSS
import { useCalendar } from '@h6s/calendar';
function TailwindCalendar() {
const { body } = useCalendar();
return (
<div className="bg-white rounded-lg shadow-md p-4">
{body.value.map(week => (
<div className="flex gap-2">
{week.value.map(day => (
<button className="w-10 h-10 rounded-full hover:bg-blue-100">
{format(day.value, 'd')}
</button>
))}
</div>
))}
</div>
);
}With CSS Modules
import { useCalendar } from '@h6s/calendar';
import styles from './Calendar.module.css';
function CSSModulesCalendar() {
const { body } = useCalendar();
return (
<div className={styles.calendar}>
{body.value.map(week => (
<div className={styles.week}>
{week.value.map(day => (
<button className={styles.day}>
{format(day.value, 'd')}
</button>
))}
</div>
))}
</div>
);
}With styled-components
import { useCalendar } from '@h6s/calendar';
import styled from 'styled-components';
const CalendarContainer = styled.div`
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
padding: 16px;
`;
const Day = styled.button`
width: 40px;
height: 40px;
border-radius: 50%;
&:hover {
background: #e3f2fd;
}
`;
function StyledCalendar() {
const { body } = useCalendar();
return (
<CalendarContainer>
{/* Same logic, different styles */}
</CalendarContainer>
);
}Same Logic, Any Design
The power of headless is that the calendar logic never changes, but you can create completely different visual experiences:
- ๐ฑ Mobile-first calendar
- ๐จ Neumorphic design
- ๐ Dark mode friendly
- โฟ Accessibility-focused
- ๐ข Corporate design system
- ๐ฎ Gaming UI theme
All using the same useCalendar() hook.
When to Use Headless?
Use headless when:
- โ You have a design system to match
- โ You need full control over styling
- โ You want to minimize bundle size
- โ Youโre building a design system yourself
Consider traditional components when:
- โ You need a quick prototype with default styles
- โ You donโt care about visual customization
- โ You want an out-of-the-box solution
Philosophy in Action
See our Examples to see how the same useCalendar hook powers completely different calendar designs:
- DatePicker with popover
- DateRangePicker with dual calendars
- Standalone date calendars
- All with Tailwind, Vanilla CSS, and Bootstrap variants
Each example uses the exact same hook, just with different presentation layers.
Next: Learn how to use the API Reference to build your own calendar.