-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(storybook): add Badges and fix storybook styles
- Loading branch information
1 parent
f510e62
commit c8af49a
Showing
13 changed files
with
180 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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,21 @@ | ||
import React from "react"; | ||
import { StyledSidebarItem } from "./style"; | ||
import StatusTag from "../StatusTag/StatusTag"; | ||
|
||
export type StatusType = "beta" | "deprecated" | "wip"; | ||
|
||
interface SidebarItemProps { | ||
children: React.ReactNode; | ||
status: StatusType; | ||
} | ||
|
||
const SidebarItem = (props: SidebarItemProps) => { | ||
return ( | ||
<StyledSidebarItem> | ||
<div>{props.children}</div> | ||
<StatusTag type={props.status}>{props.status}</StatusTag> | ||
</StyledSidebarItem> | ||
); | ||
}; | ||
|
||
export default SidebarItem; |
This file contains 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,8 @@ | ||
import { styled } from "@mui/material"; | ||
|
||
export const StyledSidebarItem = styled("div")` | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
width: 100%; | ||
`; |
This file contains 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,22 @@ | ||
import React, { FC } from "react"; | ||
import { StyledLabel } from "./style"; | ||
import { StatusType } from "../SidebarItem/SidebarItem"; | ||
|
||
interface StatusTagProps { | ||
children: React.ReactNode; | ||
type: StatusType; | ||
} | ||
|
||
const TypeToLabel: Record<StatusType, string> = { | ||
beta: "Beta", | ||
deprecated: "Deprecated", | ||
wip: "Work in Progress", | ||
}; | ||
|
||
const StatusTag: FC<StatusTagProps> = ({ type }) => { | ||
const label = TypeToLabel[type]; | ||
|
||
return <StyledLabel type={type}>{label}</StyledLabel>; | ||
}; | ||
|
||
export default StatusTag; |
This file contains 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 { styled } from "@mui/material"; | ||
import { StatusType } from "../SidebarItem/SidebarItem"; | ||
|
||
interface StyledLabelProps { | ||
type: StatusType; | ||
} | ||
|
||
const TypeToColor: Record<StatusType, string> = { | ||
beta: "#703CBE", | ||
deprecated: "#C61128", | ||
wip: "#D8921F", | ||
}; | ||
|
||
const TypeToBackGroundColor: Record<StatusType, string> = { | ||
beta: "#F4F0F9", | ||
deprecated: "#FEF2F2", | ||
wip: "#FCF6EC", | ||
}; | ||
|
||
export const StyledLabel = styled("label")` | ||
${(props: StyledLabelProps) => { | ||
const { type } = props; | ||
const color = TypeToColor[type]; | ||
return ` | ||
margin: 0 16px 0 8px; | ||
padding: 1px 4px; | ||
font-size: 10px; | ||
font-weight: 600; | ||
color: ${color}; | ||
border: solid 1px transparent; | ||
background-color: ${TypeToBackGroundColor[type]}; | ||
border-radius: 2px; | ||
`; | ||
}} | ||
`; |
This file contains 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 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,8 +1,25 @@ | ||
// .storybook/manager.js | ||
|
||
import React from "react"; | ||
import { addons } from "@storybook/addons"; | ||
import sdsTheme from "./sds-theme"; | ||
import SidebarItem from "./components/SidebarItem/SidebarItem"; | ||
|
||
addons.setConfig({ | ||
theme: sdsTheme, | ||
sidebar: { | ||
renderLabel: ({ name }) => { | ||
const statusRegex = /\[([^)]+)]/gi; | ||
const [statusMatch, statusType] = statusRegex.exec(name) || []; | ||
|
||
if (statusMatch) { | ||
return ( | ||
<SidebarItem status={statusType}> | ||
{name.replace(statusMatch, "").trim()} | ||
</SidebarItem> | ||
); | ||
} | ||
|
||
return name; | ||
}, | ||
}, | ||
}); |
This file contains 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 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,9 @@ | ||
import { BADGE as addonBadge } from "@geometricpanda/storybook-addon-badges"; | ||
|
||
export const BADGE = { | ||
BETA: addonBadge.BETA, | ||
DEPRECATED: addonBadge.DEPRECATED, | ||
NEEDS_REVISION: addonBadge.NEEDS_REVISION, | ||
STABLE: addonBadge.STABLE, | ||
WIP: "wip", | ||
}; |
This file contains 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 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 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 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 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