-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
572 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
wagtail_localize/static_src/common/components/LegacyActionMenu/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
import gettext from 'gettext'; | ||
|
||
import Icon from '../Icon'; | ||
|
||
interface ActionMenuButtonActionProps { | ||
label: string; | ||
onClick: () => void; | ||
title?: string; | ||
classes?: string[]; | ||
icon?: string; | ||
} | ||
|
||
export const ActionMenuButtonAction: FunctionComponent< | ||
ActionMenuButtonActionProps | ||
> = ({ label, onClick, title, classes, icon }) => { | ||
let classNames = ['button']; | ||
|
||
if (classes) { | ||
classNames = classNames.concat(classes); | ||
} | ||
|
||
return ( | ||
<button | ||
className={classNames.join(' ')} | ||
title={title} | ||
onClick={onClick} | ||
> | ||
{icon && <Icon name={icon} />} {label} | ||
</button> | ||
); | ||
}; | ||
|
||
interface ActionMenuLinkActionProps { | ||
label: string; | ||
href: string; | ||
title?: string; | ||
classes?: string[]; | ||
icon?: string; | ||
} | ||
|
||
export const ActionMenuLinkAction: FunctionComponent< | ||
ActionMenuLinkActionProps | ||
> = ({ label, href, title, classes, icon }) => { | ||
let classNames = ['button']; | ||
|
||
if (classes) { | ||
classNames = classNames.concat(classes); | ||
} | ||
|
||
return ( | ||
<a | ||
href={href} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className={classNames.join(' ')} | ||
title={title} | ||
> | ||
{icon && <Icon name={icon} />} {label} | ||
</a> | ||
); | ||
}; | ||
|
||
export interface PreviewMode { | ||
mode: string; | ||
label: string; | ||
url: string; | ||
} | ||
|
||
interface ActionMenuProps { | ||
defaultAction: React.ReactNode; | ||
actions: React.ReactNode[]; | ||
previewModes?: PreviewMode[]; | ||
} | ||
|
||
const LeagcyActionMenu: FunctionComponent<ActionMenuProps> = ({ | ||
defaultAction, | ||
actions, | ||
previewModes, | ||
}) => { | ||
const wrappedActions = actions.map((action) => <li>{action}</li>); | ||
|
||
return ( | ||
<nav aria-label="Actions"> | ||
<ul> | ||
<li className="actions actions--primary"> | ||
<div className="dropdown dropup dropdown-button match-width "> | ||
{defaultAction} | ||
|
||
<div className="dropdown-toggle"> | ||
<svg | ||
className="icon icon-arrow-up icon" | ||
aria-hidden="true" | ||
focusable="false" | ||
> | ||
<use href="#icon-arrow-up"></use> | ||
</svg> | ||
</div> | ||
<ul>{wrappedActions}</ul> | ||
</div> | ||
</li> | ||
|
||
{/* Single-mode preview */} | ||
{previewModes && previewModes.length == 1 && ( | ||
<li className="preview dropdown"> | ||
<a | ||
className="button button--icon" | ||
href={previewModes[0].url} | ||
target="_blank" | ||
> | ||
<svg | ||
className="icon icon-view icon" | ||
aria-hidden="true" | ||
focusable="false" | ||
> | ||
<use href="#icon-view"></use> | ||
</svg> | ||
{gettext('Preview')} | ||
</a> | ||
</li> | ||
)} | ||
|
||
{/* Multi-mode preview */} | ||
{previewModes && previewModes.length > 1 && ( | ||
<li className="preview"> | ||
<div className="dropdown dropup dropdown-button match-width"> | ||
<a | ||
className="button button--icon" | ||
href={previewModes[0].url} | ||
target="_blank" | ||
> | ||
<svg | ||
className="icon icon-view icon" | ||
aria-hidden="true" | ||
focusable="false" | ||
> | ||
<use href="#icon-view"></use> | ||
</svg> | ||
{gettext('Preview')} | ||
</a> | ||
|
||
<div className="dropdown-toggle"> | ||
<svg | ||
className="icon icon-arrow-up icon" | ||
aria-hidden="true" | ||
focusable="false" | ||
> | ||
<use href="#icon-arrow-up"></use> | ||
</svg> | ||
</div> | ||
|
||
<ul> | ||
{previewModes.map(({ label, url }) => { | ||
return ( | ||
<li> | ||
<a | ||
className="button" | ||
href={url} | ||
target="_blank" | ||
> | ||
{label} | ||
</a> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
</li> | ||
)} | ||
</ul> | ||
</nav> | ||
); | ||
}; | ||
|
||
export default LeagcyActionMenu; |
Oops, something went wrong.