Skip to content

Commit 2a60787

Browse files
committed
Merge branch 'develop' of github.com:coderan-io/ui into feature/navigation
2 parents 4231a16 + a8317f8 commit 2a60787

File tree

15 files changed

+2001
-1694
lines changed

15 files changed

+2001
-1694
lines changed

__tests__/Tag.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { shallow } from 'enzyme';
2+
import React from 'react';
3+
import { Tag, Variant } from '@/components';
4+
5+
describe('Tag test', () => {
6+
7+
it('should render tag', () => {
8+
const container = shallow(
9+
<Tag variant={Variant.ORANGE}>
10+
Hello world
11+
</Tag>
12+
);
13+
14+
expect(container.find('.tag.tag-orange').length).toBe(1);
15+
});
16+
});

src/components/Tag/Tag.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Variant } from '@/components';
4+
import clsx from 'clsx';
5+
6+
export interface TagProps extends React.HTMLAttributes<HTMLDivElement> {
7+
variant: Variant | string;
8+
}
9+
10+
const Tag = React.forwardRef<HTMLDivElement, TagProps>((
11+
{
12+
children,
13+
className,
14+
variant
15+
},
16+
ref
17+
): React.ReactElement => (
18+
<div
19+
ref={ref}
20+
className={clsx(
21+
'tag',
22+
`tag-${variant}`,
23+
className
24+
)}
25+
>
26+
{children}
27+
</div>
28+
));
29+
30+
Tag.displayName = 'Tag';
31+
Tag.propTypes = {
32+
children: PropTypes.node,
33+
className: PropTypes.string,
34+
variant: PropTypes.string.isRequired
35+
}
36+
37+
export default Tag;

src/components/Tag/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Tag } from './Tag';

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './Icon';
88
export * from './utils';
99
export * from './TextField';
1010
export * from './SelectField';
11+
export * from './Tag';

src/components/utils/Variant.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ export enum Variant {
33
PRIMARY_GHOST = 'primary-ghost',
44
SECONDARY = 'secondary',
55
DANGER = 'danger',
6-
DANGER_GHOST = 'danger-ghost'
6+
DANGER_GHOST = 'danger-ghost',
7+
RED = 'red',
8+
PINK = 'pink',
9+
PURPLE = 'purple',
10+
DEEP_PURPLE = 'deep-purple',
11+
INDIGO = 'indigo',
12+
BLUE = 'blue',
13+
LIGHT_BLUE = 'light-blue',
14+
TEAL = 'teal',
15+
GREEN = 'green',
16+
LIGHT_GREEN = 'light-green',
17+
LIME = 'lime',
18+
YELLOW = 'yellow',
19+
AMBER = 'amber',
20+
ORANGE = 'orange',
21+
BROWN = 'brown',
22+
GRAY = 'gray',
23+
BLUE_GRAY = 'blue-gray'
724
}
8-
9-
export const variantList: string[] = [
10-
'primary',
11-
'primary-ghost',
12-
'secondary',
13-
'danger',
14-
'danger-ghost'
15-
];

src/style/base/_mixins.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@use "colors";
1+
@use "variables";
22

3-
@function color($color, $variant: 500) {
4-
@return map-get(map-get(colors.$colors, $color), $variant);
3+
@function color($color, $variant: 'default') {
4+
@return map-get(map-get(variables.$colors, $color), $variant);
55
}

src/style/base/_typography.scss

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use "mixins";
2+
@use "variables";
23

34
/* inter-100 - latin */
45
@font-face {
@@ -97,46 +98,47 @@
9798

9899
h1 {
99100
font-size: 2rem;
100-
color: mixins.color('gray', 900);
101+
color: variables.$base-font-color;
101102
font-weight: normal;
102103
margin: 0;
103104
}
104105

105106
h2 {
106107
font-size: 1.8rem;
107108
margin: 0 0 1rem;
108-
color: mixins.color('gray', 900);
109+
color: variables.$base-font-color;
109110
}
110111

111112
h3 {
112113
font-size: 1.6rem;
113114
margin: 0 0 1rem;
114-
color: mixins.color('gray', 900);
115+
color: variables.$base-font-color;
115116
}
116117

117118
h4 {
118119
font-size: 1.4rem;
119120
margin: 0 0 1rem;
120-
color: mixins.color('gray', 900);
121+
color: variables.$base-font-color;
122+
font-weight: normal;
121123
}
122124

123125
h5 {
124126
font-size: 1.2rem;
125127
margin: 0 0 1rem;
126-
color: mixins.color('gray', 900);
128+
color: variables.$base-font-color;
127129
font-weight: 600;
128130
}
129131

130132
h6 {
131133
font-size: 1.1rem;
132134
margin: 0 0 1rem;
133-
color: mixins.color('gray', 900);
135+
color: variables.$base-font-color;
134136
}
135137

136138
.text-danger {
137-
color: mixins.color('red', 700);
139+
color: variables.color('red', 'default');
138140
}
139141

140142
.text-secondary {
141-
color: mixins.color('gray', 600);
143+
color: variables.color('gray', 'default');
142144
}

0 commit comments

Comments
 (0)