mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-03 19:32:35 +02:00
refactor(theme-classic): split AnnouncementBar, increase z-index, use shadow (#7940)
This commit is contained in:
parent
ad15605545
commit
53bb0307dd
7 changed files with 115 additions and 37 deletions
|
@ -55,6 +55,22 @@ declare module '@theme/AnnouncementBar' {
|
||||||
export default function AnnouncementBar(): JSX.Element | null;
|
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' {
|
declare module '@theme/BackToTopButton' {
|
||||||
export default function BackToTopButton(): JSX.Element;
|
export default function BackToTopButton(): JSX.Element;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -6,49 +6,33 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import clsx from 'clsx';
|
|
||||||
import {useThemeConfig} from '@docusaurus/theme-common';
|
import {useThemeConfig} from '@docusaurus/theme-common';
|
||||||
import {useAnnouncementBar} from '@docusaurus/theme-common/internal';
|
import {useAnnouncementBar} from '@docusaurus/theme-common/internal';
|
||||||
import {translate} from '@docusaurus/Translate';
|
import AnnouncementBarCloseButton from '@theme/AnnouncementBar/CloseButton';
|
||||||
import IconClose from '@theme/Icon/Close';
|
import AnnouncementBarContent from '@theme/AnnouncementBar/Content';
|
||||||
|
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
|
||||||
export default function AnnouncementBar(): JSX.Element | null {
|
export default function AnnouncementBar(): JSX.Element | null {
|
||||||
const {isActive, close} = useAnnouncementBar();
|
|
||||||
const {announcementBar} = useThemeConfig();
|
const {announcementBar} = useThemeConfig();
|
||||||
|
const {isActive, close} = useAnnouncementBar();
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const {backgroundColor, textColor, isCloseable} = announcementBar!;
|
||||||
const {content, backgroundColor, textColor, isCloseable} = announcementBar!;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={styles.announcementBar}
|
className={styles.announcementBar}
|
||||||
style={{backgroundColor, color: textColor}}
|
style={{backgroundColor, color: textColor}}
|
||||||
role="banner">
|
role="banner">
|
||||||
{isCloseable && <div className={styles.announcementBarPlaceholder} />}
|
{isCloseable && <div className={styles.announcementBarPlaceholder} />}
|
||||||
<div
|
<AnnouncementBarContent className={styles.announcementBarContent} />
|
||||||
className={styles.announcementBarContent}
|
{isCloseable && (
|
||||||
// Developer provided the HTML, so assume it's safe.
|
<AnnouncementBarCloseButton
|
||||||
// eslint-disable-next-line react/no-danger
|
|
||||||
dangerouslySetInnerHTML={{__html: content}}
|
|
||||||
/>
|
|
||||||
{isCloseable ? (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className={clsx('clean-btn close', styles.announcementBarClose)}
|
|
||||||
onClick={close}
|
onClick={close}
|
||||||
aria-label={translate({
|
className={styles.announcementBarClose}
|
||||||
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}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
height: var(--docusaurus-announcement-bar-height);
|
height: var(--docusaurus-announcement-bar-height);
|
||||||
background-color: var(--ifm-color-white);
|
background-color: var(--ifm-color-white);
|
||||||
color: var(--ifm-color-black);
|
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 {
|
html[data-announcement-bar-initially-dismissed='true'] .announcementBar {
|
||||||
|
@ -29,15 +30,10 @@ html[data-announcement-bar-initially-dismissed='true'] .announcementBar {
|
||||||
.announcementBarClose {
|
.announcementBarClose {
|
||||||
flex: 0 0 30px;
|
flex: 0 0 30px;
|
||||||
align-self: stretch;
|
align-self: stretch;
|
||||||
padding: 0;
|
|
||||||
line-height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.announcementBarContent {
|
.announcementBarContent {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
font-size: 85%;
|
|
||||||
text-align: center;
|
|
||||||
padding: 5px 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media print {
|
@media print {
|
||||||
|
@ -46,11 +42,6 @@ html[data-announcement-bar-initially-dismissed='true'] .announcementBar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.announcementBarContent a {
|
|
||||||
color: inherit;
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 997px) {
|
@media (min-width: 997px) {
|
||||||
:root {
|
:root {
|
||||||
--docusaurus-announcement-bar-height: 30px;
|
--docusaurus-announcement-bar-height: 30px;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue