Skip to content

Commit

Permalink
Merge pull request #105 from saucal/feature/refactor-plugin-navigation
Browse files Browse the repository at this point in the history
Feature/refactor plugin navigation
  • Loading branch information
ksere authored Jul 30, 2021
2 parents 3598d18 + b38e6f7 commit e0c33f3
Show file tree
Hide file tree
Showing 54 changed files with 36,088 additions and 1,022 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import SyncState from './sections/SyncState';
import SyncIssues from './sections/SyncIssues';
import TransientNotices from './components/TransientNotices';
import { useCreateNotice } from './helpers/effects';
import NavigationClassic from '../components/navigation-classic';

const App = () => {
const CatalogSyncApp = () => {
useCreateNotice( wcSettings.pin4wc.error );

return (
<div className="woocommerce-layout">
<div className="woocommerce-layout__main">
<div className="woocommerce-layout__main pin4wc-catalog-sync">
<NavigationClassic />

<TransientNotices />
<div className="pin4wc-catalog-sync__container">
<SyncState />
Expand All @@ -27,4 +30,4 @@ const App = () => {
);
};

export default App;
export default CatalogSyncApp;
123 changes: 0 additions & 123 deletions assets/source/catalog-sync/app/style.scss

This file was deleted.

File renamed without changes.
16 changes: 0 additions & 16 deletions assets/source/catalog-sync/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const SyncIssuesTable = ( {

const getRows = ( data ) => {
const statuses = {
success: 'green',
warning: 'yellow',
error: 'red',
success: 'success',
warning: 'warning',
error: 'error',
};

const icons = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Card,
CardHeader,
CardBody,
__experimentalText as Text,
__experimentalText as Text, // eslint-disable-line @wordpress/no-unsafe-wp-apis --- _experimentalText unlikely to change/disappear and also used by WC Core
} from '@wordpress/components';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const SyncStateTable = ( { workflow } ) => {

const getRows = ( data ) => {
const statuses = {
success: 'green',
pending: 'yellow',
warning: 'yellow',
error: 'red',
success: 'success',
pending: 'warning',
warning: 'warning',
error: 'error',
};

const icons = {
Expand Down
Empty file.
61 changes: 61 additions & 0 deletions assets/source/components/app-tab-nav/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* External dependencies
*/
import { NavigableMenu } from '@wordpress/components';
import { Link } from '@woocommerce/components';
import classnames from 'classnames';

/**
* Internal dependencies
*/
import './style.scss';

const TabLink = ( { tabId, href, children, selected, ...rest } ) => {
return (
<Link
role="tab"
tabIndex={ selected ? null : -1 }
aria-selected={ selected }
id={ tabId }
href={ href }
{ ...rest }
>
{ children }
</Link>
);
};

const AppTabNav = ( props ) => {
const { selectedKey, tabs } = props;

return (
<div className="app-tab-nav">
<NavigableMenu
role="tablist"
orientation="horizontal"
className="app-tab-nav__tabs"
>
{ tabs.map( ( tab ) => (
<TabLink
className={ classnames(
'components-button',
'app-tab-nav__tabs-item',
{
'is-active': tab.key === selectedKey,
}
) }
tabId={ `${ tab.key }` }
aria-controls={ `${ tab.key }-view` }
selected={ tab.key === selectedKey }
key={ tab.key }
href={ tab.href }
>
{ tab.title }
</TabLink>
) ) }
</NavigableMenu>
</div>
);
};

export default AppTabNav;
61 changes: 61 additions & 0 deletions assets/source/components/app-tab-nav/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.app-tab-nav__tabs {
display: flex;
align-items: stretch;
box-shadow: inset 0 -1px 0 #ccc;
margin-bottom: var(--main-gap);

&-item {
background: transparent;
border: none;
box-shadow: none;
border-radius: 0;
cursor: pointer;
height: 48px;
padding: 3px 16px; // Use padding to offset the is-active border, this benefits Windows High Contrast mode
margin-left: 0;
font-weight: 500;
//transition: box-shadow 0.1s linear;
box-sizing: border-box;

// This pseudo-element "duplicates" the tab label and sets the text to bold.
// This ensures that the tab doesn't change width when selected.
// See: https://github.com/WordPress/gutenberg/pull/9793
&::after {
content: attr(data-label);
display: block;
height: 0;
overflow: hidden;
speak: none;
visibility: hidden;
}

&:focus:not(:disabled) {
box-shadow: inset 0 2px var(--wp-admin-theme-color);
}

&.is-active {
// The transparent shadow ensures no jumpiness when focus animates on an active tab.
box-shadow: inset 0 0 0 2px transparent, inset 0 -4px 0 0 var(--wp-admin-theme-color);
position: relative;

// This border appears in Windows High Contrast mode instead of the box-shadow.
&::before {
content: "";
position: absolute;
top: 0;
bottom: 1px;
right: 0;
left: 0;
border-bottom: 4px solid transparent;
}
}

&:focus {
box-shadow: inset 0 0 0 2px var(--wp-admin-theme-color);
}

&.is-active:focus {
box-shadow: inset 0 0 0 2px var(--wp-admin-theme-color), inset 0 0 -4px 0 0 var(--wp-admin-theme-color);
}
}
}
17 changes: 17 additions & 0 deletions assets/source/components/navigation-classic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Internal dependencies
*/
import MainTabNav from './main-tab-nav';

/**
* Display tab-based navigation when the new WC Navigation is not enabled.
*
* @return {import("./main-tab-nav")} Retuns MainTabNav if WC Navigation is not enabled.
*/
const NavigationClassic = () => {
const navigationEnabled = !! window.wcAdminFeatures?.navigation;

return navigationEnabled ? null : <MainTabNav />;
};

export default NavigationClassic;
Loading

0 comments on commit e0c33f3

Please sign in to comment.