ant-design/components/_util/getAllowClear.tsx
Eden Wang 28aaeafbbc
feat(mentions): supports 'allowClear' option (#46396)
* feat(mentions): supports 'allowClear' option

* feat(mentions): add allowClear testcase

* feat(mentions): update package and styles

* feat(mentions): update lint and styles

* fix: fixed lint error

* test: add case for custom clearIcon

* feat: add useAllowClear hook

* feat: rename useAllowClear to getAllowClear

* feat: rename useAllowClear to getAllowClear

* feat(mentions): add demo for allowClear

* feat(mentions): update demo desc

* feat(mentions): update demo desc

* feat(mentions): style align middle

* feat: add multi line mentions demo and update icon position

* feat: fixing visual regression report

---------

Co-authored-by: afc163 <afc163@gmail.com>
2023-12-25 10:37:26 +08:00

21 lines
580 B
TypeScript

import React from 'react';
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
import type { BaseInputProps } from 'rc-input/lib/interface';
export type AllowClear = BaseInputProps['allowClear'];
const getAllowClear = (allowClear: AllowClear): AllowClear => {
let mergedAllowClear: AllowClear;
if (typeof allowClear === 'object' && allowClear?.clearIcon) {
mergedAllowClear = allowClear;
} else if (allowClear) {
mergedAllowClear = {
clearIcon: <CloseCircleFilled />,
};
}
return mergedAllowClear;
};
export default getAllowClear;