import React from 'react'; import usePopover from '@/_hooks/use-popover'; import { SketchPicker } from 'react-color'; import { Confirm } from '../Viewer/Confirm'; import { LeftSidebarItem } from './SidebarItem'; import FxButton from '../CodeBuilder/Elements/FxButton'; import { CodeHinter } from '../CodeBuilder/CodeHinter'; import { resolveReferences } from '@/_helpers/utils'; import { useTranslation } from 'react-i18next'; import _ from 'lodash'; export const LeftSidebarGlobalSettings = ({ globalSettings, globalSettingsChanged, darkMode, toggleAppMaintenance, is_maintenance_on, currentState, }) => { const { t } = useTranslation(); const [open, trigger, content] = usePopover(false); const { hideHeader, canvasMaxWidth, canvasMaxWidthType, canvasMaxHeight, canvasBackgroundColor, backgroundFxQuery } = globalSettings; const [showPicker, setShowPicker] = React.useState(false); const [forceCodeBox, setForceCodeBox] = React.useState(true); const [realState, setRealState] = React.useState(currentState); const [showConfirmation, setConfirmationShow] = React.useState(false); const coverStyles = { position: 'fixed', top: '0px', right: '0px', bottom: '0px', left: '0px', }; React.useEffect(() => { setRealState(currentState); // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentState.components]); React.useEffect(() => { backgroundFxQuery && globalSettingsChanged('canvasBackgroundColor', resolveReferences(backgroundFxQuery, realState)); // eslint-disable-next-line react-hooks/exhaustive-deps }, [JSON.stringify(resolveReferences(backgroundFxQuery, realState))]); return ( <> toggleAppMaintenance()} onCancel={() => setConfirmationShow(false)} darkMode={darkMode} />
{t('leftSidebar.Settings.hideHeader', 'Hide header for launched apps')}
globalSettingsChanged('hideHeader', e.target.checked)} />
{t('leftSidebar.Settings.maintenanceMode', 'Maintenance mode')}
setConfirmationShow(true)} />
{t('leftSidebar.Settings.maxWidthOfCanvas', 'Max width of canvas')}
{ const width = e.target.value; if (!Number.isNaN(width) && width >= 0) globalSettingsChanged('canvasMaxWidth', width); }} value={canvasMaxWidth} />
{t('leftSidebar.Settings.maxHeightOfCanvas', 'Max height of canvas')}
{ const height = e.target.value; if (!Number.isNaN(height) && height <= 2400) globalSettingsChanged('canvasMaxHeight', height); }} value={canvasMaxHeight} /> px
{t('leftSidebar.Settings.backgroundColorOfCanvas', 'Background color of canvas')}
{showPicker && (
setShowPicker(false)} /> setShowPicker(true)} color={canvasBackgroundColor} onChangeComplete={(color) => { globalSettingsChanged('canvasBackgroundColor', [color.hex, color.rgb]); globalSettingsChanged('backgroundFxQuery', color.hex); }} />
)} {forceCodeBox && (
setShowPicker(true)} >
{canvasBackgroundColor}
)}
{!forceCodeBox && ( { globalSettingsChanged('canvasBackgroundColor', resolveReferences(color, realState)); globalSettingsChanged('backgroundFxQuery', color); }} /> )}
{ setForceCodeBox(!forceCodeBox); }} />
); };