1
0
Fork 0
freesewing/sites/shared/components/sets/set-candidate.mjs

59 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-06-20 20:19:31 +02:00
import { ChoiceButton } from 'shared/components/choice-button.mjs'
2023-05-05 19:56:51 +02:00
import { ChoiceLink } from 'shared/components/choice-link.mjs'
import { OkIcon, NoIcon, WarningIcon } from 'shared/components/icons.mjs'
import { useTranslation } from 'next-i18next'
import { capitalize, hasRequiredMeasurements } from 'shared/utils.mjs'
2023-05-05 19:56:51 +02:00
export const ns = ['sets']
2023-06-21 11:09:57 -05:00
const Title = ({ set, language }) => (
2023-05-05 19:56:51 +02:00
<div className="flex flex-row items-center gap-2">
2023-07-06 12:55:32 -05:00
{set.img && (
<img
alt={set.name}
src={set.img}
className="shadow mask mask-squircle bg-neutral aspect-square w-12 h-12"
/>
)}
2023-06-21 11:09:57 -05:00
<span>{set[`name${language ? capitalize(language) : ''}`]}</span>
2023-05-05 19:56:51 +02:00
</div>
)
2023-06-21 11:09:57 -05:00
export const SetSummary = ({ set, href, clickHandler, language, hasMeasies, t, design }) => {
const inner = hasMeasies ? null : (
2023-05-05 19:56:51 +02:00
<div className="flex flex-row gap-2 items-center">
<WarningIcon className="w-6 h-6 shrink-0 text-error" />
<span>{t('setLacksMeasiesForDesign', { design: t(`designs:${design}.t`) })}</span>
</div>
2023-06-20 20:19:31 +02:00
)
const wrapProps = {
2023-06-21 11:09:57 -05:00
icon: hasMeasies ? (
<OkIcon className="w-10 h-10 text-success" />
) : (
<NoIcon className="w-10 h-10 text-error" />
),
title: <Title set={set} language={language} />,
2023-06-20 20:19:31 +02:00
}
if (clickHandler) wrapProps.onClick = () => clickHandler(set)
else if (href) wrapProps.href = href
2023-05-05 19:56:51 +02:00
2023-06-20 20:19:31 +02:00
const Component = clickHandler ? ChoiceButton : ChoiceLink
return <Component {...wrapProps}>{inner}</Component>
}
2023-06-21 11:09:57 -05:00
export const SetCandidate = ({
set,
design,
requiredMeasies = [],
href,
clickHandler,
language,
}) => {
const { t } = useTranslation(['sets', design])
const [hasMeasies, missingMeasies] = hasRequiredMeasurements(requiredMeasies, set.measies, true)
2023-06-21 11:09:57 -05:00
const setProps = { set, design, t, href, clickHandler, hasMeasies, language }
2023-05-05 19:56:51 +02:00
return <SetSummary {...setProps} />
}