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(fuselage): TableSelection visual improvements #1409

Merged
merged 4 commits into from
Jul 17, 2024
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
5 changes: 5 additions & 0 deletions .changeset/clever-candles-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/fuselage": minor
---

feat(fuselage): TableSelection visual improvements
84 changes: 23 additions & 61 deletions packages/fuselage/src/components/Table/Table.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,29 @@ import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';

import { Table, TableRow, TableHead, TableBody, TableCell, TableFoot } from '.';
import * as stories from './Table.stories';

const { Default, Selected } = composeStories(stories);

describe('[Table Component]', () => {
it('renders Table without crashing', () => {
render(<Table />);
});

it('renders TableRow without crashing', () => {
render(<TableRow />, {
wrapper: ({ children }) => (
<table>
<tbody>{children}</tbody>
</table>
),
});
});

it('renders TableHead without crashing', () => {
render(<TableHead />, {
wrapper: ({ children }) => <table>{children}</table>,
});
});

it('renders TableBody without crashing', () => {
render(<TableBody />, {
wrapper: ({ children }) => <table>{children}</table>,
});
});

it('renders TableFoot without crashing', () => {
render(<TableFoot />, {
wrapper: ({ children }) => <table>{children}</table>,
});
});

it('renders TableCell without crashing', () => {
render(<TableCell />, {
wrapper: ({ children }) => (
<table>
<tbody>
<tr>{children}</tr>
</tbody>
</table>
),
});
});

it('should have no a11y violations on Default story', async () => {
const { container: defaultContainer } = render(<Default />);

const defaultResults = await axe(defaultContainer);
expect(defaultResults).toHaveNoViolations();
});

it('should have no a11y violations on Selected story', async () => {
const { container: selectedContainer } = render(<Selected />);

const selectedResults = await axe(selectedContainer);
expect(selectedResults).toHaveNoViolations();
});
const testCases = Object.values(composeStories(stories)).map((Story) => [
Story.storyName || 'Story',
Story,
]);

describe('[Table Rendering]', () => {
test.each(testCases)(
`renders %s without crashing`,
async (_storyname, Story) => {
const tree = render(<Story />);
expect(tree.baseElement).toMatchSnapshot();
}
);

test.each(testCases)(
'%s should have no a11y violations',
async (_storyname, Story) => {
const { container } = render(<Story />);

const results = await axe(container);
expect(results).toHaveNoViolations();
}
);
});
12 changes: 8 additions & 4 deletions packages/fuselage/src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
TableRow,
TableCell,
TableBody,
TableSelectionButtonGroup,
} from './index';

export default {
Expand Down Expand Up @@ -73,11 +74,8 @@ export const Default: ComponentStory<typeof Table> = () => (
</>
);

export const Selected: ComponentStory<typeof Table> = () => (
export const WithSelection: ComponentStory<typeof Table> = () => (
<>
<TableSelection text='5 Items selected'>
<TableSelectionButton>Delete</TableSelectionButton>
</TableSelection>
<Table>
<TableHead>
<TableRow>
Expand Down Expand Up @@ -154,6 +152,12 @@ export const Selected: ComponentStory<typeof Table> = () => (
</TableRow>
</TableBody>
</Table>
<TableSelection text='5 Items selected'>
<TableSelectionButtonGroup>
<TableSelectionButton>Delete</TableSelectionButton>
<TableSelectionButton>Cancel</TableSelectionButton>
</TableSelectionButtonGroup>
</TableSelection>
</>
);

Expand Down
6 changes: 3 additions & 3 deletions packages/fuselage/src/components/Table/Table.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
}

&__selection {
color: colors.status-font(on-info);
color: colors.font(titles-labels);
border-radius: theme(
'table-selected-border-radius',
lengths.border-radius(small)
lengths.border-radius(medium)
);
background-color: colors.status-background(info);
background-color: colors.surface(neutral);
}

&__wrapper {
Expand Down
8 changes: 1 addition & 7 deletions packages/fuselage/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import type { ComponentProps, CSSProperties } from 'react';
import type { ComponentProps } from 'react';
import React from 'react';

import Box from '../Box';

export const style: CSSProperties = {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};

export type TableProps = ComponentProps<typeof Box> & {
striped?: boolean;
sticky?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { ComponentProps } from 'react';
import React from 'react';

import Box from '../Box';
import Margins from '../Margins';
import { style } from './Table';
import Box from '../../Box';
import Margins from '../../Margins';

type TableSelectionProps = ComponentProps<typeof Box> & {
text?: string;
Expand All @@ -19,10 +18,11 @@ export const TableSelection = ({
display='flex'
alignItems='center'
justifyContent='space-between'
{...props}
pi={24}
elevation='2'
{...props}
>
<Box fontScale='p2m' mb={16} flexShrink={1} style={style}>
<Box fontScale='p2b' mb={16} flexShrink={1} withTruncatedText>
{text}
</Box>
{children && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ComponentProps } from 'react';
import React from 'react';

import { Button } from '../../Button';

type TableSelectionButtonProps = ComponentProps<typeof Button>;

export const TableSelectionButton = (props: TableSelectionButtonProps) => (
<Button small flexShrink={0} {...props} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { ComponentProps } from 'react';
import React from 'react';

import { ButtonGroup } from '../../ButtonGroup';

export const TableSelectionButtonGroup = (
props: ComponentProps<typeof ButtonGroup>
) => <ButtonGroup {...props} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './TableSelection';
export * from './TableSelectionButton';
export * from './TableSelectionButtonGroup';
11 changes: 0 additions & 11 deletions packages/fuselage/src/components/Table/TableSelectionButton.tsx

This file was deleted.

Loading
Loading