Merge pull request #3008 from ethereum/custom-tooltips-fe

add custom tooltips for file explorer icons
pull/3005/head
Joseph Izang 2 years ago committed by GitHub
commit 62a6f4d001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 112
      libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx
  2. 3
      libs/remix-ui/workspace/src/lib/types/index.ts

@ -1,4 +1,6 @@
import React, { useState, useEffect } from 'react' //eslint-disable-line import React, { useState, useEffect } from 'react' //eslint-disable-line
import { OverlayTrigger, Tooltip } from 'react-bootstrap'
import { Placement } from 'react-bootstrap/esm/Overlay'
import { FileExplorerMenuProps } from '../types' import { FileExplorerMenuProps } from '../types'
const _paq = window._paq = window._paq || [] const _paq = window._paq = window._paq || []
@ -8,27 +10,32 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => {
{ {
action: 'createNewFile', action: 'createNewFile',
title: 'Create New File', title: 'Create New File',
icon: 'far fa-file' icon: 'far fa-file',
placement: 'top-start'
}, },
{ {
action: 'createNewFolder', action: 'createNewFolder',
title: 'Create New Folder', title: 'Create New Folder',
icon: 'far fa-folder' icon: 'far fa-folder',
placement: 'top-end'
}, },
{ {
action: 'publishToGist', action: 'publishToGist',
title: 'Publish all the current workspace files (only root) to a github gist', title: 'Publish all the current workspace files (only root) to a github gist',
icon: 'fab fa-github' icon: 'fab fa-github',
placement: 'top-start'
}, },
{ {
action: 'uploadFile', action: 'uploadFile',
title: 'Load a local file into current workspace', title: 'Load a local file into current workspace',
icon: 'fa fa-upload' icon: 'fa fa-upload',
placement: 'right'
}, },
{ {
action: 'updateGist', action: 'updateGist',
title: 'Update the current [gist] explorer', title: 'Update the current [gist] explorer',
icon: 'fab fa-github' icon: 'fab fa-github',
placement: 'right-start'
} }
].filter(item => props.menuItems && props.menuItems.find((name) => { return name === item.action })), ].filter(item => props.menuItems && props.menuItems.find((name) => { return name === item.action })),
actions: {} actions: {}
@ -46,49 +53,74 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => {
return ( return (
<> <>
<span className='remixui_label' title={props.title} data-path={props.title} style={{ fontWeight: 'bold' }}>{ props.title }</span> <OverlayTrigger
placement="top-start"
overlay={
<Tooltip id="remixuilabelTooltip" className="text-nowrap">
<span>{props.title}</span>
</Tooltip>
}
>
<span className='remixui_label' data-path={props.title} style={{ fontWeight: 'bold' }}>{ props.title }</span>
</OverlayTrigger>
<span className="pl-2">{ <span className="pl-2">{
state.menuItems.map(({ action, title, icon }, index) => { state.menuItems.map(({ action, title, icon, placement }, index) => {
if (action === 'uploadFile') { if (action === 'uploadFile') {
return ( return (
<label <OverlayTrigger
id={action} placement="right"
data-id={'fileExplorerUploadFile' + action } overlay={
className={icon + ' mb-0 remixui_newFile'} <Tooltip id="uploadFileTooltip" className="text-nowrap">
title={title} <span>{title}</span>
key={index} </Tooltip>
}
> >
<input id="fileUpload" data-id="fileExplorerFileUpload" type="file" onChange={(e) => { <label
e.stopPropagation() id={action}
props.uploadFile(e.target) data-id={'fileExplorerUploadFile' + action }
e.target.value = null className={icon + ' mb-0 remixui_newFile'}
}} key={index}
multiple /> >
</label> <input id="fileUpload" data-id="fileExplorerFileUpload" type="file" onChange={(e) => {
e.stopPropagation()
props.uploadFile(e.target)
e.target.value = null
}}
multiple />
</label>
</OverlayTrigger>
) )
} else { } else {
return ( return (
<span <OverlayTrigger
id={action} placement={placement as Placement}
data-id={'fileExplorerNewFile' + action} overlay={
onClick={(e) => { <Tooltip id={`${action}-${title}-${icon}-${index}`} className="text-nowrap">
e.stopPropagation() <span>{title}</span>
_paq.push(['trackEvent', 'fileExplorer', 'fileAction', action]) </Tooltip>
if (action === 'createNewFile') { }
props.createNewFile()
} else if (action === 'createNewFolder') {
props.createNewFolder()
} else if (action === 'publishToGist') {
props.publishToGist()
} else {
state.actions[action]()
}
}}
className={'newFile ' + icon + ' remixui_newFile'}
title={title}
key={index}
> >
</span> <span
id={action}
data-id={'fileExplorerNewFile' + action}
onClick={(e) => {
e.stopPropagation()
_paq.push(['trackEvent', 'fileExplorer', 'fileAction', action])
if (action === 'createNewFile') {
props.createNewFile()
} else if (action === 'createNewFolder') {
props.createNewFolder()
} else if (action === 'publishToGist') {
props.publishToGist()
} else {
state.actions[action]()
}
}}
className={'newFile ' + icon + ' remixui_newFile'}
key={`${action}-${title}-${index}`}
>
</span>
</OverlayTrigger>
) )
} }
})} })}

@ -103,7 +103,7 @@ export interface FileExplorerProps {
dispatchMoveFile: (src: string, dest: string) => Promise<void>, dispatchMoveFile: (src: string, dest: string) => Promise<void>,
dispatchMoveFolder: (src: string, dest: string) => Promise<void> dispatchMoveFolder: (src: string, dest: string) => Promise<void>
} }
type Placement = import('react-overlays/usePopper').Placement
export interface FileExplorerMenuProps { export interface FileExplorerMenuProps {
title: string, title: string,
menuItems: string[], menuItems: string[],
@ -111,6 +111,7 @@ export interface FileExplorerMenuProps {
createNewFolder: (parentFolder?: string) => void, createNewFolder: (parentFolder?: string) => void,
publishToGist: (path?: string) => void, publishToGist: (path?: string) => void,
uploadFile: (target: EventTarget & HTMLInputElement) => void uploadFile: (target: EventTarget & HTMLInputElement) => void
tooltipPlacement?: Placement
} }
export interface FileExplorerContextMenuProps { export interface FileExplorerContextMenuProps {
actions: action[], actions: action[],

Loading…
Cancel
Save