Skip to content

Commit

Permalink
Add Tag atom
Browse files Browse the repository at this point in the history
  • Loading branch information
luisfilipegoncalves committed Jan 16, 2021
1 parent a48f39a commit 32000bc
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
node_modules
.cache
dist
package-lock.json
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
8 changes: 4 additions & 4 deletions src/atoms/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CheckboxWrapper = styled.label<CheckboxWrapperProps>`
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;
Expand All @@ -25,13 +25,13 @@ const CheckboxWrapper = styled.label<CheckboxWrapperProps>`
}
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};
}
`;
Expand Down Expand Up @@ -81,7 +81,7 @@ const Checkmark = styled.span<CheckboxErrorProps>`
top: 0;
left: 0;
border: 2px solid
${props =>
${(props) =>
props.error
? 'var(--red, hsl(354, 83%, 64%))'
: 'var(--grey, hsl(0, 0%, 85%))'};
Expand Down
65 changes: 65 additions & 0 deletions src/atoms/tag.tsx
Original file line number Diff line number Diff line change
@@ -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 <TagWrapper color={color}>{value}</TagWrapper>;
};

export default Tag;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
42 changes: 42 additions & 0 deletions stories/tag.stories.tsx
Original file line number Diff line number Diff line change
@@ -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) => <Tag {...args} />;

TagPrimaryComponent.args = {
color: 'primary',
value: 'Burgdoggen',
};

export const TagOrangeComponent = (args) => <Tag color="orange" {...args} />;

TagOrangeComponent.args = {
color: 'orange',
value: 'Burgdoggen',
};

export const TagDangerComponent = (args) => <Tag {...args} />;

TagDangerComponent.args = {
color: 'danger',
value: 'Burgdoggen',
};

export const TagInfoComponent = (args) => <Tag {...args} />;

TagInfoComponent.args = {
color: 'info',
value: 'Burgdoggen',
};

export const TagOutlineComponent = (args) => <Tag {...args} />;

TagOutlineComponent.args = {
color: 'outline',
value: 'Burgdoggen',
};
2 changes: 1 addition & 1 deletion test/__snapshots__/checkbox.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`Checkbox renders 1`] = `
<span
class="sc-dlfnbm jMDpkz"
>
ola
hello
</span>
<input
checked=""
Expand Down
12 changes: 12 additions & 0 deletions test/__snapshots__/tag.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tag renders 1`] = `
<DocumentFragment>
<span
class="sc-jSgupP iIWTSr"
color="danger"
>
hello
</span>
</DocumentFragment>
`;
5 changes: 2 additions & 3 deletions test/checkbox.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<Checkbox value={'check'} label={'ola'} checked={true} />
<Checkbox value={'check'} label={'hello'} checked={true} />
);
screen.logTestingPlaygroundURL();
expect(asFragment()).toMatchSnapshot();
});
});
18 changes: 18 additions & 0 deletions test/tag.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<Tag color={'danger'} value={'hello'} />);
expect(asFragment()).toMatchSnapshot();
});

it('Tag has correct value', async () => {
const tagValue = 'This is my tag';
render(<Tag color={'danger'} value={tagValue} />);

const foundText = await screen.getByText(tagValue);
expect(foundText).toBeTruthy();
});
});

0 comments on commit 32000bc

Please sign in to comment.