Skip to content

Commit

Permalink
refactor: Added types to TableActionList and wrapComponent (#15689)
Browse files Browse the repository at this point in the history
* refactor: added types to TableActionList and wrapComponent

* chore: type ReactNode to ReactElement

* chore: className should be optional in wrapComponent

* chore: changed imports

* chore: fixed type error

---------

Co-authored-by: TJ Egan <tw15egan@gmail.com>
  • Loading branch information
imp-dance and tw15egan committed Feb 21, 2024
1 parent 74924c5 commit b738b35
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/components/DataTable/TableHead.tsx
Expand Up @@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { ThHTMLAttributes } from 'react';
import { ThHTMLAttributes } from 'react';
import wrapComponent from '../../tools/wrapComponent';

export type TableHeadProps = ThHTMLAttributes<HTMLTableSectionElement>;

const TableHead: React.FC<TableHeadProps> = wrapComponent({
const TableHead = wrapComponent({
name: 'TableHead',
type: 'thead',
});
Expand Down
Expand Up @@ -5,16 +5,29 @@
* LICENSE file in the root directory of this source tree.
*/

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

type HTMLTagName = keyof HTMLElementTagNameMap;

type WrapComponentArgs<T extends HTMLTagName> = {
name: string;
type: T;
className?: string | ((prefix: string) => string);
};

/**
* @param {{ name: string, type: string, className?: string | (prefix: string) => string }} props
* @returns
*/
const wrapComponent = ({ name, className: getClassName, type }) => {
const wrapComponent = <T extends HTMLTagName>({
name,
className: getClassName,
type,
}: WrapComponentArgs<T>): ((props: ReactAttr<T>) => React.ReactElement) => {
/**
*
* @param {{ className?: string, [x: string]: any}} param0
Expand All @@ -41,7 +54,7 @@ const wrapComponent = ({ name, className: getClassName, type }) => {
className: PropTypes.string,
};

return Component;
return Component as (props: ReactAttr<T>) => React.ReactElement;
};

export default wrapComponent;

0 comments on commit b738b35

Please sign in to comment.