From fdeb290502415c884059b8e85172361da0e99821 Mon Sep 17 00:00:00 2001 From: unix Date: Fri, 27 Mar 2020 09:40:21 +0800 Subject: [PATCH 1/3] feat(badge): add component --- components/badge/badge.tsx | 70 ++++++++++++++++++++++++++++++++++++++ components/badge/index.ts | 3 ++ components/index.ts | 1 + 3 files changed, 74 insertions(+) create mode 100644 components/badge/badge.tsx create mode 100644 components/badge/index.ts diff --git a/components/badge/badge.tsx b/components/badge/badge.tsx new file mode 100644 index 0000000..3d59ce3 --- /dev/null +++ b/components/badge/badge.tsx @@ -0,0 +1,70 @@ +import React, { useMemo } from 'react' +import withDefaults from '../utils/with-defaults' +import useTheme from '../styles/use-theme' +import { NormalSizes, NormalTypes } from '../utils/prop-types' +import { ZeitUIThemesPalette } from 'components/styles/themes' + +interface Props { + type?: NormalTypes + size?: NormalSizes + className?: string +} + +const defaultProps = { + type: 'default' as NormalTypes, + size: 'medium' as NormalSizes, + className: '', +} + +export type BadgeProps = Props & typeof defaultProps & React.HTMLAttributes + +const getFontSize = (size: NormalSizes) => { + const sizes: { [key in NormalSizes]: string } = { + mini: '.7rem', + small: '.75rem', + medium: '.875rem', + large: '1rem', + } + return sizes[size] +} + +const getBgColor = (type: NormalTypes, palette: ZeitUIThemesPalette) => { + const colors: { [key in NormalTypes]: string } = { + default: palette.foreground, + success: palette.success, + warning: palette.warning, + error: palette.error, + secondary: palette.secondary, + } + return colors[type] +} + +const Badge: React.FC> = React.memo(({ + type, size, className, children, ...props +}) => { + const theme = useTheme() + const bg = useMemo(() => getBgColor(type, theme.palette), [type, theme.palette]) + const font = useMemo(() => getFontSize(size), [size]) + + return ( + + {children} + + + ) +}) + +export default withDefaults(Badge, defaultProps) diff --git a/components/badge/index.ts b/components/badge/index.ts new file mode 100644 index 0000000..a712806 --- /dev/null +++ b/components/badge/index.ts @@ -0,0 +1,3 @@ +import Badge from './badge' + +export default Badge diff --git a/components/index.ts b/components/index.ts index e96894e..28fdca9 100644 --- a/components/index.ts +++ b/components/index.ts @@ -36,3 +36,4 @@ export { default as Select } from './select' export { default as Tabs } from './tabs' export { default as Progress } from './progress' export { default as Tree } from './file-tree' +export { default as Badge } from './badge' From a4a7a3c8e707103e4886eef59a8a7a793214e229 Mon Sep 17 00:00:00 2001 From: unix Date: Fri, 27 Mar 2020 09:40:33 +0800 Subject: [PATCH 2/3] docs(badge): add component --- pages/docs/components/badge.mdx | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pages/docs/components/badge.mdx diff --git a/pages/docs/components/badge.mdx b/pages/docs/components/badge.mdx new file mode 100644 index 0000000..81b50d3 --- /dev/null +++ b/pages/docs/components/badge.mdx @@ -0,0 +1,60 @@ +import { Layout, Playground, Attributes } from 'lib/components' +import { Badge, Spacer } from 'components' + +export const meta = { + title: 'Badge', + description: 'Badge', +} + +## Badge + +Display an indicator that requires attention. + + + 1 + 50 + 100 + 2020 + +`} /> + + + Success + Warning + Error + Secondary + +`} /> + + + Mini + Small + Medium + Large + +`} /> + + + +Badge.Props + +| Attribute | Description | Type | Accepted values | Default +| ---------- | ---------- | ---- | -------------- | ------ | +| **type** | badge type | `NormalTypes` | `'default', 'secondary', 'success', 'warning', 'error'` | `default` | +| **size** | badge size | `NormalSizes` | `'mini', 'small', 'medium', 'large'` | `medium` | +| ... | native props | `HTMLAttributes` | `'alt', 'id', 'className', ...` | - | + + + +export default ({ children }) => {children} From 80d169f984337a8d7688edf28a5c0bcf25139c57 Mon Sep 17 00:00:00 2001 From: unix Date: Fri, 27 Mar 2020 09:40:47 +0800 Subject: [PATCH 3/3] fix(baseline): fix section styles --- components/styles/css-baseline/css-baseline.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/styles/css-baseline/css-baseline.tsx b/components/styles/css-baseline/css-baseline.tsx index 8685a27..ee1dd14 100644 --- a/components/styles/css-baseline/css-baseline.tsx +++ b/components/styles/css-baseline/css-baseline.tsx @@ -155,11 +155,6 @@ const CSSBaseline: React.FC> = React.memo(({ font-weight: 600; } - selection { - background-color: ${theme.palette.background}; - color: ${theme.palette.foreground}; - } - input-webkit-autofill { box-shadow: 0 0 0 100px var(--geist-background) inset; } @@ -240,6 +235,11 @@ const CSSBaseline: React.FC> = React.memo(({ outline: none; list-style: none; } + + ::selection { + background-color: ${theme.palette.selection}; + color: ${theme.palette.foreground}; + } `} )