import type { FormNodeDefinition } from '@a3s-lab/form/react';
const ratingNode: FormNodeDefinition = {
type: 'company.rating',
catalog: {
label: '评分字段',
group: '业务组件',
create: ({ id, schemaPath }) => ({
id,
kind: 'field',
label: '满意度',
widget: 'company.rating',
schemaPath,
customProps: { max: 5 },
}),
},
render: ({ node, value, onChange }) => (
<Rating
max={Number(node.customProps?.max ?? 5)}
value={Number(value ?? 0)}
onChange={onChange}
/>
),
inspector: ({ node, schema, onUpdate }) => (
<RatingSettings
max={Number(node.customProps?.max ?? 5)}
onChange={(max) =>
onUpdate({
node: { customProps: { ...node.customProps, max } },
schema: { ...schema, maximum: max },
})
}
/>
),
};