mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-06 14:16:50 +02:00
feat: Add color swatch pattern
This commit is contained in:
8
contents/_includes/patterns/color-swatch.njk
Normal file
8
contents/_includes/patterns/color-swatch.njk
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="swatch">
|
||||
<div class="swatch__item swatch__item--1st"></div>
|
||||
<div class="swatch__item swatch__item--2nd"></div>
|
||||
<div class="swatch__item swatch__item--3rd"></div>
|
||||
<div class="swatch__item swatch__item--4th"></div>
|
||||
<div class="swatch__item swatch__item--5th"></div>
|
||||
<div class="swatch__item swatch__item--6th"></div>
|
||||
</div>
|
40
contents/color-swatch.md
Normal file
40
contents/color-swatch.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Color swatch
|
||||
description: Create a color swatch with CSS flexbox
|
||||
keywords: css color swatch, css flexbox
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="swatch">
|
||||
<div class="swatch__item" style="background-color: ..."></div>
|
||||
|
||||
<!-- Repeat other items -->
|
||||
...
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.swatch {
|
||||
/* Wrap the items */
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.swatch__item {
|
||||
/* Rounded border */
|
||||
border-radius: 9999px;
|
||||
height: 1.5rem;
|
||||
width: 1.5rem;
|
||||
|
||||
/* Space between items */
|
||||
margin: 0.5rem;
|
||||
}
|
||||
```
|
||||
|
||||
{% demo %}
|
||||
{% include "patterns/color-swatch.njk" %}
|
||||
{% enddemo %}
|
@@ -61,6 +61,12 @@ eleventyExcludeFromCollections: true
|
||||
<div class="pattern__title">Close button</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="pattern__item">
|
||||
<a class="pattern__link" href="/color-swatch/">
|
||||
<div class="pattern__cover">{% include "patterns/color-swatch.njk" %}</div>
|
||||
<div class="pattern__title">Color swatch</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@@ -1,79 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import Head from 'next/head';
|
||||
|
||||
import { Pattern } from '../../constants/Pattern';
|
||||
import { PatternLayout } from '../../layouts/PatternLayout';
|
||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
||||
|
||||
const Details: React.FC<{}> = () => {
|
||||
return (
|
||||
<PatternLayout pattern={Pattern.ColorSwatch}>
|
||||
<Head>
|
||||
<meta name="description" content="Create a color swatch with CSS flexbox" />
|
||||
<meta name="og:description" content="Create a color swatch with CSS flexbox" />
|
||||
<meta name="twitter:description" content="Create a color swatch with CSS flexbox" />
|
||||
<meta name="keywords" content="css color swatch, css flexbox" />
|
||||
</Head>
|
||||
<BrowserFrame
|
||||
html={`
|
||||
<div class="swatch">
|
||||
<div class="swatch__item" style="background-color: ..."></div>
|
||||
|
||||
<!-- Repeat other items -->
|
||||
...
|
||||
</div>
|
||||
`}
|
||||
css={`
|
||||
.swatch {
|
||||
/* Wrap the items */
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.swatch__item {
|
||||
/* Rounded border */
|
||||
border-radius: 9999px;
|
||||
height: 1.5rem;
|
||||
width: 1.5rem;
|
||||
|
||||
/* Space between items */
|
||||
margin: 0.5rem;
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '0.5rem',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
{Array(9)
|
||||
.fill(0)
|
||||
.map((_, index) => (
|
||||
<div
|
||||
key={index}
|
||||
style={{
|
||||
backgroundColor: `rgba(0, 0, 0, 0.${index + 1})`,
|
||||
borderRadius: '9999px',
|
||||
height: '1.5rem',
|
||||
margin: '0.5rem',
|
||||
width: '1.5rem',
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
</PatternLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Details;
|
@@ -1,37 +0,0 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import Frame from '../../placeholders/Frame';
|
||||
|
||||
const Cover: React.FC<{}> = () => {
|
||||
return (
|
||||
<Frame>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
{Array(4)
|
||||
.fill(0)
|
||||
.map((_, index) => (
|
||||
<div
|
||||
key={index}
|
||||
style={{
|
||||
backgroundColor: `rgba(0, 0, 0, 0.${index * 2 + 1})`,
|
||||
borderRadius: '9999px',
|
||||
height: '1.5rem',
|
||||
margin: '0.5rem',
|
||||
width: '1.5rem',
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Frame>
|
||||
);
|
||||
};
|
||||
|
||||
export default Cover;
|
@@ -19,6 +19,7 @@
|
||||
@import './patterns/card';
|
||||
@import './patterns/centering';
|
||||
@import './patterns/close-button';
|
||||
@import './patterns/color-swatch';
|
||||
|
||||
// Placeholders
|
||||
@import './placeholders/circle';
|
||||
|
32
styles/patterns/_color-swatch.scss
Normal file
32
styles/patterns/_color-swatch.scss
Normal file
@@ -0,0 +1,32 @@
|
||||
.swatch {
|
||||
/* Wrap the items */
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.swatch__item {
|
||||
/* Rounded border */
|
||||
border-radius: 9999px;
|
||||
height: 1.5rem;
|
||||
width: 1.5rem;
|
||||
|
||||
/* Space between items */
|
||||
margin: 0.5rem;
|
||||
}
|
||||
.swatch__item--1st {
|
||||
background-color: rgba(0, 0, 0, .1);
|
||||
}
|
||||
.swatch__item--2nd {
|
||||
background-color: rgba(0, 0, 0, .2);
|
||||
}
|
||||
.swatch__item--3rd {
|
||||
background-color: rgba(0, 0, 0, .3);
|
||||
}
|
||||
.swatch__item--4th {
|
||||
background-color: rgba(0, 0, 0, .4);
|
||||
}
|
||||
.swatch__item--5th {
|
||||
background-color: rgba(0, 0, 0, .5);
|
||||
}
|
||||
.swatch__item--6th {
|
||||
background-color: rgba(0, 0, 0, .6);
|
||||
}
|
Reference in New Issue
Block a user