Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buttons refactoring #3300

Merged
merged 22 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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
25 changes: 0 additions & 25 deletions catalog/app/components/ButtonIcon/ButtonIcon.tsx

This file was deleted.

1 change: 0 additions & 1 deletion catalog/app/components/ButtonIcon/index.ts

This file was deleted.

53 changes: 53 additions & 0 deletions catalog/app/components/Buttons/ButtonIconized.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import cx from 'classnames'
import * as React from 'react'
import * as M from '@material-ui/core'

const useStyles = M.makeStyles({
icon: {
transition: 'ease transform .15s',
},
iconRotated: {
transform: `rotate(180deg)`,
},
})

interface ButtonIconShrinkingProps extends M.IconButtonProps {
icon: string
label: string
rotate?: boolean
variant?: 'text' | 'outlined' | 'contained'
}

export default function ButtonIconShrinking({
className,
label,
icon,
rotate,
variant = 'outlined',
...props
}: ButtonIconShrinkingProps) {
const classes = useStyles()
const t = M.useTheme()
const sm = M.useMediaQuery(t.breakpoints.down('sm'))
const iconElement = (
<M.Icon className={cx(classes.icon, { [classes.iconRotated]: rotate })}>
{icon}
</M.Icon>
)

return sm ? (
<M.IconButton className={className} edge="end" size="small" title={label} {...props}>
{iconElement}
</M.IconButton>
) : (
<M.Button
className={className}
size="small"
startIcon={iconElement}
variant={variant}
{...props}
>
{label}
</M.Button>
)
}
1 change: 1 addition & 0 deletions catalog/app/components/Buttons/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Iconized } from './ButtonIconized'
58 changes: 5 additions & 53 deletions catalog/app/components/FileEditor/Controls.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import * as M from '@material-ui/core'

import * as Buttons from 'components/Buttons'
import { EditorState } from './State'

interface AddFileButtonProps {
Expand All @@ -15,55 +16,6 @@ export function AddFileButton({ onClick }: AddFileButtonProps) {
)
}

interface ButtonControlProps {
disabled?: boolean
className?: string
color?: 'primary'
icon: string
label: string
onClick: (event: React.MouseEvent) => void
variant?: 'outlined' | 'contained'
}

// TODO: use components/Buttons/ShrinkedIconButton
function ButtonControl({
disabled,
className,
color,
icon,
label,
onClick,
variant = 'outlined',
}: ButtonControlProps) {
const t = M.useTheme()
const sm = M.useMediaQuery(t.breakpoints.down('sm'))
return sm ? (
<M.IconButton
className={className}
disabled={disabled}
edge="end"
size="small"
onClick={onClick}
title={label}
color={color}
>
<M.Icon>{icon}</M.Icon>
</M.IconButton>
) : (
<M.Button
className={className}
color={color}
disabled={disabled}
onClick={onClick}
size="small"
startIcon={<M.Icon>{icon}</M.Icon>}
variant={variant}
>
{label}
</M.Button>
)
}

interface ControlsProps extends EditorState {
className?: string
}
Expand All @@ -88,7 +40,7 @@ export function Controls({
onEdit(types[0])
}
},
[onEdit, types],
[hasMultipleChoices, onEdit, types],
)
const handleTypeClick = React.useCallback(
(type) => {
Expand All @@ -100,7 +52,7 @@ export function Controls({
if (!editing)
return (
<>
<ButtonControl
<Buttons.Iconized
className={className}
disabled={disabled}
icon="edit"
Expand All @@ -120,8 +72,8 @@ export function Controls({
)
return (
<M.ButtonGroup disabled={disabled} className={className} size="small">
<ButtonControl icon="undo" onClick={onCancel} label="Cancel" />
<ButtonControl
<Buttons.Iconized icon="undo" onClick={onCancel} label="Cancel" />
<Buttons.Iconized
color="primary"
icon="save"
label="Save"
Expand Down
16 changes: 2 additions & 14 deletions catalog/app/components/Preview/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
import cx from 'classnames'
import * as React from 'react'
import * as M from '@material-ui/core'

import * as AWS from 'utils/AWS'
import * as LogicalKeyResolver from 'utils/LogicalKeyResolver'

const useStyles = M.makeStyles((t) => ({
root: {
alignItems: 'center',
display: 'flex',
height: t.spacing(4),
justifyContent: 'center',
width: t.spacing(3),
},
}))

interface MenuProps {
className?: string
handle: LogicalKeyResolver.S3SummarizeHandle
}

export default function Menu({ className, handle }: MenuProps) {
const classes = useStyles()
const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null)
const downloadUrl = AWS.Signer.useDownloadUrl(handle)
const handleClose = React.useCallback(() => setAnchorEl(null), [])
const handleOpen = React.useCallback((e) => setAnchorEl(e.currentTarget), [])
return (
<div className={cx(classes.root, className)}>
<M.IconButton onClick={handleOpen}>
<div className={className}>
<M.IconButton onClick={handleOpen} size="small">
<M.Icon>more_vert</M.Icon>
</M.IconButton>
<M.Menu anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}>
Expand Down
49 changes: 0 additions & 49 deletions catalog/app/components/Preview/ToggleButton.tsx

This file was deleted.

1 change: 0 additions & 1 deletion catalog/app/components/Preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export { default as render } from './render'
export { default as load, getRenderProps } from './load'
export { PreviewData, PreviewError, CONTEXT } from './types'
export { default as Menu } from './Menu'
export { default as ToggleButton } from './ToggleButton'
9 changes: 8 additions & 1 deletion catalog/app/components/SearchResults/SearchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom'
import * as M from '@material-ui/core'

import { copyWithoutSpaces } from 'components/BreadCrumbs'
import * as Buttons from 'components/Buttons'
import JsonDisplay from 'components/JsonDisplay'
import Pagination from 'components/Pagination2'
import * as Preview from 'components/Preview'
Expand Down Expand Up @@ -93,7 +94,13 @@ function ObjectHeader({ handle, showBucket, downloadable = false, expanded, onTo
<Heading display="flex" alignItems="center" mb="0 !important">
<ObjectCrumbs {...{ handle, showBucket }} />
<M.Box flexGrow={1} />
<Preview.ToggleButton expanded={expanded} onToggle={onToggle} mr={1} />
<Buttons.Iconized
label={expanded ? 'Collapse' : 'Expand'}
icon={expanded ? 'unfold_less' : 'unfold_more'}
rotate={expanded}
onClick={onToggle}
mr={1}
/>
{!!downloadable && (
<Preview.Menu handle={handle} expanded={expanded} onToggle={onToggle} />
)}
Expand Down
12 changes: 4 additions & 8 deletions catalog/app/components/SelectDropdown/SelectDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface SelectDropdownProps<Value extends ValueBase> {
onOpen?: () => void
options: Value[]
value: ValueBase
className?: string
}

export default function SelectDropdown<Value extends ValueBase>({
Expand All @@ -61,8 +62,7 @@ export default function SelectDropdown<Value extends ValueBase>({
onOpen,
options,
value,
...props
}: M.PaperProps & SelectDropdownProps<Value>) {
}: SelectDropdownProps<Value>) {
const classes = useStyles()

const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null)
Expand Down Expand Up @@ -94,11 +94,7 @@ export default function SelectDropdown<Value extends ValueBase>({
const { className: buttonClassName, ...buttonProps } = ButtonProps || {}

return (
<M.Paper
className={cx(className, classes.root, { [classes.disabled]: disabled })}
elevation={0}
{...props}
>
<div className={cx(className, classes.root, { [classes.disabled]: disabled })}>
<M.Button
className={cx(classes.button, buttonClassName)}
onClick={handleOpen}
Expand Down Expand Up @@ -141,6 +137,6 @@ export default function SelectDropdown<Value extends ValueBase>({
))
: emptySlot}
</M.Menu>
</M.Paper>
</div>
)
}
Loading