Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jimniels committed Jan 6, 2025
1 parent 89551dd commit aeffba9
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions quadratic-client/src/shared/components/SettingsPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Label } from '@/shared/shadcn/ui/label';
import { Switch } from '@/shared/shadcn/ui/switch';
import { cn } from '@/shared/shadcn/utils';
import { ReactNode, useId } from 'react';

/**
* Component that renders a setting panel (a label, description, and a switch)
* Optionally may include a "body" (for example, when enabled it shows additional
* informational content).
*/
type SettingPanelProps = {
label: string;
description: string | ReactNode;
onCheckedChange: (checked: boolean) => void;
checked: boolean;
children?: ReactNode;
isNested?: boolean;
className?: string;
};

export function SettingPanel({
label,
description,
onCheckedChange,
checked,
children,
isNested,
className,
}: SettingPanelProps) {
const reactId = useId();
const id = `setting-panel-${reactId}`;

return (
<div className={cn('space-y-3 rounded-lg border p-3 shadow-sm', className)}>
<div className="flex w-full flex-row items-center justify-between gap-3">
<div className="mr-auto space-y-0.5 text-sm">
<Label htmlFor={id} className="font-semibold">
{label}
</Label>
<p className="text-muted-foreground">{description}</p>
</div>

<Switch
id={id}
checked={checked}
onCheckedChange={(checked) => {
onCheckedChange(checked);
}}
/>
</div>
{children}
</div>
);
}

0 comments on commit aeffba9

Please sign in to comment.