ant-design/components/_util/hooks/useVariants.ts
MadCcc 3af521d422
feat: Input/InputNumber/Mentions support filled variant (#46435)
* feat: Input filled variant

* feat: InputNumber filled variant

* feat: mentions variant

* fix: TextArea status with affix

* chore: update snapshot

* chore: update snapshot

* feat: pagination input

* fix: fix diff

* feat: input-number disabled

* fixL InputNumber

* chore: update snapshot

* feat: better style

* chore: update

* chore: update snapshot

* feat: use variant classNames

* chore: update snapshot

* feat: mentions affix style

* chore
2023-12-18 17:53:31 +08:00

29 lines
767 B
TypeScript

type DefaultVariant = 'outlined' | 'borderless';
/**
* Compatible for legacy `bordered` prop.
*/
const useVariant = <T extends string>(
variant: T | undefined,
legacyBordered: boolean | undefined,
variants: readonly (T | DefaultVariant)[],
options?: {
omitOutlined?: boolean;
},
): [T | DefaultVariant, boolean] => {
let mergedVariant: T | DefaultVariant;
if (typeof variant !== 'undefined') {
mergedVariant = variant;
} else if (legacyBordered === false) {
mergedVariant = 'borderless';
} else {
mergedVariant = 'outlined';
}
const enableVariantCls =
variants.includes(mergedVariant) && (!options?.omitOutlined || mergedVariant !== 'outlined');
return [mergedVariant, enableVariantCls];
};
export default useVariant;