Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: redesigned announcement bar #2559

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions scripts/doc-change-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ async function main () {

//add new announcement
announcement = {
id: `release-${version.replace(/\./g, '-')}`,
content: `New Release! Version ${version} of Medusa is out now! Read all about it <a href='${response.data.html_url}'>here</a>.`,
backgroundColor: '#7C53FF',
textColor: '#fff',
isCloseable: false,
id: response.data.html_url,
content: `${version} is out`,
isCloseable: true,
}
}

Expand Down
2 changes: 1 addition & 1 deletion www/docs/announcement.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":"release-v1-6-0","content":"New Release! Version v1.6.0 of Medusa is out now! Read all about it <a href='https://github.com/medusajs/medusa/releases/tag/v1.6.0'>here</a>.","backgroundColor":"#7C53FF","textColor":"#fff","isCloseable":false}
{"id":"https://github.com/medusajs/medusa/releases/tag/v1.6.0","content":"v1.6.1 is out","isCloseable":true}
3 changes: 1 addition & 2 deletions www/docs/src/css/_card.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
position:absolute;
bottom: -1px;
left: 0;
background: linear-gradient(90deg, rgba(146, 144, 254, 0) 0%, rgba(163, 219, 254, 0.4) 26.04%,
#9290FE 53.65%, rgba(197, 145, 255, 0.4) 78.65%, rgba(201, 138, 255, 0) 100%);
background: var(--ifm-primary-gradient);
}

html:not([data-theme=dark]) .card {
Expand Down
20 changes: 20 additions & 0 deletions www/docs/src/css/_variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
--ifm-color-primary: #111827;
--ifm-medusa-gray: #f0f0f0;
--ifm-color-content: #6B7280;
--ifm-primary-gradient: linear-gradient(90deg, rgba(146, 144, 254, 0) 0%, rgba(163, 219, 254, 0.4) 26.04%,
#9290FE 53.65%, rgba(197, 145, 255, 0.4) 78.65%, rgba(201, 138, 255, 0) 100%);

/* Fonts */
--ifm-code-font-size: 14px;
Expand Down Expand Up @@ -124,6 +126,16 @@
--docsearch-hit-icon-color: #9CA3AF;
--docsearch-hit-border-color: #E5E7EB;
--docsearch-hit-title-color: #000000;

/* Announcement Bar */
--ifm-announcement-bar-bg: #FFFFFF;
--ifm-announcement-bar-border-color: #E5E7EB;
--ifm-announcement-bar-hover-bg: #F9FAFB;
--ifm-announcement-bar-icon-bg: #F3F4F6;
--ifm-announcement-bar-icon-border-color: var(--ifm-announcement-bar-border-color);
--ifm-announcement-bar-title-color: var(--ifm-color-headers);
--ifm-announcement-bar-text-color: var(--ifm-color-content);
--ifm-announcement-bar-close-icon-color: #9CA3AF;
}

html[data-theme="dark"] {
Expand Down Expand Up @@ -217,4 +229,12 @@ html[data-theme="dark"] {
--docsearch-hit-icon-color: #737373;
--docsearch-hit-border-color: #393939;
--docsearch-hit-title-color: #F3F3F3;

/* Announcement Bar */
--ifm-announcement-bar-bg: #222222;
--ifm-announcement-bar-border-color: #2D2D2D;
--ifm-announcement-bar-hover-bg: #2D2D2D;
--ifm-announcement-bar-icon-bg: #393939;
--ifm-announcement-bar-icon-border-color: #393939;
--ifm-announcement-bar-text-color: #737373;
}
21 changes: 21 additions & 0 deletions www/docs/src/theme/AnnouncementBar/Content/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import clsx from 'clsx';
import {useThemeConfig} from '@docusaurus/theme-common';
import styles from './styles.module.css';
export default function AnnouncementBarContent(props) {
const {announcementBar} = useThemeConfig();
const {content} = announcementBar;
return (
<div
className={clsx(styles.contentWrapper, props.className)}>
<div
{...props}
className={clsx(styles.contentTitle)}
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{__html: content}}
/>
<span className={styles.moreText}>Read more</span>
</div>
);
}
10 changes: 10 additions & 0 deletions www/docs/src/theme/AnnouncementBar/Content/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.contentWrapper {
font-size: 12px;
line-height: 16px;
color: var(--ifm-announcement-bar-text-color);
}

.contentTitle {
font-weight: 600;
color: var( --ifm-announcement-bar-title-color);
}
38 changes: 38 additions & 0 deletions www/docs/src/theme/AnnouncementBar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 ThemedImage from '@theme/ThemedImage';
import useBaseUrl from '@docusaurus/useBaseUrl';
import styles from './styles.module.css';

export default function AnnouncementBar() {
const {announcementBar} = useThemeConfig();
const {isActive, close} = useAnnouncementBar();
if (!isActive) {
return null;
}
const {backgroundColor, textColor, isCloseable, id} = announcementBar;
return (
<div
className={styles.announcementBar}
style={{backgroundColor, color: textColor}}>
<div
className={styles.announcementBarIconWrapper}>
<ThemedImage alt="announcement" sources={{
light: useBaseUrl('/img/bell.png'),
dark: useBaseUrl('/img/bell-dark.png')
}} className={styles.announcementBarIcon} />
</div>
<AnnouncementBarContent className={styles.announcementBarContent} />
{isCloseable && (
<AnnouncementBarCloseButton
onClick={close}
className={styles.announcementBarClose}
/>
)}
<a href={id} className={styles.announcementBarLink} />
</div>
);
}
95 changes: 95 additions & 0 deletions www/docs/src/theme/AnnouncementBar/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
:root {
--docusaurus-announcement-bar-height: auto !important;
}

.announcementBar {
position: relative;
display: flex;
align-items: center;
height: var(--docusaurus-announcement-bar-height);
background-color: var(--ifm-announcement-bar-bg);
padding: 12px 20px 12px 12px;
border: 1px solid var(--ifm-announcement-bar-border-color);
border-radius: var(--ifm-global-radius);
margin: 0 16px 16px 16px;
}

.announcementBar:after {
content: '';
width: 100%;
height: 2px;
position: absolute;
bottom: -1px;
left: 0;
background: var(--ifm-primary-gradient);
}

.announcementBar:hover {
background-color: var(--ifm-announcement-bar-hover-bg);
}

html[data-announcement-bar-initially-dismissed='true'] .announcementBar {
display: none;
}

.announcementBarContent {
flex: 1;
}

.announcementBarClose {
z-index: 101;
text-align: right;
color: var(--ifm-announcement-bar-text-color) !important;
}

.announcementBarClose svg {
/* color: var(--ifm-announcement-bar-close-icon-color); */
width: 8px !important;
height: 8px !important;
}

.announcementBarClose svg g {
stroke-width: 1.9px !important;
}

.announcementBarIconWrapper {
padding: 6px;
display: flex;
justify-content: center;
align-items: center;
background-color: var(--ifm-announcement-bar-icon-bg);
border: 1px solid var(--ifm-announcement-bar-icon-border-color);
border-radius: var(--ifm-global-radius);
margin-right: 12px;
}

.announcementBarIcon {
width: 20px;
height: 20px;
}

.announcementBarLink {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
}

@media print {
.announcementBar {
display: none;
}
}

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

.announcementBarPlaceholder,
.announcementBarClose {
flex-basis: 50px;
}
}
8 changes: 2 additions & 6 deletions www/docs/src/theme/DocSidebar/Desktop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styles from './styles.module.css';
import DocSidebarItem from '@theme/DocSidebarItem';
import SearchBar from '../../SearchBar';
import useIsBrowser from '@docusaurus/useIsBrowser';
import AnnouncementBar from '@theme/AnnouncementBar';

function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
const {
Expand All @@ -21,18 +22,12 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
const sidebarRef = useRef(null)

useEffect(() => {
console.log("here1", isBrowser, sidebarRef.current)
if (isBrowser && sidebarRef.current) {
console.log("here2")
function handleScroll () {
console.log("handlescroll")
if (!sidebarRef.current.classList.contains('scrolling')) {
console.log("scrolling")
sidebarRef.current.classList.add('scrolling');
const intervalId = setInterval(() => {
console.log("interval")
if (!sidebarRef.current.matches(':hover')) {
console.log("remove class")
sidebarRef.current.classList.remove('scrolling');
clearInterval(intervalId);
}
Expand Down Expand Up @@ -62,6 +57,7 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
<div className={styles.sidebarSearchContainer}>
<SearchBar />
</div>
<AnnouncementBar />
<Content path={path} sidebar={sidebar} />
{sidebarFooter.length > 0 && (
<ul className={
Expand Down
54 changes: 47 additions & 7 deletions www/docs/src/theme/Layout/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import React, { useEffect } from 'react';

import Layout from '@theme-original/Layout';
import clsx from 'clsx';
import ErrorBoundary from '@docusaurus/ErrorBoundary';
import {
PageMetadata,
SkipToContentFallbackId,
ThemeClassNames,
} from '@docusaurus/theme-common';
import {useKeyboardNavigation} from '@docusaurus/theme-common/internal';
import SkipToContent from '@theme/SkipToContent';
import Navbar from '@theme/Navbar';
import Footer from '@theme/Footer';
import LayoutProvider from '@theme/Layout/Provider';
import ErrorPageContent from '@theme/ErrorPageContent';
import styles from './styles.module.css';
import useIsBrowser from '@docusaurus/useIsBrowser';
import {useLocation} from '@docusaurus/router';

export default function LayoutWrapper(props) {

export default function Layout(props) {
const {
children,
noFooter,
wrapperClassName,
// Not really layout-related, but kept for convenience/retro-compatibility
title,
description,
} = props;

const isBrowser = useIsBrowser();
const location = useLocation();

Expand All @@ -29,9 +49,29 @@ export default function LayoutWrapper(props) {
}
}, [isBrowser, location.pathname]);


useKeyboardNavigation();
return (
<>
<Layout {...props} />
</>
<LayoutProvider>
<PageMetadata title={title} description={description} />

<SkipToContent />

<Navbar />

<div
id={SkipToContentFallbackId}
className={clsx(
ThemeClassNames.wrapper.main,
styles.mainWrapper,
wrapperClassName,
)}>
<ErrorBoundary fallback={(params) => <ErrorPageContent {...params} />}>
{children}
</ErrorBoundary>
</div>

{!noFooter && <Footer />}
</LayoutProvider>
);
}
19 changes: 19 additions & 0 deletions www/docs/src/theme/Layout/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
html,
body {
height: 100%;
}

.mainWrapper {
flex: 1 0 auto;
}

/* Docusaurus-specific utility class */
:global(.docusaurus-mt-lg) {
margin-top: 3rem;
}

:global(#__docusaurus) {
min-height: 100%;
display: flex;
flex-direction: column;
}
Binary file added www/docs/static/img/bell-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added www/docs/static/img/bell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.