diff --git a/contents/_includes/patterns/radio-button-group.njk b/contents/_includes/patterns/radio-button-group.njk new file mode 100644 index 0000000..2d02215 --- /dev/null +++ b/contents/_includes/patterns/radio-button-group.njk @@ -0,0 +1,14 @@ +
+ + + + +
\ No newline at end of file diff --git a/contents/index.njk b/contents/index.njk index 6ef6110..bf31725 100644 --- a/contents/index.njk +++ b/contents/index.njk @@ -93,6 +93,7 @@ eleventyExcludeFromCollections: true {% pattern "Custom radio button" %}{% include "patterns/custom-radio-button.njk" %}{% endpattern %} {% pattern "Floating label" %}{% include "patterns/floating-label.njk" %}{% endpattern %} {% pattern "Input addon" %}{% include "patterns/input-addon.njk" %}{% endpattern %} + {% pattern "Radio button group" %}{% include "patterns/radio-button-group.njk" %}{% endpattern %} {% pattern "Radio switch" %}{% include "patterns/radio-switch.njk" %}{% endpattern %} {% pattern "Rating" %}{% include "patterns/rating.njk" %}{% endpattern %} {% pattern "Search box" %}{% include "patterns/search-box.njk" %}{% endpattern %} diff --git a/contents/radio-button-group.md b/contents/radio-button-group.md new file mode 100644 index 0000000..b94ff6d --- /dev/null +++ b/contents/radio-button-group.md @@ -0,0 +1,76 @@ +--- +layout: layouts/post.njk +title: Radio button group +description: Create a radio button group with CSS flexbox +keywords: css flexbox, css radio button +--- + +## HTML + +```html +
+ + + + + + + + ... +
+``` + +## CSS + +```css +.radio-button-group { + display: flex; + + /* Border */ + border: 1px solid #d1d5db; + border-radius: 0.25rem; + height: 2rem; +} + +.radio-button-group__label { + /* Center the content */ + align-items: center; + display: inline-flex; + + border-right: 1px solid #d1d5db; + padding: 0.5rem; + + /* For not selected radio */ + background-color: transparent; + color: #ccc; +} + +.radio-button-group__label:last-child { + /* Remove the right border from the last label */ + border-right-color: transparent; +} + +.radio-button-group__label--selected { + /* For selected radio */ + background-color: #3b82f6; + color: #fff; + + margin-top: -1px; + margin-bottom: -1px; +} + +.radio-button-group__input { + /* Hide it */ + display: none; +} +``` + +{% demo %}{% include "patterns/radio-button-group.njk" %}{% enddemo %} diff --git a/pages/radio-button-group/index.tsx b/pages/radio-button-group/index.tsx deleted file mode 100644 index bd97835..0000000 --- a/pages/radio-button-group/index.tsx +++ /dev/null @@ -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'; -import Rectangle from '../../placeholders/Rectangle'; - -interface RadioProps { - value: string; -} - -const Details: React.FC<{}> = () => { - const [selectedValue, setSelectedValue] = React.useState('1'); - - const Radio: React.FC = ({ value, children }) => { - const click = () => setSelectedValue(value); - - return ( - - ); - }; - - return ( - - - - - - - - - - - - - ... - -`} - css={` - .container { - display: flex; - - /* Border */ - border: 1px solid #d1d5db; - border-radius: 4px; - height: 32px; - } - - .container__label { - /* Center the content */ - align-items: center; - display: inline-flex; - - border-right: 1px solid #d1d5db; - padding: 8px; - - /* For not selected radio */ - background-color: transparent; - color: #ccc; - } - - .container__label:last-child { - /* Remove the right border from the last label */ - border-right-color: transparent; - } - - .container__label--selected { - /* For selected radio */ - background-color: #00449e; - color: #fff; - } - - .container__input { - /* Hide it */ - display: none; - } - `} - > -
-
- -
- -
-
- -
- -
-
- -
- -
-
-
-
-
- - -
- ); -}; - -export default Details; diff --git a/patterns/radio-button-group/Cover.tsx b/patterns/radio-button-group/Cover.tsx deleted file mode 100644 index c0efda9..0000000 --- a/patterns/radio-button-group/Cover.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import * as React from 'react'; - -import Frame from '../../placeholders/Frame'; - -const Cover: React.FC<{}> = () => { - return ( - -
-
-
-
-
-
-
- - ); -}; - -export default Cover; diff --git a/styles/index.scss b/styles/index.scss index c3e76db..702df5c 100644 --- a/styles/index.scss +++ b/styles/index.scss @@ -59,6 +59,7 @@ @import './patterns/property-list'; @import './patterns/questions-and-answers'; @import './patterns/radial-progress-bar'; +@import './patterns/radio-button-group'; @import './patterns/radio-switch'; @import './patterns/rating'; @import './patterns/resizable-element'; diff --git a/styles/patterns/_radio-button-group.scss b/styles/patterns/_radio-button-group.scss new file mode 100644 index 0000000..f5fcf14 --- /dev/null +++ b/styles/patterns/_radio-button-group.scss @@ -0,0 +1,40 @@ +.radio-button-group { + display: flex; + + /* Border */ + border: 1px solid #d1d5db; + border-radius: 0.25rem; + height: 2rem; +} + +.radio-button-group__label { + /* Center the content */ + align-items: center; + display: inline-flex; + + border-right: 1px solid #d1d5db; + padding: 0.5rem; + + /* For not selected radio */ + background-color: transparent; + color: #ccc; +} + +.radio-button-group__label:last-child { + /* Remove the right border from the last label */ + border-right-color: transparent; +} + +.radio-button-group__label--selected { + /* For selected radio */ + background-color: #3b82f6; + color: #fff; + + margin-top: -1px; + margin-bottom: -1px; +} + +.radio-button-group__input { + /* Hide it */ + display: none; +} \ No newline at end of file