原文链接:https://www.newline.co/fullstack-react/30-days-of-react/day-4/
In this section, we'll continue our work with our App
component and start building a more complex UI.
A common web element we might see is a user timeline.
For instance, we might have an application that shows a history of events happening such as applications like Facebook and Twitter.
Styles
If you include the following CSS as a <link />
tag in your code, you're timeline will look similar and will be using the same styling ours is using:
<link
href="https://cdn.jsdelivr.net/gh/fullstackreact/30-days-of-react@master/day-04/src/components/Timeline/Timeline.css"
rel="stylesheet"
type="text/css"
/>
As we're not focusing on CSS in this course, we're not covering the CSS specific to build the timeline as you see it on the screen.
And make sure to surround your code in a component with the class of demo
(we left it this way purposefully as it's the exact same code we use in all the demos here).
Check out the https://jsfiddle.net/auser/zwomnfwk/ for a working example.
The entire compiled CSS can be found on the github repository at https://github.com/fullstackreact/30-days-of-react/blob/master/day-04/src/components/Timeline/Timeline.css.
In addition, in order to make the timeline look exactly like the way ours does on the site, you'll need to include font-awesome in your web application.
There are multiple ways to handle this. The simplest way is to include the link styles:
<link
href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
rel="stylesheet"
type="text/css"
/>
All the code for the examples on the page is available at the github repo (at https://github.com/fullstackreact/30-days-of-react).
We could build this entire UI in a single component.
However, building an entire application in a single component is not a great idea as it can grow huge, complex, and difficult to test.
class Timeline extends React.Component {
render() {
return (
<div className="notificationsFrame">
<div className="panel">
<div className="header">
<div className="menuIcon">
<div className="dashTop"></div>
<div className="dashBottom"></div>
<div className="circle"></div>
</div>
<span className="title">Timeline</span>
<input
type="text"
className="searchInput"
placeholder="Search ..." />
<div className="fa fa-search searchIcon"></div>
</div>
<div className="content">
<div className="line"></div>
<div className="item">
<div className="avatar">
<img
alt='doug'
src="http://www.croop.cl/UI/twitter/images/doug.jpg" />
</div>
<span className="time">
An hour ago
</span>
<p>Ate lunch</p>
</div>
<div className="item">
<div className="avatar">
<img
alt='doug' src="http://www.croop.cl/UI/twitter/images/doug.jpg" />
</div