Skip to content

Commit

Permalink
refactor: refactoring after reviw
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Nov 15, 2023
1 parent 222460e commit b8e5dfa
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 160 deletions.
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/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
73 changes: 34 additions & 39 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 Down Expand Up @@ -68,29 +69,28 @@ export interface IComponentNavItem {
type: string,
status?: string,
},
componentName: string,
isActive: boolean,
}

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

ComponentNavItem.defaultProps = {
componentName: undefined,
isActive: PropTypes.bool.isRequired,
};

export type MenuComponentListTypes = {
Expand Down Expand Up @@ -173,11 +169,12 @@ const foundationLinks = [
'Colors', 'Elevation', 'Typography', 'Layout', 'Spacing', 'Icons', 'CSS-Utilities', 'Responsive', 'Brand-icons',
];

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

Expand All @@ -204,12 +201,12 @@ function Menu({ componentName, componentCategories }) {
<Collapsible
styling="basic"
title="Guides"
defaultOpen={componentCategories === 'guides'}
defaultOpen={pathname.startsWith('/guides')}
>
<ul className="list-unstyled">
<li>
<Link
className={classNames({ active: componentName === 'getting-started' })}
className={classNames({ active: pathname.endsWith('getting-started') })}
to="/guides/getting-started"
>
Getting started
Expand All @@ -228,29 +225,37 @@ function Menu({ componentName, componentCategories }) {
<Collapsible
styling="basic"
title="Foundations"
defaultOpen={componentCategories === 'foundations'}
defaultOpen={pathname.startsWith('/foundations')}
>
<ul className="list-unstyled foundations-list">
{foundationLinks.map(link => (
<li key={link}>
<Link
className={classNames({ active: componentName === link.toLowerCase().trim() })}
to={`/foundations/${link.toLowerCase().trim()}`}
>
{link.replace(/-/g, ' ')}
</Link>
</li>
))}
{foundationLinks.map(link => {
const isActive = pathname.endsWith(link.toLowerCase()) && !pathname.endsWith(`brand-${link.toLowerCase()}`);
return (
<li key={link}>
<Link
className={classNames({ active: isActive })}
to={`/foundations/${link.toLowerCase().trim()}`}
>
{link.replace(/-/g, ' ')}
</Link>
</li>
);
})}
</ul>
</Collapsible>
<Collapsible
styling="basic"
title="Tools"
defaultOpen={componentCategories === 'tools'}
defaultOpen={pathname.startsWith('/tools') || pathname.startsWith('/insights')}
>
<ul className="list-unstyled foundations-list">
<li>
<Link className={classNames({ active: componentName === 'insights' })} 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 @@ -260,7 +265,7 @@ function Menu({ componentName, componentCategories }) {
</li>
<li>
<Link
className={classNames({ active: componentName === 'component-generator' })}
className={classNames({ active: pathname.endsWith('component-generator') })}
to="/tools/component-generator"
>
Component Generator
Expand All @@ -286,14 +291,14 @@ function Menu({ componentName, componentCategories }) {
key={fieldValue}
styling="basic"
title={fieldValue}
defaultOpen={componentCategories?.includes(fieldValue)}
defaultOpen={nodes.some(({ fields }) => fields.slug === pathname)}
>
<ul className="list-unstyled">
{nodes.map((node) => (
<ComponentNavItem
key={node.id}
{...node}
componentName={componentName}
isActive={pathname === node.fields.slug}
/>
))}
</ul>
Expand All @@ -319,14 +324,4 @@ function Menu({ componentName, componentCategories }) {
);
}

Menu.propTypes = {
componentName: PropTypes.string,
componentCategories: PropTypes.arrayOf(PropTypes.string),
};

Menu.defaultProps = {
componentName: undefined,
componentCategories: undefined,
};

export default Menu;
12 changes: 1 addition & 11 deletions www/src/components/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export interface ILayout {
tab?: string,
isAutoToc?: boolean,
githubEditPath?: string,
componentName?: string,
componentCategories?: string[],
}

function Layout({
Expand All @@ -56,8 +54,6 @@ function Layout({
isAutoToc,
tab,
githubEditPath,
componentCategories,
componentName,
}: ILayout) {
const isMobile = useMediaQuery({ maxWidth: breakpoints.extraLarge.minWidth });
const { settings } = useContext(SettingsContext);
Expand All @@ -76,16 +72,14 @@ function Layout({
<Header
siteTitle={data.site.siteMetadata?.title || 'Title'}
showMinimizedTitle={isMobile || showMinimizedTitle}
componentCategories={componentCategories}
componentName={componentName}
/>
<Settings showMinimizedTitle={showMinimizedTitle} />
{isMdx || !hideFooterComponentMenu ? (
<Container fluid>
<Row className="flex-xl-nowrap">
<Col className="d-none d-xl-block p-0" xl={settings.containerWidth === 'xl' ? 'auto' : 2}>
<Sticky offset={6} className="pgn-doc__toc p-0 pt-3">
<Menu componentName={componentName} componentCategories={componentCategories} />
<Menu />
</Sticky>
</Col>
<Col
Expand Down Expand Up @@ -199,8 +193,6 @@ Layout.propTypes = {
isMdx: PropTypes.bool,
tab: PropTypes.string,
githubEditPath: PropTypes.string,
componentName: PropTypes.string,
componentCategories: PropTypes.arrayOf(PropTypes.string),
};

Layout.defaultProps = {
Expand All @@ -211,8 +203,6 @@ Layout.defaultProps = {
tab: undefined,
isAutoToc: false,
githubEditPath: undefined,
componentName: undefined,
componentCategories: undefined,
};

export default Layout;
14 changes: 3 additions & 11 deletions www/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ import Menu from '../Menu';
export interface IHeaderProps {
siteTitle: string,
showMinimizedTitle?: boolean,
componentName?: string,
componentCategories?: string[],
}

function Header({
siteTitle, showMinimizedTitle, componentName, componentCategories,
}: IHeaderProps) {
function Header({ siteTitle, showMinimizedTitle }: IHeaderProps) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [isOpen, , close, toggle] = useToggle(false);
const [target, setTarget] = useState(null);
Expand Down Expand Up @@ -52,7 +48,7 @@ function Header({
isFullscreenOnMobile
>
<div className="pgn-doc__header-home--menu">
<Menu componentName={componentName} componentCategories={componentCategories} />
<Menu />
</div>
</ModalDialog>
) : (
Expand All @@ -65,7 +61,7 @@ function Header({
onEscapeKey={close}
>
<div className="pgn-doc__header-home--menu">
<Menu componentName={componentName} componentCategories={componentCategories} />
<Menu />
</div>
</ModalPopup>
)}
Expand All @@ -77,15 +73,11 @@ function Header({
Header.propTypes = {
siteTitle: PropTypes.string,
showMinimizedTitle: PropTypes.bool,
componentName: PropTypes.string,
componentCategories: PropTypes.arrayOf(PropTypes.string),
};

Header.defaultProps = {
siteTitle: '',
showMinimizedTitle: false,
componentName: undefined,
componentCategories: undefined,
};

export default Header;
10 changes: 1 addition & 9 deletions www/src/pages/foundations/colors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,16 @@ export interface IColorsPage {
},
pageContext: {
githubEditPath: string,
componentName: string,
componentCategories: string[],
}
}

// eslint-disable-next-line react/prop-types
export default function ColorsPage({ data, pageContext }: IColorsPage) {
const { settings } = useContext(SettingsContext);
const { githubEditPath, componentCategories, componentName } = pageContext;
parseColors(data.allCssUtilityClasses.nodes); // eslint-disable-line react/prop-types

return (
<Layout
isAutoToc
githubEditPath={githubEditPath}
componentCategories={componentCategories}
componentName={componentName}
>
<Layout isAutoToc githubEditPath={pageContext.githubEditPath}>
{/* eslint-disable-next-line react/jsx-pascal-case */}
<SEO title="Colors" />
<Container size={settings.containerWidth} className="py-5">
Expand Down
10 changes: 1 addition & 9 deletions www/src/pages/foundations/elevation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ function BoxShadowGenerator() {

export default function ElevationPage({ pageContext }) {
const { settings } = useContext(SettingsContext);
const { githubEditPath, componentCategories, componentName } = pageContext;

const levelTitle = boxShadowLevels.map(level => (
<p key={level} className="pgn-doc__box-shadow-level-title h3">
Expand All @@ -285,12 +284,7 @@ export default function ElevationPage({ pageContext }) {
));

return (
<Layout
isAutoToc
githubEditPath={githubEditPath}
componentCategories={componentCategories}
componentName={componentName}
>
<Layout isAutoToc githubEditPath={pageContext.githubEditPath}>
{/* eslint-disable-next-line react/jsx-pascal-case */}
<SEO title="Elevation" />
<Container size={settings.containerWidth} className="py-5">
Expand Down Expand Up @@ -409,7 +403,5 @@ export default function ElevationPage({ pageContext }) {
ElevationPage.propTypes = {
pageContext: PropTypes.shape({
githubEditPath: PropTypes.string,
componentName: PropTypes.string,
componentCategories: PropTypes.arrayOf(PropTypes.string),
}).isRequired,
};
10 changes: 1 addition & 9 deletions www/src/pages/foundations/responsive.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function MaxWidthCell({ row }) {

function Responsive({ pageContext }) {
const { settings } = useContext(SettingsContext);
const { githubEditPath, componentCategories, componentName } = pageContext;
const breakpointsData = Object.keys(breakpoints).map(breakpoint => {
const { minWidth, maxWidth } = breakpoints[breakpoint];
const breakpointData = getBreakpointDescription(breakpoint);
Expand All @@ -61,12 +60,7 @@ function Responsive({ pageContext }) {
});

return (
<Layout
isAutoToc
githubEditPath={githubEditPath}
componentCategories={componentCategories}
componentName={componentName}
>
<Layout isAutoToc githubEditPath={pageContext.githubEditPath}>
{/* eslint-disable-next-line react/jsx-pascal-case */}
<SEO title="Responsive" />
<Container size={settings.containerWidth} className="py-5">
Expand Down Expand Up @@ -113,8 +107,6 @@ function Responsive({ pageContext }) {
Responsive.propTypes = {
pageContext: PropTypes.shape({
githubEditPath: PropTypes.string,
componentName: PropTypes.string,
componentCategories: PropTypes.arrayOf(PropTypes.string),
}).isRequired,
};

Expand Down
Loading

0 comments on commit b8e5dfa

Please sign in to comment.