diff --git a/website/src/pages/themes/_components/button.tsx b/website/src/components/button.tsx similarity index 66% rename from website/src/pages/themes/_components/button.tsx rename to website/src/components/button.tsx index 7ae1f6203..f9fb1bd81 100644 --- a/website/src/pages/themes/_components/button.tsx +++ b/website/src/components/button.tsx @@ -10,7 +10,7 @@ type ButtonProps = { size?: "sm" | "md"; }; -const Button = ({ +export const Button = ({ onClick, children, className = "", @@ -19,13 +19,16 @@ const Button = ({ size = "md", ...props }: ButtonProps) => { + const baseClasses = + "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 && ( - + ); +}; +export default PreviewColorScaleSelect; 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..5c50be22e 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", @@ -457,40 +322,7 @@ const chartConfigs: { group: { type: "section", label: "Group", - allowColorScaleOverride: true, - content: (props) => [ - , - , - - - - - , - ], + content: GroupExamples, controls: [ { type: "section", @@ -512,54 +344,7 @@ const chartConfigs: { legend: { type: "section", label: "Legend", - content: (props) => [ - , - datum.fill, - }, - }} - />, - ], + content: LegendExamples, controls: [ { type: "section", @@ -637,22 +422,7 @@ const chartConfigs: { line: { type: "section", label: "Line Chart", - content: (props) => [ - , - , - datum.y} - />, - ], + content: LineExamples, controls: [ { type: "section", @@ -674,20 +444,7 @@ const chartConfigs: { pie: { type: "section", label: "Pie Chart", - allowColorScaleOverride: true, - hasVictoryChart: false, - content: (props) => ( - - ), + content: PieExamples, controls: [ { type: "section", @@ -718,18 +475,7 @@ const chartConfigs: { scatter: { type: "section", label: "Scatter Chart", - content: (props) => ( - - ), + content: ScatterExamples, controls: [ { type: "section", @@ -764,21 +510,7 @@ const chartConfigs: { stack: { type: "section", label: "Stack", - allowColorScaleOverride: true, - content: (props) => [ - , - , - - {[...Array(NUM_STACKS)].map((_, i) => ( - - ))} - , - ], + content: StackExamples, controls: [ { type: "section", @@ -851,18 +583,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..6ffa8a868 100644 --- a/website/src/pages/themes/_config/index.tsx +++ b/website/src/pages/themes/_config/index.tsx @@ -1,14 +1,16 @@ -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; } & ( | { - type: "section" | "accordion"; + type: "accordion" | "colorScalePreview"; + } + | { + type: "section"; + description?: string; } | { type: "colorPalette"; @@ -18,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 271e8d22a..ac4e8a385 100644 --- a/website/src/pages/themes/_config/palette.tsx +++ b/website/src/pages/themes/_config/palette.tsx @@ -1,16 +1,46 @@ 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, - })), + description: "Customize your theme's color palettes.", + controls: [ + { + type: "section", + label: "Defaults", + description: + "Set the default color scale for each of the following Victory components.", + 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 Scales", + description: "Customize the theme's predefined color scale palettes.", + controls: colorScaleOptions.map((option) => ({ + type: "colorPalette", + label: option.label, + colorScaleType: option.value, + 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 439221e51..fa1e22e7d 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 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";