UNPKG

@schema-render/form-render-react

Version:

Out-of-the-box form rendering library based on Core and Antd.

38 lines (37 loc) 1.44 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useMemoizedFn } from "@schema-render/core-react"; import { Checkbox as AntCheckbox } from "antd"; import React from "react"; import Description from "../components/Description"; import { getCheckedOptions, getOptionsLabels } from "../utils"; /** * 编辑与禁用态组件 */ const Checkbox = ({ schema, disabled, value, onChange })=>{ const handleChange = useMemoizedFn((checkedValue)=>{ var _schema_renderOptions; onChange(checkedValue, { extra: { checkedOptions: getCheckedOptions((_schema_renderOptions = schema.renderOptions) === null || _schema_renderOptions === void 0 ? void 0 : _schema_renderOptions.options, checkedValue) } }); }); return /*#__PURE__*/ _jsx(AntCheckbox.Group, { ...schema.renderOptions, value: value, onChange: handleChange, disabled: disabled }); }; /** * 只读态组件 */ const ReadonlyCheckbox = ({ schema, value, locale })=>{ var _schema_renderOptions; const labels = getOptionsLabels((_schema_renderOptions = schema.renderOptions) === null || _schema_renderOptions === void 0 ? void 0 : _schema_renderOptions.options, value); return /*#__PURE__*/ _jsx(Description, { children: labels.join(locale.FormRender.comma) }); }; export default { component: Checkbox, readonlyComponent: ReadonlyCheckbox };