bigbuffet-rw/app/soapbox/features/soapbox-config/components/site-preview.tsx

59 lines
2 KiB
TypeScript
Raw Normal View History

2023-02-06 10:01:03 -08:00
import clsx from 'clsx';
2022-05-05 11:23:25 -07:00
import React, { useMemo } from 'react';
2022-05-05 19:25:52 -07:00
import { FormattedMessage } from 'react-intl';
2020-10-01 16:57:11 -07:00
import { defaultSettings } from 'soapbox/actions/settings';
import SiteLogo from 'soapbox/components/site-logo';
2022-11-16 05:32:32 -08:00
import BackgroundShapes from 'soapbox/features/ui/components/background-shapes';
import { useSystemTheme } from 'soapbox/hooks';
2022-05-05 11:23:25 -07:00
import { normalizeSoapboxConfig } from 'soapbox/normalizers';
import { generateThemeCss } from 'soapbox/utils/theme';
2020-10-01 16:57:11 -07:00
2022-05-05 11:23:25 -07:00
interface ISitePreview {
/** Raw Soapbox configuration. */
soapbox: any
2022-05-05 11:23:25 -07:00
}
2020-10-01 16:57:11 -07:00
2022-05-05 11:23:25 -07:00
/** Renders a preview of the website's style with the configuration applied. */
const SitePreview: React.FC<ISitePreview> = ({ soapbox }) => {
const soapboxConfig = useMemo(() => normalizeSoapboxConfig(soapbox), [soapbox]);
const settings = defaultSettings.mergeDeep(soapboxConfig.defaultSettings);
2020-10-01 16:57:11 -07:00
const userTheme = settings.get('themeMode');
const systemTheme = useSystemTheme();
const dark = userTheme === 'dark' || (userTheme === 'system' && systemTheme === 'dark');
2022-05-05 19:25:52 -07:00
2023-02-06 10:01:03 -08:00
const bodyClass = clsx(
2022-05-05 19:25:52 -07:00
'site-preview',
2023-02-06 10:06:44 -08:00
'align-center relative flex justify-center text-base',
'border border-solid border-gray-200 dark:border-gray-600',
2023-02-06 10:06:44 -08:00
'h-40 overflow-hidden rounded-lg',
2022-05-05 19:25:52 -07:00
{
'bg-white': !dark,
'bg-gray-900': dark,
2022-05-05 19:25:52 -07:00
});
2020-10-01 16:57:11 -07:00
return (
<div className={bodyClass}>
2022-05-05 11:23:25 -07:00
<style>{`.site-preview {${generateThemeCss(soapboxConfig)}}`}</style>
2022-05-05 19:25:52 -07:00
<BackgroundShapes position='absolute' />
2023-02-01 14:13:42 -08:00
<div className='absolute z-20 self-center overflow-hidden rounded-lg bg-accent-500 p-2 text-white'>
2022-05-05 19:25:52 -07:00
<FormattedMessage id='site_preview.preview' defaultMessage='Preview' />
</div>
2023-02-06 10:06:44 -08:00
<div className={clsx('absolute inset-0 z-10 flex h-12 shadow lg:h-16', {
2022-05-05 19:25:52 -07:00
'bg-white': !dark,
'bg-gray-800': dark,
2022-05-05 19:25:52 -07:00
})}
>
2023-02-01 14:13:42 -08:00
<SiteLogo alt='Logo' className='h-5 w-auto self-center px-2 lg:h-6' theme={dark ? 'dark' : 'light'} />
2020-10-01 16:57:11 -07:00
</div>
</div>
);
};
2022-05-05 11:23:25 -07:00
export default SitePreview;