Notification Switches Grouped by Topic
ProNotification settings as one card per topic, each with a master switch over its own setting switches. Pausing a topic keeps the choices under it. Use it when notifications go to a single channel.
How it differs. One channel, two levels: a master switch in each topic card header pauses the setting switches under it without clearing them, and required rows stay locked on. No event by channel grid.
Install
pnpm dlx shadcn@latest add @hazine/notification-preferences-grouped-switchesAdds 1 file, 3 shadcn primitives (card, label, switch), 2 Hazine items (@hazine/heading, @hazine/use-controllable-state), and 1 package (lucide-react).
First time? Add the registry to components.json
{
"registries": {
"@hazine": {
"url": "https://api.hazine.dev/r/{name}.json",
"headers": { "Authorization": "Bearer ${HAZINE_TOKEN}" }
}
}
}Set HAZINE_TOKEN in your environment. The token comes with a Pro licence.
The source of a Pro item is not published on this site. It installs into your codebase with the same command once your registry entry carries a Pro token.
- components/blocks/notification-preferences-grouped-switches.tsx
- 446 lines
- 1 file
- 446 lines
pnpm dlx shadcn@latest add @hazine/notification-preferences-grouped-switchesAdds 1 file, 3 shadcn primitives (card, label, switch), 2 Hazine items (@hazine/heading, @hazine/use-controllable-state), and 1 package (lucide-react).
Props10
- title
- string = "Notifications"
- headingLevel
- HeadingLevel = 2
- topics
- NotificationTopic[]
- Topics with their settings and the state of every switch.
- defaultTopics
- NotificationTopic[] = DEFAULT_TOPICS
- onTopicsChange
- (topics: NotificationTopic[]) => void
- destination
- string
- The email address notifications are sent to.
- destinationHref
- string
- loading
- boolean = false
- Shows skeleton cards in place of the topics.
- error
- string
- A failed load or save, written as what happened and what to do next.
- emptyHref
- string = "/workspaces"
- Target of the action in the empty state.
Also accepts every prop of Omit<React.ComponentProps<"section">, "title">.
Accessibility
- Pattern
- Switch (APG, opens in a new tab), Landmarks and headings
- Keyboard
Keyboard support for Notification Switches Grouped by Topic Key Effect Tab Moves through the Change address link, then for each topic the master switch followed by its setting switches. Switches under a paused topic are skipped, locked switches are not Space or Enter on a master switch Pauses or resumes the topic. Pausing disables its setting switches and keeps what they were set to Space or Enter on a setting switch Turns the notification on or off and updates the counts Space or Enter on a locked switch Changes nothing and announces why the notification is always on Space or Enter on the master switch of a topic with only required notifications Changes nothing and announces that the topic cannot be paused - Screen reader
Section labelled by its heading. Each topic card is a group named by its title. The master switch takes its name from that title and its description from the summary line. Each setting switch has a visible label and description. Paused switches are disabled and their labels dim, with the reason in the summary line and the descriptions left at full contrast, and locked switches stay focusable with the reason in their description. One polite status region reports each change with the new count.
- Announces: {setting} on. {count} of {total} {topic} notifications on.
- Announces: {setting} off. {count} of {total} {topic} notifications on.
- Announces: {topic} paused. Your choices are kept.
- Announces: {topic} paused. 1 required alert still sends. Your other choices are kept.
- Announces: {topic} paused. {required} required alerts still send. Your other choices are kept.
- Announces: {topic} on.
- Announces: {topic} paused.
- Announces: {topic} cannot be paused. Every notification in it is required.
- Announces: {topic} on. {count} of {total} on.
- Announces: {setting} is always on. {reason}
- Reduced motion
- The item adds no motion of its own. The switch thumb keeps the transition of the host switch, and the loading skeleton does not pulse.
- Checked
- Not checked yet. Automated results appear here once CI has run.
Dependencies6
- card
- label
- switch
- @hazine/heading
- @hazine/use-controllable-state
- lucide-react
Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.
Tokens shipped0
None. The item is styled by the tokens your theme already has.