Skip to content

Commit

Permalink
docs: expand menu nav section with currently viewed page highlighted (#…
Browse files Browse the repository at this point in the history
…2791)

* docs: added keep the menu nav section of viewed page expanded

* refactor: some refactoring

* feat: added logic for non components pages

* refactor: fixed categories of some components

* refactor: refactoring after reviw

* refactor: foundationLinks refactoring

* fix: fixed CSS Utilities and Brand icons labels
  • Loading branch information
PKulkoRaccoonGang authored Nov 17, 2023
1 parent c373ab9 commit 583ea20
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/Avatar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ components:
- Avatar
categories:
- Imagery & Iconography
- Content
status: 'New'
designStatus: 'Done'
devStatus: 'Done'
Expand Down
2 changes: 1 addition & 1 deletion src/CheckBox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ categories:
- Forms (deprecated)
status: 'Deprecate Soon'
designStatus: 'TBD'
devStatus: 'To Do'
devStatus: 'Done'
notes: |
Replaced by Form.Checkbox
---
Expand Down
1 change: 0 additions & 1 deletion src/Image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ title: 'Image'
type: 'component'
categories:
- Imagery & Iconography
- Content
components:
- Image
status: 'Stable'
Expand Down
1 change: 0 additions & 1 deletion src/SearchField/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ components:
- SearchFieldSubmitButton
categories:
- Forms
- Navigation
status: 'Stable'
designStatus: 'Needs Review'
devStatus: 'Done'
Expand Down
1 change: 0 additions & 1 deletion src/SelectableBox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ components:
- SelectableBoxSet
categories:
- Forms
- Content
status: 'New'
designStatus: 'Done'
devStatus: 'In progress'
Expand Down
1 change: 0 additions & 1 deletion src/Spinner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ components:
- Spinner
categories:
- Status & metadata
- Choreography
designStatus: 'Done'
devStatus: 'Done'
notes: |
Expand Down
1 change: 0 additions & 1 deletion src/Stepper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ components:
- StepperHeaderStep
categories:
- Navigation
- Content
designStatus: 'Done'
devStatus: 'Done'
notes: |
Expand Down
2 changes: 1 addition & 1 deletion src/Table/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Table (Deprecated)'
title: 'Table'
type: 'component'
components:
- TableDeprecated
Expand Down
2 changes: 2 additions & 0 deletions src/Truncate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: 'Truncate'
type: 'component'
components:
- Truncate
categories:
- Content
status: 'New'
designStatus: 'Done'
devStatus: 'Done'
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useIndexOfLastVisibleChild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ title: 'useIndexOfLastVisibleChild'
type: 'hook'
categories:
- Hooks
- Layout
components:
- useIndexOfLastVisibleChild
status: 'New'
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useIsVisible.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ title: 'useIsVisible'
type: 'hook'
categories:
- Hooks
- Layout
components:
- useIsVisible
status: 'Stable'
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useWindowSize.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ title: 'useWindowSize'
type: 'hook'
categories:
- Hooks
- Layout
components:
- useWindowSize
status: 'New'
Expand Down
21 changes: 13 additions & 8 deletions www/src/components/Menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
padding: $spacer .625rem 2rem;
border-right: $border-width solid $light-400;

&-title {
.pgn-doc__menu-title {
font-size: $h4-font-size;
line-height: $line-height-base;
font-weight: $font-weight-normal;
color: $gray-700;
}

&-btn--group {
.pgn-doc__menu-btn--group {
padding-bottom: $spacer;
border-bottom: $border-width solid $light-400;
margin-bottom: $spacer;
Expand All @@ -33,13 +33,13 @@
}
}

&-component--list-category {
.pgn-doc__menu-component--list-category {
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
break-inside: avoid;
}

&-items {
.pgn-doc__menu-items {
margin-bottom: $spacer;

.pgn_collapsible {
Expand Down Expand Up @@ -68,8 +68,13 @@
font-weight: $font-weight-normal;
color: $gray-700;

&.active {
font-weight: $font-weight-bold;
text-decoration: $inline-link-decoration;
}

&:hover {
text-decoration: underline;
text-decoration: $inline-link-decoration;
}
}
}
Expand Down Expand Up @@ -103,8 +108,8 @@
}
}

&-playground {
&--title {
.pgn-doc__menu-playground {
.pgn-doc__menu-playground--title {
font-size: $font-size-base;
line-height: $line-height-base;
font-weight: $font-weight-bold;
Expand All @@ -120,7 +125,7 @@

.pgn__hyperlink {
color: $info-500;
text-decoration: underline;
text-decoration: $inline-link-decoration;
margin-left: .125rem;
}
}
Expand Down
80 changes: 60 additions & 20 deletions www/src/components/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useContext } from 'react';
import { useLocation } from '@reach/router';
import PropTypes from 'prop-types';
import { Link, graphql, useStaticQuery } from 'gatsby';
import {
Expand All @@ -9,10 +10,13 @@ import {
Collapsible,
Hyperlink,
ButtonGroup,
Image,
} from '~paragon-react';
import classNames from 'classnames';
import Search from './Search';
import { SettingsContext } from '../context/SettingsContext';
import { THEMES } from '../../theme-config';
import { FOUNDATION_PAGES } from '../config';

// MDX transforms markdown generated by gatsby-transformer-react-docgen
// This query filters out all of those markdown nodes and assumes all others
Expand Down Expand Up @@ -66,21 +70,32 @@ export interface IComponentNavItem {
type: string,
status?: string,
},
isActive: boolean,
}

export function ComponentNavItem({
id, fields, frontmatter, ...props
id, fields, frontmatter, isActive, ...props
}: IComponentNavItem) {
const isDeprecated = frontmatter?.status?.toLowerCase().includes('deprecate') || false;
const linkNode = isDeprecated ? (
<OverlayTrigger
placement="right"
overlay={<Tooltip id={`tooltip-deprecated-${id}`}>Deprecated</Tooltip>}
>
<Link className="text-muted" to={fields.slug}>{frontmatter.title}</Link>
<Link
className={classNames('text-muted', { active: isActive })}
to={fields.slug}
>
{frontmatter.title}
</Link>
</OverlayTrigger>
) : (
<Link to={fields.slug}>{frontmatter.title}</Link>
<Link
className={classNames({ active: isActive })}
to={fields.slug}
>
{frontmatter.title}
</Link>
);

return (
Expand All @@ -99,6 +114,7 @@ ComponentNavItem.propTypes = {
title: PropTypes.string.isRequired,
status: PropTypes.string,
}).isRequired,
isActive: PropTypes.bool.isRequired,
};

export type MenuComponentListTypes = {
Expand Down Expand Up @@ -150,15 +166,12 @@ interface IMenuQueryComponents {
all: Array<IComponentNavItem>
}

const foundationLinks = [
'Colors', 'Elevation', 'Typography', 'Layout', 'Spacing', 'Icons', 'CSS-Utilities', 'Responsive', 'Brand-icons',
];

function Menu() {
const {
settings,
handleSettingsChange,
} = useContext(SettingsContext);
const { pathname } = useLocation();
const { components } = useStaticQuery(menuQuery);
const { categories }: IMenuQueryComponents = components;

Expand All @@ -185,43 +198,58 @@ function Menu() {
<Collapsible
styling="basic"
title="Guides"
defaultOpen={pathname.startsWith('/guides')}
>
<ul className="list-unstyled">
<li>
<Link to="/guides/installation-and-usage">
<Link
className={classNames({ active: pathname.endsWith('getting-started') })}
to="/guides/getting-started"
>
Getting started
</Link>
</li>
<li>
<a
<Hyperlink
destination="https://openedx.atlassian.net/wiki/spaces/BPL/pages/1773502564/Component+Contribution+Process"
target="_blank"
rel="noopener noreferrer"
href="https://openedx.atlassian.net/wiki/spaces/BPL/pages/1773502564/Component+Contribution+Process"
>
Contributing
</a>
</Hyperlink>
</li>
</ul>
</Collapsible>
<Collapsible
styling="basic"
title="Foundations"
defaultOpen={pathname.startsWith('/foundations')}
>
<ul className="list-unstyled foundations-list">
{foundationLinks.map(link => (
<li key={link}>
<Link to={`/foundations/${link.toLowerCase().trim()}`}>{link.replace(/-/g, ' ')}</Link>
{FOUNDATION_PAGES.map(({ label, path }) => (
<li key={path}>
<Link
className={classNames({ active: pathname.endsWith(path) })}
to={path}
>
{label}
</Link>
</li>
))}
</ul>
</Collapsible>
<Collapsible
styling="basic"
title="Tools"
defaultOpen={pathname.startsWith('/tools') || pathname.startsWith('/insights')}
>
<ul className="list-unstyled foundations-list">
<li>
<Link to="/insights">Usage Insights</Link>
<Link
className={classNames({ active: pathname.endsWith('insights') })}
to="/insights"
>
Usage Insights
</Link>
</li>
<li>
<Link to="/playground" onClick={handlePlaygroundClick}>
Expand All @@ -230,7 +258,12 @@ function Menu() {
</Link>
</li>
<li>
<Link to="/tools/component-generator">Component Generator</Link>
<Link
className={classNames({ active: pathname.endsWith('component-generator') })}
to="/tools/component-generator"
>
Component Generator
</Link>
</li>
<li>
<Hyperlink
Expand All @@ -252,9 +285,16 @@ function Menu() {
key={fieldValue}
styling="basic"
title={fieldValue}
defaultOpen={nodes.some(({ fields }) => fields.slug === pathname)}
>
<ul className="list-unstyled">
{nodes.map((node) => <ComponentNavItem key={node.id} {...node} />)}
{nodes.map((node) => (
<ComponentNavItem
key={node.id}
{...node}
isActive={pathname === node.fields.slug}
/>
))}
</ul>
</Collapsible>
))}
Expand All @@ -266,8 +306,8 @@ function Menu() {
externalLinkTitle="Paragon npm"
target="_blank"
>
<img
className="d-inline-block mr-2"
<Image
className="mr-2"
src="https://img.shields.io/npm/v/@edx/paragon.svg"
alt="npm_version"
width={94}
Expand Down
Loading

0 comments on commit 583ea20

Please sign in to comment.