2024-09-23 12:31:01 +05:30
|
|
|
import Widget from "../../../canvas/widgets/base"
|
|
|
|
|
|
|
|
|
|
import Tools from "../../../canvas/constants/tools"
|
|
|
|
|
import { removeKeyFromObject } from "../../../utils/common"
|
2024-09-25 17:27:12 +05:30
|
|
|
import { CheckSquareFilled } from "@ant-design/icons"
|
|
|
|
|
import TkinterBase from "./base"
|
2024-09-23 12:31:01 +05:30
|
|
|
|
|
|
|
|
|
2024-09-25 17:27:12 +05:30
|
|
|
export class CheckBox extends TkinterBase{
|
2024-09-23 12:31:01 +05:30
|
|
|
|
|
|
|
|
static widgetType = "check_button"
|
|
|
|
|
// TODO: remove layouts
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.droppableTags = null // disables drops
|
|
|
|
|
|
|
|
|
|
// const {layout, ...newAttrs} = this.state.attrs // Removes the layout attribute
|
|
|
|
|
|
|
|
|
|
let newAttrs = removeKeyFromObject("layout", this.state.attrs)
|
|
|
|
|
newAttrs = removeKeyFromObject("styling.backgroundColor", newAttrs)
|
|
|
|
|
|
|
|
|
|
this.minSize = {width: 50, height: 30}
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
...this.state,
|
|
|
|
|
size: { width: 120, height: 30 },
|
|
|
|
|
attrs: {
|
|
|
|
|
...newAttrs,
|
|
|
|
|
styling: {
|
2024-09-24 23:27:52 +05:30
|
|
|
label: "Styling",
|
2024-09-23 12:31:01 +05:30
|
|
|
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) => {
|
2024-09-25 17:27:12 +05:30
|
|
|
this.setWidgetInnerStyle("color", value)
|
2024-09-23 12:31:01 +05:30
|
|
|
this.setAttrValue("styling.foregroundColor", value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
checkLabel: {
|
|
|
|
|
label: "Check Label",
|
|
|
|
|
tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
|
|
|
|
|
toolProps: {placeholder: "Button label", maxLength: 100},
|
|
|
|
|
value: "Checkbox",
|
|
|
|
|
onChange: (value) => this.setAttrValue("checkLabel", value)
|
|
|
|
|
},
|
|
|
|
|
defaultChecked: {
|
|
|
|
|
label: "Checked",
|
|
|
|
|
tool: Tools.CHECK_BUTTON, // the tool to display, can be either HTML ELement or a constant string
|
|
|
|
|
value: true,
|
|
|
|
|
onChange: (value) => this.setAttrValue("defaultChecked", value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
super.componentDidMount()
|
|
|
|
|
// this.setAttrValue("styling.backgroundColor", "#fff")
|
|
|
|
|
this.setWidgetName("Checkbox")
|
2024-09-25 17:27:12 +05:30
|
|
|
this.setWidgetInnerStyle("backgroundColor", "#fff0")
|
2024-09-23 12:31:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getToolbarAttrs(){
|
|
|
|
|
|
|
|
|
|
const toolBarAttrs = super.getToolbarAttrs()
|
|
|
|
|
|
|
|
|
|
const attrs = this.state.attrs
|
|
|
|
|
return ({
|
|
|
|
|
id: this.__id,
|
|
|
|
|
widgetName: toolBarAttrs.widgetName,
|
|
|
|
|
checkLabel: attrs.checkLabel,
|
|
|
|
|
size: toolBarAttrs.size,
|
|
|
|
|
...attrs,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderContent(){
|
|
|
|
|
return (
|
|
|
|
|
<div className="tw-flex tw-p-1 tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden"
|
2024-09-25 17:27:12 +05:30
|
|
|
style={this.state.widgetInnerStyling}
|
2024-09-23 12:31:01 +05:30
|
|
|
>
|
|
|
|
|
|
|
|
|
|
<div className="tw-flex tw-gap-2 tw-w-full tw-h-full tw-place-items-center tw-place-content-center">
|
|
|
|
|
<div className="tw-border-solid tw-border-[#D9D9D9] tw-border-2
|
|
|
|
|
tw-min-w-[20px] tw-min-h-[20px] tw-w-[20px] tw-h-[20px]
|
|
|
|
|
tw-text-blue-600 tw-flex tw-items-center tw-justify-center
|
|
|
|
|
tw-rounded-md tw-overflow-hidden">
|
|
|
|
|
{
|
|
|
|
|
this.getAttrValue("defaultChecked") === true &&
|
|
|
|
|
<CheckSquareFilled className="tw-text-[20px]" />
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{this.getAttrValue("checkLabel")}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-23 18:25:40 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class RadioButton extends Widget{
|
|
|
|
|
|
|
|
|
|
static widgetType = "radio_button"
|
2024-09-23 19:31:30 +05:30
|
|
|
// FIXME: the radio buttons are not visible because of the default height provided
|
2024-09-23 18:25:40 +05:30
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.droppableTags = null // disables drops
|
|
|
|
|
|
|
|
|
|
// const {layout, ...newAttrs} = this.state.attrs // Removes the layout attribute
|
|
|
|
|
|
|
|
|
|
let newAttrs = removeKeyFromObject("layout", this.state.attrs)
|
|
|
|
|
newAttrs = removeKeyFromObject("styling.backgroundColor", newAttrs)
|
|
|
|
|
|
|
|
|
|
this.minSize = {width: 50, height: 30}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
...this.state,
|
|
|
|
|
size: { width: 120, height: 'fit' },
|
|
|
|
|
attrs: {
|
|
|
|
|
...newAttrs,
|
|
|
|
|
styling: {
|
2024-09-24 23:27:52 +05:30
|
|
|
label: "styling",
|
2024-09-23 18:25:40 +05:30
|
|
|
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) => {
|
2024-09-25 17:27:12 +05:30
|
|
|
this.setWidgetInnerStyle("color", value)
|
2024-09-23 18:25:40 +05:30
|
|
|
this.setAttrValue("styling.foregroundColor", value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
radios: {
|
|
|
|
|
label: "Radio Group",
|
|
|
|
|
tool: Tools.INPUT_RADIO_LIST,
|
|
|
|
|
value: {inputs: ["default"], selectedRadio: -1},
|
|
|
|
|
onChange: ({inputs, selectedRadio}) => {
|
|
|
|
|
this.setAttrValue("radios", {inputs, selectedRadio})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
super.componentDidMount()
|
|
|
|
|
// this.setAttrValue("styling.backgroundColor", "#fff")
|
2024-09-25 17:27:12 +05:30
|
|
|
this.setWidgetName("Radio button")
|
|
|
|
|
this.setWidgetInnerStyle("backgroundColor", "#fff0")
|
2024-09-23 18:25:40 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getToolbarAttrs(){
|
|
|
|
|
|
|
|
|
|
const toolBarAttrs = super.getToolbarAttrs()
|
|
|
|
|
|
|
|
|
|
const attrs = this.state.attrs
|
|
|
|
|
return ({
|
|
|
|
|
id: this.__id,
|
|
|
|
|
widgetName: toolBarAttrs.widgetName,
|
|
|
|
|
checkLabel: attrs.checkLabel,
|
|
|
|
|
size: toolBarAttrs.size,
|
|
|
|
|
...attrs,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderContent(){
|
|
|
|
|
|
|
|
|
|
const {inputs, selectedRadio} = this.getAttrValue("radios")
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="tw-flex tw-p-1 tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden"
|
2024-09-25 17:27:12 +05:30
|
|
|
style={this.state.widgetInnerStyling}
|
2024-09-23 18:25:40 +05:30
|
|
|
>
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
inputs.map((value, index) => {
|
|
|
|
|
return (
|
|
|
|
|
<div key={index} className="tw-flex tw-gap-2 tw-w-full tw-h-full tw-place-items-center ">
|
|
|
|
|
<div className="tw-border-solid tw-border-[#D9D9D9] tw-border-2
|
|
|
|
|
tw-min-w-[20px] tw-min-h-[20px] tw-w-[20px] tw-h-[20px]
|
|
|
|
|
tw-text-blue-600 tw-flex tw-items-center tw-justify-center
|
|
|
|
|
tw-rounded-full tw-overflow-hidden tw-p-1">
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
selectedRadio === index &&
|
|
|
|
|
<div className="tw-rounded-full tw-bg-blue-600 tw-w-full tw-h-full">
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
2024-09-25 17:27:12 +05:30
|
|
|
<span className="tw-text-base" style={{color: this.state.widgetInnerStyling.foregroundColor}}>
|
2024-09-23 18:25:40 +05:30
|
|
|
{value}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-23 12:31:01 +05:30
|
|
|
}
|