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

Add Table, FilterChips components #124

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import styles from "./Avatar.module.css";
import { useIdColorHash } from "./useIdColorHash";

export type OnAvatarErrorHandler = React.ComponentProps<typeof SuspenseImg>["onError"];

Check failure on line 24 in src/components/Avatar/Avatar.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `typeof·SuspenseImg` with `⏎··typeof·SuspenseImg⏎`

type AvatarProps = (
| JSX.IntrinsicElements["button"]
| JSX.IntrinsicElements["span"]
Expand Down Expand Up @@ -62,7 +64,7 @@
/**
* Callback when the image has failed to load.
*/
onError?: React.ComponentProps<typeof SuspenseImg>["onError"];
onError?: OnAvatarErrorHandler;
};

/**
Expand Down
17 changes: 17 additions & 0 deletions src/components/FilterChips/FilterChip.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.filterChip {
/* disable padding here and move to the button inside */
padding: 0;
}

.filterChip:hover {
background-color: var(--cpd-color-gray-500);
}

.filterChipButton {
align-items: center;
display: flex;
gap: var(--cpd-space-1x);
/* apply compound badge padding here */
padding: var(--cpd-space-1x) var(--cpd-space-3x);
white-space: nowrap;
}
45 changes: 45 additions & 0 deletions src/components/FilterChips/FilterChip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2023 New Vector Ltd

Licensed 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 React from "react";
import { Meta, StoryFn } from "@storybook/react";

import { FilterChip } from "./FilterChip";
import { FilterChipsContainer } from "./FilterChipsContainer";

export default {
title: "FilterChip",
component: FilterChip,
tags: ["autodocs"],
argTypes: {
label: String,
},
args: {
label: "hello",
},
} as Meta<typeof FilterChip>;

const Template: StoryFn<typeof FilterChip> = (args) => (
<FilterChipsContainer>
<FilterChip {...args} />

Check failure on line 37 in src/components/FilterChips/FilterChip.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `·`
<FilterChip

Check failure on line 38 in src/components/FilterChips/FilterChip.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎······label="Second·item·with·a·name·that's·quite·long"⏎···` with `·label="Second·item·with·a·name·that's·quite·long"`
label="Second item with a name that's quite long"
/>
</FilterChipsContainer>
);

export const Primary = Template.bind({});
Primary.args = {};
20 changes: 20 additions & 0 deletions src/components/FilterChips/FilterChip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Badge } from '../Badge/Badge';

Check failure on line 1 in src/components/FilterChips/FilterChip.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `'../Badge/Badge'` with `"../Badge/Badge"`
import Close20 from '@vector-im/compound-design-tokens/icons/close.svg'

Check failure on line 2 in src/components/FilterChips/FilterChip.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `'@vector-im/compound-design-tokens/icons/close.svg'` with `"@vector-im/compound-design-tokens/icons/close.svg";`
import React from 'react';

Check failure on line 3 in src/components/FilterChips/FilterChip.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `'react'` with `"react"`
import styles from './FilterChip.module.css';

Check failure on line 4 in src/components/FilterChips/FilterChip.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `'./FilterChip.module.css'` with `"./FilterChip.module.css"`

interface FilterChipProps {
label: string;

Check failure on line 7 in src/components/FilterChips/FilterChip.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
onClick?: () => void;

Check failure on line 8 in src/components/FilterChips/FilterChip.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
}

export const FilterChip: React.FC<FilterChipProps> = ({ label, onClick }) => {
return (

Check failure on line 12 in src/components/FilterChips/FilterChip.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
<Badge className={styles.filterChip}>
<div className={styles.filterChipButton} onClick={onClick} role="button">
{label}
<Close20 />
</div>
</Badge>
);
};
5 changes: 5 additions & 0 deletions src/components/FilterChips/FilterChipsContainer.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.filterChipsContainer {
display: flex;
flex-flow: wrap;
gap: var(--cpd-space-2x);
}
10 changes: 10 additions & 0 deletions src/components/FilterChips/FilterChipsContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import styles from './FilterChipsContainer.module.css';

interface FilterChipsContainerProps {
children: React.ReactNode;
}

export const FilterChipsContainer: React.FC<FilterChipsContainerProps> = ({ children }) => {
return <div className={styles.filterChipsContainer}>{children}</div>;
};
22 changes: 22 additions & 0 deletions src/components/Table/Table.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.table {
border-collapse: collapse;
margin-bottom: var(--cpd-space-13x);
width: 100%;
}

.tableHeader {
border-bottom: var(--cpd-border-width-1) solid var(--cpd-color-border-interactive-secondary);
color: var(--cpd-color-text-secondary);
font-size: var(--cpd-font-size-body-xs);
font-weight: var(--cpd-font-weight-regular);
padding: var(--cpd-space-4x);
text-transform: uppercase;
}

.tableHeaderCentred {
text-align: center;
}

.tableHeaderCheckbox {
width: 24px;
}
136 changes: 136 additions & 0 deletions src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
Copyright 2023 New Vector Ltd

Licensed 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 React, { useState } from "react";
import { Meta, StoryFn } from "@storybook/react";

import { Table, TableSpec } from "./Table";
import { TableCell } from "./TableCell";
import { TableFilter, TableHeadline } from ".";

export default {
title: "Table",
component: Table,
tags: ["autodocs"],
argTypes: {
},
args: {
},
} as Meta<typeof Table>;

interface SimpleTableItem {
name: string,
flavor: string,
[value: string]: string;
}

const Template: StoryFn<typeof Table> = (args) => {
const tableSpec: TableSpec<SimpleTableItem> = {
columns: [
{
id: 'name',
cell: ({ item }) => (
<TableCell> { item.name } </TableCell>
),
title: 'Name',
},
{
id: 'flavor',
cell: ({ item }) => <TableCell>{item.flavor}</TableCell>,
title: 'Flavor',
},
],
getItemId: (i) => i.name,
};

const items = [{
name: 'Chili 🌶️',
flavor: 'Spicy',
}];

return <Table spec={tableSpec} items={items} />
};

export const Primary = Template.bind({});
Primary.args = {};

export const WithHeader: StoryFn<typeof Table> = (args) => {
const tableSpec: TableSpec<SimpleTableItem> = {
columns: [
{
id: 'name',
cell: ({ item }) => (
<TableCell> { item.name } </TableCell>
),
title: 'Name',
},
{
id: 'flavor',
cell: ({ item }) => <TableCell>{item.flavor}</TableCell>,
title: 'Flavor',
},
],
getItemId: (i) => i.name,
};

const items = [{
name: 'Chili 🌶️',
flavor: 'Spicy',
}];
return <>
<TableHeadline fromItem={0} toItem={0} totalItems={50} title="My Title" />
<Table spec={tableSpec} items={items} />
</>;
};

export const WithHeaderAndFilter: StoryFn<typeof Table> = (args) => {
const tableSpec: TableSpec<SimpleTableItem> = {
columns: [
{
id: 'name',
cell: ({ item }) => (
<TableCell> { item.name } </TableCell>
),
title: 'Name',
},
{
id: 'flavor',
cell: ({ item }) => <TableCell>{item.flavor}</TableCell>,
title: 'Flavor',
},
],
getItemId: (i) => i.name,
};

const items = [{
name: 'Chili 🌶️',
flavor: 'Spicy',
}];

const [filterForSauces, setFilterForSauces] = useState(false);

const filters: TableFilter[] = [{
id: 'sauces',
disabled: false,
label: 'Only Sauces',
value: filterForSauces,
setValue: () => setFilterForSauces(!filterForSauces),
}];
return <>
<TableHeadline fromItem={0} toItem={0} totalItems={50} title="My Title" filters={filters} />
<Table spec={tableSpec} items={items} />
</>;
};
Loading
Loading