Skip to content

Commit

Permalink
feat(note): add styled-system margin props
Browse files Browse the repository at this point in the history
  • Loading branch information
DipperTheDan committed Apr 9, 2021
1 parent 2eabdfe commit dca47cd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/components/note/__internal__/note.component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import PropTypes from "prop-types";
import { Editor } from "draft-js";
import styledSystemPropTypes from "@styled-system/prop-types";
import invariant from "invariant";
import {
StyledNote,
Expand All @@ -12,6 +13,11 @@ import {
} from "./note.style.js";
import StatusWithTooltip from "./status-with-tooltip";
import { ActionPopover } from "../../action-popover";
import { filterStyledSystemMarginProps } from "../../../style/utils";

const marginPropTypes = filterStyledSystemMarginProps(
styledSystemPropTypes.space
);

const Note = ({
noteContent,
Expand Down Expand Up @@ -74,6 +80,7 @@ const Note = ({
};

Note.propTypes = {
...marginPropTypes,
/** The rich text content to display in the Note */
noteContent: PropTypes.object.isRequired,
/** Set a percentage-based width for the whole Note component, relative to its parent. */
Expand Down
3 changes: 2 additions & 1 deletion src/components/note/__internal__/note.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { MarginSpacingProps } from '../../../utils/helpers/options-helper';

export interface NoteProps {
export interface NoteProps extends MarginSpacingProps {
noteContent: object;
width?: number;
inlineControl?: React.ReactNode;
Expand Down
16 changes: 15 additions & 1 deletion src/components/note/__internal__/note.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
} from "./note.style";
import { ActionPopover, ActionPopoverItem } from "../../action-popover";
import StyledStatusIconWrapper from "./status-with-tooltip/status.style";
import { assertStyleMatch } from "../../../__spec_helper__/test-utils";
import {
assertStyleMatch,
testStyledSystemMargin,
} from "../../../__spec_helper__/test-utils";

function render(props = {}) {
const defaultProps = {
Expand All @@ -30,6 +33,17 @@ function render(props = {}) {
}

describe("Note", () => {
describe("styled-system", () => {
testStyledSystemMargin((props) => (
<Note
{...props}
name="Carbon"
createdDate="23 May 2020, 12:08 PM"
noteContent={EditorState.createEmpty()}
/>
));
});

describe("Styling", () => {
it("matches the expected", () => {
const wrapper = render();
Expand Down
3 changes: 2 additions & 1 deletion src/components/note/__internal__/note.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 Note from './note.component';
import {
ActionPopover,
Expand Down Expand Up @@ -204,4 +205,4 @@ An optional status can be provided using the `status` prop.
## Props

### Note
<Props of={Note} />
<StyledSystemProps of={Note} noHeader margin />
3 changes: 3 additions & 0 deletions src/components/note/__internal__/note.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";

const StyledNoteContent = styled.div`
Expand Down Expand Up @@ -95,6 +96,8 @@ const StyledNote = styled.div`
width: auto;
}
`}
${margin}
`;

StyledNoteContent.defaultProps = {
Expand Down

0 comments on commit dca47cd

Please sign in to comment.