Skip to content

Commit e22e7ca

Browse files
refactor(web): stop borrowing ui class recipes in app code
Five app sites imported buttonVariants, toggleVariants or selectTriggerVariants to make a foreign element look like a Button, Toggle or Select field, which bypasses the component's variants and the no-restyle lint. Each now renders the real component: - The snooze schedule tabs and the publish SSH/HTTPS picker were hand-built segmented controls; they are ToggleGroup, which is the segmented control. - The composer banner's chevron renders a Button as a span. - The font-family and snapshot-sound pickers render through a new SelectButton, the select-field look for a Menu or Combobox trigger. App code can no longer import the *Variants functions (no-restricted- imports in apps/web, outside components/ui). ButtonVariant is exported as a type for the three pickers that forward a trigger variant. Visible effect: the snooze tabs lose their Base UI tab semantics and become a toggle group, matching every other segmented control. Lowers the no-restyle ceiling from 628 to 624. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent db898a3 commit e22e7ca

14 files changed

Lines changed: 129 additions & 97 deletions

‎apps/web/src/components/CustomSnoozeDialog.tsx‎

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useEffect, useId, useState } from "react";
2-
import { Tabs } from "@base-ui/react/tabs";
32
import { create } from "zustand";
43
import {
54
localSnoozeDate,
@@ -14,7 +13,7 @@ import { weekStartsOn } from "../timestampFormat";
1413
import { Popover, PopoverTrigger, PopoverPopup } from "./ui/popover";
1514
import { Input } from "./ui/input";
1615
import { Label } from "./ui/label";
17-
import { toggleVariants } from "./ui/toggle";
16+
import { Toggle, ToggleGroup } from "./ui/toggle-group";
1817
import { Select, SelectTrigger, SelectValue, SelectPopup, SelectItem } from "./ui/select";
1918
import {
2019
NumberField,
@@ -95,34 +94,21 @@ function CustomSnoozeDialog() {
9594
<DialogDescription>Choose when snoozed threads return to your inbox.</DialogDescription>
9695
</DialogHeader>
9796
<DialogPanel className="text-base sm:text-sm">
98-
<Tabs.Root
99-
value={mode}
100-
onValueChange={(value) => {
101-
if (value === "date" || value === "duration") setMode(value);
102-
setError(null);
103-
}}
104-
className="flex flex-col gap-4"
105-
>
106-
<Tabs.List
97+
<div className="flex flex-col gap-4">
98+
<ToggleGroup
10799
aria-label="Schedule type"
108-
className="flex gap-0.5 rounded-lg bg-input/40 p-0.5"
100+
className="w-full *:flex-1"
101+
value={[mode]}
102+
onValueChange={(next) => {
103+
const value = next[0];
104+
if (value === "date" || value === "duration") setMode(value);
105+
setError(null);
106+
}}
109107
>
110-
{(["date", "duration"] as const).map((value) => (
111-
<Tabs.Tab
112-
key={value}
113-
value={value}
114-
data-pressed={mode === value ? "" : undefined}
115-
className={toggleVariants({
116-
variant: "segmented",
117-
size: "sm",
118-
className: "flex-1",
119-
})}
120-
>
121-
{value === "date" ? "Date and time" : "Duration"}
122-
</Tabs.Tab>
123-
))}
124-
</Tabs.List>
125-
<Tabs.Panel value={mode} className="flex flex-col gap-4">
108+
<Toggle value="date">Date and time</Toggle>
109+
<Toggle value="duration">Duration</Toggle>
110+
</ToggleGroup>
111+
<div className="flex flex-col gap-4">
126112
{mode === "date" ? (
127113
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
128114
<div className="flex min-w-0 flex-col gap-1.5">
@@ -226,8 +212,8 @@ function CustomSnoozeDialog() {
226212
</Label>
227213
</div>
228214
)}
229-
</Tabs.Panel>
230-
</Tabs.Root>
215+
</div>
216+
</div>
231217
{error && (
232218
<p role="alert" className="text-destructive">
233219
{error}

‎apps/web/src/components/GitActionsControl.tsx‎

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
} from "~/components/Icons";
4949
import { RadioGroup } from "~/components/ui/radio-group";
5050
import { Spinner } from "~/components/ui/spinner";
51-
import { toggleVariants } from "~/components/ui/toggle";
51+
import { Toggle, ToggleGroup } from "~/components/ui/toggle-group";
5252
import { cn } from "~/lib/utils";
5353
import {
5454
buildGitActionProgressStages,
@@ -815,31 +815,20 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
815815
>
816816
Protocol
817817
</span>
818-
<RadioGroup
819-
className="w-fit flex-row gap-0.5 rounded-lg bg-input/40 p-0.5"
820-
value={publishProtocol}
821-
onValueChange={(protocol) => {
818+
<ToggleGroup
819+
value={[publishProtocol]}
820+
onValueChange={(next) => {
821+
const protocol = next[0];
822822
if (protocol === "ssh" || protocol === "https") {
823823
setPublishProtocol(protocol);
824824
}
825825
}}
826826
aria-labelledby="publish-protocol-label"
827827
disabled={publishRepositoryAction.isPending}
828828
>
829-
{(["ssh", "https"] as const).map((protocol) => (
830-
<RadioPrimitive.Root
831-
key={protocol}
832-
value={protocol}
833-
data-pressed={publishProtocol === protocol ? "" : undefined}
834-
className={toggleVariants({
835-
variant: "segmented",
836-
size: "segmented",
837-
})}
838-
>
839-
{protocol.toUpperCase()}
840-
</RadioPrimitive.Root>
841-
))}
842-
</RadioGroup>
829+
<Toggle value="ssh">SSH</Toggle>
830+
<Toggle value="https">HTTPS</Toggle>
831+
</ToggleGroup>
843832
</div>
844833
</div>
845834
) : null}

‎apps/web/src/components/chat/ComposerBanner.tsx‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ChevronDownIcon, XIcon } from "lucide-react";
44
import type { ComponentProps } from "react";
55

66
import { cn } from "~/lib/utils";
7-
import { Button, buttonVariants } from "../ui/button";
7+
import { Button } from "../ui/button";
88
import { ScrollArea } from "../ui/scroll-area";
99

1010
export type ComposerBannerVariant = "default" | "error" | "info" | "success" | "warning";
@@ -323,18 +323,18 @@ function Dot({ className, ...props }: ComponentProps<"span">) {
323323
);
324324
}
325325

326-
function ToggleIcon({ expanded, className }: { expanded: boolean; className?: string }) {
326+
// Decorative: the row itself is the control, so this only matches Dismiss's box.
327+
function ToggleIcon({ expanded }: { expanded: boolean }) {
327328
return (
328-
<span
329-
aria-hidden
330-
className={cn(
331-
buttonVariants({ size: "icon-xs", variant: "ghost" }),
332-
"pointer-events-none",
333-
className,
334-
)}
329+
<Button
330+
render={<span aria-hidden />}
331+
size="icon-xs"
332+
variant="ghost"
333+
tabIndex={-1}
334+
className="pointer-events-none"
335335
>
336336
<ChevronDownIcon className={cn("size-3.5", !expanded && "rotate-180")} />
337-
</span>
337+
</Button>
338338
);
339339
}
340340

‎apps/web/src/components/chat/ProviderModelPicker.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import {
55
type ResolvedKeybindingsConfig,
66
} from "@t3tools/contracts";
77
import { memo, useEffect, useMemo, useState } from "react";
8-
import type { VariantProps } from "class-variance-authority";
98
import { Badge } from "../ui/badge";
10-
import { buttonVariants } from "../ui/button";
9+
import type { ButtonVariant } from "../ui/button";
1110
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
1211
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
1312
import { cn } from "~/lib/utils";
@@ -49,7 +48,7 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
4948
disabled?: boolean;
5049
terminalOpen?: boolean;
5150
open?: boolean;
52-
triggerVariant?: VariantProps<typeof buttonVariants>["variant"];
51+
triggerVariant?: ButtonVariant;
5352
triggerClassName?: string;
5453
/** Aggregate settings can show a neutral value without claiming one provider is selected. */
5554
triggerLabel?: string;

‎apps/web/src/components/chat/TraitsPicker.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import {
1616
normalizeModelSlug,
1717
} from "@t3tools/shared/model";
1818
import { memo, useCallback } from "react";
19-
import type { VariantProps } from "class-variance-authority";
2019
import { GaugeIcon, ZapIcon } from "lucide-react";
21-
import { buttonVariants } from "../ui/button";
20+
import type { ButtonVariant } from "../ui/button";
2221
import {
2322
Menu,
2423
MenuGroup,
@@ -277,7 +276,7 @@ export interface TraitsMenuContentProps {
277276
modelOptions?: ProviderOptions | null | undefined;
278277
allowPromptInjectedEffort?: boolean;
279278
planModeEnabled: boolean;
280-
triggerVariant?: VariantProps<typeof buttonVariants>["variant"];
279+
triggerVariant?: ButtonVariant;
281280
triggerClassName?: string;
282281
isComposerOwned?: boolean;
283282
}

‎apps/web/src/components/chat/composerProviderState.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import {
1313
isClaudeUltrathinkPrompt,
1414
normalizeModelSlug,
1515
} from "@t3tools/shared/model";
16-
import type { VariantProps } from "class-variance-authority";
1716
import type { ReactNode } from "react";
1817

19-
import type { buttonVariants } from "../ui/button";
18+
import type { ButtonVariant } from "../ui/button";
2019
import type { DraftId } from "../../composerDraftStore";
2120
import { getProviderModelCapabilities } from "../../providerModels";
2221
import type { ComposerControlSize } from "./ComposerControl";
@@ -55,7 +54,7 @@ type TraitsRenderInput = {
5554
planModeEnabled: boolean;
5655
size?: ComposerControlSize;
5756
hidden?: boolean;
58-
triggerVariant?: VariantProps<typeof buttonVariants>["variant"];
57+
triggerVariant?: ButtonVariant;
5958
triggerClassName?: string;
6059
isComposerOwned?: boolean;
6160
};

‎apps/web/src/components/settings/FontFamilyPicker.tsx‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LegendList, type LegendListRef } from "@legendapp/list/react";
2-
import { CheckIcon, ChevronDownIcon } from "lucide-react";
2+
import { CheckIcon } from "lucide-react";
33
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
44
import { isMonospaceFamily, queryInstalledFontFamilies } from "../../appearanceFonts";
55
import {
@@ -11,7 +11,7 @@ import {
1111
ComboboxPopup,
1212
ComboboxTrigger,
1313
} from "../ui/combobox";
14-
import { selectTriggerVariants } from "../ui/select";
14+
import { SelectButton } from "../ui/select";
1515

1616
const DEFAULT_FONT_VALUE = "__default__";
1717

@@ -204,11 +204,8 @@ export function FontFamilyPicker({
204204
void listRef.current?.scrollIndexIntoView?.({ index: eventDetails.index, animated: false });
205205
}}
206206
>
207-
<ComboboxTrigger aria-label={ariaLabel} className={selectTriggerVariants({ size: "sm" })}>
208-
<span className="min-w-0 truncate">
209-
{selectedFamily.length === 0 ? defaultFamily : selectedFamily}
210-
</span>
211-
<ChevronDownIcon className="-me-1 size-3 opacity-50" />
207+
<ComboboxTrigger aria-label={ariaLabel} render={<SelectButton size="sm" />}>
208+
{selectedFamily.length === 0 ? defaultFamily : selectedFamily}
212209
</ComboboxTrigger>
213210
<ComboboxPopup align="end" className="flex w-72 flex-col">
214211
<ComboboxSearchInput

‎apps/web/src/components/settings/SnapShotSettings.tsx‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import {
77
type DesktopSnapShotSetupAction,
88
type SnapShotShortcut,
99
} from "@t3tools/contracts";
10-
import { ChevronDownIcon, PlayIcon } from "lucide-react";
10+
import { PlayIcon } from "lucide-react";
1111
import { useCallback, useEffect, useRef, useState } from "react";
1212

13-
import { cn } from "~/lib/utils";
14-
1513
import { useClientSettings, useUpdateClientSettings } from "../../hooks/useSettings";
1614
import { getDesktopSnapShotBridge } from "../../lib/desktopSnapShot";
1715
import {
@@ -44,7 +42,7 @@ import {
4442
import { searchableSetting } from "./settingsSearch";
4543
import { Button } from "../ui/button";
4644
import { Menu, MenuItem, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../ui/menu";
47-
import { selectTriggerVariants } from "../ui/select";
45+
import { SelectButton } from "../ui/select";
4846
import { Switch } from "../ui/switch";
4947
import { toastManager } from "../ui/toast";
5048
import { SnapShotSetupDialog } from "./SnapShotSetupDialog";
@@ -497,21 +495,19 @@ export function SnapShotSettings() {
497495
<Menu>
498496
<MenuTrigger
499497
aria-label={"Snapshot sound: " + soundLabel}
500-
className={cn(selectTriggerVariants({ size: "sm" }), "w-auto min-w-0")}
498+
render={<SelectButton size="sm" />}
499+
className="w-auto min-w-0"
501500
disabled={!captureAvailable}
502501
>
503-
<span className="min-w-0 flex-1 truncate text-left">
504-
{soundSelection === "off" ? (
505-
"Off"
506-
) : soundSelection === "soft-pop" ? (
507-
<>
508-
Whoosh <span className="text-muted-foreground">(Default)</span>
509-
</>
510-
) : (
511-
"Click"
512-
)}
513-
</span>
514-
<ChevronDownIcon className="-me-1 size-3 shrink-0 opacity-50" />
502+
{soundSelection === "off" ? (
503+
"Off"
504+
) : soundSelection === "soft-pop" ? (
505+
<>
506+
Whoosh <span className="text-muted-foreground">(Default)</span>
507+
</>
508+
) : (
509+
"Click"
510+
)}
515511
</MenuTrigger>
516512
<MenuPopup align="end">
517513
<MenuRadioGroup

‎apps/web/src/components/ui/badge.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ function Badge({ className, variant, size, render, ...props }: BadgeProps) {
6060
});
6161
}
6262

63+
// The *Variants function is for components/ui modules only.
6364
export { Badge, badgeVariants };

‎apps/web/src/components/ui/button.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ const buttonVariants = cva(
7171
},
7272
);
7373

74+
type ButtonVariant = NonNullable<VariantProps<typeof buttonVariants>["variant"]>;
75+
type ButtonSize = NonNullable<VariantProps<typeof buttonVariants>["size"]>;
76+
7477
interface ButtonProps extends useRender.ComponentProps<"button"> {
75-
variant?: VariantProps<typeof buttonVariants>["variant"];
76-
size?: VariantProps<typeof buttonVariants>["size"];
78+
variant?: ButtonVariant;
79+
size?: ButtonSize;
7780
}
7881

7982
function Button({ className, variant, size, render, ...props }: ButtonProps) {
@@ -95,7 +98,9 @@ function Button({ className, variant, size, render, ...props }: ButtonProps) {
9598
});
9699
}
97100

98-
export { Button, buttonVariants };
101+
// buttonVariants is exported for other components/ui modules only; app code
102+
// renders a Button (with `render` for other elements) instead.
103+
export { Button, buttonVariants, type ButtonSize, type ButtonVariant };
99104

100105
const inlineButtonVariants = cva(
101106
"inline-flex shrink-0 cursor-pointer items-center gap-0.5 whitespace-nowrap font-medium underline-offset-2 hover:underline focus-visible:outline-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-64",

0 commit comments

Comments
 (0)