{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "aside-04",
  "title": "Notification settings",
  "description": "Events by channel as a grid of switches, a group checkbox for each section, quiet hours and a digest",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/checkbox.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/select.json",
    "https://ui.ndekocode.dev/r/sheet.json",
    "https://ui.ndekocode.dev/r/switch.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/aside/aside-04.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport {\n  InboxIcon,\n  MailIcon,\n  SmartphoneIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Checkbox } from '@/registry/ndeko/ui/checkbox';\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from '@/registry/ndeko/ui/select';\nimport { Switch } from '@/registry/ndeko/ui/switch';\n\nimport {\n  AsideCloseButton,\n  AsideDescription,\n  AsidePreview,\n  AsideTitle,\n} from './_parts/aside-frame';\n\ntype Channel = 'inbox' | 'email' | 'mobile';\n\ntype ChannelSettings = Record<Channel, boolean>;\n\ntype EventSetting = { id: string; label: string };\n\ntype EventGroup = { id: string; label: string; events: EventSetting[] };\n\ntype Option = { value: string; label: string };\n\nconst CHANNELS: { id: Channel; label: string; icon: Icon }[] = [\n  { id: 'inbox', label: 'Inbox', icon: InboxIcon },\n  { id: 'email', label: 'E-mail', icon: MailIcon },\n  { id: 'mobile', label: 'Mobile', icon: SmartphoneIcon },\n];\n\nconst GROUPS: EventGroup[] = [\n  {\n    id: 'tasks',\n    label: 'Tasks',\n    events: [\n      { id: 'assigned', label: 'Assigned to me' },\n      { id: 'status', label: 'Status changed' },\n      { id: 'due', label: 'Due tomorrow' },\n    ],\n  },\n  {\n    id: 'comments',\n    label: 'Comments',\n    events: [\n      { id: 'mention', label: 'I am mentioned' },\n      { id: 'reply', label: 'Replies to me' },\n    ],\n  },\n  {\n    id: 'time',\n    label: 'Time',\n    events: [\n      { id: 'timer', label: 'Timer left running' },\n      { id: 'approved', label: 'Timesheet approved' },\n    ],\n  },\n];\n\nconst INITIAL_SETTINGS: Record<string, ChannelSettings> = {\n  assigned: { inbox: true, email: true, mobile: true },\n  status: { inbox: true, email: false, mobile: false },\n  due: { inbox: true, email: true, mobile: false },\n  mention: { inbox: true, email: true, mobile: true },\n  reply: { inbox: true, email: false, mobile: true },\n  timer: { inbox: false, email: false, mobile: false },\n  approved: { inbox: false, email: false, mobile: false },\n};\n\nconst ALL_ON: ChannelSettings = { inbox: true, email: true, mobile: true };\n\nconst ALL_OFF: ChannelSettings = { inbox: false, email: false, mobile: false };\n\nconst HOURS: Option[] = [\n  { value: '18', label: '18:00' },\n  { value: '19', label: '19:00' },\n  { value: '20', label: '20:00' },\n  { value: '21', label: '21:00' },\n  { value: '07', label: '07:00' },\n  { value: '08', label: '08:00' },\n  { value: '09', label: '09:00' },\n];\n\nconst DIGESTS: Option[] = [\n  { value: 'daily', label: 'Every day at 09:00' },\n  { value: 'weekly', label: 'Mondays at 09:00' },\n  { value: 'never', label: 'No digest' },\n];\n\nfunction everyChannel(isOn: boolean) {\n  if (isOn) {\n    return ALL_ON;\n  }\n  return ALL_OFF;\n}\n\nfunction switchedOnCount(\n  settings: Record<string, ChannelSettings>,\n  group: EventGroup\n) {\n  let count = 0;\n  for (const event of group.events) {\n    for (const channel of CHANNELS) {\n      if (settings[event.id][channel.id]) {\n        count += 1;\n      }\n    }\n  }\n  return count;\n}\n\nfunction SmallSelect({\n  label,\n  value,\n  options,\n  onChange,\n}: {\n  label: string;\n  value: string;\n  options: Option[];\n  onChange: (value: string) => void;\n}) {\n  function changeValue(nextValue: unknown) {\n    const option = options.find((candidate) => candidate.value === nextValue);\n    if (option) {\n      onChange(option.value);\n    }\n  }\n\n  return (\n    <Select items={options} value={value} onValueChange={changeValue}>\n      <SelectTrigger size='sm' aria-label={label} className='w-auto'>\n        <SelectValue />\n      </SelectTrigger>\n      <SelectContent align='end'>\n        {options.map((option) => (\n          <SelectItem key={option.value} value={option.value}>\n            {option.label}\n          </SelectItem>\n        ))}\n      </SelectContent>\n    </Select>\n  );\n}\n\nfunction GroupRows({\n  group,\n  settings,\n  onSet,\n}: {\n  group: EventGroup;\n  settings: Record<string, ChannelSettings>;\n  onSet: (eventIds: string[], channel: Channel | null, isOn: boolean) => void;\n}) {\n  const checkboxId = useId();\n  const total = group.events.length * CHANNELS.length;\n  const onCount = switchedOnCount(settings, group);\n  const isAllOn = onCount === total;\n  const isSomeOn = onCount > 0;\n  const isMixed = isSomeOn && !isAllOn;\n  const eventIds = group.events.map((event) => event.id);\n\n  function toggleGroup() {\n    onSet(eventIds, null, !isAllOn);\n  }\n\n  return (\n    <tbody className='hairline-divide-y divide-border'>\n      <tr>\n        <th scope='rowgroup' colSpan={4} className='pt-4 pb-1.5 text-left'>\n          <span className='flex items-center gap-2'>\n            <Checkbox\n              id={checkboxId}\n              checked={isAllOn}\n              indeterminate={isMixed}\n              onCheckedChange={toggleGroup}\n            />\n            <label\n              htmlFor={checkboxId}\n              className='cursor-pointer text-xs font-medium'\n            >\n              {group.label}\n            </label>\n          </span>\n        </th>\n      </tr>\n      {group.events.map((event) => (\n        <tr key={event.id}>\n          <th\n            scope='row'\n            className='py-2 pr-2 text-left text-[13px] font-normal'\n          >\n            {event.label}\n          </th>\n          {CHANNELS.map((channel) => {\n            const isOn = settings[event.id][channel.id];\n\n            function change(nextIsOn: boolean) {\n              onSet([event.id], channel.id, nextIsOn);\n            }\n\n            return (\n              <td key={channel.id} className='w-14 py-2 text-center'>\n                <Switch\n                  checked={isOn}\n                  onCheckedChange={change}\n                  aria-label={`${event.label} in ${channel.label}`}\n                />\n              </td>\n            );\n          })}\n        </tr>\n      ))}\n    </tbody>\n  );\n}\n\nfunction NotificationSettings() {\n  const [settings, setSettings] = useState(INITIAL_SETTINGS);\n  const [isQuiet, setIsQuiet] = useState(true);\n  const [quietFrom, setQuietFrom] = useState('20');\n  const [quietTo, setQuietTo] = useState('08');\n  const [digest, setDigest] = useState('daily');\n  const quietSwitchId = useId();\n  const quietLineId = useId();\n\n  function setChannels(\n    eventIds: string[],\n    channel: Channel | null,\n    isOn: boolean\n  ) {\n    setSettings((previous) => {\n      const next = { ...previous };\n      for (const eventId of eventIds) {\n        if (channel === null) {\n          next[eventId] = everyChannel(isOn);\n          continue;\n        }\n        next[eventId] = { ...previous[eventId], [channel]: isOn };\n      }\n      return next;\n    });\n  }\n\n  return (\n    <div className='flex flex-col gap-6 p-5'>\n      <div className='flex items-start gap-3'>\n        <div className='flex min-w-0 flex-1 flex-col gap-1'>\n          <AsideTitle>Notifications</AsideTitle>\n          <AsideDescription>\n            Where each event reaches you, saved as you change it\n          </AsideDescription>\n        </div>\n        <AsideCloseButton\n          label='Close notification settings'\n          className='-mt-1 -mr-2'\n        />\n      </div>\n      <table className='w-full border-collapse'>\n        <thead>\n          <tr>\n            <th scope='col' className='text-left'>\n              <span className='sr-only'>Event</span>\n            </th>\n            {CHANNELS.map((channel) => {\n              const ChannelGlyph = channel.icon;\n\n              return (\n                <th\n                  key={channel.id}\n                  scope='col'\n                  className='text-muted-foreground w-14 pb-1 text-[11px] font-medium'\n                >\n                  <span className='flex flex-col items-center gap-1'>\n                    <ChannelGlyph className='size-4' />\n                    {channel.label}\n                  </span>\n                </th>\n              );\n            })}\n          </tr>\n        </thead>\n        {GROUPS.map((group) => (\n          <GroupRows\n            key={group.id}\n            group={group}\n            settings={settings}\n            onSet={setChannels}\n          />\n        ))}\n      </table>\n      <section aria-label='Quiet hours' className='flex flex-col'>\n        <div className='flex items-start gap-3'>\n          <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n            <label htmlFor={quietSwitchId} className='text-sm font-medium'>\n              Quiet hours\n            </label>\n            <p id={quietLineId} className='text-muted-foreground text-xs'>\n              Mobile stays silent, the inbox keeps everything\n            </p>\n          </div>\n          <Switch\n            id={quietSwitchId}\n            checked={isQuiet}\n            onCheckedChange={setIsQuiet}\n            aria-describedby={quietLineId}\n          />\n        </div>\n        <AnimatedSize>\n          {isQuiet && (\n            <div className='flex items-center gap-2 pt-3 text-[13px]'>\n              <span className='text-muted-foreground'>From</span>\n              <SmallSelect\n                label='Quiet hours start'\n                value={quietFrom}\n                options={HOURS}\n                onChange={setQuietFrom}\n              />\n              <span className='text-muted-foreground'>to</span>\n              <SmallSelect\n                label='Quiet hours end'\n                value={quietTo}\n                options={HOURS}\n                onChange={setQuietTo}\n              />\n            </div>\n          )}\n        </AnimatedSize>\n      </section>\n      <section\n        aria-label='Digest'\n        className='flex items-center justify-between gap-3'\n      >\n        <div className='flex min-w-0 flex-col gap-0.5'>\n          <h3 className='text-sm font-medium'>Digest</h3>\n          <p className='text-muted-foreground text-xs'>\n            What you missed, in one e-mail\n          </p>\n        </div>\n        <SmallSelect\n          label='Digest frequency'\n          value={digest}\n          options={DIGESTS}\n          onChange={setDigest}\n        />\n      </section>\n    </div>\n  );\n}\n\nexport default function Aside04() {\n  return (\n    <AsidePreview triggerLabel='Open notification settings'>\n      <NotificationSettings />\n    </AsidePreview>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/aside/aside-04.tsx"
    },
    {
      "path": "registry/ndeko/components/aside/_parts/aside-frame.tsx",
      "content": "'use client';\n\nimport { createContext, useContext } from 'react';\n\nimport { PanelsTopLeftIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Sheet,\n  SheetClose,\n  SheetContent,\n  SheetDescription,\n  SheetTitle,\n  SheetTrigger,\n} from '@/registry/ndeko/ui/sheet';\n\n/** Where an aside's content is drawn: open in the page as a preview, or inside the real sheet. */\nexport type AsideHost = 'preview' | 'sheet';\n\nconst AsideHostContext = createContext<AsideHost>('preview');\n\nexport function useAsideHost() {\n  return useContext(AsideHostContext);\n}\n\nexport type AsideSide = 'left' | 'right';\n\nconst TITLE = 'text-lg leading-tight font-semibold';\n\nconst DESCRIPTION = 'text-muted-foreground text-[13px]';\n\n/** The background of the surface the aside sits on, for parts that must cover what scrolls under them. */\nexport const ASIDE_SURFACE = 'bg-[var(--aside-surface)]';\n\ntype AsideTextProps = { className?: string; children: React.ReactNode };\n\nexport function AsideTitle({ className, children }: AsideTextProps) {\n  const host = useAsideHost();\n  if (host === 'sheet') {\n    return <SheetTitle className={className}>{children}</SheetTitle>;\n  }\n  return <h2 className={cn(TITLE, className)}>{children}</h2>;\n}\n\nexport function AsideDescription({ className, children }: AsideTextProps) {\n  const host = useAsideHost();\n  if (host === 'sheet') {\n    return (\n      <SheetDescription className={className}>{children}</SheetDescription>\n    );\n  }\n  return <p className={cn(DESCRIPTION, className)}>{children}</p>;\n}\n\n/** The close button of the sheet's header. The preview has nothing to close, so it draws nothing. */\nexport function AsideCloseButton({\n  label = 'Close panel',\n  className,\n}: {\n  label?: string;\n  className?: string;\n}) {\n  const host = useAsideHost();\n  if (host === 'preview') {\n    return null;\n  }\n  return (\n    <SheetClose\n      render={\n        <Button\n          variant='ghost'\n          size='icon-sm'\n          aria-label={label}\n          className={cn('text-muted-foreground', className)}\n        />\n      }\n    >\n      <XIcon />\n    </SheetClose>\n  );\n}\n\ntype AsidePreviewProps = {\n  /** The content, drawn twice: open in the page, and inside the sheet the trigger opens. */\n  children: React.ReactNode;\n  triggerLabel: string;\n  side?: AsideSide;\n  className?: string;\n};\n\n/** Shows an aside open and whole on the page, with a small trigger that slides the same content in as a real sheet. */\nexport function AsidePreview({\n  children,\n  triggerLabel,\n  side = 'right',\n  className,\n}: AsidePreviewProps) {\n  return (\n    <div className='flex w-full flex-col items-center gap-4'>\n      <AsideHostContext.Provider value='preview'>\n        <div\n          className={cn(\n            'surface-raised flex w-full max-w-sm flex-col overflow-hidden rounded-2xl text-left [--aside-surface:var(--popover)]',\n            className\n          )}\n        >\n          {children}\n        </div>\n      </AsideHostContext.Provider>\n      <Sheet>\n        <SheetTrigger render={<Button variant='outline' size='sm' />}>\n          <PanelsTopLeftIcon />\n          {triggerLabel}\n        </SheetTrigger>\n        <SheetContent\n          side={side}\n          showCloseButton={false}\n          className={cn('gap-0 p-0 [--aside-surface:var(--card)]', className)}\n        >\n          <AsideHostContext.Provider value='sheet'>\n            {children}\n          </AsideHostContext.Provider>\n        </SheetContent>\n      </Sheet>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/aside/_parts/aside-frame.tsx"
    }
  ],
  "categories": [
    "components",
    "aside"
  ],
  "type": "registry:component"
}