Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create simple, general-purpose modular things with #React and play by switching CSS colors (#Codepen) #1379

Open
YumaInaura opened this issue Apr 22, 2019 · 0 comments

Comments

@YumaInaura
Copy link
Owner

YumaInaura commented Apr 22, 2019

Anyways

Let's go for a strategy to minimize the threshold.

React on CodePen-React Patterns & Templates

Choose a good teaching material.

image.png

Codepen

Appropriately made it easy to use.

A Pen by yumainaura image.png

point

I'm making a generic module called Box

image.png

Calling 3 Box Components from App Component

changing colorMode

image.png

I have defined colorMode in CSS

image.png

When colorMode = false, it seems that you can do nothing.

(Don't feel like being similar to # ruby's bogus operator)

js

// This is how a function component takes props.
const Box = props => (
  <div className={`box ${props.colorMode}`}>
    <h1 className="title">{props.title}</h1>
  </div>
);

// This Class component also can have props
class App extends React.Component {

  render() {
    
    return <div>
      <h1 class="subtitle">
        {this.props.header}
      </h1>
      <Box
        colorMode="false"
        title="Light"
      />
      <Box
        colorMode="dark-mode"
        title="Dark"
      />
      <Box
        colorMode="orange-mode"
        title="Orange"
      />
    </div>;
  }
  
}


ReactDOM.render(<App header="Hello, Colors!"/>, document.getElementById("root"));

css

body {
  height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  max-width: 250px;
  margin: 0 auto;
}
.box {
  width: 300px;
  &.dark-mode {
    background: black;
    color: #bbb;
    h1 {
      color: white;
    }
    .checkbox:hover {
      color: white;
    }
  }
  &.orange-mode {
    background: orange;
    color: red;
    h1 {
      color: red;
    }
    .checkbox:hover {
      color: red;
    }
  }
}

HTML

 <div id="root"></div> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant