Skip to content

Commit

Permalink
feature(PROT-4812): adds backgroundColor prop to RadioCheckToggleCard
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-alterio committed Jan 22, 2025
1 parent c8efbaf commit 8f78f4a
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 271 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "pcln-design-system",
"comment": "adds backgroundColor to RadioCheckToggleCard",
"type": "minor"
}
],
"packageName": "pcln-design-system"
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ describe('RadioCheckToggleCard', () => {
it('should render unchecked state UI correctly', () => {
const { asFragment } = render(
<RadioCheckToggleCard
backgroundColor='secondary.lightest'
cardType='toggle'
name='radio-1'
title='Title'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const EnabledStateCard = styled(Box)`
flex: 1 1 30%;
& > label > div {
background-color: ${getPaletteColor('background.lightest')} !important;
border-color: transparent !important;
& div.cardIcon > svg {
Expand All @@ -53,7 +52,6 @@ const HoverStateCard = styled(Box)`
flex: 1 1 30%;
& > label > div {
background-color: ${getPaletteColor('background.lightest')} !important;
border-color: ${getPaletteColor('primary.base')} !important;
& div.cardIcon > svg {
Expand All @@ -68,7 +66,6 @@ const FocusStateCard = styled(Box)`
flex: 1 1 30%;
& > label > div {
background-color: ${getPaletteColor('background.lightest')} !important;
border-color: transparent !important;
& div.cardIcon > svg {
Expand Down Expand Up @@ -141,7 +138,7 @@ const DefaultDocPage = () => {
options: {
hPosition: THPositions
vPosition: TVPositions
title: string
title: string | React.ReactElement
value: string
}[]
} = {
Expand Down Expand Up @@ -279,13 +276,53 @@ const DefaultDocPage = () => {
</RadioCheckToggleCard>
</FocusStateCard>

<EnabledStateCard>
<RadioCheckToggleCard
name='states-radio'
title={<Text>Enabled - with backgroundColor</Text>}
value='example-1-1'
isSelected={false}
onChange={() => {}}
backgroundColor='success.light'
>
<Box width='100%' height='75px' />
</RadioCheckToggleCard>
</EnabledStateCard>

<HoverStateCard>
<RadioCheckToggleCard
name='states-radio'
title='Hover - with backgroundColor'
value='example-2-2'
isSelected={false}
onChange={() => {}}
backgroundColor='success.light'
>
<Box width='100%' height='75px' />
</RadioCheckToggleCard>
</HoverStateCard>

<FocusStateCard>
<RadioCheckToggleCard
name='states-radio'
title='Focus - with backgroundColor'
value='example-3-3'
isSelected={false}
onChange={() => {}}
backgroundColor='success.light'
>
<Box width='100%' height='75px' />
</RadioCheckToggleCard>
</FocusStateCard>

<SelectedStateCard>
<RadioCheckToggleCard
name='states-radio'
title='Selected'
value='example-4'
isSelected={true}
onChange={() => {}}
backgroundColor='success.light' // set the backgroundColor, but ensure isSelected style overrides backgroundColor
>
<Box width='100%' height='75px' />
</RadioCheckToggleCard>
Expand Down
53 changes: 22 additions & 31 deletions packages/core/src/RadioCheckToggleCard/RadioCheckToggleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Box } from '../Box/Box'
import { Flex } from '../Flex/Flex'
import { Toggle } from '../Toggle/Toggle'
import { getPaletteColor } from '../utils/utils'
import { type PaletteColor } from '../theme/theme'

/**
* @public
Expand Down Expand Up @@ -41,17 +42,18 @@ export type TVPositions = (typeof RadioCheckToggleCardVPositions)[number]
* @public
*/
export type RadioCheckToggleCardProps = {
children?: React.ReactNode
backgroundColor?: PaletteColor
cardType?: TCardTypes
children?: React.ReactNode
hPosition?: THPositions
vPosition?: TVPositions
isSelected: boolean
isTakingFullHeightOfCard?: boolean
title: string
isTitleBold?: boolean
name: string
value: string
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
isSelected: boolean
title: string | React.ReactElement
value: string
vPosition?: TVPositions
}

const CombinedInput = styled.input`
Expand Down Expand Up @@ -97,7 +99,6 @@ const CombinedInput = styled.input`
`

const RCTCardContainer = styled(Flex)`
background-color: ${getPaletteColor('background.lightest')};
border: 1px solid transparent;
border-radius: ${themeGet('borderRadii.action-lg')};
box-shadow: ${themeGet('shadows.sm')};
Expand Down Expand Up @@ -170,21 +171,20 @@ const buttonIcon = (cardType: TCardTypes) => {
/**
* @public
*/
export function RadioCheckToggleCard(props: RadioCheckToggleCardProps) {
const {
children,
cardType,
hPosition,
vPosition,
isTakingFullHeightOfCard,
title,
isTitleBold,
name,
value,
onChange,
isSelected,
} = props

export function RadioCheckToggleCard({
backgroundColor = 'background.lightest',
cardType = 'radio',
children,
hPosition = 'right',
isSelected,
isTakingFullHeightOfCard = false,
isTitleBold = false,
name,
onChange = () => {},
title,
value,
vPosition = 'top',
}: RadioCheckToggleCardProps) {
const id = `${name}_${value}`
const ButtonIcon = buttonIcon(cardType)

Expand All @@ -199,7 +199,7 @@ export function RadioCheckToggleCard(props: RadioCheckToggleCardProps) {
onChange={onChange}
checked={isSelected}
/>
<RCTCardContainer flexDirection='column' data-testId='rdt-card-main'>
<RCTCardContainer flexDirection='column' data-testId='rdt-card-main' color={backgroundColor}>
<CardHeader
alignItems={vPosition}
flexDirection={hPosition === 'left' ? 'row-reverse' : 'row'}
Expand All @@ -222,12 +222,3 @@ export function RadioCheckToggleCard(props: RadioCheckToggleCardProps) {
}

RadioCheckToggleCard.displayName = 'RadioCheckToggleCard'

RadioCheckToggleCard.defaultProps = {
cardType: 'radio' as TCardTypes,
isTitleBold: false,
hPosition: 'right' as THPositions,
vPosition: 'top' as TVPositions,
isTakingFullHeightOfCard: false,
onChange: () => {},
}
Loading

0 comments on commit 8f78f4a

Please sign in to comment.