@teaui/preact
Version:
Preact renderer for TeaUI
35 lines • 1.13 kB
JavaScript
import { jsx as _jsx } from "preact/jsx-runtime";
import { useCallback, useMemo } from 'preact/hooks';
import { bold, italic, underline, strikeout } from '@teaui/core';
import { ToggleGroup } from '../components.js';
const LABELS = [bold('B'), italic('I'), underline('U'), strikeout('S')];
const KEYS = [
'bold',
'italic',
'underline',
'strikethrough',
];
export function FontStyle({ value, onChange }) {
const selected = useMemo(() => {
const indices = [];
KEYS.forEach((key, i) => {
if (value[key])
indices.push(i);
});
return indices;
}, [value]);
const handleChange = useCallback((_index, newSelected) => {
const next = {
bold: false,
italic: false,
underline: false,
strikethrough: false,
};
for (const i of newSelected) {
next[KEYS[i]] = true;
}
onChange(next);
}, [onChange]);
return (_jsx(ToggleGroup, { titles: LABELS, selected: selected, multiple: true, onChange: handleChange }));
}
//# sourceMappingURL=FontStyle.js.map