Skip to content

Commit

Permalink
🎨 tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle committed Jan 23, 2025
1 parent 431b6fc commit 92debd5
Show file tree
Hide file tree
Showing 13 changed files with 340 additions and 222 deletions.
5 changes: 5 additions & 0 deletions sanityv3/schemas/textSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,11 @@ const snippets: textSnippet = {
defaultValue: 'Featured content',
group: groups.common,
},
local: {
title: 'Local',
defaultValue: 'Local',
group: groups.common,
},
}

type textSnippetGroup = { title: string; hidden?: boolean }
Expand Down
2 changes: 1 addition & 1 deletion web/core/Link/LogoLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const LogoLink = ({ className, ...rest }: LogoLinkProps) => {
)}
prefetch={false}
>
<LogoSecondary className="-mt-[12%]" />
<LogoSecondary className="-mt-[5%]" />
</NextLink>
)
}
Expand Down
104 changes: 52 additions & 52 deletions web/core/Link/ResourceLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,58 @@ export type ResourceLinkProps = {
showExtensionIcon?: boolean
} & Omit<BaseLinkProps, 'type'>

export const iconRotation: Record<string, string> = {
externalUrl: '-rotate-45',
downloadableFile: 'rotate-90',
downloadableImage: 'rotate-90',
internalUrl: '',
}

export const getArrowAnimation = (type: LinkType) => {
switch (type) {
case 'downloadableFile':
case 'downloadableImage':
return 'group-hover:translate-y-0.5'
case 'anchorLink':
return 'translate-y-0.5 group-hover:translate-y-2'
case 'icsLink':
return 'translate-y-0.5'
default:
return 'translate-y-0.5 group-hover:translate-x-2'
}
}

export const getArrowElement = (type: LinkType, iconClassName: string) => {
const iconClassNames = envisTwMerge(
`size-arrow-right
text-energy-red-100
dark:text-white-100
justify-self-end
${iconRotation[type]}
${getArrowAnimation(type)}
transition-all
duration-300
`,
iconClassName,
)
const marginClassName = `ml-6 xl:ml-8`

switch (type) {
case 'downloadableFile':
case 'downloadableImage':
return (
<div className={`flex flex-col px-1 ${marginClassName} translate-y-[1px]`}>
<ArrowRight className={iconClassNames} />
<div className="bg-energy-red-100 h-[2px] w-full" />
</div>
)
case 'icsLink':
return <TransformableIcon iconData={add} className={`${marginClassName} ${iconClassNames}`} />
default:
return <ArrowRight className={`${marginClassName} ${iconClassNames}`} />
}
}

export const ResourceLink = forwardRef<HTMLAnchorElement, ResourceLinkProps>(function ResourceLink(
{
variant = 'default',
Expand All @@ -41,58 +93,6 @@ export const ResourceLink = forwardRef<HTMLAnchorElement, ResourceLinkProps>(fun
},
ref,
) {
const iconRotation: Record<string, string> = {
externalUrl: '-rotate-45',
downloadableFile: 'rotate-90',
downloadableImage: 'rotate-90',
internalUrl: '',
}

const getArrowAnimation = (type: LinkType) => {
switch (type) {
case 'downloadableFile':
case 'downloadableImage':
return 'group-hover:translate-y-0.5'
case 'anchorLink':
return 'translate-y-0.5 group-hover:translate-y-2'
case 'icsLink':
return 'translate-y-0.5'
default:
return 'translate-y-0.5 group-hover:translate-x-2'
}
}

const getArrowElement = (type: LinkType, iconClassName: string) => {
const iconClassNames = envisTwMerge(
`size-arrow-right
text-energy-red-100
dark:text-white-100
justify-self-end
${iconRotation[type]}
${getArrowAnimation(type)}
transition-all
duration-300
`,
iconClassName,
)
const marginClassName = `ml-6 xl:ml-8`

switch (type) {
case 'downloadableFile':
case 'downloadableImage':
return (
<div className={`flex flex-col px-1 ${marginClassName} translate-y-[1px]`}>
<ArrowRight className={iconClassNames} />
<div className="bg-energy-red-100 h-[2px] w-full" />
</div>
)
case 'icsLink':
return <TransformableIcon iconData={add} className={`${marginClassName} ${iconClassNames}`} />
default:
return <ArrowRight className={`${marginClassName} ${iconClassNames}`} />
}
}

const variantClassName: Partial<Record<Variants, string>> = {
default: 'w-full pt-3',
fit: 'w-fit pt-3',
Expand Down
70 changes: 37 additions & 33 deletions web/core/Link/StickyMenuLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { twMerge } from 'tailwind-merge'
import { BaseLink, BaseLinkProps } from './BaseLink'
import { TransformableIcon } from '../../icons/TransformableIcon'
import { arrow_down, library_pdf } from '@equinor/eds-icons'
import { PiFilePdfThin } from 'react-icons/pi'
import { ArrowRight } from 'icons'
import envisTwMerge from 'twMerge'
import { getArrowAnimation, iconRotation } from './ResourceLink'

export type StickMenuLinkProps = {
isDownloadable?: boolean
Expand All @@ -13,43 +17,43 @@ export const StickyMenuLink = forwardRef<HTMLAnchorElement, StickMenuLinkProps>(
{ children, type = 'internalUrl', className = '', href = '', isDownloadable = false, ...rest },
ref,
) {
const classNames = twMerge(
`
group
inline-flex
align-baseline
w-fit
text-slate-80
leading-0
`,
className,
)
const contentClassNames = `
relative
w-fit
hover:underline
no-underline
const iconClassNames = `size-arrow-right
text-energy-red-100
dark:text-white-100
rotate-90
group-hover:translate-y-0.5
transition-all
duration-300
`

return (
<BaseLink className={classNames} ref={ref} href={href} {...rest}>
{isDownloadable && <TransformableIcon iconData={library_pdf} className="mr-1" />}
<div className={contentClassNames}>{children}</div>
{isDownloadable && (
<TransformableIcon
iconData={arrow_down}
className="text-energy-red-100
dark:text-white-100 h-[22px] border-energy-red-100 border-b-2 ml-4"
/>
)}
{!isDownloadable && (
<TransformableIcon
iconData={arrow_down}
className="text-energy-red-100
dark:text-white-100
ml-4"
/>
<BaseLink
className={twMerge(
`group
relative
flex
justify-center
w-fit
underline-offset-2
text-slate-80
text-sm`,
className,
)}
ref={ref}
href={href}
{...rest}
>
{isDownloadable && <PiFilePdfThin className="mr-2" />}
<div className={`w-fit group-hover:underline no-underline leading-none align-middle`}>{children}</div>
{/* {isDownloadable && (
<div className={`flex flex-col px-1 ml-2 xl:ml-4 -translate-y-[3px]`}>
<ArrowRight className={iconClassNames} />
<div className="bg-energy-red-100 h-[2px] w-full" />
</div>
)} */}
{/* {!isDownloadable && (
<TransformableIcon iconData={arrow_down} className="text-energy-red-100 dark:text-white-100 ml-4" />
)} */}
</BaseLink>
)
})
Expand Down
2 changes: 1 addition & 1 deletion web/core/MenuAccordion/MenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const MenuButton = forwardRef<HTMLButtonElement, MenuButtonProps>(functio
outline-none
text-slate-80
text-base
font-medium
font-normal
leading-[1em]
md:grid-cols-[min-content_1fr]
hover:bg-moss-green-60
Expand Down
110 changes: 110 additions & 0 deletions web/core/Topbar/Topbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { forwardRef, HTMLAttributes, useEffect, useMemo, useRef, useState } from 'react'
import { mergeRefs } from '@equinor/eds-utils'
import { StickyMenuData } from '../../types/index'
import StickyMenu from '@sections/StickyMenu/StickyMenu'

export type TopbarProps = {
stickyMenuData?: StickyMenuData
} & HTMLAttributes<HTMLDivElement>

export const Topbar = forwardRef<HTMLDivElement, TopbarProps>(function Topbar(
{ stickyMenuData, children, ...rest },
ref,
) {
const topbarRef = useRef<HTMLDivElement>(null)
const combinedTopbarRef = useMemo(() => mergeRefs<HTMLDivElement>(topbarRef, ref), [topbarRef, ref])

const [height, setHeight] = useState(0)
const [prevScrollPos, setPrevScrollPos] = useState(0)
const [isVisible, setIsVisible] = useState(true)
const [hasDropShadow, setHasDropShadow] = useState(false)

useEffect(() => {
if (topbarRef && topbarRef?.current) {
setHeight(topbarRef.current.getBoundingClientRect().height)
}
}, [setHeight, topbarRef])

useEffect(() => {
const handleScroll = () => {
let currentScrollPos = window.scrollY
// Fix for iOS to avoid negative scroll positions
if (currentScrollPos < 0) currentScrollPos = 0

setIsVisible(
(prevScrollPos > currentScrollPos && prevScrollPos - currentScrollPos > height) ||
currentScrollPos < prevScrollPos ||
(currentScrollPos === 0 && prevScrollPos === 0),
)

if (!stickyMenuData) {
// Why so complicated? To attempt to limit the amount of calls to setHasDropShadow
if (currentScrollPos < 50) {
if (hasDropShadow) {
setHasDropShadow(false)
}
} else {
if (prevScrollPos > currentScrollPos) {
if (!hasDropShadow) {
setHasDropShadow(true)
}
} else if (prevScrollPos < currentScrollPos && hasDropShadow) {
setHasDropShadow(false)
}
}
}

setPrevScrollPos(currentScrollPos)
}

window.addEventListener('scroll', handleScroll)

return () => {
window.removeEventListener('scroll', handleScroll)
}
}, [prevScrollPos, isVisible, height, hasDropShadow, stickyMenuData])

useEffect(() => {
if (topbarRef && topbarRef?.current) {
const topbar = topbarRef.current

const handleFocus = (event: FocusEvent) => {
if (!isVisible) {
topbar.contains(event.target as Node) && setIsVisible(true)
}
}

topbar.addEventListener('focusin', handleFocus)

return () => topbar.removeEventListener('focusin', handleFocus)
}
}, [isVisible, topbarRef])

const animateScrollUpClassName = `
[will-change:transform]
[transition-behavior:allow-discrete]
animate-height
${isVisible ? 'top-0' : '-top-[var(--topbar-height)]'}
[transition-property:height]
[transition-property:padding]
ease-in-out
duration-400
`

return (
<>
<div
ref={combinedTopbarRef}
className={`w-screen sticky bg-white-100 z-40 ${animateScrollUpClassName}
${hasDropShadow ? 'shadow-top-bar' : ''}`}
{...rest}
>
<div className="px-layout-sm max-w-viewport mx-auto flex items-center justify-between py-4">{children}</div>
</div>
{stickyMenuData && (
<StickyMenu stickyMenuData={stickyMenuData} className={`${isVisible ? 'top-[80px] pt-2' : 'top-0'}`} />
)}
</>
)
})
export default Topbar
Loading

0 comments on commit 92debd5

Please sign in to comment.