Babel React template
How do I make an babel react template?
A very simple example for playing around with React. Includes transitions, fetching data, repetition and a stateless component.. What is a babel react template? How do you make a babel react template? This script and codes were developed by Ross B on 24 November 2022, Thursday.
Babel React template - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Babel React template</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="app"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-with-addons.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/fetch/0.10.0/fetch.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Babel React template - Script Codes CSS Codes
.card { padding: 20px; border-bottom: 1px solid lightgray;
}
.card::after { clear: both; content: ""; display: table;
}
.card .card-thumbnail { float: left; margin-right: 20px; height: 150px; width: 150px;
}
.slide-enter { opacity: 0.01;
}
.slide-enter .card-thumbnail { -webkit-transform: translateX(-100%); transform: translateX(-100%);
}
.slide-enter.slide-enter-active { opacity: 1; -webkit-transition: opacity 500ms ease-in; transition: opacity 500ms ease-in;
}
.slide-enter.slide-enter-active .card-thumbnail { -webkit-transition: -webkit-transform 0.5s ease; transition: -webkit-transform 0.5s ease; transition: transform 0.5s ease; transition: transform 0.5s ease, -webkit-transform 0.5s ease; -webkit-transform: translateZ(0); transform: translateZ(0);
}
.slide-leave { opacity: 1;
}
.slide-leave.slide-leave-active { opacity: 0.01; -webkit-transition: opacity 300ms ease-in; transition: opacity 300ms ease-in;
}
Babel React template - Script Codes JS Codes
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/*
** Data from 'http://jsonplaceholder.typicode.com/photos'
** JSON schema is as follows:
** [
** {
** "albumId": 1,
** "id": 1,
** "title": "accusamus beatae ad",
** "url": "http://placehold.it/600/92c952",
** "thumbnailUrl": "http://placehold.it/150/30ac17"
** },
** ...
** ]
*/
/*
** React Component, CSSTransitionGroup:
** This will be used to animate some DOM insertions
** by creating a container around the points at which
** nodes will be inserted [or removed].
*/
var CSSTransitionGroup = React.addons.CSSTransitionGroup;
// Source of data, we use fetch to retrieve the JSON
// fetch docs: https://github.com/github/fetch
var dataURL = 'http://jsonplaceholder.typicode.com/photos';
// Maximum number of items to show
var showNItems = 50;
/*
** React feature, stateless components:
** These components can be created with less code.
** Props can be picked through destructuring (seen below)
** or by passing a props object.
** The below example uses an implicit return, but you
** could do stuff before returning the component.
** These components do not have a state.
*/
var PreviewCard = function PreviewCard(_ref) { var title = _ref.title; var thumbnailUrl = _ref.thumbnailUrl; var url = _ref.url; var id = _ref.id; return React.createElement( "div", { className: "card", key: id }, React.createElement("img", { className: "card-thumbnail", src: thumbnailUrl }), React.createElement( "h3", { className: "card-title" }, title ), React.createElement( "span", null, "Full resolution: " ), React.createElement( "a", { href: url, target: "_blank" }, url ) );
};
/*
** Custom React component:
** This is our top level component.
** In more complex situations your uppermost
** component might be a router or some sort
** or Flux store interface which would wrap
** our App component.
*/
var App = function (_React$Component) { _inherits(App, _React$Component); function App() { _classCallCheck(this, App); var _this = _possibleConstructorReturn(this, _React$Component.call(this)); _this.state = { items: [] }; return _this; } App.prototype.componentDidMount = function componentDidMount() { var _this2 = this; fetch(dataURL).then(function (response) { return response.json(); }).then(function (body) { return _this2.setState({ items: body.slice(0, showNItems) }); }); }; App.prototype.render = function render() { var items = this.state.items.map(function (i) { return React.createElement(PreviewCard, i); }); return React.createElement( "div", null, items.length === 0 ? 'Loading...' : '', React.createElement( CSSTransitionGroup, { transitionName: "slide" }, items ) ); }; return App;
}(React.Component);
// Insertion point for App component
var entryNode = document.querySelector('.app');
// React API to render component into DOM
React.render(React.createElement(App, null), entryNode);
Developer | Ross B |
Username | rocbear |
Uploaded | November 24, 2022 |
Rating | 3 |
Size | 5,357 Kb |
Views | 14,168 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
UFO | 2,608 Kb |
Unfolding circular menu | 7,466 Kb |
Spear checkboxes | 3,682 Kb |
Responsive grid based FLIP.js demo | 3,883 Kb |
Wobbly list | 5,672 Kb |
Plane vertex manipulation experiment | 4,363 Kb |
Full page scroll-over with Skrollr | 2,633 Kb |
Spin button | 3,935 Kb |
Canvas blend modes | 4,640 Kb |
Loading animation - freedom purchase | 2,567 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Pure CSS albums gallery | Renaudtertrais | 2,978 Kb |
A Pen by John Malc | F789gh | 1,420 Kb |
Very Simple Slider | Doodlemarks | 2,682 Kb |
Login with flip 3d animation | Mariusbalaj | 3,014 Kb |
Simple CSS loader. | Cabrera | 2,574 Kb |
Html5-canvas-snow-effect | MariamMassadeh | 2,609 Kb |
Tab Menus | Zephyr | 3,180 Kb |
Spiralator 9000 | AdmiralPotato | 4,671 Kb |
Flexbox Grid - equal height | DaveOrDead | 2,855 Kb |
CSS Chat Bubbles | Boylett | 2,094 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!