Skip to content
Snippets Groups Projects
Commit a250b5a2 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[dome] restore initial toolbar switch position

parent 9a9a307d
No related branches found
No related tags found
No related merge requests found
...@@ -160,31 +160,25 @@ export interface SwitchProps { ...@@ -160,31 +160,25 @@ export interface SwitchProps {
enabled?: boolean; enabled?: boolean;
/** Defaults to `false`. */ /** Defaults to `false`. */
disabled?: boolean; disabled?: boolean;
/** Switch value. /** Switch position. Defaults to 'left'. */
When checked, the slide is switched to « right » position. position?: 'left' | 'right';
Defaults to false. */
checked?: boolean;
/** Click callback. */ /** Click callback. */
onChange?: (newValue: boolean) => void; onChange?: (newPosition: 'left' | 'right') => void;
/** Right Click callback. */
onContextMenu?: () => void;
} }
/** Toolbar Switch. */ /** Toolbar Left/Right Switch. */
export function Switch(props: SwitchProps) { export function Switch(props: SwitchProps) {
const { checked = false, onChange } = props; const { position, onChange } = props;
const { title = '', className = '', style } = props; const checked = position === 'right';
const { title, className, style } = props;
const { enabled = true, disabled = false } = props; const { enabled = true, disabled = false } = props;
const callback = onChange && (() => onChange(!checked)); const callback = onChange && (() => onChange(checked ? 'left' : 'right'));
if (disabled || !enabled) return null; if (disabled || !enabled) return null;
return ( return (
<label <label className={classes('dome-xSwitch', className)} style={style}>
className={'dome-xSwitch ' + className}
style={style}
onContextMenu={props.onContextMenu}>
<input type={'checkbox'} checked={checked} onChange={callback} /> <input type={'checkbox'} checked={checked} onChange={callback} />
<span className={'dome-xSwitch-slider'} title={title} /> <span className={'dome-xSwitch-slider'} title={title} />
</label> </label >
); );
} }
......
...@@ -50,28 +50,18 @@ export const SourceWrapText = new Settings.GFalse('SourceCode.wrapText'); ...@@ -50,28 +50,18 @@ export const SourceWrapText = new Settings.GFalse('SourceCode.wrapText');
/* --- Theme Switcher Button --- */ /* --- Theme Switcher Button --- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
const themeEntries: Dome.PopupMenuItem[] = [
{ id: 'light', label: 'Switch to Light Theme' },
{ id: 'dark', label: 'Switch to Dark Theme' },
{ id: 'system', label: 'Switch to System Default' },
];
export function ThemeSwitch(): JSX.Element { export function ThemeSwitch(): JSX.Element {
const [theme, setTheme] = Themes.useColorTheme(); const [theme, setTheme] = Themes.useColorTheme();
const other = theme === 'dark' ? 'light' : 'dark'; const other = theme === 'dark' ? 'light' : 'dark';
const position = theme === 'dark' ? 'left' : 'right';
const title = `Switch to ${other} theme (right-click for full choice)`; const title = `Switch to ${other} theme (right-click for full choice)`;
const onChange = (): void => setTheme(other); const onChange = (): void => setTheme(other);
const onPopup = (): void => Dome.popupMenu(
themeEntries,
(th) => setTheme(Themes.jColorSettings(th))
);
return ( return (
<Toolbar.Switch <Toolbar.Switch
disabled={!Dome.DEVEL} disabled={!Dome.DEVEL}
title={title} title={title}
checked={theme === 'dark'} position={position}
onChange={onChange} onChange={onChange}
onContextMenu={onPopup}
/> />
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment