Skip to content

Commit

Permalink
feat(project): add header to checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed Jul 27, 2021
1 parent 95017c5 commit 23e2ef3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/components/Checkbox/Checkbox.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

.checkbox {
display: flex;
flex-wrap: wrap;
align-items: center;

> label {
Expand All @@ -22,6 +23,14 @@
}
}

.header {
flex: 1 1 100%;
margin-bottom: 4px;
font-family: theme.$body-font-family;
font-weight: 700;
text-align: left;
}

input {
display: flex;
flex-shrink: 0;
Expand Down
8 changes: 5 additions & 3 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React, { ReactNode } from 'react';
import React from 'react';

import useOpaqueId from '../../hooks/useOpaqueId';

import styles from './Checkbox.module.scss';

type Props = {
label?: string | ReactNode;
label?: string;
name: string;
value: boolean;
onChange: React.ChangeEventHandler<HTMLInputElement>;
header?: string;
};

const Checkbox: React.FC<Props> = ({ label, name, onChange }: Props) => {
const Checkbox: React.FC<Props> = ({ label, name, onChange, header }: Props) => {
const id = useOpaqueId('check-box', name);

return (
<div className={styles.checkbox}>
{header && <span className={styles.header}>{header}</span>}
<input name={name} type="checkbox" id={id} onChange={onChange} />
<label htmlFor={id}>{label}</label>
</div>
Expand Down

0 comments on commit 23e2ef3

Please sign in to comment.