Skip to content

Commit

Permalink
Feat: theme builder palette fixes (#2992)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramenhog authored Dec 2, 2024
1 parent d5f2b06 commit fd196c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
49 changes: 30 additions & 19 deletions website/src/pages/themes/_components/color-scale-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ type ColorScaleOptionsProps = {
palette?: VictoryThemeDefinition["palette"];
activeColorScale?: ColorScalePropType;
onColorChange: (args: ColorChangeArgs) => void;
onColorScaleChange: (colorScale: string) => void;
onColorScaleChange: (colorScale?: string) => void;
};

const colorScales = [
export const colorScaleOptions = [
{
label: "Qualitative",
value: "qualitative",
},
{
label: "Grayscale",
value: "grayscale",
},
{
label: "Heatmap",
value: "heatmap",
Expand All @@ -36,6 +40,10 @@ const colorScales = [
label: "Green",
value: "green",
},
{
label: "Blue",
value: "blue",
},
];

const ColorScaleOptions = ({
Expand All @@ -50,26 +58,29 @@ const ColorScaleOptions = ({
id="color-scale-select"
value={activeColorScale as string}
onChange={onColorScaleChange}
options={colorScales}
options={colorScaleOptions}
label="Color Scale"
className="mb-5"
includeDefault
/>
<div className="flex flex-wrap gap-3">
{palette?.[activeColorScale as string]?.map((color, i) => (
<ColorPicker
key={i}
color={color}
id={`color-${i}`}
onColorChange={(newColor) =>
onColorChange({
newColor,
index: i,
colorScale: activeColorScale as string,
})
}
/>
))}
</div>
{!!activeColorScale && (
<div className="flex flex-wrap gap-3">
{palette?.[activeColorScale as string]?.map((color, i) => (
<ColorPicker
key={i}
color={color}
id={`color-${i}`}
onColorChange={(newColor) =>
onColorChange({
newColor,
index: i,
colorScale: activeColorScale as string,
})
}
/>
))}
</div>
)}
</section>
);
};
Expand Down
10 changes: 2 additions & 8 deletions website/src/pages/themes/_config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
VictoryScatter,
VictoryVoronoi,
} from "victory";
import { colorScaleOptions } from "./_components/color-scale-options";

type ThemeBuilderFieldConfig =
| {
Expand Down Expand Up @@ -63,14 +64,7 @@ const getNestedColorScaleConfig = (
{
type: "select",
label: "Color Scale",
options: [
{ label: "Qualitative", value: "qualitative" },
{ label: "Heatmap", value: "heatmap" },
{ label: "Warm", value: "warm" },
{ label: "Cool", value: "cool" },
{ label: "Red", value: "red" },
{ label: "Green", value: "green" },
],
options: colorScaleOptions,
path: getPath(basePath, "colorScale"),
},
];
Expand Down
12 changes: 7 additions & 5 deletions website/src/pages/themes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ const ThemeBuilder = () => {
const [customThemeConfig, setCustomThemeConfig] = React.useState<
VictoryThemeDefinition | undefined
>(undefined);
const [activeColorScale, setActiveColorScale] =
React.useState<ColorScalePropType>("qualitative");
const [activeColorScale, setActiveColorScale] = React.useState<
string | undefined
>(undefined);
const [showThemeConfigPreview, setShowThemeConfigPreview] =
React.useState(false);
const [showTooltips, setShowTooltips] = React.useState(false);
Expand Down Expand Up @@ -113,8 +114,9 @@ const ThemeBuilder = () => {
setCustomThemeConfig(updatedConfig);
};

const handleColorScaleChange = (colorScale: string) => {
setActiveColorScale(colorScale as ColorScalePropType);
const handleColorScaleChange = (colorScale?: string) => {
const newColorScale = colorScale === "" ? undefined : colorScale;
setActiveColorScale(newColorScale);
};

const handleThemeConfigPreviewOpen = () => {
Expand Down Expand Up @@ -202,7 +204,7 @@ const ThemeBuilder = () => {
<VictoryAxis label="X Axis" />
<VictoryAxis dependentAxis label="Y Axis" />
<VictoryStack
colorScale={activeColorScale}
colorScale={activeColorScale as ColorScalePropType}
aria-label="Victory Stack Demo"
>
{[...Array(NUM_STACKS)].map((_, i) => (
Expand Down

0 comments on commit fd196c9

Please sign in to comment.