From 14e196579639f6b01e9f2ccbd71a72c925e819f8 Mon Sep 17 00:00:00 2001 From: Phuoc Nguyen Date: Wed, 21 Sep 2022 09:09:00 +0700 Subject: [PATCH] feat: Custom checkbox button --- .../patterns/custom-checkbox-button.njk | 9 + contents/custom-checkbox-button.md | 65 +++++++ contents/index.njk | 1 + pages/custom-checkbox-button/index.tsx | 179 ------------------ patterns/custom-checkbox-button/Cover.tsx | 79 -------- styles/blocks/_pattern.scss | 2 + styles/index.scss | 1 + styles/patterns/_custom-checkbox-button.scss | 38 ++++ 8 files changed, 116 insertions(+), 258 deletions(-) create mode 100644 contents/_includes/patterns/custom-checkbox-button.njk create mode 100644 contents/custom-checkbox-button.md delete mode 100644 pages/custom-checkbox-button/index.tsx delete mode 100644 patterns/custom-checkbox-button/Cover.tsx create mode 100644 styles/patterns/_custom-checkbox-button.scss diff --git a/contents/_includes/patterns/custom-checkbox-button.njk b/contents/_includes/patterns/custom-checkbox-button.njk new file mode 100644 index 0000000..3458b7b --- /dev/null +++ b/contents/_includes/patterns/custom-checkbox-button.njk @@ -0,0 +1,9 @@ +{% for i in range(0, 3) %} + +{% endfor %} \ No newline at end of file diff --git a/contents/custom-checkbox-button.md b/contents/custom-checkbox-button.md new file mode 100644 index 0000000..7548973 --- /dev/null +++ b/contents/custom-checkbox-button.md @@ -0,0 +1,65 @@ +--- +layout: layouts/post.njk +title: Custom checkbox button +description: Create a custom checkbox button with CSS flexbox +keywords: css checkbox, css flexbox +--- + +## HTML + +```html + +``` + +## CSS + +```css +.custom-checkbox-button { + /* Center the content horizontally */ + align-items: center; + display: inline-flex; + + /* Cursor */ + cursor: pointer; +} + +.custom-checkbox-button__input { + /* Hide it */ + display: none; +} + +.custom-checkbox-button__square { + border: 1px solid #d1d5db; + border-radius: 0.25rem; + + /* Spacing */ + margin-right: 0.5rem; + padding: 0.25rem; +} + +.custom-checkbox-button__checkbox { + background-color: transparent; + border-radius: 0.25rem; + height: 1rem; + width: 1rem; +} + +.custom-checkbox-button__checkbox--selected { + /* For selected checkbox */ + background-color: #3b82f6; +} +``` + +{% demo %}{% include "patterns/custom-checkbox-button.njk" %}{% enddemo %} diff --git a/contents/index.njk b/contents/index.njk index a1ad7db..6133ffd 100644 --- a/contents/index.njk +++ b/contents/index.njk @@ -89,6 +89,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 %}
diff --git a/pages/custom-checkbox-button/index.tsx b/pages/custom-checkbox-button/index.tsx deleted file mode 100644 index 85e8a83..0000000 --- a/pages/custom-checkbox-button/index.tsx +++ /dev/null @@ -1,179 +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 CheckboxProps { - isChecked: boolean; - value: string; -} - -const Details: React.FC<{}> = () => { - const Checkbox: React.FC = ({ isChecked, value, children }) => { - const [checked, setChecked] = React.useState(isChecked); - const click = () => setChecked((c) => !c); - - return ( -