react-antd-admin-panel
Version:
Modern TypeScript-first React admin panel builder with Ant Design 6
57 lines • 1.74 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { Switch as AntSwitch } from 'antd';
import { FormFieldBuilder } from '../base/FormFieldBuilder';
/**
* Switch Field Builder
* Wrapper for Ant Design Switch component (toggle/boolean input)
*/
export class Switch extends FormFieldBuilder {
/**
* Set content to display when checked
*/
checkedChildren(content) {
this._config.checkedChildren = content;
return this;
}
/**
* Set content to display when unchecked
*/
unCheckedChildren(content) {
this._config.unCheckedChildren = content;
return this;
}
/**
* Set switch size
*/
size(value) {
this._config.size = value;
return this;
}
/**
* Set loading state
*/
loading(value = true) {
this._config.loading = value;
return this;
}
/**
* Render the switch component
*/
render() {
if (this._config.hidden) {
return null;
}
// Create a wrapper component with state
const SwitchWrapper = () => {
const [checked, setChecked] = React.useState(this._value || false);
const handleChange = (value) => {
setChecked(value);
this.handleChange(value);
};
return (_jsx(AntSwitch, { disabled: this._config.disabled, checkedChildren: this._config.checkedChildren, unCheckedChildren: this._config.unCheckedChildren, size: this._config.size, loading: this._config.loading, checked: checked, onChange: handleChange }));
};
return this.wrapWithLabel(_jsx(SwitchWrapper, {}));
}
}
//# sourceMappingURL=Switch.js.map