From 3225549c6d98ab3a7a536f75147c1caa6e9e7e6b Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Wed, 18 Dec 2024 13:22:11 -0600 Subject: [PATCH 1/4] Refactor examples so we can support multiple per chart type --- .../_components => components}/button.tsx | 6 +- website/src/hooks/useClickOutside.tsx | 29 ++ .../pages/themes/_components/chart-panel.tsx | 20 +- .../themes/_components/examples/area.tsx | 26 ++ .../themes/_components/examples/axis.tsx | 16 + .../pages/themes/_components/examples/bar.tsx | 41 +++ .../themes/_components/examples/box-plot.tsx | 26 ++ .../_components/examples/candlestick.tsx | 57 +++ .../themes/_components/examples/errorbar.tsx | 23 ++ .../themes/_components/examples/example.ts | 15 + .../themes/_components/examples/group.tsx | 45 +++ .../themes/_components/examples/histogram.tsx | 30 ++ .../themes/_components/examples/index.ts | 53 +++ .../themes/_components/examples/legend.tsx | 58 +++ .../themes/_components/examples/line.tsx | 28 ++ .../pages/themes/_components/examples/pie.tsx | 23 ++ .../examples/polar-axis-dependent.tsx | 21 ++ .../_components/examples/polar-axis.tsx | 15 + .../themes/_components/examples/scatter.tsx | 22 ++ .../themes/_components/examples/stack.tsx | 26 ++ .../themes/_components/examples/voronoi.tsx | 22 ++ .../_components/preview-settings-menu.tsx | 87 ----- .../src/pages/themes/_components/sidenav.tsx | 13 +- .../themes/_components/theme-preview.tsx | 146 -------- .../_components/theme-preview/header.tsx | 27 ++ .../_components/theme-preview/index.tsx | 34 ++ .../_components/theme-preview/options.tsx | 45 +++ .../_components/theme-preview/preview.tsx | 33 ++ website/src/pages/themes/_config/axis.tsx | 27 +- website/src/pages/themes/_config/chart.tsx | 334 ++---------------- website/src/pages/themes/_config/index.tsx | 5 +- .../_providers/previewOptionsProvider.tsx | 17 +- website/src/pages/themes/index.tsx | 2 +- 33 files changed, 782 insertions(+), 590 deletions(-) rename website/src/{pages/themes/_components => components}/button.tsx (64%) create mode 100644 website/src/hooks/useClickOutside.tsx create mode 100644 website/src/pages/themes/_components/examples/area.tsx create mode 100644 website/src/pages/themes/_components/examples/axis.tsx create mode 100644 website/src/pages/themes/_components/examples/bar.tsx create mode 100644 website/src/pages/themes/_components/examples/box-plot.tsx create mode 100644 website/src/pages/themes/_components/examples/candlestick.tsx create mode 100644 website/src/pages/themes/_components/examples/errorbar.tsx create mode 100644 website/src/pages/themes/_components/examples/example.ts create mode 100644 website/src/pages/themes/_components/examples/group.tsx create mode 100644 website/src/pages/themes/_components/examples/histogram.tsx create mode 100644 website/src/pages/themes/_components/examples/index.ts create mode 100644 website/src/pages/themes/_components/examples/legend.tsx create mode 100644 website/src/pages/themes/_components/examples/line.tsx create mode 100644 website/src/pages/themes/_components/examples/pie.tsx create mode 100644 website/src/pages/themes/_components/examples/polar-axis-dependent.tsx create mode 100644 website/src/pages/themes/_components/examples/polar-axis.tsx create mode 100644 website/src/pages/themes/_components/examples/scatter.tsx create mode 100644 website/src/pages/themes/_components/examples/stack.tsx create mode 100644 website/src/pages/themes/_components/examples/voronoi.tsx delete mode 100644 website/src/pages/themes/_components/preview-settings-menu.tsx delete mode 100644 website/src/pages/themes/_components/theme-preview.tsx create mode 100644 website/src/pages/themes/_components/theme-preview/header.tsx create mode 100644 website/src/pages/themes/_components/theme-preview/index.tsx create mode 100644 website/src/pages/themes/_components/theme-preview/options.tsx create mode 100644 website/src/pages/themes/_components/theme-preview/preview.tsx diff --git a/website/src/pages/themes/_components/button.tsx b/website/src/components/button.tsx similarity index 64% rename from website/src/pages/themes/_components/button.tsx rename to website/src/components/button.tsx index 515dc3451..36ee18636 100644 --- a/website/src/pages/themes/_components/button.tsx +++ b/website/src/components/button.tsx @@ -8,7 +8,7 @@ type ButtonProps = { disabled?: boolean; }; -const Button = ({ +export const Button = ({ onClick, children, className = "", @@ -17,7 +17,7 @@ const Button = ({ ...props }: ButtonProps) => { const baseClasses = - "py-2 px-5 border-none font-bold rounded-md cursor-pointer text-sm bg-button-bg text-button-fg hover:underline disabled:bg-grayscale-300 disabled:text-grayscale-400 disabled:cursor-not-allowed disabled:hover:no-underline"; + "py-2 px-4 font-semibold rounded-md cursor-pointer text-sm border-2 border-solid border-button-border bg-button-bg text-button-fg hover:bg-button-bg-hover hover:text-button-fg-hover disabled:bg-grayscale-300 disabled:text-grayscale-400 disabled:cursor-not-allowed"; return ( - {isSettingsMenuOpen && ( -
- -

Preview Settings

- {showColorScaleOptions && ( - + +
+ )} + + ); +}); diff --git a/website/src/pages/themes/_components/theme-preview/preview.tsx b/website/src/pages/themes/_components/theme-preview/preview.tsx new file mode 100644 index 000000000..92790b187 --- /dev/null +++ b/website/src/pages/themes/_components/theme-preview/preview.tsx @@ -0,0 +1,33 @@ +import React from "react"; + +import { + ColorScalePropType, + VictoryThemeDefinition, + VictoryTooltip, +} from "victory"; +import { ExampleConfig } from "../examples"; + +type Props = { + config: ExampleConfig; + theme: VictoryThemeDefinition; + colorScale: ColorScalePropType; + showTooltips: boolean; +}; + +export function Preview({ config, theme, colorScale, showTooltips }: Props) { + const { content: Content, title } = config; + + return ( +
+

{title}

+ {Content({ + labels: ({ datum }) => datum.y || datum.x, + colorScale: colorScale as ColorScalePropType, + theme, + ...(showTooltips && { + labelComponent: , + }), + })} +
+ ); +} diff --git a/website/src/pages/themes/_config/axis.tsx b/website/src/pages/themes/_config/axis.tsx index 815aabc16..83f258804 100644 --- a/website/src/pages/themes/_config/axis.tsx +++ b/website/src/pages/themes/_config/axis.tsx @@ -1,17 +1,16 @@ -/* eslint-disable no-magic-numbers */ -import React from "react"; import { getBaseLabelsConfig, getBaseStrokeConfig } from "../_utils"; -import { VictoryAxis, VictoryPolarAxis } from "victory"; import { StrokeProps } from "../_const"; import { ControlConfig } from "."; +import { + AxisExamples, + PolarAxisExamples, + PolarAxisDependentExamples, +} from "../_components/examples"; const generalAxisOptionsConfig: ControlConfig = { type: "accordion", label: "Base Axis", - content: (props) => [ - , - , - ], + content: AxisExamples, controls: [ { type: "section", @@ -57,9 +56,7 @@ const generalAxisOptionsConfig: ControlConfig = { const polarAxisOptionsConfig: ControlConfig = { type: "accordion", label: "Polar Axis", - content: (props) => ( - - ), + content: PolarAxisExamples, controls: [ { type: "section", @@ -105,15 +102,7 @@ const polarAxisOptionsConfig: ControlConfig = { const polarDependentAxisOptionsConfig: ControlConfig = { type: "accordion", label: "Polar Dependent Axis", - content: (props) => ( - - ), + content: PolarAxisDependentExamples, controls: [ { type: "section", diff --git a/website/src/pages/themes/_config/chart.tsx b/website/src/pages/themes/_config/chart.tsx index f64852ec8..797364f6e 100644 --- a/website/src/pages/themes/_config/chart.tsx +++ b/website/src/pages/themes/_config/chart.tsx @@ -1,28 +1,25 @@ -/* eslint-disable no-magic-numbers */ -import React from "react"; -import { - VictoryArea, - VictoryAxis, - VictoryBar, - VictoryBoxPlot, - VictoryCandlestick, - VictoryErrorBar, - VictoryGroup, - VictoryHistogram, - VictoryLegend, - VictoryLine, - VictoryPie, - VictoryScatter, - VictoryStack, - VictoryVoronoi, -} from "victory"; import { getBaseLabelsConfig, getBaseStrokeConfig, getNestedColorScaleConfig, } from "../_utils"; import { ControlConfig } from "."; -import { NUM_STACKS, sampleStackData, StrokeProps } from "../_const"; +import { StrokeProps } from "../_const"; +import { + AreaExamples, + BarExamples, + BoxPlotExamples, + CandlestickExamples, + ErrorBarExamples, + GroupExamples, + HistogramExamples, + LegendExamples, + LineExamples, + PieExamples, + ScatterExamples, + StackExamples, + VoronoiExamples, +} from "../_components/examples"; const chartConfigs: { [key: string]: ControlConfig; @@ -30,21 +27,7 @@ const chartConfigs: { area: { type: "section", label: "Area Chart", - content: (props) => [ - , - , - , - ], + content: AreaExamples, controls: [ { type: "section", @@ -79,36 +62,7 @@ const chartConfigs: { bar: { type: "section", label: "Bar Chart", - content: (props) => [ - , - , - , - ], + content: BarExamples, controls: [ { type: "section", @@ -150,20 +104,7 @@ const chartConfigs: { boxPlot: { type: "section", label: "Box Plot", - content: (props) => ( - - ), + content: BoxPlotExamples, controls: [ { type: "section", @@ -251,53 +192,7 @@ const chartConfigs: { candlestick: { type: "section", label: "Candlestick Chart", - content: (props) => ( - - ), + content: CandlestickExamples, controls: [ { type: "section", @@ -350,18 +245,7 @@ const chartConfigs: { errorBar: { type: "section", label: "Error Bar", - content: (props) => ( - - ), + content: ErrorBarExamples, controls: [ { type: "section", @@ -392,26 +276,7 @@ const chartConfigs: { histogram: { type: "section", label: "Histogram", - content: (props) => ( - `Bin count:\n ${datum.x}`} - /> - ), + content: HistogramExamples, controls: [ { type: "section", @@ -458,39 +323,7 @@ const chartConfigs: { type: "section", label: "Group", allowColorScaleOverride: true, - content: (props) => [ - , - , - - - - - , - ], + content: GroupExamples, controls: [ { type: "section", @@ -512,54 +345,7 @@ const chartConfigs: { legend: { type: "section", label: "Legend", - content: (props) => [ - , - datum.fill, - }, - }} - />, - ], + content: LegendExamples, controls: [ { type: "section", @@ -637,22 +423,7 @@ const chartConfigs: { line: { type: "section", label: "Line Chart", - content: (props) => [ - , - , - datum.y} - />, - ], + content: LineExamples, controls: [ { type: "section", @@ -675,19 +446,7 @@ const chartConfigs: { type: "section", label: "Pie Chart", allowColorScaleOverride: true, - hasVictoryChart: false, - content: (props) => ( - - ), + content: PieExamples, controls: [ { type: "section", @@ -718,18 +477,7 @@ const chartConfigs: { scatter: { type: "section", label: "Scatter Chart", - content: (props) => ( - - ), + content: ScatterExamples, controls: [ { type: "section", @@ -765,20 +513,7 @@ const chartConfigs: { type: "section", label: "Stack", allowColorScaleOverride: true, - content: (props) => [ - , - , - - {[...Array(NUM_STACKS)].map((_, i) => ( - - ))} - , - ], + content: StackExamples, controls: [ { type: "section", @@ -851,18 +586,7 @@ const chartConfigs: { voronoi: { type: "section", label: "Voronoi", - content: (props) => ( - - ), + content: VoronoiExamples, controls: [ { type: "section", diff --git a/website/src/pages/themes/_config/index.tsx b/website/src/pages/themes/_config/index.tsx index 7a9296da6..cc6f3ec9f 100644 --- a/website/src/pages/themes/_config/index.tsx +++ b/website/src/pages/themes/_config/index.tsx @@ -1,10 +1,9 @@ -import React from "react"; +import { ExampleConfig } from "../_components/examples"; export type ControlConfig = { label: string; - content?: (props: any) => React.ReactNode; + content?: ExampleConfig[]; controls?: ControlConfig[]; - hasVictoryChart?: boolean; allowColorScaleOverride?: boolean; } & ( | { diff --git a/website/src/pages/themes/_providers/previewOptionsProvider.tsx b/website/src/pages/themes/_providers/previewOptionsProvider.tsx index 439221e51..4a60bd206 100644 --- a/website/src/pages/themes/_providers/previewOptionsProvider.tsx +++ b/website/src/pages/themes/_providers/previewOptionsProvider.tsx @@ -1,5 +1,5 @@ import React, { createContext, useContext } from "react"; -import { ControlConfig } from "../_config"; +import { AllExamples, ExampleConfig } from "../_components/examples"; type PreviewOptionsContextType = { colorScale?: string; @@ -7,13 +7,12 @@ type PreviewOptionsContextType = { showTooltips: boolean; setShowTooltips: (showTooltips: boolean) => void; resetPreviewOptions: () => void; - exampleConfigs: ControlConfig[]; - setExampleConfigs: (exampleConfigs: any[]) => void; + exampleContent: ExampleConfig[]; + setExampleContent: (content: ExampleConfig[]) => void; }; -export const defaultColorScale = undefined; +export const defaultColorScale = "qualitative"; export const defaultShowTooltips = false; -export const defaultExampleConfigs = []; const PreviewOptionsContext = createContext< PreviewOptionsContextType | undefined @@ -24,9 +23,7 @@ export const PreviewOptionsProvider = ({ children }) => { defaultColorScale, ); const [showTooltips, setShowTooltips] = React.useState(defaultShowTooltips); - const [exampleConfigs, setExampleConfigs] = React.useState( - defaultExampleConfigs, - ); + const [exampleContent, setExampleContent] = React.useState(AllExamples); const updateColorScale = (newColorScale?: string) => { const updatedColorScale = !newColorScale ? undefined : newColorScale; @@ -46,8 +43,8 @@ export const PreviewOptionsProvider = ({ children }) => { showTooltips, setShowTooltips, resetPreviewOptions, - exampleConfigs, - setExampleConfigs, + exampleContent, + setExampleContent, }} > {children} diff --git a/website/src/pages/themes/index.tsx b/website/src/pages/themes/index.tsx index deb8e4a3b..3cec6edf0 100644 --- a/website/src/pages/themes/index.tsx +++ b/website/src/pages/themes/index.tsx @@ -8,7 +8,7 @@ import BaseThemePanel from "./_components/base-theme-panel"; import OptionsPanel from "./_components/options-panel"; import ChartPanel from "./_components/chart-panel"; import { ThemeProvider } from "./_providers/themeProvider"; -import ThemePreview from "./_components/theme-preview"; +import { ThemePreview } from "./_components/theme-preview"; import { PreviewOptionsProvider } from "./_providers/previewOptionsProvider"; import ExportPanel from "./_components/export-panel"; From 856db62bc117a3dcadff047671e22cf7e2b3565c Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Wed, 18 Dec 2024 14:40:11 -0600 Subject: [PATCH 2/4] Updates for panel --- .../src/pages/themes/_components/sidenav.tsx | 10 ++++- website/src/pages/themes/_config/chart.tsx | 3 -- website/src/pages/themes/_config/index.tsx | 1 - website/src/pages/themes/_config/palette.tsx | 40 ++++++++++++++++--- .../_providers/previewOptionsProvider.tsx | 2 +- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/website/src/pages/themes/_components/sidenav.tsx b/website/src/pages/themes/_components/sidenav.tsx index d459b0d26..b3072287a 100644 --- a/website/src/pages/themes/_components/sidenav.tsx +++ b/website/src/pages/themes/_components/sidenav.tsx @@ -20,7 +20,13 @@ import { usePreviewOptions, } from "../_providers/previewOptionsProvider"; import { TiExportOutline } from "react-icons/ti"; -import { AllExamples, ExampleConfig, StackExamples } from "./examples"; +import { + AllExamples, + ExampleConfig, + GroupExamples, + PieExamples, + StackExamples, +} from "./examples"; type NavItem = { title: string; @@ -57,7 +63,7 @@ export const NAV_ITEMS: NavItem[] = [ icon: SwatchIcon, config: paletteOptionsConfig, panelType: "default", - content: StackExamples, + content: [...StackExamples, ...GroupExamples, ...PieExamples], }, { title: "Global Options", diff --git a/website/src/pages/themes/_config/chart.tsx b/website/src/pages/themes/_config/chart.tsx index 797364f6e..5c50be22e 100644 --- a/website/src/pages/themes/_config/chart.tsx +++ b/website/src/pages/themes/_config/chart.tsx @@ -322,7 +322,6 @@ const chartConfigs: { group: { type: "section", label: "Group", - allowColorScaleOverride: true, content: GroupExamples, controls: [ { @@ -445,7 +444,6 @@ const chartConfigs: { pie: { type: "section", label: "Pie Chart", - allowColorScaleOverride: true, content: PieExamples, controls: [ { @@ -512,7 +510,6 @@ const chartConfigs: { stack: { type: "section", label: "Stack", - allowColorScaleOverride: true, content: StackExamples, controls: [ { diff --git a/website/src/pages/themes/_config/index.tsx b/website/src/pages/themes/_config/index.tsx index cc6f3ec9f..6a86c05f5 100644 --- a/website/src/pages/themes/_config/index.tsx +++ b/website/src/pages/themes/_config/index.tsx @@ -4,7 +4,6 @@ export type ControlConfig = { label: string; content?: ExampleConfig[]; controls?: ControlConfig[]; - allowColorScaleOverride?: boolean; } & ( | { type: "section" | "accordion"; diff --git a/website/src/pages/themes/_config/palette.tsx b/website/src/pages/themes/_config/palette.tsx index 271e8d22a..4374a283c 100644 --- a/website/src/pages/themes/_config/palette.tsx +++ b/website/src/pages/themes/_config/palette.tsx @@ -1,16 +1,44 @@ import { OptionsPanelConfig } from "."; import { colorScaleOptions } from "../_const"; +import { getNestedColorScaleConfig } from "../_utils"; const paletteOptionsConfig: OptionsPanelConfig = { title: "Color Palette", description: "Select a color palette to apply it to the preview charts, then adjust individual colors in the palette to customize the theme.", - controls: colorScaleOptions.map((option) => ({ - type: "colorPalette", - colorScaleType: option.value, - label: option.label, - value: option.value, - })), + controls: [ + { + type: "section", + label: "Component Defaults", + controls: [ + { + type: "accordion", + label: "VictoryStack", + controls: getNestedColorScaleConfig("stack"), + }, + { + type: "accordion", + label: "VictoryGroup", + controls: getNestedColorScaleConfig("group"), + }, + { + type: "accordion", + label: "VictoryPie", + controls: getNestedColorScaleConfig("pie"), + }, + ], + }, + { + type: "section", + label: "Color Palettes", + controls: colorScaleOptions.map((option) => ({ + type: "colorPalette", + colorScaleType: option.value, + label: option.label, + value: option.value, + })), + }, + ], }; export default paletteOptionsConfig; diff --git a/website/src/pages/themes/_providers/previewOptionsProvider.tsx b/website/src/pages/themes/_providers/previewOptionsProvider.tsx index 4a60bd206..fa1e22e7d 100644 --- a/website/src/pages/themes/_providers/previewOptionsProvider.tsx +++ b/website/src/pages/themes/_providers/previewOptionsProvider.tsx @@ -11,7 +11,7 @@ type PreviewOptionsContextType = { setExampleContent: (content: ExampleConfig[]) => void; }; -export const defaultColorScale = "qualitative"; +export const defaultColorScale = undefined; export const defaultShowTooltips = false; const PreviewOptionsContext = createContext< From ef427a898c903e8e2a8031e4a78a782c1c1779fe Mon Sep 17 00:00:00 2001 From: Stef Williams Date: Wed, 18 Dec 2024 15:51:20 -0500 Subject: [PATCH 3/4] fix(theme-builder): same id for all toggles bug --- .../themes/_components/color-scale-override-selector.tsx | 4 +++- website/src/pages/themes/_components/control.tsx | 9 ++++++++- website/src/pages/themes/_components/options-panel.tsx | 1 - 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/website/src/pages/themes/_components/color-scale-override-selector.tsx b/website/src/pages/themes/_components/color-scale-override-selector.tsx index 343b02152..6fe015321 100644 --- a/website/src/pages/themes/_components/color-scale-override-selector.tsx +++ b/website/src/pages/themes/_components/color-scale-override-selector.tsx @@ -4,6 +4,7 @@ import clsx from "clsx"; import Toggle from "./toggle"; type ColorScaleOverrideSelectorProps = { + id: string; label?: string; value?: string | string[]; onChange: (value: string[] | undefined) => void; @@ -11,6 +12,7 @@ type ColorScaleOverrideSelectorProps = { }; const ColorScaleOverrideSelector = ({ + id, label = "Color Scale", value, onChange, @@ -39,7 +41,7 @@ const ColorScaleOverrideSelector = ({
{ +type ControlProps = { + type: string; + control: any; + className?: string; +}; + +const Control = ({ type, control, className }: ControlProps) => { const { customThemeConfig, updateCustomThemeConfig } = useTheme(); const handleColorChange = ({ newColor, @@ -116,6 +122,7 @@ const Control = ({ type, control, className }) => { case "colorScale": return ( ); })} From 2f565ca330815f24a2b448c5b9fb1cda326c7bbf Mon Sep 17 00:00:00 2001 From: Stef Williams Date: Fri, 20 Dec 2024 14:20:44 -0500 Subject: [PATCH 4/4] wip(theme-builder): new layout for color palette panel --- .../_components/color-palette-selector.tsx | 17 ++++++--- .../color-scale-override-selector.tsx | 35 +++++++++++++----- .../src/pages/themes/_components/control.tsx | 23 ++++++++++-- .../_components/theme-preview/options.tsx | 15 ++------ .../preview-color-scale-select.tsx | 37 +++++++++++++++++++ website/src/pages/themes/_config/index.tsx | 7 +++- website/src/pages/themes/_config/palette.tsx | 12 +++--- 7 files changed, 111 insertions(+), 35 deletions(-) create mode 100644 website/src/pages/themes/_components/theme-preview/preview-color-scale-select.tsx diff --git a/website/src/pages/themes/_components/color-palette-selector.tsx b/website/src/pages/themes/_components/color-palette-selector.tsx index 0674ec4ee..ddef79a5b 100644 --- a/website/src/pages/themes/_components/color-palette-selector.tsx +++ b/website/src/pages/themes/_components/color-palette-selector.tsx @@ -28,6 +28,17 @@ const ColorPaletteSelector = ({ updateColorScale(value); }; + const handleColorChange = (newColor, i, cScale) => { + onColorChange({ + newColor, + index: i, + colorScale: cScale, + }); + if (colorScale !== cScale) { + updateColorScale(cScale); + } + }; + const isSelected = colorScale === value; return ( @@ -54,11 +65,7 @@ const ColorPaletteSelector = ({ key={i} color={color} onColorChange={(newColor) => - onColorChange({ - newColor, - index: i, - colorScale: colorScaleType as string, - }) + handleColorChange(newColor, i, colorScaleType) } /> ))} diff --git a/website/src/pages/themes/_components/color-scale-override-selector.tsx b/website/src/pages/themes/_components/color-scale-override-selector.tsx index 6fe015321..d6562be0c 100644 --- a/website/src/pages/themes/_components/color-scale-override-selector.tsx +++ b/website/src/pages/themes/_components/color-scale-override-selector.tsx @@ -1,13 +1,18 @@ -import React from "react"; +import React, { useCallback } from "react"; import ColorPicker from "./color-picker"; import clsx from "clsx"; import Toggle from "./toggle"; +import { + defaultColorScale, + usePreviewOptions, +} from "../_providers/previewOptionsProvider"; type ColorScaleOverrideSelectorProps = { id: string; label?: string; value?: string | string[]; onChange: (value: string[] | undefined) => void; + hideDefaultToggle?: boolean; className?: string; }; @@ -16,38 +21,50 @@ const ColorScaleOverrideSelector = ({ label = "Color Scale", value, onChange, + hideDefaultToggle = false, className, }: ColorScaleOverrideSelectorProps) => { + const { colorScale, updateColorScale } = usePreviewOptions(); const hasCustomValue = Array.isArray(value); const [initialCustomValue] = React.useState( hasCustomValue ? value : undefined, ); + const setColorScaleToDefault = useCallback(() => { + if (colorScale !== defaultColorScale) { + updateColorScale(defaultColorScale); + } + }, [colorScale, updateColorScale]); + const onCheckboxChange = (isChecked) => { if (isChecked) { onChange(initialCustomValue); } else { onChange(undefined); } + setColorScaleToDefault(); }; const handleColorChange = (newColor, index) => { const newValue = [...(value as string[])]; newValue[index] = newColor; onChange(newValue); + setColorScaleToDefault(); }; return (
- + {!hideDefaultToggle && ( + + )} {hasCustomValue && (
{value.map((color, i) => ( diff --git a/website/src/pages/themes/_components/control.tsx b/website/src/pages/themes/_components/control.tsx index 843793439..851208a45 100644 --- a/website/src/pages/themes/_components/control.tsx +++ b/website/src/pages/themes/_components/control.tsx @@ -7,6 +7,7 @@ import { getConfigValue } from "../_utils"; import { useTheme } from "../_providers/themeProvider"; import Accordion from "./accordion"; import ColorScaleOverrideSelector from "./color-scale-override-selector"; +import PreviewColorScaleSelect from "./theme-preview/preview-color-scale-select"; export type ColorChangeArgs = { newColor?: string; @@ -78,9 +79,16 @@ const Control = ({ type, control, className }: ControlProps) => { case "section": return (
-

- {control.label} -

+
+

+ {control.label} +

+ {control.description && ( +

+ {control.description} +

+ )} +
{control.controls?.map((nestedControl, i) => ( { value={configValue as string} onChange={handleChange} className={className} + hideDefaultToggle={control.hideDefaultToggle} + /> + ); + case "colorScalePreview": + return ( + ); case "colorPicker": diff --git a/website/src/pages/themes/_components/theme-preview/options.tsx b/website/src/pages/themes/_components/theme-preview/options.tsx index 22de5f76a..2f187f717 100644 --- a/website/src/pages/themes/_components/theme-preview/options.tsx +++ b/website/src/pages/themes/_components/theme-preview/options.tsx @@ -3,14 +3,14 @@ import Select from "../select"; import { usePreviewOptions } from "../../_providers/previewOptionsProvider"; import { colorScaleOptions } from "../../_const"; import Toggle from "../toggle"; +import PreviewColorScaleSelect from "./preview-color-scale-select"; type Props = { isOpen: boolean; }; export const Options = forwardRef(({ isOpen }, ref) => { - const { colorScale, updateColorScale, showTooltips, setShowTooltips } = - usePreviewOptions(); + const { showTooltips, setShowTooltips } = usePreviewOptions(); return (
@@ -20,16 +20,7 @@ export const Options = forwardRef(({ isOpen }, ref) => { ref={ref} >

Preview Settings

- + ); +}; +export default PreviewColorScaleSelect; diff --git a/website/src/pages/themes/_config/index.tsx b/website/src/pages/themes/_config/index.tsx index 6a86c05f5..6ffa8a868 100644 --- a/website/src/pages/themes/_config/index.tsx +++ b/website/src/pages/themes/_config/index.tsx @@ -6,7 +6,11 @@ export type ControlConfig = { controls?: ControlConfig[]; } & ( | { - type: "section" | "accordion"; + type: "accordion" | "colorScalePreview"; + } + | { + type: "section"; + description?: string; } | { type: "colorPalette"; @@ -16,6 +20,7 @@ export type ControlConfig = { | { type: "colorScale"; path: string | string[]; + showDefaultToggle?: boolean; } | { type: "slider" | "select" | "colorPicker"; diff --git a/website/src/pages/themes/_config/palette.tsx b/website/src/pages/themes/_config/palette.tsx index 4374a283c..ac4e8a385 100644 --- a/website/src/pages/themes/_config/palette.tsx +++ b/website/src/pages/themes/_config/palette.tsx @@ -4,12 +4,13 @@ import { getNestedColorScaleConfig } from "../_utils"; const paletteOptionsConfig: OptionsPanelConfig = { title: "Color Palette", - description: - "Select a color palette to apply it to the preview charts, then adjust individual colors in the palette to customize the theme.", + description: "Customize your theme's color palettes.", controls: [ { type: "section", - label: "Component Defaults", + label: "Defaults", + description: + "Set the default color scale for each of the following Victory components.", controls: [ { type: "accordion", @@ -30,11 +31,12 @@ const paletteOptionsConfig: OptionsPanelConfig = { }, { type: "section", - label: "Color Palettes", + label: "Color Scales", + description: "Customize the theme's predefined color scale palettes.", controls: colorScaleOptions.map((option) => ({ type: "colorPalette", - colorScaleType: option.value, label: option.label, + colorScaleType: option.value, value: option.value, })), },