From 75bf499f075dde80fdf7aa5792897478ae5122c3 Mon Sep 17 00:00:00 2001 From: gmeigniez-pass <139768952+gmeigniez-pass@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:25:39 +0100 Subject: [PATCH 1/9] (PC-33527)[PRO] feat: Replace withBorder checkbox prop with box variant. --- .../PriceCategoriesScreen/PriceCategoriesForm.tsx | 3 ++- .../IndividualOffer/StocksThing/StocksThing.tsx | 3 ++- pro/src/ui-kit/form/CheckboxGroup/CheckboxGroup.tsx | 4 ++++ .../ui-kit/form/CheckboxGroup/CheckboxGroupItem.tsx | 8 +++++++- .../form/shared/BaseCheckbox/BaseCheckbox.stories.tsx | 4 ++-- .../ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx | 11 ++++++++--- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pro/src/components/IndividualOffer/PriceCategoriesScreen/PriceCategoriesForm.tsx b/pro/src/components/IndividualOffer/PriceCategoriesScreen/PriceCategoriesForm.tsx index 3eb7df66e02..ecd5bd18e81 100644 --- a/pro/src/components/IndividualOffer/PriceCategoriesScreen/PriceCategoriesForm.tsx +++ b/pro/src/components/IndividualOffer/PriceCategoriesScreen/PriceCategoriesForm.tsx @@ -15,6 +15,7 @@ import { Button } from 'ui-kit/Button/Button' import { ButtonVariant, IconPositionEnum } from 'ui-kit/Button/types' import { Checkbox } from 'ui-kit/form/Checkbox/Checkbox' import { PriceInput } from 'ui-kit/form/PriceInput/PriceInput' +import { CheckboxVariant } from 'ui-kit/form/shared/BaseCheckbox/BaseCheckbox' import { TextInput } from 'ui-kit/form/TextInput/TextInput' import { InfoBox } from 'ui-kit/InfoBox/InfoBox' @@ -232,7 +233,7 @@ export const PriceCategoriesForm = ({ label="Accepter les réservations “Duo“" name="isDuo" disabled={isDisabled} - withBorder + variant={CheckboxVariant.BOX} /> diff --git a/pro/src/components/IndividualOffer/StocksThing/StocksThing.tsx b/pro/src/components/IndividualOffer/StocksThing/StocksThing.tsx index 5023d4d7830..61e70645f36 100644 --- a/pro/src/components/IndividualOffer/StocksThing/StocksThing.tsx +++ b/pro/src/components/IndividualOffer/StocksThing/StocksThing.tsx @@ -34,6 +34,7 @@ import { Quantity, QuantityInput, } from 'ui-kit/form/QuantityInput/QuantityInput' +import { CheckboxVariant } from 'ui-kit/form/shared/BaseCheckbox/BaseCheckbox' import { TextInput } from 'ui-kit/form/TextInput/TextInput' import { InfoBox } from 'ui-kit/InfoBox/InfoBox' @@ -469,7 +470,7 @@ export const StocksThing = ({ offer }: StocksThingProps): JSX.Element => { label="Accepter les réservations “Duo“" name="isDuo" disabled={isDisabled} - withBorder + variant={CheckboxVariant.BOX} /> diff --git a/pro/src/ui-kit/form/CheckboxGroup/CheckboxGroup.tsx b/pro/src/ui-kit/form/CheckboxGroup/CheckboxGroup.tsx index bd59ecf5a81..536c4ead60d 100644 --- a/pro/src/ui-kit/form/CheckboxGroup/CheckboxGroup.tsx +++ b/pro/src/ui-kit/form/CheckboxGroup/CheckboxGroup.tsx @@ -1,6 +1,7 @@ import cn from 'classnames' import { useField } from 'formik' +import { CheckboxVariant } from '../shared/BaseCheckbox/BaseCheckbox' import { FieldSetLayout } from '../shared/FieldSetLayout/FieldSetLayout' import styles from './CheckboxGroup.module.scss' @@ -19,6 +20,7 @@ interface CheckboxGroupProps { className?: string disabled?: boolean isOptional?: boolean + variant?: CheckboxVariant } export const CheckboxGroup = ({ @@ -28,6 +30,7 @@ export const CheckboxGroup = ({ className, disabled, isOptional, + variant, }: CheckboxGroupProps): JSX.Element => { const [, meta, helpers] = useField({ name: groupName }) const hasError = meta.touched && !!meta.error @@ -53,6 +56,7 @@ export const CheckboxGroup = ({ disabled={disabled} onChange={item.onChange} {...(hasError ? { ariaDescribedBy: `error-${groupName}` } : {})} + variant={variant} /> ))} diff --git a/pro/src/ui-kit/form/CheckboxGroup/CheckboxGroupItem.tsx b/pro/src/ui-kit/form/CheckboxGroup/CheckboxGroupItem.tsx index 0aa7734c9e8..aaaf8901086 100644 --- a/pro/src/ui-kit/form/CheckboxGroup/CheckboxGroupItem.tsx +++ b/pro/src/ui-kit/form/CheckboxGroup/CheckboxGroupItem.tsx @@ -1,6 +1,9 @@ import { useField } from 'formik' -import { BaseCheckbox } from 'ui-kit/form/shared/BaseCheckbox/BaseCheckbox' +import { + BaseCheckbox, + CheckboxVariant, +} from 'ui-kit/form/shared/BaseCheckbox/BaseCheckbox' interface CheckboxGroupItemProps { setGroupTouched(): void @@ -12,6 +15,7 @@ interface CheckboxGroupItemProps { disabled?: boolean onChange?: (event: React.ChangeEvent) => void ariaDescribedBy?: string + variant?: CheckboxVariant } export const CheckboxGroupItem = ({ @@ -23,6 +27,7 @@ export const CheckboxGroupItem = ({ disabled, onChange, ariaDescribedBy, + variant, }: CheckboxGroupItemProps): JSX.Element => { const [field] = useField({ name, type: 'checkbox' }) @@ -43,6 +48,7 @@ export const CheckboxGroupItem = ({ onChange={onCustomChange} disabled={disabled} ariaDescribedBy={ariaDescribedBy} + variant={variant} /> ) } diff --git a/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.stories.tsx b/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.stories.tsx index 9d0cd4829d1..4b1a6835de9 100644 --- a/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.stories.tsx +++ b/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.stories.tsx @@ -2,7 +2,7 @@ import type { StoryObj } from '@storybook/react' import strokeAccessibilityEye from 'icons/stroke-accessibility-eye.svg' -import { BaseCheckbox } from './BaseCheckbox' +import { BaseCheckbox, CheckboxVariant } from './BaseCheckbox' export default { title: 'ui-kit/forms/shared/BaseCheckbox', @@ -28,6 +28,6 @@ export const WithBorder: StoryObj = { args: { label: 'Checkbox Label with border', icon: strokeAccessibilityEye, - withBorder: true, + variant: CheckboxVariant.BOX, }, } diff --git a/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx b/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx index fbcc1d99fd8..4a3383faa85 100644 --- a/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx +++ b/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx @@ -11,6 +11,11 @@ export enum PartialCheck { UNCHECKED = 'unchecked', } +export enum CheckboxVariant { + DEFAULT = 'default', + BOX = 'box', +} + export interface BaseCheckboxProps extends React.InputHTMLAttributes { label: string | React.ReactNode @@ -19,7 +24,7 @@ export interface BaseCheckboxProps inputClassName?: string labelClassName?: string icon?: string - withBorder?: boolean + variant?: CheckboxVariant partialCheck?: boolean exceptionnallyHideLabelDespiteA11y?: boolean description?: string @@ -35,7 +40,7 @@ export const BaseCheckbox = forwardRef( inputClassName, labelClassName, icon, - withBorder, + variant = CheckboxVariant.DEFAULT, partialCheck, exceptionnallyHideLabelDespiteA11y, description, @@ -61,7 +66,7 @@ export const BaseCheckbox = forwardRef( labelClassName ) const containerClasses = cn(styles['base-checkbox'], className, { - [styles['with-border']]: withBorder, + [styles['with-border']]: variant === CheckboxVariant.BOX, [styles['has-error']]: hasError, [styles['is-disabled']]: props.disabled, }) From 64544de893d03269c5728f67bc12d6a1891d2ccd Mon Sep 17 00:00:00 2001 From: gmeigniez-pass <139768952+gmeigniez-pass@users.noreply.github.com> Date: Fri, 3 Jan 2025 12:24:57 +0100 Subject: [PATCH 2/9] (PC-33527)[PRO] feat: Rework base checkbox styles to match figma designs. --- .../UsefulInformationForm.module.scss | 6 -- .../UsefulInformationForm.tsx | 1 - .../CheckboxGroup/CheckboxGroup.module.scss | 12 +--- .../form/CheckboxGroup/CheckboxGroup.tsx | 39 +++++++------ .../BaseCheckbox/BaseCheckbox.module.scss | 56 ++++++++++++++----- .../form/shared/BaseCheckbox/BaseCheckbox.tsx | 21 +++---- 6 files changed, 75 insertions(+), 60 deletions(-) diff --git a/pro/src/pages/IndividualOffer/IndividualOfferInformations/components/UsefulInformationForm/UsefulInformationForm.module.scss b/pro/src/pages/IndividualOffer/IndividualOfferInformations/components/UsefulInformationForm/UsefulInformationForm.module.scss index 91fa1808199..1603dd4fd27 100644 --- a/pro/src/pages/IndividualOffer/IndividualOfferInformations/components/UsefulInformationForm/UsefulInformationForm.module.scss +++ b/pro/src/pages/IndividualOffer/IndividualOfferInformations/components/UsefulInformationForm/UsefulInformationForm.module.scss @@ -1,11 +1,5 @@ @use "styles/mixins/_rem.scss" as rem; -.accessibility-checkbox-group { - legend { - margin-bottom: rem.torem(24px); - } -} - .info-banners { margin-bottom: rem.torem(24px); } diff --git a/pro/src/pages/IndividualOffer/IndividualOfferInformations/components/UsefulInformationForm/UsefulInformationForm.tsx b/pro/src/pages/IndividualOffer/IndividualOfferInformations/components/UsefulInformationForm/UsefulInformationForm.tsx index d1ffe5f7a6c..a273de6fdf0 100644 --- a/pro/src/pages/IndividualOffer/IndividualOfferInformations/components/UsefulInformationForm/UsefulInformationForm.tsx +++ b/pro/src/pages/IndividualOffer/IndividualOfferInformations/components/UsefulInformationForm/UsefulInformationForm.tsx @@ -253,7 +253,6 @@ export const UsefulInformationForm = ({ ) => void }[] - className?: string disabled?: boolean isOptional?: boolean variant?: CheckboxVariant @@ -27,7 +26,6 @@ export const CheckboxGroup = ({ group, groupName, legend, - className, disabled, isOptional, variant, @@ -37,29 +35,30 @@ export const CheckboxGroup = ({ return ( - {group.map((item) => ( -
- - !meta.touched ? helpers.setTouched(true) : null - } - disabled={disabled} - onChange={item.onChange} - {...(hasError ? { ariaDescribedBy: `error-${groupName}` } : {})} - variant={variant} - /> -
- ))} +
+ {group.map((item) => ( +
+ + !meta.touched ? helpers.setTouched(true) : null + } + disabled={disabled} + onChange={item.onChange} + {...(hasError ? { ariaDescribedBy: `error-${groupName}` } : {})} + variant={variant} + /> +
+ ))} +
) } diff --git a/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.module.scss b/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.module.scss index 1ff51b640f3..c4ded33f818 100644 --- a/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.module.scss +++ b/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.module.scss @@ -6,7 +6,6 @@ .base-checkbox { display: inline-flex; - cursor: pointer; width: 100%; &-label-row { @@ -16,10 +15,8 @@ } &-label { - display: inline-flex; - flex-direction: column; width: 100%; - justify-items: center; + cursor: pointer; } &-description { @@ -32,8 +29,8 @@ &-icon { margin-right: rem.torem(8px); display: inline-flex; + vertical-align: text-bottom; flex-direction: column; - vertical-align: middle; &-svg { width: rem.torem(20px); @@ -43,7 +40,6 @@ &-input { appearance: none; - background-color: var(--color-input-bg-color); border: rem.torem(2px) solid var(--color-grey-dark); border-radius: rem.torem(3px); transition: @@ -82,9 +78,8 @@ } &:focus-visible { - outline: rem.torem(1px) solid var(--color-input-text-color); + outline: rem.torem(1px) solid var(--color-black); outline-offset: rem.torem(4px); - border-radius: rem.torem(4px); } } @@ -141,22 +136,55 @@ } } -.with-border { +.box-vairant, +.inline-box-vairant { border: rem.torem(1px) solid var(--color-grey-semi-dark); - border-radius: rem.torem(6px); + border-radius: rem.torem(8px); min-width: 100%; padding-left: rem.torem(16px); - padding-top: rem.torem(16px); - padding-bottom: rem.torem(16px); + + &.is-checked { + background-color: var(--color-background-secondary); + border-color: var(--color-secondary); + } + + &.is-disabled .base-checkbox-input:checked { + background-color: var(--color-grey-semi-dark); + border-color: var(--color-grey-semi-dark); + } + + &.has-error { + background-color: transparent; + border-color: var(--color-error); + } + + &.is-disabled { + background-color: var(--color-grey-light); + border-color: var(--color-grey-medium); + } .base-checkbox-input:focus-visible { outline: none; } + .base-checkbox-label { + padding: rem.torem(16px) rem.torem(16px) rem.torem(16px) 0; + } + &:focus-within { - outline: rem.torem(1px) solid var(--color-input-text-color); + outline: rem.torem(1px) solid var(--color-black); outline-offset: rem.torem(4px); - border-radius: rem.torem(4px); + } + + @supports selector(:has(*)) { + &:focus-within { + outline: none; + } + + &:has(.base-checkbox-input:focus-visible) { + outline: rem.torem(1px) solid var(--color-black); + outline-offset: rem.torem(4px); + } } } diff --git a/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx b/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx index 4a3383faa85..adc4eaf5cbe 100644 --- a/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx +++ b/pro/src/ui-kit/form/shared/BaseCheckbox/BaseCheckbox.tsx @@ -66,9 +66,10 @@ export const BaseCheckbox = forwardRef( labelClassName ) const containerClasses = cn(styles['base-checkbox'], className, { - [styles['with-border']]: variant === CheckboxVariant.BOX, + [styles['box-vairant']]: variant === CheckboxVariant.BOX, [styles['has-error']]: hasError, [styles['is-disabled']]: props.disabled, + [styles['is-checked']]: props.checked, }) return ( @@ -83,16 +84,16 @@ export const BaseCheckbox = forwardRef( className={cn(styles['base-checkbox-input'], inputClassName)} id={id} /> - {icon && ( - - - - )}