From 90df4bd5d4f29e180ba59b9708cf063b8b8bac9d Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Wed, 6 Nov 2024 04:30:56 -0800 Subject: [PATCH] Add gradient announcement bar --- docusaurus.config.ts | 3 +- .../AnnouncementBar/CloseButton/index.tsx | 24 ++++++++ .../CloseButton/styles.module.css | 4 ++ src/theme/AnnouncementBar/Content/index.tsx | 21 +++++++ .../AnnouncementBar/Content/styles.module.css | 10 ++++ src/theme/AnnouncementBar/index.tsx | 29 ++++++++++ src/theme/AnnouncementBar/styles.module.css | 55 +++++++++++++++++++ 7 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 src/theme/AnnouncementBar/CloseButton/index.tsx create mode 100644 src/theme/AnnouncementBar/CloseButton/styles.module.css create mode 100644 src/theme/AnnouncementBar/Content/index.tsx create mode 100644 src/theme/AnnouncementBar/Content/styles.module.css create mode 100644 src/theme/AnnouncementBar/index.tsx create mode 100644 src/theme/AnnouncementBar/styles.module.css diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 8e73ab04ee..bdf71642f8 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -78,8 +78,7 @@ const config: Config = { announcementBar: { id: "code_remix", content: - "Now announcing the inaugural Code Remix Summit – in Miami May 12th-14th. Use the code MODERNE3VIP for an additional $300 off.", - backgroundColor: "#555555", + 'Now announcing the inaugural Code Remix Summit – in Miami May 12th-14th. Use the code MODERNE3VIP for an additional $300 off.', textColor: "#E3F2FD", }, image: "img/moderne-poster-logo.svg", diff --git a/src/theme/AnnouncementBar/CloseButton/index.tsx b/src/theme/AnnouncementBar/CloseButton/index.tsx new file mode 100644 index 0000000000..999bcd5644 --- /dev/null +++ b/src/theme/AnnouncementBar/CloseButton/index.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import clsx from 'clsx'; +import {translate} from '@docusaurus/Translate'; +import IconClose from '@theme/Icon/Close'; +import type {Props} from '@theme/AnnouncementBar/CloseButton'; +import styles from './styles.module.css'; + +export default function AnnouncementBarCloseButton( + props: Props, +): JSX.Element | null { + return ( + + ); +} diff --git a/src/theme/AnnouncementBar/CloseButton/styles.module.css b/src/theme/AnnouncementBar/CloseButton/styles.module.css new file mode 100644 index 0000000000..0494ec0d40 --- /dev/null +++ b/src/theme/AnnouncementBar/CloseButton/styles.module.css @@ -0,0 +1,4 @@ +.closeButton { + padding: 0; + line-height: 0; +} diff --git a/src/theme/AnnouncementBar/Content/index.tsx b/src/theme/AnnouncementBar/Content/index.tsx new file mode 100644 index 0000000000..1e1a7d4158 --- /dev/null +++ b/src/theme/AnnouncementBar/Content/index.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import clsx from 'clsx'; +import {useThemeConfig} from '@docusaurus/theme-common'; +import type {Props} from '@theme/AnnouncementBar/Content'; +import styles from './styles.module.css'; + +export default function AnnouncementBarContent( + props: Props, +): JSX.Element | null { + const {announcementBar} = useThemeConfig(); + const {content} = announcementBar!; + return ( +
+ ); +} diff --git a/src/theme/AnnouncementBar/Content/styles.module.css b/src/theme/AnnouncementBar/Content/styles.module.css new file mode 100644 index 0000000000..16635d4b7d --- /dev/null +++ b/src/theme/AnnouncementBar/Content/styles.module.css @@ -0,0 +1,10 @@ +.content { + font-size: 85%; + text-align: center; + padding: 5px 0; +} + +.content a { + color: inherit; + text-decoration: underline; +} diff --git a/src/theme/AnnouncementBar/index.tsx b/src/theme/AnnouncementBar/index.tsx new file mode 100644 index 0000000000..302f62a15d --- /dev/null +++ b/src/theme/AnnouncementBar/index.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import {useThemeConfig} from '@docusaurus/theme-common'; +import {useAnnouncementBar} from '@docusaurus/theme-common/internal'; +import AnnouncementBarCloseButton from '@theme/AnnouncementBar/CloseButton'; +import AnnouncementBarContent from '@theme/AnnouncementBar/Content'; +import styles from './styles.module.css'; +export default function AnnouncementBar(): JSX.Element | null { + const {announcementBar} = useThemeConfig(); + const {isActive, close} = useAnnouncementBar(); + if (!isActive) { + return null; + } + const {textColor, isCloseable} = announcementBar!; + return ( +
+ {isCloseable &&
} + + {isCloseable && ( + + )} +
+ ); +} \ No newline at end of file diff --git a/src/theme/AnnouncementBar/styles.module.css b/src/theme/AnnouncementBar/styles.module.css new file mode 100644 index 0000000000..fee583f9db --- /dev/null +++ b/src/theme/AnnouncementBar/styles.module.css @@ -0,0 +1,55 @@ +:root { + --docusaurus-announcement-bar-height: auto; +} + +.announcementBar { + display: flex; + align-items: center; + height: var(--docusaurus-announcement-bar-height); + background-color: var(--ifm-color-white); + color: var(--ifm-color-black); + + /* + Unfortunately we can't make announcement bar render above the navbar + IE need to use border-bottom instead of shadow + See https://github.com/facebookincubator/infima/issues/275 + + box-shadow: var(--ifm-global-shadow-lw); + z-index: calc(var(--ifm-z-index-fixed) + 1); + */ + border-bottom: 1px solid var(--ifm-color-emphasis-100); +} + +html[data-announcement-bar-initially-dismissed='true'] .announcementBar { + display: none; +} + +.announcementBarPlaceholder { + flex: 0 0 10px; +} + +.announcementBarClose { + flex: 0 0 30px; + align-self: stretch; +} + +.announcementBarContent { + flex: 1 1 auto; +} + +@media print { + .announcementBar { + display: none; + } +} + +@media (min-width: 997px) { + :root { + --docusaurus-announcement-bar-height: 30px; + } + + .announcementBarPlaceholder, + .announcementBarClose { + flex-basis: 50px; + } +}