mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-08 07:07:15 +02:00
feat: Radio switch
This commit is contained in:
8
contents/_includes/patterns/radio-switch.njk
Normal file
8
contents/_includes/patterns/radio-switch.njk
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<div class="radio-switch">
|
||||||
|
<label class="radio-switch__label">
|
||||||
|
<input type="radio" class="radio-switch__input" /> Monthly
|
||||||
|
</label>
|
||||||
|
<label class="radio-switch__label radio-switch__label--selected">
|
||||||
|
<input type="radio" class="radio-switch__input" /> Yearly
|
||||||
|
</label>
|
||||||
|
</div>
|
@@ -92,6 +92,7 @@ eleventyExcludeFromCollections: true
|
|||||||
{% pattern "Custom checkbox button" %}{% include "patterns/custom-checkbox-button.njk" %}{% endpattern %}
|
{% pattern "Custom checkbox button" %}{% include "patterns/custom-checkbox-button.njk" %}{% endpattern %}
|
||||||
{% pattern "Custom radio button" %}{% include "patterns/custom-radio-button.njk" %}{% endpattern %}
|
{% pattern "Custom radio button" %}{% include "patterns/custom-radio-button.njk" %}{% endpattern %}
|
||||||
{% pattern "Input addon" %}{% include "patterns/input-addon.njk" %}{% endpattern %}
|
{% pattern "Input addon" %}{% include "patterns/input-addon.njk" %}{% endpattern %}
|
||||||
|
{% pattern "Radio switch" %}{% include "patterns/radio-switch.njk" %}{% endpattern %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
52
contents/radio-switch.md
Normal file
52
contents/radio-switch.md
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
---
|
||||||
|
layout: layouts/post.njk
|
||||||
|
title: Radio switch
|
||||||
|
description: Create a radio switch with CSS flexbox
|
||||||
|
keywords: css flexbox, css radio switch, css switch
|
||||||
|
---
|
||||||
|
|
||||||
|
## HTML
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div class="radio-switch">
|
||||||
|
<!-- Radio container -->
|
||||||
|
<label class="radio-switch__label radio-switch__label--selected">
|
||||||
|
<input type="radio" class="radio-switch__input" />
|
||||||
|
|
||||||
|
<!-- Text -->
|
||||||
|
...
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<!-- Other radio item -->
|
||||||
|
...
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
## CSS
|
||||||
|
|
||||||
|
```css
|
||||||
|
.radio-switch {
|
||||||
|
background-color: #d1d5db;
|
||||||
|
border-radius: 9999px;
|
||||||
|
display: inline-flex;
|
||||||
|
padding: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-switch__label {
|
||||||
|
border-radius: 9999px;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-switch__label--selected {
|
||||||
|
/* For selected radio only */
|
||||||
|
background-color: #3b82f6;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-switch__input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
{% demo %}{% include "patterns/radio-switch.njk" %}{% enddemo %}
|
@@ -1,183 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import { Heading, 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 [isFirstChecked, setFirstChecked] = React.useState(false);
|
|
||||||
const toggle = () => setFirstChecked((c) => !c);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PatternLayout pattern={Pattern.RadioSwitch}>
|
|
||||||
<Head>
|
|
||||||
<meta name="description" content="Create a radio switch with CSS flexbox" />
|
|
||||||
<meta name="og:description" content="Create a radio switch with CSS flexbox" />
|
|
||||||
<meta name="twitter:description" content="Create a radio switch with CSS flexbox" />
|
|
||||||
<meta name="keywords" content="css flexbox, css radio switch, css switch" />
|
|
||||||
</Head>
|
|
||||||
<BrowserFrame
|
|
||||||
html={`
|
|
||||||
<!-- Container -->
|
|
||||||
<div class="container">
|
|
||||||
<!-- Radio container -->
|
|
||||||
<label class="container__label container__label--selected">
|
|
||||||
<input type="radio" class="container__input" />
|
|
||||||
|
|
||||||
<!-- Text -->
|
|
||||||
...
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<!-- Other radio item -->
|
|
||||||
...
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
css={`
|
|
||||||
.container {
|
|
||||||
background-color: rgba(0, 0, 0, 0.1);
|
|
||||||
border-radius: 9999px;
|
|
||||||
display: inline-flex;
|
|
||||||
padding: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__label {
|
|
||||||
border-radius: 9999px;
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 4px 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__label--selected {
|
|
||||||
/* For selected radio only */
|
|
||||||
background-color: #357edd;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__input {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.1)',
|
|
||||||
borderRadius: '9999px',
|
|
||||||
display: 'inline-flex',
|
|
||||||
padding: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
htmlFor="radio-switch-first"
|
|
||||||
style={{
|
|
||||||
backgroundColor: isFirstChecked ? '#357EDD' : '',
|
|
||||||
borderRadius: '9999px',
|
|
||||||
color: isFirstChecked ? '#FFF' : '',
|
|
||||||
cursor: 'pointer',
|
|
||||||
padding: '16px 8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
id="radio-switch-first"
|
|
||||||
type="radio"
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
checked={isFirstChecked}
|
|
||||||
onChange={toggle}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
backgroundColor: isFirstChecked ? '#FFF' : 'rgba(0, 0, 0, 0.2)',
|
|
||||||
borderRadius: '4px',
|
|
||||||
height: '8px',
|
|
||||||
width: '64px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
<label
|
|
||||||
htmlFor="radio-switch-second"
|
|
||||||
style={{
|
|
||||||
backgroundColor: isFirstChecked ? '' : '#357EDD',
|
|
||||||
borderRadius: '9999px',
|
|
||||||
color: isFirstChecked ? '' : '#FFF',
|
|
||||||
cursor: 'pointer',
|
|
||||||
padding: '16px 8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
id="radio-switch-second"
|
|
||||||
type="radio"
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
checked={!isFirstChecked}
|
|
||||||
onChange={toggle}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
backgroundColor: isFirstChecked ? 'rgba(0, 0, 0, 0.2)' : '#FFF',
|
|
||||||
borderRadius: '4px',
|
|
||||||
height: '8px',
|
|
||||||
width: '64px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</BrowserFrame>
|
|
||||||
<Spacer size="extraLarge" />
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<Heading level={2}>Use cases</Heading>
|
|
||||||
|
|
||||||
<div style={{ padding: '32px' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.1)',
|
|
||||||
borderRadius: '9999px',
|
|
||||||
display: 'inline-flex',
|
|
||||||
padding: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
backgroundColor: '#357EDD',
|
|
||||||
borderRadius: '9999px',
|
|
||||||
color: '#FFF',
|
|
||||||
cursor: 'pointer',
|
|
||||||
display: 'flex',
|
|
||||||
padding: '4px 8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input type="radio" style={{ display: 'none' }} />
|
|
||||||
Monthly
|
|
||||||
</label>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
borderRadius: '9999px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
display: 'flex',
|
|
||||||
padding: '4px 8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input type="radio" style={{ display: 'none' }} />
|
|
||||||
Yearly
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<Spacer size="extraLarge" />
|
|
||||||
<RelatedPatterns patterns={[Pattern.Switch]} />
|
|
||||||
</PatternLayout>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Details;
|
|
@@ -1,48 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
|
|
||||||
import Frame from '../../placeholders/Frame';
|
|
||||||
import Rectangle from '../../placeholders/Rectangle';
|
|
||||||
|
|
||||||
const Cover: React.FC<{}> = () => {
|
|
||||||
return (
|
|
||||||
<Frame>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
border: '1px solid #d1d5db',
|
|
||||||
borderRadius: '9999px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '4px',
|
|
||||||
width: '80%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ flex: 1, padding: '4px' }}>
|
|
||||||
<Rectangle />
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.1)',
|
|
||||||
borderRadius: '9999px',
|
|
||||||
flex: 1,
|
|
||||||
height: '100%',
|
|
||||||
padding: '4px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Frame>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Cover;
|
|
@@ -5,7 +5,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.pattern__link {
|
.pattern__link {
|
||||||
color: #6366f1;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
@@ -18,11 +17,13 @@
|
|||||||
|
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
|
||||||
|
color: #000;
|
||||||
height: 8rem;
|
height: 8rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
}
|
}
|
||||||
.pattern__title {
|
.pattern__title {
|
||||||
|
color: #6366f1;
|
||||||
font-size: 1.25rem;
|
font-size: 1.25rem;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
@@ -58,6 +58,7 @@
|
|||||||
@import './patterns/property-list';
|
@import './patterns/property-list';
|
||||||
@import './patterns/questions-and-answers';
|
@import './patterns/questions-and-answers';
|
||||||
@import './patterns/radial-progress-bar';
|
@import './patterns/radial-progress-bar';
|
||||||
|
@import './patterns/radio-switch';
|
||||||
@import './patterns/resizable-element';
|
@import './patterns/resizable-element';
|
||||||
@import './patterns/ribbon';
|
@import './patterns/ribbon';
|
||||||
@import './patterns/separator';
|
@import './patterns/separator';
|
||||||
|
22
styles/patterns/_radio-switch.scss
Normal file
22
styles/patterns/_radio-switch.scss
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
.radio-switch {
|
||||||
|
background-color: #d1d5db;
|
||||||
|
border-radius: 9999px;
|
||||||
|
display: inline-flex;
|
||||||
|
padding: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-switch__label {
|
||||||
|
border-radius: 9999px;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-switch__label--selected {
|
||||||
|
/* For selected radio only */
|
||||||
|
background-color: #3b82f6;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-switch__input {
|
||||||
|
display: none;
|
||||||
|
}
|
Reference in New Issue
Block a user