Skip to content

Commit b1d7e8e

Browse files
author
Hector Arce De Las Heras
committed
Add Link Feature to Message Component
This commit introduces a new feature to the Message component that allows a link to be included in the message. The link can be customized through properties. Key changes include: New MessageLinkType introduced in message.ts to represent the link in the message component. This type is used to add a link property to the IMessageStandAlone interface. MessageLinkType is exported in index.ts and types/index.ts for use in other modules. A linkContainer property is added to the MessagePropsThemeType in messageTheme.ts to allow for styling of the link container. A new styled component LinkContainerStyled is created in message.styled.ts to style the container that holds the link in the message. The Link component and the new LinkContainerStyled styled component are imported in messageStandAlone.tsx. These are used to add a link to the MessageStandAloneComponent if the link property is provided in the props. A link property is added to the MOCK object used in tests in message.test.tsx to reflect the changes in the component's props. A link property is added to the argtypes function and the Message story in argtypes.ts and message.stories.tsx to allow for testing of the new feature in Storybook. These changes enhance the functionality of the Message component by allowing links to be included in messages.
1 parent 2e49d4d commit b1d7e8e

File tree

9 files changed

+57
-2
lines changed

9 files changed

+57
-2
lines changed

src/components/message/__tests__/message.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const MOCK = {
2424
variant: 'ERROR',
2525
open: true,
2626
closeIcon: { onClick: jest.fn() },
27+
link: { content: 'Link', variant: 'SECONDARY', url: '#' },
2728
};
2829

2930
const mockPropsWithTagAndExtraAction = {

src/components/message/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ export type {
22
IMessageStandAlone,
33
IMessageControlled,
44
IMessageUnControlled,
5+
MessageActionButtonType,
6+
MessageExtraActionButtonType,
7+
MessageContentType,
8+
MessageTitleType,
9+
MessageTagType,
10+
MessageLinkType,
511
MessagePropsThemeType,
612
MessageStylesType,
713
} from './types';

src/components/message/message.styled.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ export const CloseButtonSectionStyled = styled.div<{
7070
}>`
7171
${({ styles }) => getStyles(styles.closeIconContainer)};
7272
`;
73+
74+
export const LinkContainerStyled = styled.div<{
75+
styles: MessagePropsThemeType;
76+
}>`
77+
${({ styles }) => getStyles(styles.linkContainer)};
78+
`;

src/components/message/messageStandAlone.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import { Button } from '@/components/button';
44
import { ElementOrIcon } from '@/components/elementOrIcon';
55
import { ElementOrIllustration } from '@/components/elementOrIllustration';
66
import { Tag } from '@/components/tag';
7-
import { Text, TextComponentType } from '@/components/text';
7+
import { Text, TextComponentType, TextDecorationType } from '@/components/text';
88
import { AriaLiveOptionType } from '@/types';
99

10+
import { Link } from '../link';
1011
// styles
1112
import {
1213
ActioButtonWrapperStyled,
1314
ButtonSectionStyled,
1415
CloseButtonSectionStyled,
1516
ExtraActioButtonWrapperStyled,
17+
LinkContainerStyled,
1618
MessageContentStyled,
1719
MessageHeaderStyled,
1820
MessageHeaderTitleStyled,
@@ -136,6 +138,17 @@ const MessageStandAloneComponent = (
136138
</CloseButtonSectionStyled>
137139
)}
138140
</ButtonSectionStyled>
141+
{props.link?.content && (
142+
<LinkContainerStyled styles={props.styles}>
143+
<Link
144+
dataTestId={`${props.dataTestId}Link`}
145+
decoration={TextDecorationType.UNDERLINE}
146+
{...props.link}
147+
>
148+
{props.link.content}
149+
</Link>
150+
</LinkContainerStyled>
151+
)}
139152
</MessageStyled>
140153
) : null;
141154
};

src/components/message/stories/argtypes.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ export const argtypes = (variants: IThemeObjectVariants, themeSelected: string):
9191
category: CATEGORY_CONTROL.CONTENT,
9292
},
9393
},
94+
link: {
95+
description: 'Object with link properties',
96+
type: { name: 'object', required: false },
97+
control: { type: 'object' },
98+
table: {
99+
type: {
100+
summary: 'MessageLinkType',
101+
},
102+
category: CATEGORY_CONTROL.CONTENT,
103+
},
104+
},
94105
infoIcon: {
95106
description: 'Object with properties of the icon to show into title message',
96107
type: { name: 'object' },

src/components/message/stories/message.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const Message: Story = {
4343
),
4444
},
4545
title: { content: 'Title' },
46+
link: { content: 'Link', variant: 'SECONDARY', url: '#' },
4647
themeArgs: themesObject[themeSelected][STYLES_NAME.MESSAGE],
4748
},
4849
};

src/components/message/types/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
export type { IMessageStandAlone, IMessageControlled, IMessageUnControlled } from './message';
1+
export type {
2+
IMessageStandAlone,
3+
IMessageControlled,
4+
IMessageUnControlled,
5+
MessageActionButtonType,
6+
MessageExtraActionButtonType,
7+
MessageContentType,
8+
MessageTitleType,
9+
MessageTagType,
10+
MessageLinkType,
11+
} from './message';
212
export type { MessagePropsThemeType, MessageStylesType } from './messageTheme';

src/components/message/types/message.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ReactNode } from 'react';
33
import { IButton } from '@/components/button';
44
import { IElementOrIcon } from '@/components/elementOrIcon';
55
import { IElementOrillustration } from '@/components/elementOrIllustration';
6+
import { ILink } from '@/components/link';
67
import { ITag } from '@/components/tag';
78
import { IText } from '@/components/text';
89
import { AriaLiveOptionType, CustomTokenTypes, ROLES } from '@/types';
@@ -30,6 +31,10 @@ export type MessageTagType = Omit<ITag, 'children'> & {
3031
content: string;
3132
};
3233

34+
export type MessageLinkType = Omit<ILink, 'children'> & {
35+
content?: string;
36+
};
37+
3338
export interface IMessageStandAlone {
3439
illustration?: IElementOrillustration;
3540
infoIcon?: IElementOrIcon;
@@ -47,6 +52,7 @@ export interface IMessageStandAlone {
4752
role?: ROLES.STATUS | ROLES.ALERT;
4853
id?: string;
4954
ariaLive?: AriaLiveOptionType;
55+
link?: MessageLinkType;
5056
}
5157

5258
export interface IMessageControlled<V = undefined extends string ? unknown : string>

src/components/message/types/messageTheme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type MessagePropsThemeType = {
2020
size?: string;
2121
};
2222
illustration?: IllustrationTypes;
23+
linkContainer?: CommonStyleType;
2324
};
2425

2526
export type MessageStylesType<P extends string | number | symbol> = {

0 commit comments

Comments
 (0)