{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "teams-06",
  "title": "Team settings",
  "description": "Name, colour, visibility, join requests and a hold to archive, with the team tile following every change.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/switch.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/toggle-group.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/teams/teams-06.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useId, useRef, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  ArchiveIcon,\n  ArchiveRestoreIcon,\n  CheckIcon,\n  LoaderIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Switch } from '@/registry/ndeko/ui/switch';\nimport { ToggleGroup, ToggleGroupItem } from '@/registry/ndeko/ui/toggle-group';\n\nimport { Segments, type Segment } from './_parts/segments';\nimport { Swap } from './_parts/swap';\nimport { TeamTile } from './_parts/team-tile';\n\ntype SaveState = 'idle' | 'saving' | 'saved';\n\ntype Visibility = 'public' | 'private';\n\ntype HoldState = 'idle' | 'holding' | 'archived';\n\ntype Swatch = { id: string; label: string; color: string };\n\nconst SWATCHES: Swatch[] = [\n  { id: 'blue', label: 'Blue', color: 'var(--info)' },\n  { id: 'indigo', label: 'Indigo', color: 'var(--primary)' },\n  { id: 'green', label: 'Green', color: 'var(--success)' },\n  { id: 'amber', label: 'Amber', color: 'var(--warning)' },\n  { id: 'grey', label: 'Grey', color: 'var(--muted-foreground)' },\n];\n\nconst VISIBILITY_SEGMENTS: Segment<Visibility>[] = [\n  { value: 'public', label: 'Public' },\n  { value: 'private', label: 'Private' },\n];\n\nconst VISIBILITY_HINTS: Record<Visibility, string> = {\n  public: 'Anyone in Fernhall can find this team and ask to join',\n  private: 'Only the people you invite can see and join this team',\n};\n\nconst SAVE_DELAY_MS = 700;\nconst SAVED_RESET_MS = 1500;\nconst HOLD_DURATION_MS = 1600;\nconst HOLD_KEYS = new Set([' ', 'Enter']);\n\nconst MORPH: Transition = { type: 'spring', bounce: 0, duration: 0.3 };\nconst INSTANT: Transition = { duration: 0 };\nconst ARRIVE: Transition = { duration: 0.18, ease: [0.23, 1, 0.32, 1] };\nconst LEAVE: Transition = { duration: 0.12, ease: [0.23, 1, 0.32, 1] };\n\nconst BLUR_VARIANTS: Variants = {\n  enter: { opacity: 0, filter: 'blur(2px)' },\n  visible: { opacity: 1, filter: 'blur(0px)', transition: ARRIVE },\n  exit: { opacity: 0, filter: 'blur(2px)', transition: LEAVE },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1, transition: ARRIVE },\n  exit: { opacity: 0, transition: LEAVE },\n};\n\nconst SWATCH_RING =\n  'bg-transparent shadow-[0_0_0_1.5px_color-mix(in_oklab,var(--foreground)_35%,transparent)]';\n\nconst HOLD_LAYER =\n  'bg-destructive pointer-events-none absolute inset-0 flex items-center justify-center gap-2 rounded-[inherit] text-white';\n\nconst HOLD_FILL = [\n  '[clip-path:inset(0_100%_0_0)] transition-[clip-path] duration-200 ease-(--ease-out-strong)',\n  'group-data-filled/button:[clip-path:inset(0)] group-data-filled/button:duration-[1600ms] group-data-filled/button:ease-linear',\n].join(' ');\n\nconst HOLD_FILL_REDUCED = [\n  'opacity-0 transition-opacity duration-200',\n  'group-data-filled/button:opacity-100 group-data-filled/button:duration-[1600ms] group-data-filled/button:ease-linear',\n].join(' ');\n\nconst ROW = 'grid gap-x-6 gap-y-2 sm:grid-cols-[8rem_minmax(0,1fr)]';\n\nconst ROW_LABEL = 'text-[13px] font-medium sm:pt-1.5';\n\nfunction morphOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return MORPH;\n}\n\nfunction blurOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return BLUR_VARIANTS;\n}\n\nfunction holdFillOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return HOLD_FILL_REDUCED;\n  }\n  return HOLD_FILL;\n}\n\nfunction saveLabelOf(state: SaveState) {\n  if (state === 'saving') {\n    return 'Saving';\n  }\n  if (state === 'saved') {\n    return 'Saved';\n  }\n  return 'Save';\n}\n\nfunction HoldLabel() {\n  return (\n    <>\n      <ArchiveIcon />\n      Hold to archive\n    </>\n  );\n}\n\nfunction swatchById(swatchId: string) {\n  const found = SWATCHES.find((swatch) => swatch.id === swatchId);\n  if (found) {\n    return found;\n  }\n  return SWATCHES[0];\n}\n\nfunction useTimer() {\n  const timer = useRef<number | null>(null);\n\n  useEffect(() => {\n    return () => {\n      if (timer.current !== null) {\n        window.clearTimeout(timer.current);\n      }\n    };\n  }, []);\n\n  function schedule(callback: () => void, delay: number) {\n    if (timer.current !== null) {\n      window.clearTimeout(timer.current);\n    }\n    timer.current = window.setTimeout(() => {\n      timer.current = null;\n      callback();\n    }, delay);\n  }\n\n  function cancel() {\n    if (timer.current !== null) {\n      window.clearTimeout(timer.current);\n      timer.current = null;\n    }\n  }\n\n  return { schedule, cancel };\n}\n\nfunction NameField({\n  savedName,\n  onSave,\n}: {\n  savedName: string;\n  onSave: (name: string) => void;\n}) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const inputId = useId();\n  const [draft, setDraft] = useState(savedName);\n  const [saveState, setSaveState] = useState<SaveState>('idle');\n  const { schedule } = useTimer();\n  const trimmed = draft.trim();\n  const isDirty = trimmed !== savedName;\n  const isEmpty = trimmed.length === 0;\n  const canSave = isDirty && !isEmpty;\n  const isBusy = saveState !== 'idle';\n  const isSaveDisabled = !canSave && !isBusy;\n\n  function finishSaving() {\n    onSave(trimmed);\n    setSaveState('saved');\n    schedule(() => setSaveState('idle'), SAVED_RESET_MS);\n  }\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    if (!canSave) {\n      return;\n    }\n    setSaveState('saving');\n    schedule(finishSaving, SAVE_DELAY_MS);\n  }\n\n  return (\n    <form onSubmit={submit} className={ROW}>\n      <label htmlFor={inputId} className={ROW_LABEL}>\n        Name\n      </label>\n      <div className='flex gap-2'>\n        <Input\n          id={inputId}\n          value={draft}\n          onChange={(event) => setDraft(event.target.value)}\n          aria-invalid={isEmpty}\n          className='flex-1'\n        />\n        <Button type='submit' variant='outline' disabled={isSaveDisabled}>\n          <Swap swapKey={saveState}>\n            {saveState === 'saving' && <LoaderIcon className='animate-spin' />}\n            {saveState === 'saved' && <CheckIcon />}\n          </Swap>\n          <motion.span layout transition={morphOf(shouldReduceMotion)}>\n            {saveLabelOf(saveState)}\n          </motion.span>\n        </Button>\n      </div>\n    </form>\n  );\n}\n\nfunction ColourField({\n  swatchId,\n  onChange,\n}: {\n  swatchId: string;\n  onChange: (swatchId: string) => void;\n}) {\n  const labelId = useId();\n  const pressedValues = [swatchId];\n\n  function changeValue(nextValues: unknown[]) {\n    const [nextValue] = nextValues;\n    const swatch = SWATCHES.find((candidate) => candidate.id === nextValue);\n    if (swatch) {\n      onChange(swatch.id);\n    }\n  }\n\n  return (\n    <div className={ROW}>\n      <p id={labelId} className={ROW_LABEL}>\n        Colour\n      </p>\n      <ToggleGroup\n        aria-labelledby={labelId}\n        value={pressedValues}\n        onValueChange={changeValue}\n        travel\n        indicatorClassName={SWATCH_RING}\n        className='gap-1'\n      >\n        {SWATCHES.map((swatch) => {\n          const gemStyle = { '--gem': swatch.color } as React.CSSProperties;\n          return (\n            <ToggleGroupItem\n              key={swatch.id}\n              value={swatch.id}\n              aria-label={swatch.label}\n              className='size-8 min-w-8 rounded-full p-0 hover:bg-transparent data-pressed:bg-transparent'\n            >\n              <span\n                aria-hidden='true'\n                style={gemStyle}\n                className='gem-plate block size-5 rounded-full'\n              />\n            </ToggleGroupItem>\n          );\n        })}\n      </ToggleGroup>\n    </div>\n  );\n}\n\nfunction VisibilityField({\n  visibility,\n  onChange,\n}: {\n  visibility: Visibility;\n  onChange: (visibility: Visibility) => void;\n}) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const labelId = useId();\n\n  return (\n    <div className={ROW}>\n      <p id={labelId} className={ROW_LABEL}>\n        Visibility\n      </p>\n      <div className='flex flex-col gap-2'>\n        <Segments\n          value={visibility}\n          segments={VISIBILITY_SEGMENTS}\n          onValueChange={onChange}\n          label='Visibility'\n          className='w-48'\n        />\n        <AnimatedSize>\n          <div className='relative'>\n            <AnimatePresence mode='popLayout' initial={false}>\n              <motion.p\n                key={visibility}\n                variants={blurOf(shouldReduceMotion)}\n                initial='enter'\n                animate='visible'\n                exit='exit'\n                className='text-muted-foreground text-xs'\n              >\n                {VISIBILITY_HINTS[visibility]}\n              </motion.p>\n            </AnimatePresence>\n          </div>\n        </AnimatedSize>\n      </div>\n    </div>\n  );\n}\n\nfunction ApprovalField({\n  isPrivate,\n  isRequired,\n  onChange,\n}: {\n  isPrivate: boolean;\n  isRequired: boolean;\n  onChange: (isRequired: boolean) => void;\n}) {\n  const labelId = useId();\n  const hintId = useId();\n  const isOn = isRequired && !isPrivate;\n\n  return (\n    <div className={ROW}>\n      <p id={labelId} className={ROW_LABEL}>\n        Join requests\n      </p>\n      <div className='flex items-start gap-3 sm:pt-1'>\n        <Switch\n          checked={isOn}\n          disabled={isPrivate}\n          onCheckedChange={onChange}\n          aria-labelledby={labelId}\n          aria-describedby={hintId}\n        />\n        <p id={hintId} className='text-muted-foreground text-xs'>\n          {isPrivate && 'Private teams only take people you invite'}\n          {!isPrivate && 'A manager approves each request before someone joins'}\n        </p>\n      </div>\n    </div>\n  );\n}\n\nfunction ArchiveField() {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [holdState, setHoldState] = useState<HoldState>('idle');\n  const { schedule, cancel } = useTimer();\n  const isFilled = holdState === 'holding';\n  const isArchived = holdState === 'archived';\n\n  function startHold() {\n    if (holdState !== 'idle') {\n      return;\n    }\n    setHoldState('holding');\n    schedule(() => setHoldState('archived'), HOLD_DURATION_MS);\n  }\n\n  function cancelHold() {\n    if (holdState !== 'holding') {\n      return;\n    }\n    cancel();\n    setHoldState('idle');\n  }\n\n  function pressPointer(event: React.PointerEvent<HTMLButtonElement>) {\n    if (event.button === 0) {\n      startHold();\n    }\n  }\n\n  function pressKey(event: React.KeyboardEvent<HTMLButtonElement>) {\n    const isHoldKey = HOLD_KEYS.has(event.key);\n    if (!isHoldKey) {\n      return;\n    }\n    event.preventDefault();\n    if (!event.repeat) {\n      startHold();\n    }\n  }\n\n  function releaseKey(event: React.KeyboardEvent<HTMLButtonElement>) {\n    if (HOLD_KEYS.has(event.key)) {\n      cancelHold();\n    }\n  }\n\n  function restore() {\n    setHoldState('idle');\n  }\n\n  return (\n    <div className={ROW}>\n      <p className={ROW_LABEL}>Archive</p>\n      <AnimatedSize>\n        <div aria-live='polite' className='relative'>\n          <AnimatePresence mode='popLayout' initial={false}>\n            <motion.div\n              key={String(isArchived)}\n              variants={blurOf(shouldReduceMotion)}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              className='flex flex-col items-start gap-2'\n            >\n              {!isArchived && (\n                <>\n                  <Button\n                    variant='outline'\n                    data-filled={isFilled || undefined}\n                    onPointerDown={pressPointer}\n                    onPointerUp={cancelHold}\n                    onPointerLeave={cancelHold}\n                    onPointerCancel={cancelHold}\n                    onKeyDown={pressKey}\n                    onKeyUp={releaseKey}\n                    onBlur={cancelHold}\n                    onContextMenu={(event) => event.preventDefault()}\n                    className='touch-manipulation [-webkit-touch-callout:none]'\n                  >\n                    <HoldLabel />\n                    <span\n                      aria-hidden='true'\n                      className={cn(HOLD_LAYER, holdFillOf(shouldReduceMotion))}\n                    >\n                      <HoldLabel />\n                    </span>\n                  </Button>\n                  <p className='text-muted-foreground text-xs'>\n                    Tasks and time stay readable. Nobody can add to the team\n                  </p>\n                </>\n              )}\n              {isArchived && (\n                <div className='flex flex-wrap items-center gap-3'>\n                  <p className='text-[13px]'>The team is archived</p>\n                  <Button size='sm' variant='outline' onClick={restore}>\n                    <ArchiveRestoreIcon />\n                    Restore\n                  </Button>\n                </div>\n              )}\n            </motion.div>\n          </AnimatePresence>\n        </div>\n      </AnimatedSize>\n    </div>\n  );\n}\n\nexport default function Teams06() {\n  const [name, setName] = useState('Atlas Redesign');\n  const [swatchId, setSwatchId] = useState(SWATCHES[0].id);\n  const [visibility, setVisibility] = useState<Visibility>('public');\n  const [isApprovalRequired, setIsApprovalRequired] = useState(true);\n  const swatch = swatchById(swatchId);\n  const isPrivate = visibility === 'private';\n\n  return (\n    <section\n      aria-label={`Settings of ${name}`}\n      className='bg-card hairline-ring ring-border flex w-full max-w-[34rem] flex-col gap-6 rounded-xl p-5 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n    >\n      <div className='flex items-center gap-3'>\n        <Swap swapKey={`${swatch.id}-${name}`}>\n          <TeamTile name={name} color={swatch.color} size='lg' />\n        </Swap>\n        <div className='min-w-0'>\n          <h3 className='truncate text-sm font-medium'>{name}</h3>\n          <p className='text-muted-foreground text-xs'>Team settings</p>\n        </div>\n      </div>\n      <NameField savedName={name} onSave={setName} />\n      <ColourField swatchId={swatchId} onChange={setSwatchId} />\n      <VisibilityField visibility={visibility} onChange={setVisibility} />\n      <ApprovalField\n        isPrivate={isPrivate}\n        isRequired={isApprovalRequired}\n        onChange={setIsApprovalRequired}\n      />\n      <ArchiveField />\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/teams-06.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/segments.tsx",
      "content": "'use client';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { ToggleGroup, ToggleGroupItem } from '@/registry/ndeko/ui/toggle-group';\n\nexport type Segment<Value extends string> = {\n  value: Value;\n  label: string;\n};\n\nconst THUMB =\n  'bg-card shadow-[0_1px_2px_rgb(0_0_0/0.08)] hairline-ring ring-foreground/10 dark:bg-foreground/[0.09] dark:ring-foreground/15';\n\ntype SegmentsProps<Value extends string> = {\n  value: Value;\n  segments: Segment<Value>[];\n  onValueChange: (value: Value) => void;\n  label: string;\n  className?: string;\n};\n\n/** One choice on a grey track: the raised thumb travels to the segment picked. */\nexport function Segments<Value extends string>({\n  value,\n  segments,\n  onValueChange,\n  label,\n  className,\n}: SegmentsProps<Value>) {\n  const pressedValues = [value];\n\n  function changeValue(nextValues: unknown[]) {\n    const [nextValue] = nextValues;\n    const segment = segments.find((candidate) => candidate.value === nextValue);\n    if (segment) {\n      onValueChange(segment.value);\n    }\n  }\n\n  return (\n    <ToggleGroup\n      aria-label={label}\n      value={pressedValues}\n      onValueChange={changeValue}\n      travel\n      size='sm'\n      indicatorClassName={THUMB}\n      className={cn('bg-foreground/[0.05] rounded-lg p-0.5', className)}\n    >\n      {segments.map((segment) => (\n        <ToggleGroupItem\n          key={segment.value}\n          value={segment.value}\n          className='h-6 flex-1 rounded-md px-2.5 text-xs'\n        >\n          {segment.label}\n        </ToggleGroupItem>\n      ))}\n    </ToggleGroup>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/segments.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/swap.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst SWAP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction variantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\ntype SwapProps = {\n  /** Changes when the content becomes another one. */\n  swapKey: string;\n  className?: string;\n  children: React.ReactNode;\n};\n\n/** An icon that becomes another: the old one shrinks out of focus while the new one settles. */\nexport function Swap({ swapKey, className, children }: SwapProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  return (\n    <AnimatePresence mode='popLayout' initial={false}>\n      <motion.span\n        key={swapKey}\n        variants={variantsOf(shouldReduceMotion)}\n        initial='enter'\n        animate='visible'\n        exit='exit'\n        transition={SWAP_TRANSITION}\n        className={cn('flex', className)}\n      >\n        {children}\n      </motion.span>\n    </AnimatePresence>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/swap.tsx"
    },
    {
      "path": "registry/ndeko/components/teams/_parts/team-tile.tsx",
      "content": "import { cn } from '@/registry/ndeko/lib/utils';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\n\nconst SIZE_CLASS = {\n  sm: 'size-5 rounded-[5px]',\n  md: 'size-6 rounded-md',\n  lg: 'size-9 rounded-lg',\n} as const;\n\ntype TeamTileProps = {\n  name: string;\n  color: string;\n  size?: keyof typeof SIZE_CLASS;\n  className?: string;\n};\n\n/** A team without a logo: a picture drawn from its name, in its colour. */\nexport function TeamTile({\n  name,\n  color,\n  size = 'md',\n  className,\n}: TeamTileProps) {\n  const sizeClass = SIZE_CLASS[size];\n\n  return (\n    <MeshTile seed={name} color={color} className={cn(sizeClass, className)} />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/teams/_parts/team-tile.tsx"
    }
  ],
  "categories": [
    "components",
    "teams"
  ],
  "type": "registry:component"
}