-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
fix(v2): enable scrolling for sidebar menu only #2645
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
20bc7cc
fix(v2): enable scrolling for sidebar menu only
lex111 e8b449a
Add support for announcement bar
lex111 5112605
Merge branch 'master' into lex111/scroll-menu
lex111 a276048
fix: remove redundant styles
lex111 803cf22
Merge branch 'master' of github.com:facebook/docusaurus into lex111/s…
lex111 b377c23
Merge branch 'lex111/scroll-menu' of github.com:facebook/docusaurus i…
lex111 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
15 changes: 15 additions & 0 deletions
15
packages/docusaurus-theme-classic/src/theme/AnnouncementBarContext.js
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,15 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {createContext} from 'react'; | ||
|
||
const AnnouncementBarContext = createContext({ | ||
isAnnouncementBarClosed: false, | ||
closeAnnouncementBar: () => {}, | ||
}); | ||
|
||
export default AnnouncementBarContext; |
24 changes: 24 additions & 0 deletions
24
packages/docusaurus-theme-classic/src/theme/AnnouncementBarProvider/index.js
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,24 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import AnnouncementBarContext from '@theme/AnnouncementBarContext'; | ||
import useAnnouncementBar from '@theme/hooks/useAnnouncementBar'; | ||
|
||
function AnnouncementBarProvider(props) { | ||
const {isAnnouncementBarClosed, closeAnnouncementBar} = useAnnouncementBar(); | ||
|
||
return ( | ||
<AnnouncementBarContext.Provider | ||
value={{isAnnouncementBarClosed, closeAnnouncementBar}}> | ||
{props.children} | ||
</AnnouncementBarContext.Provider> | ||
); | ||
} | ||
|
||
export default AnnouncementBarProvider; |
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
52 changes: 52 additions & 0 deletions
52
packages/docusaurus-theme-classic/src/theme/hooks/useAnnouncementBar.js
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,52 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {useState, useEffect} from 'react'; | ||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
|
||
const STORAGE_DISMISS_KEY = 'docusaurus.announcement.dismiss'; | ||
const STORAGE_ID_KEY = 'docusaurus.announcement.id'; | ||
|
||
const useAnnouncementBar = () => { | ||
const { | ||
siteConfig: { | ||
themeConfig: { | ||
announcementBar: {id}, | ||
}, | ||
} = {}, | ||
} = useDocusaurusContext(); | ||
const [isClosed, setClosed] = useState(true); | ||
const handleClose = () => { | ||
localStorage.setItem(STORAGE_DISMISS_KEY, true); | ||
setClosed(true); | ||
}; | ||
|
||
useEffect(() => { | ||
const viewedId = localStorage.getItem(STORAGE_ID_KEY); | ||
const isNewAnnouncement = id !== viewedId; | ||
|
||
localStorage.setItem(STORAGE_ID_KEY, id); | ||
|
||
if (isNewAnnouncement) { | ||
localStorage.setItem(STORAGE_DISMISS_KEY, false); | ||
} | ||
|
||
if ( | ||
isNewAnnouncement || | ||
localStorage.getItem(STORAGE_DISMISS_KEY) === 'false' | ||
) { | ||
setClosed(false); | ||
} | ||
}, []); | ||
|
||
return { | ||
isAnnouncementBarClosed: isClosed, | ||
closeAnnouncementBar: handleClose, | ||
}; | ||
}; | ||
|
||
export default useAnnouncementBar; |
15 changes: 15 additions & 0 deletions
15
packages/docusaurus-theme-classic/src/theme/hooks/useAnnouncementBarContext.js
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,15 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {useContext} from 'react'; | ||
import AnnouncementBarContext from '@theme/AnnouncementBarContext'; | ||
|
||
function useAnnouncementBarContext() { | ||
return useContext(AnnouncementBarContext); | ||
} | ||
|
||
export default useAnnouncementBarContext; |
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.
Subjective, but i'd rather use something like
useDocusaurusContext().siteConfig.themeConfig?. announcementBar?.id