Skip to content
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
10 changes: 10 additions & 0 deletions web/vtadmin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions web/vtadmin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.6.0",
"@types/classnames": "^2.2.11",
"@types/jest": "^26.0.19",
"@types/node": "^12.19.9",
"@types/react": "^16.14.2",
"@types/react-dom": "^16.9.10",
"@types/react-router-dom": "^5.1.7",
"classnames": "^2.2.6",
"node-sass": "^4.14.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand Down
78 changes: 78 additions & 0 deletions web/vtadmin/src/components/Button.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
.button {
background: var(--colorPrimary);
border: solid 2px var(--colorPrimary);
border-radius: 6px;
color: var(--textColorInverted);
cursor: pointer;
font-family: var(--fontFamilyPrimary);
font-size: var(--fontSizeDefault);
font-weight: 500;
line-height: var(--lineHeightBody);
outline: none;
padding: 8px 11px;
user-select: none;
transition: all 0.1s ease-in-out;
white-space: nowrap;
width: min-content;

.icon {
display: inline-block;
fill: var(--textColorInverted);
height: 1.4em;
margin-right: 0.4em;
vertical-align: middle;
width: 1.4em;
}
}

.button:active {
background: var(--colorPrimary200);
border-color: var(--colorPrimary200);
box-shadow: none !important;
}

.button:disabled {
background: var(--colorDisabled);
border-color: var(--colorDisabled);
cursor: not-allowed;
}

.button:not(:disabled):hover,
.button:not(:disabled):focus {
box-shadow: var(--boxShadowHover);
}

.button.secondary {
background: transparent;
border: solid 2px var(--colorPrimary);
color: var(--colorPrimary);

.icon {
fill: var(--colorPrimary);
}

&:active {
background: var(--backgroundSecondaryHighlight);
}

&:disabled {
background: transparent;
border-color: var(--colorDisabled);
color: var(--colorDisabled);
}

&:disabled .icon {
fill: var(--colorDisabled);
}
}

.button.sizeLarge {
font-size: var(--fontSizeLarge);
padding: 13px 15px;
}

.button.sizeSmall {
border-width: 1px;
font-size: var(--fontSizeSmall);
padding: 4px 6px;
}
36 changes: 36 additions & 0 deletions web/vtadmin/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import cx from 'classnames';

import style from './Button.module.scss';
import { Icon, Icons } from './Icon';

interface Props extends React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
className?: string;
icon?: Icons;
secondary?: boolean;
size?: 'large' | 'medium' | 'small';
}

export const Button: React.FunctionComponent<Props> = ({
children,
className,
icon,
secondary,
size = 'medium',
type = 'button',
...props
}) => {
const buttonClass = cx(className, style.button, {
[style.secondary]: !!secondary,
[style.sizeLarge]: size === 'large',
[style.sizeSmall]: size === 'small',
[style.withIcon]: !!icon,
});

return (
<button {...props} className={buttonClass} type={type}>
{icon && <Icon className={style.icon} icon={icon} />}
{children}
</button>
);
};
82 changes: 82 additions & 0 deletions web/vtadmin/src/components/Icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as icons from '../icons';

interface Props {
className?: string;
icon: Icons;
}

// All icons are from the VTAdmin Figma icon library:
// https://www.figma.com/file/By3SoETBRHpOirv3Ctfxdq/Designs
export const Icon = ({ icon, ...props }: Props) => {
Copy link
Copy Markdown
Contributor Author

@doeg doeg Jan 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Between the SVGs and the Icons enum, it's a lot of boilerplate BUT I'm... happy with this implementation. Mostly? It's one of the best SVG/icon implementations I've worked with, but it's still pretty clunky. 😕 The trade-off here is verbosity for type-safety.

It's possible we could reduce almost all of this boilerplate through some cheeky codegen, but that's not particularly well-supported in TypeScript (compared to Go) so it'll take some exploration.

const componentName = icon.charAt(0).toUpperCase() + icon.slice(1);

const IconComponent = (icons as any)[componentName];
if (!IconComponent) {
console.warn(`Invalid icon: ${icon}`);
return null;
}

return <IconComponent {...props} />;
};

export enum Icons {
add = 'add',
alertFail = 'alertFail',
archive = 'archive',
archiveAuto = 'archiveAuto',
archiveForever = 'archiveForever',
archiveRestore = 'archiveRestore',
arrowDown = 'arrowDown',
arrowLeft = 'arrowLeft',
arrowRight = 'arrowRight',
arrowUp = 'arrowUp',
avatar = 'avatar',
boxChecked = 'boxChecked',
boxEmpty = 'boxEmpty',
boxIndeterminate = 'boxIndeterminate',
bug = 'bug',
chart = 'chart',
checkSuccess = 'checkSuccess',
chevronDown = 'chevronDown',
chevronLeft = 'chevronLeft',
chevronRight = 'chevronRight',
chevronUp = 'chevronUp',
circleAdd = 'circleAdd',
circleDelete = 'circleDelete',
circleRemove = 'circleRemove',
circleWorkflow = 'circleWorkflow',
clear = 'clear',
code = 'code',
copy = 'copy',
delete = 'delete',
document = 'document',
download = 'download',
dropDown = 'dropDown',
dropUp = 'dropUp',
ellipsis = 'ellipsis',
gear = 'gear',
history = 'history',
info = 'info',
keyG = 'keyG',
keyK = 'keyK',
keyR = 'keyR',
keyS = 'keyS',
keyT = 'keyT',
keyboard = 'keyboard',
link = 'link',
pageFirst = 'pageFirst',
pageLast = 'pageLast',
pause = 'pause',
question = 'question',
radioEmpty = 'radioEmpty',
radioSelected = 'radioSelected',
refresh = 'refresh',
remove = 'remove',
retry = 'retry',
runQuery = 'runQuery',
search = 'search',
sort = 'sort',
spinnerLoading = 'spinnerLoading',
start = 'start',
wrench = 'wrench',
}
24 changes: 24 additions & 0 deletions web/vtadmin/src/components/routes/Debug.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.buttonContainer {
column-gap: 16px;
display: grid;
grid-template-columns: repeat(4, min-content);
row-gap: 24px;
}

.iconContainer {
column-gap: 0;
display: grid;
grid-template-columns: repeat(12, min-content);
row-gap: 0;
}

.icon {
fill: var(--colorPrimary);
padding: 16px;
transition: fill 0.1s ease-in-out;

&:hover {
background: var(--backgroundSecondaryHighlight);
fill: var(--colorPrimary200);
}
}
108 changes: 108 additions & 0 deletions web/vtadmin/src/components/routes/Debug.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,120 @@
import * as React from 'react';
import { Theme, useTheme } from '../../hooks/useTheme';
import { Button } from '../Button';
import { Icon, Icons } from '../Icon';
import style from './Debug.module.scss';

export const Debug = () => {
const [theme, setTheme] = useTheme();

return (
<div>
<h1>Debugging ✨🦋🐛🐝🐞🐜🕷🕸🦂🦗🦟✨</h1>

<h2>Environment variables</h2>
<pre>{JSON.stringify(process.env, null, 2)}</pre>

<h2>Style Guide</h2>

<h3>Theme</h3>
<div>
{Object.values(Theme).map((t) => (
<div key={t}>
<label>
<input
checked={theme === t}
name="theme"
onChange={() => setTheme(t)}
type="radio"
value={t}
/>
{t}
</label>
</div>
))}
</div>

<h3>Icons</h3>
<div className={style.iconContainer}>
{Object.values(Icons).map((i) => (
<Icon className={style.icon} icon={i} key={i} />
))}
</div>

<h3>Buttons</h3>
<div className={style.buttonContainer}>
{/* Large */}
<Button size="large">Button</Button>
<Button secondary size="large">
Button
</Button>
<Button icon={Icons.circleAdd} size="large">
Button
</Button>
<Button icon={Icons.circleAdd} secondary size="large">
Button
</Button>
<Button disabled size="large">
Button
</Button>
<Button disabled secondary size="large">
Button
</Button>
<Button disabled icon={Icons.circleAdd} size="large">
Button
</Button>
<Button disabled icon={Icons.circleAdd} secondary size="large">
Button
</Button>

{/* Medium */}
<Button size="medium">Button</Button>
<Button secondary size="medium">
Button
</Button>
<Button icon={Icons.circleAdd} size="medium">
Button
</Button>
<Button icon={Icons.circleAdd} secondary size="medium">
Button
</Button>
<Button disabled size="medium">
Button
</Button>
<Button disabled secondary size="medium">
Button
</Button>
<Button disabled icon={Icons.circleAdd} size="medium">
Button
</Button>
<Button disabled icon={Icons.circleAdd} secondary size="medium">
Button
</Button>

{/* Small */}
<Button size="small">Button</Button>
<Button secondary size="small">
Button
</Button>
<Button icon={Icons.circleAdd} size="small">
Button
</Button>
<Button icon={Icons.circleAdd} secondary size="small">
Button
</Button>
<Button disabled size="small">
Button
</Button>
<Button disabled secondary size="small">
Button
</Button>
<Button disabled icon={Icons.circleAdd} size="small">
Button
</Button>
<Button disabled icon={Icons.circleAdd} secondary size="small">
Button
</Button>
</div>
</div>
);
};
Loading