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
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export const MP: Story = {
overviewHref: '/',
onLinkClick: link => alert(link.href),
onUnauthorizedClick: link => alert(`unauthorized ${link?.href} `),
unauthorizedLinks: ['oversight', 'dataPlatform'],
unauthorizedLinks: ['dataPlatform'],
links: [
{ linkId: 'oversight', href: '/oversight' },
{ linkId: 'dataPlatform', href: '/data-platform' },
Expand Down
17 changes: 12 additions & 5 deletions src/components/navigation/MiniMap/SvgLinker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Children, ReactElement } from 'react'
import React, { Children, ReactElement, useState } from 'react'
import './miniMap.css'

export interface ISvgLink {
Expand All @@ -15,13 +15,18 @@ 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) props.onLinkClick(link)
if (link) {
!link.isUnauthorized && setActiveLink(link.href)
props.onLinkClick(link)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this will work in CDP, because I believe the MiniMap is been unmounted and mounted again when switching suites (would need to confirmate)
If that's true, you probably need to receive the active as a prop, probably as a field in the link obj

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, when opening/refreshing the app using the full URL, you will not set the active suite.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GlobalNav already knows the current route. We don't have to couple to the Nav, but just like the Nav is getting the route, MiniMap should to. Because:

  1. Consistency
  2. One solution that works in all cases
  3. Makes the Mini dumb which makes it easy to understand.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you're curious, this is where the current route comes from, and it updates whenever the route changes.

}
}

return <div onClick={handleContainerClick}>{wrapButtonsIntoLinks(props.children)}</div>
Expand All @@ -32,9 +37,11 @@ export const SvgLinker = (props: ISvgLinkerProps) => {
const link = props.links.find(b => b.elementId === id)

if (link) {
const className = `svg-linker-root__button svg-linker-root__button--${link.variant}${
link.isUnauthorized ? ' svg-linker-root__button--disabled' : ''
}`
const isActiveClass = link.href === activeLink && ' svg-linker-root__button--active'
const isUnauthorizedClass = link.isUnauthorized && ' svg-linker-root__button--disabled'
const linkStateClass = isActiveClass || isUnauthorizedClass

const className = `svg-linker-root__button svg-linker-root__button--${link.variant} ${linkStateClass} `

return (
<a key={id} href={link.href} className={className}>
Expand Down
21 changes: 21 additions & 0 deletions src/components/navigation/MiniMap/miniMap.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* disabled general */
.svg-linker-root__button.svg-linker-root__button--disabled {
cursor: default;
}

/* disabled variant-regular */
.svg-linker-root__button.svg-linker-root__button--disabled.svg-linker-root__button--regular rect:first-child {
fill: transparent;
stroke: var(--color-border);
Expand All @@ -15,6 +17,8 @@
fill: transparent;
}


/* disabled - variant: shadow */
.svg-linker-root__button.svg-linker-root__button--disabled.svg-linker-root__button--drop-shadow > g > g > rect {
fill: var(--mp-brand-secondary-3);
}
Expand All @@ -27,6 +31,7 @@
filter: none;
}

/* disabled - variant: black */
.svg-linker-root__button.svg-linker-root__button--disabled.svg-linker-root__button--black rect:first-child {
fill: var(--mp-brand-secondary-6);
}
Expand All @@ -35,14 +40,30 @@
fill: var(--mp-brand-secondary-6);
}

/* general - variant: shadow */
.svg-linker-root__button.svg-linker-root__button--drop-shadow:hover {
filter: drop-shadow(0px 9px 28px rgba(0, 0, 0, 0.05)) drop-shadow(0px 3px 6px rgba(0, 0, 0, 0.12)) drop-shadow(0px 6px 16px rgba(0, 0, 0, 0.08));
}

/* general - variant: black */
.svg-linker-root__button.svg-linker-root__button--regular:hover rect:first-child {
fill: var(--mp-brand-primary-2);
}

.svg-linker-root__button.svg-linker-root__button--black:hover rect:first-child {
fill: var(--mp-brand-secondary-7);
}

/* for the active state */
.svg-linker-root__button--active > g > rect + rect {
stroke: var(--mp-brand-primary-6);
stroke-width: var(--line-width-bold)
}

/* some fixes so the shadow on hover looks good without changing the svg */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question Is this going to break when we change the SVG?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if they make edits on the minimap following the current svg, it should be good...

#clip0_5505_13516 {
display: none;
}
#Frame\ 481773 > #Frame\ 481772 > rect {
display: none;
}
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">
<svg width="385" height="374" viewBox="0 0 385 374" fill="none" xmlns="http://www.w3.org/2000/svg" className="u-overflow-visible">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question How are we going to remember to keep this here when we replace the SVG?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add it though css maybe its better

<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
6 changes: 5 additions & 1 deletion src/utils/utils.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
}

.u-padding-sm {
padding:var(--padding-sm)
padding:var(--padding-sm) !important;
}

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