[questions][fix] tweak question filters ()

pull/454/head
Yangshun Tay 2 years ago committed by GitHub
parent d7548460e6
commit 22f2f15aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

Loading…
Cancel
Save