-
Notifications
You must be signed in to change notification settings - Fork 14
feat: optional status tags in sidebar (closes #22) #105
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
Changes from all commits
0bdca04
0b0cef8
0827703
408c5b3
15a1278
ffb120f
5137e30
b861e11
eadd1c3
ac7b0ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import React from 'react'; | ||
|
|
||
| import StatusTagBase from './StatusTagBase'; | ||
|
|
||
| const SidebarStatusTag = ({ statusConfig }) => ( | ||
|
Check warning on line 5 in src/components/SidebarStatusTag.jsx
|
||
| <StatusTagBase | ||
| label={statusConfig.label} | ||
|
Check warning on line 7 in src/components/SidebarStatusTag.jsx
|
||
| status={statusConfig.status} | ||
|
Check warning on line 8 in src/components/SidebarStatusTag.jsx
|
||
| variant="sidebar" | ||
| /> | ||
| ); | ||
|
|
||
| export default SidebarStatusTag; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import startCase from 'lodash/startCase'; | ||
| import React from 'react'; | ||
| import { styled, css } from 'storybook/theming'; | ||
|
|
||
| import { defaultStatuses, defaultBackground, defaultColor } from '../defaults'; | ||
|
|
||
| const baseStyles = css` | ||
| align-self: center; | ||
| border-radius: 0.25em; | ||
| font-weight: 700; | ||
| text-decoration: none; | ||
| text-transform: uppercase; | ||
| user-select: none; | ||
| `; | ||
|
|
||
| const toolbarStyles = css` | ||
| font-size: 11px; | ||
| line-height: 20px; | ||
| padding: 0 0.5em; | ||
| `; | ||
|
|
||
| const sidebarStyles = css` | ||
| font-size: 10px; | ||
| line-height: 16px; | ||
| padding: 0 0.4em; | ||
| `; | ||
|
|
||
| const variantStyles = ({ variant }) => | ||
| variant === 'sidebar' ? sidebarStyles : toolbarStyles; | ||
|
|
||
| const LinkTag = styled.a` | ||
| ${baseStyles} | ||
| ${variantStyles} | ||
| `; | ||
|
|
||
| const TextTag = styled.span` | ||
| ${baseStyles} | ||
| ${variantStyles} | ||
| `; | ||
|
|
||
| const StatusTagBase = ({ label, status, url, variant = 'toolbar' }) => { | ||
|
Check warning on line 41 in src/components/StatusTagBase.jsx
|
||
| const resolvedColor = | ||
| status?.color ?? | ||
|
Check warning on line 43 in src/components/StatusTagBase.jsx
|
||
| (defaultStatuses[label] ? defaultStatuses[label].color : defaultColor); | ||
| const resolvedBackground = | ||
| status?.background ?? | ||
|
Check warning on line 46 in src/components/StatusTagBase.jsx
|
||
| (defaultStatuses[label] | ||
| ? defaultStatuses[label].background | ||
| : defaultBackground); | ||
|
|
||
| const style = { | ||
| color: resolvedColor, | ||
| backgroundColor: resolvedBackground, | ||
| }; | ||
|
|
||
| const description = status?.description; | ||
|
Check warning on line 56 in src/components/StatusTagBase.jsx
|
||
| const displayLabel = startCase(label); | ||
| const isLink = variant === 'toolbar' && !!url; | ||
|
|
||
| if (isLink) { | ||
| return ( | ||
| <LinkTag variant={variant} style={style} title={description} href={url}> | ||
| {displayLabel} | ||
| </LinkTag> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <TextTag variant={variant} style={style} title={description}> | ||
| {displayLabel} | ||
| </TextTag> | ||
| ); | ||
| }; | ||
|
|
||
| export default StatusTagBase; | ||
Uh oh!
There was an error while loading. Please reload this page.