-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[vtadmin-web] Add Button + Icon components #7350
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
Merged
rohit-nayak-ps
merged 2 commits into
vitessio:master
from
tinyspeck:sarabee-vtadmin-components
Jan 23, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) => { | ||
| 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', | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
Iconsenum, 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.