From c7cc4c806bcfa3d086e40856532a12c2caffb50e Mon Sep 17 00:00:00 2001 From: Bernardo Sunderhus Date: Thu, 8 Sep 2022 15:07:52 +0000 Subject: [PATCH] feat: add helper types to assist DOM element handling --- ...-4fd3fe1f-3f59-48b1-acab-2e459a62c03d.json | 7 +++++++ .../react-aria/etc/react-aria.api.md | 6 ++++++ .../src/hooks/useARIAButton/types.ts | 19 +++++++++++++++++-- .../react-components/react-aria/src/index.ts | 2 ++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 change/@fluentui-react-aria-4fd3fe1f-3f59-48b1-acab-2e459a62c03d.json diff --git a/change/@fluentui-react-aria-4fd3fe1f-3f59-48b1-acab-2e459a62c03d.json b/change/@fluentui-react-aria-4fd3fe1f-3f59-48b1-acab-2e459a62c03d.json new file mode 100644 index 0000000000000..2334b7f180b89 --- /dev/null +++ b/change/@fluentui-react-aria-4fd3fe1f-3f59-48b1-acab-2e459a62c03d.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "feat: add helper types to assist DOM element handling", + "packageName": "@fluentui/react-aria", + "email": "bernardo.sunderhus@gmail.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-components/react-aria/etc/react-aria.api.md b/packages/react-components/react-aria/etc/react-aria.api.md index c9f136db5c050..9450ba46c1e89 100644 --- a/packages/react-components/react-aria/etc/react-aria.api.md +++ b/packages/react-components/react-aria/etc/react-aria.api.md @@ -9,6 +9,12 @@ import * as React_2 from 'react'; import type { ResolveShorthandFunction } from '@fluentui/react-utilities'; import type { Slot } from '@fluentui/react-utilities'; +// @internal (undocumented) +export type ARIAButtonElement = HTMLButtonElement | (AlternateAs extends 'a' ? HTMLAnchorElement : never) | (AlternateAs extends 'div' ? HTMLDivElement : never); + +// @internal (undocumented) +export type ARIAButtonElementIntersection = UnionToIntersection>; + // @public export type ARIAButtonProps = React_2.PropsWithRef & { disabled?: boolean; diff --git a/packages/react-components/react-aria/src/hooks/useARIAButton/types.ts b/packages/react-components/react-aria/src/hooks/useARIAButton/types.ts index f712dcc341a8d..541be29d845f9 100644 --- a/packages/react-components/react-aria/src/hooks/useARIAButton/types.ts +++ b/packages/react-components/react-aria/src/hooks/useARIAButton/types.ts @@ -1,8 +1,25 @@ import type { ExtractSlotProps, Slot } from '@fluentui/react-utilities'; import * as React from 'react'; +type UnionToIntersection = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never; + export type ARIAButtonType = 'button' | 'a' | 'div'; +/** + * @internal + */ +export type ARIAButtonElement = + | HTMLButtonElement + | (AlternateAs extends 'a' ? HTMLAnchorElement : never) + | (AlternateAs extends 'div' ? HTMLDivElement : never); + +/** + * @internal + */ +export type ARIAButtonElementIntersection = UnionToIntersection< + ARIAButtonElement +>; + /** * Props expected by `useARIAButtonProps` hooks */ @@ -48,8 +65,6 @@ export type ARIAButtonAlteredProps = ? Pick : never); -type UnionToIntersection = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never; - /** * Merge of props provided by the user and props provided internally. */ diff --git a/packages/react-components/react-aria/src/index.ts b/packages/react-components/react-aria/src/index.ts index 31983e05e85be..f5d6693c1789f 100644 --- a/packages/react-components/react-aria/src/index.ts +++ b/packages/react-components/react-aria/src/index.ts @@ -4,4 +4,6 @@ export type { ARIAButtonProps, ARIAButtonResultProps, ARIAButtonType, + ARIAButtonElement, + ARIAButtonElementIntersection, } from './hooks/useARIAButton/index';