Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import './BackButton.scss';

type Props = {
className?: string,
to?: Location,
to?: Location | string,
};

const BackButton = ({ className, to, ...rest }: Props) => (
Expand Down
35 changes: 35 additions & 0 deletions src/elements/common/nav-button/BackButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';
import classNames from 'classnames';
import { FormattedMessage } from 'react-intl';
import { Route } from 'react-router-dom';
import type { Location } from 'history';
import IconNavigateLeft from '../../../icons/general/IconNavigateLeft';
import PlainButton from '../../../components/plain-button';
import messages from '../messages';
import { ButtonType } from '../../../components/button';
import './BackButton.scss';

export interface BackButtonProps {
className?: string;
to?: Location;
}

const BackButton = ({ className, to, ...rest }: BackButtonProps) => (
<Route>
{({ history }) => (
<PlainButton
className={classNames('bdl-BackButton', className)}
onClick={() => (to ? history.push(to) : history.goBack())}
type={ButtonType.BUTTON}
{...rest}
>
<IconNavigateLeft height={24} width={24} />
<span className="accessibility-hidden">
<FormattedMessage {...messages.back} />
</span>
</PlainButton>
)}
</Route>
);

export default BackButton;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import type { Match, Location } from 'react-router-dom';
import PlainButton from '../../../components/plain-button';
import { isLeftClick } from '../../../utils/dom';

// Custom Location type that makes hash optional
type CustomLocation = {
...Location,
hash?: string,
};

type Props = {
activeClassName?: string,
children: React.Node,
Expand All @@ -22,7 +28,7 @@ type Props = {
onClick?: (event: SyntheticEvent<>) => void,
replace?: boolean,
strict?: boolean,
to: string | Location,
to: string | CustomLocation,
};

const NavButton = React.forwardRef<Props, React.Ref<any>>((props: Props, ref: React.Ref<any>) => {
Expand Down
77 changes: 77 additions & 0 deletions src/elements/common/nav-button/NavButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as React from 'react';
import classNames from 'classnames';
import { Route } from 'react-router-dom';
import type { match } from 'react-router';
import type { Location } from 'history';
import PlainButton, { PlainButtonProps } from '../../../components/plain-button';
import { isLeftClick } from '../../../utils/dom';

export interface NavButtonProps {
activeClassName?: string;
children: React.ReactNode;
className?: string;
component?: React.ComponentType<PlainButtonProps & { ref?: React.Ref<HTMLButtonElement> }>;
exact?: boolean;
isActive?: (match: match, location: Location) => boolean;
isDisabled?: boolean;
onClick?: (event: React.SyntheticEvent) => void;
replace?: boolean;
strict?: boolean;
to: string | Location;
}

const NavButton = React.forwardRef<HTMLButtonElement, NavButtonProps>(
(props: NavButtonProps, ref: React.Ref<HTMLButtonElement>) => {
const {
activeClassName = 'bdl-is-active',
children,
className = 'bdl-NavButton',
component: Component = PlainButton,
exact,
isActive,
isDisabled,
onClick,
replace,
strict,
to,
...rest
} = props;
const path = typeof to === 'object' ? to.pathname : to;

const disabledClassName = 'bdl-is-disabled';

return (
<Route exact={exact} path={path} strict={strict}>
{({ history, location, match }) => {
const isActiveValue = !!(isActive ? isActive(match, location) : match);

return (
<Component
className={classNames(className, {
[activeClassName]: isActiveValue,
[disabledClassName]: isDisabled,
})}
isDisabled={isDisabled}
onClick={event => {
if (onClick) {
onClick(event);
}

if (!event.defaultPrevented && isLeftClick(event)) {
const method = replace ? history.replace : history.push;
method(to);
}
}}
ref={ref}
{...rest}
>
{children}
</Component>
);
}}
</Route>
);
},
);

export default NavButton;
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// @flow
export { default as BackButton } from './BackButton';
export { default } from './NavButton';
4 changes: 4 additions & 0 deletions src/elements/common/nav-button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { default as BackButton } from './BackButton';
export { default } from './NavButton';
export type { BackButtonProps } from './BackButton';
export type { NavButtonProps } from './NavButton';
86 changes: 86 additions & 0 deletions src/elements/content-sidebar/SidebarNavButton.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* @flow
* @file Preview sidebar nav button component
* @author Box
*/

import * as React from 'react';
import { Route } from 'react-router-dom';
import noop from 'lodash/noop';
import NavButton from '../common/nav-button';
import Tooltip from '../../components/tooltip/Tooltip';
import './SidebarNavButton.scss';

type Props = {
'data-resin-target'?: string,
'data-testid'?: string,
children: React.Node,
elementId?: string,
isDisabled?: boolean,
isOpen?: boolean,
onClick?: (sidebarView: string) => void,
sidebarView: string,
tooltip: React.Node,
};

const SidebarNavButton = React.forwardRef<Props, React.Ref<any>>((props: Props, ref: React.Ref<any>) => {
const {
'data-resin-target': dataResinTarget,
'data-testid': dataTestId,
children,
elementId = '',
isDisabled,
isOpen,
onClick = noop,
sidebarView,
tooltip,
} = props;
const sidebarPath = `/${sidebarView}`;

const handleNavButtonClick = () => {
onClick(sidebarView);
};

return (
<Route path={sidebarPath}>
{({ match }) => {
const isMatch = !!match;
const isActive = () => isMatch && !!isOpen;
const isActiveValue = isActive();
const isExactMatch = isMatch && match.isExact;
const id = `${elementId}${elementId === '' ? '' : '_'}${sidebarView}`;

return (
<Tooltip position="middle-left" text={tooltip} isTabbable={false}>
<NavButton
activeClassName="bcs-is-selected"
aria-selected={isActiveValue}
aria-controls={`${id}-content`}
aria-label={tooltip}
className="bcs-NavButton"
data-resin-target={dataResinTarget}
data-testid={dataTestId}
getDOMRef={ref}
id={id}
isActive={isActive}
isDisabled={isDisabled}
onClick={handleNavButtonClick}
replace={isExactMatch}
role="tab"
tabIndex={isActiveValue ? '0' : '-1'}
to={{
pathname: sidebarPath,
state: { open: true },
}}
type="button"
>
{children}
</NavButton>
</Tooltip>
);
}}
</Route>
);
});

export default SidebarNavButton;
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @flow
* @file Static Versions Sidebar component
* @author Box
*/

import * as React from 'react';
import { FormattedMessage } from 'react-intl';

import BoxDrive140 from '../../../illustration/BoxDrive140';

import { BackButton } from '../../common/nav-button';
import PrimaryButton from '../../../components/primary-button';
import { LoadingIndicatorWrapper } from '../../../components/loading-indicator';
import VersionsMenu from './VersionsMenu';

import messages from './messages';

import './StaticVersionsSidebar.scss';

type Props = {
isLoading: boolean,
onUpgradeClick: () => void,
parentName: string,
};

const StaticVersionsSidebar = ({ isLoading, onUpgradeClick, parentName }: Props): React.Node => {
const versionTimestamp = new Date();
versionTimestamp.setDate(versionTimestamp.getDate() - 1);

const versions = ['1', '2', '3'].map(versionNumber => {
return {
id: versionNumber,
version_number: versionNumber,
type: 'file_version',
permissions: {
can_preview: true,
},
created_at: versionTimestamp.toUTCString(),
modified_by: null,
size: 1875887,
trashed_at: null,
uploader_display_name: 'John Doe',
};
});

return (
<div
className="bcs-StaticVersionSidebar"
role="tabpanel"
data-resin-component="preview"
data-resin-feature="versions"
>
<div className="bcs-StaticVersionSidebar-header">
<h3 className="bcs-StaticVersionSidebar-title">
<>
<BackButton data-resin-target="back" to={`/${parentName}`} />
<FormattedMessage {...messages.versionsTitle} />
</>
</h3>
</div>

<div className="bcs-StaticVersionSidebar-content-wrapper">
<LoadingIndicatorWrapper
className="bcs-StaticVersionSidebar-content"
crawlerPosition="top"
isLoading={isLoading}
>
<VersionsMenu versions={versions} fileId="1" versionCount={3} versionLimit={3} />
</LoadingIndicatorWrapper>
</div>

<div className="bcs-StaticVersionSidebar-upsell-wrapper">
<div className="bcs-StaticVersionSidebar-upsell">
<BoxDrive140 className="bcs-StaticVersionSidebar-upsell-icon" />
<p className="bcs-StaticVersionSidebar-upsell-header">
<FormattedMessage {...messages.versionUpgradeLink} />
</p>
<p>
<FormattedMessage {...messages.versionUpsell} />
</p>
<PrimaryButton
className="bcs-StaticVersionSidebar-upsell-button"
data-resin-target="versioning_error_upgrade_cta"
onClick={onUpgradeClick}
type="button"
>
<FormattedMessage {...messages.upgradeButton} />
</PrimaryButton>
</div>
</div>
</div>
);
};

export default StaticVersionsSidebar;
Loading