Skip to content

Commit 8436097

Browse files
authored
Merge pull request #51 from metalabdesign/prettier
Set up Prettier
2 parents f4df5cb + 206f632 commit 8436097

16 files changed

Lines changed: 220 additions & 158 deletions

File tree

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ node_modules
22
coverage
33
dist
44
lib
5-
types
65
flow-typed

.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
extends:
22
- metalab
33
- metalab/react
4+
plugins:
5+
- prettier
46
rules:
57
complexity: 0
8+
jsx-quotes:
9+
- 2
10+
- prefer-double
11+
prettier/prettier: 2
12+
metalab/flowtype/space-after-type-colon: 0
613
overrides:
714
-
815
files: "*.test.js"

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
coverage
3+
dist
4+
lib
5+
flow-typed

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parser: flow
2+
semi: true
3+
singleQuote: true
4+
trailingComma: all
5+
bracketSpacing: false
6+
arrowParens: always

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
# FlowTip
22

3-
*A flexible, adaptable, and easy to use tooltip positioning library.*
3+
_A flexible, adaptable, and easy to use tooltip positioning library._
44

55
![build status](http://img.shields.io/travis/metalabdesign/flowtip/master.svg?style=flat)
66
![coverage](http://img.shields.io/coveralls/metalabdesign/flowtip/master.svg?style=flat)
7-
![license](http://img.shields.io/npm/l/flowtip.svg?style=flat)
8-
![version](http://img.shields.io/npm/v/flowtip.svg?style=flat)
9-
![downloads](http://img.shields.io/npm/dm/flowtip.svg?style=flat)
107

118
## Packages
129

1310
FlowTip is managed as a monorepo that is composed of several npm packages.
1411

15-
| Package | Version |
16-
|---------|---------|
17-
| [`flowtip-core`] | [![npm](https://img.shields.io/npm/v/flowtip-core.svg?maxAge=2592000)](https://www.npmjs.com/package/flowtip-core) |
18-
| [`flowtip-react-dom`] | [![npm](https://img.shields.io/npm/v/flowtip-react-dom.svg?maxAge=2592000)](https://www.npmjs.com/package/flowtip-react-dom) |
12+
| Package | Version |
13+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14+
| [`flowtip-core`] | [![npm](https://img.shields.io/npm/v/flowtip-core.svg?maxAge=2592000)](https://www.npmjs.com/package/flowtip-core) [![downloads](http://img.shields.io/npm/dm/flowtip-core.svg?style=flat)](https://www.npmjs.com/package/flowtip-core) |
15+
| [`flowtip-react-dom`] | [![npm](https://img.shields.io/npm/v/flowtip-react-dom.svg?maxAge=2592000)](https://www.npmjs.com/package/flowtip-react-dom) [![downloads](http://img.shields.io/npm/dm/flowtip-react-dom.svg?style=flat)](https://www.npmjs.com/package/flowtip-react-dom) |
1916

2017
#### [`flowtip-core`]
2118

@@ -29,5 +26,4 @@ A FlowTip Component for [React DOM] using [`flowtip-core`] internally.
2926

3027
[`flowtip-core`]: /packages/flowtip-core
3128
[`flowtip-react-dom`]: /packages/flowtip-react-dom
32-
33-
[React DOM]: https://facebook.github.io/react/docs/react-dom.html
29+
[react dom]: https://facebook.github.io/react/docs/react-dom.html

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"flow": "./node_modules/.bin/flow",
55
"lerna": "./node_modules/.bin/lerna",
66
"lint": "./node_modules/.bin/eslint .",
7+
"format": "./node_modules/.bin/prettier --write '**/*.js'",
78
"postinstall": "./node_modules/.bin/lerna bootstrap",
89
"test": "npm run lint --silent && npm run flow --silent && npm run spec --silent",
910
"spec": "./node_modules/.bin/jest --runInBand=${SPEC_SERIAL:-$CI} --coverage=${SPEC_COVERAGE:-$CI}",
@@ -20,10 +21,12 @@
2021
"babel-jest": "^22.4.1",
2122
"eslint": "^4.18.2",
2223
"eslint-config-metalab": "^8.0.0",
24+
"eslint-plugin-prettier": "^2.6.0",
2325
"flow-bin": "^0.67.1",
2426
"jest": "^22.4.2",
2527
"lerna": "^2.9.0",
2628
"ncp": "^2.0.0",
29+
"prettier": "^1.11.1",
2730
"regenerator-runtime": "^0.11.1",
2831
"renamer": "^0.6.1",
2932
"rimraf": "^2.6.2"

packages/flowtip-core/README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,45 @@ const {region, rect} = flowtip(config);
1919

2020
## Config
2121

22-
### `target`: object
23-
*required*
22+
### `target`: object
23+
24+
_required_
2425

2526
The measured position of the target element as a [DOMRect-shaped] object.
2627

27-
### `content`: object
28-
*required*
28+
### `content`: object
29+
30+
_required_
2931

3032
The measured width and height of the tooltip content. as a [dimensions] object.
3133

32-
### `bounds`: object
33-
*required*
34+
### `bounds`: object
35+
36+
_required_
3437

3538
The measured position of the available layout area for the tooltip content as a [DOMRect-shaped] object. This defines the outer collision boundaries referenced by the `constrain` option.
3639

3740
> This should be the browser viewport rect in most instances.
3841
3942
### `region`: string
4043

41-
*optional*
44+
_optional_
4245

4346
The preferred region in which the tooltip will appear at first relative to its target. Possibly values are: `top`, `bottom`, `left`, and `right`.
4447

4548
> If `region` is omitted, the algorithm will pick default to the region with the most available space. (handled by the `getIdealRegion` function)
4649
4750
### `offset`: number
4851

49-
*optional*, *default: `0`*
52+
_optional_, _default: `0`_
5053

5154
The desired distance between the positioned content and the target.
5255

5356
Since the layout algorithm does not factor the size of an indicator triangle element into the calculation, this value should be supplied as the combined length of the indicator plus the desired margin.
5457

5558
### `overlap`: number
5659

57-
*optional*, *default: `0`*
60+
_optional_, _default: `0`_
5861

5962
The minimum overlap along an edge for each region to be considered valid.
6063

@@ -64,13 +67,13 @@ If you are rendering an indicator triangle, this should be the minimum linear ov
6467
6568
### `align`: string | number
6669

67-
*optional*, *default: `center`*
70+
_optional_, _default: `center`_
6871

6972
Linear alignment between the positioned content and the target. Possible values are a number in the range of `0` to `1`, or one of `start`, `center`, and `end` (aliases for `0`, `0.5`, and `1` respectively).
7073

7174
### `disabled`: object
7275

73-
*optional*, *default: `{top: false, left: false, bottom: false, right: false}`*
76+
_optional_, _default: `{top: false, left: false, bottom: false, right: false}`_
7477

7578
Map of boolean values denoting particular regions as disabled.
7679

@@ -88,7 +91,7 @@ flowtip({
8891

8992
### `constrain`: object
9093

91-
*optional*, *default: `{top: true, left: true, bottom: true, right: true}`*
94+
_optional_, _default: `{top: true, left: true, bottom: true, right: true}`_
9295

9396
Map of boolean values denoting particular boundary edges should constrain the positioned tooltip.
9497

@@ -100,5 +103,5 @@ While `flowtip-core` has no dependency on the DOM, it is designed to be directly
100103

101104
The absolute reference frame of the measurements does not have an impact on the calculation - as long as all measurements are relative to the same frame everything will work out.
102105

103-
[DOMRect-shaped]: #rect-interface
106+
[domrect-shaped]: #rect-interface
104107
[dimensions]: #rect-interface

packages/flowtip-core/__test__/rect.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ describe('Rect', () => {
2525
});
2626

2727
it('should true with two equivalent rects', () => {
28-
expect(Rect.areEqual(new Rect(1, 2, 3, 4), new Rect(1, 2, 3, 4)))
29-
.toBe(true);
28+
expect(Rect.areEqual(new Rect(1, 2, 3, 4), new Rect(1, 2, 3, 4))).toBe(
29+
true,
30+
);
3031
});
3132

3233
it('should true with two different rects', () => {
33-
expect(Rect.areEqual(new Rect(1, 2, 3, 4), new Rect(4, 3, 2, 1)))
34-
.toBe(false);
34+
expect(Rect.areEqual(new Rect(1, 2, 3, 4), new Rect(4, 3, 2, 1))).toBe(
35+
false,
36+
);
3537
});
3638
});
3739
});

packages/flowtip-core/__test__/util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,14 @@ export const drawResult = (config, result) => {
113113
drawScaled(canvas, _rect.left, _rect.top + overlapCenter, tail.left);
114114
}
115115

116+
const printed = printCanvas(canvas)
117+
.split('\n')
118+
.join(`\n${region[0]} `);
119+
116120
return `
117121
${reason}
118122
${region}
119123
120-
${region[0]} ${printCanvas(canvas).split('\n').join(`\n${region[0]} `)}
124+
${region[0]} ${printed}
121125
`;
122126
};

0 commit comments

Comments
 (0)