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

54 lines
1.7 KiB
TypeScript
Raw Normal View History

import classNames from 'classnames';
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';
2022-05-05 19:25:52 -07:00
import BackgroundShapes from 'soapbox/features/ui/components/background_shapes';
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,
}
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
2022-05-05 19:25:52 -07:00
const dark = settings.get('themeMode') === 'dark';
const bodyClass = classNames(
'site-preview',
'relative flex justify-center align-center text-base',
'border border-solid border-gray-200 dark:border-slate-600',
'h-40 rounded-lg overflow-hidden',
{
'bg-white': !dark,
'bg-slate-900': dark,
});
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' />
<div className='absolute p-2 rounded-lg overflow-hidden bg-accent-500 text-white self-center z-20'>
<FormattedMessage id='site_preview.preview' defaultMessage='Preview' />
</div>
<div className={classNames('flex absolute inset-0 shadow z-10 h-12 lg:h-16', {
'bg-white': !dark,
'bg-slate-800': dark,
})}
>
<img alt='Logo' className='h-5 lg:h-6 self-center px-2' src={soapboxConfig.logo} />
2020-10-01 16:57:11 -07:00
</div>
</div>
);
};
2022-05-05 11:23:25 -07:00
export default SitePreview;