-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: basic theme builder layout with qualitative scale customization #2926
Merged
ramenhog
merged 1 commit into
feat/theme-builder-setup
from
feat/theme-builder-basic-functionality
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 was deleted.
Oops, something went wrong.
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,84 @@ | ||
import React from "react"; | ||
import { VictoryThemeDefinition } from "victory-core/lib"; | ||
|
||
type ConfigPreviewProps = { | ||
config: VictoryThemeDefinition; | ||
onClose: () => void; | ||
}; | ||
|
||
const containerStyles: React.CSSProperties = { | ||
position: "fixed", | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
width: "100%", | ||
padding: 20, | ||
backgroundColor: "rgba(255, 255, 255, 0.9)", | ||
zIndex: 1000, | ||
}; | ||
|
||
const copyButtonContainerStyles: React.CSSProperties = { | ||
display: "flex", | ||
alignItems: "center", | ||
gap: 10, | ||
marginBottom: 20, | ||
}; | ||
|
||
const copyStatusStyles: React.CSSProperties = { | ||
color: "#666", | ||
fontSize: 12, | ||
fontStyle: "italic", | ||
}; | ||
|
||
const codeStyles: React.CSSProperties = { | ||
overflow: "auto", | ||
maxHeight: 600, | ||
border: "1px solid #ccc", | ||
padding: 10, | ||
backgroundColor: "#f9f9f9", | ||
}; | ||
|
||
const closeButtonStyles: React.CSSProperties = { | ||
position: "absolute", | ||
top: 10, | ||
right: 10, | ||
background: "transparent", | ||
border: "none", | ||
fontSize: "20px", | ||
cursor: "pointer", | ||
}; | ||
|
||
const ConfigPreview = ({ config, onClose }: ConfigPreviewProps) => { | ||
const [copyStatus, setCopyStatus] = React.useState<string | null>(null); | ||
|
||
const handleCopyThemeConfig = () => { | ||
navigator.clipboard | ||
.writeText(JSON.stringify(config, null, 2)) | ||
.then(() => { | ||
setCopyStatus("Copied successfully."); | ||
return "Theme config copied to clipboard"; | ||
}) | ||
.catch(() => { | ||
setCopyStatus("Failed to copy."); | ||
}); | ||
}; | ||
|
||
const handleClose = () => { | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<div style={containerStyles}> | ||
<div style={copyButtonContainerStyles}> | ||
<button onClick={handleCopyThemeConfig}>Copy Theme Config</button> | ||
{copyStatus && <span style={copyStatusStyles}>{copyStatus}</span>} | ||
</div> | ||
<h2>Theme Config Preview</h2> | ||
<pre style={codeStyles}>{JSON.stringify(config, null, 2)}</pre> | ||
<button onClick={handleClose} style={closeButtonStyles}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe an aria-label here 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I'll fix this in my next PR |
||
× | ||
</button> | ||
</div> | ||
); | ||
}; | ||
export default ConfigPreview; |
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,76 @@ | ||
import React from "react"; | ||
import { ThemeOption } from "."; | ||
import ConfigPreview from "./config-preview"; | ||
|
||
type ColorChangeArgs = { | ||
event: React.ChangeEvent<HTMLInputElement>; | ||
index: number; | ||
colorScale: string; | ||
}; | ||
|
||
type CustomOptionsProps = { | ||
activeTheme: ThemeOption; | ||
onColorChange: (args: ColorChangeArgs) => void; | ||
}; | ||
|
||
const colorContainer: React.CSSProperties = { | ||
display: "grid", | ||
gridTemplateColumns: "repeat(4, 1fr)", | ||
gap: 20, | ||
}; | ||
|
||
const colorPickerStyles: React.CSSProperties = { | ||
width: 50, | ||
height: 50, | ||
}; | ||
|
||
const CustomOptions = ({ activeTheme, onColorChange }: CustomOptionsProps) => { | ||
const [showThemeConfigPreview, setShowThemeConfigPreview] = | ||
React.useState(false); | ||
|
||
const onThemeConfigPreviewOpen = () => { | ||
setShowThemeConfigPreview(true); | ||
}; | ||
|
||
const onThemeConfigPreviewClose = () => { | ||
setShowThemeConfigPreview(false); | ||
}; | ||
return ( | ||
<> | ||
<div> | ||
<button onClick={onThemeConfigPreviewOpen}> | ||
See Custom Config JSON | ||
</button> | ||
<section> | ||
<h2>Color Scales</h2> | ||
<h3>Qualitative</h3> | ||
<div style={colorContainer}> | ||
{activeTheme.config?.palette?.qualitative?.map((color, index) => ( | ||
<input | ||
key={index} | ||
style={colorPickerStyles} | ||
type="color" | ||
value={color} | ||
onChange={(event) => | ||
onColorChange({ | ||
event, | ||
index, | ||
colorScale: "qualitative", | ||
}) | ||
} | ||
/> | ||
))} | ||
</div> | ||
</section> | ||
</div> | ||
|
||
{showThemeConfigPreview && activeTheme.config && ( | ||
<ConfigPreview | ||
config={activeTheme.config} | ||
onClose={onThemeConfigPreviewClose} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
export default CustomOptions; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this string get used at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not 😬 but the linter complains about .then() not returning anything, so I just put that in there.