awesome-uses/src/components/Topics.js

96 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-01-07 20:23:53 +00:00
import React, { useContext } from 'react';
2020-01-07 22:58:15 +00:00
import styled from 'styled-components';
2020-01-07 20:23:53 +00:00
import FilterContext from '../context/FilterContext';
export default function Topics() {
const { countries, tags, currentTag, setCurrentTag } = useContext(
FilterContext
);
console.log(countries);
return (
2020-01-07 22:58:15 +00:00
<Tags>
2020-01-07 20:23:53 +00:00
{tags.map(tag => (
2020-01-07 22:58:15 +00:00
<TagLabel
2020-01-07 20:23:53 +00:00
className={`tag ${tag.name === currentTag ? 'currentTag' : ''}`}
htmlFor={`filter-${tag.name}`}
key={`filter-${tag.name}`}
>
<input
type="radio"
name="tag"
id={`filter-${tag.name}`}
value={tag.name}
checked={tag.name === currentTag}
onChange={e => setCurrentTag(e.currentTarget.value)}
/>
{tag.name}
2020-01-07 22:58:15 +00:00
<TagCount>{tag.count}</TagCount>
</TagLabel>
2020-01-07 20:23:53 +00:00
))}
{countries.map(tag => (
2020-01-07 22:58:15 +00:00
<TagLabel
2020-01-07 20:23:53 +00:00
className={`tag ${tag.emoji === currentTag ? 'currentTag' : ''}`}
htmlFor={`filter-${tag.name}`}
key={`filter-${tag.name}`}
title={tag.name}
>
<input
type="radio"
name="tag"
id={`filter-${tag.name}`}
value={tag.emoji}
checked={tag.emoji === currentTag}
onChange={e => setCurrentTag(e.currentTarget.value)}
/>
2020-01-07 22:58:15 +00:00
<TagEmoji>{tag.emoji}</TagEmoji>
<TagCount>{tag.count}</TagCount>
</TagLabel>
2020-01-07 20:23:53 +00:00
))}
2020-01-07 22:58:15 +00:00
</Tags>
2020-01-07 20:23:53 +00:00
);
}
2020-01-07 22:58:15 +00:00
// Component Styles
const Tags = styled.div`
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
`;
const TagLabel = styled.label`
background: var(--pink);
margin: 2px;
border-radius: 3px;
font-size: 1.7rem;
padding: 5px;
color: hsla(0, 100%, 100%, 0.8);
transition: background-color 0.2s;
cursor: pointer;
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
input {
display: none;
}
&.currentTag {
background: var(--yellow);
color: hsla(0, 100%, 0%, 0.8);
}
`;
const TagEmoji = styled.span`
transform: scale(1.45);
`;
const TagCount = styled.span`
background: var(--blue);
font-size: 1rem;
color: white;
padding: 2px;
border-radius: 2px;
margin-left: 5px;
`;