styling your react app

48
<ReactApp /> Style With

Upload: riza-fahmi

Post on 12-Apr-2017

87 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Styling Your React App

<ReactApp />Style

With

Page 2: Styling Your React App

RIZA, CURRICULUM DIRECTOR, CO-FOUNDER

“Hacktiv8 Ada Untuk Menciptakan Developer Handal Yang Bisa Berjaya Di Negara Sendiri"

Page 3: Styling Your React App

[email protected]

facebook.com/rizafahmi

github.com/rizafahmi

medium.com/@rizafahmi22

@rizafahmi22

appscoast.id

slideshare.net/rizafahmi

Hi, I’m Riza

Page 4: Styling Your React App

Let’s talk about styling

Page 5: Styling Your React App

Good Old CSSBrand New

React Styling

Page 6: Styling Your React App

Good Old CSS

Page 7: Styling Your React App

Options For CSS

Page 8: Styling Your React App

CSS Preprocessors

Page 9: Styling Your React App

Good Old CSS // index.css body { margin: 0; padding: 0; font-family: sans-serif; }

// App.jsx import './index.css' ReactDOM.render( <App />, document.getElementById('root') )

Page 10: Styling Your React App

Styling Your CSS Using // index.styl border-radius() -webkit-border-radius: arguments -moz-border-radius: arguments border-radius: arguments .cool_button border-radius(5px)

// react.js import './index.styl'

const CoolButton = () => ( <button className=‘cool_button’>Confirm </button> )

Page 11: Styling Your React App

Pros

Familiar

Page 12: Styling Your React App

Cons

Page 13: Styling Your React App
Page 14: Styling Your React App
Page 15: Styling Your React App
Page 16: Styling Your React App

Bad For Dynamic UI

Page 17: Styling Your React App

React-based Styling

Page 18: Styling Your React App
Page 19: Styling Your React App

// cool.js import styles from './styles.css'

export const CoolButton = (props) => { return ( <button className={styles.red}>{this.props.text} </button> ) }

/* styles.css */ .red { font-size: 25px; background-color: red; color: white; }

Page 20: Styling Your React App

Pros

Page 21: Styling Your React App
Page 22: Styling Your React App

Cons

Page 23: Styling Your React App
Page 24: Styling Your React App

React-Style

React Style

Page 25: Styling Your React App

import StyleSheet from 'react-style'

const styles = StyleSheet.create({ primary: { backgroundColor: 'green' }, button: { padding: '1em' }, // media queries '@media (max-width: 200px)': { button: { width: '100%' } } })

// ... <button styles={[styles.button, styles.primary]}>Confirm </button>

Page 26: Styling Your React App

Pros

Page 27: Styling Your React App
Page 28: Styling Your React App

import styles from './styles.js'

<button styles={[styles.button, styles.primary]}>Confirm </button>

Page 29: Styling Your React App

Cons

Page 30: Styling Your React App
Page 31: Styling Your React App
Page 32: Styling Your React App
Page 33: Styling Your React App

Inline Styling

Page 34: Styling Your React App

const divStyle = { color: 'blue', backgroundImage: 'url(' + imgUrl + ')', WebkitTransition: 'all', msTransition: ‘all’, height: 20, }

function App () { return <div style={divStyle}>Hello World! </div> }

Page 35: Styling Your React App

Pros

Page 36: Styling Your React App

Implement Logic<div> <input onChange={this.handleColorChange} /> <input type='number' onChange={this.handleSizeChange} /> <p style={{ color: this.state.color, fontSize: this.state.fontSize }} > This paragraph is {this.state.color} and {this.state.fontSize} px </p> </div>

Page 37: Styling Your React App
Page 38: Styling Your React App

Code Reusability

Page 39: Styling Your React App

Style Next To Markupconst divStyle = { color: 'blue', backgroundImage: 'url(' + imgUrl + ')', WebkitTransition: 'all', msTransition: 'all' }

function App () { return <div style={divStyle}>Hello World! </div> }

Page 40: Styling Your React App

Cons

Page 41: Styling Your React App
Page 42: Styling Your React App
Page 43: Styling Your React App
Page 44: Styling Your React App
Page 45: Styling Your React App
Page 46: Styling Your React App
Page 47: Styling Your React App
Page 48: Styling Your React App

Let’s have some question