-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add chip, traffic light and centered-column
- Loading branch information
1 parent
09835ee
commit 2e6351e
Showing
12 changed files
with
154 additions
and
0 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,9 @@ | ||
import React from 'react'; | ||
|
||
type CenteredColumnProps = { children: React.ReactNode }; | ||
|
||
export const CenteredColumn = ({ children }: CenteredColumnProps) => ( | ||
<div className="min-h-screen flex items-center justify-center"> | ||
<div className="max-w-md w-full space-y-8">{children}</div> | ||
</div> | ||
); |
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,18 @@ | ||
import React from 'react'; | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { CenteredColumn } from './centered-column.component'; | ||
|
||
export default { | ||
title: 'Atoms/Centered Column', | ||
component: CenteredColumn, | ||
} as ComponentMeta<typeof CenteredColumn>; | ||
|
||
const Template: ComponentStory<typeof CenteredColumn> = (args) => ( | ||
<CenteredColumn {...args} /> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
children: <div className="text-center p-4">This is a Centered Column</div>, | ||
}; |
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 @@ | ||
export * from './centered-column.component'; |
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,27 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
|
||
import { ValhallaVariant } from '../../models'; | ||
import { CHIP_VARIANTS } from './chip.constant'; | ||
|
||
export type ChipProps = { | ||
children: React.ReactNode; | ||
variant?: ValhallaVariant; | ||
className?: string; | ||
}; | ||
|
||
export const Chip = ({ | ||
variant = 'default', | ||
children, | ||
className, | ||
}: ChipProps) => ( | ||
<div | ||
className={clsx( | ||
'px-2 py-1 rounded text-xs font-bold', | ||
CHIP_VARIANTS[variant], | ||
className | ||
)} | ||
> | ||
{children} | ||
</div> | ||
); |
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 { ValhallaVariant } from '../../models'; | ||
|
||
export const CHIP_VARIANTS: Record<ValhallaVariant, string> = { | ||
default: 'bg-neutral-400 text-white', | ||
info: 'bg-blue-400 text-white', | ||
success: 'bg-brand-400 text-white', | ||
error: 'bg-red-600 text-white', | ||
warning: 'bg-yellow-400 text-white', | ||
}; |
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,20 @@ | ||
import React from 'react'; | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { Chip } from './chip.component'; | ||
|
||
export default { | ||
title: 'Atoms/Chip', | ||
component: Chip, | ||
} as ComponentMeta<typeof Chip>; | ||
|
||
const Template: ComponentStory<typeof Chip> = (args) => ( | ||
<div className="flex"> | ||
<Chip {...args} /> | ||
</div> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
children: 'Chip', | ||
}; |
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 @@ | ||
export * from './chip.component'; |
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 @@ | ||
export * from './traffic-light-number.component'; |
28 changes: 28 additions & 0 deletions
28
src/ui/traffic-light-number/traffic-light-number.component.tsx
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,28 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
|
||
type TrafficLightNumberProps = { | ||
value: number; | ||
total?: number; | ||
}; | ||
|
||
export const TrafficLightNumber = ({ | ||
value, | ||
total = 20, | ||
}: TrafficLightNumberProps) => { | ||
const quarter = total / 4; | ||
const half = total / 2; | ||
|
||
return ( | ||
<span | ||
data-testid="traffic-light-number" | ||
className={clsx({ | ||
'text-yellow-400': value >= quarter && value <= half, | ||
'text-red-600': value <= quarter, | ||
'text-green-600': value >= half, | ||
})} | ||
> | ||
{value} | ||
</span> | ||
); | ||
}; |
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 { render, screen } from '@testing-library/react'; | ||
|
||
import { TrafficLightNumber } from './traffic-light-number.component'; | ||
|
||
describe('TrafficLightNumber', () => { | ||
test.each([ | ||
[20, 'text-green-600'], | ||
[10, 'text-yellow-400'], | ||
[5, 'text-red-600'], | ||
])('renders the value', (value, className) => { | ||
const { container } = render( | ||
<TrafficLightNumber value={value} total={20} /> | ||
); | ||
|
||
const el = screen.getByTestId('traffic-light-number'); | ||
|
||
expect(el).toHaveTextContent(String(value)); | ||
expect(container.getElementsByClassName(className)).toBeTruthy(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/ui/traffic-light-number/traffic-light-number.stories.tsx
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,16 @@ | ||
import React from 'react'; | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { TrafficLightNumber } from './traffic-light-number.component'; | ||
|
||
export default { | ||
title: 'Atoms/Traffic Light Number', | ||
component: TrafficLightNumber, | ||
} as ComponentMeta<typeof TrafficLightNumber>; | ||
|
||
const Template: ComponentStory<typeof TrafficLightNumber> = (args) => ( | ||
<TrafficLightNumber {...args} /> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { value: 10 }; |