mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-05 05:37:29 +02:00
feat: Spin button
This commit is contained in:
11
contents/_includes/patterns/spin-button.njk
Normal file
11
contents/_includes/patterns/spin-button.njk
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<div class="spin-button">
|
||||||
|
<input type="text" class="spin-button__input" />
|
||||||
|
<div class="spin-button__buttons">
|
||||||
|
<button class="spin-button__button">
|
||||||
|
{% triangle "t" %}
|
||||||
|
</button>
|
||||||
|
<button class="spin-button__button">
|
||||||
|
{% triangle "b" %}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
@@ -96,6 +96,7 @@ eleventyExcludeFromCollections: true
|
|||||||
{% pattern "Rating" %}{% include "patterns/rating.njk" %}{% endpattern %}
|
{% pattern "Rating" %}{% include "patterns/rating.njk" %}{% endpattern %}
|
||||||
{% pattern "Search box" %}{% include "patterns/search-box.njk" %}{% endpattern %}
|
{% pattern "Search box" %}{% include "patterns/search-box.njk" %}{% endpattern %}
|
||||||
{% pattern "Slider" %}{% include "patterns/slider.njk" %}{% endpattern %}
|
{% pattern "Slider" %}{% include "patterns/slider.njk" %}{% endpattern %}
|
||||||
|
{% pattern "Spin button" %}{% include "patterns/spin-button.njk" %}{% endpattern %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
71
contents/spin-button.md
Normal file
71
contents/spin-button.md
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
---
|
||||||
|
layout: layouts/post.njk
|
||||||
|
title: Spin button
|
||||||
|
description: Create a spin button with CSS flexbox
|
||||||
|
keywords: css flexbox, css spin button
|
||||||
|
---
|
||||||
|
|
||||||
|
## HTML
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div class="spin-button">
|
||||||
|
<!-- Input -->
|
||||||
|
<input type="text" class="spin-button__input" />
|
||||||
|
|
||||||
|
<!-- Buttons spin-button -->
|
||||||
|
<div class="spin-button__buttons">
|
||||||
|
<!-- Up button -->
|
||||||
|
<button class="spin-button__button">
|
||||||
|
...
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Down button -->
|
||||||
|
<button class="spin-button__button">
|
||||||
|
...
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
## CSS
|
||||||
|
|
||||||
|
```css
|
||||||
|
.spin-button {
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
display: flex;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spin-button__input {
|
||||||
|
border-color: transparent;
|
||||||
|
padding: 0.5rem;
|
||||||
|
|
||||||
|
/* Demo */
|
||||||
|
width: 8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spin-button__buttons {
|
||||||
|
/* Content is centered vertically */
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
/* Left border */
|
||||||
|
border-left: 1px solid #d1d5db;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spin-button__button {
|
||||||
|
/* Reset */
|
||||||
|
background: #fff;
|
||||||
|
border-color: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
/* Make buttons have the same height */
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use the [triangle buttons](/triangle-buttons/) to create the up and down buttons:
|
||||||
|
|
||||||
|
{% demo %}{% include "patterns/spin-button.njk" %}{% enddemo %}
|
@@ -1,139 +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';
|
|
||||||
import Triangle from '../../placeholders/Triangle';
|
|
||||||
|
|
||||||
const Details: React.FC<{}> = () => {
|
|
||||||
const [value, setValue] = React.useState(0);
|
|
||||||
const decrease = () => setValue(value - 1);
|
|
||||||
const increase = () => setValue(value + 1);
|
|
||||||
const change = (e: React.ChangeEvent<HTMLInputElement>) => setValue(parseInt(e.target.value, 10));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PatternLayout pattern={Pattern.SpinButton}>
|
|
||||||
<Head>
|
|
||||||
<meta name="description" content="Create a spin button with CSS flexbox" />
|
|
||||||
<meta name="og:description" content="Create a spin button with CSS flexbox" />
|
|
||||||
<meta name="twitter:description" content="Create a spin button with CSS flexbox" />
|
|
||||||
<meta name="keywords" content="css flexbox, css spin button" />
|
|
||||||
</Head>
|
|
||||||
<BrowserFrame
|
|
||||||
html={`
|
|
||||||
<div class="container">
|
|
||||||
<!-- Input -->
|
|
||||||
<input type="text" class="container__input" />
|
|
||||||
|
|
||||||
<!-- Buttons container -->
|
|
||||||
<div class="container__buttons">
|
|
||||||
<!-- Up button -->
|
|
||||||
<button class="container__button">
|
|
||||||
...
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<!-- Down button -->
|
|
||||||
<button class="container__button">
|
|
||||||
...
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
css={`
|
|
||||||
.container {
|
|
||||||
border: 1px solid #d1d5db;
|
|
||||||
border-radius: 2px;
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__input {
|
|
||||||
border-color: transparent;
|
|
||||||
margin-right: 4px;
|
|
||||||
padding: 4px;
|
|
||||||
width: 100px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__buttons {
|
|
||||||
/* Content is centered vertically */
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__button {
|
|
||||||
border-color: transparent;
|
|
||||||
/* Make buttons have the same height */
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
border: '1px solid #d1d5db',
|
|
||||||
borderRadius: '2px',
|
|
||||||
display: 'flex',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
style={{
|
|
||||||
borderColor: 'transparent',
|
|
||||||
marginRight: '4px',
|
|
||||||
padding: '4px',
|
|
||||||
width: '100px',
|
|
||||||
}}
|
|
||||||
value={value}
|
|
||||||
onChange={change}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
style={{
|
|
||||||
borderColor: 'transparent',
|
|
||||||
cursor: 'pointer',
|
|
||||||
flex: 1,
|
|
||||||
padding: '4px 4px 2px 4px',
|
|
||||||
}}
|
|
||||||
onClick={increase}
|
|
||||||
>
|
|
||||||
<Triangle size={6} corner="t" />
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
style={{
|
|
||||||
borderColor: 'transparent',
|
|
||||||
cursor: 'pointer',
|
|
||||||
flex: 1,
|
|
||||||
padding: '2px 4px 4px 4px',
|
|
||||||
}}
|
|
||||||
onClick={decrease}
|
|
||||||
>
|
|
||||||
<Triangle size={6} corner="b" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</BrowserFrame>
|
|
||||||
<Spacer size="extraLarge" />
|
|
||||||
<RelatedPatterns patterns={[Pattern.StepperInput, Pattern.Voting]} />
|
|
||||||
</PatternLayout>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Details;
|
|
@@ -1,48 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
|
|
||||||
import Frame from '../../placeholders/Frame';
|
|
||||||
import Triangle from '../../placeholders/Triangle';
|
|
||||||
|
|
||||||
const Cover: React.FC<{}> = () => {
|
|
||||||
return (
|
|
||||||
<Frame>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
border: '1px solid #d1d5db',
|
|
||||||
borderRadius: '4px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'flex-end',
|
|
||||||
width: '80%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ flex: 1, padding: '4px 4px 2px 4px' }}>
|
|
||||||
<Triangle size={6} corner="t" />
|
|
||||||
</div>
|
|
||||||
<div style={{ flex: 1, padding: '2px 4px 4px 4px' }}>
|
|
||||||
<Triangle size={6} corner="b" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Frame>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Cover;
|
|
@@ -65,6 +65,7 @@
|
|||||||
@import './patterns/search-box';
|
@import './patterns/search-box';
|
||||||
@import './patterns/separator';
|
@import './patterns/separator';
|
||||||
@import './patterns/slider';
|
@import './patterns/slider';
|
||||||
|
@import './patterns/spin-button';
|
||||||
@import './patterns/stacked-cards';
|
@import './patterns/stacked-cards';
|
||||||
@import './patterns/stamp-border';
|
@import './patterns/stamp-border';
|
||||||
@import './patterns/statistic';
|
@import './patterns/statistic';
|
||||||
|
34
styles/patterns/_spin-button.scss
Normal file
34
styles/patterns/_spin-button.scss
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
.spin-button {
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
display: flex;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spin-button__input {
|
||||||
|
border-color: transparent;
|
||||||
|
padding: 0.5rem;
|
||||||
|
|
||||||
|
/* Demo */
|
||||||
|
width: 8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spin-button__buttons {
|
||||||
|
/* Content is centered vertically */
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
/* Left border */
|
||||||
|
border-left: 1px solid #d1d5db;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spin-button__button {
|
||||||
|
/* Reset */
|
||||||
|
background: #fff;
|
||||||
|
border-color: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
/* Make buttons have the same height */
|
||||||
|
flex: 1;
|
||||||
|
}
|
Reference in New Issue
Block a user