|
|
@ -70,9 +70,13 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
setIsClosing(true); |
|
|
setIsClosing(true); |
|
|
if (isMulti) { |
|
|
if (isMulti) { |
|
|
const currentList = localSelectedListRef.current; |
|
|
const currentList = localSelectedListRef.current; |
|
|
|
|
|
const trimmedList = |
|
|
|
|
|
maxSelect && currentList.length > maxSelect |
|
|
|
|
|
? currentList.slice(0, maxSelect) |
|
|
|
|
|
: currentList; |
|
|
setAnswerValue( |
|
|
setAnswerValue( |
|
|
question, |
|
|
question, |
|
|
currentList.length > 0 ? currentList : null, |
|
|
|
|
|
|
|
|
trimmedList.length > 0 ? trimmedList : null, |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
window.setTimeout(() => { |
|
|
window.setTimeout(() => { |
|
|
@ -80,7 +84,7 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
setIsClosing(false); |
|
|
setIsClosing(false); |
|
|
setSearchQuery(""); |
|
|
setSearchQuery(""); |
|
|
}, EXIT_ANIMATION_MS); |
|
|
}, EXIT_ANIMATION_MS); |
|
|
}, [isMulti, question, setAnswerValue]); |
|
|
|
|
|
|
|
|
}, [isMulti, maxSelect, question, setAnswerValue]); |
|
|
|
|
|
|
|
|
const openSheet = useCallback(() => { |
|
|
const openSheet = useCallback(() => { |
|
|
if (disabled) return; |
|
|
if (disabled) return; |
|
|
@ -341,9 +345,13 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
|
|
|
|
|
|
const handleConfirmMulti = () => { |
|
|
const handleConfirmMulti = () => { |
|
|
const currentList = localSelectedListRef.current; |
|
|
const currentList = localSelectedListRef.current; |
|
|
|
|
|
const trimmedList = |
|
|
|
|
|
maxSelect && currentList.length > maxSelect |
|
|
|
|
|
? currentList.slice(0, maxSelect) |
|
|
|
|
|
: currentList; |
|
|
setAnswerValue( |
|
|
setAnswerValue( |
|
|
question, |
|
|
question, |
|
|
currentList.length > 0 ? currentList : null, |
|
|
|
|
|
|
|
|
trimmedList.length > 0 ? trimmedList : null, |
|
|
); |
|
|
); |
|
|
closeSheet(); |
|
|
closeSheet(); |
|
|
}; |
|
|
}; |
|
|
@ -449,9 +457,26 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
].join(" ")} |
|
|
].join(" ")} |
|
|
> |
|
|
> |
|
|
<div className="flex items-center justify-between gap-3 px-5 pt-2.5 pb-3 border-b border-[#F2F4F7]"> |
|
|
<div className="flex items-center justify-between gap-3 px-5 pt-2.5 pb-3 border-b border-[#F2F4F7]"> |
|
|
<h3 className="flex-1 min-w-0 text-[17px] font-bold leading-snug text-[#181818] line-clamp-2 break-words text-start"> |
|
|
|
|
|
{question.title} |
|
|
|
|
|
</h3> |
|
|
|
|
|
|
|
|
<div className="flex-1 min-w-0 flex flex-col text-start"> |
|
|
|
|
|
<h3 className="flex-1 text-[17px] font-bold leading-snug text-[#181818] line-clamp-2 break-words text-start"> |
|
|
|
|
|
{question.title} |
|
|
|
|
|
</h3> |
|
|
|
|
|
{isMulti && Boolean(maxSelect) && ( |
|
|
|
|
|
<span className="text-xs text-[#667085] mt-0.5"> |
|
|
|
|
|
{localSelectedList.length >= (maxSelect as number) |
|
|
|
|
|
? (locale === "fa" |
|
|
|
|
|
? `سقف ${maxSelect} انتخاب تکمیل شد` |
|
|
|
|
|
: locale === "ar" |
|
|
|
|
|
? `تم اختيار الحد الأقصى (${maxSelect})` |
|
|
|
|
|
: `Maximum of ${maxSelect} selected`) |
|
|
|
|
|
: (locale === "fa" |
|
|
|
|
|
? `انتخاب حداکثر ${maxSelect} مورد (${localSelectedList.length}/${maxSelect})` |
|
|
|
|
|
: locale === "ar" |
|
|
|
|
|
? `اختر حتى ${maxSelect} عناصر (${localSelectedList.length}/${maxSelect})` |
|
|
|
|
|
: `Select up to ${maxSelect} (${localSelectedList.length}/${maxSelect})`)} |
|
|
|
|
|
</span> |
|
|
|
|
|
)} |
|
|
|
|
|
</div> |
|
|
<button |
|
|
<button |
|
|
type="button" |
|
|
type="button" |
|
|
onClick={closeSheet} |
|
|
onClick={closeSheet} |
|
|
@ -546,11 +571,18 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
? localSelectedList.includes(option.id) |
|
|
? localSelectedList.includes(option.id) |
|
|
: singleValue === option.id; |
|
|
: singleValue === option.id; |
|
|
|
|
|
|
|
|
|
|
|
const isOptionDisabled = |
|
|
|
|
|
isMulti && |
|
|
|
|
|
!isSelected && |
|
|
|
|
|
Boolean(maxSelect && localSelectedList.length >= maxSelect); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<button |
|
|
<button |
|
|
key={option.id} |
|
|
key={option.id} |
|
|
type="button" |
|
|
type="button" |
|
|
|
|
|
disabled={isOptionDisabled} |
|
|
onClick={() => { |
|
|
onClick={() => { |
|
|
|
|
|
if (isOptionDisabled) return; |
|
|
if (isMulti) { |
|
|
if (isMulti) { |
|
|
toggleMultiOption(option.id); |
|
|
toggleMultiOption(option.id); |
|
|
} else { |
|
|
} else { |
|
|
@ -558,10 +590,12 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
} |
|
|
} |
|
|
}} |
|
|
}} |
|
|
className={[ |
|
|
className={[ |
|
|
"flex min-h-[52px] w-full items-start gap-3 rounded-[12px] border px-3.5 py-3 text-start transition-colors cursor-pointer", |
|
|
|
|
|
isSelected |
|
|
|
|
|
? "bg-[#FFF4F5] border-[#F0445B]/40 text-[#181818]" |
|
|
|
|
|
: "bg-white hover:bg-[#F2F4F7] border-[#EAECF0] text-[#181818]", |
|
|
|
|
|
|
|
|
"flex min-h-[52px] w-full items-start gap-3 rounded-[12px] border px-3.5 py-3 text-start transition-colors", |
|
|
|
|
|
isOptionDisabled |
|
|
|
|
|
? "opacity-35 cursor-not-allowed bg-[#F9FAFB] border-[#F2F4F7] text-[#98A2B3] pointer-events-none" |
|
|
|
|
|
: isSelected |
|
|
|
|
|
? "bg-[#FFF4F5] border-[#F0445B]/40 text-[#181818] cursor-pointer" |
|
|
|
|
|
: "bg-white hover:bg-[#F2F4F7] border-[#EAECF0] text-[#181818] cursor-pointer", |
|
|
].join(" ")} |
|
|
].join(" ")} |
|
|
> |
|
|
> |
|
|
{/* Indicator Icon */} |
|
|
{/* Indicator Icon */} |
|
|
@ -569,9 +603,11 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
<div |
|
|
<div |
|
|
className={[ |
|
|
className={[ |
|
|
"size-[20px] shrink-0 rounded-[6px] transition-all duration-150 mt-[2px] flex items-center justify-center", |
|
|
"size-[20px] shrink-0 rounded-[6px] transition-all duration-150 mt-[2px] flex items-center justify-center", |
|
|
isSelected |
|
|
|
|
|
? "bg-[#F0445B] text-white shadow-xs" |
|
|
|
|
|
: "border-[2px] border-[#98A2B3] bg-white", |
|
|
|
|
|
|
|
|
isOptionDisabled |
|
|
|
|
|
? "border-[2px] border-[#D0D5DD] bg-[#F2F4F7]" |
|
|
|
|
|
: isSelected |
|
|
|
|
|
? "bg-[#F0445B] text-white shadow-xs" |
|
|
|
|
|
: "border-[2px] border-[#98A2B3] bg-white", |
|
|
].join(" ")} |
|
|
].join(" ")} |
|
|
> |
|
|
> |
|
|
{isSelected && ( |
|
|
{isSelected && ( |
|
|
@ -615,10 +651,23 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
const description = parts.slice(1).join(" - "); |
|
|
const description = parts.slice(1).join(" - "); |
|
|
return ( |
|
|
return ( |
|
|
<span className="flex flex-col gap-1 text-start"> |
|
|
<span className="flex flex-col gap-1 text-start"> |
|
|
<span className="font-bold text-[#181818]"> |
|
|
|
|
|
|
|
|
<span |
|
|
|
|
|
className={[ |
|
|
|
|
|
"font-bold", |
|
|
|
|
|
isOptionDisabled |
|
|
|
|
|
? "text-[#98A2B3]" |
|
|
|
|
|
: "text-[#181818]", |
|
|
|
|
|
].join(" ")} |
|
|
|
|
|
> |
|
|
{title} |
|
|
{title} |
|
|
</span> |
|
|
</span> |
|
|
<ExplanationUiFont> |
|
|
|
|
|
|
|
|
<ExplanationUiFont |
|
|
|
|
|
className={ |
|
|
|
|
|
isOptionDisabled |
|
|
|
|
|
? "text-[#98A2B3]" |
|
|
|
|
|
: undefined |
|
|
|
|
|
} |
|
|
|
|
|
> |
|
|
{description} |
|
|
{description} |
|
|
</ExplanationUiFont> |
|
|
</ExplanationUiFont> |
|
|
</span> |
|
|
</span> |
|
|
@ -627,9 +676,11 @@ export function QuestionSheet({ question, disabled }: QuestionSheetProps) { |
|
|
) : ( |
|
|
) : ( |
|
|
<span |
|
|
<span |
|
|
className={ |
|
|
className={ |
|
|
isSelected |
|
|
|
|
|
? "font-bold text-[#181818] block" |
|
|
|
|
|
: "font-semibold text-[#344054] block" |
|
|
|
|
|
|
|
|
isOptionDisabled |
|
|
|
|
|
? "font-normal text-[#98A2B3] block" |
|
|
|
|
|
: isSelected |
|
|
|
|
|
? "font-bold text-[#181818] block" |
|
|
|
|
|
: "font-semibold text-[#344054] block" |
|
|
} |
|
|
} |
|
|
> |
|
|
> |
|
|
{option.label} |
|
|
{option.label} |
|
|
|