Files
carmanagement/homepage/src/components/forms/ChoiceControls.tsx
T
root d7fb7b7a7b
Build & Deploy / Build & Push Docker Image (push) Failing after 47s
Build & Deploy / Deploy to VPS (push) Has been skipped
Test / API Unit Tests (push) Failing after 5m4s
Test / Marketplace Unit Tests (push) Failing after 4m55s
Test / Admin Unit Tests (push) Successful in 9m37s
Test / Dashboard Unit Tests (push) Successful in 9m37s
Test / API Integration Tests (push) Successful in 9m54s
redesign the homepage
2026-06-26 16:27:21 -04:00

59 lines
1.7 KiB
TypeScript

'use client';
import { classNames } from '@/lib/components/classNames';
import type { InputHTMLAttributes, ReactNode } from 'react';
import styles from './ChoiceControls.module.css';
interface ChoiceProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
label: ReactNode;
description?: ReactNode;
invalid?: boolean;
}
function Choice({
label,
description,
invalid = false,
className,
type,
...props
}: ChoiceProps & { type: 'checkbox' | 'radio' }) {
return (
<label className={classNames(styles.choice, invalid && styles.invalid, className)}>
<input type={type} aria-invalid={invalid || undefined} {...props} />
<span className={styles.content}>
<span className={styles.label}>{label}</span>
{description ? <span className={styles.description}>{description}</span> : null}
</span>
</label>
);
}
export function Checkbox(props: ChoiceProps) {
return <Choice type="checkbox" {...props} />;
}
export function Radio(props: ChoiceProps) {
return <Choice type="radio" {...props} />;
}
interface SwitchProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'role'> {
label: ReactNode;
description?: ReactNode;
}
export function Switch({ label, description, className, ...props }: SwitchProps) {
return (
<label className={classNames(styles.choice, className)}>
<input type="checkbox" role="switch" className={styles.switchInput} {...props} />
<span aria-hidden="true" className={styles.switchTrack}>
<span />
</span>
<span className={styles.content}>
<span className={styles.label}>{label}</span>
{description ? <span className={styles.description}>{description}</span> : null}
</span>
</label>
);
}