From ab1d41ae14aaad3a5039688eb6950aa76a5a34bd Mon Sep 17 00:00:00 2001 From: unix Date: Sat, 23 May 2020 07:59:14 +0800 Subject: [PATCH] feat(checkbox): add support of different sizes --- components/checkbox/checkbox-group.tsx | 18 +++++++++++++++++- components/checkbox/checkbox.icon.tsx | 18 ++++-------------- components/checkbox/checkbox.tsx | 21 +++++++++++++-------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/components/checkbox/checkbox-group.tsx b/components/checkbox/checkbox-group.tsx index 4f99df8..6a3f3db 100644 --- a/components/checkbox/checkbox-group.tsx +++ b/components/checkbox/checkbox-group.tsx @@ -2,26 +2,40 @@ import React, { useEffect, useMemo, useState } from 'react' import withDefaults from '../utils/with-defaults' import { CheckboxContext } from './checkbox-context' import useWarning from '../utils/use-warning' +import { NormalSizes } from '../utils/prop-types' interface Props { value: string[] disabled?: boolean + size?: NormalSizes onChange?: (values: string[]) => void className?: string } const defaultProps = { disabled: false, + size: 'small' as NormalSizes, className: '', } type NativeAttrs = Omit, keyof Props> export type CheckboxGroupProps = Props & typeof defaultProps & NativeAttrs +export const getCheckboxSize = (size: NormalSizes): string => { + const sizes: { [key in NormalSizes]: string } = { + mini: '.75rem', + small: '.875rem', + medium: '1rem', + large: '1.125rem', + } + return sizes[size] +} + const CheckboxGroup: React.FC> = ({ disabled, onChange, value, + size, children, className, ...props @@ -47,6 +61,7 @@ const CheckboxGroup: React.FC> = ({ values: selfVal, } }, [disabled, selfVal]) + const fontSize = useMemo(() => getCheckboxSize(size), [size]) useEffect(() => { setSelfVal(value) @@ -58,7 +73,8 @@ const CheckboxGroup: React.FC> = ({ {children} diff --git a/components/checkbox/checkbox.icon.tsx b/components/checkbox/checkbox.icon.tsx index 4c7bbb7..a89dd37 100644 --- a/components/checkbox/checkbox.icon.tsx +++ b/components/checkbox/checkbox.icon.tsx @@ -20,12 +20,7 @@ const CheckboxIcon: React.FC = ({ disabled, checked }) => { return ( <> {checked ? ( - + = ({ disabled, checked }) => { ) : ( - + = ({ disabled, checked }) => {