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

feat(HTL-109459): multiroom drawer) #1523

Merged
merged 1 commit into from
Oct 24, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "pcln-design-system",
"comment": "update drawer props",
"type": "minor"
}
],
"packageName": "pcln-design-system"
}
2 changes: 1 addition & 1 deletion packages/core/src/Drawer/Drawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const Anchored = (args) => (
)

export const Mobile = (args) => (
<DrawerStory {...args} isMobile isFloating={false} placement='right'>
<DrawerStory {...args} isMobile isFloating={false} placement='right' width='100%'>
Drawer Content
</DrawerStory>
)
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/Drawer/Drawer.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Flex } from '../Flex/Flex'
import { theme } from '../theme'
import { motion } from 'framer-motion'
import React from 'react'
import { Absolute } from '../Absolute/Absolute'
import { getPaletteColor } from '../utils'
import { Box } from '../Box/Box'
import { IconButton } from '../IconButton/IconButton'
Expand All @@ -13,7 +12,7 @@ const Component = React.forwardRef((props, ref: React.MutableRefObject<HTMLDivEl
<Box {...props} ref={ref} />
))

const AnimatedAbsolute = motion(Component)
const AnimatedComponent = motion(Component)

const getBorderRadiusStyles = (placement, isFloating) => {
const themeRadius = theme.borderRadii['2xl']
Expand All @@ -40,13 +39,16 @@ const positions: Record<PlacementOptions, string> = {
}
const getPlacementStyles = (placement) =>
placement ? `margin-inline:auto; margin-block:auto; ${positions[placement]};` : ``
export const DrawerWrapper = styled(Absolute)`
${({ placement }) =>
export const DrawerWrapper = styled(Box)`
${({ placement, zIndex, position }) =>
`
position: ${position || 'absolute'};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow position to be set by prop

${getPlacementStyles(placement)}
${getPlacementStyles(placement)}
z-index: ${zIndex || theme.zIndices.modal};
`}
`
export const DrawerRoot = styled(AnimatedAbsolute)`
export const DrawerRoot = styled(AnimatedComponent)`
background-color: ${getPaletteColor('background.lightest')};
${({ theme, placement, isFloating }) =>
`box-shadow: ${theme.shadows['overlay-md']};
Expand Down
19 changes: 12 additions & 7 deletions packages/core/src/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import { AnimatePresence, motion } from 'framer-motion'
import { SpaceProps, LayoutProps } from 'styled-system'
import { useScrollWithShadow } from '../useScrollWithShadows/useScrollWithShadow'
import { MotionVariants } from '../Animate/Animate'
import { theme } from '../theme'

export type PlacementOptions = 'top' | 'bottom' | 'right' | 'left'
export type DrawerProps = SpaceProps &
LayoutProps & {
children?: string | React.ReactNode
heading?: string | React.ReactNode
isCollapsed?: boolean
isFloating?: boolean
isOpen?: boolean
isMobile?: boolean
isOpen?: boolean
isDraggable?: boolean
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ability to enable/disable the swipe to dismiss animation

onClose?: () => void
onCollapse?: () => void
placement?: PlacementOptions
children?: string | React.ReactNode
position?: string
}

const enterAnimation = {
Expand Down Expand Up @@ -51,6 +54,7 @@ export const Drawer: React.FC<DrawerProps> = ({
isFloating = true,
isMobile = false,
isOpen = false,
isDraggable = true,
onClose,
onCollapse,
placement = 'right',
Expand All @@ -62,11 +66,12 @@ export const Drawer: React.FC<DrawerProps> = ({
{isOpen && (
<DrawerWrapper
placement={isMobile ? 'bottom' : placement}
padding={isFloating ? '16px' : 0}
padding={isFloating ? 3 : 0}
maxHeight={isMobile ? ['290px', '400px', '480px', 'calc(100vh - 64px)'] : props.height ?? '100%'}
maxWidth={isMobile ? '100%' : ['400px', '600px', '800px', '100%']}
width={isMobile ? '100%' : props.width}
height={!isCollapsed && props.height ? props.height : 'fit-content'}
{...props}
>
<DrawerRoot
data-testid='drawer'
Expand All @@ -75,7 +80,7 @@ export const Drawer: React.FC<DrawerProps> = ({
key='drawer'
placement={isMobile ? 'bottom' : placement}
{...enterAnimation[isMobile ? 'bottom' : placement]}
{...dragToDismissAnimation(onCollapse)}
{...(isDraggable ? dragToDismissAnimation(onCollapse) : {})}
height='100%'
width='100%'
overflow='hidden'
Expand All @@ -92,7 +97,7 @@ export const Drawer: React.FC<DrawerProps> = ({
heading
)}
{onClose || onCollapse ? (
<Flex flexDirection='row' ml='auto' style={{ columnGap: '8px' }}>
<Flex flexDirection='row' ml='auto' style={{ columnGap: theme.space[2] }}>
{onCollapse && (
<motion.div
animate={{
Expand Down Expand Up @@ -139,12 +144,12 @@ export const Drawer: React.FC<DrawerProps> = ({
boxShadow,
}}
>
<Box p={3} height='100%'>
<Box py={2} px={3} height='100%'>
{children}
</Box>
</Box>
) : (
<Box p={3} height='100%'>
<Box py={2} px={3} height='100%'>
{children}
</Box>
)}
Expand Down
Loading