mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-13 17:44:19 +02:00
feat: Voting control
This commit is contained in:
9
contents/_includes/patterns/voting.njk
Normal file
9
contents/_includes/patterns/voting.njk
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<div class="voting">
|
||||||
|
<button class="voting__button">
|
||||||
|
<div class="voting__triangle voting__triangle--up"></div>
|
||||||
|
</button>
|
||||||
|
<div class="voting__number">999</div>
|
||||||
|
<button class="voting__button">
|
||||||
|
<div class="voting__triangle voting__triangle--down"></div>
|
||||||
|
</button>
|
||||||
|
</div>
|
@@ -169,6 +169,12 @@ eleventyExcludeFromCollections: true
|
|||||||
<div class="pattern__title">Watermark</div>
|
<div class="pattern__title">Watermark</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="pattern__item">
|
||||||
|
<a class="pattern__link" href="/voting/">
|
||||||
|
<div class="pattern__cover">{% include "patterns/voting.njk" %}</div>
|
||||||
|
<div class="pattern__title">Voting</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
90
contents/voting.md
Normal file
90
contents/voting.md
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
---
|
||||||
|
layout: layouts/post.njk
|
||||||
|
title: Voting
|
||||||
|
description: Create a voting control with CSS flexbox
|
||||||
|
keywords: css flexbox, css triangle buttons, css voting control
|
||||||
|
---
|
||||||
|
|
||||||
|
## HTML
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div class="voting">
|
||||||
|
<!-- Up button -->
|
||||||
|
<button class="voting__button">
|
||||||
|
<div class="voting__triangle voting__triangle--up"></div>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Number -->
|
||||||
|
<div class="voting__number">...</div>
|
||||||
|
|
||||||
|
<!-- Down button -->
|
||||||
|
<button class="voting__button">
|
||||||
|
<div class="voting__triangle voting__triangle--down"></div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
## CSS
|
||||||
|
|
||||||
|
```css
|
||||||
|
.voting {
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.3);
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__button {
|
||||||
|
/* Reset */
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
/* Center the content */
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
height: 1rem;
|
||||||
|
|
||||||
|
/* Position the triangle */
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__triangle {
|
||||||
|
border-style: solid;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
height: 0;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__triangle--up {
|
||||||
|
border-color: transparent transparent rgba(0, 0, 0, 0.3);
|
||||||
|
border-width: 0 0.5rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__triangle--down {
|
||||||
|
border-color: rgba(0, 0, 0, 0.3) transparent transparent;
|
||||||
|
border-width: 0.5rem 0.5rem 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__number {
|
||||||
|
/* Take the available height */
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
/* Center the number */
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
/* Spacing */
|
||||||
|
padding: 0.25rem;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
{% demo %}
|
||||||
|
{% include "patterns/voting.njk" %}
|
||||||
|
{% enddemo %}
|
@@ -1,182 +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<{}> = () => {
|
|
||||||
const [value, setValue] = React.useState(900);
|
|
||||||
const decrease = () => setValue(value - 1);
|
|
||||||
const increase = () => setValue(value + 1);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PatternLayout pattern={Pattern.Voting}>
|
|
||||||
<Head>
|
|
||||||
<meta name="description" content="Create a voting control with CSS flexbox" />
|
|
||||||
<meta name="og:description" content="Create a voting control with CSS flexbox" />
|
|
||||||
<meta name="twitter:description" content="Create a voting control with CSS flexbox" />
|
|
||||||
<meta name="keywords" content="css flexbox, css triangle buttons, css voting control" />
|
|
||||||
</Head>
|
|
||||||
<BrowserFrame
|
|
||||||
html={`
|
|
||||||
<div class="voting">
|
|
||||||
<!-- Up button -->
|
|
||||||
<button class="voting__button">
|
|
||||||
<div class="voting__triangle voting__triangle--up"></div>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<!-- Number -->
|
|
||||||
<div class="voting__number">
|
|
||||||
...
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Down button -->
|
|
||||||
<button class="voting__button">
|
|
||||||
<div class="voting__triangle voting__triangle--down"></div>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
css={`
|
|
||||||
.voting {
|
|
||||||
border: 1px solid rgba(0, 0, 0, 0.3);
|
|
||||||
border-radius: 0.25rem;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
height: 8rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voting__button {
|
|
||||||
/* Reset */
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
/* Size */
|
|
||||||
height: 1rem;
|
|
||||||
|
|
||||||
/* Position the triangle */
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voting__triangle {
|
|
||||||
border-style: solid;
|
|
||||||
|
|
||||||
/* Size */
|
|
||||||
height: 0;
|
|
||||||
width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voting__triangle--up {
|
|
||||||
border-color: transparent transparent rgba(0, 0, 0, 0.3);
|
|
||||||
border-width: 0 0.5rem 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voting__triangle--down {
|
|
||||||
border-color: rgba(0, 0, 0, 0.3) transparent transparent;
|
|
||||||
border-width: 0.5rem 0.5rem 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voting__number {
|
|
||||||
/* Take the available height */
|
|
||||||
flex: 1;
|
|
||||||
|
|
||||||
/* Center the number */
|
|
||||||
align-items: center;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
|
|
||||||
/* Spacing */
|
|
||||||
padding: 0.25rem;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '0.5rem',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
|
||||||
borderRadius: '0.25rem',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '8rem',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
style={{
|
|
||||||
background: 'none',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
height: '1rem',
|
|
||||||
position: 'relative',
|
|
||||||
}}
|
|
||||||
onClick={increase}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
borderColor: 'transparent transparent rgba(0, 0, 0, 0.3) transparent',
|
|
||||||
borderStyle: 'solid',
|
|
||||||
borderWidth: '0 0.5rem 0.5rem 0.5rem',
|
|
||||||
height: 0,
|
|
||||||
left: '50%',
|
|
||||||
position: 'absolute',
|
|
||||||
top: '50%',
|
|
||||||
transform: 'translate(-50%, -50%)',
|
|
||||||
width: 0,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flex: 1,
|
|
||||||
padding: '0.25rem',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{value}
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
style={{
|
|
||||||
background: 'none',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
height: '1rem',
|
|
||||||
position: 'relative',
|
|
||||||
}}
|
|
||||||
onClick={decrease}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
borderColor: 'rgba(0, 0, 0, 0.3) transparent transparent transparent',
|
|
||||||
borderStyle: 'solid',
|
|
||||||
borderWidth: '0.5rem 0.5rem 0 0.5rem',
|
|
||||||
height: 0,
|
|
||||||
left: '50%',
|
|
||||||
position: 'absolute',
|
|
||||||
top: '50%',
|
|
||||||
transform: 'translate(-50%, -50%)',
|
|
||||||
width: 0,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</BrowserFrame>
|
|
||||||
<Spacer size="extraLarge" />
|
|
||||||
<RelatedPatterns patterns={[Pattern.SpinButton, Pattern.StepperInput, Pattern.TriangleButtons]} />
|
|
||||||
</PatternLayout>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Details;
|
|
@@ -1,83 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
|
|
||||||
import Frame from '../../placeholders/Frame';
|
|
||||||
|
|
||||||
const Cover: React.FC<{}> = () => {
|
|
||||||
return (
|
|
||||||
<Frame>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '0.5rem',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
|
||||||
borderRadius: '0.25rem',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '1rem',
|
|
||||||
position: 'relative',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
borderColor: 'transparent transparent rgba(0, 0, 0, 0.3) transparent',
|
|
||||||
borderStyle: 'solid',
|
|
||||||
borderWidth: '0 0.5rem 0.5rem 0.5rem',
|
|
||||||
height: 0,
|
|
||||||
left: '50%',
|
|
||||||
position: 'absolute',
|
|
||||||
top: '50%',
|
|
||||||
transform: 'translate(-50%, -50%)',
|
|
||||||
width: 0,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flex: 1,
|
|
||||||
padding: '0.25rem',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
99
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '1rem',
|
|
||||||
position: 'relative',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
borderColor: 'rgba(0, 0, 0, 0.3) transparent transparent transparent',
|
|
||||||
borderStyle: 'solid',
|
|
||||||
borderWidth: '0.5rem 0.5rem 0 0.5rem',
|
|
||||||
height: 0,
|
|
||||||
left: '50%',
|
|
||||||
position: 'absolute',
|
|
||||||
top: '50%',
|
|
||||||
transform: 'translate(-50%, -50%)',
|
|
||||||
width: 0,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Frame>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Cover;
|
|
@@ -36,6 +36,7 @@
|
|||||||
@import './patterns/fixed-at-side';
|
@import './patterns/fixed-at-side';
|
||||||
@import './patterns/full-background';
|
@import './patterns/full-background';
|
||||||
@import './patterns/initial-avatar';
|
@import './patterns/initial-avatar';
|
||||||
|
@import './patterns/voting';
|
||||||
@import './patterns/watermark';
|
@import './patterns/watermark';
|
||||||
|
|
||||||
// Placeholders
|
// Placeholders
|
||||||
|
56
styles/patterns/_voting.scss
Normal file
56
styles/patterns/_voting.scss
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
.voting {
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.3);
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__button {
|
||||||
|
/* Reset */
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
/* Center the content */
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
height: 1rem;
|
||||||
|
|
||||||
|
/* Position the triangle */
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__triangle {
|
||||||
|
border-style: solid;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
height: 0;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__triangle--up {
|
||||||
|
border-color: transparent transparent rgba(0, 0, 0, 0.3);
|
||||||
|
border-width: 0 0.5rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__triangle--down {
|
||||||
|
border-color: rgba(0, 0, 0, 0.3) transparent transparent;
|
||||||
|
border-width: 0.5rem 0.5rem 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voting__number {
|
||||||
|
/* Take the available height */
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
/* Center the number */
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
/* Spacing */
|
||||||
|
padding: 0.25rem;
|
||||||
|
}
|
Reference in New Issue
Block a user