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-5687] Migrate PageFooter to TailwindCSS #4584

Merged
merged 5 commits into from
Oct 3, 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
5 changes: 5 additions & 0 deletions .changeset/witty-seahorses-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@toptal/picasso-page': patch
---

- migrate `PageFooter` to TailwindCSS
9 changes: 7 additions & 2 deletions packages/base/Page/src/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ export const Page = forwardRef<HTMLDivElement, Props>(function Page(
<div
{...rest}
ref={ref}
className={cx(classes.root, className)}
style={{ ...style, '--header-height': '3.5rem' } as React.CSSProperties}
className={cx(
classes.root,
className,
'[--content-padding-horizontal:1em] md:[--content-padding-horizontal:2em]',
ruslan-sed marked this conversation as resolved.
Show resolved Hide resolved
'[--header-height:3.5rem] [--content-width-wide:90em] [--content-width:75em]'
)}
style={{ ...style } as React.CSSProperties}
>
<PageContext.Provider value={{ width, fullWidth }}>
<PageHamburgerContextProvider hamburgerId={hamburgerId}>
Expand Down
3 changes: 1 addition & 2 deletions packages/base/Page/src/Page/__snapshots__/test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ exports[`Page renders 1`] = `
class="Picasso-root"
>
<div
class="Page-root"
style="--header-height: 3.5rem;"
class="Page-root [--content-padding md:[--content-padding [--header [--content-width [--content"
>
<div>
Test
Expand Down
33 changes: 15 additions & 18 deletions packages/base/Page/src/PageFooter/PageFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { ReactNode, HTMLAttributes } from 'react'
import React, { useContext, forwardRef } from 'react'
import type { Theme } from '@material-ui/core/styles'
import { makeStyles } from '@material-ui/core/styles'
import cx from 'classnames'
import type { BaseProps } from '@toptal/picasso-shared'
import { twJoin, twMerge } from '@toptal/picasso-tailwind-merge'

import { PageContext } from '../Page'
import type { PageContextProps } from '../Page/types'
import styles from './styles'
import { getMaxWidthClass } from './styles'

export interface Props extends BaseProps, HTMLAttributes<HTMLElement> {
/** Content for copyright. You can override default if needed. */
Expand All @@ -16,37 +14,36 @@ export interface Props extends BaseProps, HTMLAttributes<HTMLElement> {
rightContent?: ReactNode
}

const useStyles = makeStyles<Theme>(styles, {
name: 'PicassoPageFooter',
})

export const PageFooter = forwardRef<HTMLElement, Props>(function PageFooter(
props,
ref
) {
const { className, style, rightContent, copyrightContent, ...rest } = props
const classes = useStyles()
const { width, fullWidth } = useContext<PageContextProps>(PageContext)

const contentClassnames = cx(
{
[classes.fullWidth]: fullWidth || width === 'full',
[classes.wide]: width === 'wide',
},
classes.content
const contentClassnames = twJoin(
getMaxWidthClass({ width, fullWidth }),
'box-border',
'flex justify-between xs:max-lg:flex-col',
'text-white text-md leading-[1em]',
'mx-auto pt-2 pb-6 px-[--content-padding-horizontal]'
)

return (
<footer
{...rest}
ref={ref}
className={cx(classes.root, className)}
className={twMerge('bg-[#262d3d] w-full', className)}
TomasSlama marked this conversation as resolved.
Show resolved Hide resolved
TomasSlama marked this conversation as resolved.
Show resolved Hide resolved
style={style}
>
<div className={contentClassnames}>
<div className={classes.left}>{copyrightContent}</div>
<div className='flex items-center justify-center mt-4'>
{copyrightContent}
</div>

<div className={classes.right}>{rightContent}</div>
<div className='flex items-center justify-center mt-4 xs:max-lg:-order-1 xs:max-md:flex-col'>
{rightContent}
</div>
</div>
</footer>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react'
import { Page, Typography } from '@toptal/picasso'

const Example = () => (
<div>
<Page>
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 added Page here and in two other stories because without it CSS variables are missed and storybook visual tests fail.

<Page.Footer copyrightContent={<CopyrightContent />} />
</div>
</Page>
)

const CopyrightContent = () => (
Expand Down
4 changes: 2 additions & 2 deletions packages/base/Page/src/PageFooter/story/Default.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react'
import { Page } from '@toptal/picasso'

const Example = () => (
<div>
<Page>
<Page.Footer />
</div>
</Page>
)

export default Example
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const StyledLink = styled(Link)`
`

const Example = () => (
<div>
<Page>
<Page.Footer rightContent={<Links />} />
</div>
</Page>
)

const Links = () => (
Expand Down
67 changes: 10 additions & 57 deletions packages/base/Page/src/PageFooter/styles.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,13 @@
import type { Theme } from '@material-ui/core/styles'
import { createStyles } from '@material-ui/core/styles'
import type { PageContextProps } from '../Page/types'

export default ({ palette, screens, layout }: Theme) =>
createStyles({
root: {
backgroundColor: palette.grey.darker,
width: '100%',
},
content: {
boxSizing: 'border-box',
display: 'flex',
justifyContent: 'space-between',
margin: '0 auto',
paddingTop: '0.5rem',
paddingBottom: '1.5rem',
paddingLeft: layout.contentMobilePaddingHorizontal,
paddingRight: layout.contentMobilePaddingHorizontal,
maxWidth: layout.contentWidth,
color: palette.common.white,
fontSize: '0.875rem',
lineHeight: '1em',
export const getMaxWidthClass = ({ fullWidth, width }: PageContextProps) => {
if (fullWidth || width === 'full') {
return 'max-w-full'
}

[screens('xs', 'sm', 'md')]: {
flexDirection: 'column',
},
if (width === 'wide') {
return 'max-w-[--content-width-wide]'
}

[screens('md', 'lg', 'xl')]: {
paddingLeft: layout.contentPaddingHorizontal,
paddingRight: layout.contentPaddingHorizontal,
},
},
centered: {},
wide: {
maxWidth: layout.contentWidthWide,
},
fullWidth: {
maxWidth: '100%',
},
left: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
marginTop: '1rem',
},
right: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
marginTop: '1rem',

[screens('xs', 'sm', 'md')]: {
order: -1,
},

[screens('xs', 'sm')]: {
flexDirection: 'column',
},
},
})
return 'max-w-[--content-width]'
}
Loading