Files
PyUIBuilder/src/frameworks/tkinter/widgets/label.js

86 lines
2.7 KiB
JavaScript
Raw Normal View History

2024-09-22 22:24:35 +05:30
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
2024-09-22 22:24:35 +05:30
class Label extends Widget{
static widgetType = "label"
constructor(props) {
super(props)
this.droppableTags = {
// TODO: exclude all
exclude: ["image", "video", "media", "main_window", "toplevel"]
}
const newAttrs = removeKeyFromObject("layout", this.state.attrs)
2024-09-22 22:24:35 +05:30
this.state = {
...this.state,
size: { width: 80, height: 40 },
attrs: {
...newAttrs,
2024-09-22 22:24:35 +05:30
styling: {
...newAttrs.styling,
2024-09-22 22:24:35 +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) => {
this.setWidgetStyling("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
},
labelWidget: {
label: "Text",
tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
toolProps: {placeholder: "text", maxLength: 100},
value: "Label",
onChange: (value) => this.setAttrValue("labelWidget", value)
}
}
}
}
componentDidMount(){
super.componentDidMount()
this.setAttrValue("styling.backgroundColor", "#fff")
this.setWidgetStyling("backgroundColor", "#fff0")
2024-09-22 22:24:35 +05:30
}
getToolbarAttrs(){
const toolBarAttrs = super.getToolbarAttrs()
2024-09-22 22:24:35 +05:30
return ({
id: this.__id,
widgetName: toolBarAttrs.widgetName,
2024-09-22 22:24:35 +05:30
labelWidget: this.state.attrs.labelWidget,
size: toolBarAttrs.size,
2024-09-22 22:24:35 +05:30
...this.state.attrs,
})
}
renderContent(){
return (
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start " style={this.state.widgetStyling}>
{/* {this.props.children} */}
<div className="tw-text-sm" style={{color: this.getAttrValue("styling.foregroundColor")}}>
{this.getAttrValue("labelWidget")}
</div>
</div>
</div>
)
}
}
export default Label