ToggleButton
A button with a pressed and an unpressed state, for marks like Watchlist and Like.
import { ToggleButton } from '@iffday/ui';Example
ToggleButton only handles pressed and unpressed: pressed, it carries data-pressed and a screen reader announces it as pressed. className decides the look. The Watched, Watchlist and Add to plan buttons under a film page’s poster use release-toggle: pressed, the text turns brand red on a 10% red ground.
import { useT } from '@iffday/i18n';
import { ToggleButton } from '@iffday/ui';
import { CalendarPlus, Eye, Heart } from 'lucide-react';
import { useState } from 'react';
/** The three marks beside the poster on a film page. */
export default function Example() {
const t = useT();
const [watched, setWatched] = useState(false);
const [wanted, setWanted] = useState(true);
const [planned, setPlanned] = useState(false);
return (
<div className="release-toggles" style={{ width: 'min(100%, 300px)' }}>
<ToggleButton className="release-toggle" pressed={watched} onPressedChange={setWatched}>
<Eye size={22} />
<span>{watched ? t('film.entry.watched') : t('film.entry.markWatched')}</span>
</ToggleButton>
<ToggleButton className="release-toggle" pressed={wanted} onPressedChange={setWanted}>
<Heart size={22} fill={wanted ? 'currentColor' : 'none'} />
<span>{wanted ? t('film.entry.onWatchlist') : t('film.entry.watchlist')}</span>
</ToggleButton>
<ToggleButton className="release-toggle" pressed={planned} onPressedChange={setPlanned}>
<CalendarPlus size={22} />
<span>{planned ? t('film.entry.inPlan') : t('film.entry.addToPlan')}</span>
</ToggleButton>
</div>
);
}Usage
- Change the words with the state (Watchlist, On watchlist), so color is not the only signal.
- For a toggle that needs a signed-in reader, check the session in
onPressedChangebefore switching. - The Like button is one too: see
LikeButtonon ReviewCard.
Props
ToggleButton
packages/ui/src/rating.tsx:93A pressable two-state button (record.club's Listened / Rotation / Queue).
| Prop | Type | Default |
|---|---|---|
children* | ReactNode | |
className | '' |
Other props go to ComponentProps<typeof Toggle> (see the Base UI documentation).