Skip to content

Commit

Permalink
[components] Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard authored and rexxars committed Oct 6, 2020
1 parent 6ac4b76 commit 9b859ae
Show file tree
Hide file tree
Showing 47 changed files with 138 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface DefaultAutocompleteProps {
value?: string
}

// @todo: refactor to functional component
export default class DefaultAutocomplete extends React.PureComponent<DefaultAutocompleteProps> {
_inputId?: string = undefined

Expand Down
19 changes: 7 additions & 12 deletions packages/@sanity/components/src/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,13 @@ export function Avatar(props: AvatarProps) {
if (src) setImageFailed(false)
}, [src])

const handleImageError = useCallback(
evt => {
setImageFailed(true)

if (onImageLoadError) {
const err = new Error('Avatar: the image failed to load')
;(err as any).event = evt
onImageLoadError(err)
}
},
[onImageLoadError]
)
const handleImageError = useCallback(() => {
setImageFailed(true)

if (onImageLoadError) {
onImageLoadError(new Error('Avatar: the image failed to load'))
}
}, [onImageLoadError])

return (
<div
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/buttons/ButtonGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface ButtonGridProps {
align?: 'start' | 'end'
}

// @todo: refactor to functional component
export default class ButtonGrid extends React.PureComponent<
ButtonGridProps & React.HTMLProps<HTMLDivElement>
> {
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/buttons/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'

import styles from './ButtonGroup.css'

// @todo: refactor to functional component
export default class ButtonGroup extends React.PureComponent<React.HTMLProps<HTMLDivElement>> {
render() {
const {children, className, ...restProps} = this.props
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/buttons/DropDownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function parentButtonIsMenuButton(node, id) {
return false
}

// @todo: refactor to functional component
export default class DropDownButton extends React.PureComponent<
DropdownButtonProps & React.HTMLProps<HTMLButtonElement>,
DropdownButtonState
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/buttons/InInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface InInputButtonProps {
colored?: boolean
}

// @todo: refactor to functional component
export default class InInputButton extends React.Component<
InInputButtonProps & React.HTMLProps<HTMLButtonElement>
> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function createButtonLike(
) {
const Component = as as ButtonComponent

// @todo: refactor to functional component
return class ButtonLike extends React.Component<ButtonProps, ButtonState> {
static displayName =
displayName ||
Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/components/src/buttons/stories/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const actionsProps = {
onFocus: action('onFocus')
}

let buttonElement: any = null
let buttonElement: HTMLButtonElement | null = null

function testFocus() {
if (buttonElement) buttonElement.focus()
}

function setButtonElement(element: any) {
function setButtonElement(element: HTMLButtonElement | null) {
buttonElement = element
}

Expand Down Expand Up @@ -60,7 +60,7 @@ export function DefaultStory() {
<div style={{width: '100%', maxWidth: 300}}>
<div>
<h2>kind="default"</h2>
<Button {...buttonProps} ref={setButtonElement}>
<Button {...buttonProps} ref={setButtonElement as any}>
{children}
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function DefaultStory() {
{ref => (
<div
onClick={action('click inside')}
ref={ref as any}
ref={ref}
style={{background: '#fff', border: '1px solid #999', padding: '2em'}}
>
click inside/outside
Expand Down
1 change: 0 additions & 1 deletion packages/@sanity/components/src/containerQuery/story.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO
import {storiesOf} from 'part:@sanity/storybook'
import {withKnobs} from 'part:@sanity/storybook/addons/knobs'
import {QueriesStory} from './stories/queries'
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/dialogs/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface ConfirmDialogProps {
title?: string
}

// @todo: refactor to functional component
export default class ConfirmDialog extends React.PureComponent<ConfirmDialogProps> {
handleAction = (action: DialogAction) => {
if (action.key === 'confirm') {
Expand Down
15 changes: 9 additions & 6 deletions packages/@sanity/components/src/dialogs/DefaultDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ function DefaultDialog(props: DefaultDialogProps) {
classNameProp
)

const handleEscape = useCallback((event: KeyboardEvent) => {
// This code used to be `onEscape || onClose`
if (onEscape) onEscape(event)
else if (onClose) onClose()
}, [])
const handleEscape = useCallback(
(event: KeyboardEvent) => {
// This code used to be `onEscape || onClose`
if (onEscape) onEscape(event)
else if (onClose) onClose()
},
[onEscape, onClose]
)

const renderCloseButton = onClose && showCloseButton
const renderFloatingCloseButton = !title && renderCloseButton
Expand Down Expand Up @@ -87,8 +90,8 @@ function DefaultDialog(props: DefaultDialogProps) {
<ClickOutside onClickOutside={isActive ? handleClickOutside : undefined}>
{ref => (
<div className={styles.card} ref={ref}>
{/* eslint-disable-next-line react/jsx-no-bind */}
<Escapable
// eslint-disable-next-line react/jsx-no-bind
onEscape={event => (isActive || event.shiftKey) && handleEscape(event)}
/>
<div className={styles.inner}>
Expand Down
18 changes: 9 additions & 9 deletions packages/@sanity/components/src/dialogs/DialogContent.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import classNames from 'classnames'
import styles from 'part:@sanity/components/dialogs/content-style'
import React from 'react'
import React, {useEffect} from 'react'

interface DialogContentProps {
size?: 'small' | 'medium' | 'large' | 'auto'
padding?: 'none' | 'small' | 'medium' | 'large'
children?: React.ReactNode
}

export default class DialogContent extends React.PureComponent<DialogContentProps> {
componentDidMount() {
function DialogContent(props: DialogContentProps) {
const {size = 'auto', children, padding = 'medium'} = props

useEffect(() => {
// eslint-disable-next-line no-console
console.warn('DialogContent is deprecated. Use `<DefaultDialog padding size />` instead.')
}

render() {
const {size = 'auto', children, padding = 'medium'} = this.props
}, [])

return <div className={classNames(styles[size], styles[`padding_${padding}`])}>{children}</div>
}
return <div className={classNames(styles[size], styles[`padding_${padding}`])}>{children}</div>
}

export default DialogContent
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface FullScreenDialogProps {

const noop = () => undefined

// @todo: refactor to functional component
export default class FullScreenDialog extends React.PureComponent<FullScreenDialogProps> {
createButtonFromAction = (action: DialogAction, i: number) => {
const {onAction} = this.props
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/dialogs/PanePopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const DEFAULT_ICONS = {
error: <WarningIcon />
}

// @todo: refactor to functional component
export default class PanePopover extends React.PureComponent<PanePopoverProps> {
iconKind = () => {
const {icon, kind = 'info'} = this.props
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/components/src/dialogs/PopOver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface PopOverProps {
actions?: DialogAction[]
}

// @todo: Rename to `Popover`
// @todo: refactor to functional component
export default class PopOver extends React.PureComponent<PopOverProps> {
static defaultProps = {
title: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface EditItemFoldOutProps {
onClose?: () => void
}

// @todo: refactor to functional component
export default class EditItemFoldOut extends React.PureComponent<EditItemFoldOutProps> {
render() {
const {title = '', onClose, children} = this.props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface DefaultFileInputProps {
style?: React.CSSProperties
}

// @todo: refactor to functional component
export default class DefaultFileInput extends React.PureComponent<DefaultFileInputProps> {
_inputId = uniqueId('FileSelect')
componentDidMount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default class SnackbarProvider extends React.Component<SnackbarProviderPr
key={snack.id}
{...snack}
offset={this.offsets[index]}
onDismiss={id => this.handleDismissSnack(id)}
onDismiss={this.handleDismissSnack}
onSetHeight={this.handleSetHeight}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const globalDefaults: Omit<SnackbarItemProps, 'onSetHeight'> = {
onDismiss: action('onDismiss()')
}

// @todo: refactor to functional component
class SnackQueue extends React.PureComponent<SnackQueueProps> {
static contextTypes = {
addToSnackQueue: PropTypes.func
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/tabs/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface State {
isDOMFocused: boolean
}

// @todo: refactor to functional component
export default class Tab extends React.PureComponent<TabProps, State> {
element: HTMLButtonElement | null = null
focusTimeout?: NodeJS.Timer
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/tabs/TabList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface State {
focusedTabIdx: number
}

// @todo: refactor to functional component
export default class TabList extends React.PureComponent<TabListProps, State> {
state: State = {
focusedTabIdx: -1
Expand Down
3 changes: 3 additions & 0 deletions packages/@sanity/components/src/tags/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function removeAt(array: string[], index: number) {
return copy
}

// @todo: refactor to functional component
export default class TagsTextField extends React.Component<
TagsTextFieldProps & Omit<React.HTMLProps<HTMLInputElement>, 'onBlur' | 'onChange' | 'value'>,
State
Expand Down Expand Up @@ -94,6 +95,8 @@ export default class TagsTextField extends React.Component<

render() {
const {inputValue} = this.state

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {onChange, value = [], readOnly, markers, inputId, ...rest} = this.props

return (
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/tags/stories/tagsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface State {
tags: string[]
}

// @todo: refactor to functional component
class DefaultTextFieldTagsImplementation extends React.PureComponent<
DefaultTextFieldTagsImplementationProps,
State
Expand Down
3 changes: 3 additions & 0 deletions packages/@sanity/components/src/textareas/DefaultTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface DefaultTextAreaProps {
inputId?: string
}

// @todo: refactor to functional component
export default class DefaultTextArea extends React.Component<
DefaultTextAreaProps & Omit<React.HTMLProps<HTMLTextAreaElement>, 'id'>
> {
Expand Down Expand Up @@ -56,8 +57,10 @@ export default class DefaultTextArea extends React.Component<
const {
isClearable,
onClear,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
customValidity = '',
inputId,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hasFocus,
rows = 10,
...rest
Expand Down
11 changes: 6 additions & 5 deletions packages/@sanity/components/src/textfields/DefaultTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ interface DefaultTextFieldProps {
isClearable?: boolean
className?: string
description?: string
hasFocus?: boolean
inputId?: string
// hasFocus?: boolean
// inputId?: string
}

// @todo: refactor to functional component
export default class DefaultTextField extends React.Component<DefaultTextFieldProps> {
_inputId?: string

Expand All @@ -47,13 +48,13 @@ export default class DefaultTextField extends React.Component<DefaultTextFieldPr
className,
level = 1,
description,
hasFocus,
// hasFocus,
onChange,
onKeyPress,
onFocus,
onBlur,
value = '',
inputId
value = ''
// inputId
} = this.props

return (
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/components/src/textfields/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface SearchFieldFieldProps {
value?: string
}

// @todo: refactor to functional component
export default class SearchFieldField extends React.Component<SearchFieldFieldProps> {
_inputId = uniqueId('searchfield')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function DefaultStory() {
onFocus={action('onFocus')}
onClear={action('onClear')}
isClearable={boolean('isClearable', false, 'props')}
hasFocus={boolean('hasFocus', false, 'props')}
// hasFocus={boolean('hasFocus', false, 'props')}
/>
</Sanity>
</div>
Expand Down
6 changes: 6 additions & 0 deletions packages/@sanity/components/src/textinputs/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import defaultStyles from 'part:@sanity/components/textinputs/default-style'
import React from 'react'
import {DefaultTextInputProps} from './types'

// @todo: refactor to functional component
export default class DefaultTextInput extends React.PureComponent<DefaultTextInputProps> {
_input: HTMLInputElement | null = null

Expand Down Expand Up @@ -42,13 +43,18 @@ export default class DefaultTextInput extends React.PureComponent<DefaultTextInp
const {
className: classNameProp,
onClear,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hasError = false,
isClearable = false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
isSelected = false,
disabled = false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
markers,
styles: stylesProp,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
customValidity,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
focusPath,
inputId = '',
...restProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface State {
value: string
}

// @todo: refactor to functional component
class DefaultTextInputTest extends React.PureComponent<DefaultTextInputProps, State> {
constructor(props: DefaultTextInputProps) {
super(props)
Expand Down

0 comments on commit 9b859ae

Please sign in to comment.