Skip to content

Commit 29f2587

Browse files
author
Billy He
committed
Merge pull request #8 from qiushihe/react
Implement as React package
2 parents 5a6817e + c63bafd commit 29f2587

32 files changed

Lines changed: 1404 additions & 107 deletions

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015", "react", "stage-0"]
3+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/*

.eslintrc

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"node": true
5+
},
6+
7+
"parser": "babel-eslint",
8+
9+
"plugins": [
10+
"react"
11+
],
12+
13+
"ecmaFeatures": {
14+
"jsx": true
15+
},
16+
17+
"rules": {
18+
// For a complete reference, check out http://eslint.org/docs/rules/
19+
20+
//-------------------------------------------------------------------------
21+
// Best practices
22+
//-------------------------------------------------------------------------
23+
24+
// Prevent abbreviated blocks for clarity
25+
"curly": 2,
26+
27+
// Enforce a reasonable cap on functions spiralling out of control
28+
// with many branches.
29+
"complexity": [2, 10],
30+
31+
// Prefer foo.x over foo['x']; static properties are always preferable
32+
// to dynamic strings.
33+
"dot-notation": 2,
34+
35+
"dot-location": [2, "property"],
36+
37+
// enforce === and !== for comparisons
38+
"eqeqeq": [2, "smart"],
39+
40+
"guard-for-in": 2,
41+
42+
"no-floating-decimal": 2,
43+
44+
// Avoid funny things with parseInt.
45+
// See: http://stackoverflow.com/questions/850341
46+
"radix": 2,
47+
48+
// Avoid pitfalls when trying to call a just-declared function.
49+
"wrap-iife": 2,
50+
51+
// May the force be with you.
52+
"yoda": [0, "always"],
53+
54+
//-------------------------------------------------------------------------
55+
// Strict Mode
56+
//-------------------------------------------------------------------------
57+
58+
// Transpilers deal with the effects of strict, so ignore it.
59+
"strict": [2, "never"],
60+
61+
//-------------------------------------------------------------------------
62+
// Variable declaration
63+
//-------------------------------------------------------------------------
64+
"no-use-before-define": 2,
65+
66+
"no-undefined": 2,
67+
68+
"no-unused-vars": 2,
69+
70+
//-------------------------------------------------------------------------
71+
// Code style
72+
//-------------------------------------------------------------------------
73+
74+
// The one true brace style.
75+
"brace-style": [2, "1tbs"],
76+
77+
"camelcase": 0,
78+
79+
"comma-spacing": [2, { "before": false, "after": true }],
80+
81+
"consistent-this": [2, "_this"],
82+
83+
"eol-last": 2,
84+
85+
"indent": [2, 2],
86+
87+
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
88+
89+
"new-cap": 2,
90+
91+
"no-lonely-if": 2,
92+
93+
"no-mixed-spaces-and-tabs": [2, true],
94+
95+
"no-multiple-empty-lines": 2,
96+
97+
// Nested ternaries are just plain confusing. Avoiding them keeps the
98+
// code readable.
99+
"no-nested-ternary": 2,
100+
101+
// There are no such thing as "private" properties. Use closure
102+
// variables if you really need isolation.
103+
"no-underscore-dangle": 0,
104+
105+
"no-spaced-func": 2,
106+
107+
// use one variable declaration for each variable you want to define
108+
"one-var": [2, "never"],
109+
110+
// enforce double quotes
111+
"quotes": [2, "double"],
112+
113+
// Enforce whitespace for visual clarity.
114+
"space-after-keywords": [2, "always"],
115+
"spaced-comment": [2, "always", { "exceptions": ["-"] }],
116+
117+
//-------------------------------------------------------------------------
118+
// ECMAScript 6
119+
//-------------------------------------------------------------------------
120+
121+
// Enforce `const` and `let` to describe what's going on.
122+
"no-var": 2,
123+
124+
//-------------------------------------------------------------------------
125+
// React
126+
//-------------------------------------------------------------------------
127+
"jsx-quotes": [2, "prefer-double"],
128+
"react/jsx-uses-vars": 2,
129+
"react/jsx-uses-react": 2,
130+
131+
// Display name is not needed when using ES6-style components
132+
"react/display-name": 0,
133+
134+
// Make things consistent and readable – prefer `x={true}` over `x`
135+
"react/jsx-boolean-value": 2,
136+
137+
// Keep the quote style consistent with Javascript land
138+
"react/jsx-no-undef": 2,
139+
"react/jsx-sort-props": 0,
140+
"react/jsx-sort-prop-types": 0,
141+
"react/no-did-mount-set-state": 1,
142+
"react/no-did-update-set-state": 1,
143+
"react/no-multi-comp": 2,
144+
"react/no-unknown-property": 2,
145+
"react/react-in-jsx-scope": 1,
146+
"react/self-closing-comp": 2,
147+
"react/wrap-multilines": 2,
148+
149+
// Potential issue in React ESLint package- receiving 'Can't add property
150+
// react, object is not extensible' when used with eslint-loader.
151+
"react/prop-types": 0
152+
}
153+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
build/*

README.md

Lines changed: 26 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# FlowTip
22

3-
*A flexible, adaptable and easy to use tooltip positioning library.*
3+
*A flexible, adaptable and easy to use tooltip component for React.js*
44

5-
* [Website](http://qiushihe.github.io/flowtip)
6-
* [Interactive Demo](http://qiushihe.github.io/flowtip/demo.html)
7-
* [Github Repo](https://github.com/qiushihe/flowtip)
5+
Looking for the non-React.js version? It's in the [v1](v1) folder.
86

97
## Dependencies
108

11-
* [jQuery](http://jquery.com)
12-
* [Unerscore.js](http://underscorejs.org)
13-
* [CoffeeScript](http://coffeescript.org) (development only)
9+
* React
10+
* ReactDOM
1411

1512
## Glossaries
1613

@@ -38,40 +35,35 @@ then in term aligned to the pivot.
3835

3936
## Basic Usage
4037

41-
Creates an instance of the **FlowTip** object:
38+
To include an instance of FlowTip in your component:
4239

43-
var tooltip = new FlowTip();
40+
```
41+
<FlowTip target={targetProperties} parent={parentProperties} {...flowtipProperties}>
42+
<b>Holy Shit!</b>
43+
<br />
44+
FlowTip as React Component
45+
</FlowTip>
46+
```
4447

45-
An instance of the **FlowTip** can be created with options (see **Attributes** section below):
48+
The `target` and `parent` properties specifies the position and dimension of the tooltip's
49+
target and parent, and for `parent` scroll positions should be included as well:
4650

47-
var myFlowTip = new FlowTip({
48-
region: "bottom"
49-
className: "my-tip"
50-
hasTail: false
51-
})
51+
```
52+
targetProperties = {
53+
top: ##, left: ##, width: ##, height: ##
54+
};
5255
53-
At this point, the tooltip is not yet "attached" to a target. The tooltip's target can be set by
54-
calling `setTarget`:
56+
parentProperties = {
57+
top: ##, left: ##, width: ##, height: ##,
58+
scrollTop: ##, scrollLeft: ##
59+
};
60+
```
5561

56-
tooltip.setTarget(tooltipTarget);
62+
... where all `##` above should be integer values (i.e. not `##px`).
5763

58-
... where `tooltipTarget` may be a DOM object or a jQuery selection.
64+
For possible values of `flowtipProperties` see [FlowTip Properties](#flowtip-properties) below.
5965

60-
To make the tooltip visible, call `show`:
61-
62-
tooltip.show();
63-
64-
This will render the tooltip is it's not already rendered, and position the tooltip in the
65-
appropriate region (see `region` in **Attributes** section below) with proper alignments
66-
(see **Alignments** section below).
67-
68-
It's important to note that instances of **FlowTip** does **not** automatically re-position
69-
themselves when their targets move. The responsibility of detecting target movement lies outside
70-
the scope of this library. To update the tooltip's position against its target:
71-
72-
tooltip.reposition();
73-
74-
## Attributes
66+
## FlowTip Properties
7567

7668
### `className`: **String**
7769

@@ -91,24 +83,6 @@ _Default value: ""_
9183

9284
Additional class name(s) for the tooltip's tail.
9385

94-
### `appendTo`: **Element**
95-
96-
_Default value: null_
97-
98-
The element within which the tooltip will be inserted into. Can be set or updated by calling
99-
`setAppendTo`. Default value is the document's `body` and the tooltip would thus be free to appear
100-
and move anywhere on the page and edge detection will only be performed on the edge of the page.
101-
102-
If `appendTo` is set to an element then edge detection will be performed on the edge of
103-
the element instead.
104-
105-
### `tooltipContent`: **String** or **Element**
106-
107-
_Default value: null_
108-
109-
The content of the tooltip. May be specified as (HTML) string or DOM element. Can be set original
110-
updated by calling `setTooltipContent`.
111-
11286
### `region`: **String**
11387

11488
_Default value: top_
@@ -273,56 +247,6 @@ pivot. When this value is positive, the clockwise edge will be used, and the cou
273247
edge will be used when this value is negative. The absolute value of this value controls the
274248
amount of shifting.
275249

276-
## Public Methods
277-
278-
### `constructor`
279-
280-
Accepts a hash of options. See **Attributes**.
281-
282-
### `render`
283-
284-
Render the tooltip's root (if not already rendered), content and insert the tooltip into the DOM.
285-
If called repeatedly, only re-render the tooltip's content.
286-
287-
### `setAppendTo`
288-
289-
Set the tooltip's containing element. If the tooltip has already been rendered, the tooltip will
290-
be moved/inserted into the new containing element.
291-
292-
### `setTarget`
293-
294-
Set the tooltip's target. The target is the element to which the tooltip will be pointing at.
295-
296-
### `setClientRectTarget`
297-
298-
Set the tooltip's target to be a ClientRect instead of a html element. The target is the
299-
ClientRect to which the tooltip will be pointing at.
300-
301-
### `setTooltipContent`
302-
303-
Set the tooltip's content. If `render` is set to `true` for `options`, the `render()` method will
304-
be called to re-render the content.
305-
306-
### `reposition`
307-
308-
Perform edge detection and position calculations to update the tooltip's position.
309-
310-
### `show`
311-
312-
Show the tooltip. Also update the tooltip's `visible` attribute.
313-
314-
### `hide`
315-
316-
Hide the tooltip. Also update the tooltip's `visible` attribute.
317-
318-
### `trigger`
319-
320-
Trigger an event from the root of the tooltip.
321-
322-
### `destroy`
323-
324-
Remove the tooltip's root from DOM.
325-
326250
## Edge Detection
327251

328252
There are three strategies for detection: **flip**, **rotate** and **squeeze**.
@@ -362,8 +286,3 @@ Target alignment refers to the alignment of the pivot relative to the target of
362286

363287
Root alignment refers to the alignment of the tooltip's root relative to the pivot. See
364288
`rootAlign` and `rootAlignOffset`.
365-
366-
## Coordinator
367-
368-
_TODO: Add documentation for `FlowTip.Coordinator`_
369-

demo/.DS_Store

6 KB
Binary file not shown.

demo/index.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
body {
2+
position: relative;
3+
margin: 0px;
4+
padding: 0px;
5+
}
6+
7+
.flowtipDemoArea {
8+
background-color: gainsboro;
9+
}
10+
11+
.flowtipDemoTarget {
12+
background-color: black;
13+
}
14+
15+
.flowtip-tail {
16+
background-color: red;
17+
}
18+
19+
.flowtip-root {
20+
background-color: gray;
21+
}

demo/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>FlowTip.React Demo</title>
5+
<link rel="stylesheet" href="/index.css" />
6+
</head>
7+
<body>
8+
<div id="demo"></div>
9+
</body>
10+
<script src="/demo.js"></script>
11+
</body>
12+
</html>
13+

0 commit comments

Comments
 (0)