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
This commit is contained in:
vchikalkin 2023-05-15 12:02:14 +03:00
parent 58e01d025c
commit 32f265fc8d
34 changed files with 465 additions and 449 deletions

View File

@ -2,7 +2,7 @@ import type { columns } from '../lib/config';
import type { Row, StoreSelector } from '../types'; import type { Row, StoreSelector } from '../types';
import { useStore } from '@/stores/hooks'; import { useStore } from '@/stores/hooks';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import { message, Table } from 'ui/antd'; import { message, Table } from 'ui/elements';
export const PolicyTable = observer( export const PolicyTable = observer(
({ ({

View File

@ -1,7 +1,7 @@
import type { StoreSelector } from '../types'; import type { StoreSelector } from '../types';
import { useStore } from '@/stores/hooks'; import { useStore } from '@/stores/hooks';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import { Button } from 'ui/antd'; import { Button } from 'ui/elements';
import { ReloadOutlined } from 'ui/elements/icons'; import { ReloadOutlined } from 'ui/elements/icons';
import { Flex } from 'ui/grid'; import { Flex } from 'ui/grid';
@ -16,7 +16,8 @@ export const ReloadButton = observer(
<Flex justifyContent="center"> <Flex justifyContent="center">
<Button <Button
onClick={onClick} onClick={onClick}
disabled={hasErrors || rows.some((x) => x.status === 'fetching')} disabled={hasErrors}
loading={rows.some((x) => x.status === 'fetching')}
shape="circle" shape="circle"
icon={<ReloadOutlined />} icon={<ReloadOutlined />}
/> />

View File

@ -1,7 +1,7 @@
import type { StoreSelector } from '../types'; import type { StoreSelector } from '../types';
import { useStore } from '@/stores/hooks'; import { useStore } from '@/stores/hooks';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import { Alert } from 'ui/antd'; import { Alert } from 'ui/elements';
export const Validation = observer(({ storeSelector }: { storeSelector: StoreSelector }) => { export const Validation = observer(({ storeSelector }: { storeSelector: StoreSelector }) => {
const { $tables, $process } = useStore(); const { $tables, $process } = useStore();

View File

@ -13,10 +13,17 @@ export function buildOptionComponent<T>(
const [value, setValue] = useInsuranceValue(key, valueName); const [value, setValue] = useInsuranceValue(key, valueName);
const { getOptions, getStatus } = useRow(key); const { getOptions, getStatus } = useRow(key);
const options = getOptions(valueName); const options = getOptions(valueName);
const statuses = getStatus(valueName); const status = getStatus(valueName);
return ( return (
<Component options={options} setValue={setValue} status={statuses} value={value} {...props} /> <Component
options={options}
onChange={setValue}
disabled={status === 'Disabled'}
loading={status === 'Loading'}
value={value}
{...props}
/>
); );
}); });
} }
@ -29,8 +36,10 @@ export function buildValueComponent<T>(
return observer((props: T) => { return observer((props: T) => {
const [value, setValue] = useInsuranceValue(key, valueName); const [value, setValue] = useInsuranceValue(key, valueName);
const { getStatus } = useRow(key); const { getStatus } = useRow(key);
const statuses = getStatus(valueName); const status = getStatus(valueName);
return <Component setValue={setValue} status={statuses} value={value} {...props} />; return (
<Component onChange={setValue} disabled={status === 'Disabled'} value={value} {...props} />
);
}); });
} }

View File

@ -1,5 +1,6 @@
import type { KeysSchema, RowSchema } from '@/config/schema/insurance'; import type { KeysSchema, RowSchema } from '@/config/schema/insurance';
import type { BaseOption, Status } from 'ui/elements/types'; import type { Status } from '@/stores/calculation/statuses/types';
import type { BaseOption } from 'ui/elements/types';
import type { z } from 'zod'; import type { z } from 'zod';
export type Keys = z.infer<typeof KeysSchema>; export type Keys = z.infer<typeof KeysSchema>;

View File

@ -5,8 +5,7 @@ import { computed } from 'mobx';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import { createContext, useContext, useMemo, useState } from 'react'; import { createContext, useContext, useMemo, useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { Segmented } from 'ui/antd'; import { Alert, Segmented, Table } from 'ui/elements';
import { Alert, Table } from 'ui/elements';
import { Box, Flex } from 'ui/grid'; import { Box, Flex } from 'ui/grid';
import { useDebouncedCallback } from 'use-debounce'; import { useDebouncedCallback } from 'use-debounce';

View File

@ -3,6 +3,7 @@ import { useProcessContext } from '@/process/hooks/common';
import { useStatus } from '@/stores/calculation/statuses/hooks'; import { useStatus } from '@/stores/calculation/statuses/hooks';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import type { ComponentType } from 'react'; import type { ComponentType } from 'react';
import { useThrottledCallback } from 'use-debounce';
type BuilderProps = { type BuilderProps = {
elementName: Elements; elementName: Elements;
@ -17,13 +18,23 @@ export default function buildAction<T>(
const status = useStatus(elementName); const status = useStatus(elementName);
const context = useProcessContext(); const context = useProcessContext();
const throttledAction = useThrottledCallback(
() => {
import(`process/${processName}/action`).then((module) => module.action(context));
},
1200,
{
trailing: false,
}
);
return ( return (
<Component <Component
action={() => onClick={throttledAction}
import(`process/${processName}/action`).then((module) => module.action(context))}
status={status} status={status}
{...props} {...props}
disabled={status === 'Disabled'}
loading={status === 'Loading'}
/> />
); );
}); });

View File

@ -0,0 +1,38 @@
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>
);
});
}

View File

@ -0,0 +1,31 @@
import type { Elements } from '../config/map/values';
import { useStoreValue } from './hooks';
import { useStatus } from '@/stores/calculation/statuses/hooks';
import type { Values } from '@/stores/calculation/values/types';
import { observer } from 'mobx-react-lite';
import type { ComponentType } from 'react';
export type BuilderProps = {
elementName: Elements;
valueName: Values;
};
export default function buildLink<T>(
Component: ComponentType<T>,
{ elementName, valueName }: BuilderProps
) {
return observer((props: T) => {
const [value] = useStoreValue(valueName);
const status = useStatus(elementName);
return (
<Component
status={status}
href={value}
disabled={!value}
loading={status === 'Loading'}
{...props}
/>
);
});
}

View File

@ -6,6 +6,7 @@ import { useValidation } from '@/stores/calculation/validation/hooks';
import type { Values } from '@/stores/calculation/values/types'; import type { Values } from '@/stores/calculation/values/types';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import type { ComponentType } from 'react'; import type { ComponentType } from 'react';
import { Form } from 'ui/elements';
type BuilderProps = { type BuilderProps = {
elementName: Elements; elementName: Elements;
@ -23,15 +24,16 @@ export default function buildOptions<T>(
const options = useOptions(elementName); const options = useOptions(elementName);
return ( return (
<Component <Form.Item help={help} validateStatus={validateStatus}>
help={help} <Component
validateStatus={validateStatus} disabled={status === 'Disabled'}
options={options} loading={status === 'Loading'}
setValue={setValue} options={options}
status={status} onChange={setValue}
value={value} value={value}
{...props} {...props}
/> />
</Form.Item>
); );
}); });
} }

View File

@ -4,14 +4,15 @@ import { useStatus } from '@/stores/calculation/statuses/hooks';
import { useValidation } from '@/stores/calculation/validation/hooks'; import { useValidation } from '@/stores/calculation/validation/hooks';
import type { Values } from '@/stores/calculation/values/types'; import type { Values } from '@/stores/calculation/values/types';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
import type { ComponentType } from 'react'; import type { ChangeEvent, ComponentType } from 'react';
import { Form } from 'ui/elements';
export type BuilderProps = { type BuilderProps = {
elementName: Elements; elementName: Elements;
valueName: Values; valueName: Values;
}; };
export default function buildValue<T>( export function buildValue<T>(
Component: ComponentType<T>, Component: ComponentType<T>,
{ elementName, valueName }: BuilderProps { elementName, valueName }: BuilderProps
) { ) {
@ -21,14 +22,40 @@ export default function buildValue<T>(
const { validateStatus, help } = useValidation(elementName); const { validateStatus, help } = useValidation(elementName);
return ( return (
<Component <Form.Item help={help} validateStatus={validateStatus}>
help={help} <Component
validateStatus={validateStatus} onChange={(e: ChangeEvent<HTMLInputElement>) => {
setValue={setValue} setValue(e.target.value);
status={status} }}
value={value} disabled={status === 'Disabled'}
{...props} value={value}
/> {...props}
/>
</Form.Item>
);
});
}
export function buildNumberValue<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={(v = 0) => {
setValue(v);
}}
disabled={status === 'Disabled'}
value={value}
{...props}
/>
</Form.Item>
); );
}); });
} }

View File

@ -1,4 +1,6 @@
export { default as buildAction } from './build-action'; export { default as buildAction } from './build-action';
export * from './build-check';
export { default as buildLink } from './build-link';
export { default as buildOptions } from './build-options'; export { default as buildOptions } from './build-options';
export { default as buildReadonly } from './build-readonly'; export { default as buildReadonly } from './build-readonly';
export { default as buildValue } from './build-value'; export * from './build-value';

View File

@ -19,6 +19,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: CurrencyAddon, addonAfter: CurrencyAddon,
style: {
width: '100%',
},
}, },
tbxLeaseObjectPriceWthtVAT: { tbxLeaseObjectPriceWthtVAT: {
min: 0, min: 0,
@ -28,6 +31,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: CurrencyAddon, addonAfter: CurrencyAddon,
style: {
width: '100%',
},
}, },
tbxVATInLeaseObjectPrice: { tbxVATInLeaseObjectPrice: {
min: 0, min: 0,
@ -37,12 +43,18 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: CurrencyAddon, addonAfter: CurrencyAddon,
style: {
width: '100%',
},
}, },
tbxEngineHours: { tbxEngineHours: {
min: 0, min: 0,
step: 10, step: 10,
precision: 2, precision: 2,
addonAfter: 'ч.', addonAfter: 'ч.',
style: {
width: '100%',
},
}, },
tbxSupplierDiscountRub: { tbxSupplierDiscountRub: {
min: 0, min: 0,
@ -52,6 +64,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: CurrencyAddon, addonAfter: CurrencyAddon,
style: {
width: '100%',
},
}, },
tbxSupplierDiscountPerc: { tbxSupplierDiscountPerc: {
min: 0, min: 0,
@ -59,6 +74,9 @@ const props: Partial<ElementsProps> = {
precision: 2, precision: 2,
addonAfter: '%', addonAfter: '%',
style: {
width: '100%',
},
}, },
radioBalanceHolder: { radioBalanceHolder: {
optionType: 'button', optionType: 'button',
@ -71,6 +89,9 @@ const props: Partial<ElementsProps> = {
precision: 2, precision: 2,
addonAfter: '%', addonAfter: '%',
style: {
width: '100%',
},
}, },
radioLastPaymentRule: { radioLastPaymentRule: {
block: true, block: true,
@ -82,6 +103,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter: createFormatter({ minimumFractionDigits: 4, maximumFractionDigits: 4 }), formatter: createFormatter({ minimumFractionDigits: 4, maximumFractionDigits: 4 }),
addonAfter: '%', addonAfter: '%',
style: {
width: '100%',
},
}, },
tbxFirstPaymentRub: { tbxFirstPaymentRub: {
min: 0, min: 0,
@ -91,6 +115,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxLastPaymentPerc: { tbxLastPaymentPerc: {
min: 0, min: 0,
@ -100,6 +127,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter: createFormatter({ minimumFractionDigits: 6, maximumFractionDigits: 6 }), formatter: createFormatter({ minimumFractionDigits: 6, maximumFractionDigits: 6 }),
addonAfter: '%', addonAfter: '%',
style: {
width: '100%',
},
}, },
tbxLastPaymentRub: { tbxLastPaymentRub: {
min: 0, min: 0,
@ -109,6 +139,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxRedemptionPaymentSum: { tbxRedemptionPaymentSum: {
min: 1000, min: 1000,
@ -118,34 +151,55 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxLeasingPeriod: { tbxLeasingPeriod: {
min: 13, min: 13,
max: MAX_LEASING_PERIOD, max: MAX_LEASING_PERIOD,
addonAfter: 'мес.', addonAfter: 'мес.',
style: {
width: '100%',
},
}, },
tbxSubsidySum: { tbxSubsidySum: {
min: 0, min: 0,
precision: 2, precision: 2,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxImportProgramSum: { tbxImportProgramSum: {
min: 0, min: 0,
precision: 2, precision: 2,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxAddEquipmentPrice: { tbxAddEquipmentPrice: {
min: 0, min: 0,
precision: 2, precision: 2,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxParmentsDecreasePercent: { tbxParmentsDecreasePercent: {
min: 50, min: 50,
max: 99, max: 99,
style: {
width: '100%',
},
}, },
tbxComissionPerc: { tbxComissionPerc: {
min: 0, min: 0,
max: 100, max: 100,
style: {
width: '100%',
},
}, },
tbxComissionRub: { tbxComissionRub: {
min: 0, min: 0,
@ -154,6 +208,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
selectLeaseObjectType: { selectLeaseObjectType: {
showSearch: true, showSearch: true,
@ -175,6 +232,9 @@ const props: Partial<ElementsProps> = {
min: 1, min: 1,
max: 1000, max: 1000,
addonAfter: 'шт.', addonAfter: 'шт.',
style: {
width: '100%',
},
}, },
selectLeaseObjectUseFor: { selectLeaseObjectUseFor: {
showSearch: true, showSearch: true,
@ -183,6 +243,9 @@ const props: Partial<ElementsProps> = {
tbxLeaseObjectYear: { tbxLeaseObjectYear: {
min: 1994, min: 1994,
max: dayjs().year(), max: dayjs().year(),
style: {
width: '100%',
},
}, },
selectLeaseObjectCategory: { selectLeaseObjectCategory: {
showSearch: false, showSearch: false,
@ -199,6 +262,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: 'л.с.', addonAfter: 'л.с.',
style: {
width: '100%',
},
}, },
tbxEngineVolume: { tbxEngineVolume: {
min: 0, min: 0,
@ -208,6 +274,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter: createFormatter({ minimumFractionDigits: 4, maximumFractionDigits: 4 }), formatter: createFormatter({ minimumFractionDigits: 4, maximumFractionDigits: 4 }),
addonAfter: 'л', addonAfter: 'л',
style: {
width: '100%',
},
}, },
tbxMaxMass: { tbxMaxMass: {
min: 0, min: 0,
@ -216,12 +285,18 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: 'кг', addonAfter: 'кг',
style: {
width: '100%',
},
}, },
tbxCountSeats: { tbxCountSeats: {
min: 0, min: 0,
max: 2000, max: 2000,
precision: 0, precision: 0,
parser, parser,
style: {
width: '100%',
},
}, },
tbxMaxSpeed: { tbxMaxSpeed: {
min: 0, min: 0,
@ -229,6 +304,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: 'км/ч', addonAfter: 'км/ч',
style: {
width: '100%',
},
}, },
selectDealer: { selectDealer: {
showSearch: true, showSearch: true,
@ -239,36 +317,54 @@ const props: Partial<ElementsProps> = {
max: 20, max: 20,
step: 0.1, step: 0.1,
precision: 2, precision: 2,
style: {
width: '100%',
},
}, },
tbxDealerBrokerRewardSumm: { tbxDealerBrokerRewardSumm: {
min: 0, min: 0,
max: 20, max: 20,
step: 0.1, step: 0.1,
precision: 2, precision: 2,
style: {
width: '100%',
},
}, },
tbxIndAgentRewardSumm: { tbxIndAgentRewardSumm: {
min: 0, min: 0,
max: 20, max: 20,
step: 0.1, step: 0.1,
precision: 2, precision: 2,
style: {
width: '100%',
},
}, },
tbxCalcDoubleAgentRewardSumm: { tbxCalcDoubleAgentRewardSumm: {
min: 0, min: 0,
max: 20, max: 20,
step: 0.1, step: 0.1,
precision: 2, precision: 2,
style: {
width: '100%',
},
}, },
tbxCalcBrokerRewardSum: { tbxCalcBrokerRewardSum: {
min: 0, min: 0,
max: 20, max: 20,
step: 0.1, step: 0.1,
precision: 2, precision: 2,
style: {
width: '100%',
},
}, },
tbxFinDepartmentRewardSumm: { tbxFinDepartmentRewardSumm: {
min: 0, min: 0,
max: 20, max: 20,
step: 0.1, step: 0.1,
precision: 2, precision: 2,
style: {
width: '100%',
},
}, },
tbxInsFranchise: { tbxInsFranchise: {
min: 0, min: 0,
@ -278,14 +374,23 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxInsAgeDrivers: { tbxInsAgeDrivers: {
// min: 18, // min: 18,
// max: 99, // max: 99,
style: {
width: '100%',
},
}, },
tbxInsExpDrivers: { tbxInsExpDrivers: {
// min: 0, // min: 0,
// max: 99, // max: 99,
style: {
width: '100%',
},
}, },
selectRegionRegistration: { selectRegionRegistration: {
showSearch: true, showSearch: true,
@ -300,17 +405,17 @@ const props: Partial<ElementsProps> = {
buttonStyle: 'solid', buttonStyle: 'solid',
}, },
btnCalculate: { btnCalculate: {
text: 'Рассчитать график', children: 'Рассчитать график',
type: 'primary', type: 'primary',
block: true, block: true,
}, },
btnCreateKP: { btnCreateKP: {
type: 'primary', type: 'primary',
text: 'Создать КП', children: 'Создать КП',
icon: <PlusOutlined />, icon: <PlusOutlined />,
}, },
btnCreateKPMini: { btnCreateKPMini: {
text: '', children: '',
type: 'primary', type: 'primary',
icon: <PlusOutlined />, icon: <PlusOutlined />,
block: true, block: true,
@ -319,6 +424,9 @@ const props: Partial<ElementsProps> = {
min: 0, min: 0,
max: 99.99, max: 99.99,
step: 0.1, step: 0.1,
style: {
width: '100%',
},
}, },
tbxMaxPriceChange: { tbxMaxPriceChange: {
min: 0, min: 0,
@ -326,6 +434,9 @@ const props: Partial<ElementsProps> = {
step: 10_000, step: 10_000,
parser, parser,
formatter, formatter,
style: {
width: '100%',
},
}, },
tbxMinPriceChange: { tbxMinPriceChange: {
min: 0, min: 0,
@ -333,12 +444,18 @@ const props: Partial<ElementsProps> = {
step: 10_000, step: 10_000,
parser, parser,
formatter, formatter,
style: {
width: '100%',
},
}, },
tbxImporterRewardPerc: { tbxImporterRewardPerc: {
min: 0, min: 0,
max: 99.99, max: 99.99,
step: 0.1, step: 0.1,
precision: 2, precision: 2,
style: {
width: '100%',
},
}, },
tbxImporterRewardRub: { tbxImporterRewardRub: {
min: 0, min: 0,
@ -347,6 +464,9 @@ const props: Partial<ElementsProps> = {
precision: 2, precision: 2,
parser, parser,
formatter, formatter,
style: {
width: '100%',
},
}, },
selectLead: { selectLead: {
showSearch: true, showSearch: true,
@ -368,23 +488,22 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter: createFormatter({ minimumFractionDigits: 6, maximumFractionDigits: 6 }), formatter: createFormatter({ minimumFractionDigits: 6, maximumFractionDigits: 6 }),
addonAfter: '%', addonAfter: '%',
style: {
width: '100%',
},
}, },
linkDownloadKp: { linkDownloadKp: { children: 'Скачать КП', icon: <DownloadOutlined />, target: '_blank' },
type: 'primary',
text: 'Скачать КП',
icon: <DownloadOutlined />,
},
tbxMileage: { tbxMileage: {
min: 0, min: 0,
step: 100, step: 100,
precision: 2, precision: 2,
addonAfter: 'км', addonAfter: 'км',
style: {
width: '100%',
},
}, },
cbxRecalcWithRevision: { cbxRecalcWithRevision: {
text: 'Пересчет без пересмотра', children: 'Пересчет без пересмотра',
style: {
marginBottom: '8px',
},
}, },
tbxTotalPayments: { tbxTotalPayments: {
min: 0, min: 0,
@ -393,6 +512,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxVehicleTaxInYear: { tbxVehicleTaxInYear: {
min: 0, min: 0,
@ -402,6 +524,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
tbxVehicleTaxInLeasingPeriod: { tbxVehicleTaxInLeasingPeriod: {
min: 0, min: 0,
@ -411,6 +536,9 @@ const props: Partial<ElementsProps> = {
parser, parser,
formatter, formatter,
addonAfter: '₽', addonAfter: '₽',
style: {
width: '100%',
},
}, },
selectObjectRegionRegistration: { selectObjectRegionRegistration: {
showSearch: true, showSearch: true,
@ -423,6 +551,9 @@ const props: Partial<ElementsProps> = {
formatter, formatter,
readOnly: true, readOnly: true,
controls: false, controls: false,
style: {
width: '100%',
},
}, },
selectLegalClientRegion: { selectLegalClientRegion: {
showSearch: true, showSearch: true,
@ -457,6 +588,9 @@ const props: Partial<ElementsProps> = {
step: 0.1, step: 0.1,
precision: 4, precision: 4,
formatter: createFormatter({ minimumFractionDigits: 4, maximumFractionDigits: 4 }), formatter: createFormatter({ minimumFractionDigits: 4, maximumFractionDigits: 4 }),
style: {
width: '100%',
},
}, },
tbxVIN: { tbxVIN: {
onInput: (e) => { onInput: (e) => {

View File

@ -1,4 +1,4 @@
import buildReadonly from '../../builders/build-readonly'; import { buildLink } from '../../builders';
import components from '../elements-components'; import components from '../elements-components';
import elementsProps from '../elements-props'; import elementsProps from '../elements-props';
import titles from '../elements-titles'; import titles from '../elements-titles';
@ -14,7 +14,7 @@ import { Link, Tooltip } from 'ui/elements';
import { LoadingOutlined } from 'ui/elements/icons'; import { LoadingOutlined } from 'ui/elements/icons';
const defaultLinkProps: ComponentProps<typeof Link> = { const defaultLinkProps: ComponentProps<typeof Link> = {
text: 'Открыть в CRM', children: 'Открыть в CRM',
type: 'link', type: 'link',
}; };
@ -58,7 +58,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
valueName, valueName,
}); });
const LinkComponent = buildReadonly(Link, { const LinkComponent = buildLink(Link, {
elementName: 'linkLeadUrl', elementName: 'linkLeadUrl',
valueName: 'leadUrl', valueName: 'leadUrl',
}); });
@ -90,7 +90,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
valueName, valueName,
}); });
const LinkComponent = buildReadonly(Link, { const LinkComponent = buildLink(Link, {
elementName: 'linkOpportunityUrl', elementName: 'linkOpportunityUrl',
valueName: 'opportunityUrl', valueName: 'opportunityUrl',
}); });
@ -122,7 +122,7 @@ const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
valueName, valueName,
}); });
const LinkComponent = buildReadonly(Link, { const LinkComponent = buildLink(Link, {
elementName: 'linkQuoteUrl', elementName: 'linkQuoteUrl',
valueName: 'quoteUrl', valueName: 'quoteUrl',
}); });

View File

@ -1,11 +1,15 @@
/* eslint-disable jsdoc/multiline-blocks */ /* eslint-disable jsdoc/multiline-blocks */
/* eslint-disable canonical/sort-keys */ /* eslint-disable canonical/sort-keys */
import { buildAction, buildOptions, buildReadonly, buildValue } from '../builders'; import * as b from '../builders';
import type { Elements as ActionElements } from './map/actions'; import type { Elements as ActionElements } from './map/actions';
import type { Elements as ValuesElements } from './map/values'; import type { Elements as ValuesElements } from './map/values';
type ElementTypes = 'Action' | 'Options' | 'Readonly' | 'Value'; type ElementTypes = 'Action' | 'Check' | 'Link' | 'Options' | 'Readonly' | 'Value';
type Builders = typeof buildAction | typeof buildOptions | typeof buildReadonly | typeof buildValue; type Builders =
| typeof b.buildAction
| typeof b.buildOptions
| typeof b.buildReadonly
| typeof b.buildValue;
type GetType = () => { type GetType = () => {
builder: Builders; builder: Builders;
@ -19,19 +23,31 @@ function wrapTypeGetters<G extends GetType, E extends Record<ElementTypes, G>>(a
const t = wrapTypeGetters({ const t = wrapTypeGetters({
Value: () => ({ Value: () => ({
typeName: 'Value', typeName: 'Value',
builder: buildValue, builder: b.buildValue,
}),
Number: () => ({
typeName: 'Number',
builder: b.buildNumberValue,
}), }),
Readonly: () => ({ Readonly: () => ({
typeName: 'Readonly', typeName: 'Readonly',
builder: buildReadonly, builder: b.buildReadonly,
}), }),
Options: () => ({ Options: () => ({
typeName: 'Options', typeName: 'Options',
builder: buildOptions, builder: b.buildOptions,
}), }),
Action: () => ({ Action: () => ({
typeName: 'Action', typeName: 'Action',
builder: buildAction, builder: b.buildAction,
}),
Link: () => ({
typeName: 'Link',
builder: b.buildLink,
}),
Check: () => ({
typeName: 'Check',
builder: b.buildCheck,
}), }),
}); });
@ -40,68 +56,68 @@ function wrapElementsTypes<T, E extends Record<ActionElements | ValuesElements,
} }
const types = wrapElementsTypes({ const types = wrapElementsTypes({
cbxRecalcWithRevision: t.Value, cbxRecalcWithRevision: t.Check,
tbxLeaseObjectPrice: t.Value, tbxLeaseObjectPrice: t.Number,
tbxLeaseObjectPriceWthtVAT: t.Value, tbxLeaseObjectPriceWthtVAT: t.Number,
tbxVATInLeaseObjectPrice: t.Value, tbxVATInLeaseObjectPrice: t.Number,
tbxEngineHours: t.Value, tbxEngineHours: t.Number,
tbxSupplierDiscountRub: t.Value, tbxSupplierDiscountRub: t.Number,
tbxSupplierDiscountPerc: t.Value, tbxSupplierDiscountPerc: t.Number,
tbxLeasingPeriod: t.Value, tbxLeasingPeriod: t.Number,
tbxFirstPaymentPerc: t.Value, tbxFirstPaymentPerc: t.Number,
tbxFirstPaymentRub: t.Value, tbxFirstPaymentRub: t.Number,
tbxLastPaymentPerc: t.Value, tbxLastPaymentPerc: t.Number,
tbxLastPaymentRub: t.Value, tbxLastPaymentRub: t.Number,
selectImportProgram: t.Options, selectImportProgram: t.Options,
tbxImportProgramSum: t.Readonly, tbxImportProgramSum: t.Readonly,
tbxAddEquipmentPrice: t.Value, tbxAddEquipmentPrice: t.Number,
tbxRedemptionPaymentSum: t.Value, tbxRedemptionPaymentSum: t.Number,
tbxParmentsDecreasePercent: t.Value, tbxParmentsDecreasePercent: t.Number,
tbxComissionPerc: t.Value, tbxComissionPerc: t.Number,
tbxComissionRub: t.Value, tbxComissionRub: t.Number,
tbxSaleBonus: t.Value, tbxSaleBonus: t.Number,
tbxIRR_Perc: t.Value, tbxIRR_Perc: t.Number,
tbxLeaseObjectCount: t.Value, tbxLeaseObjectCount: t.Number,
cbxWithTrailer: t.Value, cbxWithTrailer: t.Check,
cbxLeaseObjectUsed: t.Value, cbxLeaseObjectUsed: t.Check,
tbxMaxMass: t.Value, tbxMaxMass: t.Number,
tbxCountSeats: t.Value, tbxCountSeats: t.Number,
tbxMaxSpeed: t.Value, tbxMaxSpeed: t.Number,
tbxLeaseObjectYear: t.Value, tbxLeaseObjectYear: t.Number,
tbxLeaseObjectMotorPower: t.Value, tbxLeaseObjectMotorPower: t.Number,
tbxEngineVolume: t.Value, tbxEngineVolume: t.Number,
tbxDealerRewardSumm: t.Value, tbxDealerRewardSumm: t.Number,
tbxDealerBrokerRewardSumm: t.Value, tbxDealerBrokerRewardSumm: t.Number,
tbxIndAgentRewardSumm: t.Value, tbxIndAgentRewardSumm: t.Number,
tbxCalcDoubleAgentRewardSumm: t.Value, tbxCalcDoubleAgentRewardSumm: t.Number,
tbxCalcBrokerRewardSum: t.Value, tbxCalcBrokerRewardSum: t.Number,
tbxFinDepartmentRewardSumm: t.Value, tbxFinDepartmentRewardSumm: t.Number,
cbxInsDecentral: t.Value, cbxInsDecentral: t.Check,
tbxInsFranchise: t.Value, tbxInsFranchise: t.Number,
cbxInsUnlimitDrivers: t.Value, cbxInsUnlimitDrivers: t.Check,
tbxInsAgeDrivers: t.Value, tbxInsAgeDrivers: t.Number,
tbxInsExpDrivers: t.Value, tbxInsExpDrivers: t.Number,
cbxLastPaymentRedemption: t.Value, cbxLastPaymentRedemption: t.Check,
cbxPriceWithDiscount: t.Value, cbxPriceWithDiscount: t.Check,
cbxFullPriceWithDiscount: t.Value, cbxFullPriceWithDiscount: t.Check,
cbxCostIncrease: t.Value, cbxCostIncrease: t.Check,
cbxInsurance: t.Value, cbxInsurance: t.Check,
cbxRegistrationQuote: t.Value, cbxRegistrationQuote: t.Check,
cbxTechnicalCardQuote: t.Value, cbxTechnicalCardQuote: t.Check,
cbxNSIB: t.Value, cbxNSIB: t.Check,
tbxQuoteName: t.Value, tbxQuoteName: t.Value,
cbxQuoteRedemptionGraph: t.Value, cbxQuoteRedemptionGraph: t.Check,
cbxShowFinGAP: t.Value, cbxShowFinGAP: t.Check,
tbxCreditRate: t.Value, tbxCreditRate: t.Number,
tbxMaxPriceChange: t.Value, tbxMaxPriceChange: t.Number,
tbxImporterRewardPerc: t.Value, tbxImporterRewardPerc: t.Number,
tbxImporterRewardRub: t.Value, tbxImporterRewardRub: t.Number,
cbxDisableChecks: t.Value, cbxDisableChecks: t.Check,
tbxMileage: t.Value, tbxMileage: t.Number,
tbxTotalPayments: t.Value, tbxTotalPayments: t.Number,
tbxVehicleTaxInYear: t.Value, tbxVehicleTaxInYear: t.Number,
tbxVehicleTaxInLeasingPeriod: t.Value, tbxVehicleTaxInLeasingPeriod: t.Number,
tbxMinPriceChange: t.Value, tbxMinPriceChange: t.Number,
selectProduct: t.Options, selectProduct: t.Options,
selectClientRisk: t.Options, selectClientRisk: t.Options,
@ -163,7 +179,7 @@ const types = wrapElementsTypes({
selectLeasingWithoutKasko: t.Options, selectLeasingWithoutKasko: t.Options,
tbxVIN: t.Value, tbxVIN: t.Value,
selectUser: t.Options, selectUser: t.Options,
cbxSupplierFinancing: t.Value, cbxSupplierFinancing: t.Check,
labelLeaseObjectRisk: t.Readonly, labelLeaseObjectRisk: t.Readonly,
tbxInsKaskoPriceLeasePeriod: t.Readonly, tbxInsKaskoPriceLeasePeriod: t.Readonly,
@ -176,10 +192,10 @@ const types = wrapElementsTypes({
btnCreateKPMini: t.Action, btnCreateKPMini: t.Action,
btnCalculate: t.Action, btnCalculate: t.Action,
linkDownloadKp: t.Readonly, linkDownloadKp: t.Link,
linkLeadUrl: t.Readonly, linkLeadUrl: t.Link,
linkOpportunityUrl: t.Readonly, linkOpportunityUrl: t.Link,
linkQuoteUrl: t.Readonly, linkQuoteUrl: t.Link,
}); });
export default types; export default types;

View File

@ -18,6 +18,10 @@ const Grid = styled(Box)`
} }
`; `;
const Wrapper = styled.div`
margin-bottom: 18px;
`;
const Results = observer(() => { const Results = observer(() => {
const { $results, $process } = useStore(); const { $results, $process } = useStore();
@ -38,10 +42,12 @@ const Results = observer(() => {
const value = formatter(storeValue); const value = formatter(storeValue);
return ( return (
<Container key={valueName}> <Wrapper key={valueName}>
<Head title={titles[valueName]} /> <Container key={valueName}>
<Text>{value}</Text> <Head title={titles[valueName]} />
</Container> <Text>{value}</Text>
</Container>
</Wrapper>
); );
})} })}
</Grid> </Grid>

View File

@ -1,10 +1,9 @@
import type { CalculationStatuses } from './types'; import type { CalculationStatuses, Status } from './types';
import type { Elements as ElementsActions } from '@/Components/Calculation/config/map/actions'; import type { Elements as ElementsActions } from '@/Components/Calculation/config/map/actions';
import type { Elements as ElementsValues } from '@/Components/Calculation/config/map/values'; import type { Elements as ElementsValues } from '@/Components/Calculation/config/map/values';
import defaultStatuses from '@/config/default-statuses'; import defaultStatuses from '@/config/default-statuses';
import type RootStore from '@/stores/root'; import type RootStore from '@/stores/root';
import { makeAutoObservable } from 'mobx'; import { makeAutoObservable } from 'mobx';
import type { Status } from 'ui/elements/types';
export default class StatusStore { export default class StatusStore {
private root: RootStore; private root: RootStore;

View File

@ -1,5 +1,6 @@
import type { Elements as ElementsActions } from '@/Components/Calculation/config/map/actions'; import type { Elements as ElementsActions } from '@/Components/Calculation/config/map/actions';
import type { Elements as ElementsValues } from '@/Components/Calculation/config/map/values'; import type { Elements as ElementsValues } from '@/Components/Calculation/config/map/values';
import type { Status } from 'ui/elements/types';
export type Status = 'Default' | 'Disabled' | 'Hidden' | 'Loading';
export type CalculationStatuses = Record<ElementsActions | ElementsValues, Status>; export type CalculationStatuses = Record<ElementsActions | ElementsValues, Status>;

View File

@ -1,6 +1,12 @@
import type { Elements } from '@/Components/Calculation/config/map/values';
import { useStore } from '@/stores/hooks'; import { useStore } from '@/stores/hooks';
import type { ComponentProps, ReactNode } from 'react';
import type { Form } from 'ui/elements';
export function useValidation(elementName) { export function useValidation(elementName: Elements): {
help: ReactNode;
validateStatus: ComponentProps<(typeof Form)['Item']>['validateStatus'];
} {
const { $calculation, $process } = useStore(); const { $calculation, $process } = useStore();
const hasErrors = $calculation.$validation?.[elementName]?.hasErrors; const hasErrors = $calculation.$validation?.[elementName]?.hasErrors;
if (hasErrors) { if (hasErrors) {
@ -11,6 +17,7 @@ export function useValidation(elementName) {
} }
return { return {
help: '',
validateStatus: '', validateStatus: '',
}; };
} }

View File

@ -1,10 +1,10 @@
import Validation from '../../validation'; import Validation from '../../validation';
import type { ValidationParams } from '../../validation/types'; import type { ValidationParams } from '../../validation/types';
import type { Row } from './types'; import type { Row } from './types';
import type { Status } from '@/stores/calculation/statuses/types';
import type RootStore from '@/stores/root'; import type RootStore from '@/stores/root';
import type { IObservableArray, IObservableValue } from 'mobx'; import type { IObservableArray, IObservableValue } from 'mobx';
import { makeAutoObservable, observable, reaction } from 'mobx'; import { makeAutoObservable, observable, reaction } from 'mobx';
import type { Status } from 'ui/elements/types';
export default class PaymentsTable { export default class PaymentsTable {
private root: RootStore; private root: RootStore;

View File

@ -1,4 +1,4 @@
import type { Status } from 'ui/elements/types'; import type { Status } from '@/stores/calculation/statuses/types';
export type Row = { export type Row = {
status: Status; status: Status;

View File

@ -1 +0,0 @@
export * from 'antd';

View File

@ -1,31 +0,0 @@
import type { BaseElementProps } from './types';
import { Button as AntButton } from 'antd';
import type { BaseButtonProps } from 'antd/lib/button/button';
import type { FC } from 'react';
import { useThrottledCallback } from 'use-debounce';
type ElementProps = {
action: () => void;
text: string;
};
type ButtonProps = BaseButtonProps & Pick<ElementProps, 'text'>;
function Button({ status, action, text, ...props }: BaseElementProps<never> & ElementProps) {
const throttledAction = useThrottledCallback(action, 1200, {
trailing: false,
});
return (
<AntButton
disabled={status === 'Disabled'}
loading={status === 'Loading'}
onClick={throttledAction}
{...props}
>
{text}
</AntButton>
);
}
export default Button as FC<ButtonProps>;

View File

@ -1,42 +0,0 @@
import type { BaseElementProps } from './types';
import type { CheckboxProps as AntCheckboxProps } from 'antd';
import { Checkbox as AntCheckbox, Form } from 'antd';
import type { CheckboxChangeEvent } from 'antd/lib/checkbox';
import type { FC } from 'react';
const { Item: FormItem } = Form;
type ElementProps = {
text: string;
};
type CheckboxProps = AntCheckboxProps & ElementProps;
function Checkbox({
value,
setValue,
status,
validateStatus,
help,
text,
...props
}: BaseElementProps<boolean> & ElementProps) {
function handleChange(event: CheckboxChangeEvent) {
setValue(event.target.checked);
}
return (
<FormItem help={help} validateStatus={validateStatus}>
<AntCheckbox
checked={value}
disabled={status === 'Disabled'}
onChange={handleChange}
{...props}
>
{text}
</AntCheckbox>
</FormItem>
);
}
export default Checkbox as FC<CheckboxProps>;

View File

@ -1,27 +0,0 @@
import type { BaseElementProps } from './types';
import type { InputProps } from 'antd';
import { Form, Input as AntInput } from 'antd';
import type { ChangeEvent, FC } from 'react';
const { Item: FormItem } = Form;
function Input({
value,
setValue,
status,
validateStatus,
help,
...props
}: BaseElementProps<string>) {
function handleChange(event: ChangeEvent<HTMLInputElement>) {
setValue(event.target.value);
}
return (
<FormItem hasFeedback help={help} validateStatus={validateStatus}>
<AntInput disabled={status === 'Disabled'} onChange={handleChange} value={value} {...props} />
</FormItem>
);
}
export default Input as FC<InputProps>;

View File

@ -1,43 +1,6 @@
import type { BaseElementProps } from './types'; import type { InputNumberProps } from 'antd';
import type { InputNumberProps as AntInputNumberProps } from 'antd';
import { Form, InputNumber as AntInputNumber } from 'antd';
import type { FC } from 'react';
const { Item: FormItem } = Form; type Formatter = NonNullable<InputNumberProps['formatter']>;
type InputNumberProps = AntInputNumberProps<number>;
function InputNumber({
setValue,
status,
validateStatus,
help,
...props
}: BaseElementProps<number>) {
function handleChange(value: number | null) {
if (value) {
setValue(value);
} else {
setValue(0);
}
}
return (
<FormItem help={help} validateStatus={validateStatus}>
<AntInputNumber
disabled={status === 'Disabled'}
onChange={handleChange}
// eslint-disable-next-line react/forbid-component-props
style={{
width: '100%',
}}
{...props}
/>
</FormItem>
);
}
export default InputNumber as FC<InputNumberProps>;
export function createFormatter(options: Intl.NumberFormatOptions) { export function createFormatter(options: Intl.NumberFormatOptions) {
const format = Intl.NumberFormat('ru', options).format; const format = Intl.NumberFormat('ru', options).format;
@ -46,12 +9,12 @@ export function createFormatter(options: Intl.NumberFormatOptions) {
return ((value, { userTyping }) => { return ((value, { userTyping }) => {
if (userTyping) { if (userTyping) {
if (options.minimumFractionDigits && options.minimumFractionDigits <= 2) { if (options.minimumFractionDigits && options.minimumFractionDigits <= 2) {
return defaultFormat(value || 0); return defaultFormat((value || 0) as number);
} }
return value || 0; return value || 0;
} }
return format(value || 0); return format((value || 0) as number);
}) as NonNullable<InputNumberProps['formatter']>; }) as Formatter;
} }

View File

@ -1,31 +1,18 @@
import type { BaseElementProps } from './types'; import type { ButtonProps } from 'antd';
import { Button as AntButton } from 'antd'; import { Button as AntButton } from 'antd';
import type { BaseButtonProps } from 'antd/lib/button/button';
import type { FC } from 'react';
type ElementProps = { export default function Link({ href, ...props }: ButtonProps) {
text: string;
};
type LinkProps = BaseButtonProps & ElementProps;
function Link({ value, status, text, ...props }: BaseElementProps<string> & ElementProps) {
return ( return (
<AntButton <AntButton
disabled={status === 'Disabled' || !value}
// href={value}
loading={status === 'Loading'}
rel="noopener" rel="noopener"
target="_blank" target="_blank"
type="link" type="link"
onClick={() => { onClick={() => {
window.open(value, '_blank')?.focus(); window.open(href, '_blank')?.focus();
}} }}
{...props} {...props}
> >
{text} {props.children}
</AntButton> </AntButton>
); );
} }
export default Link as FC<LinkProps>;

View File

@ -1,51 +1,34 @@
import type { BaseElementProps, BaseOption } from './types';
import type { RadioChangeEvent, RadioGroupProps, SpaceProps } from 'antd'; import type { RadioChangeEvent, RadioGroupProps, SpaceProps } from 'antd';
import { Form, Radio as AntRadio, Space } from 'antd'; import { Radio as AntRadio, Space } from 'antd';
import type { FC } from 'react'; import type { CheckboxOptionType } from 'antd/lib/checkbox';
import type { Key } from 'react';
const { Item: FormItem } = Form; type RadioProps = Omit<RadioGroupProps, 'onChange' | 'options'> & {
onChange?: (value: unknown) => void;
type ElementProps = BaseElementProps<string | null> & { options?: CheckboxOptionType[];
options: BaseOption[];
spaceProps?: SpaceProps; spaceProps?: SpaceProps;
}; };
type RadioProps = RadioGroupProps & { export default function Radio({
spaceProps?: SpaceProps;
};
function Radio({
value = null, value = null,
setValue,
options, options,
status,
validateStatus,
help,
spaceProps, spaceProps,
onChange,
...props ...props
}: ElementProps) { }: RadioProps) {
function handleChange(event: RadioChangeEvent) { function handleChange(event: RadioChangeEvent) {
setValue(event.target.value); if (onChange) onChange(event.target.value);
} }
return ( return (
<FormItem help={help} validateStatus={validateStatus}> <AntRadio.Group onChange={handleChange} value={value} {...props}>
<AntRadio.Group <Space {...spaceProps}>
disabled={status === 'Disabled'} {options?.map((option) => (
onChange={handleChange} <AntRadio key={option.value as Key} value={option.value}>
value={value} {option.label}
{...props} </AntRadio>
> ))}
<Space {...spaceProps}> </Space>
{options.map((option) => ( </AntRadio.Group>
<AntRadio key={option.value} value={option.value}>
{option.label}
</AntRadio>
))}
</Space>
</AntRadio.Group>
</FormItem>
); );
} }
export default Radio as FC<RadioProps>;

View File

@ -1,36 +1,10 @@
import type { BaseElementProps, BaseOption } from './types';
import type { SegmentedProps } from 'antd'; import type { SegmentedProps } from 'antd';
import { Form, Segmented as AntSegmented } from 'antd'; import { Segmented as AntSegmented } from 'antd';
import type { FC } from 'react';
const { Item: FormItem } = Form; type ElementProps = Omit<SegmentedProps, 'options' | 'ref'> & {
options?: SegmentedProps['options'];
type ElementProps = BaseElementProps<number | string> & {
options: BaseOption[];
}; };
function Segmented({ export default function Segmented({ options = [], ...props }: ElementProps) {
value, return <AntSegmented {...props} options={options} />;
setValue,
options,
status,
validateStatus,
help,
...props
}: ElementProps) {
return (
<FormItem help={help} validateStatus={validateStatus}>
<AntSegmented
disabled={status === 'Disabled'}
onChange={setValue}
onResize={undefined}
onResizeCapture={undefined}
options={options}
value={value}
{...props}
/>
</FormItem>
);
} }
export default Segmented as FC<Partial<SegmentedProps>>;

View File

@ -1,24 +1,8 @@
import type { BaseElementProps, BaseOption } from './types';
import type { SelectProps } from 'antd'; import type { SelectProps } from 'antd';
import { Form, Select as AntSelect } from 'antd'; import { Select as AntSelect } from 'antd';
import type { FC } from 'react';
import { useMemo } from 'react'; import { useMemo } from 'react';
const { Item: FormItem } = Form; export default function Select({ options = [], ...props }: SelectProps<string | null>) {
type ElementProps = {
options: BaseOption[];
};
function Select({
value = null,
setValue,
options = [],
status,
validateStatus,
help,
...props
}: BaseElementProps<string | null> & ElementProps) {
const optionsWithNull = useMemo( const optionsWithNull = useMemo(
() => [ () => [
{ {
@ -30,19 +14,5 @@ function Select({
[options] [options]
); );
return ( return <AntSelect options={optionsWithNull} {...props} />;
<FormItem help={help} validateStatus={validateStatus}>
<AntSelect
disabled={status === 'Disabled'}
loading={status === 'Loading'}
onChange={setValue}
optionFilterProp="children"
options={optionsWithNull}
value={value}
{...props}
/>
</FormItem>
);
} }
export default Select as FC<SelectProps>;

View File

@ -1,23 +0,0 @@
import type { BaseElementProps } from './types';
import type { SwitchProps } from 'antd';
import { Form, Switch as AntSwitch } from 'antd';
import type { FC } from 'react';
const { Item: FormItem } = Form;
function Switch({
value,
setValue,
status,
validateStatus,
help,
...props
}: BaseElementProps<boolean>) {
return (
<FormItem help={help} validateStatus={validateStatus}>
<AntSwitch checked={value} disabled={status === 'Disabled'} onChange={setValue} {...props} />
</FormItem>
);
}
export default Switch as FC<SwitchProps>;

View File

@ -1,19 +1,9 @@
import type { FC, ReactNode } from 'react'; import { Typography } from 'antd';
import styled from 'styled-components'; import type { ComponentProps, ReactNode } from 'react';
const Span = styled.span` export default function Text({
margin-bottom: 18px; value = '',
font-size: 0.85rem; ...props
`; }: ComponentProps<(typeof Typography)['Text']> & { value: ReactNode }) {
return <Typography.Text>{value || props.children}</Typography.Text>;
type TextProps = {
children: ReactNode;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any;
};
function Text({ value, ...props }: TextProps) {
return <Span {...props}>{value || props.children}</Span>;
} }
export default Text as FC<TextProps>;

View File

@ -10,24 +10,25 @@ notification.config({
style: { borderRadius: 2 }, style: { borderRadius: 2 },
}); });
export { default as Button } from './Button';
export { default as Checkbox } from './Checkbox';
export { default as AntdConfig } from './Config'; export { default as AntdConfig } from './Config';
export { default as Input } from './Input';
export { default as InputNumber } from './InputNumber';
export { default as Link } from './Link'; export { default as Link } from './Link';
export { default as Radio } from './Radio'; export { default as Radio } from './Radio';
export { default as Segmented } from './Segmented'; export { default as Segmented } from './Segmented';
export { default as Select } from './Select'; export { default as Select } from './Select';
export { default as Switch } from './Switch';
export { default as Text } from './Text'; export { default as Text } from './Text';
export { export {
Alert, Alert,
Badge, Badge,
Button,
Checkbox,
Divider, Divider,
Form,
Input,
InputNumber,
message, message,
notification, notification,
Result, Result,
Switch,
Table, Table,
Tabs, Tabs,
Tag, Tag,

View File

@ -1,15 +1,3 @@
import type { ValidateStatus } from 'antd/es/form/FormItem';
export type Status = 'Default' | 'Disabled' | 'Hidden' | 'Loading';
export type BaseElementProps<Value> = {
help?: string;
setValue: (value: Value) => void;
status?: Status;
validateStatus?: ValidateStatus;
value: Value;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
export type BaseOption<Value = any> = { export type BaseOption<Value = any> = {
label: string; label: string;