Skip to content
Merged
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
2 changes: 1 addition & 1 deletion example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const App = () => {
<em>Media.Item</em>
</small>
<img
src="https://source.unsplash.com/64x64/daily"
src="https://source.unsplash.com/random/64x64"
alt="Unsplash daily"
/>
</Media.Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { mount, shallow } from 'enzyme';

import { TestComponent } from '../../../setupTests';
import Entry from './';
import Entry from './Entry';

describe('<Entry />', () => {
it('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import React from 'react';
import React, { Fragment } from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is currently an issue with TypeScript and Fragments that I cannot track down, but using <> is not working nicely: microsoft/TypeScript#35392

import PropTypes from 'prop-types';

import styles from './Entry.module.css';

interface EntryProps extends React.HTMLAttributes<HTMLDivElement> {
children: React.ReactNode; // the `children` prop is required
entryPercentWidth?: number;
gutter?: number | string;
}

/**
This component should only be used by the Grid component.
It has no public API.
*/
const Entry = ({ children, entryPercentWidth, gutter, ...passedProps }) => {
const childProps = children.props || {};
const Entry: React.FC<EntryProps> = ({
children,
entryPercentWidth = 100,
gutter = 0,
...passedProps
}) => {
const c = children as React.ReactElement;
const childProps = c.props || {};
let { clear = false, colSpan = 1, offset = 0 } = childProps;
clear = !!clear && clear !== 'false';
colSpan = parseInt(colSpan, 10) || 1;
Expand All @@ -25,7 +37,7 @@ const Entry = ({ children, entryPercentWidth, gutter, ...passedProps }) => {
padding: gutter,
}}
>
{React.cloneElement(children, {
{React.cloneElement(c, {
clear: undefined,
colSpan: undefined,
offset: undefined,
Expand All @@ -35,10 +47,10 @@ const Entry = ({ children, entryPercentWidth, gutter, ...passedProps }) => {

if (clear) {
return (
<>
<Fragment>
<div className={styles.Clear} />
{entry}
</>
</Fragment>
);
}

Expand Down
1 change: 1 addition & 0 deletions src/components/Grid/Entry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Entry';
12 changes: 8 additions & 4 deletions src/components/Grid/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ storiesOf('Dark Matter/Grid', module)
.add(
'Overview',
() => (
<Grid gutter={text('gutter', '20px')} columns={number('columns', 3)}>
<Grid
className="p-4"
gutter={text('gutter', '20px')}
columns={number('columns', 3)}
>
<span
colSpan={number('colSpan (entry 1)', 1)}
offset={number('offset (entry 1)', 0)}
style={{ background: 'white' }}
className="bg-white shadow rounded p-6"
>
Sam
</span>
<span
style={{ background: 'white' }}
className="bg-white shadow rounded p-6"
clear={boolean('clear (entry 2)', false)}
>
Pat
</span>
<span style={{ background: 'white' }}>Taylor</span>
<span className="bg-white shadow rounded p-6">Taylor</span>
</Grid>
),
{
Expand Down