Skip to content

Commit

Permalink
feat(message): add styled-system margin props
Browse files Browse the repository at this point in the history
  • Loading branch information
DipperTheDan committed Apr 8, 2021
1 parent da396d7 commit 26e793e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from "styled-components";
import { margin } from "styled-system";

const MessageContentStyle = styled.div`
padding: 15px 50px 15px 20px;
Expand All @@ -11,6 +12,8 @@ const MessageContentStyle = styled.div`
.carbon-content__body {
margin-top: 0px;
}
${margin}
`;

export default MessageContentStyle;
10 changes: 10 additions & 0 deletions src/components/message/message.component.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import React from "react";
import PropTypes from "prop-types";
import I18n from "i18n-js";
import styledSystemPropTypes from "@styled-system/prop-types";
import MessageStyle from "./message.style";
import TypeIcon from "./type-icon/type-icon.component";
import MessageContent from "./message-content/message-content.component";
import OptionsHelper from "../../utils/helpers/options-helper";
import tagComponent from "../../utils/helpers/tags";
import Icon from "../icon";
import IconButton from "../icon-button";
import { filterStyledSystemMarginProps } from "../../style/utils";

const marginPropTypes = filterStyledSystemMarginProps(
styledSystemPropTypes.space
);

const Message = ({
open = true,
Expand All @@ -22,6 +28,8 @@ const Message = ({
showCloseIcon = true,
...props
}) => {
const marginProps = filterStyledSystemMarginProps(props);

const renderCloseIcon = () => {
if (!showCloseIcon || !onDismiss) return null;

Expand Down Expand Up @@ -51,6 +59,7 @@ const Message = ({
variant={variant}
role="status"
id={id}
{...marginProps}
>
<TypeIcon variant={variant} transparent={transparent} />
<MessageContent
Expand All @@ -67,6 +76,7 @@ const Message = ({
};

Message.propTypes = {
...marginPropTypes,
/** set type of message based on new DLS standard */
variant: PropTypes.oneOf(OptionsHelper.colors),
/** set content to component */
Expand Down
5 changes: 5 additions & 0 deletions src/components/message/message.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Message from "./message.component";
import {
assertStyleMatch,
carbonThemesJestTable,
testStyledSystemMargin,
} from "../../__spec_helper__/test-utils";
import { baseTheme } from "../../style/themes";
import IconButton from "../icon-button";
Expand Down Expand Up @@ -210,4 +211,8 @@ describe("Message", () => {
});
});
});

describe("styled-system", () => {
testStyledSystemMargin((props) => <Message {...props} />);
});
});
3 changes: 2 additions & 1 deletion src/components/message/message.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
import StyledSystemProps from "../../../.storybook/utils/styled-system-props";

import Message from '.';
import Button from '../button';
Expand Down Expand Up @@ -167,4 +168,4 @@ It is also possible to use the `List`, `ListItem` and `Typography` components to

### Message

<Props of={Message} />
<StyledSystemProps of={Message} noHeader margin />
3 changes: 3 additions & 0 deletions src/components/message/message.style.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled, { css } from "styled-components";
import PropTypes from "prop-types";
import { margin } from "styled-system";
import BaseTheme from "../../style/themes/base";
import StyledIconButton from "../icon-button/icon-button.style";

Expand All @@ -25,6 +26,8 @@ const MessageStyle = styled.div`
top: 50%;
transform: translateY(-50%);
}
${margin}
`;

MessageStyle.defaultProps = {
Expand Down

0 comments on commit 26e793e

Please sign in to comment.