mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-06 06:07:33 +02:00
feat: Add badge
This commit is contained in:
1
contents/_includes/patterns/badge.njk
Normal file
1
contents/_includes/patterns/badge.njk
Normal file
@@ -0,0 +1 @@
|
||||
<div class="badge">9+</div>
|
38
contents/badge.md
Normal file
38
contents/badge.md
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Badge
|
||||
description: Create a badge component with CSS flexbox
|
||||
keywords: css badge, css flexbox
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="badge">
|
||||
...
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.badge {
|
||||
/* Center the content */
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
/* Colors */
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
color: #fff;
|
||||
|
||||
/* Rounded border */
|
||||
border-radius: 9999px;
|
||||
height: 3rem;
|
||||
width: 3rem;
|
||||
}
|
||||
```
|
||||
|
||||
{% demo %}
|
||||
{% include "patterns/badge.njk" %}
|
||||
{% enddemo %}
|
@@ -37,6 +37,12 @@ eleventyExcludeFromCollections: true
|
||||
<div class="card__title">Avatar list</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="card__item">
|
||||
<a class="card__link" href="/badge/">
|
||||
<div class="card__cover">{% include "patterns/badge.njk" %}</div>
|
||||
<div class="card__title">Badge</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@@ -1,78 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import Head from 'next/head';
|
||||
import { Spacer } from '@1milligram/design';
|
||||
|
||||
import { RelatedPatterns } from '../../components/RelatedPatterns';
|
||||
import { Pattern } from '../../constants/Pattern';
|
||||
import { PatternLayout } from '../../layouts/PatternLayout';
|
||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
||||
|
||||
const Details: React.FC<{}> = () => {
|
||||
return (
|
||||
<PatternLayout pattern={Pattern.Badge}>
|
||||
<Head>
|
||||
<meta name="description" content="Create a badge component with CSS flexbox" />
|
||||
<meta name="og:description" content="Create a badge component with CSS flexbox" />
|
||||
<meta name="twitter:description" content="Create a badge component with CSS flexbox" />
|
||||
<meta name="keywords" content="css badge, css flexbox" />
|
||||
</Head>
|
||||
<BrowserFrame
|
||||
html={`
|
||||
<div class="badge">
|
||||
...
|
||||
</div>
|
||||
`}
|
||||
css={`
|
||||
.badge {
|
||||
/* Center the content */
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
/* Colors */
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
color: #fff;
|
||||
|
||||
/* Rounded border */
|
||||
border-radius: 9999px;
|
||||
height: 32px;
|
||||
width: 32px;
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
||||
borderRadius: '9999px',
|
||||
color: '#FFF',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
fontSize: '20px',
|
||||
height: '32px',
|
||||
justifyContent: 'center',
|
||||
width: '32px',
|
||||
}}
|
||||
>
|
||||
1
|
||||
</div>
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
|
||||
<Spacer size="extraLarge" />
|
||||
<RelatedPatterns patterns={[Pattern.Centering, Pattern.InitialAvatar]} />
|
||||
</PatternLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Details;
|
@@ -1,38 +0,0 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import Frame from '../../placeholders/Frame';
|
||||
|
||||
const Cover: React.FC<{}> = () => {
|
||||
return (
|
||||
<Frame>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
||||
borderRadius: '9999px',
|
||||
color: '#FFF',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '32px',
|
||||
justifyContent: 'center',
|
||||
width: '32px',
|
||||
}}
|
||||
>
|
||||
1
|
||||
</div>
|
||||
</div>
|
||||
</Frame>
|
||||
);
|
||||
};
|
||||
|
||||
export default Cover;
|
@@ -15,6 +15,7 @@
|
||||
@import './patterns/arrow-buttons';
|
||||
@import './patterns/avatar';
|
||||
@import './patterns/avatar-list';
|
||||
@import './patterns/badge';
|
||||
|
||||
// Placeholders
|
||||
@import './placeholders/circle';
|
||||
|
15
styles/patterns/_badge.scss
Normal file
15
styles/patterns/_badge.scss
Normal file
@@ -0,0 +1,15 @@
|
||||
.badge {
|
||||
/* Center the content */
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
/* Colors */
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
color: #fff;
|
||||
|
||||
/* Rounded border */
|
||||
border-radius: 9999px;
|
||||
height: 3rem;
|
||||
width: 3rem;
|
||||
}
|
Reference in New Issue
Block a user