2023-11-09 21:19:08 +02:00
|
|
|
import { AppType, SettingSectionSource } from '@joplin/lib/models/Setting';
|
2020-09-15 15:01:07 +02:00
|
|
|
import * as React from 'react';
|
2021-01-22 00:40:14 +02:00
|
|
|
import Setting from '@joplin/lib/models/Setting';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
2020-09-15 15:01:07 +02:00
|
|
|
const styled = require('styled-components').default;
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied;
|
|
|
|
type StyleProps = any;
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
interface Props {
|
2020-11-12 21:29:22 +02:00
|
|
|
selection: string;
|
2023-06-30 11:30:29 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
onSelectionChange: Function;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied;
|
2020-11-12 21:29:22 +02:00
|
|
|
sections: any[];
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const StyledRoot = styled.div`
|
|
|
|
display: flex;
|
2024-04-05 13:16:49 +02:00
|
|
|
background-color: ${(props: StyleProps) => props.theme.backgroundColor2};
|
2020-09-15 15:01:07 +02:00
|
|
|
flex-direction: column;
|
2021-02-07 14:55:28 +02:00
|
|
|
overflow-x: hidden;
|
|
|
|
overflow-y: auto;
|
2020-09-15 15:01:07 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
export const StyledListItem = styled.a`
|
|
|
|
box-sizing: border-box;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2024-04-05 13:16:49 +02:00
|
|
|
padding: ${(props: StyleProps) => props.theme.mainPadding}px;
|
|
|
|
background: ${(props: StyleProps) => props.selected ? props.theme.selectedColor2 : 'none'};
|
2020-09-15 15:01:07 +02:00
|
|
|
transition: 0.1s;
|
|
|
|
text-decoration: none;
|
|
|
|
cursor: default;
|
2024-04-05 13:16:49 +02:00
|
|
|
opacity: ${(props: StyleProps) => props.selected ? 1 : 0.8};
|
|
|
|
padding-left: ${(props: StyleProps) => props.isSubSection ? '35' : props.theme.mainPadding}px;
|
2020-09-15 15:01:07 +02:00
|
|
|
|
|
|
|
&:hover {
|
2024-04-05 13:16:49 +02:00
|
|
|
background-color: ${(props: StyleProps) => props.theme.backgroundColorHover2};
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2021-01-22 00:40:14 +02:00
|
|
|
export const StyledDivider = styled.div`
|
|
|
|
box-sizing: border-box;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2024-04-05 13:16:49 +02:00
|
|
|
color: ${(props: StyleProps) => props.theme.color2};
|
|
|
|
padding: ${(props: StyleProps) => props.theme.mainPadding}px;
|
|
|
|
padding-top: ${(props: StyleProps) => props.theme.mainPadding * .8}px;
|
|
|
|
padding-bottom: ${(props: StyleProps) => props.theme.mainPadding * .8}px;
|
|
|
|
border-top: 1px solid ${(props: StyleProps) => props.theme.dividerColor};
|
|
|
|
border-bottom: 1px solid ${(props: StyleProps) => props.theme.dividerColor};
|
|
|
|
background-color: ${(props: StyleProps) => props.theme.selectedColor2};
|
|
|
|
font-size: ${(props: StyleProps) => Math.round(props.theme.fontSize)}px;
|
2021-01-22 00:40:14 +02:00
|
|
|
opacity: 0.5;
|
|
|
|
`;
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
export const StyledListItemLabel = styled.span`
|
2024-04-05 13:16:49 +02:00
|
|
|
font-size: ${(props: StyleProps) => Math.round(props.theme.fontSize * 1.2)}px;
|
2020-09-15 15:01:07 +02:00
|
|
|
font-weight: 500;
|
2024-04-05 13:16:49 +02:00
|
|
|
color: ${(props: StyleProps) => 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`
|
2024-04-05 13:16:49 +02:00
|
|
|
font-size: ${(props: StyleProps) => Math.round(props.theme.fontSize * 1.4)}px;
|
|
|
|
color: ${(props: StyleProps) => props.theme.color2};
|
|
|
|
margin-right: ${(props: StyleProps) => props.theme.mainPadding / 1.5}px;
|
2020-09-15 15:01:07 +02:00
|
|
|
`;
|
|
|
|
|
2021-01-12 14:28:55 +02:00
|
|
|
export default function Sidebar(props: Props) {
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied;
|
2020-11-12 21:13:28 +02:00
|
|
|
const buttons: any[] = [];
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied;
|
2020-11-12 21:13:28 +02:00
|
|
|
function renderButton(section: any) {
|
2020-09-15 15:01:07 +02:00
|
|
|
const selected = props.selection === section.name;
|
|
|
|
return (
|
2023-11-10 16:00:59 +02:00
|
|
|
<StyledListItem
|
|
|
|
key={section.name}
|
|
|
|
href='#'
|
2023-11-12 17:01:14 +02:00
|
|
|
role='tab'
|
2023-11-10 16:00:59 +02:00
|
|
|
aria-selected={selected}
|
|
|
|
isSubSection={Setting.isSubSection(section.name)}
|
|
|
|
selected={selected}
|
|
|
|
onClick={() => { props.onSelectionChange({ section: section }); }}
|
|
|
|
>
|
2023-11-09 21:19:08 +02:00
|
|
|
<StyledListItemIcon
|
|
|
|
className={Setting.sectionNameToIcon(section.name, AppType.Desktop)}
|
|
|
|
/>
|
2020-09-15 15:01:07 +02:00
|
|
|
<StyledListItemLabel>
|
|
|
|
{Setting.sectionNameToLabel(section.name)}
|
|
|
|
</StyledListItemLabel>
|
|
|
|
</StyledListItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-22 00:40:14 +02:00
|
|
|
function renderDivider(key: string) {
|
|
|
|
return (
|
|
|
|
<StyledDivider key={key}>
|
|
|
|
{_('Plugins')}
|
|
|
|
</StyledDivider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let pluginDividerAdded = false;
|
|
|
|
|
2024-03-09 13:03:57 +02:00
|
|
|
for (const section of props.sections) {
|
2021-01-22 00:40:14 +02:00
|
|
|
if (section.source === SettingSectionSource.Plugin && !pluginDividerAdded) {
|
|
|
|
buttons.push(renderDivider('divider-plugins'));
|
|
|
|
pluginDividerAdded = true;
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
buttons.push(renderButton(section));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-11-12 17:01:14 +02:00
|
|
|
<StyledRoot role='tablist'>
|
2020-09-15 15:01:07 +02:00
|
|
|
{buttons}
|
|
|
|
</StyledRoot>
|
|
|
|
);
|
|
|
|
}
|