Skip to content

Commit

Permalink
Add onVisibilityChanged function as a property argument (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
efremov-av authored Aug 13, 2024
1 parent 461f450 commit 2d4383c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 2d4383c

Please sign in to comment.