Skip to content

Commit

Permalink
refactor: using ReactNode instead of ReactNodeLike (#16418)
Browse files Browse the repository at this point in the history
* refactor: using reactnode instead of reactnodelike

* refactor: changed reactelementlike to reactelement
  • Loading branch information
Gururajj77 committed May 13, 2024
1 parent 8293f95 commit 7171531
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/components/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Add, Subtract } from '@carbon/icons-react';
import cx from 'classnames';
import PropTypes, { ReactNodeLike } from 'prop-types';
import PropTypes from 'prop-types';
import React, {
ReactNode,
useContext,
Expand Down Expand Up @@ -168,7 +168,7 @@ export interface NumberInputProps
/**
* **Experimental**: Provide a `Slug` component to be rendered inside the `TextInput` component
*/
slug?: ReactNodeLike;
slug?: ReactNode;

/**
* Specify how much the values should increase/decrease upon clicking on up/down button
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/components/RadioButton/RadioButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import PropTypes, { ReactNodeLike } from 'prop-types';
import React, { useRef } from 'react';
import PropTypes from 'prop-types';
import React, { ReactNode, useRef } from 'react';
import classNames from 'classnames';
import { Text } from '../Text';
import { usePrefix } from '../../internal/usePrefix';
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface RadioButtonProps
* Provide label text to be read by screen readers when interacting with the
* control
*/
labelText: ReactNodeLike;
labelText: ReactNode;

/**
* Provide a name for the underlying `<input>` node
Expand All @@ -85,7 +85,7 @@ export interface RadioButtonProps
/**
* **Experimental**: Provide a `Slug` component to be rendered inside the `RadioButton` component
*/
slug?: ReactNodeLike;
slug?: ReactNode;

/**
* Specify the value of the `<RadioButton>`
Expand Down
28 changes: 17 additions & 11 deletions packages/react/src/components/RadioButtonGroup/RadioButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

import PropTypes, { ReactElementLike, ReactNodeLike } from 'prop-types';
import React, { createContext, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import React, {
createContext,
ReactElement,
ReactNode,
useRef,
useState,
} from 'react';
import classNames from 'classnames';
import { Legend } from '../Text';
import { usePrefix } from '../../internal/usePrefix';
Expand All @@ -28,7 +34,7 @@ export interface RadioButtonGroupProps
/**
* Provide a collection of `<RadioButton>` components to render in the group
*/
children?: ReactNodeLike;
children?: ReactNode;

/**
* Provide an optional className to be applied to the container node
Expand All @@ -48,7 +54,7 @@ export interface RadioButtonGroupProps
/**
* Provide text that is used alongside the control label for additional help
*/
helperText?: ReactNodeLike;
helperText?: ReactNode;

/**
* Specify whether the control is currently invalid
Expand All @@ -58,7 +64,7 @@ export interface RadioButtonGroupProps
/**
* Provide the text that is displayed when the control is in an invalid state
*/
invalidText?: ReactNodeLike;
invalidText?: ReactNode;

/**
* Provide where label text should be placed
Expand All @@ -69,7 +75,7 @@ export interface RadioButtonGroupProps
* Provide a legend to the RadioButtonGroup input that you are
* exposing to the user
*/
legendText?: ReactNodeLike;
legendText?: ReactNode;

/**
* Specify the name of the underlying `<input>` nodes
Expand Down Expand Up @@ -98,7 +104,7 @@ export interface RadioButtonGroupProps
/**
* **Experimental**: Provide a `Slug` component to be rendered inside the `RadioButtonGroup` component
*/
slug?: ReactNodeLike;
slug?: ReactNode;

/**
* Specify whether the control is currently in warning state
Expand All @@ -108,7 +114,7 @@ export interface RadioButtonGroupProps
/**
* Provide the text that is displayed when the control is in warning state
*/
warnText?: ReactNodeLike;
warnText?: ReactNode;

/**
* Specify the value that is currently selected in the group
Expand Down Expand Up @@ -161,7 +167,7 @@ const RadioButtonGroup = React.forwardRef(

function getRadioButtons() {
const mappedChildren = React.Children.map(children, (radioButton) => {
const { value } = (radioButton as ReactElementLike)?.props ?? undefined;
const { value } = (radioButton as ReactElement)?.props ?? undefined;

const newProps = {
name: name,
Expand All @@ -172,11 +178,11 @@ const RadioButtonGroup = React.forwardRef(
required: required,
};

if (!selected && (radioButton as ReactElementLike)?.props.checked) {
if (!selected && (radioButton as ReactElement)?.props.checked) {
newProps.checked = true;
}
if (radioButton) {
return React.cloneElement(radioButton as ReactElementLike, newProps);
return React.cloneElement(radioButton as ReactElement, newProps);
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import PropTypes, { ReactNodeLike } from 'prop-types';
import PropTypes from 'prop-types';
import React, {
ChangeEventHandler,
ComponentPropsWithRef,
Expand Down Expand Up @@ -122,7 +122,7 @@ interface SelectProps
/**
* **Experimental**: Provide a `Slug` component to be rendered inside the `Dropdown` component
*/
slug?: ReactNodeLike;
slug?: ReactNode;

/**
* Specify whether the control is currently in warning state
Expand Down
14 changes: 9 additions & 5 deletions packages/react/src/components/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { type KeyboardEventHandler, PureComponent } from 'react';
import PropTypes, { ReactNodeLike } from 'prop-types';
import React, {
type KeyboardEventHandler,
PureComponent,
ReactNode,
} from 'react';
import PropTypes from 'prop-types';

import classNames from 'classnames';
import throttle from 'lodash.throttle';
Expand Down Expand Up @@ -136,7 +140,7 @@ export interface SliderProps
/**
* The child nodes.
*/
children?: ReactNodeLike;
children?: ReactNode;

/**
* The CSS class name for the slider, set on the wrapping div.
Expand Down Expand Up @@ -176,12 +180,12 @@ export interface SliderProps
/**
* Provide the text that is displayed when the Slider is in an invalid state
*/
invalidText?: React.ReactNode;
invalidText?: ReactNode;

/**
* The label for the slider.
*/
labelText?: ReactNodeLike;
labelText?: ReactNode;

/**
* @deprecated
Expand Down

0 comments on commit 7171531

Please sign in to comment.