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(react): Add Table, TableRow, TableHead, TableBody, TableCell and TableContainer components. #314

Merged
merged 5 commits into from
Jan 9, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"devDependencies": {
"@oxygen-ui/logger": "2.1.0",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?21281faa4f8354491747075f40f58b497d0c4730",
"@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"@wso2/stylelint-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/stylelint-config?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"dotenv": "^16.0.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-brand-identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/testing-library__jest-dom": "^5.14.5",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?21281faa4f8354491747075f40f58b497d0c4730",
"@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"@wso2/stylelint-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/stylelint-config?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"eslint": "8.25.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@types/chalk": "^2.2.0",
"@types/jest": "^29.2.3",
"@types/node": "^18.11.18",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?21281faa4f8354491747075f40f58b497d0c4730",
"@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"babel-jest": "^29.3.1",
"eslint": "8.25.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@oxygen-ui/logger": "2.1.0",
"@types/jest": "^29.2.3",
"@types/node": "^18.11.18",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?21281faa4f8354491747075f40f58b497d0c4730",
"@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"cheerio": "1.0.0-rc.12",
"eslint": "8.25.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/react": "18.0.25",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?d84dd6df97ba9812d30b17d482ecaec5d35d3e54",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?21281faa4f8354491747075f40f58b497d0c4730",
"@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?d84dd6df97ba9812d30b17d482ecaec5d35d3e54",
"babel-jest": "^29.3.1",
"eslint": "8.25.0",
Expand Down
28 changes: 28 additions & 0 deletions packages/react/.storybook/story-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export type Stories =
| 'Stepper'
| 'Switch'
| 'Tab'
| 'Table'
| 'TableBody'
| 'TableCell'
| 'TableContainer'
| 'TableFooter'
| 'TableHead'
| 'TableRow'
| 'TabPanel'
| 'Tabs'
| 'TransitionStepper'
Expand Down Expand Up @@ -392,6 +399,27 @@ const StoryConfig: StorybookConfig = {
Tab: {
hierarchy: `${StorybookCategories.Navigation}/Tab`,
},
Table: {
hierarchy: `${StorybookCategories.DataDisplay}/Table`,
},
TableBody: {
hierarchy: `${StorybookCategories.DataDisplay}/Table Body`,
},
TableCell: {
hierarchy: `${StorybookCategories.DataDisplay}/Table Cell`,
},
TableContainer: {
hierarchy: `${StorybookCategories.DataDisplay}/Table Container`,
},
TableFooter: {
hierarchy: `${StorybookCategories.DataDisplay}/Table Footer`,
},
TableHead: {
hierarchy: `${StorybookCategories.DataDisplay}/Table Head`,
},
TableRow: {
hierarchy: `${StorybookCategories.DataDisplay}/Table Row`,
},
TabPanel: {
hierarchy: `${StorybookCategories.Navigation}/Tab Panel`,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/testing-library__jest-dom": "^5.14.5",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?21281faa4f8354491747075f40f58b497d0c4730",
"@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"@wso2/stylelint-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/stylelint-config?b21bbbd7379ab3b7315d7d9478dbd88c0bf11241",
"babel-jest": "^29.3.1",
Expand Down
90 changes: 90 additions & 0 deletions packages/react/src/components/Table/Table.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
import dedent from 'ts-dedent';
import StoryConfig from '../../../.storybook/story-config.ts';
import Table from './Table.tsx';
import TableRow from '../TableRow/TableRow.tsx';
import TableHead from '../TableHead/TableHead.tsx';
import TableBody from '../TableBody/TableBody.tsx';
import TableCell from '../TableCell/TableCell.tsx';

export const meta = {
component: Table,
title: StoryConfig.Table.hierarchy,
};

<Meta title={meta.title} component={meta.component} />

export const Template = args => {
return (
<Table {...args}>
<TableHead>
<TableRow>
<TableCell>
Table Head Cell 1
</TableCell>
<TableCell>
Table Head Cell 2
</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>
Table Body Cell 1
</TableCell>
<TableCell>
Table Body Cell 2
</TableCell>
</TableRow>
<TableRow hideBorder={true}>
<TableCell>
Table Body Cell 3
</TableCell>
<TableCell>
Table Body Cell 4
</TableCell>
</TableRow>
</TableBody>
</Table>
);
};

# Table

- [Overview](#overview)
- [Props](#props)
- [Usage](#usage)

## Overview

The `Table` component is used to display a set of data in a tabular format.

<Canvas>
<Story name="Overview">
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable story="Overview" />

## Usage

Import and use the `Table` component in your components as follows:

<Source
language="jsx"
dark
format
code={dedent`
import Table from '@oxygen-ui/react/Table';\n
function Demo {
return (
<Table>
{/** Table content */}
</Table>
);
}
`}
/>
67 changes: 67 additions & 0 deletions packages/react/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import MuiTable, {TableProps as MuiTableProps, TableTypeMap} from '@mui/material/Table';
import clsx from 'clsx';
import {forwardRef} from 'react';
import type {ElementType, ForwardRefExoticComponent, ReactElement, Ref} from 'react';

export type TableProps<
C extends ElementType = ElementType,
D extends ElementType = TableTypeMap['defaultComponent'],
P = {},
> = {
/**
* The component used for the root node. Either a string to use a HTML element or a component.
*/
component?: C;
} & Omit<MuiTableProps<D, P>, 'component'>;

/**
* The Table component lets display sets of data
*
* Demos:
*
* - [Table (Oxygen UI)](https://wso2.github.io/oxygen-ui/react/?path=/docs/data-display-table)
* - [Table (MUI)](https://mui.com/material-ui/react-table/)
*
* API:
*
* - [Table API](https://mui.com/material-ui/api/table/)
*
* @remarks
* - ✅ `component` prop is supported.
* - ✅ The `ref` is forwarded to the root element.
*
* @template C - The type of the component.
* @param props - The props for the Table component.
* @param ref - The ref to be forwarded to the MuiTable component.
* @returns The rendered Table component.
*/
const Table: ForwardRefExoticComponent<TableProps> = forwardRef(
<C extends ElementType = ElementType>(
{className, ...rest}: TableProps<C>,
ref: Ref<HTMLTableElement>,
): ReactElement => {
const classes: string = clsx('oxygen-table', className);

return <MuiTable ref={ref} className={classes} {...rest} />;
},
) as ForwardRefExoticComponent<TableProps>;

export default Table;
40 changes: 40 additions & 0 deletions packages/react/src/components/Table/__tests__/Table.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {render} from '@unit-testing';
import Table from '../Table';

describe('Table', () => {
it('should render successfully', () => {
const {baseElement} = render(
<Table>
<p>test Table</p>
</Table>,
);
expect(baseElement).toBeTruthy();
});

it('should match the snapshot', () => {
const {baseElement} = render(
<Table>
<p>test Table</p>
</Table>,
);
expect(baseElement).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Table should match the snapshot 1`] = `
<body>
<div>
<table
class="MuiTable-root oxygen-table css-1du9rtx-MuiTable-root"
>
<p>
test Table
</p>
</table>
</div>
</body>
`;
23 changes: 23 additions & 0 deletions packages/react/src/components/Table/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export {default} from './Table';
export * from './Table';
DonOmalVindula marked this conversation as resolved.
Show resolved Hide resolved

export {TablePropsSizeOverrides} from '@mui/material/Table';
export {TableTypeMap} from '@mui/material/Table';
Loading
Loading