Project visibility
Everyone in the workspace, Only the project team, Only me. The team option has a description with the head count.
Components / InputsStable
Picks exactly one option from a short list that stays visible, so people can compare before choosing.
'use client'
import { useId, useState, type Ref } from 'react'
import { Note } from './Note'
// Nacre Radio: pick exactly one of a short visible list. A fieldset of native radios drawn by CSS, so arrow keys work
// the platform way. React plus Tailwind classes only; needs nacre-theme.css. Motion: the new dot grows from .6 with
// opacity on the spring curve (base 240, a small overshoot) while the old one shrinks back to .6 and fades, quicker
// (instant 100), so a fast run of clicks retargets instead of restarting. A pointer press squeezes the circle to .9 and
// lets go on the spring. With the keyboard (arrow keys) the choice swaps at once; reduced motion or
// [data-nacre-motion="off"]: no movement.
// invalid marks the group; error is the message (it replaces the hint and implies invalid). ref reaches the fieldset.
export type RadioOption = { value: string; label: string; description?: string; disabled?: boolean }
export type RadioGroupProps = {
label: string
options: RadioOption[]
name?: string
value?: string
defaultValue?: string
onValueChange?: (value: string) => void
orientation?: 'vertical' | 'horizontal'
size?: 'sm' | 'md'
disabled?: boolean
required?: boolean
invalid?: boolean
hint?: string
error?: string
className?: string
ref?: Ref<HTMLFieldSetElement>
}
// The circle squeezes on a pointer press (arrow keys and Space leave focus-visible, so they do not) and springs back.
const press =
'transition-[scale] duration-(--nx-dur-gentle) ease-spring ' +
'motion-safe:group-[:active:not(:has(:focus-visible,:disabled))]/item:scale-90 group-active/item:duration-(--nx-dur-instant) group-active/item:ease-out'
// Leaving: quick fade and shrink. Arriving: opacity instant, scale on the spring. Keyboard: no transition at all.
const dot =
'[transition:opacity_var(--nx-dur-instant)_var(--nx-ease-out),scale_var(--nx-dur-instant)_var(--nx-ease-out)] ' +
'peer-checked:[transition:opacity_var(--nx-dur-instant)_var(--nx-ease-out),scale_var(--nx-dur-base)_var(--nx-ease-spring)] group-data-[kbd]/radio:transition-none!'
export function RadioGroup({
label,
options,
name,
value,
defaultValue,
onValueChange,
orientation = 'vertical',
size = 'md',
disabled = false,
required,
invalid = false,
hint,
error,
className = '',
ref,
}: RadioGroupProps) {
const auto = useId()
const groupName = name ?? auto
const hintId = `${auto}-hint`
const bad = invalid || Boolean(error)
const note = error || hint
const [inner, setInner] = useState(defaultValue)
const current = value ?? inner
const choose = (v: string) => {
if (value === undefined) setInner(v)
onValueChange?.(v)
}
const border = bad ? 'border-error' : 'border-line enabled:hover:border-line-strong'
return (
<fieldset
data-part="root"
ref={ref}
disabled={disabled}
aria-describedby={note ? hintId : undefined}
onKeyDown={(e) => e.currentTarget.setAttribute('data-kbd', '')}
onPointerDown={(e) => e.currentTarget.removeAttribute('data-kbd')}
className={`group/radio m-0 flex min-w-0 flex-col gap-3 border-0 p-0 ${className}`}
>
<legend data-part="legend" className="mb-3 p-0 text-label text-fg-strong">{label}</legend>
<div className={orientation === 'horizontal' ? 'flex flex-wrap gap-x-6 gap-y-3' : 'flex flex-col gap-3'}>
{options.map((o, n) => {
const id = `${auto}-${n}`
const off = disabled || o.disabled
return (
<div key={o.value} data-part="item" className="group/item flex items-start gap-3">
<span data-press-scale="" className={`${press} relative inline-grid shrink-0 place-items-center ${size === 'sm' ? 'mt-[3px] size-3.5' : 'mt-px size-[18px]'}`}>
<input
id={id}
type="radio"
name={groupName}
value={o.value}
checked={current === o.value}
disabled={o.disabled}
required={required}
{...(bad ? { 'aria-invalid': true } : {})}
aria-describedby={o.description ? `${id}-desc` : undefined}
onChange={() => choose(o.value)}
data-part="control"
className={`peer col-start-1 row-start-1 m-0 size-full cursor-pointer appearance-none rounded-full border bg-surface transition-[border-color] duration-(--nx-dur-quick) ease-out checked:border-accent/45 focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--nx-fg-muted)_16%,transparent)] disabled:cursor-not-allowed disabled:border-line-subtle disabled:bg-sunken ${border}`}
/>
<span
data-part="dot"
aria-hidden="true"
className={`pointer-events-none absolute inset-0 m-auto ${size === 'sm' ? 'size-1.5' : 'size-2'} scale-[.6] rounded-full bg-accent opacity-0 peer-checked:scale-100 peer-checked:opacity-100 peer-disabled:bg-fg-disabled ${dot}`}
/>
</span>
<span className="flex min-w-0 flex-col gap-0.5">
<label data-part="label" htmlFor={id} className={`text-body ${off ? 'cursor-not-allowed text-fg-disabled' : 'cursor-pointer text-fg-strong'}`}>{o.label}</label>
{o.description && <span id={`${id}-desc`} className="text-caption text-fg-muted">{o.description}</span>}
</span>
</div>
)
})}
</div>
<Note part={error ? 'error' : 'hint'} id={hintId} className="[--nx-note-gap:12px]">{error || hint}</Note>
</fieldset>
)
}
'use client'
import { useEffect, useRef, useState, type ReactNode } from 'react'
// Nacre Note: the hint, error or success line under a field. It rolls out: the row grows from 0 to its height (base 240
// out) while the words fade and rise 4 px into place, so the fields below glide down instead of jumping. On the way out
// it keeps its last words on screen while the row rolls back up (quick 160), then unmounts the words. reserve keeps one
// line of space even when there is nothing to say, for a field whose message is likely to appear (no layout shift at all).
// With motion off or reduced, it changes at once. Parts: data-part="hint" (muted), "error" and "success" (their tone).
// React plus Tailwind classes only; needs nacre-theme.css. --nx-note-gap (default 6 px) is the gap the parent puts above
// the note, so the collapsed row cancels it.
export type NoteProps = {
id?: string
part: 'hint' | 'error' | 'success'
children?: ReactNode
className?: string
as?: 'p' | 'span'
/** Keep one line of space while empty. */
reserve?: boolean
}
const tone = { hint: 'text-fg-muted', error: 'text-error-strong', success: 'text-success-strong' } as const
export function Note({ id, part, children, className = '', as: Tag = 'p', reserve = false }: NoteProps) {
const has = children !== undefined && children !== null && children !== false && children !== ''
const [last, setLast] = useState<ReactNode>(children)
const el = useRef<HTMLElement>(null)
const [leaving, setLeaving] = useState(false)
const [seen, setSeen] = useState(has)
if (has !== seen) {
setSeen(has)
setLeaving(!has)
}
if (has && children !== last) setLast(children)
useEffect(() => {
if (!leaving) return
const node = el.current
const raw = node ? getComputedStyle(node).transitionDuration.split(',')[0] : '0s'
const ms = parseFloat(raw) * (raw.endsWith('ms') ? 1 : 1000)
if (!ms) {
setLeaving(false)
return
}
const t = setTimeout(() => setLeaving(false), ms)
return () => clearTimeout(t)
}, [leaving])
const Element = 'span' as unknown as 'p'
const open = has
const hasWords = has || leaving
// The row: a one-cell grid whose track animates 0fr to 1fr. The negative margin cancels the parent's gap while closed.
const wrap = open || reserve ? 'grid-rows-[1fr]' : 'grid-rows-[0fr] mt-[calc(var(--nx-note-gap,6px)*-1)]'
const Wrap = Tag as 'p'
return (
<Wrap
data-part="note"
aria-hidden={hasWords ? undefined : true}
className={`grid transition-[grid-template-rows,margin-top] ease-out ${open ? 'duration-(--nx-dur-base)' : 'duration-(--nx-dur-quick)'} ${wrap} ${className}`}
>
<span className="block min-h-0 overflow-hidden">
{hasWords && (
<Element
ref={el as React.Ref<HTMLParagraphElement>}
data-part={part}
id={id}
aria-hidden={has ? undefined : true}
className={`block text-caption ${tone[part]} transition-[opacity,translate] duration-(--nx-dur-quick) ease-out starting:-translate-y-1 starting:opacity-0 ${has ? '' : '-translate-y-1 opacity-0'}`}
>
{has ? children : last}
</Element>
)}
{reserve && !hasWords && <span className="block text-caption" aria-hidden="true"> </span>}
</span>
</Wrap>
)
}
<fieldset data-part="root" class="group/radio m-0 flex min-w-0 flex-col gap-3 border-0 p-0 ">
<legend data-part="legend" class="mb-3 p-0 text-label text-fg-strong">Who can see this project</legend>
<div class="flex flex-col gap-3">
<div data-part="item" class="group/item flex items-start gap-3">
<span data-press-scale="" class="transition-[scale] duration-(--nx-dur-gentle) ease-spring motion-safe:group-[:active:not(:has(:focus-visible,:disabled))]/item:scale-90 group-active/item:duration-(--nx-dur-instant) group-active/item:ease-out relative inline-grid shrink-0 place-items-center mt-px size-[18px]">
<input id="_R_0_-0" type="radio" data-part="control" class="peer col-start-1 row-start-1 m-0 size-full cursor-pointer appearance-none rounded-full border bg-surface transition-[border-color] duration-(--nx-dur-quick) ease-out checked:border-accent/45 focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--nx-fg-muted)_16%,transparent)] disabled:cursor-not-allowed disabled:border-line-subtle disabled:bg-sunken border-line enabled:hover:border-line-strong" name="_R_0_" value="workspace"/>
<span data-part="dot" aria-hidden="true" class="pointer-events-none absolute inset-0 m-auto size-2 scale-[.6] rounded-full bg-accent opacity-0 peer-checked:scale-100 peer-checked:opacity-100 peer-disabled:bg-fg-disabled [transition:opacity_var(--nx-dur-instant)_var(--nx-ease-out),scale_var(--nx-dur-instant)_var(--nx-ease-out)] peer-checked:[transition:opacity_var(--nx-dur-instant)_var(--nx-ease-out),scale_var(--nx-dur-base)_var(--nx-ease-spring)] group-data-[kbd]/radio:transition-none!"></span>
</span>
<span class="flex min-w-0 flex-col gap-0.5">
<label data-part="label" for="_R_0_-0" class="text-body cursor-pointer text-fg-strong">Everyone in the workspace</label>
</span>
</div>
<div data-part="item" class="group/item flex items-start gap-3">
<span data-press-scale="" class="transition-[scale] duration-(--nx-dur-gentle) ease-spring motion-safe:group-[:active:not(:has(:focus-visible,:disabled))]/item:scale-90 group-active/item:duration-(--nx-dur-instant) group-active/item:ease-out relative inline-grid shrink-0 place-items-center mt-px size-[18px]">
<input id="_R_0_-1" type="radio" aria-describedby="_R_0_-1-desc" data-part="control" class="peer col-start-1 row-start-1 m-0 size-full cursor-pointer appearance-none rounded-full border bg-surface transition-[border-color] duration-(--nx-dur-quick) ease-out checked:border-accent/45 focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--nx-fg-muted)_16%,transparent)] disabled:cursor-not-allowed disabled:border-line-subtle disabled:bg-sunken border-line enabled:hover:border-line-strong" name="_R_0_" checked="" value="team"/>
<span data-part="dot" aria-hidden="true" class="pointer-events-none absolute inset-0 m-auto size-2 scale-[.6] rounded-full bg-accent opacity-0 peer-checked:scale-100 peer-checked:opacity-100 peer-disabled:bg-fg-disabled [transition:opacity_var(--nx-dur-instant)_var(--nx-ease-out),scale_var(--nx-dur-instant)_var(--nx-ease-out)] peer-checked:[transition:opacity_var(--nx-dur-instant)_var(--nx-ease-out),scale_var(--nx-dur-base)_var(--nx-ease-spring)] group-data-[kbd]/radio:transition-none!"></span>
</span>
<span class="flex min-w-0 flex-col gap-0.5">
<label data-part="label" for="_R_0_-1" class="text-body cursor-pointer text-fg-strong">Only the project team</label>
<span id="_R_0_-1-desc" class="text-caption text-fg-muted">Five people today.</span>
</span>
</div>
<div data-part="item" class="group/item flex items-start gap-3">
<span data-press-scale="" class="transition-[scale] duration-(--nx-dur-gentle) ease-spring motion-safe:group-[:active:not(:has(:focus-visible,:disabled))]/item:scale-90 group-active/item:duration-(--nx-dur-instant) group-active/item:ease-out relative inline-grid shrink-0 place-items-center mt-px size-[18px]">
<input id="_R_0_-2" type="radio" data-part="control" class="peer col-start-1 row-start-1 m-0 size-full cursor-pointer appearance-none rounded-full border bg-surface transition-[border-color] duration-(--nx-dur-quick) ease-out checked:border-accent/45 focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--nx-fg-muted)_16%,transparent)] disabled:cursor-not-allowed disabled:border-line-subtle disabled:bg-sunken border-line enabled:hover:border-line-strong" name="_R_0_" value="me"/>
<span data-part="dot" aria-hidden="true" class="pointer-events-none absolute inset-0 m-auto size-2 scale-[.6] rounded-full bg-accent opacity-0 peer-checked:scale-100 peer-checked:opacity-100 peer-disabled:bg-fg-disabled [transition:opacity_var(--nx-dur-instant)_var(--nx-ease-out),scale_var(--nx-dur-instant)_var(--nx-ease-out)] peer-checked:[transition:opacity_var(--nx-dur-instant)_var(--nx-ease-out),scale_var(--nx-dur-base)_var(--nx-ease-spring)] group-data-[kbd]/radio:transition-none!"></span>
</span>
<span class="flex min-w-0 flex-col gap-0.5">
<label data-part="label" for="_R_0_-2" class="text-body cursor-pointer text-fg-strong">Only me</label>
</span>
</div>
</div>
<p data-part="note" aria-hidden="true" class="grid transition-[grid-template-rows,margin-top] ease-out duration-(--nx-dur-quick) grid-rows-[0fr] mt-[calc(var(--nx-note-gap,6px)*-1)] [--nx-note-gap:12px]">
<span class="block min-h-0 overflow-hidden"></span>
</p>
</fieldset>/* The Tailwind theme lines Radio uses. They come from nacre-theme.css (Resources, Tokens), which also defines
the --nx-* values these lines point at. Import that file once; this list is what this component needs from it. */
@theme inline {
--color-surface: var(--nx-surface);
--color-sunken: var(--nx-sunken);
--color-fg-strong: var(--nx-fg-strong);
--color-fg-muted: var(--nx-fg-muted);
--color-fg-disabled: var(--nx-fg-disabled);
--color-line-subtle: var(--nx-line-subtle);
--color-line: var(--nx-line);
--color-line-strong: var(--nx-line-strong);
--color-accent: var(--nx-accent);
--color-success-strong: var(--nx-success-strong);
--color-error-strong: var(--nx-error-strong);
--color-error: var(--nx-error);
--text-body: 0.875rem;
--text-body--line-height: 1.25rem;
--text-body--letter-spacing: 0em;
--text-body--font-weight: 400;
--text-label: 0.8125rem;
--text-label--line-height: 1rem;
--text-label--letter-spacing: 0em;
--text-label--font-weight: 600;
--text-caption: 0.75rem;
--text-caption--line-height: 1rem;
--text-caption--letter-spacing: 0.01em;
--text-caption--font-weight: 400;
--spacing: 0.25rem;
--ease-out: cubic-bezier(.23, 1, .32, 1);
--ease-spring: linear(0, 0.036 3.1%, 0.128 6.3%, 0.251 9.4%, 0.389 12.5%, 0.526 15.6%, 0.655 18.8%, 0.769 21.9%, 0.864 25%, 0.939 28.1%, 0.996 31.3%, 1.036 34.4%, 1.062 37.5%, 1.075 40.6%, 1.08 43.8%, 1.077 46.9%, 1.07 50%, 1.061 53.1%, 1.05 56.3%, 1.039 59.4%, 1.028 62.5%, 1.019 65.6%, 1.011 68.8%, 1.005 71.9%, 1.001 75%, 0.997 78.1%, 0.995 81.3%, 0.994 84.4%, 0.994 87.5%, 0.994 90.6%, 0.994 93.8%, 0.995 96.9%, 1);
}
Everyone in the workspace, Only the project team, Only me. The team option has a description with the head count.
In a calendar event, a horizontal group offers 10 minutes, 1 hour and 1 day before.
DoPreselect the safest sensible option.
Don'tLeave a required group empty with no hint of what is expected.
DoKeep labels parallel and short, in a meaningful order.
Don'tMix sentence lengths and orders so the options are hard to compare.