vchikalkin 32f265fc8d optimize package/ui/elements imports
optimize antd/link imports

ui/elements/text: use antd component

ui/element: optimize input, input-number, switch, checkbox imports

fix Number typename

ui/elements: optimize Radio, Segmented, Select

move type Status to store types

fix TableInsurance builders

packages/ui: remove antd dir

Output/Results: fix elements margin

revert Loading status to elements

packages/ui: remove value from props

remove unnecessary loading prop
2023-05-16 11:31:45 +03:00

39 lines
1.2 KiB
TypeScript

import type { Elements } from '../config/map/values';
import { useStoreValue } from './hooks';
import { useStatus } from '@/stores/calculation/statuses/hooks';
import { useValidation } from '@/stores/calculation/validation/hooks';
import type { Values } from '@/stores/calculation/values/types';
import type { CheckboxChangeEvent } from 'antd/lib/checkbox';
import { observer } from 'mobx-react-lite';
import type { ComponentType } from 'react';
import { Form } from 'ui/elements';
type BuilderProps = {
elementName: Elements;
valueName: Values;
};
export function buildCheck<T>(
Component: ComponentType<T>,
{ elementName, valueName }: BuilderProps
) {
return observer((props: T) => {
const [value, setValue] = useStoreValue(valueName);
const status = useStatus(elementName);
const { validateStatus, help } = useValidation(elementName);
return (
<Form.Item help={help} validateStatus={validateStatus}>
<Component
onChange={(event: CheckboxChangeEvent) => {
setValue(event.target.checked);
}}
disabled={status === 'Disabled'}
checked={value}
{...props}
/>
</Form.Item>
);
});
}