-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate option controls from config
- Loading branch information
Showing
5 changed files
with
168 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react"; | ||
import clsx from "clsx"; | ||
import { FaChevronDown } from "react-icons/fa"; | ||
|
||
const Accordion = ({ id, title, children }) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
|
||
const toggleAccordion = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
return ( | ||
<div id={id} className="group"> | ||
<h2 id={`${id}-heading`}> | ||
<button | ||
type="button" | ||
className={clsx( | ||
"flex items-center justify-between w-full px-5 py-3 text-sm font-bold rtl:text-right text-gray-500 border border-b-0 border-gray-200 gap-3 group-last:border-b", | ||
{ "group-last:border-b-0": isOpen }, | ||
)} | ||
aria-expanded="true" | ||
aria-controls={`${id}-body`} | ||
onClick={toggleAccordion} | ||
> | ||
<span>{title}</span> | ||
<FaChevronDown | ||
className={clsx("w-3 h-3 shrink-0", { "rotate-180 ": isOpen })} | ||
/> | ||
</button> | ||
</h2> | ||
<div | ||
id={`${id}-body`} | ||
className={isOpen ? "block" : "hidden"} | ||
aria-labelledby={`${id}-heading`} | ||
> | ||
<div className="p-5 border border-b-0 border-gray-200 group-last:border-b"> | ||
{children} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
export default Accordion; |
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,65 @@ | ||
import React from "react"; | ||
import optionsConfig from "./options-config"; | ||
import Accordion from "./accordion"; | ||
import Select from "./select"; | ||
import Slider from "./slider"; | ||
import ColorPicker from "./color-picker"; | ||
|
||
const ConfigMapper = ({ | ||
activeColorScale, | ||
handleColorScaleChange, | ||
handleLabelConfigChange, | ||
}) => { | ||
return ( | ||
<> | ||
{optionsConfig.map((section) => ( | ||
<Accordion key={section.title} title={section.title} id={section.title}> | ||
{section.fields.map((field) => { | ||
if (field.type === "colorScale") { | ||
return ( | ||
<Select | ||
key={field.label} | ||
id="color-scale-select" | ||
value={activeColorScale} | ||
onChange={handleColorScaleChange} | ||
options={field.options} | ||
label={field.label} | ||
/> | ||
); | ||
} | ||
if (field.type === "slider") { | ||
return ( | ||
<Slider | ||
id={field.label} | ||
key={field.label} | ||
label={field.label} | ||
defaultValue={field.default} | ||
unit={field.unit} | ||
onChange={(value) => | ||
handleLabelConfigChange({ [field.label]: value }) | ||
} | ||
/> | ||
); | ||
} | ||
if (field.type === "colorPicker") { | ||
return ( | ||
<ColorPicker | ||
id={field.label} | ||
key={field.label} | ||
label={field.label} | ||
color={field.default} | ||
onColorChange={(color) => | ||
handleLabelConfigChange({ [field.label]: color }) | ||
} | ||
/> | ||
); | ||
} | ||
return null; | ||
})} | ||
</Accordion> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default ConfigMapper; |
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,43 @@ | ||
const optionsConfig = [ | ||
{ | ||
type: "section", | ||
title: "Color Options", | ||
fields: [ | ||
{ | ||
type: "colorScale", | ||
label: "Color Scale", | ||
options: ["Qualitative", "Sequential", "Diverging"], | ||
default: "Qualitative", | ||
}, | ||
], | ||
}, | ||
{ | ||
type: "section", | ||
title: "Axis Label Options", | ||
fields: [ | ||
{ | ||
type: "slider", | ||
label: "Font Size", | ||
min: 10, | ||
max: 24, | ||
default: 12, | ||
unit: "px", | ||
}, | ||
{ | ||
type: "slider", | ||
label: "Padding", | ||
min: 0, | ||
max: 50, | ||
default: 35, | ||
unit: "px", | ||
}, | ||
{ | ||
type: "colorPicker", | ||
label: "Fill", | ||
default: "#292929", | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export default optionsConfig; |
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