add custom tooltips for file explorer icons

pull/5370/head
Joseph Izang 2 years ago
parent 3abf767b3f
commit 252a1a78d4
  1. 69
      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-end'
}, },
{ {
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: 'bottom-start'
}, },
{ {
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: {}
@ -48,14 +55,13 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => {
<> <>
<span className='remixui_label' title={props.title} data-path={props.title} style={{ fontWeight: 'bold' }}>{ props.title }</span> <span className='remixui_label' title={props.title} data-path={props.title} style={{ fontWeight: 'bold' }}>{ props.title }</span>
<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 <label
id={action} id={action}
data-id={'fileExplorerUploadFile' + action } data-id={'fileExplorerUploadFile' + action }
className={icon + ' mb-0 remixui_newFile'} className={icon + ' mb-0 remixui_newFile'}
title={title}
key={index} key={index}
> >
<input id="fileUpload" data-id="fileExplorerFileUpload" type="file" onChange={(e) => { <input id="fileUpload" data-id="fileExplorerFileUpload" type="file" onChange={(e) => {
@ -68,27 +74,36 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => {
) )
} 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() key={`${action}-${title}-${index}`}
} 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={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