Skip to content

Commit f4df5cb

Browse files
authored
Merge pull request #50 from metalabdesign/flow-lint
Activate flow lint for stricter type annotations
2 parents 5f6051e + 56d5728 commit f4df5cb

3 files changed

Lines changed: 37 additions & 18 deletions

File tree

.flowconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
[include]
55

6+
[lints]
7+
all=error
8+
69
[libs]
710
<PROJECT_ROOT>/flow-typed
811

packages/flowtip-core/src/flowtip.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function constrainTop(config: _Config, region: Region, rect: Rect): number {
190190
* @param {string} region A region (`top`, `right`, `bottom`, or `left`).
191191
* @returns {bool} True if the content will be constrained.
192192
*/
193-
function getRegionClip(config: _Config, region: Region): Regions {
193+
function getRegionClip(config: _Config, region: Region): _Regions {
194194
const {bounds} = config;
195195
const rect = getRect(config, region);
196196

@@ -794,16 +794,27 @@ function normalizeAlign(align: ?Align): number {
794794
return 0.5;
795795
}
796796

797-
const defaults = (rawConfig: Config): _Config => (({
798-
offset: 0,
799-
overlap: 0,
800-
...rawConfig,
801-
align: normalizeAlign(rawConfig.align),
802-
bounds: Rect.from(rawConfig.bounds),
803-
target: Rect.from(rawConfig.target),
804-
disabled: {...noRegions, ...rawConfig.disabled},
805-
constrain: {...allRegions, ...rawConfig.constrain},
806-
}: any): _Config);
797+
const defaults = ({
798+
offset = 0,
799+
overlap = 0,
800+
align,
801+
region,
802+
bounds,
803+
target,
804+
content,
805+
disabled,
806+
constrain,
807+
}: Config = {}): _Config => ({
808+
offset,
809+
overlap,
810+
align: normalizeAlign(align),
811+
region,
812+
bounds: Rect.from(bounds),
813+
target: Rect.from(target),
814+
content,
815+
disabled: {...noRegions, ...disabled},
816+
constrain: {...allRegions, ...constrain},
817+
});
807818

808819
/**
809820
* Calculate a Flowtip layout result.

packages/flowtip-react-dom/src/FlowTip.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export type State = {
3737
result: Result | null,
3838
};
3939

40+
type Style = {[string]: string | number};
41+
4042
export type Props = {
4143
/** DOMRect (or similar shaped object) of target position. */
4244
target: RectLike | null,
@@ -76,12 +78,12 @@ export type Props = {
7678
/** Constrain the content at the bottom boundary. */
7779
constrainLeft: boolean,
7880
content: React.ComponentType<{
79-
style: Object,
81+
style: Style,
8082
result: Result,
8183
children?: React.Node,
8284
}> | string,
8385
tail?: React.ComponentType<{
84-
style: Object,
86+
style: Style,
8587
result: Result,
8688
children?: React.Node,
8789
}>,
@@ -314,7 +316,10 @@ class FlowTip extends React.Component<Props, State> {
314316

315317
let result = null;
316318

317-
if (bounds && target && content && (!nextProps.Tail || tail)) {
319+
if (
320+
bounds && target && content &&
321+
(typeof nextProps.Tail !== 'function' || tail)
322+
) {
318323
const config = {
319324
offset: this._getOffset(nextProps),
320325
overlap: this._getOverlap(nextProps),
@@ -504,12 +509,12 @@ class FlowTip extends React.Component<Props, State> {
504509
* @param {Object} result - A `flowtip` layout result.
505510
* @returns {Object} Content position style.
506511
*/
507-
_getContentStyle(result: Result): Object {
512+
_getContentStyle(result: Result): Style {
508513
const {containingBlock} = this.state;
509514

510515
// Hide the result with css clip - preserving its ability to be measured -
511516
// when working with a static layout result mock.
512-
if (!result || result._static) {
517+
if (!result || result._static === true) {
513518
return {
514519
position: 'absolute',
515520
clip: 'rect(0 0 0 0)',
@@ -530,7 +535,7 @@ class FlowTip extends React.Component<Props, State> {
530535
* @param {Object} result - A `flowtip` layout result.
531536
* @returns {Object} Tail position style.
532537
*/
533-
_getTailStyle(result: Result): Object {
538+
_getTailStyle(result: Result): Style {
534539
const {tailOffset} = this.props;
535540
const {tail} = this.state;
536541

@@ -540,7 +545,7 @@ class FlowTip extends React.Component<Props, State> {
540545

541546
const tailAttached = result.offset >= this._getOffset(this.props);
542547

543-
const style: Object = {
548+
const style: Style = {
544549
position: 'absolute',
545550
visibility: tailAttached ? 'visible' : 'hidden',
546551
};

0 commit comments

Comments
 (0)