[questions][fix] tweak question filters (#452)

This commit is contained in:
Yangshun Tay
2022-10-29 08:00:07 +08:00
committed by GitHub
parent d7548460e6
commit 22f2f15aa4
2 changed files with 27 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import { useMemo } from 'react';
import type { UseFormRegisterReturn } from 'react-hook-form';
import { useForm } from 'react-hook-form';
import { CheckboxInput, Collapsible, RadioList } from '@tih/ui';
import { CheckboxInput, CheckboxList, Collapsible, RadioList } from '@tih/ui';
export type FilterChoice<V extends string = string> = {
id: string;
@ -96,7 +96,7 @@ export default function FilterSection<V extends string>({
<Collapsible defaultOpen={true} label={collapsibleLabel}>
<div className="-mx-2 flex flex-col items-stretch gap-2">
{!showAll && (
<div className="z-10">
<div>
{renderInput({
field,
onOptionChange: async (option: FilterOption<V>) => {
@ -110,8 +110,8 @@ export default function FilterSection<V extends string>({
})}
</div>
)}
{isSingleSelect ? (
<div className="px-1.5">
<div className="px-1.5">
{isSingleSelect ? (
<RadioList
isLabelHidden={true}
label={label}
@ -133,26 +133,26 @@ export default function FilterSection<V extends string>({
/>
))}
</RadioList>
</div>
) : (
<div className="px-1.5">
{options
.filter((option) => showAll || option.checked)
.map((option) => (
<CheckboxInput
key={option.value}
label={option.label}
value={option.checked}
onChange={(checked) => {
onOptionChange({
...option,
checked,
});
}}
/>
))}
</div>
)}
) : (
<CheckboxList isLabelHidden={true} label={label}>
{options
.filter((option) => showAll || option.checked)
.map((option) => (
<CheckboxInput
key={option.value}
label={option.label}
value={option.checked}
onChange={(checked) => {
onOptionChange({
...option,
checked,
});
}}
/>
))}
</CheckboxList>
)}
</div>
</div>
</Collapsible>
</div>

View File

@ -14,6 +14,9 @@ export default {
description: {
control: 'text',
},
isLabelHidden: {
control: 'boolean',
},
label: {
control: 'text',
},