mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-08 07:07:15 +02:00
feat: Stepper input
This commit is contained in:
7
contents/_includes/patterns/stepper-input.njk
Normal file
7
contents/_includes/patterns/stepper-input.njk
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<div class="stepper-input">
|
||||||
|
<button class="stepper-input__button">-</button>
|
||||||
|
<div class="stepper-input__content">
|
||||||
|
<input type="text" class="stepper-input__input" />
|
||||||
|
</div>
|
||||||
|
<button class="stepper-input__button">+</button>
|
||||||
|
</div>
|
@@ -97,6 +97,7 @@ eleventyExcludeFromCollections: true
|
|||||||
{% 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 %}
|
{% pattern "Spin button" %}{% include "patterns/spin-button.njk" %}{% endpattern %}
|
||||||
|
{% pattern "Stepper input" %}{% include "patterns/stepper-input.njk" %}{% endpattern %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
67
contents/stepper-input.md
Normal file
67
contents/stepper-input.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
---
|
||||||
|
layout: layouts/post.njk
|
||||||
|
title: Stepper input
|
||||||
|
description: Create a stepper input with CSS flexbox
|
||||||
|
keywords: css flexbox, css stepper input
|
||||||
|
---
|
||||||
|
|
||||||
|
## HTML
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div class="stepper-input">
|
||||||
|
<!-- Minus button -->
|
||||||
|
<button class="stepper-input__button">-</button>
|
||||||
|
|
||||||
|
<!-- Input container -->
|
||||||
|
<div class="stepper-input__content">
|
||||||
|
<input type="text" class="stepper-input__input" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Plus button -->
|
||||||
|
<button class="stepper-input__button">+</button>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
## CSS
|
||||||
|
|
||||||
|
```css
|
||||||
|
.stepper-input {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
/* Border */
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
height: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stepper-input__button {
|
||||||
|
/* Reset */
|
||||||
|
background: #d1d5db;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
/* Center the content */
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
width: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stepper-input__content {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stepper-input__input {
|
||||||
|
/* Reset */
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
/* Take full size of its container */
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
{% demo %}{% include "patterns/stepper-input.njk" %}{% enddemo %}
|
@@ -1,152 +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(0);
|
|
||||||
const decrease = () => setValue(value - 1);
|
|
||||||
const increase = () => setValue(value + 1);
|
|
||||||
const change = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const v = parseInt(e.target.value, 10);
|
|
||||||
const newValue = isNaN(v) ? 0 : v;
|
|
||||||
setValue(newValue);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PatternLayout pattern={Pattern.StepperInput}>
|
|
||||||
<Head>
|
|
||||||
<meta name="description" content="Create a stepper input with CSS flexbox" />
|
|
||||||
<meta name="og:description" content="Create a stepper input with CSS flexbox" />
|
|
||||||
<meta name="twitter:description" content="Create a stepper input with CSS flexbox" />
|
|
||||||
<meta name="keywords" content="css flexbox, css stepper input" />
|
|
||||||
</Head>
|
|
||||||
<BrowserFrame
|
|
||||||
html={`
|
|
||||||
<div class="stepper">
|
|
||||||
<!-- Minus button -->
|
|
||||||
<button class="stepper__button">-</button>
|
|
||||||
|
|
||||||
<!-- Input container -->
|
|
||||||
<div class="stepper__content">
|
|
||||||
<input type="text" class="stepper__input" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Plus button -->
|
|
||||||
<button class="stepper__button">+</button>
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
css={`
|
|
||||||
.stepper {
|
|
||||||
display: flex;
|
|
||||||
|
|
||||||
/* Border */
|
|
||||||
border: 1px solid #d1d5db;
|
|
||||||
|
|
||||||
/* Size */
|
|
||||||
height: 32px;
|
|
||||||
width: 128px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stepper__button {
|
|
||||||
/* Center the content */
|
|
||||||
align-items: center;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
|
|
||||||
/* Size */
|
|
||||||
width: 32px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stepper__content {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stepper__input {
|
|
||||||
/* Take full size of its container */
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
border: '1px solid #d1d5db',
|
|
||||||
borderRadius: '8px',
|
|
||||||
display: 'flex',
|
|
||||||
height: '32px',
|
|
||||||
width: '128px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.05)',
|
|
||||||
borderColor: 'transparent',
|
|
||||||
cursor: 'pointer',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
width: '32px',
|
|
||||||
}}
|
|
||||||
onClick={decrease}
|
|
||||||
>
|
|
||||||
-
|
|
||||||
</button>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
borderLeft: '1px solid #d1d5db',
|
|
||||||
borderRight: '1px solid #d1d5db',
|
|
||||||
flex: 1,
|
|
||||||
height: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
style={{
|
|
||||||
borderColor: 'transparent',
|
|
||||||
height: '100%',
|
|
||||||
padding: '8px',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
value={value}
|
|
||||||
onChange={change}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.05)',
|
|
||||||
borderColor: 'transparent',
|
|
||||||
cursor: 'pointer',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
width: '32px',
|
|
||||||
}}
|
|
||||||
onClick={increase}
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</BrowserFrame>
|
|
||||||
<Spacer size="extraLarge" />
|
|
||||||
<RelatedPatterns patterns={[Pattern.SpinButton, Pattern.Voting]} />
|
|
||||||
</PatternLayout>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Details;
|
|
@@ -1,55 +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: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
border: '1px solid #d1d5db',
|
|
||||||
borderRadius: '4px',
|
|
||||||
display: 'flex',
|
|
||||||
height: '24px',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
borderRight: '1px solid #d1d5db',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
width: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
-
|
|
||||||
</div>
|
|
||||||
<div style={{ flex: 1 }} />
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
borderLeft: '1px solid #d1d5db',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
width: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Frame>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Cover;
|
|
@@ -70,6 +70,7 @@
|
|||||||
@import './patterns/stamp-border';
|
@import './patterns/stamp-border';
|
||||||
@import './patterns/statistic';
|
@import './patterns/statistic';
|
||||||
@import './patterns/status-light';
|
@import './patterns/status-light';
|
||||||
|
@import './patterns/stepper-input';
|
||||||
@import './patterns/sticky-table-column';
|
@import './patterns/sticky-table-column';
|
||||||
@import './patterns/sticky-table-headers';
|
@import './patterns/sticky-table-headers';
|
||||||
@import './patterns/teardrop';
|
@import './patterns/teardrop';
|
||||||
|
38
styles/patterns/_stepper-input.scss
Normal file
38
styles/patterns/_stepper-input.scss
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
.stepper-input {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
/* Border */
|
||||||
|
border: 1px solid #d1d5db;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
height: 2rem;
|
||||||
|
width: 8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stepper-input__button {
|
||||||
|
/* Reset */
|
||||||
|
background: #d1d5db;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
/* Center the content */
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
width: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stepper-input__content {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stepper-input__input {
|
||||||
|
/* Reset */
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
/* Take full size of its container */
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
Reference in New Issue
Block a user