diff --git a/.gitignore b/.gitignore index d4de8fc0..7d6cff0c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules .cache dist +package-lock.json \ No newline at end of file diff --git a/README.md b/README.md index a8a286b0..7a19015d 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adju Jest tests are set up to run with `npm test` or `yarn test`. +To debug tests +``` +import { screen } from '@testing-library/react'; +screen.logTestingPlaygroundURL(); +``` + ### Bundle analysis Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`. diff --git a/src/atoms/checkbox.tsx b/src/atoms/checkbox.tsx index 81c2ca3b..c20dd979 100644 --- a/src/atoms/checkbox.tsx +++ b/src/atoms/checkbox.tsx @@ -14,7 +14,7 @@ const CheckboxWrapper = styled.label` position: relative; height: 24px; padding-left: 0; - cursor: ${props => (props.disabled ? 'auto' : 'pointer')}; + cursor: ${(props) => (props.disabled ? 'auto' : 'pointer')}; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; @@ -25,13 +25,13 @@ const CheckboxWrapper = styled.label` } span { - color: ${props => + color: ${(props) => props.error ? 'var(--red, hsl(354, 83%, 64%))' : props.disabled ? 'var(--grey, hsl(0, 0%, 85%))' : null}; - border-color: ${props => + border-color: ${(props) => props.error ? 'var(--red, hsl(354, 83%, 64%))' : null}; } `; @@ -81,7 +81,7 @@ const Checkmark = styled.span` top: 0; left: 0; border: 2px solid - ${props => + ${(props) => props.error ? 'var(--red, hsl(354, 83%, 64%))' : 'var(--grey, hsl(0, 0%, 85%))'}; diff --git a/src/atoms/tag.tsx b/src/atoms/tag.tsx new file mode 100644 index 00000000..74af3dd4 --- /dev/null +++ b/src/atoms/tag.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import styled, { css } from 'styled-components'; + +const TagWrapper = styled.span` + display: inline-block; + border: 2px solid var(--green, hsl(186, 62%, 59%)); + border-radius: 999px; + background-color: var(--green, hsl(186, 62%, 59%)); + max-width: 150px; + padding: 2px 10px; + font-size: 0.85rem; + color: var(--white, hsl(0, 0%, 100%)); + text-transform: lowercase; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + + &:not(:first-child) { + margin-left: 5px; + } + + ${(props) => + props.color === 'orange' && + css` + border-color: var(--orange, hsl(36, 100%, 57%)); + background-color: var(--orange, hsl(36, 100%, 57%)); + `} + + ${(props) => + props.color === 'danger' && + css` + border-color: var(--red, hsl(354, 83%, 64%)); + background-color: var(--red, hsl(354, 83%, 64%)); + `} + + ${(props) => + props.color === 'info' && + css` + border-color: var(--grey, hsl(0, 0%, 85%)); + background-color: var(--lightGrey, hsl(0, 0%, 98%)); + color: var(--default, hsl(0, 0%, 16%)); + `} + + ${(props) => + props.color === 'outline' && + css` + border-color: var(--default, hsl(0, 0%, 16%)); + background-color: transparent; + color: var(--default, hsl(0, 0%, 16%)); + `} +`; + +type Color = 'primary' | 'orange' | 'danger' | 'info' | 'outline'; + +interface TagProps { + color?: Color; + value: string; +} + +const Tag = (props: TagProps) => { + const { color = 'primary', value } = props; + return {value}; +}; + +export default Tag; diff --git a/src/index.ts b/src/index.ts index 68a83da6..1f2dd69a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,3 +7,4 @@ export { default as TaikaiLogo } from './ions/taikai-logo'; // Atoms export { default as Avatar } from './atoms/avatar'; export { default as Checkbox } from './atoms/checkbox'; +export { default as Tag } from './atoms/tag'; diff --git a/stories/tag.stories.tsx b/stories/tag.stories.tsx new file mode 100644 index 00000000..ea06a0ec --- /dev/null +++ b/stories/tag.stories.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { Tag } from '../src'; + +export default { + title: 'Design System|Atoms/Tags', + component: Tag, +}; + +export const TagPrimaryComponent = (args) => ; + +TagPrimaryComponent.args = { + color: 'primary', + value: 'Burgdoggen', +}; + +export const TagOrangeComponent = (args) => ; + +TagOrangeComponent.args = { + color: 'orange', + value: 'Burgdoggen', +}; + +export const TagDangerComponent = (args) => ; + +TagDangerComponent.args = { + color: 'danger', + value: 'Burgdoggen', +}; + +export const TagInfoComponent = (args) => ; + +TagInfoComponent.args = { + color: 'info', + value: 'Burgdoggen', +}; + +export const TagOutlineComponent = (args) => ; + +TagOutlineComponent.args = { + color: 'outline', + value: 'Burgdoggen', +}; diff --git a/test/__snapshots__/checkbox.test.tsx.snap b/test/__snapshots__/checkbox.test.tsx.snap index 71e0f7fa..04bbe5f9 100644 --- a/test/__snapshots__/checkbox.test.tsx.snap +++ b/test/__snapshots__/checkbox.test.tsx.snap @@ -8,7 +8,7 @@ exports[`Checkbox renders 1`] = ` - ola + hello + + hello + + +`; diff --git a/test/checkbox.test.tsx b/test/checkbox.test.tsx index e2cddd00..6702f0c3 100644 --- a/test/checkbox.test.tsx +++ b/test/checkbox.test.tsx @@ -1,13 +1,12 @@ import React from 'react'; -import { render, screen } from '@testing-library/react'; +import { render } from '@testing-library/react'; import { Checkbox } from '../src'; describe('Checkbox', () => { it('renders', () => { const { asFragment } = render( - + ); - screen.logTestingPlaygroundURL(); expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/test/tag.test.tsx b/test/tag.test.tsx new file mode 100644 index 00000000..ee98ff47 --- /dev/null +++ b/test/tag.test.tsx @@ -0,0 +1,18 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { Tag } from '../src'; + +describe('Tag', () => { + it('renders', () => { + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); + }); + + it('Tag has correct value', async () => { + const tagValue = 'This is my tag'; + render(); + + const foundText = await screen.getByText(tagValue); + expect(foundText).toBeTruthy(); + }); +});