Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add typescript types to togglesmall and portal #17712

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@
* LICENSE file in the root directory of this source tree.
*/

import PropTypes from 'prop-types';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Portal isn't within /internal but isn't exported, so I agree removing proptypes is a good option here 👍

import { useEffect, useState } from 'react';
import React, { useEffect, useState, ReactNode } from 'react';
import ReactDOM from 'react-dom';

interface PortalProps {
/**
* Specify the children elements to be rendered inside of the <Portal>
*/
children: ReactNode;
/**
* Provide a ref for a container node to render the portal
*/
container?: React.RefObject<HTMLElement>;
}

/**
* Helper component for rendering content within a portal. By default, the
* portal will render into document.body. You can customize this behavior with
* the `container` prop. Any `children` provided to this component will be
* rendered inside of the container.
*/
function Portal({ container, children }) {
const [mountNode, setMountNode] = useState(null);
function Portal({
container,
children,
}: PortalProps): React.ReactPortal | null {
const [mountNode, setMountNode] = useState<HTMLElement | null>(null);

useEffect(() => {
setMountNode(container ? container.current : document.body);
Expand All @@ -29,20 +42,4 @@ function Portal({ container, children }) {
return null;
}

Portal.propTypes = {
/**
* Specify the children elements to be rendered inside of the <Portal>
*/
children: PropTypes.node,

/**
* Provide a ref for a container node to render the portal
*/
container: PropTypes.oneOfType([
PropTypes.shape({
current: PropTypes.any,
}),
]),
};

export { Portal };
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,33 @@
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import PropTypes from 'prop-types';
import React from 'react';
import cx from 'classnames';
import { PrefixContext } from '../../internal/usePrefix';

class ToggleSmallSkeleton extends React.Component {
interface ToggleSmallSkeletonProps {
['aria-label']: string;
/**
* Specify an optional className to add to the form item wrapper.
*/
className?: string;
/**
* Provide an id that unique represents the underlying `<input>`
*/
id?: string;
/**
* Provide the text that will be read by a screen reader when visiting this
* control
* `aria-label` is always required but will be null if `labelText` is also
* provided
*/
labelText?: string;
}

class ToggleSmallSkeleton extends React.Component<ToggleSmallSkeletonProps> {
static propTypes = {
['aria-label']: PropTypes.string.isRequired,

/**
* Specify an optional className to add to the form item wrapper.
*/
Expand All @@ -22,7 +39,6 @@ class ToggleSmallSkeleton extends React.Component {
* Provide an id that unique represents the underlying `<input>`
*/
id: PropTypes.string,

/**
* Provide the text that will be read by a screen reader when visiting this
* control
Expand All @@ -44,7 +60,6 @@ class ToggleSmallSkeleton extends React.Component {
id={id}
className={`${prefix}--toggle ${prefix}--toggle--small ${prefix}--skeleton`}
/>

<label
className={`${prefix}--toggle__label ${prefix}--skeleton`}
htmlFor={id}>
Expand Down
Loading