Skip to content

Commit 508636a

Browse files
authored
Run Prettier in pre-commit hook (#130)
Plus reformated the codebase
1 parent 283d8db commit 508636a

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"lint-staged": {
9595
"src/*.{js,jsx}": [
9696
"eslint src --fix",
97+
"prettier --write",
9798
"git add"
9899
]
99100
},

src/Textarea.jsx

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,52 +86,74 @@ class Autocomplete extends React.Component<AutocompleteProps> {
8686
}
8787

8888
componentDidUpdate() {
89-
const top = this.props.top || 0
90-
const left = this.props.left || 0
91-
const usedClasses = []
92-
const unusedClasses = []
89+
const top = this.props.top || 0;
90+
const left = this.props.left || 0;
91+
const usedClasses = [];
92+
const unusedClasses = [];
9393

94-
let topPosition = 0
95-
let leftPosition = 0
94+
let topPosition = 0;
95+
let leftPosition = 0;
9696

97-
const containerBounds = this.containerElem.getBoundingClientRect()
98-
const dropdownBounds = this.ref.getBoundingClientRect()
99-
const textareaBounds = this.props.textareaRef.getBoundingClientRect()
97+
const containerBounds = this.containerElem.getBoundingClientRect();
98+
const dropdownBounds = this.ref.getBoundingClientRect();
99+
const textareaBounds = this.props.textareaRef.getBoundingClientRect();
100100
const computedStyle = window.getComputedStyle(this.ref);
101101

102-
const marginTop = parseInt(computedStyle.getPropertyValue('margin-top'), 10)
103-
const marginBottom = parseInt(computedStyle.getPropertyValue('margin-bottom'), 10)
104-
const marginLeft = parseInt(computedStyle.getPropertyValue('margin-left'), 10)
105-
const marginRight = parseInt(computedStyle.getPropertyValue('margin-right'), 10)
102+
const marginTop = parseInt(
103+
computedStyle.getPropertyValue("margin-top"),
104+
10
105+
);
106+
const marginBottom = parseInt(
107+
computedStyle.getPropertyValue("margin-bottom"),
108+
10
109+
);
110+
const marginLeft = parseInt(
111+
computedStyle.getPropertyValue("margin-left"),
112+
10
113+
);
114+
const marginRight = parseInt(
115+
computedStyle.getPropertyValue("margin-right"),
116+
10
117+
);
106118

107-
const dropdownBottom = marginTop + marginBottom + textareaBounds.top + top + dropdownBounds.height
108-
const dropdownRight = marginLeft + marginRight + textareaBounds.left + left + dropdownBounds.width
119+
const dropdownBottom =
120+
marginTop +
121+
marginBottom +
122+
textareaBounds.top +
123+
top +
124+
dropdownBounds.height;
125+
const dropdownRight =
126+
marginLeft +
127+
marginRight +
128+
textareaBounds.left +
129+
left +
130+
dropdownBounds.width;
109131

110132
if (dropdownRight > containerBounds.right) {
111-
leftPosition = left - dropdownBounds.width
112-
usedClasses.push(POSITION_CONFIGURATION.X.LEFT)
113-
unusedClasses.push(POSITION_CONFIGURATION.X.RIGHT)
133+
leftPosition = left - dropdownBounds.width;
134+
usedClasses.push(POSITION_CONFIGURATION.X.LEFT);
135+
unusedClasses.push(POSITION_CONFIGURATION.X.RIGHT);
114136
} else {
115-
leftPosition = left
116-
usedClasses.push(POSITION_CONFIGURATION.X.RIGHT)
117-
unusedClasses.push(POSITION_CONFIGURATION.X.LEFT)
137+
leftPosition = left;
138+
usedClasses.push(POSITION_CONFIGURATION.X.RIGHT);
139+
unusedClasses.push(POSITION_CONFIGURATION.X.LEFT);
118140
}
119141

120142
if (dropdownBottom > containerBounds.bottom) {
121-
topPosition = top - dropdownBounds.height
122-
usedClasses.push(POSITION_CONFIGURATION.Y.TOP)
123-
unusedClasses.push(POSITION_CONFIGURATION.Y.BOTTOM)
143+
topPosition = top - dropdownBounds.height;
144+
usedClasses.push(POSITION_CONFIGURATION.Y.TOP);
145+
unusedClasses.push(POSITION_CONFIGURATION.Y.BOTTOM);
124146
} else {
125-
topPosition = top
126-
usedClasses.push(POSITION_CONFIGURATION.Y.BOTTOM)
127-
unusedClasses.push(POSITION_CONFIGURATION.Y.TOP)
147+
topPosition = top;
148+
usedClasses.push(POSITION_CONFIGURATION.Y.BOTTOM);
149+
unusedClasses.push(POSITION_CONFIGURATION.Y.TOP);
128150
}
129151

130-
this.ref.style.top = `${topPosition}px`
131-
this.ref.style.left = `${leftPosition}px`
152+
this.ref.style.top = `${topPosition}px`;
153+
this.ref.style.left = `${leftPosition}px`;
132154

133-
this.ref.classList.remove(...unusedClasses)
134-
this.ref.classList.add(...usedClasses)
155+
this.ref.classList.remove(...unusedClasses);
156+
this.ref.classList.add(...usedClasses);
135157
}
136158

137159
render() {

0 commit comments

Comments
 (0)