From 203c6f299c6e041ef8b00d366fedd07f300fdad9 Mon Sep 17 00:00:00 2001 From: Phuoc Nguyen Date: Wed, 21 Sep 2022 09:16:07 +0700 Subject: [PATCH] feat: Custom radio button --- .../patterns/custom-radio-button.njk | 9 + contents/custom-radio-button.md | 69 +++++++ contents/index.njk | 1 + pages/custom-radio-button/index.tsx | 182 ------------------ patterns/custom-radio-button/Cover.tsx | 75 -------- styles/index.scss | 1 + styles/patterns/_custom-radio-button.scss | 42 ++++ 7 files changed, 122 insertions(+), 257 deletions(-) create mode 100644 contents/_includes/patterns/custom-radio-button.njk create mode 100644 contents/custom-radio-button.md delete mode 100644 pages/custom-radio-button/index.tsx delete mode 100644 patterns/custom-radio-button/Cover.tsx create mode 100644 styles/patterns/_custom-radio-button.scss diff --git a/contents/_includes/patterns/custom-radio-button.njk b/contents/_includes/patterns/custom-radio-button.njk new file mode 100644 index 0000000..dc4010d --- /dev/null +++ b/contents/_includes/patterns/custom-radio-button.njk @@ -0,0 +1,9 @@ +{% for i in range(0, 3) %} + +{% endfor %} \ No newline at end of file diff --git a/contents/custom-radio-button.md b/contents/custom-radio-button.md new file mode 100644 index 0000000..34a378e --- /dev/null +++ b/contents/custom-radio-button.md @@ -0,0 +1,69 @@ +--- +layout: layouts/post.njk +title: Custom radio button +description: Create a custom radio button with CSS flexbox +keywords: css flexbox, css radio +--- + +## HTML + +```html + +``` + +## CSS + +```css +.custom-radio-button { + /* Center the content horizontally */ + align-items: center; + display: inline-flex; + + /* Cursor */ + cursor: pointer; +} + +.custom-radio-button__input { + /* Hide it */ + display: none; +} + +.custom-radio-button__circle { + /* Rounded border */ + border: 1px solid #d1d5db; + border-radius: 9999px; + + /* Spacing */ + margin-right: 0.5rem; + padding: 0.25rem; +} + +.custom-radio-button__radio { + /* Rounded border */ + border-radius: 9999px; + height: 1rem; + width: 1rem; + + /* For not selected radio */ + background-color: transparent; +} + +.custom-radio-button__radio--selected { + /* For selected radio */ + background-color: #3b82f6; +} +``` + +{% demo %}{% include "patterns/custom-radio-button.njk" %}{% enddemo %} diff --git a/contents/index.njk b/contents/index.njk index 6133ffd..49e627b 100644 --- a/contents/index.njk +++ b/contents/index.njk @@ -90,6 +90,7 @@ eleventyExcludeFromCollections: true {% pattern "Button with icon" %}{% include "patterns/button-with-icon.njk" %}{% endpattern %} {% pattern "Chip" %}{% include "patterns/chip.njk" %}{% endpattern %} {% pattern "Custom checkbox button" %}{% include "patterns/custom-checkbox-button.njk" %}{% endpattern %} + {% pattern "Custom radio button" %}{% include "patterns/custom-radio-button.njk" %}{% endpattern %} diff --git a/pages/custom-radio-button/index.tsx b/pages/custom-radio-button/index.tsx deleted file mode 100644 index 3749130..0000000 --- a/pages/custom-radio-button/index.tsx +++ /dev/null @@ -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'; -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 ( -