Skip to content

Commit

Permalink
refactor(theme-classic): split AnnouncementBar, increase z-index, use…
Browse files Browse the repository at this point in the history
… shadow (#7940)
  • Loading branch information
slorber committed Aug 12, 2022
1 parent ad15605 commit 53bb030
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 37 deletions.
16 changes: 16 additions & 0 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Expand Up @@ -55,6 +55,22 @@ declare module '@theme/AnnouncementBar' {
export default function AnnouncementBar(): JSX.Element | null;
}

declare module '@theme/AnnouncementBar/Content' {
import type {ComponentProps} from 'react';

export interface Props extends ComponentProps<'div'> {}

export default function AnnouncementBarContent(props: Props): JSX.Element;
}

declare module '@theme/AnnouncementBar/CloseButton' {
import type {ComponentProps} from 'react';

export interface Props extends ComponentProps<'button'> {}

export default function AnnouncementBarCloseButton(props: Props): JSX.Element;
}

declare module '@theme/BackToTopButton' {
export default function BackToTopButton(): JSX.Element;
}
Expand Down
@@ -0,0 +1,31 @@
/**
* 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 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 (
<button
type="button"
aria-label={translate({
id: 'theme.AnnouncementBar.closeButtonAriaLabel',
message: 'Close',
description: 'The ARIA label for close button of announcement bar',
})}
{...props}
className={clsx('clean-btn close', styles.closeButton, props.className)}>
<IconClose width={14} height={14} strokeWidth={3.1} />
</button>
);
}
@@ -0,0 +1,11 @@
/**
* 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.
*/

.closeButton {
padding: 0;
line-height: 0;
}
@@ -0,0 +1,28 @@
/**
* 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 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 (
<div
{...props}
className={clsx(styles.content, props.className)}
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{__html: content}}
/>
);
}
@@ -0,0 +1,17 @@
/**
* 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.
*/

.content {
font-size: 85%;
text-align: center;
padding: 5px 0;
}

.content a {
color: inherit;
text-decoration: underline;
}
Expand Up @@ -6,49 +6,33 @@
*/

import React from 'react';
import clsx from 'clsx';
import {useThemeConfig} from '@docusaurus/theme-common';
import {useAnnouncementBar} from '@docusaurus/theme-common/internal';
import {translate} from '@docusaurus/Translate';
import IconClose from '@theme/Icon/Close';
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 {isActive, close} = useAnnouncementBar();
const {announcementBar} = useThemeConfig();

const {isActive, close} = useAnnouncementBar();
if (!isActive) {
return null;
}

const {content, backgroundColor, textColor, isCloseable} = announcementBar!;

const {backgroundColor, textColor, isCloseable} = announcementBar!;
return (
<div
className={styles.announcementBar}
style={{backgroundColor, color: textColor}}
role="banner">
{isCloseable && <div className={styles.announcementBarPlaceholder} />}
<div
className={styles.announcementBarContent}
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{__html: content}}
/>
{isCloseable ? (
<button
type="button"
className={clsx('clean-btn close', styles.announcementBarClose)}
<AnnouncementBarContent className={styles.announcementBarContent} />
{isCloseable && (
<AnnouncementBarCloseButton
onClick={close}
aria-label={translate({
id: 'theme.AnnouncementBar.closeButtonAriaLabel',
message: 'Close',
description: 'The ARIA label for close button of announcement bar',
})}>
<IconClose width={14} height={14} strokeWidth={3.1} />
</button>
) : null}
className={styles.announcementBarClose}
/>
)}
</div>
);
}
Expand Up @@ -15,7 +15,8 @@
height: var(--docusaurus-announcement-bar-height);
background-color: var(--ifm-color-white);
color: var(--ifm-color-black);
border-bottom: 1px solid var(--ifm-color-emphasis-100);
box-shadow: var(--ifm-global-shadow-lw);
z-index: calc(var(--ifm-z-index-fixed) + 1); /* just above the navbar */
}

html[data-announcement-bar-initially-dismissed='true'] .announcementBar {
Expand All @@ -29,15 +30,10 @@ html[data-announcement-bar-initially-dismissed='true'] .announcementBar {
.announcementBarClose {
flex: 0 0 30px;
align-self: stretch;
padding: 0;
line-height: 0;
}

.announcementBarContent {
flex: 1 1 auto;
font-size: 85%;
text-align: center;
padding: 5px 0;
}

@media print {
Expand All @@ -46,11 +42,6 @@ html[data-announcement-bar-initially-dismissed='true'] .announcementBar {
}
}

.announcementBarContent a {
color: inherit;
text-decoration: underline;
}

@media (min-width: 997px) {
:root {
--docusaurus-announcement-bar-height: 30px;
Expand Down

0 comments on commit 53bb030

Please sign in to comment.