Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Designing in React

Designing in React

A thought experiment to test the reusability of components beyond developers

Siddharth Kshetrapal

April 22, 2017
Tweet

More Decks by Siddharth Kshetrapal

Other Decks in Technology

Transcript

  1. import React from 'react' import styled from styled-components' const Title

    = styled.div` font-size: 16px; text-align: center; color: red; ` const MyComponent = () => ( <Title> This text is styled </Title> ) This text is styled
  2. import React from 'react' import styled from styled-components' const Title

    = styled.div` font-size: 16px; text-align: center; color: ${props => props.color}; ` const MyComponent = () => ( <Title color='red'> This text is styled </Title> ) This text is styled
  3. import React from 'react' const Component = (props) => (

    ) Component props: { width: 200px, height: 50px, background: green }
  4. import React from 'react' const Component = (props) => (

    <div style={props.styles}></div> ) Component props: { width: 200px, height: 50px, background: green }
  5. import React from 'react' const Toolbar = () => <div>

    <Slider name='width'/> <Slider name='height'/> <Colorpicker name='background'/> </div> Toolbar
  6. import React from 'react' const Toolbar = ({update}) => <div>

    <Slider name='width' onChange={update}/> <Slider name='height' onChange={update}/> <Colorpicker name='background' onChange={update}/> </div> Toolbar
  7. Workspace Component Toolbar import React from 'react' import Component, Toolbar

    from '...' class Workspace extends React.Component { render () { return <div> <Component/> <Toolbar/> </div> } }
  8. Workspace Component Toolbar import React from 'react' import Component, Toolbar

    from '...' import defaultValues from '...' class Workspace extends React.Component { constructor () { this.state = defaultValues } render () { return <div> <Component/> <Toolbar/> </div> } }
  9. Workspace Component Toolbar import React from 'react' import Component, Toolbar

    from '...' import defaultValues from '...' class Workspace extends React.Component { constructor () { this.state = defaultValues } render () { return <div> <Component styles={this.state}/> <Toolbar/> </div> } }
  10. Workspace Component Toolbar import React from 'react' import Component, Toolbar

    from '...' import defaultValues from '...' class Workspace extends React.Component { constructor () { this.state = defaultValues } update (property) { this.setState(property) } render () { return <div> <Component styles={this.state}/> <Toolbar/> </div> } }
  11. Workspace Component Toolbar import React from 'react' import Component, Toolbar

    from '...' import defaultValues from '...' class Workspace extends React.Component { constructor () { this.state = defaultValues } update (property) { this.setState(property) } render () { return <div> <Component styles={this.state}/> <Toolbar update={this.update}/> </div> } }
  12. import canvas from './canvas' class Workspace extends React.Component { }

    const canvas = { components: [defaultComponent], active: 0 }
  13. import canvas from './canvas' class Workspace extends React.Component { constructor

    () { this.state = canvas } ... } const canvas = { components: [defaultComponent], active: 0 }
  14. import canvas from './canvas' class Workspace extends React.Component { constructor

    () { this.state = canvas } update (property) { this.setState( canvas.update(property) ) } add () { this.setState( canvas.add() ) } ... } const canvas = { components: [defaultComponent], active: 0 }
  15. import canvas from './canvas' class Workspace extends React.Component { constructor

    () { this.state = canvas } update (property) { this.setState( canvas.update(property) ) } add () { this.setState( canvas.add() ) } ... } const canvas = { components: [defaultComponent], active: 0 } const update = (property) => { Object.assign( canvas.components[canvas.active], property ) return canvas }
  16. const canvas = { components: [defaultComponent], active: 0 } const

    canvasHistory = [] const update = (property) => { ... }
  17. const canvas = { components: [defaultComponent], active: 0 } const

    canvasHistory = [] const update = (property) => { const currentState = clone(canvas) canvasHistory.push(currentState) ... }
  18. const canvas = { components: [defaultComponent], active: 0 } const

    canvasHistory = [] const update = (property) => { const currentState = clone(canvas) canvasHistory.push(currentState) ... } const undo = () => { canvas = canvasHistory.pop() return canvas }
  19. { "components": [ { "name": "box", "width": "200px", "height": "50px",

    "background": "green" }, { "name": "title", "width": "150px", "height": "25px", "background": "#333" } ] }
  20. { "components": [ { "name": "box", "width": "200px", "height": "50px",

    "background": "green" }, { "name": "title", "width": "150px", "height": "25px", "background": "#333" } ] } import React from 'react' const styles = { box: {width: '200px', ...}, title: {width: '150px', ...}, } const Box = () => ( <div style={styles.box}></div> ) const Title = () => ( <div style={styles.title}></div> )
  21. { "components": [ { "name": "box", "width": "200px", "height": "50px",

    "background": "green" }, { "name": "title", "width": "150px", "height": "25px", "background": "#333" } ] } import React from 'react' import styled from 'styled-components' const Box = styled.div` width: '200px'; height: '50px'; background: 'green' ` const Title = styled.div` width: '150px'; height: '25px'; background: '#333' `