Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright Oxide Computer Company
*/
import cn from 'classnames'
import { NavLink } from 'react-router-dom'
import { NavLink, useLocation } from 'react-router-dom'

import { Action16Icon, Document16Icon } from '@oxide/design-system/icons/react'

Expand Down Expand Up @@ -88,20 +88,24 @@ export const NavLinkItem = (props: {
children: React.ReactNode
end?: boolean
disabled?: boolean
}) => (
<li>
<NavLink
to={props.to}
className={({ isActive }) =>
cn(linkStyles, {
'text-accent !bg-accent-secondary hover:!bg-accent-secondary-hover svg:!text-accent-tertiary':
isActive,
'pointer-events-none text-disabled': props.disabled,
})
}
end={props.end}
>
{props.children}
</NavLink>
</li>
)
}) => {
// If the current page is the create form for this NavLinkItem's resource, highlight the NavLink in the sidebar
const currentPathIsCreateForm = useLocation().pathname.startsWith(`${props.to}-new`)
return (
<li>
<NavLink
to={props.to}
className={({ isActive }) =>
cn(linkStyles, {
'text-accent !bg-accent-secondary hover:!bg-accent-secondary-hover svg:!text-accent-tertiary':
isActive || currentPathIsCreateForm,
'pointer-events-none text-disabled': props.disabled,
})
}
end={props.end}
>
{props.children}
</NavLink>
</li>
)
}