Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calendar): style recurring event scope radios with a design-system RadioGroup (#6422)

gbirman58734a0ab21d
diff --git a/apps/web/src/components/ui/components/RadioGroup.docs.tsx b/apps/web/src/components/ui/components/RadioGroup.docs.tsx
new file mode 100644
index 0000000000..151d5dd942
--- /dev/null
+++ b/apps/web/src/components/ui/components/RadioGroup.docs.tsx
@@ -0,0 +1,108 @@
+import { defineDoc } from '@app/features/ui-gallery/types';
+import { createSignal, For } from 'solid-js';
+import { RadioGroup } from './RadioGroup';
+
+const SCOPE_OPTIONS = [
+ { value: 'this_event', label: 'This event' },
+ { value: 'this_and_following', label: 'This and following events' },
+ { value: 'all', label: 'All events' },
+];
+
+// #region demo:basic
+function BasicDemo() {
+ const [value, setValue] = createSignal('this_event');
+
+ return (
+ <RadioGroup
+ value={value()}
+ onChange={setValue}
+ aria-label="Apply changes to"
+ class="text-sm text-ink"
+ >
+ <For each={SCOPE_OPTIONS}>
+ {(option) => (
+ <RadioGroup.Item value={option.value}>
+ <RadioGroup.ItemControl />
+ <RadioGroup.ItemLabel>{option.label}</RadioGroup.ItemLabel>
+ </RadioGroup.Item>
+ )}
+ </For>
+ </RadioGroup>
+ );
+}
+// #endregion
+
+// #region demo:horizontal
+function HorizontalDemo() {
+ return (
+ <RadioGroup
+ defaultValue="this_event"
+ aria-label="Apply changes to"
+ class="flex-row items-center gap-3 text-xs text-ink-muted"
+ >
+ <RadioGroup.Item value="this_event" class="gap-1.5">
+ <RadioGroup.ItemControl class="size-3.5" />
+ <RadioGroup.ItemLabel>This event</RadioGroup.ItemLabel>
+ </RadioGroup.Item>
+ <RadioGroup.Item value="all" class="gap-1.5">
+ <RadioGroup.ItemControl class="size-3.5" />
+ <RadioGroup.ItemLabel>All events</RadioGroup.ItemLabel>
+ </RadioGroup.Item>
+ </RadioGroup>
+ );
+}
+// #endregion
+
+// #region demo:disabled
+function DisabledDemo() {
+ return (
+ <RadioGroup
+ defaultValue="all"
+ disabled
+ aria-label="Apply changes to"
+ class="text-sm text-ink-disabled"
+ >
+ <For each={SCOPE_OPTIONS}>
+ {(option) => (
+ <RadioGroup.Item value={option.value}>
+ <RadioGroup.ItemControl />
+ <RadioGroup.ItemLabel>{option.label}</RadioGroup.ItemLabel>
+ </RadioGroup.Item>
+ )}
+ </For>
+ </RadioGroup>
+ );
+}
+// #endregion
+
+export default defineDoc({
+ name: 'RadioGroup',
+ category: 'Inputs',
+ description:
+ "A Kobalte radio group with the app's control styling. Composed from slots, so the item label, description, and error message are yours to place.",
+ status: 'stable',
+ exports: ['RadioGroup'],
+ import: "import { RadioGroup } from '@ui';",
+ demos: [
+ {
+ id: 'basic',
+ title: 'Basic',
+ description:
+ 'Pass `value` and `onChange` for a controlled group, or `defaultValue` to let it manage itself. `RadioGroup.ItemControl` renders the hidden input as well as the dot.',
+ render: BasicDemo,
+ },
+ {
+ id: 'horizontal',
+ title: 'Horizontal',
+ description:
+ 'The root defaults to a vertical stack; override with `flex-row` and a smaller `ItemControl` for a compact inline selector, e.g. a form footer.',
+ render: HorizontalDemo,
+ },
+ {
+ id: 'disabled',
+ title: 'Disabled',
+ description: '`disabled` on the root dims and locks every item.',
+ render: DisabledDemo,
+ },
+ ],
+});
diff --git a/apps/web/src/components/ui/components/RadioGroup.test.tsx b/apps/web/src/components/ui/components/RadioGroup.test.tsx
new file mode 100644
index 0000000000..52874d3301
--- /dev/null
+++ b/apps/web/src/components/ui/components/RadioGroup.test.tsx
@@ -0,0 +1,62 @@
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { createSignal, For } from 'solid-js';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { RadioGroup } from './RadioGroup';
+
+const OPTIONS = [
+ { value: 'this_event', label: 'This event' },
+ { value: 'all', label: 'All events' },
+];
+
+function Fixture(props: { onChange?: (value: string) => void }) {
+ const [value, setValue] = createSignal('this_event');
+ return (
+ <RadioGroup
+ value={value()}
+ onChange={(next) => {
+ setValue(next);
+ props.onChange?.(next);
+ }}
+ aria-label="Apply changes to"
+ >
+ <For each={OPTIONS}>
+ {(option) => (
+ <RadioGroup.Item value={option.value}>
+ <RadioGroup.ItemControl />
+ <RadioGroup.ItemLabel>{option.label}</RadioGroup.ItemLabel>
+ </RadioGroup.Item>
+ )}
+ </For>
+ </RadioGroup>
+ );
+}
+
+afterEach(cleanup);
+
+describe('RadioGroup', () => {
+ it('renders a native radio per item and checks the controlled value', () => {
+ render(() => <Fixture />);
+ const radios = screen.getAllByRole('radio') as HTMLInputElement[];
+ expect(radios).toHaveLength(2);
+ expect(radios[0].checked).toBe(true);
+ expect(radios[1].checked).toBe(false);
+ });
+
+ it('emits the new value and moves the selection on change', () => {
+ const onChange = vi.fn();
+ render(() => <Fixture onChange={onChange} />);
+ const radios = screen.getAllByRole('radio') as HTMLInputElement[];
+
+ fireEvent.click(radios[1]);
+
+ expect(onChange).toHaveBeenCalledWith('all');
+ expect(radios[1].checked).toBe(true);
+ expect(radios[0].checked).toBe(false);
+ });
+
+ it('associates each label with its control', () => {
+ render(() => <Fixture />);
+ const radio = screen.getByRole('radio', { name: 'All events' });
+ expect(radio).toBeInstanceOf(HTMLInputElement);
+ });
+});
diff --git a/apps/web/src/components/ui/components/RadioGroup.tsx b/apps/web/src/components/ui/components/RadioGroup.tsx
new file mode 100644
index 0000000000..e0d4857225
--- /dev/null
+++ b/apps/web/src/components/ui/components/RadioGroup.tsx
@@ -0,0 +1,102 @@
+import { RadioGroup as KobalteRadioGroup } from '@kobalte/core/radio-group';
+import type { ComponentProps } from 'solid-js';
+import { splitProps } from 'solid-js';
+import { cn } from '../utils/classname';
+
+/*
+<RadioGroup value={...} onChange={...}>
+ <RadioGroup.Item value="a">
+ <RadioGroup.ItemControl />
+ <RadioGroup.ItemLabel>Option A</RadioGroup.ItemLabel>
+ </RadioGroup.Item>
+</RadioGroup>
+
+A bare <RadioGroup.ItemControl /> renders its own dot indicator. It also
+renders the hidden input, so don't add <RadioGroup.ItemInput /> yourself.
+*/
+
+export type RadioGroupProps = ComponentProps<typeof KobalteRadioGroup>;
+type ItemProps = ComponentProps<typeof KobalteRadioGroup.Item>;
+type ItemControlProps = ComponentProps<typeof KobalteRadioGroup.ItemControl>;
+type ItemLabelProps = ComponentProps<typeof KobalteRadioGroup.ItemLabel>;
+
+const CONTROL_CLASS = cn(
+ 'inline-flex items-center justify-center size-4 shrink-0 rounded-full',
+ 'bg-surface border-1 border-edge',
+ 'data-checked:border-accent',
+ 'data-disabled:opacity-50 data-disabled:cursor-not-allowed',
+ 'data-invalid:border-failure',
+ 'peer-focus-visible:ring-2 peer-focus-visible:ring-accent'
+);
+
+function RadioGroupItem(props: ItemProps) {
+ const [local, rest] = splitProps(props, ['class']);
+ return (
+ <KobalteRadioGroup.Item
+ class={cn('inline-flex items-center gap-2', local.class)}
+ {...rest}
+ />
+ );
+}
+
+function RadioGroupItemControl(props: ItemControlProps) {
+ const [local, rest] = splitProps(props, ['class', 'children']);
+ return (
+ <>
+ <KobalteRadioGroup.ItemInput class="peer sr-only" />
+ <KobalteRadioGroup.ItemControl
+ class={cn(CONTROL_CLASS, local.class)}
+ {...rest}
+ >
+ {local.children ?? (
+ <KobalteRadioGroup.ItemIndicator class="size-2 rounded-full bg-accent" />
+ )}
+ </KobalteRadioGroup.ItemControl>
+ </>
+ );
+}
+
+function RadioGroupItemLabel(props: ItemLabelProps) {
+ const [local, rest] = splitProps(props, ['class']);
+ return <KobalteRadioGroup.ItemLabel class={cn(local.class)} {...rest} />;
+}
+
+/**
+ * A Kobalte radio group with the app's control styling, composed from slots so
+ * the item label, description, and error message are yours to place.
+ *
+ * @do Give the group an `aria-label` (or a `RadioGroup.Label`) describing the
+ * choice.
+ * @do Render a `RadioGroup.ItemLabel` for every item, even when the visible
+ * text sits elsewhere.
+ * @dont Do not add `RadioGroup.ItemInput` yourself; `RadioGroup.ItemControl`
+ * already renders one.
+ * @dont Do not use a radio group for two mutually exclusive actions inline —
+ * that is a SegmentedControl.
+ */
+export const RadioGroup = Object.assign(
+ (props: RadioGroupProps) => {
+ const [local, rest] = splitProps(props, ['class']);
+ return (
+ <KobalteRadioGroup
+ class={cn('flex flex-col gap-2', local.class)}
+ {...rest}
+ />
+ );
+ },
+ {
+ Label:
+ KobalteRadioGroup.Label /* passthrough — styled via class at use sites */,
+ Description:
+ KobalteRadioGroup.Description /* passthrough — styled via class at use sites */,
+ ErrorMessage:
+ KobalteRadioGroup.ErrorMessage /* passthrough — styled via class at use sites */,
+ Item: RadioGroupItem,
+ ItemInput:
+ KobalteRadioGroup.ItemInput /* passthrough — ItemControl already renders one */,
+ ItemControl: RadioGroupItemControl,
+ ItemIndicator: KobalteRadioGroup.ItemIndicator,
+ ItemLabel: RadioGroupItemLabel,
+ ItemDescription: KobalteRadioGroup.ItemDescription,
+ }
+);
diff --git a/apps/web/src/components/ui/index.ts b/apps/web/src/components/ui/index.ts
index 0e8174ebeb..c98abe4c68 100644
--- a/apps/web/src/components/ui/index.ts
+++ b/apps/web/src/components/ui/index.ts
@@ -123,6 +123,8 @@ export { NavRow } from './components/NavRow';
export { Panel } from './components/Panel';
export type { PillButtonProps, PillButtonTone } from './components/PillButton';
export { PillButton } from './components/PillButton';
+export type { RadioGroupProps } from './components/RadioGroup';
+export { RadioGroup } from './components/RadioGroup';
export { Scroll } from './components/Scroll';
export { SegmentedControl } from './components/SegmentedControl';
export type {
diff --git a/apps/web/src/features/block-calendar/components/EventRsvpScopeDialog.tsx b/apps/web/src/features/block-calendar/components/EventRsvpScopeDialog.tsx
index 8f25b7d22d..a3926764c1 100644
--- a/apps/web/src/features/block-calendar/components/EventRsvpScopeDialog.tsx
+++ b/apps/web/src/features/block-calendar/components/EventRsvpScopeDialog.tsx
@@ -1,10 +1,10 @@
import { MobileDrawer } from '@components/app/mobile/MobileDrawer';
import { isMobile } from '@core/mobile/isMobile';
-import { RadioGroup } from '@kobalte/core/radio-group';
+import { RadioGroup as KobalteRadioGroup } from '@kobalte/core/radio-group';
import CheckIcon from '@phosphor/check.svg';
import CloseIcon from '@phosphor/x.svg';
import type { CalendarRsvpScope } from '@service-email/client';
-import { Button, Dialog, Panel } from '@ui';
+import { Button, Dialog, Panel, RadioGroup } from '@ui';
import { For, Show } from 'solid-js';
const SCOPE_OPTIONS = [
@@ -41,21 +41,25 @@ export function EventRsvpScopeDialog(props: {
</Dialog.Title>
</Panel.Header>
<Panel.Body class="flex flex-col gap-3 p-3">
- <div class="flex max-w-80 flex-col gap-2 text-sm text-ink-muted">
+ <RadioGroup
+ value={props.scope}
+ onChange={(value) =>
+ props.onScopeChange(value as CalendarRsvpScope)
+ }
+ aria-label="Response applies to"
+ class="max-w-80 text-sm text-ink-muted"
+ >
<For each={SCOPE_OPTIONS}>
{(option) => (
- <label class="flex items-center gap-2">
- <input
- type="radio"
- name="rsvp-scope"
- checked={props.scope === option.scope}
- onChange={() => props.onScopeChange(option.scope)}
- />
- {option.label}
- </label>
+ <RadioGroup.Item value={option.scope}>
+ <RadioGroup.ItemControl />
+ <RadioGroup.ItemLabel>
+ {option.label}
+ </RadioGroup.ItemLabel>
+ </RadioGroup.Item>
)}
</For>
- </div>
+ </RadioGroup>
<div class="flex justify-end gap-1 pt-2">
<Button
variant="ghost"
@@ -110,7 +114,7 @@ export function EventRsvpScopeDialog(props: {
Apply your response to:
</p>
<MobileDrawer.Section>
- <RadioGroup
+ <KobalteRadioGroup
value={props.scope}
onChange={(value) => {
const option = SCOPE_OPTIONS.find(
@@ -123,23 +127,23 @@ export function EventRsvpScopeDialog(props: {
>
<For each={SCOPE_OPTIONS}>
{(option) => (
- <RadioGroup.Item
+ <KobalteRadioGroup.Item
value={option.scope}
class="relative rounded-[20px] text-ink data-checked:bg-ink/8 focus-within:outline-2 focus-within:outline-accent"
>
- <RadioGroup.ItemInput />
- <RadioGroup.ItemLabel class="flex min-h-12 items-center justify-between gap-3 px-4 py-3 text-base">
+ <KobalteRadioGroup.ItemInput />
+ <KobalteRadioGroup.ItemLabel class="flex min-h-12 items-center justify-between gap-3 px-4 py-3 text-base">
{option.label}
- <RadioGroup.ItemControl class="flex size-5 items-center justify-center">
- <RadioGroup.ItemIndicator>
+ <KobalteRadioGroup.ItemControl class="flex size-5 items-center justify-center">
+ <KobalteRadioGroup.ItemIndicator>
<CheckIcon class="size-5 text-accent" />
- </RadioGroup.ItemIndicator>
- </RadioGroup.ItemControl>
- </RadioGroup.ItemLabel>
- </RadioGroup.Item>
+ </KobalteRadioGroup.ItemIndicator>
+ </KobalteRadioGroup.ItemControl>
+ </KobalteRadioGroup.ItemLabel>
+ </KobalteRadioGroup.Item>
)}
</For>
- </RadioGroup>
+ </KobalteRadioGroup>
</MobileDrawer.Section>
<div class="flex gap-3 px-6 pt-5 pb-2">
<Button
diff --git a/apps/web/src/features/block-calendar/components/SelectedEventDetails.tsx b/apps/web/src/features/block-calendar/components/SelectedEventDetails.tsx
index 704503bf31..c3cde6a403 100644
--- a/apps/web/src/features/block-calendar/components/SelectedEventDetails.tsx
+++ b/apps/web/src/features/block-calendar/components/SelectedEventDetails.tsx
@@ -32,9 +32,10 @@ import {
DeleteDialog,
Layer,
type ManagedDialogProps,
+ RadioGroup,
useImperativeDialog,
} from '@ui';
-import { type Accessor, createMemo, createSignal, Show } from 'solid-js';
+import { type Accessor, createMemo, createSignal, For, Show } from 'solid-js';
import { copyCalendarEventMention } from '../copy-event-mention';
import { copyGuestEmails } from '../copy-guest-emails';
import { EventRsvpSection } from './EventRsvpSection';
@@ -347,6 +348,15 @@ function useDeleteEventDialog(props: {
return { open, isOpen: dialog.isOpen };
}
+const DELETE_SCOPE_OPTIONS = [
+ { scope: 'this_event', label: 'This event' },
+ { scope: 'this_and_following', label: 'This and following events' },
+ { scope: 'all', label: 'All events' },
+] as const satisfies readonly {
+ scope: CalendarDeletionScope;
+ label: string;
+}[];
+
function DeleteEventDialog(
props: ManagedDialogProps & {
event: CalendarEvent;
@@ -395,38 +405,25 @@ function DeleteEventDialog(
</p>
}
>
- <div class="flex flex-col gap-2">
+ <div class="flex flex-col gap-3">
<p>
Remove “{props.event.title || 'Untitled event'}”? Guests will be
notified.
</p>
- <label class="flex items-center gap-2">
- <input
- type="radio"
- name="delete-scope"
- checked={scope() === 'this_event'}
- onChange={() => setScope('this_event')}
- />
- This event
- </label>
- <label class="flex items-center gap-2">
- <input
- type="radio"
- name="delete-scope"
- checked={scope() === 'this_and_following'}
- onChange={() => setScope('this_and_following')}
- />
- This and following events
- </label>
- <label class="flex items-center gap-2">
- <input
- type="radio"
- name="delete-scope"
- checked={scope() === 'all'}
- onChange={() => setScope('all')}
- />
- All events
- </label>
+ <RadioGroup
+ value={scope()}
+ onChange={(value) => setScope(value as CalendarDeletionScope)}
+ aria-label="Delete recurring event"
+ >
+ <For each={DELETE_SCOPE_OPTIONS}>
+ {(option) => (
+ <RadioGroup.Item value={option.scope}>
+ <RadioGroup.ItemControl />
+ <RadioGroup.ItemLabel>{option.label}</RadioGroup.ItemLabel>
+ </RadioGroup.Item>
+ )}
+ </For>
+ </RadioGroup>
</div>
</Show>
</DeleteDialog>
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.tsx b/apps/web/src/features/calendar/components/composer/EventForm.tsx
index 440349b5e3..6dde515655 100644
--- a/apps/web/src/features/calendar/components/composer/EventForm.tsx
+++ b/apps/web/src/features/calendar/components/composer/EventForm.tsx
@@ -1,7 +1,7 @@
import { MarkdownTextarea } from '@core/component/LexicalMarkdown/component/core/MarkdownTextarea';
import SpinnerIcon from '@phosphor/spinner.svg';
import type { CalendarUpdateScope } from '@service-email/client';
-import { Button, cn, Layer } from '@ui';
+import { Button, cn, Layer, RadioGroup } from '@ui';
import {
createEffect,
createSignal,
@@ -356,26 +356,22 @@ export function EventForm(props: EventFormProps) {
<div class="flex shrink-0 items-center justify-end gap-3">
<Show when={props.showRecurringEditNotice}>
- <div
- role="radiogroup"
+ <RadioGroup
+ value={editScope()}
+ onChange={(value) => setEditScope(value as CalendarUpdateScope)}
+ disabled={formIsDisabled()}
aria-label="Apply changes to"
- class="mr-auto flex items-center gap-3 text-xs text-ink-muted"
+ class="mr-auto flex-row items-center gap-3 text-xs text-ink-muted"
>
<For each={RECURRING_EDIT_SCOPE_OPTIONS}>
{(option) => (
- <label class="flex items-center gap-1.5">
- <input
- type="radio"
- name="event-edit-scope"
- checked={editScope() === option.scope}
- onChange={() => setEditScope(option.scope)}
- disabled={formIsDisabled()}
- />
- {option.label}
- </label>
+ <RadioGroup.Item value={option.scope} class="gap-1.5">
+ <RadioGroup.ItemControl class="size-3.5" />
+ <RadioGroup.ItemLabel>{option.label}</RadioGroup.ItemLabel>
+ </RadioGroup.Item>
)}
</For>
- </div>
+ </RadioGroup>
</Show>
<Button
type="button"