|
| 1 | +import { cn } from "@/utils"; |
| 2 | +import { |
| 3 | + ComponentProps, |
| 4 | + ComponentPropsWithoutRef, |
| 5 | + PropsWithChildren, |
| 6 | +} from "react"; |
| 7 | +import { Switch } from "./Switch"; |
| 8 | + |
| 9 | +/** Provides a default gap between section elements */ |
| 10 | +export function SettingsSection({ |
| 11 | + className, |
| 12 | + ...props |
| 13 | +}: ComponentProps<"section">) { |
| 14 | + return ( |
| 15 | + <section |
| 16 | + className={cn("max-w-paragraph space-y-6", className)} |
| 17 | + {...props} |
| 18 | + /> |
| 19 | + ); |
| 20 | +} |
| 21 | + |
| 22 | +export function SettingsSectionHeader({ |
| 23 | + className, |
| 24 | + ...props |
| 25 | +}: ComponentProps<"header">) { |
| 26 | + return <header className={cn("space-y-1", className)} {...props} />; |
| 27 | +} |
| 28 | + |
| 29 | +export function SettingsSectionTitle({ |
| 30 | + className, |
| 31 | + ...props |
| 32 | +}: ComponentProps<"h2">) { |
| 33 | + return ( |
| 34 | + <h2 |
| 35 | + className={cn( |
| 36 | + "text-text-primary text-xl font-bold leading-snug", |
| 37 | + className |
| 38 | + )} |
| 39 | + {...props} |
| 40 | + /> |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +export function SettingsSectionDescription({ |
| 45 | + className, |
| 46 | + ...props |
| 47 | +}: ComponentProps<"div">) { |
| 48 | + return ( |
| 49 | + <div |
| 50 | + className={cn( |
| 51 | + "text-text-secondary font-base text-base leading-snug", |
| 52 | + className |
| 53 | + )} |
| 54 | + {...props} |
| 55 | + /> |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +/** Contains a list of `SettingsSection` elements and provides a gap between them */ |
| 60 | +export function SettingsSectionContainer({ |
| 61 | + className, |
| 62 | + ...props |
| 63 | +}: ComponentProps<"div">) { |
| 64 | + return <div className={cn("flex flex-col gap-9", className)} {...props} />; |
| 65 | +} |
| 66 | + |
| 67 | +export function ToggleSetting({ |
| 68 | + label, |
| 69 | + description, |
| 70 | + ...props |
| 71 | +}: ComponentPropsWithoutRef<typeof Switch> & { |
| 72 | + label: string; |
| 73 | + description?: string; |
| 74 | +}) { |
| 75 | + return ( |
| 76 | + <label |
| 77 | + htmlFor={props.id} |
| 78 | + className="flex flex-row items-center justify-between space-x-4" |
| 79 | + > |
| 80 | + <div className="space-y-1"> |
| 81 | + <p className="text-text-primary text-pretty text-base font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"> |
| 82 | + {label} |
| 83 | + </p> |
| 84 | + {description ? ( |
| 85 | + <p className="text-text-secondary font-base text-pretty text-sm leading-normal peer-disabled:cursor-not-allowed peer-disabled:opacity-70"> |
| 86 | + {description} |
| 87 | + </p> |
| 88 | + ) : null} |
| 89 | + </div> |
| 90 | + <Switch {...props} /> |
| 91 | + </label> |
| 92 | + ); |
| 93 | +} |
| 94 | + |
| 95 | +export function LabelledSetting({ |
| 96 | + label, |
| 97 | + description, |
| 98 | + children, |
| 99 | +}: PropsWithChildren<{ |
| 100 | + label: string; |
| 101 | + description?: string; |
| 102 | +}>) { |
| 103 | + return ( |
| 104 | + <div className="flex flex-row items-center justify-between space-x-4"> |
| 105 | + <div className="block cursor-pointer space-y-1"> |
| 106 | + <p className="text-text-primary text-pretty text-base font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"> |
| 107 | + {label} |
| 108 | + </p> |
| 109 | + {description ? ( |
| 110 | + <p className="text-text-secondary font-base text-pretty text-sm leading-normal peer-disabled:cursor-not-allowed peer-disabled:opacity-70"> |
| 111 | + {description} |
| 112 | + </p> |
| 113 | + ) : null} |
| 114 | + </div> |
| 115 | + {children} |
| 116 | + </div> |
| 117 | + ); |
| 118 | +} |
0 commit comments