NamH 02478b3242
feat: add input actions for setting item (#2978)
Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
2024-06-02 22:41:27 +07:00

52 lines
1.3 KiB
TypeScript

import { ChangeEvent } from 'react'
import { CheckboxComponentProps, SettingComponentProps } from '@janhq/core'
import { Switch } from '@janhq/joi'
import { Marked, Renderer } from 'marked'
type Props = {
settingProps: SettingComponentProps
onValueChanged?: (e: ChangeEvent<HTMLInputElement>) => void
}
const marked: Marked = new Marked({
renderer: {
link: (href, title, text) => {
return Renderer.prototype.link
?.apply(this, [href, title, text])
.replace(
'<a',
"<a class='text-[hsla(var(--app-link))]' target='_blank'"
)
},
},
})
const SettingDetailToggleItem: React.FC<Props> = ({
settingProps,
onValueChanged,
}) => {
const { value } = settingProps.controllerProps as CheckboxComponentProps
const description = marked.parse(settingProps.description ?? '', {
async: false,
})
return (
<div className="flex w-full justify-between py-6">
<div className="flex flex-1 flex-col space-y-1">
<h1 className="font-semibold">{settingProps.title}</h1>
{
<div
dangerouslySetInnerHTML={{ __html: description }}
className="font-medium leading-relaxed text-[hsla(var(--text-secondary))]"
/>
}
</div>
<Switch checked={value} onChange={onValueChanged} />
</div>
)
}
export default SettingDetailToggleItem