Skip to content

Commit

Permalink
feat: add possibility to add background color to the suite icon logo (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gabyzif authored May 22, 2024
1 parent 873bc8b commit d4c206a
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/components/general/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Icons } from 'src/constants/Icons'
import './icon.css'

type IconSize = 'xxxxl' | 'xxxl' | 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs'
type IconColor =
export type IconColor =
| 'default'
| 'primary'
| 'success'
Expand Down Expand Up @@ -32,4 +32,4 @@ export const Icon = (props: IIconProps) => {
Icon.defaultProps = {
color: 'default',
size: 'lg',
} satisfies Partial<IIconProps>
} satisfies Partial<IIconProps>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { useNewExperienceReminder } from 'src/hooks/NewExperienceReminder/useNew

const defaultLogo: IGlobalNavigationLogo = {
label: 'Aqua',
icon: <Icon name="alicorn" />,
icon: <Icon name="alicorn" size="xxl" color="brand" />,
type: 'custom-size',
onSuiteLogoClick: () => {
alert('Going to Aqua Home!')
},
Expand Down Expand Up @@ -165,7 +166,25 @@ export const Primary: Story = {

const mpLogo: IGlobalNavigationLogo = {
label: 'Data Platform',
icon: <Icon name="mpLogo" />,
icon: <Icon name="siteMap" />,
onSuiteLogoClick: () => {
alert('Going to mP Home!')
},
}

const mpLogoWithBackground: IGlobalNavigationLogo = {
label: 'Data Platform',
icon: 'catalog',
type: 'background-solid',
onSuiteLogoClick: () => {
alert('Going to mP Home!')
},
}

const mpLogoWithoutCustomSizeLogo: IGlobalNavigationLogo = {
label: 'Data Platform',
icon: 'catalog',
type: 'default',
onSuiteLogoClick: () => {
alert('Going to mP Home!')
},
Expand Down Expand Up @@ -834,7 +853,8 @@ export const Indicative: Story = {

const cortexLogo: IGlobalNavigationLogo = {
label: 'Predictions',
icon: <Icon name="sparkles" />,
icon: 'sparkles',
type: 'background-solid',
onSuiteLogoClick: () => {
alert('Going to Predictions Home!')
},
Expand Down Expand Up @@ -1063,3 +1083,69 @@ export const UseNewExperienceReminderHook: Story = {
},
},
}

export const MPWithoutLogo: Story = {
args: {
onSearchClick: () => {
alert('Searching!')
},
logo: {
onSuiteLogoClick: () => {},
label: '',
},
tools: mpTools,
management: mpManagement,
orgs: mpOrgs,
minimapOptions: { overviewHref: '/', show: true },
onMpHomeClick: () => {
alert('going to overview map')
},
avatarOptions: {
// src: "https://static-qa1.qa.corp.mparticle.com/appimg/logo_af_916397d2-9732-8de6-77cc-80e3bba120ca.png",
alt: 'avatar',
},
showSuiteLogo: false,
},
}

export const MPWithBackgroundLogo: Story = {
args: {
onSearchClick: () => {
alert('Searching!')
},
logo: mpLogoWithBackground,
tools: mpTools,
management: mpManagement,
orgs: mpOrgs,
minimapOptions: { overviewHref: '/', show: true },
onMpHomeClick: () => {
alert('going to overview map')
},
avatarOptions: {
// src: "https://static-qa1.qa.corp.mparticle.com/appimg/logo_af_916397d2-9732-8de6-77cc-80e3bba120ca.png",
alt: 'avatar',
},
showSuiteLogo: true,
},
}

export const MPWithoutCustomSizeLogo: Story = {
args: {
onSearchClick: () => {
alert('Searching!')
},
logo: mpLogoWithoutCustomSizeLogo,
tools: mpTools,
management: mpManagement,
orgs: mpOrgs,
minimapOptions: { overviewHref: '/', show: true },
onMpHomeClick: () => {
alert('going to overview map')
},
avatarOptions: {
// src: "https://static-qa1.qa.corp.mparticle.com/appimg/logo_af_916397d2-9732-8de6-77cc-80e3bba120ca.png",
alt: 'avatar',
},
showSuiteLogo: true,
},
}
13 changes: 11 additions & 2 deletions src/components/navigation/GlobalNavigation/GlobalNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IGlobalNavigationProps {
onSuiteLogoClick?: () => void
onMpHomeClick: () => void
hideMpHome?: boolean
showSuiteLogo?: boolean
avatarOptions?: IAvatarProps
navigationButtonItemOptions?: {
label: string
Expand All @@ -50,8 +51,12 @@ export const GlobalNavigation = (props: IGlobalNavigationProps) => {
<Layout.Sider className="globalNavigation__sider" width={GlobalNavWidth}>
<Flex vertical justify="space-between" style={{ height: '100%' }}>
<div>
<SuiteLogo {...props.logo} />
<div className="globalNavigation__divider" />
{props.showSuiteLogo && (
<>
<SuiteLogo {...props.logo} />
<div className="globalNavigation__divider" />
</>
)}
<Center vertical>
{props.onSearchClick && <NavigationSearch onClick={props.onSearchClick} />}
{props.createItems && <NavigationCreate createItems={props.createItems} />}
Expand Down Expand Up @@ -88,3 +93,7 @@ export const GlobalNavigation = (props: IGlobalNavigationProps) => {
}

GlobalNavigation.useNewExperienceReminder = useNewExperienceReminder

GlobalNavigation.defaultProps = {
showSuiteLogo: true,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReactNode, type MouseEvent } from 'react'
import type { ReactNode, type MouseEvent, ReactElement } from 'react'
import { type HrefOptions } from 'src/utils/utils'
import { Icons } from 'src/constants/Icons'

export interface IBaseGlobalNavigationItem {
type?: 'menu' | 'link'
Expand All @@ -11,6 +12,8 @@ export interface IBaseGlobalNavigationItem {

export interface IGlobalNavigationLogo extends IBaseGlobalNavigationItem {
onSuiteLogoClick: () => void
type?: 'default' | 'background-solid' | 'custom-size'
icon?: ReactElement | keyof typeof Icons
}

export interface IGlobalNavigationMenu extends IBaseGlobalNavigationItem {
Expand Down
37 changes: 32 additions & 5 deletions src/components/navigation/GlobalNavigation/SuiteLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
import { Center } from 'src/components'
import React, { ReactElement, ReactNode } from 'react'
import { Center, Icon } from 'src/components'
import { NavigationIcon } from 'src/components/navigation/GlobalNavigation/NavigationIcon'
import { Icons } from 'src/constants/Icons'
import { type IGlobalNavigationLogo } from 'src/components/navigation/GlobalNavigation/GlobalNavigationItems'
import { IconColor } from 'src/components/general/Icon/Icon'

// custom-size is the default size to prevent breaking changes.
function isStringIcon(icon: ReactNode | string): icon is keyof typeof Icons {
return typeof icon === 'string'
}

export function SuiteLogo({ icon, label, type = 'custom-size', onSuiteLogoClick }: IGlobalNavigationLogo) {
const classMap = {
default: '',
'custom-size': 'globalNavigation__icon--suiteLogo',
'background-solid': 'globalNavigation__icon--suiteBackground',
}

const iconColorMap: { [key in 'default' | 'background-solid' | 'custom-size']: IconColor } = {
default: 'default',
'background-solid': 'brand',
'custom-size': 'default',
}

const getIcon = () => {
if (isStringIcon(icon)) {
return <Icon name={icon} color={iconColorMap[type]} size="xxl" />
}
return icon
}

export function SuiteLogo(props: IGlobalNavigationLogo) {
return (
<Center vertical className="globalNavigation__suiteLogo" onClick={props.onSuiteLogoClick}>
<NavigationIcon icon={props.icon} label="" hideLabel className="globalNavigation__icon--suiteLogo" />
{props.label}
<Center vertical className="globalNavigation__suiteLogo" onClick={onSuiteLogoClick}>
<NavigationIcon icon={getIcon()} label="" hideLabel className={classMap[type]} />
{label}
</Center>
)
}
18 changes: 13 additions & 5 deletions src/components/navigation/GlobalNavigation/global-navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@
padding-bottom: var(--padding-xxs);
}

.globalNavigation__icon.globalNavigation__icon--suiteLogo svg {
width: 36px;
height: 36px;
}

.globalNavigation__menu .globalNavigation__iconLabel {
margin-top: var(--margin-xxs);
}
Expand Down Expand Up @@ -295,6 +290,19 @@
cursor: pointer;
}

.globalNavigation__icon--suiteBackground {
background-color: var(--mp-brand-primary-2);
padding: 10px;
margin-bottom: 8px;
border-radius: 100%;
}

.globalNavigation__icon.globalNavigation__icon--suiteLogo svg {
width: 36px;
height: 36px;

}

.globalNavigation__divider {
border-bottom: 1px solid var(--color-border-secondary);
margin-right: var(--margin-sm);
Expand Down

0 comments on commit d4c206a

Please sign in to comment.