You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-3Lines changed: 29 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,36 @@
1
1
# react-automatic-width
2
2
3
-
Reacts on window.onResize and sets its current width as property on its children. Use this to keep components such as [fixed-data-table](https://facebook.github.io/fixed-data-table/) or [react-d3-components](https://github.com/codesuki/react-d3-components)responsive.
3
+
So you found those cool components that do what you want, but they work on fixed with ([fixed-data-table](https://facebook.github.io/fixed-data-table/) or [react-d3-components](https://github.com/codesuki/react-d3-components)for instance).
4
4
5
-
# Usage
5
+
~~~ jsx
6
+
import D3 from 'react-d3-components';
6
7
7
-
**TODO**
8
+
<D3.BarChart
9
+
width={500} /> // :(
10
+
~~~
11
+
12
+
You care about responsiveness and different display sizes! You want variable width! HULK SMASH!
13
+
14
+
Solution: Just wrap it in `AutoWidth`.
15
+
16
+
~~~ jsx
17
+
import D3 from 'react-d3-components';
18
+
import AutoWidth from 'react-automatic-width';
19
+
20
+
<AutoWidth>
21
+
<D3.BarChart /> {/* ^_^ */}
22
+
</AutoWidth>
23
+
~~~
24
+
25
+
# How?
26
+
27
+
It attaches a listener to `resize` event of `window`. In it, the component reads the current width of its DOM node and sets this as `width` property on its children.
28
+
29
+
# Issues
30
+
31
+
* Uses `addEventListener`, so no IE8 currently. PRs welcome.
32
+
* Uses `clientWidth` because that worked on my current Chrome. Might be funky in your browser. PRs welcome.
33
+
* Not clear what should happen if window is resized while container is invisible. Currently zero-widths just get ignored.
0 commit comments