feat: files page updated to latest design (#218)
* feat: altered the design of the tabs and redid the download tab * feat: redesign the upload file * fix: styles of tabs on hover * fix: display troubleshoot component when the status of the node is not OK * fix: when removing the file, remove the reference upload reference as well * fix: on inputs the label should not be selectable * feat: add placeholder to inputs and make the label non-selectable * refactor: improved the readability of the upload file component * chore: removed PeerDetail component * fix: replaced "batch" with (postage) "stamp" for clarity * refactor: address PR review comments * feat: disable the download button if there is no value
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { ReactElement, useState } from 'react'
|
||||
import { ReactElement, ChangeEvent, useState } from 'react'
|
||||
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'
|
||||
import Collapse from '@material-ui/core/Collapse'
|
||||
import { ListItem, Typography, Grid, IconButton, InputBase, Button } from '@material-ui/core'
|
||||
import { Edit, Minus, RotateCcw, Check } from 'react-feather'
|
||||
|
||||
import ExpandableListItemActions from './ExpandableListItemActions'
|
||||
import ExpandableListItemNote from './ExpandableListItemNote'
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) =>
|
||||
createStyles({
|
||||
@@ -33,44 +34,80 @@ const useStyles = makeStyles((theme: Theme) =>
|
||||
keyMargin: {
|
||||
marginRight: theme.spacing(1),
|
||||
},
|
||||
unselectableLabel: {
|
||||
cursor: 'default',
|
||||
userSelect: 'none',
|
||||
// Many browsers don't support yet the general user-select css property
|
||||
WebkitUserSelect: 'none',
|
||||
MozUserSelect: 'none',
|
||||
msUserSelect: 'none',
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
interface Props {
|
||||
label: string
|
||||
value: string
|
||||
value?: string
|
||||
placeholder?: string
|
||||
helperText?: string
|
||||
expandedOnly?: boolean
|
||||
confirmLabel?: string
|
||||
confirmLabelDisabled?: boolean
|
||||
onChange?: (value: string) => void
|
||||
onConfirm: (value: string) => void
|
||||
}
|
||||
|
||||
export default function ExpandableListItemKey({ label, value, onConfirm }: Props): ReactElement | null {
|
||||
export default function ExpandableListItemKey({
|
||||
label,
|
||||
value,
|
||||
onConfirm,
|
||||
onChange,
|
||||
confirmLabel,
|
||||
confirmLabelDisabled,
|
||||
expandedOnly,
|
||||
helperText,
|
||||
placeholder,
|
||||
}: Props): ReactElement | null {
|
||||
const classes = useStyles()
|
||||
const [open, setOpen] = useState(false)
|
||||
const [inputValue, setInputValue] = useState(value)
|
||||
const [open, setOpen] = useState(Boolean(expandedOnly))
|
||||
const [inputValue, setInputValue] = useState<string>(value || '')
|
||||
const toggleOpen = () => setOpen(!open)
|
||||
const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
setInputValue(e.target.value)
|
||||
|
||||
if (onChange) onChange(e.target.value)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ListItem className={`${classes.header} ${open ? classes.headerOpen : ''}`}>
|
||||
<Grid container direction="column" justifyContent="space-between" alignItems="stretch">
|
||||
<Grid container direction="row" justifyContent="space-between" alignItems="center">
|
||||
{label && <Typography variant="body1">{label}</Typography>}
|
||||
{label && (
|
||||
<Typography variant="body1" className={classes.unselectableLabel}>
|
||||
{label}
|
||||
</Typography>
|
||||
)}
|
||||
<Typography variant="body2">
|
||||
<div>
|
||||
{!open && value}
|
||||
<IconButton size="small" className={classes.copyValue}>
|
||||
{open ? (
|
||||
<Minus onClick={toggleOpen} strokeWidth={1} />
|
||||
) : (
|
||||
<Edit onClick={toggleOpen} strokeWidth={1} />
|
||||
)}
|
||||
</IconButton>
|
||||
{!expandedOnly && (
|
||||
<IconButton size="small" className={classes.copyValue}>
|
||||
{open ? (
|
||||
<Minus onClick={toggleOpen} strokeWidth={1} />
|
||||
) : (
|
||||
<Edit onClick={toggleOpen} strokeWidth={1} />
|
||||
)}
|
||||
</IconButton>
|
||||
)}
|
||||
</div>
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Collapse in={open} timeout="auto" unmountOnExit>
|
||||
<InputBase
|
||||
value={inputValue}
|
||||
onChange={e => setInputValue(e.target.value)}
|
||||
placeholder={placeholder}
|
||||
onChange={handleChange}
|
||||
fullWidth
|
||||
className={classes.content}
|
||||
autoFocus
|
||||
@@ -79,20 +116,25 @@ export default function ExpandableListItemKey({ label, value, onConfirm }: Props
|
||||
</Grid>
|
||||
</ListItem>
|
||||
<Collapse in={open} timeout="auto" unmountOnExit>
|
||||
{helperText && <ExpandableListItemNote>{helperText}</ExpandableListItemNote>}
|
||||
<ExpandableListItemActions>
|
||||
<Button
|
||||
variant="contained"
|
||||
disabled={inputValue === value}
|
||||
disabled={
|
||||
inputValue === value ||
|
||||
Boolean(confirmLabelDisabled) || // Disable if external validation is provided
|
||||
(inputValue === '' && value === undefined) // Disable if no initial value was not provided and the field is empty. The undefined check is improtant so that it is possible to submit with empty input in other cases
|
||||
}
|
||||
startIcon={<Check size="1rem" />}
|
||||
onClick={() => onConfirm(inputValue)}
|
||||
>
|
||||
Save
|
||||
{confirmLabel || 'Save'}
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
disabled={inputValue === value}
|
||||
disabled={inputValue === value || inputValue === ''}
|
||||
startIcon={<RotateCcw size="1rem" />}
|
||||
onClick={() => setInputValue(value)}
|
||||
onClick={() => setInputValue(value || '')}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import type { ReactElement } from 'react'
|
||||
import { Typography } from '@material-ui/core'
|
||||
|
||||
function truncStringPortion(str: string, firstCharCount = 10, endCharCount = 10) {
|
||||
return `${str.substring(0, firstCharCount)}...${str.substring(str.length - endCharCount, str.length)}`
|
||||
}
|
||||
|
||||
interface Props {
|
||||
peerId: string
|
||||
characterLength?: number
|
||||
}
|
||||
|
||||
export default function PeerDetail({ peerId, characterLength }: Props): ReactElement {
|
||||
return (
|
||||
<Typography
|
||||
variant="button"
|
||||
style={{
|
||||
fontFamily: 'monospace, monospace',
|
||||
}}
|
||||
>
|
||||
{truncStringPortion(peerId, characterLength, characterLength)}
|
||||
</Typography>
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
import React, { ReactElement, ReactNode } from 'react'
|
||||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import Tabs from '@material-ui/core/Tabs'
|
||||
import Tab from '@material-ui/core/Tab'
|
||||
import Typography from '@material-ui/core/Typography'
|
||||
import Box from '@material-ui/core/Box'
|
||||
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'
|
||||
import { Tab, Tabs } from '@material-ui/core'
|
||||
|
||||
interface TabPanelProps {
|
||||
children?: ReactNode
|
||||
@@ -16,24 +13,25 @@ function TabPanel(props: TabPanelProps) {
|
||||
|
||||
return (
|
||||
<div role="tabpanel" hidden={value !== index} {...other}>
|
||||
{value === index && (
|
||||
<Box p={3}>
|
||||
<Typography>{children}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
{value === index && children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
flexGrow: 1,
|
||||
},
|
||||
}))
|
||||
const useStyles = makeStyles((theme: Theme) =>
|
||||
createStyles({
|
||||
root: {
|
||||
flexGrow: 1,
|
||||
},
|
||||
content: {
|
||||
marginTop: theme.spacing(2),
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
interface TabsValues {
|
||||
component: ReactNode
|
||||
label: string
|
||||
label: ReactNode
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -55,16 +53,18 @@ export default function SimpleTabs({ values, index, indexChanged }: Props): Reac
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<Tabs value={v} onChange={handleChange}>
|
||||
<Tabs value={v} onChange={handleChange} variant="fullWidth">
|
||||
{values.map(({ label }, idx) => (
|
||||
<Tab key={idx} label={label} />
|
||||
))}
|
||||
</Tabs>
|
||||
{values.map(({ component }, idx) => (
|
||||
<TabPanel key={idx} value={v} index={idx}>
|
||||
{component}
|
||||
</TabPanel>
|
||||
))}
|
||||
<div className={classes.content}>
|
||||
{values.map(({ component }, idx) => (
|
||||
<TabPanel key={idx} value={v} index={idx}>
|
||||
{component}
|
||||
</TabPanel>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user