Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(PROT-4812): adds backgroundColor prop to RadioCheckToggleCard #1546

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,21 +1,17 @@
import { ArgTypes } from '@storybook/react/*'
import {
RadioCheckToggleCard,
RadioCheckToggleCardHPositions,
RadioCheckToggleCardVPositions,
} from './RadioCheckToggleCard'
import { RadioCheckToggleCardHPositions, RadioCheckToggleCardVPositions } from './RadioCheckToggleCard'

export const argTypes: ArgTypes = {
hPosition: {
control: { type: 'radio' },
options: RadioCheckToggleCardHPositions,
defaultValue: RadioCheckToggleCard.defaultProps.hPosition,
defaultValue: 'right',
description: 'Controlling the button icon horizontal position',
},
vPosition: {
control: { type: 'radio' },
options: RadioCheckToggleCardVPositions,
defaultValue: RadioCheckToggleCard.defaultProps.vPosition,
defaultValue: 'top',
description: 'Controlling the button icon vertical position',
},
isTakingFullHeightOfCard: {
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
Loading