-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jeremy Clements <[email protected]>
- Loading branch information
Showing
18 changed files
with
2,204 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from "react"; | ||
import { DefaultButton, Pivot, PivotItem, PrimaryButton } from "@fluentui/react"; | ||
import { ThemeEditor } from "./ThemeEditor"; | ||
import { useUserTheme } from "../hooks/theme"; | ||
import { MessageBox } from "../layouts/MessageBox"; | ||
import nlsHPCC from "src/nlsHPCC"; | ||
|
||
interface SettingsProps { | ||
show?: boolean; | ||
onClose?: () => void; | ||
} | ||
|
||
export const Settings: React.FunctionComponent<SettingsProps> = ({ | ||
show = false, | ||
onClose = () => { } | ||
}) => { | ||
|
||
const { primaryColor, setPrimaryColor, resetTheme } = useUserTheme(); | ||
const [previousColor, setPreviousColor] = React.useState(primaryColor); | ||
const [activePivot, setActivePivot] = React.useState("theme"); | ||
|
||
React.useEffect(() => { | ||
// cache the previous color at dialog open, used to reset upon close | ||
if (show) setPreviousColor(primaryColor); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [show]); | ||
|
||
return <MessageBox show={show} setShow={onClose} blocking={true} modeless={false} title={nlsHPCC.Settings} minWidth={400} | ||
footer={<> | ||
<PrimaryButton onClick={() => { | ||
if (onClose) { | ||
onClose(); | ||
} | ||
}} text={nlsHPCC.OK} /> | ||
<DefaultButton onClick={() => { | ||
switch (activePivot) { | ||
case "theme": | ||
default: | ||
setPrimaryColor(previousColor); | ||
break; | ||
|
||
} | ||
if (onClose) { | ||
onClose(); | ||
} | ||
}} text={nlsHPCC.Cancel} /> | ||
<DefaultButton onClick={() => { | ||
switch (activePivot) { | ||
case "theme": | ||
default: | ||
resetTheme(); | ||
break; | ||
|
||
} | ||
if (onClose) { | ||
onClose(); | ||
} | ||
}} text={nlsHPCC.Reset} /> | ||
</>}> | ||
<Pivot onLinkClick={item => { | ||
setActivePivot(item.props.itemKey); | ||
}}> | ||
<PivotItem itemKey="theme" headerText={nlsHPCC.Theme}> | ||
<ThemeEditor /> | ||
</PivotItem> | ||
</Pivot> | ||
</MessageBox>; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import * as React from "react"; | ||
import { Callout, ColorPicker, getColorFromString, IColor, Label, mergeStyles, Stack, TextField } from "@fluentui/react"; | ||
import { useUserTheme } from "../hooks/theme"; | ||
import nlsHPCC from "src/nlsHPCC"; | ||
|
||
const colorBoxClassName = mergeStyles({ | ||
width: 20, | ||
height: 20, | ||
display: "inline-block", | ||
position: "absolute", | ||
left: 5, | ||
top: 5, | ||
border: "1px solid black", | ||
flexShrink: 0, | ||
}); | ||
|
||
const textBoxClassName = mergeStyles({ | ||
width: 100, | ||
}); | ||
|
||
const colorPanelClassName = mergeStyles({ | ||
position: "relative", | ||
}); | ||
|
||
interface ThemeEditorColorPickerProps { | ||
color: IColor; | ||
onColorChange: (color: IColor | undefined) => void; | ||
label: string; | ||
} | ||
|
||
export const ThemeEditorColorPicker: React.FunctionComponent<ThemeEditorColorPickerProps> = ({ | ||
color, | ||
onColorChange, | ||
label | ||
}) => { | ||
const [pickerColor, setPickerColor] = React.useState(color); | ||
const _colorPickerRef = React.useRef(null); | ||
const [editingColorStr, setEditingColorStr] = React.useState(pickerColor?.str ?? ""); | ||
const [isColorPickerVisible, setIsColorPickerVisible] = React.useState<boolean>(false); | ||
|
||
const _onTextFieldValueChange = React.useCallback((ev: any, newValue: string | undefined) => { | ||
const newColor = getColorFromString(newValue); | ||
if (newColor) { | ||
onColorChange(newColor); | ||
setEditingColorStr(newColor.str); | ||
} else { | ||
setEditingColorStr(newValue); | ||
} | ||
}, [onColorChange, setEditingColorStr]); | ||
|
||
React.useEffect(() => { | ||
setPickerColor(color); | ||
}, [color]); | ||
|
||
React.useEffect(() => { | ||
setEditingColorStr(pickerColor?.str); | ||
}, [pickerColor]); | ||
|
||
return <div> | ||
<Stack horizontal horizontalAlign={"space-between"} tokens={{ childrenGap: 20 }}> | ||
<Label>{label}</Label> | ||
<Stack horizontal className={colorPanelClassName} tokens={{ childrenGap: 35 }}> | ||
<div | ||
ref={_colorPickerRef} | ||
id="colorbox" | ||
className={colorBoxClassName} | ||
style={{ backgroundColor: color?.str }} | ||
onClick={() => setIsColorPickerVisible(true)} | ||
/> | ||
<TextField | ||
id="textfield" | ||
className={textBoxClassName} | ||
value={editingColorStr} | ||
onChange={_onTextFieldValueChange} | ||
/> | ||
</Stack> | ||
</Stack> | ||
{isColorPickerVisible && ( | ||
<Callout | ||
gapSpace={10} | ||
target={_colorPickerRef.current} | ||
setInitialFocus={true} | ||
onDismiss={() => setIsColorPickerVisible(false)} | ||
> | ||
<ColorPicker color={pickerColor} onChange={(evt, color) => onColorChange(color)} alphaType={"none"} /> | ||
</Callout> | ||
)} | ||
</div>; | ||
}; | ||
|
||
interface ThemeEditorProps { | ||
} | ||
|
||
export const ThemeEditor: React.FunctionComponent<ThemeEditorProps> = () => { | ||
|
||
const { primaryColor, setPrimaryColor } = useUserTheme(); | ||
|
||
return <div style={{ minHeight: "208px", paddingTop: "32px" }}> | ||
<ThemeEditorColorPicker | ||
color={getColorFromString(primaryColor)} | ||
onColorChange={(newColor: IColor | undefined) => { | ||
setPrimaryColor(newColor.str); | ||
}} | ||
label={nlsHPCC.PrimaryColor} | ||
/> | ||
</div>; | ||
|
||
}; |
Oops, something went wrong.