forked from vtex-apps/search-result
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LayoutModeSwitcher.js
68 lines (62 loc) · 1.51 KB
/
LayoutModeSwitcher.js
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
import React from 'react'
import PropTypes from 'prop-types'
import { Button } from 'vtex.styleguide'
import { IconGrid, IconInlineGrid, IconSingleGrid } from 'vtex.store-icons'
import searchResult from '../searchResult.css'
export const LAYOUT_MODE = [
{
value: 'normal',
label: 'layoutModeSwitcher.normal',
},
{
value: 'small',
label: 'layoutModeSwitcher.small',
},
{
value: 'inline',
label: 'layoutModeSwitcher.inline',
},
]
const LayoutIcon = ({ mode }) => {
switch (mode) {
case 'small':
return <IconGrid size={20} />
case 'inline':
return <IconInlineGrid size={20} />
case 'normal':
return <IconSingleGrid size={20} />
default: {
// eslint-disable-next-line no-undef
if (process.env.NODE_ENV === 'development') {
console.warn(`Unsupported icon ${mode} in LayoutIcon`)
}
return null
}
}
}
const LayoutModeSwitcher = ({ activeMode, onChange }) => {
return (
<div
className={`${
searchResult.layoutSwitcher
} h-100 flex justify-center items-center pl4`}
>
<Button
variation="tertiary"
size="small"
onClick={e => onChange(e, activeMode)}
>
<span className="c-on-base">
<LayoutIcon mode={activeMode} />
</span>
</Button>
</div>
)
}
LayoutModeSwitcher.propTypes = {
/** Current active mode */
activeMode: PropTypes.string,
/** On change callback */
onChange: PropTypes.func.isRequired,
}
export default LayoutModeSwitcher