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

[FX-5690] Migrate PageSidebar to TailwindCSS #4597

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions .changeset/strange-stingrays-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@toptal/picasso-page': patch
'@toptal/picasso': patch
---

### PageSidebar

- migrate `PageSidebar` to TailwindCSS
63 changes: 45 additions & 18 deletions packages/base/Page/src/PageSidebar/PageSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { Theme } from '@material-ui/core/styles'
import { makeStyles } from '@material-ui/core/styles'
import { useSidebar } from '@toptal/picasso-provider'
import type { BaseProps, SizeType } from '@toptal/picasso-shared'
import cx from 'classnames'
import { twMerge } from '@toptal/picasso-tailwind-merge'
import { twMerge, twJoin } from '@toptal/picasso-tailwind-merge'
import type { ReactNode } from 'react'
import React, { forwardRef, useCallback, useEffect, useState } from 'react'
import { ButtonCircular } from '@toptal/picasso-button'
Expand All @@ -20,7 +17,6 @@ import { SidebarItem } from '../SidebarItem'
import { SidebarLogo } from '../SidebarLogo'
import { SidebarMenu } from '../SidebarMenu'
import { SidebarContextProvider } from './SidebarContextProvider'
import styles from './styles'
import type { VariantType } from './types'

export interface Props extends BaseProps {
Expand All @@ -47,9 +43,16 @@ export interface Props extends BaseProps {
onCollapse?: () => void
}

const useStyles = makeStyles<Theme>(styles, {
name: 'PageSidebar',
})
const classesByVariant = {
light: 'shadow-gray-200 bg-gray-100',
dark: 'shadow-graphite-800 bg-graphite-800',
}

const classesBySize = {
small: 'w-[212px]',
medium: 'w-[236px]',
large: 'w-[280px]',
}

export const PageSidebar = forwardRef<HTMLDivElement, Props>(function Sidebar(
props,
Expand All @@ -68,7 +71,7 @@ export const PageSidebar = forwardRef<HTMLDivElement, Props>(function Sidebar(
disableSticky,
onCollapse = noop,
} = props
const classes = useStyles()

const { setHasSidebar } = useSidebar()
const [isCollapsed, setIsCollapsed] = useState(!!defaultCollapsed)
const [isHovered, setIsHovered] = useState(false)
Expand Down Expand Up @@ -101,10 +104,32 @@ export const PageSidebar = forwardRef<HTMLDivElement, Props>(function Sidebar(
<Container
ref={ref}
style={style}
className={cx(classes.root, className, classes[variant], classes[size], {
[classes.rootCollapsed]: collapsible && isCollapsed,
[classes.hamburgerNotAvailable]: !hasTopBar,
})}
className={twMerge(
'h-full',
'shadow-[inset_-1px_0_0_0]',
'text-lg/[inherit]',
'relative',
sashuk marked this conversation as resolved.
Show resolved Hide resolved
'transition-[width] ease-in-out delay-[225ms]',
'hidden min-[1280px]:block',
'[&]:before:absolute',
'[&]:before:content-[""]',
'[&]:before:left-0',
'[&]:before:top-0',
'[&]:before:w-[15.5rem]',
'[&]:before:h-full',
className,
classesByVariant[variant],
classesBySize[size],
'xs:max-md:overflow-y-scroll',
collapsible &&
sashuk marked this conversation as resolved.
Show resolved Hide resolved
isCollapsed && [
'w-[5rem]',
'[&]:before:w-[5.75rem]',
'[&_.scrollable-content]:[-ms-overflow-style:none]',
'[&_.scrollable-content]:[scrollbar-width:none]',
],
sashuk marked this conversation as resolved.
Show resolved Hide resolved
!hasTopBar && 'block'
)}
data-testid={testIds?.container}
onMouseEnter={collapsible ? () => setIsHovered(true) : noop}
onMouseLeave={collapsible ? () => setIsHovered(false) : noop}
Expand All @@ -115,14 +140,16 @@ export const PageSidebar = forwardRef<HTMLDivElement, Props>(function Sidebar(
style={{
maxHeight: wrapperMaxHeight,
}}
className={cx(classes.wrapper, {
[classes.sticky]: !disableSticky,
})}
className={twJoin(
'h-full',
!disableSticky &&
'max-h-[calc(100vh-var(--header-height,3.5rem))] sticky top-[var(--header-height,3.5rem)]'
)}
>
<Container
flex
direction='column'
className={classes.scrollableContent}
className='scrollable-content h-full overflow-y-auto pt-4 pb-2 px-0'
data-testid={testIds?.scrollableContainer}
sashuk marked this conversation as resolved.
Show resolved Hide resolved
>
{collapsible && (
Expand All @@ -139,7 +166,7 @@ export const PageSidebar = forwardRef<HTMLDivElement, Props>(function Sidebar(
data-testid={testIds?.collapseButton}
/>
)}
<div className={classes.spacer} />
<div className='order-[50] flex-1 h-full' />
<SidebarContextProvider
isCollapsed={isCollapsed}
isHovered={isHovered}
Expand Down
24 changes: 12 additions & 12 deletions packages/base/Page/src/PageSidebar/__snapshots__/test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ exports[`PageSidebar renders 1`] = `
class="Picasso-root"
>
<div
class="PageSidebar-root PageSidebar-light PageSidebar-medium PageSidebar-hamburgerNotAvailable"
class="h-full shadow-[inset_-1px_0_0_0] text-lg/[inherit] relative transition-[width] ease-in delay-[225ms] min-[1280px]:block [&]:before:absolute [&]:before:content-[""] [&]:before:left-0 [&]:before:top-0 [&]:before:w-[15.5rem] [&]:before:h-full shadow-gray bg-gray w-[236px] xs:max-md:overflow-y block"
>
<div
class="PageSidebar-wrapper PageSidebar-sticky"
class="h-full max-h-[calc(100vh-var(--header sticky top-[var(--header"
>
<div
class="flex flex-col PageSidebar-scrollableContent"
class="flex flex-col scrollable-content h-full overflow-y pt-4 pb-2 px-0"
>
<div
class="PageSidebar-spacer"
class="order-[50] flex-1 h-full"
/>
</div>
</div>
Expand All @@ -30,16 +30,16 @@ exports[`PageSidebar with menu 1`] = `
class="Picasso-root"
>
<div
class="PageSidebar-root PageSidebar-light PageSidebar-medium PageSidebar-hamburgerNotAvailable"
class="h-full shadow-[inset_-1px_0_0_0] text-lg/[inherit] relative transition-[width] ease-in delay-[225ms] min-[1280px]:block [&]:before:absolute [&]:before:content-[""] [&]:before:left-0 [&]:before:top-0 [&]:before:w-[15.5rem] [&]:before:h-full shadow-gray bg-gray w-[236px] xs:max-md:overflow-y block"
>
<div
class="PageSidebar-wrapper PageSidebar-sticky"
class="h-full max-h-[calc(100vh-var(--header sticky top-[var(--header"
>
<div
class="flex flex-col PageSidebar-scrollableContent"
class="flex flex-col scrollable-content h-full overflow-y pt-4 pb-2 px-0"
>
<div
class="PageSidebar-spacer"
class="order-[50] flex-1 h-full"
/>
<ul
class="relative list-none outline-none py-2 px-0 m-0 rounded-sm shadow-0 order-1 [&_&]:flex-1 flex-grow flex-shrink max-w"
Expand All @@ -59,16 +59,16 @@ exports[`PageSidebar with one normal and one bottom menu 1`] = `
class="Picasso-root"
>
<div
class="PageSidebar-root PageSidebar-light PageSidebar-medium PageSidebar-hamburgerNotAvailable"
class="h-full shadow-[inset_-1px_0_0_0] text-lg/[inherit] relative transition-[width] ease-in delay-[225ms] min-[1280px]:block [&]:before:absolute [&]:before:content-[""] [&]:before:left-0 [&]:before:top-0 [&]:before:w-[15.5rem] [&]:before:h-full shadow-gray bg-gray w-[236px] xs:max-md:overflow-y block"
>
<div
class="PageSidebar-wrapper PageSidebar-sticky"
class="h-full max-h-[calc(100vh-var(--header sticky top-[var(--header"
>
<div
class="flex flex-col PageSidebar-scrollableContent"
class="flex flex-col scrollable-content h-full overflow-y pt-4 pb-2 px-0"
>
<div
class="PageSidebar-spacer"
class="order-[50] flex-1 h-full"
/>
<ul
class="relative list-none outline-none py-2 px-0 m-0 rounded-sm shadow-0 order-1 [&_&]:flex-1 flex-grow flex-shrink max-w"
Expand Down
88 changes: 0 additions & 88 deletions packages/base/Page/src/PageSidebar/styles.ts

This file was deleted.

16 changes: 8 additions & 8 deletions packages/base/Page/src/SidebarItem/__snapshots__/test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ exports[`SidebarItem collapsible menu is expanded when one of the children is se
class="Picasso-root"
>
<div
class="PageSidebar-root PageSidebar-light PageSidebar-medium PageSidebar-hamburgerNotAvailable"
class="h-full shadow-[inset_-1px_0_0_0] text-lg/[inherit] relative transition-[width] ease-in delay-[225ms] min-[1280px]:block [&]:before:absolute [&]:before:content-[""] [&]:before:left-0 [&]:before:top-0 [&]:before:w-[15.5rem] [&]:before:h-full shadow-gray bg-gray w-[236px] xs:max-md:overflow-y block"
>
<div
class="PageSidebar-wrapper PageSidebar-sticky"
class="h-full max-h-[calc(100vh-var(--header sticky top-[var(--header"
>
<div
class="flex flex-col PageSidebar-scrollableContent"
class="flex flex-col scrollable-content h-full overflow-y pt-4 pb-2 px-0"
>
<div
class="PageSidebar-spacer"
class="order-[50] flex-1 h-full"
/>
<ul
class="relative list-none outline-none py-2 px-0 m-0 rounded-sm shadow-0 order-1 [&_&]:flex-1 flex-grow flex-shrink max-w"
Expand Down Expand Up @@ -152,16 +152,16 @@ exports[`SidebarItem collapsible menu is expanded when one of the children is se
class="Picasso-root"
>
<div
class="PageSidebar-root PageSidebar-light PageSidebar-medium PageSidebar-hamburgerNotAvailable"
class="h-full shadow-[inset_-1px_0_0_0] text-lg/[inherit] relative transition-[width] ease-in delay-[225ms] min-[1280px]:block [&]:before:absolute [&]:before:content-[""] [&]:before:left-0 [&]:before:top-0 [&]:before:w-[15.5rem] [&]:before:h-full shadow-gray bg-gray w-[236px] xs:max-md:overflow-y block"
>
<div
class="PageSidebar-wrapper PageSidebar-sticky"
class="h-full max-h-[calc(100vh-var(--header sticky top-[var(--header"
>
<div
class="flex flex-col PageSidebar-scrollableContent"
class="flex flex-col scrollable-content h-full overflow-y pt-4 pb-2 px-0"
>
<div
class="PageSidebar-spacer"
class="order-[50] flex-1 h-full"
/>
<ul
class="relative list-none outline-none py-2 px-0 m-0 rounded-sm shadow-0 order-1 [&_&]:flex-1 flex-grow flex-shrink max-w"
Expand Down
Loading