Color Value – React

In this example below you will see how to do a Color Value – React with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by ninjazim, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright ninjazim ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Color Value – React</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id="app"></div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/ninjazim/color-value-andx2013-react-XMwGEp */
html, body {
	height: 100%;
	padding: 0;
	margin: 0;
}

#app {
	height: 100%;
}


.container {
	display: flex;
	flex-direction: column;
	width: 100%;
	background-color: white;
	height: 100%;
	justify-content: center;
	align-items: center;
	transition: 0.4s;
}

input {
	height: 100%;
	width: 100%;
	font-size: 3em;
	background: none;
	border: 0;
	text-align: center;
	color: gray;
	opacity: 0.7;
	mix-blend-mode: luminosity;
}

input:focus {
	outline: none;
}

/*Downloaded from https://www.codeseek.co/ninjazim/color-value-andx2013-react-XMwGEp */
var InputBox = React.createClass({
	displayName: 'InputBox',


	getInitialState: function getInitialState() {
		return {
			placeholder: "type something here",
			color: ''
		};
	},
	handleChange: function handleChange(e) {
		this.setState({
			color: e.target.value
		});
	},
	render: function render() {
		var style = {
			backgroundColor: this.state.color
		};

		if (this.state.color == 'gray') {
			var fontColor = {
				color: 'lightgray'
			};
		}

		return React.createElement(
			'div',
			{ style: style, className: 'container' },
			React.createElement('input', { type: 'text', style: fontColor, placeholder: 'enter a color value', value: this.state.color, onChange: this.handleChange })
		);
	}
});

ReactDOM.render(React.createElement(InputBox, null), document.getElementById('app'));

Comments