1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-06 14:16:50 +02:00

feat: Timeline

This commit is contained in:
Phuoc Nguyen
2022-09-20 09:08:58 +07:00
parent f14eac7023
commit 33aceeb8a5
7 changed files with 184 additions and 291 deletions

View File

@@ -0,0 +1,16 @@
<div class="timeline">
<div class="timeline__line"></div>
<div class="timeline__items">
{% for i in range(0, 2) -%}
<div class="timeline__item">
<div class="timeline__top">
<div class="timeline__circle"></div>
<div class="timeline__title">{% rectangle %}</div>
</div>
<div class="timeline__desc">
{% lines "hor", 5 %}
</div>
</div>
{%- endfor %}
</div>
</div>

View File

@@ -271,6 +271,12 @@ eleventyExcludeFromCollections: true
<div class="pattern__title">Three dimensions card</div>
</a>
</div>
<div class="pattern__item">
<a class="pattern__link" href="/timeline/">
<div class="pattern__cover">{% include "patterns/timeline.njk" %}</div>
<div class="pattern__title">Timeline</div>
</a>
</div>
<div class="pattern__item">
<a class="pattern__link" href="/video-background/">
<div class="pattern__cover">{% include "patterns/video-background.njk" %}</div>

102
contents/timeline.md Normal file
View File

@@ -0,0 +1,102 @@
---
layout: layouts/post.njk
title: Timeline
description: Create a timeline with CSS flexbox
keywords: css flexbox, css timeline
---
## HTML
```html
<div class="timeline">
<!-- Left vertical line -->
<div class="timeline__line"></div>
<!-- The timeline items timeline -->
<div class="timeline__items">
<!-- Each timeline item -->
<div class="timeline__item">
<!-- The circle and title -->
<div class="timeline__top">
<!-- The circle -->
<div class="timeline__circle"></div>
<!-- The title -->
<div class="timeline__title">
...
</div>
</div>
<!-- The description -->
<div class="timeline__desc">
...
</div>
</div>
<!-- Repeat other items -->
...
</div>
</div>
```
## CSS
```css
.timeline {
/* Used to position the left vertical line */
position: relative;
}
.timeline__line {
/* Border */
border-right: 2px solid #d1d5db;
/* Positioned at the left */
left: 0.75rem;
position: absolute;
top: 0px;
/* Take full height */
height: 100%;
}
.timeline__items {
/* Reset styles */
list-style-type: none;
margin: 0px;
padding: 0px;
}
.timeline__item {
margin-bottom: 8px;
}
.timeline__top {
/* Center the content horizontally */
align-items: center;
display: flex;
}
.timeline__circle {
/* Rounded border */
background-color: #d1d5db;
border-radius: 9999px;
/* Size */
height: 1.5rem;
width: 1.5rem;
}
.timeline__title {
/* Take available width */
flex: 1;
margin-left: 0.5rem;
}
.timeline__desc {
/* Make it align with the title */
margin-left: 2rem;
}
```
{% demo %}{% include "patterns/timeline.njk" %}{% enddemo %}

View File

@@ -1,193 +0,0 @@
import * as React from 'react';
import Head from 'next/head';
import { Spacer } from '@1milligram/design';
import { Pattern } from '../../constants/Pattern';
import { RelatedPatterns } from '../../components/RelatedPatterns';
import { PatternLayout } from '../../layouts/PatternLayout';
import Block from '../../placeholders/Block';
import BrowserFrame from '../../placeholders/BrowserFrame';
import Circle from '../../placeholders/Circle';
import Rectangle from '../../placeholders/Rectangle';
const Details: React.FC<{}> = () => {
return (
<PatternLayout pattern={Pattern.Timeline}>
<Head>
<meta name="description" content="Create a timeline with CSS flexbox" />
<meta name="og:description" content="Create a timeline with CSS flexbox" />
<meta name="twitter:description" content="Create a timeline with CSS flexbox" />
<meta name="keywords" content="css flexbox, css timeline" />
</Head>
<BrowserFrame
html={`
<div class="container">
<!-- Left vertical line -->
<div class="container__line"></div>
<!-- The timeline items container -->
<ul class="container__items">
<!-- Each timeline item -->
<li class="container__item">
<!-- The circle and title -->
<div class="container__top">
<!-- The circle -->
<div class="container__circle"></div>
<!-- The title -->
<div class="container__title">
...
</div>
</div>
<!-- The description -->
<div class="container__desc">
...
</div>
</li>
<!-- Repeat other items -->
...
</ul>
</div>
`}
css={`
.container {
/* Used to position the left vertical line */
position: relative;
}
.container__line {
/* Border */
border-right: 2px solid #aaa;
/* Positioned at the left */
left: 16px;
position: absolute;
top: 0px;
/* Take full height */
height: 100%;
}
.container__items {
/* Reset styles */
list-style-type: none;
margin: 0px;
padding: 0px;
}
.container__item {
margin-bottom: 8px;
}
.container__top {
/* Center the content horizontally */
align-items: center;
display: flex;
}
.container__circle {
/* Rounded border */
background-color: rgb(170, 170, 170);
border-radius: 9999px;
/* Size */
height: 32px;
width: 32px;
}
.container__title {
/* Take available width */
flex: 1;
}
.container__desc {
/* Make it align with the title */
margin-left: 48px;
}
`}
>
<div
style={{
alignItems: 'center',
display: 'flex',
flexDirection: 'column',
height: '100%',
justifyContent: 'center',
padding: '8px',
}}
>
<div
style={{
position: 'relative',
width: '60%',
}}
>
<div
style={{
borderRight: '2px solid #aaa',
height: '100%',
left: '16px',
position: 'absolute',
top: 0,
}}
/>
<ul
style={{
listStyleType: 'none',
margin: 0,
padding: 0,
}}
>
<li style={{ marginBottom: '8px' }}>
<div style={{ alignItems: 'center', display: 'flex', marginBottom: '4px' }}>
<Circle backgroundColor="#aaa" size={32} />
<div style={{ flex: 1, marginLeft: '16px' }}>
<div style={{ width: '80%' }}>
<Rectangle />
</div>
</div>
</div>
<div style={{ marginLeft: '48px' }}>
<Block numberOfBlocks={10} blockHeight={2} />
</div>
</li>
<li style={{ marginBottom: '8px' }}>
<div style={{ alignItems: 'center', display: 'flex', marginBottom: '4px' }}>
<Circle backgroundColor="#aaa" size={32} />
<div style={{ flex: 1, marginLeft: '16px' }}>
<div style={{ width: '60%' }}>
<Rectangle />
</div>
</div>
</div>
<div style={{ marginLeft: '48px' }}>
<Block numberOfBlocks={15} blockHeight={2} />
</div>
</li>
<li style={{ marginBottom: '8px' }}>
<div style={{ alignItems: 'center', display: 'flex', marginBottom: '4px' }}>
<Circle backgroundColor="#aaa" size={32} />
<div style={{ flex: 1, marginLeft: '16px' }}>
<div style={{ width: '60%' }}>
<Rectangle />
</div>
</div>
</div>
<div style={{ marginLeft: '48px' }}>
<Block numberOfBlocks={10} blockHeight={2} />
</div>
</li>
</ul>
</div>
</div>
</BrowserFrame>
<Spacer size="extraLarge" />
<RelatedPatterns patterns={[Pattern.ZigzagTimeline]} />
</PatternLayout>
);
};
export default Details;

View File

@@ -1,98 +0,0 @@
import * as React from 'react';
import Circle from '../../placeholders/Circle';
import Frame from '../../placeholders/Frame';
import Line from '../../placeholders/Line';
import Rectangle from '../../placeholders/Rectangle';
const Cover: React.FC<{}> = () => {
return (
<Frame>
<div
style={{
alignItems: 'center',
display: 'flex',
flexDirection: 'column',
height: '100%',
justifyContent: 'center',
padding: '8px',
}}
>
<div
style={{
position: 'relative',
width: '100%',
}}
>
<div
style={{
borderRight: '1px solid #aaa',
height: '100%',
left: '6px',
position: 'absolute',
top: 0,
}}
/>
<ul
style={{
listStyleType: 'none',
margin: 0,
padding: 0,
}}
>
<li style={{ marginBottom: '8px' }}>
<div style={{ alignItems: 'center', display: 'flex', marginBottom: '4px' }}>
<Circle backgroundColor="#aaa" size={12} />
<div style={{ flex: 1, marginLeft: '8px' }}>
<div style={{ width: '80%' }}>
<Rectangle />
</div>
</div>
</div>
<div style={{ marginLeft: '20px' }}>
<div style={{ marginBottom: '4px', width: '100%' }}>
<Line />
</div>
<div style={{ marginBottom: '4px', width: '80%' }}>
<Line />
</div>
<div style={{ marginBottom: '4px', width: '60%' }}>
<Line />
</div>
<div style={{ width: '40%' }}>
<Line />
</div>
</div>
</li>
<li>
<div style={{ alignItems: 'center', display: 'flex', marginBottom: '4px' }}>
<Circle backgroundColor="#aaa" size={12} />
<div style={{ flex: 1, marginLeft: '8px' }}>
<div style={{ width: '60%' }}>
<Rectangle />
</div>
</div>
</div>
<div style={{ marginLeft: '20px' }}>
<div style={{ marginBottom: '4px', width: '80%' }}>
<Line />
</div>
<div style={{ marginBottom: '4px', width: '60%' }}>
<Line />
</div>
<div style={{ marginBottom: '4px', width: '40%' }}>
<Line />
</div>
<div style={{ width: '80%' }}>
<Line />
</div>
</div>
</li>
</ul>
</div>
</div>
</Frame>
);
};
export default Cover;

View File

@@ -54,6 +54,7 @@
@import './patterns/status-light';
@import './patterns/teardrop';
@import './patterns/three-dimensions-card';
@import './patterns/timeline';
@import './patterns/triangle-buttons';
@import './patterns/video-background';
@import './patterns/voting';

View File

@@ -0,0 +1,59 @@
.timeline {
/* Used to position the left vertical line */
position: relative;
/* Demo */
height: 100%;
width: 100%;
}
.timeline__line {
/* Border */
border-right: 2px solid #d1d5db;
/* Positioned at the left */
left: 0.75rem;
position: absolute;
top: 0px;
/* Take full height */
height: 100%;
}
.timeline__items {
/* Reset styles */
list-style-type: none;
margin: 0px;
padding: 0px;
}
.timeline__item {
margin-bottom: 8px;
}
.timeline__top {
/* Center the content horizontally */
align-items: center;
display: flex;
}
.timeline__circle {
/* Rounded border */
background-color: #d1d5db;
border-radius: 9999px;
/* Size */
height: 1.5rem;
width: 1.5rem;
}
.timeline__title {
/* Take available width */
flex: 1;
margin-left: 0.5rem;
}
.timeline__desc {
/* Make it align with the title */
margin-left: 2rem;
}