Skip to content

Commit

Permalink
feat(loader): add styled-system
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawid committed Apr 9, 2021
1 parent da396d7 commit 28f4656
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/components/loader/loader.component.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import React from "react";
import PropTypes from "prop-types";
import styledSystemPropTypes from "@styled-system/prop-types";
import tagComponent from "../../utils/helpers/tags";
import OptionsHelper from "../../utils/helpers/options-helper";
import StyledLoader from "./loader.style";
import StyledLoaderSquare from "./loader-square.style";
import { filterStyledSystemMarginProps } from "../../style/utils";

const marginPropTypes = filterStyledSystemMarginProps(
styledSystemPropTypes.space
);

const Loader = (props) => {
const marginProps = filterStyledSystemMarginProps(props);
return (
<StyledLoader {...props} {...tagComponent("loader", props)}>
<StyledLoader
{...props}
{...tagComponent("loader", props)}
{...marginProps}
>
<StyledLoaderSquare {...props} />
<StyledLoaderSquare {...props} />
<StyledLoaderSquare {...props} />
Expand All @@ -22,6 +33,7 @@ Loader.defaultProps = {
};

Loader.propTypes = {
...marginPropTypes,
/** Size of the loader. */
size: PropTypes.oneOf(OptionsHelper.sizesBinary),
/** Applies white color. */
Expand Down
8 changes: 7 additions & 1 deletion src/components/loader/loader.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from "react";
import TestRenderer from "react-test-renderer";
import { shallow } from "enzyme";
import { assertStyleMatch } from "../../__spec_helper__/test-utils";
import {
assertStyleMatch,
testStyledSystemMargin,
} from "../../__spec_helper__/test-utils";
import "jest-styled-components";
import Loader from "./loader.component";
import StyledLoader from "./loader.style";
Expand All @@ -16,6 +19,9 @@ function renderStyles(props) {

describe("Loader", () => {
let wrapper;

testStyledSystemMargin((props) => <Loader {...props} />);

it("renders as expected", () => {
assertStyleMatch(
{
Expand Down
3 changes: 2 additions & 1 deletion src/components/loader/loader.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from 'react';
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
import Loader from '.';
import Button from '../button';
import StyledSystemProps from "../../../.storybook/utils/styled-system-props";

<Meta title="Design System/Loader" parameters={{ info: { disable: true }, chromatic: { disable: true }}} />

Expand Down Expand Up @@ -69,4 +70,4 @@ please remember to pass the `isInsideButton` prop to the `Loader` component.
## Props

### Loader
<Props of={Loader} />
<StyledSystemProps of={Loader} noHeader margin />
7 changes: 7 additions & 0 deletions src/components/loader/loader.style.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import styled from "styled-components";
import { margin } from "styled-system";
import { baseTheme } from "../../style/themes";

const StyledLoader = styled.div`
${margin}
text-align: center;
white-space: nowrap;
`;

StyledLoader.defaultProps = {
theme: baseTheme,
};

export default StyledLoader;

0 comments on commit 28f4656

Please sign in to comment.