Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: minimap active state #263

Merged
merged 8 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ export const MP: Story = {
onLinkClick: link => alert(link.href),
onUnauthorizedClick: link => alert(`unauthorized ${link?.href} `),
unauthorizedLinks: ['dataPlatform'],
activeLink: 'oversight',
links: [
{ linkId: 'oversight', href: '/oversight' },
{ linkId: 'dataPlatform', href: '/data-platform' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export interface IMiniMapOptions {
onLinkClick: (link: MiniMapLink) => void
onUnauthorizedClick: (link?: MiniMapLink) => void
unauthorizedLinks: MiniMapLinks[]
activeLink: MiniMapLinks
}
2 changes: 2 additions & 0 deletions src/components/navigation/GlobalNavigation/HomeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function MinimapWithPopover(props: MinimapWithPopoverProps) {
links={props.links}
onLinkClick={props.onLinkClick}
unauthorizedLinks={props.unauthorizedLinks}
activeLink={props.activeLink}
/>
)}
placement="rightBottom"
Expand Down Expand Up @@ -68,6 +69,7 @@ export function HomeButton(props: HomeButtonProps) {
onLinkClick={props.minimapOptions.onLinkClick}
unauthorizedLinks={props.minimapOptions.unauthorizedLinks}
onPopoverClick={props.onMpHomeClick}
activeLink={props.minimapOptions.activeLink}
/>
)
}
1 change: 1 addition & 0 deletions src/components/navigation/MiniMap/MiniMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Minimap = (props: IMiniMapProps) => {
href: link.href,
variant: 'drop-shadow',
isUnauthorized: props.unauthorizedLinks.includes(link.linkId),
isActive: props.activeLink === link.linkId,
}))

return (
Expand Down
14 changes: 8 additions & 6 deletions src/components/navigation/MiniMap/SvgLinker.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { Children, ReactElement, useState } from 'react'
import React, { Children, ReactElement } from 'react'
import './miniMap.css'

export interface ISvgLink {
elementId: string
href: string
variant?: 'regular' | 'black' | 'drop-shadow'
isUnauthorized?: boolean
isActive?: boolean
}

interface ISvgLinkerProps {
Expand All @@ -15,29 +16,30 @@ interface ISvgLinkerProps {
}

export const SvgLinker = (props: ISvgLinkerProps) => {
const [activeLink, setActiveLink] = useState<string | null>(null)

const handleContainerClick = (e: React.MouseEvent) => {
e.preventDefault()
const target = e.target as HTMLElement
const href = target.closest('a')?.getAttribute('href')
const link = props.links.find(b => b.href === href)

if (link) {
!link.isUnauthorized && setActiveLink(link.href)
props.onLinkClick(link)
}
}

return <div onClick={handleContainerClick}>{wrapButtonsIntoLinks(props.children)}</div>
return (
<div onClick={handleContainerClick} className="svg-linker__container">
{wrapButtonsIntoLinks(props.children)}
</div>
)
gabyzif marked this conversation as resolved.
Show resolved Hide resolved

function wrapButtonsIntoLinks(parent: React.ReactNode): React.ReactNode {
const wrapElement = (element: ReactElement): ReactElement => {
const { id, children } = element.props
const link = props.links.find(b => b.elementId === id)

if (link) {
const isActiveClass = link.href === activeLink && ' svg-linker-root__button--active'
const isActiveClass = link.isActive && ' svg-linker-root__button--active'
const isUnauthorizedClass = link.isUnauthorized && ' svg-linker-root__button--disabled'
gabyzif marked this conversation as resolved.
Show resolved Hide resolved
const linkStateClass = isActiveClass || isUnauthorizedClass

Expand Down
3 changes: 3 additions & 0 deletions src/components/navigation/MiniMap/miniMap.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.svg-linker__container svg {
overflow: visible;
}
/* disabled general */
.svg-linker-root__button.svg-linker-root__button--disabled {
cursor: default;
Expand Down
2 changes: 1 addition & 1 deletion src/components/navigation/MiniMap/minimap-svg.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

export const minimap = (
<svg width="385" height="374" viewBox="0 0 385 374" fill="none" xmlns="http://www.w3.org/2000/svg" className="u-overflow-visible">
<svg width="385" height="374" viewBox="0 0 385 374" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="mini map content" clipPath="url(#clip0_5505_13516)">
<rect width="385" height="374" fill="white" />
<g id="Frame 481773" clipPath="url(#clip1_5505_13516)">
Expand Down
4 changes: 0 additions & 4 deletions src/utils/utils.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@
.u-padding-sm {
padding:var(--padding-sm) !important;
}

.u-overflow-visible {
overflow: visible !important;
}
Loading