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

fix: declarations of ContentSwitcher, Switch, Slider, SkeletonIcon #15382

Merged
merged 1 commit into from Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,9 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import { ComponentClass } from 'react';
import { createClassWrapper } from '../../internal/createClassWrapper';
import ContentSwitcherCarbon from './ContentSwitcher';
import ContentSwitcherCarbon, { ContentSwitcherProps } from './ContentSwitcher';

const ContentSwitcher = createClassWrapper(ContentSwitcherCarbon);
const ContentSwitcher = createClassWrapper(
ContentSwitcherCarbon as ComponentClass<ContentSwitcherProps>
);
export default ContentSwitcher;
export { ContentSwitcher };
Expand Up @@ -5,22 +5,21 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import React, { ComponentClass, FunctionComponent } from 'react';

/**
* Wrap a class component with a functional component. This prevents an end-user
* from being able to pass `ref` and access the underlying class instance.
*
* @param {ReactNode} Component
* @returns {ReactNode}
*/
export function createClassWrapper(Component) {
export function createClassWrapper<Props>(
Component: ComponentClass<Props>
): FunctionComponent<Props> {
function ClassWrapper(props) {
return <Component {...props} />;
}

const name = Component.displayName || Component.name;
ClassWrapper.displayName = `ClassWrapper(${name})`;

return ClassWrapper;
return ClassWrapper as FunctionComponent<Props>;
}