Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Misc fixes (#27)
Browse files Browse the repository at this point in the history
* Fix pure CSS example

* example(css): Hover underline links in content

* example(css-modules): Hover underline links in content

* example(jss): Hover underline links in content

* fix(all): Open links in new tab

* feat(babel): Add transform-class-properties

* Use class properties instead of binding in the constructor

* fix(eslint): Use babel-eslint parser to support class properties
  • Loading branch information
mxstbr authored Sep 21, 2016
1 parent 6671a10 commit 480929d
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 37 deletions.
3 changes: 2 additions & 1 deletion examples/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"presets": ["es2015", "react"]
"presets": ["es2015", "react"],
"plugins": ["transform-class-properties"]
}
1 change: 1 addition & 0 deletions examples/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"parser": "babel-eslint",
"extends": "airbnb",
"rules": {
"react/prop-types": 0
Expand Down
2 changes: 1 addition & 1 deletion examples/aphrodite/src/components/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const styles = StyleSheet.create({
const Content = ({ text, media }) => (
<div>
<p className={css(styles.text)} dangerouslySetInnerHTML={{ __html: text }} />
<a className={css(styles.media)} href={media.expanded_url}>
<a className={css(styles.media)} target="_blank" href={media.expanded_url}>
<img className={css(styles.image)} src={media.media_url_https} alt="" />
</a>
</div>
Expand Down
4 changes: 1 addition & 3 deletions examples/aphrodite/src/components/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ class Footer extends Component {
this.state = {
liked: false,
};

this.handleClick = this.handleClick.bind(this);
}

handleClick() {
handleClick = () => {
this.setState({
liked: !this.state.liked,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/aphrodite/src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ const styles = StyleSheet.create({
const Header = ({ name, profileImageUrl, screenName, url }) => (
<div className={css(styles.header)}>
<div className={css(styles.profile)}>
<a href={url}>
<a target="_blank" href={url}>
<img className={css(styles.image)} src={profileImageUrl} alt={name} />
</a>
</div>
<div className={css(styles.user)}>
<a className={css(styles.url)} href={url}>
<a className={css(styles.url)} target="_blank" href={url}>
<span className={css(styles.name)}>{name}</span>
<span className={css(styles.screenName)}>@{screenName}</span>
</a>
Expand Down
4 changes: 4 additions & 0 deletions examples/css-modules/src/components/content/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
color: accent;
}

.text a:hover {
text-decoration: underline;
}

.media {
border-radius: .35rem;
border: 1px solid border;
Expand Down
2 changes: 1 addition & 1 deletion examples/css-modules/src/components/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styles from './content.css';
const Content = ({ text, media }) => (
<div>
<p className={styles.text} dangerouslySetInnerHTML={{ __html: text }} />
<a className={styles.media} href={media.expanded_url}>
<a className={styles.media} target="_blank" href={media.expanded_url}>
<img className={styles.image} src={media.media_url_https} alt="" />
</a>
</div>
Expand Down
4 changes: 1 addition & 3 deletions examples/css-modules/src/components/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ class Footer extends Component {
this.state = {
liked: false,
};

this.handleClick = this.handleClick.bind(this);
}

handleClick() {
handleClick = () => {
this.setState({
liked: !this.state.liked,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/css-modules/src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import styles from './header.css';
const Header = ({ name, profileImageUrl, screenName, url }) => (
<div className={styles.header}>
<div className={styles.profile}>
<a href={url}>
<a target="_blank" href={url}>
<img className={styles.image} src={profileImageUrl} alt={name} />
</a>
</div>
<div className={styles.user}>
<a className={styles.url} href={url}>
<a className={styles.url} target="_blank" href={url}>
<span className={styles.name}>{name}</span>
<span className={styles.screenName}>@{screenName}</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion examples/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "src/index.js",
"scripts": {
"start": "../node_modules/.bin/webpack-dev-server --config ../webpack.base.babel.js"
"start": "../node_modules/.bin/webpack-dev-server --config webpack.custom.babel.js"
},
"author": "Max Stoiber",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion examples/css/src/components/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { PropTypes } from 'react';
const Content = ({ text, media }) => (
<div>
<p className="tweet__text" dangerouslySetInnerHTML={{ __html: text }} />
<a className="tweet__media" href={media.expanded_url}>
<a className="tweet__media" target="_blank" href={media.expanded_url}>
<img className="tweet__image" src={media.media_url_https} alt="" />
</a>
</div>
Expand Down
6 changes: 2 additions & 4 deletions examples/css/src/components/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ class Footer extends Component {
this.state = {
liked: false,
};

this.handleClick = this.handleClick.bind(this);
}

handleClick() {
handleClick = () => {
this.setState({
liked: !this.state.liked,
});
Expand Down Expand Up @@ -49,7 +47,7 @@ class Footer extends Component {
<div className="footer__icon">
<RetweetIcon />
</div>
<button className="footer__button" onClick={this.handleClick}>
<button className="footer__icon footer__button" onClick={this.handleClick}>
<LikeIcon className={liked && 'footer__liked'} />
</button>
<div className="footer__icon">
Expand Down
4 changes: 2 additions & 2 deletions examples/css/src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import React, { PropTypes } from 'react';
const Header = ({ name, profileImageUrl, screenName, url }) => (
<div className="header">
<div className="header__profile">
<a href={url}>
<a target="_blank" href={url}>
<img className="header__image" src={profileImageUrl} alt={name} />
</a>
</div>
<div className="header__user">
<a className="header__user-url" href={url}>
<a className="header__user-url" target="_blank" href={url}>
<span className="header__user-name">{name}</span>
<span className="header__user-screenName">@{screenName}</span>
</a>
Expand Down
4 changes: 4 additions & 0 deletions examples/css/src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ svg {
color: #1da1f2;
}

.tweet__text a:hover {
text-decoration: underline;
}

.tweet__media {
border-radius: .35rem;
border: 1px solid #e1e8ed;
Expand Down
13 changes: 13 additions & 0 deletions examples/css/webpack.custom.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { extendBaseConfig } from '../webpack.base.babel';

export default extendBaseConfig({
module: {
loaders: [
{
test: /\.css$/,
exclude: /node_modules/,
loader: 'style!css',
},
],
},
});
8 changes: 7 additions & 1 deletion examples/jss/src/components/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const styles = {
lineHeight: '1.5em',
margin: 0,
padding: '.65625rem 0 .98438rem',
'& a': {
color: '#1da1f2',
},
'& a:hover': {
textDecoration: 'underline',
},
},
media: {
borderRadius: '.35rem',
Expand All @@ -25,7 +31,7 @@ const styles = {
const Content = ({ text, media, sheet: { classes } }) => (
<div>
<p className={classes.text} dangerouslySetInnerHTML={{ __html: text }} />
<a className={classes.media} href={media.expanded_url}>
<a className={classes.media} target="_blank" href={media.expanded_url}>
<img className={classes.image} src={media.media_url_https} alt="" />
</a>
</div>
Expand Down
4 changes: 1 addition & 3 deletions examples/jss/src/components/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ class Footer extends Component {
this.state = {
liked: false,
};

this.handleClick = this.handleClick.bind(this);
}

handleClick() {
handleClick = () => {
this.setState({
liked: !this.state.liked,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/jss/src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ const styles = {
const Header = ({ name, profileImageUrl, screenName, url, sheet }) => (
<div className={sheet.classes.header}>
<div className={sheet.classes.profile}>
<a href={url}>
<a target="_blank" href={url}>
<img className={sheet.classes.image} src={profileImageUrl} alt={name} />
</a>
</div>
<div className={sheet.classes.user}>
<a className={sheet.classes.url} href={url}>
<a className={sheet.classes.url} target="_blank" href={url}>
<span className={sheet.classes.name}>{name}</span>
<span className={sheet.classes.screenName}>@{screenName}</span>
</a>
Expand Down
2 changes: 2 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
},
"devDependencies": {
"babel-core": "6.11.4",
"babel-eslint": "^6.1.2",
"babel-loader": "6.2.4",
"babel-plugin-transform-class-properties": "^6.11.5",
"babel-preset-es2015": "6.9.0",
"babel-preset-react": "6.11.1",
"babel-register": "6.11.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/radium/src/components/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const styles = {
const Content = ({ text, media }) => (
<div>
<p style={styles.text} dangerouslySetInnerHTML={{ __html: text }} />
<a style={styles.media} href={media.expanded_url}>
<a style={styles.media} target="_blank" href={media.expanded_url}>
<img style={styles.image} src={media.media_url_https} alt="" />
</a>
</div>
Expand Down
4 changes: 1 addition & 3 deletions examples/radium/src/components/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ class Footer extends Component {
this.state = {
liked: false,
};

this.handleClick = this.handleClick.bind(this);
}

handleClick() {
handleClick = () => {
this.setState({
liked: !this.state.liked,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/radium/src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ const styles = {
const Header = ({ name, profileImageUrl, screenName, url }) => (
<div style={styles.header}>
<div style={styles.profile}>
<a href={url}>
<a target="_blank" href={url}>
<img style={styles.image} src={profileImageUrl} alt={name} />
</a>
</div>
<div style={styles.user}>
<a style={styles.url} href={url}>
<a style={styles.url} target="_blank" href={url}>
<span style={styles.name}>{name}</span>
<span style={styles.screenNameBefore}></span>
<span style={styles.screenName}>@{screenName}</span>
Expand Down
2 changes: 1 addition & 1 deletion examples/shared/data/755481795206971392.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"user": {
"name": "Max Stoiber",
"screen_name": "mxstbr",
"url": "https:\/\/t.co\/uAtI6h0Zng",
"url": "https:\/\/twitter.com\/mxstbr",
"profile_image_url_https": "https:\/\/mxstbr.com\/headshot.jpeg"
},
"retweet_count": 32,
Expand Down
4 changes: 2 additions & 2 deletions examples/shared/utils/text/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ export const transform = data => {
data.entities.user_mentions.forEach(userMention => {
text = text.replace(
`@${userMention.screen_name}`,
`<a href="https://twitter.com/${userMention.screen_name}">@${userMention.screen_name}</a>`
`<a target="_blank" href="https://twitter.com/${userMention.screen_name}">@${userMention.screen_name}</a>`
);
});

data.entities.urls.forEach(url => {
text = text.replace(
url.url,
`<a href="${url.url}">${url.display_url}</a>`
`<a target="_blank" href="${url.url}">${url.display_url}</a>`
);
});

Expand Down
2 changes: 1 addition & 1 deletion examples/shared/utils/text/text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('text', () => {
},
};

const expected = '\ud83d\udc4f Love love love this article by <a href="https://twitter.com/chantastic">@chantastic</a>. CSS-in-JS isn\u2019t a campaign against CSS! <a href="https://t.co/P3QdkX88rs">medium.com/learnreact/sca…</a>';
const expected = '\ud83d\udc4f Love love love this article by <a target="_blank" href="https://twitter.com/chantastic">@chantastic</a>. CSS-in-JS isn\u2019t a campaign against CSS! <a target="_blank" href="https://t.co/P3QdkX88rs">medium.com/learnreact/sca…</a>';

assert.equal(transform(data), expected);
});
Expand Down

0 comments on commit 480929d

Please sign in to comment.