-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClimateModeMenu.tsx
More file actions
108 lines (101 loc) · 2.87 KB
/
ClimateModeMenu.tsx
File metadata and controls
108 lines (101 loc) · 2.87 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import classNames from 'classnames'
import type { CSSProperties } from 'react'
import { ChevronDownIcon } from 'lib/icons/ChevronDown.js'
import { OffIcon } from 'lib/icons/Off.js'
import { ThermostatCoolIcon } from 'lib/icons/ThermostatCool.js'
import { ThermostatHeatIcon } from 'lib/icons/ThermostatHeat.js'
import { ThermostatHeatCoolIcon } from 'lib/icons/ThermostatHeatCool.js'
import type { HvacModeSetting } from 'lib/seam/thermostats/thermostat-device.js'
import { Menu } from 'lib/ui/Menu/Menu.js'
import { ThermoModeMenuOption } from 'lib/ui/thermostat/ThermoModeMenuOption.js'
interface ClimateModeMenuProps {
mode: HvacModeSetting
onChange: (mode: HvacModeSetting) => void
supportedModes?: HvacModeSetting[]
buttonTextVisible?: boolean
className?: string
style?: CSSProperties
block?: boolean
size?: 'regular' | 'large'
}
export function ClimateModeMenu({
mode,
onChange,
supportedModes = ['heat', 'cool', 'heat_cool', 'off'],
buttonTextVisible = false,
className,
style,
block,
size = 'regular',
}: ClimateModeMenuProps): JSX.Element {
return (
<Menu
renderButton={({ onOpen }) => (
<button
type='button'
style={style}
onClick={onOpen}
className={classNames(
'seam-climate-mode-menu-button',
{
'seam-climate-mode-menu-button-block': block,
'seam-climate-mode-menu-button-regular': size === 'regular',
'seam-climate-mode-menu-button-large': size === 'large',
},
className
)}
>
<div className='seam-climate-mode-menu-button-icon'>
<ModeIcon mode={mode} />
</div>
{buttonTextVisible && (
<span className='seam-climate-mode-menu-button-text'>
{t[mode]}
</span>
)}
<ChevronDownIcon className='seam-climate-mode-menu-button-chevron' />
</button>
)}
verticalOffset={-180}
horizontalOffset={-32}
backgroundProps={{
className: 'seam-thermo-mode-menu',
}}
>
{supportedModes.map((m) => (
<ThermoModeMenuOption
key={m}
label={t[m]}
icon={<ModeIcon mode={m} />}
isSelected={mode === m}
onClick={() => {
onChange(m)
}}
/>
))}
</Menu>
)
}
function ModeIcon(props: { mode: HvacModeSetting }): JSX.Element {
switch (props.mode) {
case 'heat':
return <ThermostatHeatIcon />
case 'cool':
return <ThermostatCoolIcon />
case 'heat_cool':
return <ThermostatHeatCoolIcon />
case 'off':
return <OffIcon />
case 'eco':
return <ThermostatHeatCoolIcon />
default:
return <OffIcon />
}
}
const t: Record<HvacModeSetting, string> = {
heat: 'Heat',
cool: 'Cool',
heat_cool: 'Heat & Cool',
off: 'Off',
eco: 'Eco',
}