-
Notifications
You must be signed in to change notification settings - Fork 8
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: aside header top alert #118
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3fef146
feat: aside header top block
goshander fccba6b
fix: fix top aside header logic for use static alert
goshander e5c7363
fix: add divider to top alert
goshander d4a3e76
feat: add centered and closable props
goshander 6e9e767
fix: divider color with alpha chanel
goshander a1929bd
fix: refactor top alert with new layout scheme
goshander fec3a00
fix: fix topAlert props passing
goshander e15a016
fix: aside header top alert css var trick
goshander 3d4f002
fix: remove useless changes
goshander 0a1ce0c
fix: remove maxHeight from Content widget
goshander 2a94579
fix: top ref callback update
goshander 18b751e
fix: fix type LayoutProps
goshander a0c63d2
fix: drawer panel height
goshander 48daab3
fix: import FC from React
goshander d041c19
fix: change root element var
goshander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import {Alert} from '@gravity-ui/uikit'; | ||
|
||
import {b} from '../utils'; | ||
import {AsideHeaderTopAlertProps} from '../../types'; | ||
import {useAsideHeaderTopPanel} from '../useAsideHeaderTopPanel'; | ||
|
||
type Props = { | ||
topAlert?: AsideHeaderTopAlertProps; | ||
}; | ||
|
||
export const TopPanel = ({topAlert}: Props) => { | ||
const {topRef, updateTopSize} = useAsideHeaderTopPanel({topAlert}); | ||
|
||
const [opened, setOpened] = React.useState(true); | ||
|
||
const handleClose = React.useCallback(() => { | ||
setOpened(false); | ||
topAlert?.onCloseTopAlert?.(); | ||
}, [topAlert]); | ||
|
||
React.useEffect(() => { | ||
if (!opened) { | ||
updateTopSize(); | ||
} | ||
}, [opened, updateTopSize]); | ||
|
||
if (!topAlert || !topAlert.message) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div ref={topRef} className={b('pane-top', {opened})}> | ||
{opened && ( | ||
<React.Fragment> | ||
<Alert | ||
className={b('pane-top-alert', { | ||
centered: topAlert.centered, | ||
dense: topAlert.dense, | ||
})} | ||
corners="square" | ||
layout="horizontal" | ||
theme={topAlert.theme || 'warning'} | ||
icon={topAlert.icon} | ||
title={topAlert.title} | ||
message={topAlert.message} | ||
actions={topAlert.actions} | ||
onClose={topAlert.closable ? handleClose : undefined} | ||
/> | ||
<div className={b('pane-top-divider')}></div> | ||
</React.Fragment> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export {FirstPanel} from './FirstPanel'; | ||
export {TopPanel} from './TopPanel'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
|
||
import debounceFn from 'lodash/debounce'; | ||
import {AsideHeaderTopAlertProps} from '../types'; | ||
|
||
type AsideHeaderTopPanel = { | ||
topRef: React.RefObject<HTMLDivElement>; | ||
updateTopSize: () => void; | ||
}; | ||
|
||
const G_ROOT_CLASS_NAME = 'g-root'; | ||
|
||
const useRefHeight = (ref: React.RefObject<HTMLDivElement>) => { | ||
const [topHeight, setTopHeight] = React.useState(0); | ||
React.useEffect(() => { | ||
if (ref.current) { | ||
const {current} = ref; | ||
setTopHeight(current.clientHeight); | ||
} | ||
}, [ref]); | ||
return topHeight; | ||
}; | ||
|
||
export const useAsideHeaderTopPanel = ({ | ||
topAlert, | ||
}: { | ||
topAlert?: AsideHeaderTopAlertProps; | ||
}): AsideHeaderTopPanel => { | ||
const topRef = React.useRef<HTMLDivElement>(null); | ||
const topHeight = useRefHeight(topRef); | ||
|
||
const setAsideTopPanelHeight = React.useCallback((clientHeight: number) => { | ||
const gRootElement = document | ||
.getElementsByClassName(G_ROOT_CLASS_NAME) | ||
.item(0) as HTMLElement | null; | ||
gRootElement?.style.setProperty('--gn-aside-top-panel-height', clientHeight + 'px'); | ||
}, []); | ||
|
||
const updateTopSize = React.useCallback(() => { | ||
if (topRef.current) { | ||
setAsideTopPanelHeight(topRef.current?.clientHeight || 0); | ||
} | ||
}, [topRef, setAsideTopPanelHeight]); | ||
|
||
React.useLayoutEffect(() => { | ||
const updateTopSizeDebounce = debounceFn(updateTopSize, 200, {leading: true}); | ||
|
||
if (topAlert) { | ||
window.addEventListener('resize', updateTopSizeDebounce); | ||
updateTopSizeDebounce(); | ||
} | ||
return () => { | ||
window.removeEventListener('resize', updateTopSizeDebounce); | ||
setAsideTopPanelHeight(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set top panel size to zero for correct destroy component behaviour with iframe switching at storybook |
||
}; | ||
}, [topAlert, topHeight, topRef, updateTopSize]); | ||
|
||
return { | ||
topRef, | ||
updateTopSize, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix drawer padding at 20px for remove unexpected scroll