mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 02:42:41 +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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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 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>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue