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

feat(message): add width prop #7196

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/components/message/message-test.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const Default = ({ title, children, ...args }: MessageProps) => {
};
return (
<>
<Button onClick={handleOpen}>Open Message</Button>
<Button mb={2} onClick={handleOpen}>
Open Message
</Button>
<Message open={isOpen} onDismiss={onDismiss} title={title} {...args}>
{children}
</Message>
Expand All @@ -54,6 +56,7 @@ Default.args = {
transparent: false,
children: "This is some information from the Message Component.",
showCloseIcon: true,
width: "",
};

export const Transparent = (args: MessageProps) => {
Expand Down
22 changes: 13 additions & 9 deletions src/components/message/message.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,30 @@ export type MessageVariant =
| "neutral";

export interface MessageProps extends MarginProps {
/** set content to component */
/** Set the component's content */
children?: React.ReactNode;
/** set custom aria label for message close button */
/** Set custom aria-label for component's close button */
closeButtonAriaLabel?: string;
/** set custom id to component root */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-pick i'd separate any non-related changes into a chore commit

/** Set custom id to component root */
id?: string;
/** function runs when user click dismiss button */
/** Callback triggered on dismiss */
onDismiss?: (
e:
| React.KeyboardEvent<HTMLButtonElement>
| React.MouseEvent<HTMLButtonElement>,
) => void;
/** show message component */
/** Flag to determine if the message is rendered */
open?: boolean;
/** determines if the close icon is shown */
/** Flag to determine if the close button is rendered */
showCloseIcon?: boolean;
/** set message title */
/** Set message title */
title?: React.ReactNode;
/** set background to be invisible */
/** Set transparent styling */
transparent?: boolean;
/** set type of message based on new DLS standard */
/** Set the component's variant */
variant?: MessageVariant;
/** Set the component's width, accepts any valid css string */
width?: string;
}

export const Message = React.forwardRef<HTMLDivElement, MessageProps>(
Expand All @@ -55,6 +57,7 @@ export const Message = React.forwardRef<HTMLDivElement, MessageProps>(
id,
closeButtonAriaLabel,
showCloseIcon = true,
width,
...props
}: MessageProps,
ref,
Expand Down Expand Up @@ -85,6 +88,7 @@ export const Message = React.forwardRef<HTMLDivElement, MessageProps>(
transparent={transparent}
variant={variant}
id={id}
width={width}
ref={refToPass}
{...marginProps}
tabIndex={-1}
Expand Down
3 changes: 3 additions & 0 deletions src/components/message/message.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const messageVariants = {
type MessageStyleProps = {
variant?: MessageVariant;
transparent?: boolean;
width?: string;
};

const MessageStyle = styled.div<MessageStyleProps & MarginProps>`
Expand Down Expand Up @@ -47,6 +48,8 @@ const MessageStyle = styled.div<MessageStyleProps & MarginProps>`
transform: translateY(-50%);
}

${({ width }) => width && `width: ${width};`}

${margin}
`;

Expand Down
12 changes: 12 additions & 0 deletions src/components/message/message.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ test("renders with expected styles when `transparent` is true", () => {
});
});

test("renders with provided width when `width` is provided", () => {
render(
<Message data-role="my-message" width="100px">
Message
</Message>,
);

expect(screen.getByTestId("my-message")).toHaveStyle({
width: "100px",
});
});

test("renders with `ref` when provided as an object", () => {
const ref = { current: null };
render(<Message ref={ref}>Message</Message>);
Expand Down
Loading