-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
REMOVE tslint, and use eslint for everything #6621
Changes from 2 commits
0296ef7
f939e14
d0d5ab3
022429a
22bc243
8f2bcf1
b708eaf
bfb5546
61d9551
44b5ace
4280795
a739c75
62f13a4
4e7da65
1546f88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { document } from 'global'; | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { styled, themes, convert } from '@storybook/theming'; | ||
|
@@ -10,6 +11,7 @@ import { IFRAME } from '../../constants'; | |
|
||
export class HighlightedElementData { | ||
originalOutline: string; | ||
|
||
isHighlighted: boolean; | ||
} | ||
|
||
|
@@ -50,6 +52,7 @@ function getElementBySelectorPath(elementPath: string): HTMLElement { | |
} | ||
|
||
function setElementOutlineStyle(targetElement: HTMLElement, outlineStyle: string): void { | ||
// eslint-disable-next-line no-param-reassign | ||
targetElement.style.outline = outlineStyle; | ||
} | ||
|
||
|
@@ -65,6 +68,7 @@ function areAllRequiredElementsHighlighted( | |
); | ||
}).length; | ||
|
||
// eslint-disable-next-line no-nested-ternary | ||
return highlightedCount === 0 | ||
? CheckBoxStates.UNCHECKED | ||
: highlightedCount === elementsToHighlight.length | ||
|
@@ -99,34 +103,55 @@ class HighlightToggle extends Component<ToggleProps> { | |
private checkBoxRef = React.createRef<HTMLInputElement>(); | ||
|
||
componentDidMount() { | ||
this.props.elementsToHighlight.forEach(element => { | ||
const { elementsToHighlight, highlightedElementsMap } = this.props; | ||
elementsToHighlight.forEach(element => { | ||
const targetElement = getElementBySelectorPath(element.target[0]); | ||
if (targetElement && !this.props.highlightedElementsMap.has(targetElement)) { | ||
if (targetElement && !highlightedElementsMap.has(targetElement)) { | ||
this.saveElementDataToMap(targetElement, false, targetElement.style.outline); | ||
} | ||
}); | ||
} | ||
|
||
componentDidUpdate(prevProps: Readonly<ToggleProps>): void { | ||
const { indeterminate } = this.props; | ||
if (this.checkBoxRef.current) { | ||
this.checkBoxRef.current.indeterminate = this.props.indeterminate; | ||
this.checkBoxRef.current.indeterminate = indeterminate; | ||
} | ||
} | ||
|
||
onToggle = (): void => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are these changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linting fixes, typescript files were missing a ton of useful eslint rules! Now all eslint rules apply to typescript code as well 🎉 |
||
const { elementsToHighlight, highlightedElementsMap } = this.props; | ||
elementsToHighlight.forEach(element => { | ||
const targetElement = getElementBySelectorPath(element.target[0]); | ||
if (!highlightedElementsMap.has(targetElement)) { | ||
return; | ||
} | ||
const { originalOutline } = highlightedElementsMap.get(targetElement); | ||
const { isHighlighted } = highlightedElementsMap.get(targetElement); | ||
const { isToggledOn } = this.props; | ||
if ((isToggledOn && isHighlighted) || (!isToggledOn && !isHighlighted)) { | ||
const addHighlight = !isToggledOn && !isHighlighted; | ||
this.highlightRuleLocation(targetElement, addHighlight); | ||
this.saveElementDataToMap(targetElement, addHighlight, originalOutline); | ||
} | ||
}); | ||
}; | ||
|
||
highlightRuleLocation(targetElement: HTMLElement, addHighlight: boolean): void { | ||
const { highlightedElementsMap, type } = this.props; | ||
if (!targetElement) { | ||
return; | ||
} | ||
|
||
if (addHighlight) { | ||
setElementOutlineStyle(targetElement, `${colorsByType[this.props.type]} dotted 1px`); | ||
setElementOutlineStyle(targetElement, `${colorsByType[type]} dotted 1px`); | ||
return; | ||
} | ||
|
||
if (this.props.highlightedElementsMap.has(targetElement)) { | ||
if (highlightedElementsMap.has(targetElement)) { | ||
setElementOutlineStyle( | ||
targetElement, | ||
this.props.highlightedElementsMap.get(targetElement).originalOutline | ||
highlightedElementsMap.get(targetElement).originalOutline | ||
); | ||
} | ||
} | ||
|
@@ -136,40 +161,25 @@ class HighlightToggle extends Component<ToggleProps> { | |
isHighlighted: boolean, | ||
originalOutline: string | ||
): void { | ||
const { addElement: localAddElement } = this.props; | ||
const data: HighlightedElementData = new HighlightedElementData(); | ||
data.isHighlighted = isHighlighted; | ||
data.originalOutline = originalOutline; | ||
const payload = { element: targetElement, highlightedElementData: data }; | ||
this.props.addElement(payload); | ||
localAddElement(payload); | ||
} | ||
|
||
onToggle = (): void => { | ||
this.props.elementsToHighlight.forEach(element => { | ||
const targetElement = getElementBySelectorPath(element.target[0]); | ||
if (!this.props.highlightedElementsMap.has(targetElement)) { | ||
return; | ||
} | ||
const originalOutline = this.props.highlightedElementsMap.get(targetElement).originalOutline; | ||
const { isHighlighted } = this.props.highlightedElementsMap.get(targetElement); | ||
const { isToggledOn } = this.props; | ||
if ((isToggledOn && isHighlighted) || (!isToggledOn && !isHighlighted)) { | ||
const addHighlight = !isToggledOn && !isHighlighted; | ||
this.highlightRuleLocation(targetElement, addHighlight); | ||
this.saveElementDataToMap(targetElement, addHighlight, originalOutline); | ||
} | ||
}); | ||
}; | ||
|
||
render() { | ||
const { toggleId, elementsToHighlight, isToggledOn } = this.props; | ||
return ( | ||
<Checkbox | ||
ref={this.checkBoxRef} | ||
id={this.props.toggleId} | ||
id={toggleId} | ||
type="checkbox" | ||
aria-label="Highlight result" | ||
disabled={!this.props.elementsToHighlight.length} | ||
disabled={!elementsToHighlight.length} | ||
onChange={this.onToggle} | ||
checked={this.props.isToggledOn} | ||
checked={isToggledOn} | ||
/> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?