mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-10-01 11:41:14 +08:00
website: Switch to likert style labelling
This commit is contained in:
1 parent
274d03c5f0
commit
007773a3f5
19 files changed
+481
-519
No files matched your search
@@ -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