Skip to content

Commit

Permalink
theme aphrodite styles rather than default vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jossmac committed Aug 21, 2016
1 parent 1c9594c commit 76bafbb
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 120 deletions.
67 changes: 56 additions & 11 deletions examples/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,61 @@ const THUMBNAIL_IMAGES = [
// https://unsplash.com/photos/NUMlxTPsznM coyote?
];

const theme = {
// container
container: { background: 'rgba(255, 255, 255, 0.9)' },

// arrows
arrow: {
backgroundColor: 'rgba(255, 255, 255, 0.8)',
fill: '#222',
opacity: 0.6,
transition: 'opacity 200ms',

':hover': {
opacity: 1,
},
},
arrow__size__medium: {
borderRadius: 40,
height: 40,
marginTop: -20,

'@media (min-width: 768px)': {
height: 70,
padding: 15,
},
},
arrow__direction__left: { marginLeft: 10 },
arrow__direction__right: { marginRight: 10 },

// header
close: {
fill: '#D40000',
opacity: 0.6,
transition: 'all 200ms',

':hover': {
opacity: 1,
},
},

// footer
footer: {
color: 'black',
},
footerCount: {
color: 'rgba(0, 0, 0, 0.6)',
},

// thumbnails
thumbnail: {
},
thumbnail__active: {
boxShadow: '0 0 0 2px #00D8FF',
},
};

render(
<div>
<div style={{ marginBottom: 40 }}>
Expand Down Expand Up @@ -95,17 +150,7 @@ render(
caption,
orientation,
useForDemo,
}))} theme={{
arrow: { color: '#999' },
close: { color: '#666' },
container: { background: 'rgba(255, 255, 255, 0.9)' },
footer: {
color: 'black',
count: {
color: 'rgba(0, 0, 0, 0.6)',
},
},
}} />
}))} theme={theme} showThumbnails />
</div>,
document.getElementById('example')
);
32 changes: 21 additions & 11 deletions src/Lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import Footer from './components/Footer';
import Header from './components/Header';
import PaginatedThumbnails from './components/PaginatedThumbnails';
import Portal from './components/Portal';
// import Thumbnails from './components/Thumbnails';

import { bindFunctions, bodyScroll, canUseDom, deepMerge } from './utils';
import styles from './styles/default';

const classes = StyleSheet.create(styles);
import { bindFunctions, bodyScroll, canUseDom } from './utils';

class Lightbox extends Component {
constructor () {
Expand All @@ -27,11 +23,8 @@ class Lightbox extends Component {
]);
}
getChildContext () {
const extended = deepMerge(theme, this.props.theme);
// console.log('Lightbox extended theme', extended);

return {
theme: extended,
theme: this.props.theme,
};
}
componentWillReceiveProps (nextProps) {
Expand Down Expand Up @@ -187,9 +180,9 @@ class Lightbox extends Component {
/>
{this.renderImages()}
</div>
{this.renderThumbnails()}
{this.renderArrowPrev()}
{this.renderArrowNext()}
{this.renderThumbnails()}
</Container>
);
}
Expand Down Expand Up @@ -314,6 +307,23 @@ Lightbox.childContextTypes = {
theme: PropTypes.object.isRequired,
};

Lightbox.PaginatedThumbnails = PaginatedThumbnails;
const classes = StyleSheet.create({
content: {
position: 'relative',
},
figure: {
margin: 0, // remove browser default
},
image: {
display: 'block', // removes browser default gutter
height: 'auto',
margin: '0 auto', // maintain center on very short screens OR very narrow image
maxWidth: '100%',

// disable user select
WebkitTouchCallout: 'none',
userSelect: 'none',
},
});

export default Lightbox;
33 changes: 18 additions & 15 deletions src/components/Arrow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { PropTypes } from 'react';
import { css, StyleSheet } from 'aphrodite/no-important';

import theme from '../theme';
import defaults from '../theme';
import { deepMerge } from '../utils';
import Icon from './Icon';

function Arrow ({
Expand All @@ -14,15 +15,17 @@ function Arrow ({
{
theme,
}) {
const classes = StyleSheet.create(deepMerge(defaultStyles, theme));

return (
<button
type="button"
className={css(classes.arrow, classes[direction], size && classes[size])}
className={css(classes.arrow, classes['arrow__direction__' + direction], size && classes['arrow__size__' + size])}
onClick={onClick}
onTouchEnd={onClick}
{...props}
>
<Icon color={theme.arrow.color} type={icon} />
<Icon fill={!!theme.arrow && theme.arrow.fill || defaults.arrow.fill} type={icon} />
</button>
);
};
Expand All @@ -40,7 +43,7 @@ Arrow.contextTypes = {
theme: PropTypes.object.isRequired,
};

const classes = StyleSheet.create({
const defaultStyles = {
arrow: {
background: 'none',
border: 'none',
Expand All @@ -57,18 +60,18 @@ const classes = StyleSheet.create({
},

// sizees
medium: {
height: theme.arrow.height,
marginTop: theme.arrow.height / -2,
arrow__size__medium: {
height: defaults.arrow.height,
marginTop: defaults.arrow.height / -2,
width: 40,

'@media (min-width: 768px)': {
width: 70,
},
},
small: {
height: theme.thumbnail.size,
marginTop: theme.thumbnail.size / -2,
arrow__size__small: {
height: defaults.thumbnail.size,
marginTop: defaults.thumbnail.size / -2,
width: 30,

'@media (min-width: 500px)': {
Expand All @@ -77,12 +80,12 @@ const classes = StyleSheet.create({
},

// direction
right: {
right: theme.container.gutter.horizontal,
arrow__direction__right: {
right: defaults.container.gutter.horizontal,
},
left: {
left: theme.container.gutter.horizontal,
arrow__direction__left: {
left: defaults.container.gutter.horizontal,
},
});
};

module.exports = Arrow;
25 changes: 12 additions & 13 deletions src/components/Container.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import React, { PropTypes } from 'react';
import { css, StyleSheet } from 'aphrodite/no-important';

// import theme from './theme';
import defaults from '../theme';
import { deepMerge } from '../utils';

function Container ({ style, ...props }, { theme }) {
props.style = {
backgroundColor: theme.container.background,
paddingBottom: theme.container.gutter.vertical,
paddingLeft: theme.container.gutter.horizontal,
paddingRight: theme.container.gutter.horizontal,
paddingTop: theme.container.gutter.vertical,
zIndex: theme.container.zIndex,
...style,
};
function Container ({ ...props }, { theme }) {
const classes = StyleSheet.create(deepMerge(defaultStyles, theme));

return (
<div
Expand All @@ -26,18 +19,24 @@ Container.contextTypes = {
theme: PropTypes.object.isRequired,
};

const classes = StyleSheet.create({
const defaultStyles = {
container: {
alignItems: 'center',
backgroundColor: defaults.container.background,
boxSizing: 'border-box',
display: 'flex',
height: '100%',
justifyContent: 'center',
left: 0,
paddingBottom: defaults.container.gutter.vertical,
paddingLeft: defaults.container.gutter.horizontal,
paddingRight: defaults.container.gutter.horizontal,
paddingTop: defaults.container.gutter.vertical,
position: 'fixed',
top: 0,
width: '100%',
zIndex: defaults.container.zIndex,
},
});
};

module.exports = Container;
31 changes: 15 additions & 16 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { PropTypes } from 'react';
import { css, StyleSheet } from 'aphrodite/no-important';
import theme from '../theme';
import defaults from '../theme';
import { deepMerge } from '../utils';

function Footer ({
caption,
Expand All @@ -14,21 +15,18 @@ function Footer ({
}) {
if (!caption && !showCount) return null;

const classes = StyleSheet.create(deepMerge(defaultStyles, theme));

const imageCount = showCount ? (
<div className={css(classes.footerCount)} style={{
color: theme.footer.count.color,
fontSize: theme.footer.count.fontSize,
}}>
<div className={css(classes.footerCount)}>
{countCurrent}
{countSeparator}
{countTotal}
</div>)
: <span />;

return (
<div className={css(classes.footer)} {...props} style={{
color: theme.footer.color,
}}>
<div className={css(classes.footer)} {...props}>
{caption ? (
<figcaption className={css(classes.footerCaption)}>
{caption}
Expand All @@ -50,27 +48,28 @@ Footer.contextTypes = {
theme: PropTypes.object.isRequired,
};

const classes = StyleSheet.create({
const defaultStyles = {
footer: {
boxSizing: 'border-box',
color: 'white',
color: defaults.footer.color,
cursor: 'auto',
display: 'flex',
height: theme.footer.height,
justifyContent: 'space-between',
left: 0,
lineHeight: 1.3,
paddingBottom: theme.footer.gutter.vertical,
paddingLeft: theme.footer.gutter.horizontal,
paddingRight: theme.footer.gutter.horizontal,
paddingTop: theme.footer.gutter.vertical,
paddingBottom: defaults.footer.gutter.vertical,
paddingLeft: defaults.footer.gutter.horizontal,
paddingRight: defaults.footer.gutter.horizontal,
paddingTop: defaults.footer.gutter.vertical,
},
footerCount: {
color: defaults.footer.count.color,
fontSize: defaults.footer.count.fontSize,
paddingLeft: '1em', // add a small gutter for the caption
},
footerCaption: {
flex: '1 1 0',
},
});
};

module.exports = Footer;
Loading

0 comments on commit 76bafbb

Please sign in to comment.