-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(v2): enable scrolling for sidebar menu only (#2645)
* fix(v2): enable scrolling for sidebar menu only * Add support for announcement bar * fix: remove redundant styles
- Loading branch information
Showing
9 changed files
with
186 additions
and
65 deletions.
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; |