Skip to content

Commit 7cf24ca

Browse files
author
Hector Arce De Las Heras
committed
Introduce lastChild Property to RadioButton Component
This commit introduces a new lastChild property to the RadioButton component and its associated interfaces. This property is used to control the bottom margin of each radio button in a group, ensuring that the last radio button does not have a bottom margin. Key changes include: radioButton.styled.ts: Added a new lastChild optional property to the IRadioButtonContentStyled interface. This property is then used in the RadioButtonStyled component to conditionally apply a bottom margin. radioButtonStandAlone.tsx: The RadioButtonStandAlone component now accepts a lastChild prop and passes it to the RadioButtonStyled component. radioButton.ts: The IRadioButtonStandAlone interface has been updated to include the lastChild optional property. radioButtonGroupStandAlone.tsx: The RadioButtonGroupStandAloneComponent now calculates whether each option is the last child and passes the result as the lastChild prop to the RadioButtonStandAlone component. This change improves the visual consistency and spacing within radio button groups.
1 parent 5fad565 commit 7cf24ca

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import styled from 'styled-components';
22

3-
export const InfoIconWrapperStyled = styled.div`
4-
display: flex;
3+
import { getStyles } from '@/utils';
4+
5+
import { IRadioButtonGroupStyled, RadioButtonGroupStateType } from '../../types';
6+
7+
export const InfoIconWrapperStyled = styled.div<IRadioButtonGroupStyled>`
8+
${({ styles }) => getStyles(styles?.[RadioButtonGroupStateType.DEFAULT]?.infoIconContainer)}
59
`;

src/components/radioButtonGroup/components/infoIconWithTooltipStandAlone/infoIconWithTooltipStandAlone.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const InfoIconWithTooltipStandAlone = ({
1717
return null;
1818
}
1919
const infoIconWithoutTooltip = (
20-
<InfoIconWrapperStyled>
20+
<InfoIconWrapperStyled styles={styles}>
2121
<ElementOrIcon
2222
customIconStyles={styles[RadioButtonGroupStateType.DEFAULT]?.tooltip?.icon}
2323
dataTestId={dataTestId}

src/components/radioButtonGroup/components/radioButton/types/radioButtonTheme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type RadioButtonBaseStyles = {
1616
errorMessageIconContainer?: CommonStyleType;
1717
radioButtonContainer?: CommonStyleType;
1818
radioButton?: CommonStyleType;
19+
infoIconContainer?: CommonStyleType;
1920
tooltip?: {
2021
icon?: IconTypes;
2122
variant?: string;

src/components/radioButtonGroup/radioButtonGroupStandAlone.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ const RadioButtonGroupStandAloneComponent = (
3737
<>
3838
<Text component={legendComponent} customTypography={props.styles?.[state]?.title}>
3939
{props.legend}
40+
<InfoIconWithTooltipStandAlone
41+
dataTestId={`${dataTestId}InfoIcon`}
42+
infoIcon={props.infoIcon}
43+
styles={props.styles}
44+
tooltip={props.tooltip}
45+
/>
4046
{props.required && (
4147
<>
4248
{requiredSymbol}
4349
<ScreenReaderOnly>{props.requiredScreenReaderText}</ScreenReaderOnly>
4450
</>
4551
)}
4652
</Text>
47-
<InfoIconWithTooltipStandAlone
48-
dataTestId={`${dataTestId}InfoIcon`}
49-
infoIcon={props.infoIcon}
50-
styles={props.styles}
51-
tooltip={props.tooltip}
52-
/>
5353
</>
5454
)}
5555
{props.options.map((o, index) => (

src/components/radioButtonGroup/stories/radioButtonGroup.stories.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Meta, StoryObj } from '@storybook/react';
2+
import React from 'react';
23

4+
import { ICONS } from '@/assets';
35
import { STYLES_NAME } from '@/constants';
46
import { themesObject, variantsObject } from '@/designSystem/themesObject';
57

@@ -21,18 +23,27 @@ const meta = {
2123
figmaUrl:
2224
'https://www.figma.com/file/EYQkbENTFO5r8muvXlPoOy/Kubit-v.1.0.0?type=design&node-id=3922-29665&mode=dev',
2325
},
26+
render: ({ ...args }) => <StoryWithHooks {...args} />,
2427
} satisfies Meta<typeof Story>;
2528

2629
export default meta;
2730

2831
type Story = StoryObj<typeof meta> & { args: { themeArgs?: object } };
2932

33+
const StoryWithHooks = args => {
34+
return (
35+
<div style={{ width: '32px' }}>
36+
<Story {...args} />
37+
</div>
38+
);
39+
};
40+
3041
export const RadioButtongroup: Story = {
3142
args: {
3243
variant: Object.values(
3344
variantsObject[themeSelected].RadioButtonGroupVariantType || {}
3445
)[0] as string,
35-
legend: 'Select your favorite fruit',
46+
legend: 'Select your favorite fruit. Make sure your decision',
3647
name: 'Name',
3748
options: [
3849
{ label: 'Strawberry', value: 'S' },
@@ -45,6 +56,12 @@ export const RadioButtongroup: Story = {
4556
{ label: 'Kiwis', value: 'K', disabled: true },
4657
{ label: 'Coconut', value: 'C' },
4758
],
59+
infoIcon: { icon: ICONS.ICON_PLACEHOLDER },
60+
tooltip: {
61+
closeIcon: { icon: ICONS.ICON_CLOSE },
62+
title: { content: 'Tooltip title' },
63+
content: { content: 'Tooltip content' },
64+
},
4865
themeArgs: themesObject[themeSelected][STYLES_NAME.RADIO_BUTTON_GROUP],
4966
},
5067
};

0 commit comments

Comments
 (0)