1
1
import styled from "styled-components" ;
2
2
import StringToColor from "../../lib/stringToColor" ;
3
3
4
+ const { contrastColor} = require ( 'contrast-color' ) ;
5
+
4
6
interface KeywordSpanProps {
5
7
color : string ,
8
+ textColor ?: string ,
6
9
horizontal ?: boolean ,
7
10
compact ?: boolean ,
8
11
onClick ?: ( ) => void
@@ -14,8 +17,8 @@ margin: ${(props) => props.compact ? '0 10px' : '0 0 10px 15px'};
14
17
cursor: pointer;
15
18
color: #222;
16
19
:hover {
17
- color: ${ ( props ) => props . onClick ?'red' :'var(--navds-color-text-link)' } ;
18
- text-decoration: ${ ( props ) => props . onClick ?'line-through' : 'underline' } ;
20
+ color: ${ ( props ) => props . onClick ? 'red' : 'var(--navds-color-text-link)' } ;
21
+ text-decoration: ${ ( props ) => props . onClick ? 'line-through' : 'underline' } ;
19
22
}
20
23
&:before {
21
24
background-color: ${ ( props ) => props . color } ;
@@ -27,6 +30,22 @@ color: #222;
27
30
content: '';
28
31
}
29
32
`
33
+ const KeywordPillStyle = styled . span < KeywordSpanProps > `
34
+ display: ${ ( props ) => props . horizontal ? 'block' : 'inline-block' } ;
35
+ background-color: ${ ( props ) => props . color } ;
36
+ color: ${ ( props ) => props . textColor } ;
37
+ border-radius: 999px;
38
+ font-size: 12px;
39
+ padding: 3px 5px 3px 5px;
40
+ border: 0.5px solid transparent;
41
+
42
+ margin: ${ ( props ) => props . compact ? '0 5px' : '0 0 10px 15px' } ;
43
+ cursor: pointer;
44
+ :hover {
45
+ filter: brightness(110%);
46
+ border: 0.5px solid #f5f5f5;
47
+ }
48
+ `
30
49
31
50
interface keywordLinkProps {
32
51
keyword : string ,
@@ -36,12 +55,20 @@ interface keywordLinkProps {
36
55
onClick ?: ( ) => void
37
56
}
38
57
39
- const KeywordLink = ( { keyword, horizontal, children, compact, onClick} : keywordLinkProps ) => {
58
+ export const KeywordLink = ( { keyword, horizontal, children, compact, onClick} : keywordLinkProps ) => {
40
59
return < KeywordSpan color = { StringToColor ( keyword ) } horizontal = { horizontal } compact = { compact } onClick = { onClick } >
41
60
{ children }
42
61
</ KeywordSpan >
43
62
44
63
64
+ }
65
+ export const KeywordPill = ( { keyword, horizontal, children, compact, onClick} : keywordLinkProps ) => {
66
+ const color = StringToColor ( keyword )
67
+ return < KeywordPillStyle color = { color } textColor = { contrastColor ( { bgColor : color } ) } horizontal = { horizontal }
68
+ compact = { compact } onClick = { onClick } >
69
+ { children }
70
+ </ KeywordPillStyle >
71
+
45
72
}
46
73
47
74
export default KeywordLink
0 commit comments