feat: theme add sidebar activeBackgroundColor and activeTextColor (#1600)

This commit is contained in:
Loïc Fürhoff 2022-04-07 15:51:52 +02:00 committed by GitHub
parent a160498089
commit 6716b08e88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 20 deletions

View File

@ -285,21 +285,25 @@ You can use all of the following options with the standalone version of the <red
* `color`: # COMPUTED: colors.primary.main * `color`: # COMPUTED: colors.primary.main
* `visited`: # COMPUTED: typography.links.color * `visited`: # COMPUTED: typography.links.color
* `hover`: # COMPUTED: lighten(0.2 typography.links.color) * `hover`: # COMPUTED: lighten(0.2 typography.links.color)
* `menu` * `sidebar`
* `width`: '260px' * `width`: '260px'
* `backgroundColor`: '#fafafa' * `backgroundColor`: '#fafafa'
* `textColor`: '#333333' * `textColor`: '#333333'
* `activeTextColor`: # COMPUTED: theme.menu.textColor (if set by user) or theme.colors.primary.main * `activeTextColor`: # COMPUTED: theme.sidebar.textColor (if set by user) or theme.colors.primary.main
* `groupItems` # Group headings * `groupItems` # Group headings
* `activeBackgroundColor`: # COMPUTED: theme.sidebar.backgroundColor
* `activeTextColor`: # COMPUTED: theme.sidebar.activeTextColor
* `textTransform`: 'uppercase' * `textTransform`: 'uppercase'
* `level1Items` # Level 1 items like tags or section 1st level items * `level1Items` # Level 1 items like tags or section 1st level items
* `activeBackgroundColor`: # COMPUTED: theme.sidebar.backgroundColor
* `activeTextColor`: # COMPUTED: theme.sidebar.activeTextColor
* `textTransform`: 'none' * `textTransform`: 'none'
* `arrow` # menu arrow * `arrow` # sidebar arrow
* `size`: '1.5em' * `size`: '1.5em'
* `color`: # COMPUTED: theme.menu.textColor * `color`: # COMPUTED: theme.sidebar.textColor
* `logo` * `logo`
* `maxHeight`: # COMPUTED: menu.width * `maxHeight`: # COMPUTED: sidebar.width
* `maxWidth`: # COMPUTED: menu.width * `maxWidth`: # COMPUTED: sidebar.width
* `gutter`: '2px' # logo image padding * `gutter`: '2px' # logo image padding
* `rightPanel` * `rightPanel`
* `backgroundColor`: '#263238' * `backgroundColor`: '#263238'

View File

@ -66,11 +66,12 @@ export const OperationBadge = styled.span.attrs((props: { type: string }) => ({
} }
`; `;
function menuItemActiveBg(depth, { theme }: { theme: ResolvedThemeInterface }): string {
function menuItemActive(depth, { theme }: { theme: ResolvedThemeInterface }, option: string): string {
if (depth > 1) { if (depth > 1) {
return darken(0.1, theme.sidebar.backgroundColor); return theme.sidebar.level1Items[option];
} else if (depth === 1) { } else if (depth === 1) {
return darken(0.05, theme.sidebar.backgroundColor); return theme.sidebar.groupItems[option];
} else { } else {
return ''; return '';
} }
@ -102,17 +103,10 @@ export const menuItemDepth = {
font-size: 0.8em; font-size: 0.8em;
padding-bottom: 0; padding-bottom: 0;
cursor: default; cursor: default;
color: ${props => props.theme.sidebar.textColor};
`, `,
1: css` 1: css`
font-size: 0.929em; font-size: 0.929em;
text-transform: ${({ theme }) => theme.sidebar.level1Items.textTransform}; text-transform: ${({ theme }) => theme.sidebar.level1Items.textTransform};
&:hover {
color: ${props => props.theme.sidebar.activeTextColor};
}
`,
2: css`
color: ${props => props.theme.sidebar.textColor};
`, `,
}; };
@ -131,7 +125,7 @@ export const MenuItemLabel = styled.label.attrs((props: MenuItemLabelType) => ({
}))<MenuItemLabelType>` }))<MenuItemLabelType>`
cursor: pointer; cursor: pointer;
color: ${props => color: ${props =>
props.active ? props.theme.sidebar.activeTextColor : props.theme.sidebar.textColor}; props.active ? menuItemActive(props.depth, props, 'activeTextColor') : props.theme.sidebar.textColor};
margin: 0; margin: 0;
padding: 12.5px ${props => props.theme.spacing.unit * 4}px; padding: 12.5px ${props => props.theme.spacing.unit * 4}px;
${({ depth, type, theme }) => ${({ depth, type, theme }) =>
@ -140,12 +134,14 @@ export const MenuItemLabel = styled.label.attrs((props: MenuItemLabelType) => ({
justify-content: space-between; justify-content: space-between;
font-family: ${props => props.theme.typography.headings.fontFamily}; font-family: ${props => props.theme.typography.headings.fontFamily};
${props => menuItemDepth[props.depth]}; ${props => menuItemDepth[props.depth]};
background-color: ${props => (props.active ? menuItemActiveBg(props.depth, props) : '')}; background-color: ${props =>
props.active ? menuItemActive(props.depth, props, 'activeBackgroundColor') : props.theme.sidebar.backgroundColor};
${props => (props.deprecated && deprecatedCss) || ''}; ${props => (props.deprecated && deprecatedCss) || ''};
&:hover { &:hover {
background-color: ${props => menuItemActiveBg(props.depth, props)}; color: ${props => menuItemActive(props.depth, props, 'activeTextColor')};
background-color: ${props => menuItemActive(props.depth, props, 'activeBackgroundColor')};
} }
${ShelfIcon} { ${ShelfIcon} {

View File

@ -139,9 +139,13 @@ const defaultTheme: ThemeInterface = {
? theme.sidebar.textColor ? theme.sidebar.textColor
: theme.colors.primary.main, : theme.colors.primary.main,
groupItems: { groupItems: {
textTransform: 'uppercase', activeBackgroundColor: theme => darken(0.1, theme.sidebar.backgroundColor),
activeTextColor: theme => theme.sidebar.activeTextColor,
textTransform: 'uppercase'
}, },
level1Items: { level1Items: {
activeBackgroundColor: theme => darken(0.05, theme.sidebar.backgroundColor),
activeTextColor: theme => theme.sidebar.activeTextColor,
textTransform: 'none', textTransform: 'none',
}, },
arrow: { arrow: {
@ -319,9 +323,13 @@ export interface ResolvedThemeInterface {
textColor: string; textColor: string;
activeTextColor: string; activeTextColor: string;
groupItems: { groupItems: {
activeBackgroundColor: string;
activeTextColor: string;
textTransform: string; textTransform: string;
}; };
level1Items: { level1Items: {
activeBackgroundColor: string;
activeTextColor: string;
textTransform: string; textTransform: string;
}; };
arrow: { arrow: {