2022-01-26 11:53:43 +01:00
|
|
|
import { useState } from 'react'
|
|
|
|
import ClearIcon from 'shared/components/icons/clear.js'
|
2022-02-08 20:49:19 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2022-01-26 11:53:43 +01:00
|
|
|
|
|
|
|
const DesignOptionList = props => {
|
2022-02-08 20:49:19 +01:00
|
|
|
const { t } = useTranslation(['app'])
|
2022-01-26 11:53:43 +01:00
|
|
|
const { dflt, list } = props.pattern.config.options[props.option]
|
|
|
|
const val = (typeof props.gist?.options?.[props.option] === 'undefined')
|
|
|
|
? dflt
|
|
|
|
: props.gist.options[props.option]
|
|
|
|
|
|
|
|
const [value, setValue] = useState(val)
|
|
|
|
|
|
|
|
const handleChange = (newVal) => {
|
|
|
|
if (newVal === dflt) reset()
|
|
|
|
else {
|
|
|
|
setValue(newVal)
|
|
|
|
props.updateGist(['options', props.option], newVal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const reset = () => {
|
|
|
|
setValue(dflt)
|
|
|
|
props.unsetGist(['options', props.option])
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="py-4 mx-6 border-l-2 pl-2">
|
|
|
|
<div className="flex flex-row">
|
|
|
|
<div className="grow">
|
|
|
|
{list.map(choice => (
|
2022-02-12 15:23:37 +01:00
|
|
|
<button key={choice}
|
2022-01-26 11:53:43 +01:00
|
|
|
onClick={() => handleChange(choice)}
|
|
|
|
className={`
|
|
|
|
mr-1 mb-1 text-left text-lg w-full
|
|
|
|
${choice === value
|
|
|
|
? choice === dflt
|
|
|
|
? 'text-secondary'
|
|
|
|
: 'text-accent'
|
2022-05-14 14:53:29 +02:00
|
|
|
: 'text-base-content'
|
2022-01-26 11:53:43 +01:00
|
|
|
}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
<span className={`
|
|
|
|
text-3xl mr-2 inline-block p-0 leading-3
|
|
|
|
translate-y-3
|
|
|
|
`}>
|
|
|
|
<>°</>
|
|
|
|
</span>
|
2022-02-10 21:40:19 +01:00
|
|
|
{props.ot(`${props.option}.o.${choice}`)}
|
2022-01-26 11:53:43 +01:00
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<button
|
2022-02-08 20:49:19 +01:00
|
|
|
title={t('reset')}
|
2022-01-26 11:53:43 +01:00
|
|
|
className=""
|
|
|
|
disabled={val === dflt}
|
|
|
|
onClick={reset}
|
|
|
|
>
|
2022-05-14 14:53:29 +02:00
|
|
|
<span className={val===dflt ? 'text-base' : 'text-accent'}><ClearIcon /></span>
|
2022-01-26 11:53:43 +01:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DesignOptionList
|