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

Add onVisibilityChanged function as a property argument #75

Merged
merged 4 commits into from
Aug 13, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Add onVisibilityChanged function as a property argument of the Drawer component

## [0.17.1] - 2024-02-28

## [0.17.0] - 2024-01-09
Expand Down
9 changes: 9 additions & 0 deletions react/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {
MouseEventHandler,
useMemo,
useState,
useEffect,
} from 'react'
import { defineMessages } from 'react-intl'
import { IconMenu } from 'vtex.store-icons'
Expand Down Expand Up @@ -62,6 +63,7 @@ interface Props {
renderingStrategy?: RenderingStrategy
customPixelEventId?: PixelData['id']
customPixelEventName?: PixelData['event']
onVisibilityChanged?: (visible: boolean) => void
}

function menuReducer(state: MenuState, action: MenuAction) {
Expand Down Expand Up @@ -125,6 +127,7 @@ function Drawer(props: Props) {
renderingStrategy = 'lazy',
customPixelEventId,
customPixelEventName,
onVisibilityChanged,
} = props
const handles = useCssHandles(CSS_HANDLES)
const backdropMode = useResponsiveValue(backdropModeProp)
Expand All @@ -148,6 +151,12 @@ function Drawer(props: Props) {
eventName: customPixelEventName,
})

useEffect(() => {
if (onVisibilityChanged !== undefined) {
onVisibilityChanged(isMenuOpen)
}
}, [onVisibilityChanged, isMenuOpen])

const handleContainerClick: MouseEventHandler<HTMLElement> = event => {
// target is the clicked element
// currentTarget is the element which was attached the event (e.g. the container)
Expand Down
Loading