Skip to content

Commit 5ca77bb

Browse files
committed
Add props to override/set gallery/component styles
1 parent 1b4d1d8 commit 5ca77bb

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ Prop | Description
5050
`marginBottom` | Set marginBottom (in pixels) separate from marginRight
5151
`targetWidth` | Desired width for each component. Used when calculating the gallery layout.
5252
`widthHeightRatio` | Defaults to 1 but useful if components don't fit well in a square.
53+
`galleryStyle` | Override/set inline styles for the gallery div.
54+
`componentStyle` | Override/set inline styles for each component div.

examples/index.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@
1414
width: 100%;
1515
}
1616
code {
17+
background: #EDEDED;
18+
border: none;
19+
display: inline-block;
1720
font-family: "Inconsolata" monospace sans-serif;
21+
overflow: initial;
22+
padding: 16px;
23+
white-space: inherit;
24+
width: 100%;
25+
word-wrap: inherit;
1826
}
1927
body {
2028
font-family: "Lato" sans-serif;
2129
line-height: 1.4;
2230
color: #4A4A4A;
2331
}
24-
h1,h2 {
32+
h1,h2,h3 {
2533
color: #1f1f1f;
2634
}
2735
</style>

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"isarray": "0.0.1",
11+
"object-assign": "^2.0.0",
1112
"react-component-width-mixin": "^1.1.7"
1213
},
1314
"devDependencies": {

src/index.cjsx

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
React = require 'react'
22
PropTypes = React.PropTypes
33
componentWidthMixin = require 'react-component-width-mixin'
4+
assign = require 'object-assign'
45

56
calculateLayout = require './calculate_layout'
67

@@ -16,13 +17,17 @@ module.exports = React.createClass
1617
marginBottom: PropTypes.number
1718
targetWidth: PropTypes.number
1819
widthHeightRatio: PropTypes.number
20+
galleryStyle: PropTypes.object
21+
componentStyle: PropTypes.object
1922

2023
getDefaultProps: ->
2124
margin: 10
2225
noMarginBottomOnLastRow: false
2326
targetWidth: 200
2427
widthHeightRatio: 1
2528
disableServerRender: false
29+
galleryStyle: {}
30+
componentStyle: {}
2631

2732
render: ->
2833
# If we don't know the component width, there's nothing we can do.
@@ -34,7 +39,14 @@ module.exports = React.createClass
3439
else
3540
[componentWidth, componentsPerRow] = calculateLayout(@props, @state)
3641
return (
37-
<div className="component-gallery #{@props.className}" style={{overflow: "hidden"}}>
42+
<div
43+
className="component-gallery #{@props.className}"
44+
style={assign(
45+
{},
46+
{overflow: "hidden"},
47+
@props.galleryStyle
48+
)}
49+
>
3850
{React.Children.map(@props.children, (child, i) =>
3951
marginBottom = @props.margin
4052

@@ -59,16 +71,20 @@ module.exports = React.createClass
5971
return (
6072
React.DOM.div({
6173
className: "component-wrapper"
62-
style: {
63-
width: "#{componentWidth}px"
64-
height: "#{componentWidth*@props.widthHeightRatio}px"
65-
display: "inline-block"
66-
marginRight: "#{marginRight}px"
67-
marginBottom: "#{marginBottom}px"
68-
overflow: "hidden"
69-
position: "relative"
70-
"verticalAlign": "top"
71-
}
74+
style: assign(
75+
{},
76+
{
77+
width: "#{componentWidth}px"
78+
height: "#{componentWidth*@props.widthHeightRatio}px"
79+
display: "inline-block"
80+
marginRight: "#{marginRight}px"
81+
marginBottom: "#{marginBottom}px"
82+
overflow: "hidden"
83+
position: "relative"
84+
verticalAlign: "top"
85+
},
86+
@props.componentStyle
87+
)
7288
}, child)
7389
)
7490
)}

0 commit comments

Comments
 (0)