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 110511 update drawer divider #1529

Merged
merged 8 commits into from
Nov 6, 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": "Add divider styling logic",
"type": "minor"
}
],
"packageName": "pcln-design-system"
}
20 changes: 20 additions & 0 deletions packages/core/src/Drawer/Drawer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,24 @@ describe('Drawer', () => {
)
expect(getByText('Custom Heading')).toBeTruthy()
})

test('renders Drawer with no divider', () => {
const { getByTestId } = render(
<Drawer
isOpen={true}
placement='right'
onClose={jest.fn}
onCollapse={jest.fn}
heading={<div>Custom Heading</div>}
showDivider={false} // Default true
>
Content
</Drawer>
)

const element = getByTestId('drawer-divider')
const style = window.getComputedStyle(element)
const boxShadow = style?.boxShadow
expect(boxShadow).toBeFalsy()
})
})
3 changes: 2 additions & 1 deletion packages/core/src/Drawer/Drawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const WithCustomHeadingAndContent = (args) => (
</DrawerStory>
)

export const WithCustomHeading = (args) => (
export const WithNeighborhoodsHeadingNoDivider = (args) => (
<DrawerStory
{...args}
placement='right'
Expand All @@ -191,6 +191,7 @@ export const WithCustomHeading = (args) => (
width='100%'
onClose={null}
onCollapse={null}
showDivider={false}
/>
)

Expand Down
14 changes: 11 additions & 3 deletions packages/core/src/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type DrawerProps = SpaceProps &
isMobile?: boolean
isOpen?: boolean
isDraggable?: boolean
showDivider?: boolean
onClose?: () => void
onCollapse?: () => void
placement?: PlacementOptions
Expand Down Expand Up @@ -47,6 +48,13 @@ const dragToDismissAnimation = (onDragEnd) => {
}
}

const getDividerStyle = ({ showDivider, boxShadow }) =>
showDivider
? {
boxShadow,
}
: {}

export const Drawer: React.FC<DrawerProps> = ({
children,
heading,
Expand All @@ -55,6 +63,7 @@ export const Drawer: React.FC<DrawerProps> = ({
isMobile = false,
isOpen = false,
isDraggable = true,
showDivider = true,
onClose,
onCollapse,
placement = 'right',
Expand Down Expand Up @@ -140,9 +149,8 @@ export const Drawer: React.FC<DrawerProps> = ({
maxHeight={`calc(${props.height ?? '100vh'} - 100px)`}
overflow='scroll'
onScroll={onScrollHandler}
style={{
boxShadow,
}}
data-testid='drawer-divider'
style={getDividerStyle({ showDivider, boxShadow })}
>
<Box py={2} px={3} height='100%'>
{children}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/SlideBox/Slide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export function Slide({
const ref = useRef()

useEffect(() => {
/* istanbul ignore next */
/* c8 ignore next */
if (isCurrentSlide === true && typeof slideBoxRef?.current?.scroll === 'function' && ref?.current) {
/* c8 ignore next */
const { offsetLeft, offsetParent, offsetWidth } = ref.current
const { offsetWidth: parentOffset } = offsetParent || {}
slideBoxRef?.current?.scroll({ left: offsetLeft - parentOffset + offsetWidth + overflowAllowancePxX })
Expand Down
Loading