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

feat(DataTableSkeleton): 12513 - Add TS types for props #13245

Merged
merged 8 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -20,7 +20,7 @@ const props = () => ({
});

export default {
title: 'Components/DataTable',
title: 'Components/DataTable/Skeleton',
decorators: [withKnobs],
component: DataTableSkeleton,
};
Expand All @@ -34,3 +34,25 @@ export const Skeleton = () => {
</div>
);
};

export const Playground = (args) => {
return (
<div style={{ width: '800px' }}>
<DataTableSkeleton {...args} headers={headers} />
<br />
</div>
);
};

Playground.argTypes = {
headers: {
table: {
disable: true,
},
},
className: {
table: {
disable: true,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@ import React from 'react';
import cx from 'classnames';
import { usePrefix } from '../../internal/usePrefix';

export interface DataTableSkeletonProps {
/**
* Specify an optional className to add.
*/
className?: string;

/**
* Specify the number of columns that you want to render in the skeleton state
*/
columnCount: number;

/**
* Optionally specify whether you want the Skeleton to be rendered as a
* compact DataTable
*/
compact: boolean;

/**
* Optionally specify the displayed headers
*/
headers?: [{ header: string, key: string }] | { header: string, key: string };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pre-existing header type is an array or an object with a key. The object with a key, I do not think is being used. However, to remove it would break the API and require a major version bump. The array itself expects an object with a header.

  headers: PropTypes.oneOfType([
    PropTypes.array,
    PropTypes.shape({
      key: PropTypes.string,
    }),
  ]),


/**
* Specify the number of rows that you want to render in the skeleton state
*/
rowCount: number;

/**
* Specify if the table header should be rendered as part of the skeleton.
*/
showHeader: boolean;

/**
* Specify if the table toolbar should be rendered as part of the skeleton.
*/
showToolbar: boolean;

/**
* Optionally specify whether you want the DataTable to be zebra striped
*/
zebra: boolean;
}

const DataTableSkeleton = ({
headers,
rowCount,
Expand Down Expand Up @@ -48,8 +91,8 @@ const DataTableSkeleton = ({
<div className={`${prefix}--skeleton ${prefix}--data-table-container`}>
{showHeader ? (
<div className={`${prefix}--data-table-header`}>
<div className={`${prefix}--data-table-header__title`}></div>
<div className={`${prefix}--data-table-header__description`}></div>
<div className={`${prefix}--data-table-header__title`}/>
<div className={`${prefix}--data-table-header__description`}/>
</div>
) : null}
{showToolbar ? (
Expand All @@ -58,7 +101,7 @@ const DataTableSkeleton = ({
className={`${prefix}--table-toolbar`}>
<div className={`${prefix}--toolbar-content`}>
<span
className={`${prefix}--skeleton ${prefix}--btn ${prefix}--btn--sm`}></span>
className={`${prefix}--skeleton ${prefix}--btn ${prefix}--btn--sm`}/>
</div>
</section>
) : null}
Expand All @@ -72,7 +115,7 @@ const DataTableSkeleton = ({
{headers[i]?.header}
</div>
) : (
<span></span>
<span/>
)}
</th>
))}
Expand Down