Skip to content
This repository was archived by the owner on Oct 15, 2021. It is now read-only.

Commit 61bd385

Browse files
heystevegraykeonikstoriesOfRen
authored
feat:(UI): New UI for List items - Graphql (#19)
* update next version (#11) * chore: Upgrade dependencies and add scripts to documentation * Updated Readme * Updated TOC * Fixed typo * feat(A11Y): Accessibility rewrite and addition of axe * New UI for List items - Graphql * Fixed list item accessibility * fix(UI): Tool list styling * New UI for List items * Centered title and image * Fixed list item accessibility * fix(Tests): Fixed broken link tests * fix bad merge Co-authored-by: John Fay <46365891+keonik@users.noreply.github.com> Co-authored-by: Ren Estep <n.ren.estep@gmail.com> Co-authored-by: John Fay <jfay@miletwo.us>
1 parent 9327af8 commit 61bd385

File tree

9 files changed

+19071
-62
lines changed

9 files changed

+19071
-62
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# misc
77
.DS_Store
8+
.env
89
.env.local
910
.env
1011
.env.development.local

components/Image.tsx

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
import React, { ReactElement } from 'react';
22
import NextImage from 'next/image';
3+
import { Avatar, createStyles, makeStyles, Theme } from '@material-ui/core';
34

45
interface Props {
5-
image: string;
6+
image: Maybe<string> | undefined;
67
name: string;
78
}
89

10+
const useStyles = makeStyles((theme: Theme) =>
11+
createStyles({
12+
avatar: {
13+
color: theme.palette.common.white,
14+
backgroundColor: theme.palette.primary.main,
15+
},
16+
})
17+
);
18+
919
export default function Image({ image, name }: Props): ReactElement {
20+
const firstLetter = name.slice(0, 1).toUpperCase();
21+
const classes = useStyles();
22+
23+
if (!image) {
24+
return <Avatar className={classes.avatar}>{firstLetter}</Avatar>;
25+
}
26+
1027
if (image.startsWith('/')) {
11-
return <NextImage src={image} width={50} height={50} alt={name} data-testid="image" />;
28+
return <NextImage src={image || firstLetter} width={50} height={50} alt={name} data-testid="image" />;
1229
}
30+
1331
return (
1432
<>
1533
{/* used for non optimizable entries (files not stored in public directory) */}
16-
<img data-testid="image" src={image} width={50} height={50} alt={name} />
34+
<img data-testid="image" src={image || firstLetter} width={50} height={50} alt={name} />
1735
</>
1836
);
1937
}

components/link/Link.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import { Link as MUILink } from '@material-ui/core';
3+
import Link from 'next/link';
4+
5+
type Props = {
6+
href: string;
7+
as?: string;
8+
label: string;
9+
color?: 'inherit' | 'initial' | 'primary' | 'secondary' | 'textPrimary' | 'textSecondary' | 'error' | undefined;
10+
};
11+
12+
export default function CustomLink({ href, as, label, color = 'inherit' }: Props) {
13+
return (
14+
<Link passHref href={href} as={as}>
15+
<MUILink color={color}>{label}</MUILink>
16+
</Link>
17+
);
18+
}

components/list/ListItem.tsx

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import Image from '../Image';
2+
import {
3+
ListItem as MUIListItem,
4+
ListItemAvatar,
5+
Avatar,
6+
ListItemText,
7+
Grid,
8+
Typography,
9+
makeStyles,
10+
createStyles,
11+
Theme,
12+
} from '@material-ui/core';
13+
import Link from '../link/Link';
14+
import { Image as ImageType } from '../../pages/index';
15+
16+
const useStyles = makeStyles((theme: Theme) =>
17+
createStyles({
18+
info: {
19+
justify: 'center',
20+
padding: theme.spacing(2),
21+
},
22+
avatar: {
23+
backgroundColor: theme.palette.gray.light,
24+
},
25+
})
26+
);
27+
28+
export type Link = {
29+
label: string;
30+
href: string;
31+
as?: string;
32+
};
33+
34+
type Props = {
35+
name: string;
36+
image: ImageType | undefined;
37+
link: Link;
38+
};
39+
40+
export default function ListItem({ name, image, link }: Props) {
41+
const classes = useStyles();
42+
return (
43+
<MUIListItem divider>
44+
<Grid container alignItems="center">
45+
<ListItemAvatar>
46+
<Avatar alt={name} className={classes.avatar}>
47+
{/* NextJS Image optimization example. Props are src(any file under the public dir), width, and height */}
48+
<Image image={image} name={name} />
49+
</Avatar>
50+
</ListItemAvatar>
51+
<ListItemText>
52+
<Typography variant="body1">{name}</Typography>
53+
</ListItemText>
54+
<Grid container item xs={12} md={3} className={classes.info} justify="flex-end" alignItems="center">
55+
<Link href={link.href} as={link?.as} label={link.label} />
56+
</Grid>
57+
</Grid>
58+
</MUIListItem>
59+
);
60+
}

lib/tools.ts

+12
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,16 @@ export const tools: Omit<Tool, 'id'>[] = [
7474
link: 'https://github.com/dequelabs/axe-core-npm/blob/develop/packages/react/README.md',
7575
image: '/axe.svg',
7676
},
77+
{
78+
name: 'Deque Axe',
79+
description:
80+
'Test your React application with the axe-core accessibility testing library. Results will show in the Chrome DevTools console.',
81+
link: 'https://github.com/dequelabs/axe-core-npm/blob/develop/packages/react/README.md',
82+
image: {
83+
src: '/axe.svg',
84+
width: 50,
85+
height: 50,
86+
alt: 'axe-core/react',
87+
},
88+
},
7789
];

0 commit comments

Comments
 (0)