-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
616 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as React from "react"; | ||
import css from "./styling/ThemeEditor.module.scss"; | ||
import { ThemeColorSetter } from "./ThemeColorSetter"; | ||
import { Button } from "react-common/components/controls/Button"; | ||
|
||
export interface ThemeColorFamilyProps { | ||
key: string; | ||
baseColorId: string; | ||
derivedColorIds: string[]; | ||
} | ||
export const ThemeColorFamily = (props: ThemeColorFamilyProps) => { | ||
const { key, baseColorId, derivedColorIds } = props; | ||
const [expanded, setExpanded] = React.useState<boolean>(false); | ||
|
||
function toggleExpanded() { | ||
setExpanded(!expanded); | ||
} | ||
|
||
return ( | ||
<div className={css["theme-color-family-root"]} key={key}> | ||
<div className={css["theme-color-family-base-row"]}> | ||
<Button | ||
onClick={toggleExpanded} | ||
className={css["expand-collapse-button"]} | ||
title={expanded ? lf("Collapse Derived Colors") : lf("Expand Derived Colors")} | ||
leftIcon={expanded ? "fas fa-caret-down" : "fas fa-caret-right"} | ||
/> | ||
<ThemeColorSetter colorId={baseColorId} /> | ||
</div> | ||
{expanded && ( | ||
<div className={css["derived-color-set"]}> | ||
{derivedColorIds.map(colorId => ( | ||
<ThemeColorSetter key={`derived-color-setter-${colorId}`} colorId={colorId} /> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
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,50 @@ | ||
import * as React from "react"; | ||
import css from "./styling/ThemeEditor.module.scss"; | ||
import { Input } from "react-common/components/controls/Input"; | ||
import { AppStateContext } from "../state/appStateContext"; | ||
import { Button } from "react-common/components/controls/Button"; | ||
import { toggleColorHighlight } from "../transforms/toggleColorHighlight"; | ||
import { classList } from "react-common/components/util"; | ||
import { setColorValue } from "../transforms/setColorValue"; | ||
|
||
export interface ThemeColorSetterProps { | ||
key?: string; | ||
colorId: string; | ||
} | ||
export const ThemeColorSetter = (props: ThemeColorSetterProps) => { | ||
const { state } = React.useContext(AppStateContext); | ||
const { editingTheme } = state; | ||
const { key, colorId } = props; | ||
const [isHighlighted, setIsHighlighted] = React.useState<boolean>(false); | ||
|
||
React.useEffect(() => { | ||
setIsHighlighted(!!state.colorsToHighlight?.includes(colorId)); | ||
}, [state.colorsToHighlight]); | ||
|
||
const color = editingTheme?.colors[colorId]; | ||
if (!color) return null; | ||
return ( | ||
<div key={key} className={css["theme-color-setter"]}> | ||
<Button | ||
className={classList(css["highlight-color-button"], isHighlighted ? css["highlighted"] : undefined)} | ||
style={isHighlighted ? { borderColor: state.highlightColor, color: state.highlightColor } : undefined} | ||
leftIcon="fas fa-search" | ||
title={lf("Highlight color")} | ||
onClick={() => toggleColorHighlight(colorId)} | ||
/> | ||
<Input | ||
className={css["theme-color-input"]} | ||
label={colorId} | ||
initialValue={color} | ||
onBlur={value => setColorValue(colorId, value)} | ||
onEnterKey={value => setColorValue(colorId, value)} | ||
/> | ||
<input | ||
type="color" | ||
className={css["theme-color-button"]} | ||
value={color} | ||
onChange={e => setColorValue(colorId, e.target.value)} | ||
/> | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,40 +1,38 @@ | ||
import * as React from "react"; | ||
import { Input } from "react-common/components/controls/Input"; | ||
import { setCurrentFrameTheme } from "../transforms/setCurrentFrameTheme"; | ||
import css from "./styling/ThemeEditor.module.scss"; | ||
import { Input } from "react-common/components/controls/Input"; | ||
import { AppStateContext } from "../state/appStateContext"; | ||
|
||
import { setThemeName } from "../transforms/setThemeName"; | ||
import { getColorHeirarchy } from "../utils/colorUtils"; | ||
import { ThemeColorFamily } from "./ThemeColorFamily"; | ||
|
||
export const ThemeEditorPane = () => { | ||
const { state } = React.useContext(AppStateContext); | ||
const { theme } = state; | ||
|
||
function setThemeName(name: string) { | ||
if (theme) { | ||
const id = name.toLocaleLowerCase().replace(" ", "-").replace(/[^a-z0-9-]/g, ""); | ||
setCurrentFrameTheme ({...theme, id, name}); | ||
} | ||
} | ||
const { editingTheme } = state; | ||
|
||
function setColorValue(colorId: string, value: string) { | ||
if (theme) { | ||
setCurrentFrameTheme({ ...theme, colors: { ...theme.colors, [colorId]: value } }); | ||
} | ||
} | ||
const colorHeirarchy: { [baseColorId: string]: string[] } = React.useMemo(() => { | ||
return state.editingTheme?.colors ? getColorHeirarchy(Object.keys(state.editingTheme.colors)) : {}; | ||
}, [state.editingTheme?.colors]); | ||
const baseColorIds = Object.keys(colorHeirarchy); | ||
|
||
return !theme ? null : ( | ||
return ( | ||
<div className={css["theme-editor-container"]}> | ||
<Input className={css["theme-name-input"]} label={lf("Theme Name")} onBlur={setThemeName} onEnterKey={setThemeName} initialValue={theme.name} /> | ||
<div className={css["theme-colors-list"]} > | ||
{Object.keys(theme.colors).map((colorId) => { | ||
const color = theme.colors[colorId]; | ||
return <div key={`theme-color-wrapper-${colorId}`} className={css["theme-color-wrapper"]}> | ||
<Input className={css["theme-color-input"]} label={colorId} initialValue={color} onBlur={value => setColorValue(colorId, value)} onEnterKey={value => setColorValue(colorId, value)} /> | ||
{/* <Button className={css["color-preview"]} style={{ backgroundColor: color }} onClick={() => {}} title={lf("Choose color: {0}", colorId)} /> */} | ||
<input type="color" className={css["theme-color-button"]} value={color} onChange={e => setColorValue(colorId, e.target.value)} /> | ||
</div> | ||
})} | ||
<Input | ||
className={css["theme-name-input"]} | ||
label={lf("Theme Name")} | ||
onBlur={setThemeName} | ||
onEnterKey={setThemeName} | ||
initialValue={editingTheme?.name} | ||
/> | ||
<div className={css["theme-colors-list"]}> | ||
{baseColorIds.map(baseColorId => ( | ||
<ThemeColorFamily | ||
key={`base-color-${baseColorId}`} | ||
baseColorId={baseColorId} | ||
derivedColorIds={colorHeirarchy[baseColorId]} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
}; |
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
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,15 @@ | ||
import { stateAndDispatch } from "../state"; | ||
import { setColorsToHighlight } from "../state/actions"; | ||
import { setCurrentFrameTheme } from "./setCurrentFrameTheme"; | ||
|
||
export function clearHighlight() { | ||
const { state, dispatch } = stateAndDispatch(); | ||
const { editingTheme } = state; | ||
|
||
// Go back to the editing theme, clearing any discrepancies between it and the iframe theme. | ||
if (editingTheme) { | ||
setCurrentFrameTheme(editingTheme); | ||
} | ||
|
||
dispatch(setColorsToHighlight([])); | ||
} |
Oops, something went wrong.