Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .changeset/paper-border-radius-prop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@toptal/picasso-paper': minor
'@toptal/picasso': minor
---

Add `borderRadius` prop to `Paper` component. Accepts `'none' | 'sm' | 'md' | 'full'` and maps to Picasso's Tailwind border-radius scale. Defaults to no border radius (backward compatible).
14 changes: 13 additions & 1 deletion packages/base/Paper/src/Paper/Paper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import React, { forwardRef } from 'react'
import type { BaseProps } from '@toptal/picasso-shared'
import { twMerge } from '@toptal/picasso-tailwind-merge'

export type PaperBorderRadius = 'none' | 'sm' | 'md' | 'full'

export interface Props extends BaseProps, HTMLAttributes<HTMLDivElement> {
/** Paper elevation shadow */
elevation?: number
/** Border radius of the Paper surface */
borderRadius?: PaperBorderRadius
children: ReactNode
}

Expand Down Expand Up @@ -38,8 +42,15 @@ const shadowsMapping: Record<number, string> = {
24: 'shadow-24',
}

const borderRadiusMapping: Record<PaperBorderRadius, string> = {
none: 'rounded-none',
sm: 'rounded-sm',
md: 'rounded-md',
full: 'rounded-full',
}

export const Paper = forwardRef<HTMLDivElement, Props>(function Paper(
{ elevation = 1, ...props },
{ elevation = 1, borderRadius, ...props },
ref
) {
const { className, style, children, ...rest } = props
Expand All @@ -51,6 +62,7 @@ export const Paper = forwardRef<HTMLDivElement, Props>(function Paper(
'bg-white',
shadowsMapping[elevation],
'transition-shadow duration-300 delay-0',
borderRadius !== undefined ? borderRadiusMapping[borderRadius] : undefined,
className
)}
style={style}
Expand Down
22 changes: 22 additions & 0 deletions packages/base/Paper/src/Paper/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,26 @@ describe('Paper', () => {

expect(container).toMatchSnapshot()
})

describe('borderRadius', () => {
it.each(['none', 'sm', 'md', 'full'] as const)(
'applies %s border radius class',
borderRadius => {
const { container } = render(
<Paper borderRadius={borderRadius}>Content</Paper>
)

expect(container.firstChild).toMatchSnapshot()
}
)

it('applies no border radius class when borderRadius is not set', () => {
const { container } = render(<Paper>Content</Paper>)

expect(container.firstChild).not.toHaveClass('rounded-none')
expect(container.firstChild).not.toHaveClass('rounded-sm')
expect(container.firstChild).not.toHaveClass('rounded-md')
expect(container.firstChild).not.toHaveClass('rounded-full')
})
})
})
Loading