2024-09-30 15:54:09 +05:30
|
|
|
import Tools from "../../../canvas/constants/tools"
|
|
|
|
|
import { convertObjectToKeyValueString } from "../../../utils/common"
|
2024-09-30 19:13:26 +05:30
|
|
|
import { CustomTkWidgetBase } from "./base"
|
2024-09-30 15:54:09 +05:30
|
|
|
|
|
|
|
|
|
2024-09-30 19:13:26 +05:30
|
|
|
class Button extends CustomTkWidgetBase{
|
2024-09-30 15:54:09 +05:30
|
|
|
|
|
|
|
|
static widgetType = "button"
|
2025-03-11 07:23:17 +05:30
|
|
|
static displayName = "Button"
|
2024-09-30 15:54:09 +05:30
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
...this.state,
|
|
|
|
|
size: { width: 80, height: 40 },
|
|
|
|
|
widgetName: "Button",
|
|
|
|
|
attrs: {
|
|
|
|
|
...this.state.attrs,
|
|
|
|
|
buttonLabel: {
|
|
|
|
|
label: "Button Label",
|
|
|
|
|
tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
|
|
|
|
|
toolProps: {placeholder: "Button label", maxLength: 100},
|
|
|
|
|
value: "Button",
|
|
|
|
|
onChange: (value) => this.setAttrValue("buttonLabel", value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
super.componentDidMount()
|
2024-09-30 22:18:08 +05:30
|
|
|
this.setAttrValue("styling.backgroundColor", "#029CFF")
|
|
|
|
|
this.setAttrValue("styling.foregroundColor", "#fff")
|
2024-09-30 15:54:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generateCode(variableName, parent){
|
|
|
|
|
|
|
|
|
|
const labelText = this.getAttrValue("buttonLabel")
|
|
|
|
|
|
|
|
|
|
const config = convertObjectToKeyValueString(this.getConfigCode())
|
|
|
|
|
|
|
|
|
|
return [
|
2024-09-30 19:13:26 +05:30
|
|
|
`${variableName} = ctk.CTkButton(master=${parent}, text="${labelText}")`,
|
2024-09-30 22:18:08 +05:30
|
|
|
`${variableName}.configure(${config})`,
|
2024-09-30 15:54:09 +05:30
|
|
|
`${variableName}.${this.getLayoutCode()}`
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getToolbarAttrs(){
|
|
|
|
|
|
|
|
|
|
const toolBarAttrs = super.getToolbarAttrs()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ({
|
|
|
|
|
id: this.__id,
|
|
|
|
|
widgetName: toolBarAttrs.widgetName,
|
|
|
|
|
buttonLabel: this.state.attrs.buttonLabel,
|
|
|
|
|
size: toolBarAttrs.size,
|
|
|
|
|
|
|
|
|
|
...this.state.attrs,
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderContent(){
|
|
|
|
|
return (
|
|
|
|
|
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md
|
|
|
|
|
tw-border tw-border-solid tw-border-gray-400 tw-overflow-hidden">
|
|
|
|
|
<div className="tw-p-2 tw-w-full tw-flex tw-place-content-center tw-place-items-center tw-h-full tw-text-center"
|
2025-03-22 11:11:19 +05:30
|
|
|
ref={this.styleAreaRef}
|
2024-09-30 15:54:09 +05:30
|
|
|
style={this.getInnerRenderStyling()}>
|
|
|
|
|
{/* {this.props.children} */}
|
|
|
|
|
<div className="tw-text-sm" style={{color: this.getAttrValue("styling.foregroundColor")}}>
|
|
|
|
|
{this.getAttrValue("buttonLabel")}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default Button
|