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.

feat(ui): radio / checkbox (#3606)

Fake-User242e9d3e7884
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/group-dropdown.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/group-dropdown.tsx
index 93d8b04dab..68ad00c6ed 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/group-dropdown.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/group-dropdown.tsx
@@ -2,10 +2,10 @@ import type {
GroupOption,
GroupOptionId,
} from '@app/component/next-soup/soup-view/group-options';
-import CheckIcon from '@phosphor/check.svg';
import StackSimpleIcon from '@phosphor/stack-simple.svg';
import { Dropdown, Tooltip } from '@ui';
-import { type Component, For, Show } from 'solid-js';
+import { type Component, For } from 'solid-js';
+import { TypeIndicator } from './unified-filter-dropdown';
interface GroupDropdownProps {
value: () => GroupOptionId;
@@ -33,6 +33,7 @@ export const GroupDropdown: Component<GroupDropdownProps> = (props) => {
<For each={props.options}>
{(option) => (
<Dropdown.Item onSelect={() => props.onChange(option.value)}>
+ <TypeIndicator active={props.value() === option.value} />
<span
class="flex-1 truncate"
classList={{
@@ -42,11 +43,6 @@ export const GroupDropdown: Component<GroupDropdownProps> = (props) => {
>
{option.label}
</span>
- <span class="size-3.5 flex items-center justify-center shrink-0">
- <Show when={props.value() === option.value}>
- <CheckIcon class="size-3 text-accent" />
- </Show>
- </span>
</Dropdown.Item>
)}
</For>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/searchable-multi-select.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
index 074ca489c9..349be22125 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/searchable-multi-select.tsx
@@ -44,9 +44,15 @@ const SearchableMultiSelectItem = (itemProps: {
item={itemProps.item}
class="w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left text-xs data-highlighted:bg-ink/5 group cursor-default"
>
- <span class="size-4 flex items-center justify-center shrink-0 rounded-xs border border-edge group-data-selected:bg-accent group-data-selected:border-accent">
+ <span
+ class={cn(
+ 'size-3.5 flex items-center justify-center shrink-0 rounded-sm border text-surface',
+ 'border-transparent group-hover:not-hover:border-edge-muted group-data-highlighted:not-hover:border-edge-muted hover:border-accent',
+ 'group-data-selected:bg-accent group-data-selected:border-accent'
+ )}
+ >
<Combobox.ItemIndicator>
- <CheckIcon class="size-2.5 text-surface" />
+ <CheckIcon class="size-2.5" />
</Combobox.ItemIndicator>
</span>
<Show when={itemProps.item.rawValue.icon}>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/sort-dropdown.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/sort-dropdown.tsx
index 6dd0259e6e..4453989d1f 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/sort-dropdown.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/sort-dropdown.tsx
@@ -3,10 +3,10 @@ import type {
SystemSortOption,
} from '@app/component/next-soup/soup-view/sort-options';
import { TOKENS } from '@core/hotkey/tokens';
-import CheckIcon from '@phosphor/check.svg';
import SortIcon from '@phosphor-icons/core/regular/funnel-simple.svg?component-solid';
import { Dropdown, Tooltip } from '@ui';
import { type Component, For, Show } from 'solid-js';
+import { TypeIndicator } from './unified-filter-dropdown';
interface SortDropdownProps {
/** Current sort value */
@@ -41,6 +41,7 @@ export const SortDropdown: Component<SortDropdownProps> = (props) => {
<For each={options()}>
{(option) => (
<Dropdown.Item onSelect={() => props.onChange(option.value)}>
+ <TypeIndicator active={props.value() === option.value} />
<Show when={option.icon}>
{(icon) => (
<span class="size-3.5 flex items-center justify-center shrink-0 text-ink-muted">
@@ -57,11 +58,6 @@ export const SortDropdown: Component<SortDropdownProps> = (props) => {
>
{option.label}
</span>
- <span class="size-3.5 flex items-center justify-center shrink-0">
- <Show when={props.value() === option.value}>
- <CheckIcon class="size-3 text-accent" />
- </Show>
- </span>
</Dropdown.Item>
)}
</For>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx
index 9dc4fa7794..9d827d7332 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx
@@ -51,15 +51,17 @@ import {
} from './search-filter-controls';
import { SearchableMultiSelectInline } from './searchable-multi-select';
-const TypeIndicator = (props: { active: boolean }) => (
+export const TypeIndicator = (props: { active: boolean }) => (
<span
class={cn(
- 'size-4 flex items-center justify-center shrink-0 rounded-full border',
- props.active ? 'bg-accent border-accent' : 'border-edge'
+ 'size-3.5 flex items-center justify-center shrink-0 rounded-sm border text-surface',
+ props.active
+ ? 'bg-accent border-accent'
+ : 'border-transparent group-hover:not-hover:border-edge-muted group-data-highlighted:not-hover:border-edge-muted hover:border-accent'
)}
>
<Show when={props.active}>
- <CheckIcon class="size-2.5 text-surface" />
+ <CheckIcon class="size-2.5" />
</Show>
</span>
);
@@ -917,18 +919,7 @@ export const UnifiedFilterDropdown = (
onSelect={() => toggleFilter(option.id)}
closeOnSelect={!category.multiple}
>
- <span
- class={cn(
- 'size-4 flex items-center justify-center shrink-0 rounded border',
- active()
- ? 'bg-accent border-accent'
- : 'border-edge'
- )}
- >
- <Show when={active()}>
- <CheckIcon class="size-2.5 text-surface" />
- </Show>
- </span>
+ <TypeIndicator active={active()} />
<Show when={option.icon}>
{(icon) => (
@@ -1035,16 +1026,7 @@ export const UnifiedFilterDropdown = (
onSelect={() => toggleFilter(option.id)}
closeOnSelect={!categories()[0]!.multiple}
>
- <span
- class={cn(
- 'size-4 flex items-center justify-center shrink-0 rounded border',
- active() ? 'bg-accent border-accent' : 'border-edge'
- )}
- >
- <Show when={active()}>
- <CheckIcon class="size-2.5 text-surface" />
- </Show>
- </span>
+ <TypeIndicator active={active()} />
<Show when={option.icon}>
{(icon) => (
diff --git a/js/app/packages/ui/components/Checkbox.tsx b/js/app/packages/ui/components/Checkbox.tsx
new file mode 100644
index 0000000000..006573d834
--- /dev/null
+++ b/js/app/packages/ui/components/Checkbox.tsx
@@ -0,0 +1,81 @@
+import { Checkbox as KobalteCheckbox } from '@kobalte/core/checkbox';
+import CheckIcon from '@phosphor/check.svg';
+import MinusIcon from '@phosphor/minus.svg';
+import { splitProps, type ComponentProps } from 'solid-js';
+import { cn } from '../utils/classname';
+
+/*
+<Checkbox checked={...} onChange={...}>
+ <Checkbox.Control />
+</Checkbox>
+
+A bare <Checkbox.Control /> renders its own <Checkbox.Indicator /> with a
+check (or minus for indeterminate). Override by passing children:
+
+<Checkbox.Control>
+ <Checkbox.Indicator>
+ <CustomGlyph />
+ </Checkbox.Indicator>
+</Checkbox.Control>
+*/
+
+export type CheckboxProps = ComponentProps<typeof KobalteCheckbox>;
+type ControlProps = ComponentProps<typeof KobalteCheckbox.Control>;
+type IndicatorProps = ComponentProps<typeof KobalteCheckbox.Indicator>;
+
+const CONTROL_CLASS = cn(
+ 'inline-flex items-center justify-center size-4 shrink-0 rounded-sm text-surface',
+ 'bg-surface border border-edge',
+ 'data-checked:bg-accent data-checked:border-accent',
+ 'data-indeterminate:bg-accent data-indeterminate:border-accent',
+ 'data-disabled:opacity-50 data-disabled:cursor-not-allowed',
+ 'data-invalid:border-red-500',
+);
+
+function CheckboxIndicator(props: IndicatorProps) {
+ const [local, rest] = splitProps(props, ['class', 'children']);
+ return (
+ <KobalteCheckbox.Indicator
+ class={cn('group inline-flex items-center justify-center', local.class)}
+ {...rest}
+ >
+ {local.children ?? (
+ <>
+ <CheckIcon class="size-3 group-data-indeterminate:hidden" />
+ <MinusIcon class="size-3 hidden group-data-indeterminate:block" />
+ </>
+ )}
+ </KobalteCheckbox.Indicator>
+ );
+}
+
+function CheckboxControl(props: ControlProps) {
+ const [local, rest] = splitProps(props, ['class', 'children']);
+ return (
+ <>
+ <KobalteCheckbox.Input class="sr-only" />
+ <KobalteCheckbox.Control class={cn(CONTROL_CLASS, local.class)} {...rest}>
+ {local.children ?? <CheckboxIndicator />}
+ </KobalteCheckbox.Control>
+ </>
+ );
+}
+
+export const Checkbox = Object.assign(
+ (props: CheckboxProps) => {
+ const [local, rest] = splitProps(props, ['class']);
+ return (
+ <KobalteCheckbox
+ class={cn('inline-flex items-center gap-2', local.class)}
+ {...rest}
+ />
+ );
+ },
+ {
+ ErrorMessage: KobalteCheckbox.ErrorMessage, /* passthrough — styled via class at use sites */
+ Description: KobalteCheckbox.Description, /* passthrough — styled via class at use sites */
+ Input: KobalteCheckbox.Input, /* passthrough — Control already renders one */
+ Indicator: CheckboxIndicator,
+ Control: CheckboxControl,
+ },
+);
diff --git a/js/app/packages/ui/components/Dropdown.tsx b/js/app/packages/ui/components/Dropdown.tsx
index f62da2853d..2ab0b62400 100644
--- a/js/app/packages/ui/components/Dropdown.tsx
+++ b/js/app/packages/ui/components/Dropdown.tsx
@@ -1,4 +1,5 @@
import { DropdownMenu as KobalteDropdownMenu } from '@kobalte/core/dropdown-menu';
+import CheckIcon from '@phosphor/check.svg';
import { Button, type ButtonProps } from './Button';
import { Surface, type SurfaceProps } from './Surface';
import { cn } from '../utils/classname';
@@ -42,7 +43,7 @@ export type DropdownGroupProps = ComponentProps<typeof KobalteDropdownMenu.Group
export type DropdownItemProps = ComponentProps<typeof KobalteDropdownMenu.Item>;
export type DropdownSubProps = ComponentProps<typeof KobalteDropdownMenu.Sub>;
-const ROW_CLASS = 'rounded-lg w-full flex items-center gap-2.5 px-2 h-8 text-left text-xs cursor-default outline-none hover:bg-ink/5 data-highlighted:bg-ink/5 data-disabled:opacity-50 data-disabled:cursor-not-allowed';
+const ROW_CLASS = 'group rounded-lg w-full flex items-center gap-2.5 px-2 h-8 text-left text-xs cursor-default outline-none hover:bg-ink/5 data-highlighted:bg-ink/5 data-disabled:opacity-50 data-disabled:cursor-not-allowed';
function resolvePortalMount(
searchRef: HTMLElement | undefined,
@@ -117,13 +118,28 @@ function DropdownGroupLabel(props: DropdownGroupLabelProps) {
);
}
+const CHECKBOX_ITEM_BOX_CLASS = cn(
+ 'inline-flex items-center justify-center size-3.5 shrink-0 rounded-sm',
+ 'border border-transparent text-surface',
+ 'group-hover:not-hover:border-edge-muted group-data-highlighted:not-hover:border-edge-muted',
+ 'hover:border-accent',
+ 'group-data-checked:bg-accent group-data-checked:border-accent',
+);
+
function DropdownCheckboxItem(props: DropdownCheckboxItemProps) {
- const [local, rest] = splitProps(props, ['class']);
+ const [local, rest] = splitProps(props, ['class', 'children']);
return (
<KobalteDropdownMenu.CheckboxItem
class={cn(ROW_CLASS, local.class)}
{...rest}
- />
+ >
+ <div class={CHECKBOX_ITEM_BOX_CLASS}>
+ <KobalteDropdownMenu.ItemIndicator>
+ <CheckIcon class="size-2.5" />
+ </KobalteDropdownMenu.ItemIndicator>
+ </div>
+ {local.children}
+ </KobalteDropdownMenu.CheckboxItem>
);
}
diff --git a/js/app/packages/ui/index.ts b/js/app/packages/ui/index.ts
index bb8719b4a4..3ee7c33019 100644
--- a/js/app/packages/ui/index.ts
+++ b/js/app/packages/ui/index.ts
@@ -4,6 +4,7 @@ export { TabbedControl } from './components/TabbedControl';
export { Avatar, AvatarGroup } from './components/Avatar';
export { LogoProgress } from './components/LogoProgress';
export { ToggleSwitch } from './components/ToggleSwitch';
+export { Checkbox } from './components/Checkbox';
export { ButtonGroup } from './components/ButtonGroup';
export { SendButton } from './components/SendButton';
export { HoverCard } from './components/HoverCard';
@@ -22,6 +23,7 @@ export type { AvatarSize, AvatarProps, AvatarGroupSize, AvatarGroupProps } from
export type { ChatInputRows, ChatInputProps } from './components/ChatInput';
export type { ToggleSwitchProps } from './components/ToggleSwitch';
export type { SendButtonProps } from './components/SendButton';
+export type { CheckboxProps } from './components/Checkbox';
export type { ButtonProps } from './components/Button';
export type { DialogProps } from './components/Dialog';