import Widget from "../../../canvas/widgets/base" import Tools from "../../../canvas/constants/tools" import { removeKeyFromObject } from "../../../utils/common" import { ArrowDownOutlined, DownOutlined } from "@ant-design/icons" import {TkinterBase} from "./base" class OptionMenu extends TkinterBase{ static widgetType = "option_menu" // FIXME: the radio buttons are not visible because of the default heigh provided constructor(props) { super(props) this.droppableTags = null // disables drops // const {layout, ...newAttrs} = this.state.attrs // Removes the layout attribute const newAttrs = removeKeyFromObject("layout", this.state.attrs) this.minSize = {width: 50, height: 30} this.state = { ...this.state, isDropDownOpen: false, widgetName: "Option menu", size: { width: 120, height: 'fit' }, attrs: { ...newAttrs, styling: { label: "styling", foregroundColor: { label: "Foreground Color", tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string value: "#000", onChange: (value) => { this.setWidgetInnerStyle("color", value) this.setAttrValue("styling.foregroundColor", value) } } }, defaultValue: { label: "Default Value", tool: Tools.INPUT, value: "Select option", onChange: ({inputs, selectedRadio}) => { this.setAttrValue("options", {inputs, selectedRadio}) } }, options: { label: "Options", tool: Tools.INPUT_RADIO_LIST, value: {inputs: ["option 1"], selectedRadio: -1}, onChange: ({inputs, selectedRadio}) => { this.setAttrValue("options", {inputs, selectedRadio}) } } } } } componentDidMount(){ super.componentDidMount() this.setWidgetInnerStyle("backgroundColor", "#fff") } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() const attrs = this.state.attrs return ({ id: this.__id, widgetName: toolBarAttrs.widgetName, checkLabel: attrs.checkLabel, size: toolBarAttrs.size, ...attrs, }) } toggleDropDownOpen = () => { this.setState((prev) => ({ isDropDownOpen: !prev.isDropDownOpen })) } renderContent(){ const {inputs, selectedRadio} = this.getAttrValue("options") return (
{this.getAttrValue("defaultValue")}
{this.state.isDropDownOpen &&
{ inputs.map((value, index) => { return (
{value}
) }) }
}
) } } export default OptionMenu