import React, { useCallback } from 'react'; import { connect } from 'react-redux'; import { FormFieldContainer, Checkbox, Label, Description, css, spacing, RadioBoxGroup, RadioBox, } from '@mongodb-js/compass-components'; import type { RootState } from '../../stores'; import { changeFieldValue } from '../../stores/settings'; import type { PreferenceStateInformation, THEMES, } from 'compass-preferences-model'; import { settingStateLabels } from './state-labels'; type ThemeSettingsProps = { handleChange: (field: 'theme', value: THEMES) => void; preferenceStates: PreferenceStateInformation; themeValue: THEMES; }; const checkboxStyles = css({ marginTop: spacing[3], marginBottom: spacing[3], }); const radioBoxStyles = css({ div: { textAlign: 'left', padding: spacing[3], justifyContent: 'flex-start', }, }); const themePreviewStyles = css({ marginRight: spacing[2], maxWidth: '50%', }); function LightThemePreview() { return ( ); } function DarkThemePreview() { return ( ); } export const ThemeSettings: React.FunctionComponent = ({ themeValue, preferenceStates, handleChange, }) => { const handleOSCheckboxChange = useCallback( (event: React.ChangeEvent) => { handleChange('theme', event.target.checked ? 'OS_THEME' : 'LIGHT'); }, [handleChange] ); const handleSelectorChange = useCallback( (event: React.ChangeEvent) => { handleChange('theme', event.target.value as THEMES); }, [handleChange] ); return (
Change the appearance of Compass.
Automatically switch between light and dark themes based on your OS settings } onChange={handleOSCheckboxChange} checked={themeValue === 'OS_THEME'} disabled={!!preferenceStates.theme} /> {settingStateLabels[preferenceStates.theme ?? '']} Light Theme Dark Theme (Preview)
); }; const mapState = ({ settings: { settings, preferenceStates } }: RootState) => ({ themeValue: settings.theme ?? 'OS_THEME', preferenceStates, }); const mapDispatch = { handleChange: changeFieldValue, }; export default connect(mapState, mapDispatch)(ThemeSettings);