Files
piratepoet/packages/js/email-editor/src/engine/hooks/use-email-css.ts
Oluwaseun Olorunsola 912282f57c Move all items to src folder
MAILPOET-6215
2024-11-11 11:53:49 +02:00

38 lines
1.0 KiB
TypeScript

import { useMemo } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import deepmerge from 'deepmerge';
import {
// @ts-expect-error No types for this exist yet.
privateApis as blockEditorPrivateApi,
} from '@wordpress/block-editor';
import { unlock } from '../../lock-unlock';
import { EmailStyles, storeName } from '../store';
import { useEmailTheme } from './use-email-theme';
const { useGlobalStylesOutputWithConfig } = unlock(blockEditorPrivateApi);
export function useEmailCss() {
const { templateTheme } = useEmailTheme();
const { editorTheme } = useSelect(
(select) => ({
editorTheme: select(storeName).getTheme(),
}),
[],
);
const mergedConfig = useMemo(
() =>
deepmerge.all([
{},
editorTheme || {},
templateTheme || {},
]) as EmailStyles,
[editorTheme, templateTheme],
);
const [styles] = useGlobalStylesOutputWithConfig(mergedConfig);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return [styles];
}