useClosable.d.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type { ReactNode } from 'react';
  2. import React from 'react';
  3. import type { DialogProps } from 'rc-dialog';
  4. import type { HTMLAriaDataAttributes } from '../aria-data-attrs';
  5. export type ClosableType = DialogProps['closable'];
  6. export type BaseContextClosable = {
  7. closable?: ClosableType;
  8. closeIcon?: ReactNode;
  9. };
  10. export type ContextClosable<T extends BaseContextClosable = any> = Partial<Pick<T, 'closable' | 'closeIcon'>>;
  11. export declare function pickClosable<T extends BaseContextClosable>(context?: ContextClosable<T>): ContextClosable<T> | undefined;
  12. export type UseClosableParams = {
  13. closable?: ClosableType;
  14. closeIcon?: ReactNode;
  15. defaultClosable?: boolean;
  16. defaultCloseIcon?: ReactNode;
  17. customCloseIconRender?: (closeIcon: ReactNode) => ReactNode;
  18. context?: ContextClosable;
  19. };
  20. /** Collection contains the all the props related with closable. e.g. `closable`, `closeIcon` */
  21. interface ClosableCollection {
  22. closable?: ClosableType;
  23. closeIcon?: ReactNode;
  24. }
  25. interface FallbackCloseCollection extends ClosableCollection {
  26. /**
  27. * Some components need to wrap CloseIcon twice,
  28. * this method will be executed once after the final CloseIcon is calculated
  29. */
  30. closeIconRender?: (closeIcon: ReactNode) => ReactNode;
  31. }
  32. export default function useClosable(propCloseCollection?: ClosableCollection, contextCloseCollection?: ClosableCollection | null, fallbackCloseCollection?: FallbackCloseCollection): [
  33. closable: boolean,
  34. closeIcon: React.ReactNode,
  35. closeBtnIsDisabled: boolean,
  36. ariaOrDataProps?: HTMLAriaDataAttributes
  37. ];
  38. export {};