1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/app-desktop/gui/ConfigScreen/SideBar.tsx

75 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-09-15 15:01:07 +02:00
import * as React from 'react';
const styled = require('styled-components').default;
const Setting = require('@joplin/lib/models/Setting').default;
2020-09-15 15:01:07 +02:00
interface Props {
selection: string,
onSelectionChange: Function,
sections: any[],
}
export const StyledRoot = styled.div`
display: flex;
background-color: ${(props: any) => props.theme.backgroundColor2};
2020-09-15 15:01:07 +02:00
flex-direction: column;
`;
export const StyledListItem = styled.a`
box-sizing: border-box;
display: flex;
flex-direction: row;
padding: ${(props: any) => props.theme.mainPadding}px;
background: ${(props: any) => props.selected ? props.theme.selectedColor2 : 'none'};
2020-09-15 15:01:07 +02:00
transition: 0.1s;
text-decoration: none;
cursor: default;
opacity: ${(props: any) => props.selected ? 1 : 0.8};
2020-09-15 15:01:07 +02:00
&:hover {
background-color: ${(props: any) => props.theme.backgroundColorHover2};
2020-09-15 15:01:07 +02:00
}
`;
export const StyledListItemLabel = styled.span`
font-size: ${(props: any) => Math.round(props.theme.fontSize * 1.2)}px;
2020-09-15 15:01:07 +02:00
font-weight: 500;
color: ${(props: any) => props.theme.color2};
2020-09-15 15:01:07 +02:00
white-space: nowrap;
display: flex;
flex: 1;
align-items: center;
user-select: none;
`;
export const StyledListItemIcon = styled.i`
font-size: ${(props: any) => Math.round(props.theme.fontSize * 1.4)}px;
color: ${(props: any) => props.theme.color2};
margin-right: ${(props: any) => props.theme.mainPadding / 1.5}px;
2020-09-15 15:01:07 +02:00
`;
export default function SideBar(props: Props) {
const buttons: any[] = [];
2020-09-15 15:01:07 +02:00
function renderButton(section: any) {
2020-09-15 15:01:07 +02:00
const selected = props.selection === section.name;
return (
<StyledListItem key={section.name} selected={selected} onClick={() => { props.onSelectionChange({ section: section }); }}>
<StyledListItemIcon className={Setting.sectionNameToIcon(section.name)} />
<StyledListItemLabel>
{Setting.sectionNameToLabel(section.name)}
</StyledListItemLabel>
</StyledListItem>
);
}
for (const section of props.sections) {
buttons.push(renderButton(section));
}
return (
<StyledRoot>
{buttons}
</StyledRoot>
);
}