From ade16712fac66b958dc5b51215754eb6796cdb9e Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Sat, 20 Jan 2024 23:41:25 -0600 Subject: [PATCH] Checkbox component --- src/components/CheckBox.module.scss | 51 +++++++++++++++++++++++ src/components/CheckBox.tsx | 30 ++++++++++++++ src/components/CheckList.module.scss | 13 +++--- src/components/CheckList.tsx | 62 ++++++++++++++-------------- src/index.css | 34 +-------------- 5 files changed, 120 insertions(+), 70 deletions(-) create mode 100644 src/components/CheckBox.module.scss create mode 100644 src/components/CheckBox.tsx diff --git a/src/components/CheckBox.module.scss b/src/components/CheckBox.module.scss new file mode 100644 index 0000000..7a965dc --- /dev/null +++ b/src/components/CheckBox.module.scss @@ -0,0 +1,51 @@ +.CheckBox { + --cb-color-border: #888; + --cb-color-checked: #008; + --cb-color-unchecked: #fff; + --cb-size: 1.2em; + --cb-check-size: 1em; + --cb-gap: 0.4em; + + display: flex; + flex-direction: row; + align-items: center; + + input { + appearance: none; + -webkit-appearance: none; + margin: 0; + } + + > span:first-of-type { + display: flex; + align-items: center; + justify-content: center; + background-color: var(--cb-color-unchecked); + border: 0.2em solid var(--cb-color-border); + border-radius: 0.2em; + box-sizing: border-box; + width: var(--cb-size); + height: var(--cb-size); + + &::before { + content: ''; + display: block; + /* https://bennettfeely.com/clippy/ */ + clip-path: polygon(11% 34%, 46% 68%, 88% 1%, 100% 8%, 50% 91%, 0 48%); + width: var(--cb-check-size); + height: var(--cb-check-size); + transform: scale(0); + } + } + > span:last-of-type { + margin-left: var(--cb-gap); + } + + input:checked + span { + background-color: var(--cb-color-checked); + } + input:checked + span::before { + transform: scale(1); + background-color: var(--cb-color-unchecked); + } +} diff --git a/src/components/CheckBox.tsx b/src/components/CheckBox.tsx new file mode 100644 index 0000000..9726915 --- /dev/null +++ b/src/components/CheckBox.tsx @@ -0,0 +1,30 @@ +import type { JSX } from 'solid-js' +import styles from './CheckBox.module.scss' + +export interface CheckBoxProps { + class?: string + isChecked: boolean + children?: JSX.Element + onChange: (checked: boolean) => void +} + +export function CheckBox({ + class: cl, + isChecked, + children, + onChange, +}: CheckBoxProps) { + return ( + + ) +} diff --git a/src/components/CheckList.module.scss b/src/components/CheckList.module.scss index 048cb7b..a44dbb4 100644 --- a/src/components/CheckList.module.scss +++ b/src/components/CheckList.module.scss @@ -13,14 +13,15 @@ overflow-y: scroll; } - label { - display: flex; - align-items: center; - gap: var(--check-list-item-gap); + .CheckBox { padding: var(--check-list-item-pad); + span:last-of-type { + display: flex; + gap: 8px; + } } - - .CheckListShowCompleted { + .WeekLabel { + display: block; padding: var(--check-list-item-pad); } } diff --git a/src/components/CheckList.tsx b/src/components/CheckList.tsx index a2a486c..69aea2c 100644 --- a/src/components/CheckList.tsx +++ b/src/components/CheckList.tsx @@ -3,6 +3,7 @@ import styles from './CheckList.module.scss' import planText from '../data/five-day.txt?raw' import { CheckListItem, isRangeComplete, versionLink } from '../model' import { loadCheckListState, saveCheckListState } from '../data' +import { CheckBox } from './CheckBox' export function CheckList() { const checkList: CheckListItem[] = planText @@ -25,19 +26,18 @@ export function CheckList() { return (
- + +