-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(v2): add announcement bar #2330
Conversation
Deploy preview for docusaurus-2 ready! Built with commit b652771 |
FYI may not be the best solution because sticky navbar here makes it difficult to "elegantly" implement such a thing. Any improvements are welcome! |
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.
I don't think this should be added to Navbar
. Can we add it into Layout
and leave Navbar
alone? I hope this is possible if the styling is not affected.
Most users will not AnnouncementBar
but everyone needs Navbar
. Doing this will just bloat up the Navbar
.
@yangshun It was a bit tricky, but now it really got better, re-check it please. |
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.
I think there's a bug - after I dismiss the announcement bar and refresh the page, the page layout goes haywire totally.
To be honest I'm not really in favor of this feature as it makes the code much more complicated to work together with the existing Nav. But both Gatsby and Next.js websites have an announcement bar :/
Let's fix the bugs first then I'll try to improve the code.
|
||
import styles from './styles.module.css'; | ||
|
||
const STORAGE_KEY = 'announcement_closed'; |
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.
Better to namespace it - docusaurus.announcement.dismiss
.
I'd also recommend adding allowing a key for the announcement config. Otherwise users will never ever see new announcements after they've dismissed an announcement. Library authors can create new announcements but it will never show up for users who have dismissed announcements before.
We can allow the announcement config to take in a key
/id
prop that is added at the end of the storage key so that new announcements will still be visible to users who have dismissed older announcements - docusaurus.announcement.dismiss.<id>
packages/docusaurus-theme-classic/src/theme/AnnouncementBar/styles.module.css
Show resolved
Hide resolved
I'll see what is wrong 😱 😱 😱 . But why is the current code bad? |
@yangshun I fixed all the bugs, now it should be fine, check again please. |
I reworked PR according to new changes (navbar via sticky positioning) |
c0ecd00
to
698905f
Compare
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.
Let's release this in alpha.45. Some issues which still exist:
- I don't want to overload
theme/Layout
with non-essential features. If a user is not using the announcement feature they are still paying the cost of it. Using dynamic imports would be better - Serializing the content to use as a key is less work, but letting the user specify a key is still better. If the user had a typo and they fixed it later on, the announcement shows up twice
This is an additional work for user, since in addition to the announcement text, they needs to specify a new id. It seems to me serialization would be enough, because, for example, typos is a rare use case.. |
@yangshun I reworked component (using ids, styles, updating docs). I think it would be nice to delivery this feature in a new release. |
f565cca
to
b652771
Compare
@lex111 this is awesome! I personally think it might look nice in the same color of the search bar, which is (I think) |
Motivation
Resolve https://docusaurus.canny.io/admin/board/feature-requests/p/announcement-bar
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Preview.
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)