Skip to content

Commit 21982ec

Browse files
joepioPolleps
authored andcommitted
Improve hover / active / current states in sidebar #1105
1 parent c715351 commit 21982ec

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

browser/data-browser/src/components/SideBar/SideBarDrive.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export function SideBarDrive({
7373
<TitleButton
7474
resource={drive}
7575
clean
76+
current={drive === currentSubject}
7677
title={`Your current baseURL is ${drive}`}
7778
data-test='sidebar-drive-open'
7879
onClick={() => {
@@ -161,9 +162,24 @@ const DriveTitle = styled.h2`
161162
flex: 1;
162163
`;
163164

164-
const TitleButton = styled(Button)`
165+
const TitleButton = styled(Button)<{ current?: boolean }>`
165166
text-align: left;
166167
flex: 1;
168+
padding: 0.5rem 1rem;
169+
border-radius: ${props => props.theme.radius};
170+
171+
${({ current, theme }) =>
172+
current &&
173+
`
174+
color: ${theme.colors.main};
175+
`}
176+
177+
&:hover {
178+
background-color: ${props => props.theme.colors.bg1};
179+
}
180+
&:active {
181+
background-color: ${props => props.theme.colors.bg2};
182+
}
167183
`;
168184

169185
const SideBarErr = styled(ErrorLook)`

browser/data-browser/src/components/SideBar/SideBarItem.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { styled } from 'styled-components';
22

33
export interface SideBarItemProps {
44
disabled?: boolean;
5+
current?: boolean;
56
}
67

78
/** SideBarItem should probably be wrapped in an AtomicLink for optimal behavior */
@@ -20,12 +21,18 @@ export const SideBarItem = styled('span')<SideBarItemProps>`
2021
&:hover,
2122
&:focus {
2223
background-color: ${p => p.theme.colors.bg1};
23-
color: ${p => (p.disabled ? p.theme.colors.main : p.theme.colors.text)};
24+
// color: ${p => (p.disabled ? p.theme.colors.main : p.theme.colors.text)};
2425
}
2526
&:active {
2627
background-color: ${p => p.theme.colors.bg2};
2728
}
2829
30+
${props =>
31+
props.current &&
32+
`
33+
color: ${props.theme.colors.main};
34+
`}
35+
2936
svg {
3037
font-size: 0.8rem;
3138
}

browser/data-browser/src/components/SideBar/SideBarMenuItem.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { styled } from 'styled-components';
22
import { AtomicLink, AtomicLinkProps } from '../AtomicLink';
33
import { SideBarItem } from './SideBarItem';
4+
import { useLocation } from '@tanstack/react-router';
45

56
export interface SideBarMenuItemProps extends AtomicLinkProps {
67
label: string;
@@ -20,9 +21,18 @@ export function SideBarMenuItem({
2021
subject,
2122
onClick,
2223
}: SideBarMenuItemProps) {
24+
const { pathname } = useLocation();
25+
const targetPath = path || href || subject;
26+
const current: boolean = pathname === targetPath;
27+
2328
return (
2429
<AtomicLink href={href} subject={subject} path={path} clean>
25-
<SideBarItem key={label} title={helper} onClick={onClick}>
30+
<SideBarItem
31+
key={label}
32+
title={helper}
33+
onClick={onClick}
34+
current={current}
35+
>
2636
{icon && <SideBarIcon>{icon}</SideBarIcon>}
2737
{label}
2838
</SideBarItem>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Formats a number as a currency string
3+
* @param value - The number to format
4+
* @param currency - The currency code (default: 'USD')
5+
* @param locale - The locale to use for formatting (default: 'en-US')
6+
* @returns A formatted currency string
7+
*/
8+
export

0 commit comments

Comments
 (0)