mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-11 00:30:06 +08:00
website: Switch to likert style labelling
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { Button, SimpleGrid } from "@chakra-ui/react";
|
||||
import { PropsWithChildren, ReactNode } from "react";
|
||||
|
||||
export const LikertButtons = ({
|
||||
isDisabled,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
"data-cy": dataCy,
|
||||
}: PropsWithChildren<{
|
||||
isDisabled: boolean;
|
||||
options: ReactNode[];
|
||||
value: number;
|
||||
onChange: (value: number) => void;
|
||||
"data-cy"?: string;
|
||||
}>) => {
|
||||
return (
|
||||
<SimpleGrid aria-roledescription="radiogroup" columns={options.length} spacing={[1, 4]} data-cy={dataCy}>
|
||||
{options.map((option, idx) => {
|
||||
const indexValue = idx / (options.length - 1);
|
||||
return (
|
||||
<Button
|
||||
aria-roledescription="radio"
|
||||
aria-checked={indexValue === value}
|
||||
key={idx}
|
||||
onClick={() => {
|
||||
onChange(indexValue === value ? null : indexValue);
|
||||
}}
|
||||
isDisabled={isDisabled}
|
||||
isActive={indexValue === value}
|
||||
>
|
||||
{option}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</SimpleGrid>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user