Skip to content

Commit

Permalink
Update to use ReactElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Sana Malik committed Jan 30, 2025
1 parent e2f1044 commit 99cb77e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/@react-spectrum/labeledvalue/docs/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {DateTime, LabeledValueBaseProps} from '@react-spectrum/labeledvalue/src/LabeledValue';
import {RangeValue} from '@react-types/shared';
import {ReactNode} from 'react';
import {ReactElement} from 'react';

// The doc generator is not smart enough to handle the real types for LabeledValue so this is a simpler one.
export interface LabeledValueProps extends LabeledValueBaseProps {
/** The value to display. */
value: string | string[] | number | RangeValue<number> | DateTime | RangeValue<DateTime> | ReactNode,
value: string | string[] | number | RangeValue<number> | DateTime | RangeValue<DateTime> | ReactElement,
/** Formatting options for the value. The available options depend on the type passed to the `value` prop. */
formatOptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | Intl.ListFormatOptions
}
8 changes: 4 additions & 4 deletions packages/@react-spectrum/labeledvalue/src/LabeledValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {DOMProps, DOMRef, RangeValue, SpectrumLabelableProps, StyleProps} f
import {Field} from '@react-spectrum/label';
import {filterDOMProps} from '@react-aria/utils';
import labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';
import React, {ReactNode, useEffect} from 'react';
import React, {ReactElement, ReactNode, useEffect} from 'react';
import {useDateFormatter, useListFormatter, useNumberFormatter} from '@react-aria/i18n';

// NOTE: the types here need to be synchronized with the ones in docs/types.ts, which are simpler so the documentation generator can handle them.
Expand Down Expand Up @@ -58,7 +58,7 @@ interface StringListProps<T extends string[]> {
formatOptions?: Intl.ListFormatOptions
}

interface ReactNodeProps<T extends ReactNode> {
interface ReactElementProps<T extends ReactElement> {
/** The value to display. */
value: T,
/** Formatting options for the value. */
Expand All @@ -70,10 +70,10 @@ type LabeledValueProps<T> =
T extends DateTimeValue ? DateProps<T> :
T extends string[] ? StringListProps<T> :
T extends string ? StringProps<T> :
T extends ReactNode ? ReactNodeProps<T> :
T extends ReactElement ? ReactElementProps<T> :
never;

type SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime> | ReactNode;
type SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime> | ReactElement;
export type SpectrumLabeledValueProps<T> = LabeledValueProps<T> & LabeledValueBaseProps;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ describe('LabeledValue', function () {
expect(staticField).toHaveTextContent('10 – 20');
});

it('renders correctly with ReactNode value', function () {
it('renders correctly with ReactElement value', function () {
let {getByTestId} = render(
<LabeledValue
data-testid="test-id"
Expand Down

0 comments on commit 99cb77e

Please sign in to comment.