Skip to content

Commit 8d4fa16

Browse files
committed
Rollback sidebar header controls prop
1 parent 469d8f3 commit 8d4fa16

1 file changed

Lines changed: 63 additions & 2 deletions

File tree

src/shared/components/organisms/Sidebar/atoms/SidebarHeader.tsx

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import { AppComponent } from '../../../../lib/types'
44
import cc from 'classcat'
55
import Button from '../../../atoms/Button'
66
import RoundedImage from '../../../atoms/RoundedImage'
7-
import { mdiChevronDown } from '@mdi/js'
7+
import { mdiChevronDown, mdiDotsHorizontal } from '@mdi/js'
88
import { overflowEllipsis } from '../../../../lib/styled/styleFunctions'
99
import Icon from '../../../atoms/Icon'
10+
import {
11+
useContextMenu,
12+
MenuTypes,
13+
MenuItem,
14+
} from '../../../../lib/stores/contextMenu'
15+
import Checkbox from '../../../molecules/Form/atoms/FormCheckbox'
16+
import Radio from '../../../molecules/Form/atoms/FormRadio'
1017

1118
interface SidebarHeaderProps {
1219
spaceImage?: string
@@ -31,7 +38,9 @@ const SidebarHeader: AppComponent<SidebarHeaderProps> = ({
3138
onSpaceClick,
3239
spaceImage,
3340
spaceName,
41+
controls,
3442
}) => {
43+
const { popup } = useContextMenu()
3544
return (
3645
<Container className={cc(['sidebar__header', className])}>
3746
<Button
@@ -55,10 +64,62 @@ const SidebarHeader: AppComponent<SidebarHeaderProps> = ({
5564
path={mdiChevronDown}
5665
/>
5766
</Button>
67+
{controls != null && (
68+
<Button
69+
variant='icon'
70+
size='sm'
71+
className='sidebar__header__controls'
72+
iconPath={mdiDotsHorizontal}
73+
iconSize={20}
74+
onClick={async (event) => {
75+
popup(event, mapControlsToPopup(controls))
76+
}}
77+
/>
78+
)}
5879
</Container>
5980
)
6081
}
6182

83+
function mapControlsToPopup(controls: SidebarControls) {
84+
const items: MenuItem[] = []
85+
86+
Object.entries(controls).forEach(([category, value]) => {
87+
items.push({
88+
type: MenuTypes.Component,
89+
component: <PopupCategory>{category}</PopupCategory>,
90+
})
91+
value.forEach((option) => {
92+
items.push({
93+
type: MenuTypes.Normal,
94+
onClick: option.onClick,
95+
label: (
96+
<span>
97+
{option.type === 'check' ? (
98+
<Checkbox checked={option.checked} />
99+
) : (
100+
<Radio checked={option.checked} />
101+
)}
102+
<span style={{ paddingLeft: 6 }}>{option.label}</span>
103+
</span>
104+
),
105+
})
106+
})
107+
})
108+
109+
return items
110+
}
111+
112+
const PopupCategory = styled.div`
113+
padding: 0 ${({ theme }) => theme.sizes.spaces.sm}px;
114+
color: ${({ theme }) => theme.colors.text.subtle};
115+
font-size: ${({ theme }) => theme.sizes.fonts.df}px;
116+
margin-top: ${({ theme }) => theme.sizes.spaces.sm}px;
117+
margin-bottom: ${({ theme }) => theme.sizes.spaces.sm}px;
118+
&.last {
119+
margin-top: ${({ theme }) => theme.sizes.spaces.df}px;
120+
}
121+
`
122+
62123
const Container = styled.div`
63124
&.sidebar__header {
64125
display: flex;
@@ -77,7 +138,7 @@ const Container = styled.div`
77138
justify-content: left;
78139
min-width: 30px;
79140
color: ${({ theme }) => theme.colors.text.secondary};
80-
q .button__label {
141+
.button__label {
81142
text-align: left;
82143
justify-content: left;
83144
flex: 0 1 auto;

0 commit comments

Comments
 (0)