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(Table): add typescript type annotations to Table #13372

Merged
merged 11 commits into from
Mar 23, 2023
Merged
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,15 @@
"code"
]
},
{
"login": "aze3ma",
"name": "Mahmoud Abdulazim",
"avatar_url": "https://avatars.githubusercontent.com/u/6822318?v=4",
"profile": "https://www.github.com/aze3ma",
"contributions": [
"code"
]
},
{
"login": "davesteinberg",
"name": "Dave Steinberg",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ check out our [Contributing Guide](/.github/CONTRIBUTING.md) and our
<td align="center"><a href="https://github.com/awarrier99"><img src="https://avatars.githubusercontent.com/u/17476235?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ashvin Warrier</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=awarrier99" title="Code">💻</a></td>
<td align="center"><a href="https://galvingao.com/"><img src="https://avatars.githubusercontent.com/u/12567059?v=4?s=100" width="100px;" alt=""/><br /><sub><b>GalvinGao</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=GalvinGao" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/bianca-sparxs"><img src="https://avatars.githubusercontent.com/u/33003148?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bianca Sparxs</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=bianca-sparxs" title="Code">💻</a></td>
<td align="center"><a href="https://www.github.com/aze3ma"><img src="https://avatars.githubusercontent.com/u/6822318?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mahmoud Abdulazim</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=aze3ma" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/davesteinberg"><img src="https://avatars.githubusercontent.com/u/3935584?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dave Steinberg</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=davesteinberg" title="Code">💻</a></td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,57 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { useContext } from 'react';
import React, { useContext, PropsWithChildren } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { usePrefix } from '../../internal/usePrefix';
import { TableContext } from './TableContext';

interface TableProps {
className?: string;

/**
* `false` If true, will apply sorting styles
*/
isSortable?: boolean;

/**
* Specify whether the overflow menu (if it exists) should be shown always, or only on hover
*/
overflowMenuOnHover?: boolean;

/**
* Change the row height of table. Currently supports `xs`, `sm`, `md`, `lg`, and `xl`.
*/
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';

/**
* `false` If true, will keep the header sticky (only data rows will scroll)
*/
stickyHeader?: boolean;

/**
* `false` If true, will use a width of 'auto' instead of 100%
*/
useStaticWidth?: boolean;

/**
* `true` to add useZebraStyles striping.
*/
useZebraStyles?: boolean;
}

export const Table = ({
className,
children,
useZebraStyles,
size,
isSortable,
size = 'md',
aze3ma marked this conversation as resolved.
Show resolved Hide resolved
isSortable = false,
useStaticWidth,
stickyHeader,
overflowMenuOnHover,
overflowMenuOnHover = true,
...other
}) => {
}: PropsWithChildren<TableProps>) => {
const { titleId, descriptionId } = useContext(TableContext);
const prefix = usePrefix();
const componentClass = cx(`${prefix}--data-table`, className, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

import { createContext } from 'react';

interface TableContextType {
titleId?: string;
descriptionId?: string;
}

export const TableContext = createContext({
titleId: null,
descriptionId: null,
});
titleId: undefined,
descriptionId: undefined,
} as TableContextType);
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const blocklist = new Set([
'DataTable.mdx',
'stories',
'next',
'TableContext.js',
'TableContext.tsx',
]);
const components = fs
.readdirSync(COMPONENT_PATH)
Expand Down