diff --git a/package.json b/package.json index 075a2b978..dd8dbbeb7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openstax/ui-components", - "version": "1.17.1", + "version": "1.17.2", "license": "MIT", "source": "./src/index.ts", "types": "./dist/index.d.ts", diff --git a/src/components/Checkbox.tsx b/src/components/Checkbox.tsx deleted file mode 100644 index 19dfd9fdd..000000000 --- a/src/components/Checkbox.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import { LabelHTMLAttributes, PropsWithChildren } from "react"; -import { colors } from "../theme"; -import styled from "styled-components"; -import { InputHTMLAttributes } from "react"; -import { whiteCheckmark, grayCheckmark, redCheckmark } from "./svgs/checkmarksvgs"; - -export type CheckboxVariant = keyof typeof checkboxVariants; -export type CheckboxSize = 1.4 | 1.6 | 1.8 | 2; - -export const checkboxVariants = { - primary: { - backgroundColor: colors.palette.mediumBlue, - color: 'inherit', - unCheckedBorder: `1px solid ${colors.palette.neutralThin}`, - checkedBorder: `1px solid ${colors.palette.mediumBlue}`, - backgroundImage: whiteCheckmark - }, - light: { - backgroundColor: colors.palette.white, - color: 'inherit', - unCheckedBorder: `1px solid ${colors.palette.pale}`, - checkedBorder: `1px solid ${colors.palette.pale}`, - backgroundImage: grayCheckmark - }, - error: { - backgroundColor: colors.palette.paleRed, - color: colors.palette.darkRed, - unCheckedBorder: `1px solid ${colors.palette.lightRed}`, - checkedBorder: `1px solid ${colors.palette.lightRed}`, - backgroundImage: redCheckmark - }, - disabled: { - backgroundColor: colors.palette.white, - color: 'inherit', - unCheckedBorder: `1px solid ${colors.palette.pale}`, - checkedBorder: `1px solid ${colors.palette.pale}`, - backgroundImage: 'none' - } -} as const; - -const StyledLabel = styled.label<{ bold: boolean; variant: CheckboxVariant; isDisabled?: boolean; }>` - font-size: 1.6rem; - display: flex; - align-items: center; - font-weight: ${props => props.bold ? 700 : 400}; - color: ${(props => props.isDisabled ? colors.palette.neutralLight : checkboxVariants[props.variant].color)}; -`; - -// https://moderncss.dev/pure-css-custom-checkbox-style/ -const StyledInput = styled.input<{ variant: CheckboxVariant; checkboxSize: CheckboxSize; isDisabled?: boolean; }>` - appearance: none; - /* For iOS < 15 to remove gradient background */ - background-color: ${colors.palette.white}; - opacity: ${(props => props.isDisabled ? '0.4' : '1')}; - border: ${props => props.isDisabled ? `1px solid ${colors.palette.pale}` : checkboxVariants[props.variant].unCheckedBorder}; - border-radius: 0.2rem; - transform: translateY(-0.075em); - width: ${props => props.checkboxSize}rem; - height: ${props => props.checkboxSize}rem; - margin: 0 1.6rem 0 0; - display: grid; - place-content: center; - - &::before { - content: ""; - width: ${props => props.checkboxSize}rem; - height: ${props => props.checkboxSize}rem; - border: ${props => checkboxVariants[props.variant].checkedBorder}; - border-radius: 0.2rem; - transform: scale(0); - background-color: ${props => checkboxVariants[props.variant].backgroundColor}; - background-image: url('${props => checkboxVariants[props.variant].backgroundImage}'); - background-size: 80%; - background-position: center; - background-repeat: no-repeat; - } - - &:checked::before { - transform: scale(1); - opacity: ${(props => props.isDisabled ? 0 : 1)}; - } - `; - -type CheckboxProps = PropsWithChildren< - Omit, 'type'> & { - variant?: CheckboxVariant; - size?: CheckboxSize; - bold?: boolean; - labelProps?: LabelHTMLAttributes; -}>; - -export const Checkbox = ({ children, disabled, variant = 'primary', bold = false, size = 1.6, labelProps, ...props }: CheckboxProps) => { - return ( - - - {children} - - ); -}; diff --git a/src/components/Checkbox.spec.tsx b/src/components/Checkbox/Checkbox.spec.tsx similarity index 100% rename from src/components/Checkbox.spec.tsx rename to src/components/Checkbox/Checkbox.spec.tsx diff --git a/src/components/Checkbox.stories.tsx b/src/components/Checkbox/Checkbox.stories.tsx similarity index 100% rename from src/components/Checkbox.stories.tsx rename to src/components/Checkbox/Checkbox.stories.tsx diff --git a/src/components/Checkbox/Checkbox.tsx b/src/components/Checkbox/Checkbox.tsx new file mode 100644 index 000000000..6049171c5 --- /dev/null +++ b/src/components/Checkbox/Checkbox.tsx @@ -0,0 +1,30 @@ +import { LabelHTMLAttributes, PropsWithChildren } from "react"; +import { checkboxLabelStyles, checkboxInputStyles, CheckboxVariant, CheckboxSize } from "./sharedCheckboxStyles"; +import styled from "styled-components"; +import { InputHTMLAttributes } from "react"; + +const StyledLabel = styled.label<{ bold: boolean; variant: CheckboxVariant; isDisabled?: boolean; }>` + ${checkboxLabelStyles} +`; + +// https://moderncss.dev/pure-css-custom-checkbox-style/ +const StyledInput = styled.input<{ variant: CheckboxVariant; checkboxSize: CheckboxSize; isDisabled?: boolean; }>` + ${checkboxInputStyles} +`; + +type CheckboxProps = PropsWithChildren< + Omit, 'type'> & { + variant?: CheckboxVariant; + size?: CheckboxSize; + bold?: boolean; + labelProps?: LabelHTMLAttributes; +}>; + +export const Checkbox = ({ children, disabled, variant = 'primary', bold = false, size = 1.6, labelProps, ...props }: CheckboxProps) => { + return ( + + + {children} + + ); +}; diff --git a/src/components/__snapshots__/Checkbox.spec.tsx.snap b/src/components/Checkbox/__snapshots__/Checkbox.spec.tsx.snap similarity index 67% rename from src/components/__snapshots__/Checkbox.spec.tsx.snap rename to src/components/Checkbox/__snapshots__/Checkbox.spec.tsx.snap index 06cb1bf0e..197f0c3f5 100644 --- a/src/components/__snapshots__/Checkbox.spec.tsx.snap +++ b/src/components/Checkbox/__snapshots__/Checkbox.spec.tsx.snap @@ -3,10 +3,10 @@ exports[`Checkbox allows setting props on label 1`] = `