From a8a011e6744cad57740c260fd0442b16f6b379ac Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Wed, 26 Apr 2023 11:00:38 -0700 Subject: [PATCH] feat: Counter (#123) * feat: Counter * reduce size, change global styles --- src/counter/Counter.tsx | 38 ++++++++++++++++++++++++ src/counter/index.tsx | 1 + src/index.tsx | 1 + src/provider/GlobalStyles.tsx | 5 ++++ src/tabs/Tabs.tsx | 6 ++++ stories/Accordion.stories.tsx | 56 ++++++++++++++++++++--------------- stories/Counter.stories.tsx | 48 ++++++++++++++++++++++++++++++ stories/Tabs.stories.tsx | 25 ++++++++++++++++ 8 files changed, 156 insertions(+), 24 deletions(-) create mode 100644 src/counter/Counter.tsx create mode 100644 src/counter/index.tsx create mode 100644 stories/Counter.stories.tsx diff --git a/src/counter/Counter.tsx b/src/counter/Counter.tsx new file mode 100644 index 00000000..294378d3 --- /dev/null +++ b/src/counter/Counter.tsx @@ -0,0 +1,38 @@ +import React, { PropsWithChildren } from 'react'; +import { css } from '@emotion/react'; +import theme from '../theme'; + +type CounterProps = PropsWithChildren<{ + /** + * The color of the counter + * @default 'default' + **/ + variant?: 'default' | 'danger'; +}>; + +const counterCSS = css` + display: inline-block; + padding: 0 var(--ac-global-dimension-static-size-65); + border-radius: calc( + ( + ${theme.typography.sizes.small.lineHeight}px + 2 * + var(--ac-global-dimension-static-size-25) / 2 + ) + ); + background-color: var(--ac-global-background-color-light); + font-size: ${theme.typography.sizes.small.fontSize}px; + line-height: ${theme.typography.sizes.small.lineHeight}px; + color: var(--ac-global-text-color-900); + &[data-variant='danger'] { + background-color: var(--ac-global-background-color-danger); + } +`; + +export function Counter(props: CounterProps) { + const { children, variant = 'default' } = props; + return ( + + {children} + + ); +} diff --git a/src/counter/index.tsx b/src/counter/index.tsx new file mode 100644 index 00000000..c7c1dc37 --- /dev/null +++ b/src/counter/index.tsx @@ -0,0 +1 @@ +export * from "./Counter"; \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index 4b8cbbcb..58227e85 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -30,6 +30,7 @@ export * from './progress'; export * from './switch'; export * from './empty'; export * from './contextualhelp'; +export * from './counter'; export { theme, designationColors } from './theme'; // export interface Props extends HTMLAttributes { // /** custom content, defaults to 'the snozzberries taste like snozzberries' */ diff --git a/src/provider/GlobalStyles.tsx b/src/provider/GlobalStyles.tsx index 51b5d19f..6943d5b9 100644 --- a/src/provider/GlobalStyles.tsx +++ b/src/provider/GlobalStyles.tsx @@ -72,8 +72,13 @@ export const globalCSS = css` --ac-global-color-gray-200: #585d64; --ac-global-color-gray-100: #666b71; + --ac-global-color-danger: #f85149; + + --ac-global-text-color-900: rgba(255, 255, 255, 0.9); + --ac-global-background-color-light: var(--ac-global-color-gray-500); --ac-global-background-color-dark: var(--ac-global-color-gray-900); + --ac-global-background-color-danger: var(--ac-global-color-danger); --ac-global-border-color-light: var(--ac-global-color-gray-100); --ac-global-border-color-dark: var(--ac-global-color-gray-400); diff --git a/src/tabs/Tabs.tsx b/src/tabs/Tabs.tsx index 722a9beb..fa9a7ebb 100644 --- a/src/tabs/Tabs.tsx +++ b/src/tabs/Tabs.tsx @@ -44,6 +44,10 @@ const tabListCSS = css` transition: 0.3s; font-weight: bold; border-color: var(--tab-border-color); + + display: flex; + align-items: center; + gap: var(--ac-global-dimension-static-size-65); } &[data-orientation='horizontal'] { @@ -139,6 +143,7 @@ export function Tabs({ > {tab.name} + {tab?.extra} ); })} @@ -165,6 +170,7 @@ type TabPaneChildFC = (props: TabPaneChildFCProps) => ReactNode; interface TabPaneProps extends Omit, 'children'> { name: string; + extra?: ReactNode; children: ReactNode | TabPaneChildFC; className?: string; /** diff --git a/stories/Accordion.stories.tsx b/stories/Accordion.stories.tsx index ff887734..48573b39 100644 --- a/stories/Accordion.stories.tsx +++ b/stories/Accordion.stories.tsx @@ -1,6 +1,12 @@ import React from 'react'; import { Meta, Story } from '@storybook/react'; -import { Accordion, AccordionProps, AccordionItem, Card } from '../src'; +import { + Accordion, + AccordionProps, + AccordionItem, + Card, + Provider, +} from '../src'; import { withDesign } from 'storybook-addon-designs'; import InfoTip from './components/InfoTip'; @@ -32,29 +38,31 @@ const AccordionContents = () => ( export default meta; const Template: Story = args => ( - - - Description of predictions} - id="predictions" - > - - - - - - - - - - + + + + Description of predictions} + id="predictions" + > + + + + + + + + + + + ); // By passing using the Args format for exported stories, you can control the props for a component for reuse in a test diff --git a/stories/Counter.stories.tsx b/stories/Counter.stories.tsx new file mode 100644 index 00000000..6268b740 --- /dev/null +++ b/stories/Counter.stories.tsx @@ -0,0 +1,48 @@ +import React from 'react'; +import { css } from '@emotion/react'; +import { Meta, Story } from '@storybook/react'; +import { withDesign } from 'storybook-addon-designs'; +import { LabelGroup, Label, LabelProps } from '../src/label'; +import { Counter, Provider } from '../src'; + +const meta: Meta = { + title: 'Counter', + component: Counter, + decorators: [withDesign], + argTypes: { + children: { + control: { + type: 'text', + default: 'Label', + }, + }, + }, + parameters: { + controls: { expanded: true }, + }, +}; + +export default meta; + +/** + * A gallery of all the variants + */ +export const Gallery = () => ( + +
+ 12 + 12 +
+
+); + +const Template: Story = args => ; + +// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test +// https://storybook.js.org/docs/react/workflows/unit-testing +export const Default = Template.bind({}); diff --git a/stories/Tabs.stories.tsx b/stories/Tabs.stories.tsx index 9f17d709..64f19332 100644 --- a/stories/Tabs.stories.tsx +++ b/stories/Tabs.stories.tsx @@ -4,6 +4,7 @@ import { Meta, Story } from '@storybook/react'; import { withDesign } from 'storybook-addon-designs'; import { Tabs, TabsProps } from '../src/tabs/Tabs'; import { Heading } from '../src/content'; +import { Counter, Provider } from '../src'; const { TabPane } = Tabs; @@ -75,6 +76,30 @@ export const LazyLoading: Story = args => ( ); +export const WithExtra: Story = args => ( + +
+ + 12}> + {({ isSelected }) => ( + + )} + + 23}> + {({ isSelected }) => ( + + )} + + 2}> + {({ isSelected }) => ( + + )} + + +
+
+); + export const Gallery: Story = args => (