From a96c72621a6c35927f0683d8701c1103883ca9e8 Mon Sep 17 00:00:00 2001 From: garrettbear Date: Thu, 20 Jul 2023 13:46:05 -0700 Subject: [PATCH] label TS updates --- .../label/__snapshots__/label.test.js.snap | 11 ---- .../label/__snapshots__/label.test.tsx.snap | 2 +- .../component-library/label/index.ts | 2 +- .../component-library/label/label.js | 44 -------------- .../component-library/label/label.tsx | 58 ++++++++++--------- .../component-library/label/label.types.ts | 12 +++- 6 files changed, 43 insertions(+), 86 deletions(-) delete mode 100644 ui/components/component-library/label/__snapshots__/label.test.js.snap delete mode 100644 ui/components/component-library/label/label.js diff --git a/ui/components/component-library/label/__snapshots__/label.test.js.snap b/ui/components/component-library/label/__snapshots__/label.test.js.snap deleted file mode 100644 index e2d20a61feff..000000000000 --- a/ui/components/component-library/label/__snapshots__/label.test.js.snap +++ /dev/null @@ -1,11 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`label should render text inside the label 1`] = ` -
- -
-`; diff --git a/ui/components/component-library/label/__snapshots__/label.test.tsx.snap b/ui/components/component-library/label/__snapshots__/label.test.tsx.snap index f72fcd1f742d..e2d20a61feff 100644 --- a/ui/components/component-library/label/__snapshots__/label.test.tsx.snap +++ b/ui/components/component-library/label/__snapshots__/label.test.tsx.snap @@ -3,7 +3,7 @@ exports[`label should render text inside the label 1`] = `
diff --git a/ui/components/component-library/label/index.ts b/ui/components/component-library/label/index.ts index c2db3927398e..1a984b62cd71 100644 --- a/ui/components/component-library/label/index.ts +++ b/ui/components/component-library/label/index.ts @@ -1,2 +1,2 @@ export { Label } from './label'; -export type { LabelProps } from './label.types'; +export type { LabelComponent, LabelProps } from './label.types'; diff --git a/ui/components/component-library/label/label.js b/ui/components/component-library/label/label.js deleted file mode 100644 index 7eca591b224e..000000000000 --- a/ui/components/component-library/label/label.js +++ /dev/null @@ -1,44 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classnames from 'classnames'; -import { - FontWeight, - TextVariant, - Display, - AlignItems, -} from '../../../helpers/constants/design-system'; -import { Text } from '..'; - -export const Label = ({ htmlFor, className, children, ...props }) => ( - - {children} - -); - -Label.propTypes = { - /** - * The content of the label - */ - children: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), - /** - * The id of the input associated with the label - */ - htmlFor: PropTypes.string, - /** - * Additional classNames to be added to the label component - */ - className: PropTypes.string, -}; diff --git a/ui/components/component-library/label/label.tsx b/ui/components/component-library/label/label.tsx index ec4b751dd3ee..4b7cd6e3a1b8 100644 --- a/ui/components/component-library/label/label.tsx +++ b/ui/components/component-library/label/label.tsx @@ -1,35 +1,39 @@ -import React, { Ref, forwardRef } from 'react'; +import React from 'react'; import classnames from 'classnames'; -import { Text, ValidTag } from '../text'; +import { Text } from '../text'; +import type { TextProps } from '../text'; import { FontWeight, TextVariant, Display, AlignItems, } from '../../../helpers/constants/design-system'; -import { LabelProps } from './label.types'; +import type { PolymorphicRef } from '../box'; +import { LabelProps, LabelComponent } from './label.types'; -export const Label = forwardRef(function Label( - { htmlFor, className, children, ...props }: LabelProps, - ref: Ref, -) { - return ( - - {children} - - ); -}); +export const Label: LabelComponent = React.forwardRef( + ( + { htmlFor, className, children, ...props }: LabelProps, + ref?: PolymorphicRef, + ) => { + return ( + )} + > + {children} + + ); + }, +); diff --git a/ui/components/component-library/label/label.types.ts b/ui/components/component-library/label/label.types.ts index 96065e2d0d71..8f897e4450b7 100644 --- a/ui/components/component-library/label/label.types.ts +++ b/ui/components/component-library/label/label.types.ts @@ -1,6 +1,7 @@ -import { TextProps } from '../text'; +import type { PolymorphicComponentPropWithRef } from '../box'; +import type { TextStyleUtilityProps } from '../text'; -export interface LabelProps extends TextProps { +export interface LabelStyleUtilityProps extends TextStyleUtilityProps { /** * The id of the input associated with the label */ @@ -14,3 +15,10 @@ export interface LabelProps extends TextProps { */ children: string | React.ReactNode; } + +export type LabelProps = + PolymorphicComponentPropWithRef; + +export type LabelComponent = ( + props: LabelProps, +) => React.ReactElement | null;