Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
feat: Add a barebones Card component.
Browse files Browse the repository at this point in the history
Closes #67.
  • Loading branch information
sarahmonster authored and tofumatt committed Aug 22, 2019
1 parent ee3776e commit f3764cc
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/components/ui/Card/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
A card is used to represent a descrete and self-contained piece of data, typically as part of a feed or series of related datum.

```jsx
import { Paragraph, Button, Heading, Tags } from '@octopusthink/nautilus';

<React.Fragment>
<Card title="Cards can be super simple">
<Heading level={3}>Cards should always have a title</Heading>
<Paragraph size="small">The Card can either have a title attribute, or you can pass it a heading. Not sure which is the best approach here.</Paragraph>
</Card>

</React.Fragment>
```
<Card orientation="landscape" title="Fish & Chips & Vinegar" metadata="Places I like to visit" media="http://placekitten.com/400/800"> <Paragraph size="small">By default, cards use a landscape orientation, but can also be swapped around. All content is optional.</Paragraph>
</Card>

<Card orientation="portrait" title="A card can go both ways" metadata="Horizontal, or vertical?" media="http://placekitten.com/800/400"> <Paragraph size="medium">An experimental project designed to vastly simplify and streamline the WordPress site building process for small business owners, by using technology to automate visual design decisions.</Paragraph>
</Card>

<Card orientation="landscape">
<Card.Header>
<img src="http://placekitten.com/400/800" />
<Heading>Fish & Chips & Vinegar</Heading>
<Tags><Tags.Tag>Places I like to visit</Tags.Tag></Tags>
</Card.Header>

<Paragraph size="small">By default, cards use a landscape orientation, but can also be swapped around. All content is optional.</Paragraph>

<Card.Footer>
<Button>Learn more</Button>
<Button minimal>Hide this</Button>
</Card.Footer>
</Card>
39 changes: 39 additions & 0 deletions src/components/ui/Card/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { css } from '@emotion/core';
import styled from '@emotion/styled';
import PropTypes from 'prop-types';
import React, { forwardRef } from 'react';

import { headingSmall, toUnits } from 'styles';
import { useTheme } from 'themes';

export const Card = (props) => {
const { children, ...otherProps } = props;
const theme = useTheme();

return (
<div
css={css`
background: white;
border: 1px solid ${theme.colors.neutral.grey200};
box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.25);
padding: ${toUnits(theme.spacing.padding.large)};
`}
{...otherProps}
>
{children}
</div>
);
};

Card.defaultProps = {
children: undefined,
};

Card.propTypes = {
/** @ignore */
children: PropTypes.node,
};

export const { defaultProps, propTypes } = Card;

export default Card;
37 changes: 37 additions & 0 deletions src/components/ui/Card/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';

import { axe, render } from 'utils/testing';

import Card from '.';

describe('Card', () => {
it('should render a <div>', () => {
const { container } = render(<Card>My Account</Card>);

expect(container.firstChild.tagName).toEqual('DIV');
});

it('should output its children', () => {
const { getByTestId } = render(
<Card>
<div data-testid="child" />
</Card>,
);

expect(getByTestId('child')).toBeDefined();
});

it('should output card CSS', () => {
const { container } = render(<Card>My Blog Posts</Card>);

expect(container.firstChild).toMatchSnapshot();
});

describe('accessibility', () => {
it('should pass aXe tests', async () => {
const { container } = render(<Card>My Blog Posts</Card>);

expect(await axe(container.innerHTML)).toHaveNoViolations();
});
});
});

0 comments on commit f3764cc

Please sign in to comment.