// Dependencies import { flagTypes } from 'plugins/plugin-annotations/src/flag.mjs' import mustache from 'mustache' import { nsMerge } from 'shared/utils.mjs' // Hooks import { useTranslation } from 'next-i18next' import { useState } from 'react' // Components import { CloseIcon, ChatIcon, TipIcon, WarningIcon, ErrorIcon, FixmeIcon, ExpandIcon, } from 'shared/components/icons.mjs' import Markdown from 'react-markdown' const flagColors = { note: 'primary', tip: 'accent', warn: 'error', error: 'error', fixme: 'warning', } const flagIcons = { note: ChatIcon, tip: TipIcon, warn: WarningIcon, error: ErrorIcon, fixme: FixmeIcon, // Used in content expand: ExpandIcon, } export const Flags = ({ flags, update }) => { const handleUpdate = (config) => { if (config.settings) update.settings(...config.settings) if (config.ui) update.ui(...config.settings) } return (
{flagTypes.map((type) => flags[type] ? Object.values(flags[type]).map((flag) => ( )) : null )}
) } export const Flag = ({ type, data, handleUpdate }) => { const { t } = useTranslation(nsMerge('flag', data.ns, data.msg.split(':').shift())) const [hide, setHide] = useState(false) if (hide || !data.msg) return null const color = flagColors[type] const Icon = flagIcons[type] const BtnIcon = data.suggest?.icon ? flagIcons[data.suggest.icon] : false const button = data.suggest?.text && data.suggest?.update ? ( ) : null const msg = data.replace ? mustache.render(t(data.msg), { ...data.replace, '"': '"' }) : t(data.msg) return (
{msg}
{button ? (
{button}
) : (
)}
) }