Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 20795e9

Browse files
committed
display keywords as pills
1 parent cb2858a commit 20795e9

File tree

7 files changed

+70
-15915
lines changed

7 files changed

+70
-15915
lines changed

components/dataproducts/dataproductInfo.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Keyword from '../widgets/Keyword'
21
import IconBox from '../lib/icons/iconBox'
32
import GithubIcon from '../lib/icons/github'
43
import {UrlLink} from '../widgets/UrlLink'
@@ -18,6 +17,7 @@ interface DataproductDetailProps {
1817
const DataproductInfo = ({product}: DataproductDetailProps) => {
1918
return (
2019
<>
20+
<table>
2121
{!!product.keywords.length && (
2222
<tr>
2323
<td>
@@ -33,6 +33,7 @@ const DataproductInfo = ({product}: DataproductDetailProps) => {
3333
</td>
3434
</tr>
3535
)}
36+
</table>
3637
<StyledTable>
3738
<tbody>
3839
{product.repo && (

components/index/results/searchResult.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import Link from 'next/link'
2-
import {SearchContentQuery} from '../../../lib/schema/graphql'
3-
import {ArrayElement} from '../../../lib/schema/ArrayElement'
42
import Card from '@mui/material/Card'
53
import CardHeader from '@mui/material/CardHeader'
64
import IconBox from '../../lib/icons/iconBox'
75
import BigQueryLogo from '../../lib/icons/bigQueryLogo'
86
import * as React from 'react'
97
import styled from 'styled-components'
10-
import KeywordLink from "../../lib/keywordList";
8+
import {KeywordPill} from "../../lib/keywordList";
119

1210
const StyledCard = styled(Card)`
1311
margin: 0 10px 20px;
@@ -27,9 +25,8 @@ export interface SearchResultProps {
2725
}
2826

2927
export const SearchResultLink = ({link, name, group, keywords}: SearchResultProps) => {
30-
3128
return (
32-
<Link href={link}>
29+
<Link href={link} passHref={true}>
3330
<a>
3431
<StyledCard>
3532
<CardHeader
@@ -44,7 +41,12 @@ export const SearchResultLink = ({link, name, group, keywords}: SearchResultProp
4441
subheader={`eier: ${group}`}
4542
/>
4643
<div style={{float: 'right'}}>
47-
{keywords && keywords.map((k, i) => <KeywordLink key={i} keyword={k} compact={true}/>)}
44+
{keywords && keywords.map((k, i) =>
45+
<Link key={i} href={`/search?q=${k}`} passHref={true}>
46+
<a>
47+
<KeywordPill key={i} keyword={k} compact={true}>{k}</KeywordPill>
48+
</a>
49+
</Link>)}
4850
</div>
4951
</StyledCard>
5052
</a>

components/lib/keywordList.tsx

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import styled from "styled-components";
22
import StringToColor from "../../lib/stringToColor";
33

4+
const {contrastColor} = require('contrast-color');
5+
46
interface KeywordSpanProps {
57
color: string,
8+
textColor?: string,
69
horizontal?: boolean,
710
compact?: boolean,
811
onClick?: () => void
@@ -14,8 +17,8 @@ margin: ${(props) => props.compact ? '0 10px' : '0 0 10px 15px'};
1417
cursor: pointer;
1518
color: #222;
1619
: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'} ;
1922
}
2023
&:before {
2124
background-color: ${(props) => props.color};
@@ -27,6 +30,22 @@ color: #222;
2730
content: '';
2831
}
2932
`
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+
`
3049

3150
interface keywordLinkProps {
3251
keyword: string,
@@ -36,12 +55,20 @@ interface keywordLinkProps {
3655
onClick?: () => void
3756
}
3857

39-
const KeywordLink = ({keyword, horizontal, children, compact, onClick}: keywordLinkProps) => {
58+
export const KeywordLink = ({keyword, horizontal, children, compact, onClick}: keywordLinkProps) => {
4059
return <KeywordSpan color={StringToColor(keyword)} horizontal={horizontal} compact={compact} onClick={onClick}>
4160
{children}
4261
</KeywordSpan>
4362

4463

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+
4572
}
4673

4774
export default KeywordLink

0 commit comments

Comments
 (0)