8000 feat(CSidebar): add `onHide` and `onShow` event · v-rr/coreui-react@efa1ee4 · GitHub
[go: up one dir, main page]

Skip to content

Commit efa1ee4

Browse files
committed
feat(CSidebar): add onHide and onShow event
1 parent 1fec507 commit efa1ee4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/components/sidebar/CSidebar.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
1515
* Make sidebar narrow.
1616
*/
1717
narrow?: boolean
18+
/**
19+
* Callback fired when the component requests to be hidden.
20+
*/
21+
onHide?: () => void
22+
/**
23+
* Callback fired when the component requests to be shown.
24+
*/
25+
onShow?: () => void
1826
/**
1927
* Event emitted after visibility of component changed.
2028
*/
@@ -60,6 +68,8 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
6068
children,
6169
className,
6270
narrow,
71+
onHide,
72+
onShow,
6373
onVisibleChange,
6474
overlaid,
6575
position,
@@ -84,6 +94,8 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
8494

8595
useEffect(() => {
8696
typeof inViewport !== 'undefined' && onVisibleChange && onVisibleChange(inViewport)
97+
!inViewport && onHide && onHide()
98+
inViewport && onShow && onShow()
8799
}, [inViewport])
88100

89101
useEffect(() => {
@@ -186,6 +198,8 @@ CSidebar.propTypes = {
186198
children: PropTypes.node,
187199
className: PropTypes.string,
188200
narrow: PropTypes.bool,
201+
onHide: PropTypes.func,
202+
onShow: PropTypes.func,
189203
onVisibleChange: PropTypes.func,
190204
overlaid: PropTypes.bool,
191205
position: PropTypes.oneOf(['fixed', 'sticky']),

0 commit comments

Comments
 (0)
0