/
ComponentsFilters.tsx
82 lines (74 loc) · 2.08 KB
/
ComponentsFilters.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, { memo } from 'react'
import styled from 'styled-components'
import media from '../../../theming/mediaQueries'
const filters = ['SVG', 'HTML', 'Canvas', 'API'] as const
interface ComponentsFiltersProps {
filter: string | null
onChange: (filter: string | null) => void
}
export const ComponentsFilters = memo(
({ filter: currentFilter, onChange }: ComponentsFiltersProps) => {
return (
<Container>
<Item
isActive={currentFilter === null}
onClick={() => {
onChange(null)
}}
>
All
</Item>
{filters.map(filter => (
<Item
key={filter}
isActive={
currentFilter !== null &&
filter.toLowerCase() === currentFilter.toLowerCase()
}
onClick={() => {
onChange(filter)
}}
>
{filter}
</Item>
))}
</Container>
)
}
)
const Container = styled.div`
display: flex;
border: 2px solid ${({ theme }) => theme.colors.accent};
height: 42px;
border-radius: 2px;
overflow: hidden;
font-size: 13px;
font-weight: 700;
`
const Item = styled.span<{
isActive: boolean
}>`
line-height: 38px;
background: ${({ isActive, theme }) =>
isActive ? theme.colors.accent : theme.colors.cardBackground};
color: ${({ isActive, theme }) =>
isActive ? theme.colors.cardBackground : theme.colors.accent};
flex: 1;
text-align: center;
cursor: pointer;
border-left: 1px solid ${({ theme }) => theme.colors.accent};
padding: 0 26px;
&:first-child {
border-left-width: 0;
}
${media.tablet`
& {
padding: 0 12px;
}
`}
${media.mobile`
& {
padding: 0 12px;
}
`}
`