Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #625 - Add support for the className prop for the Column component #626

Merged
merged 2 commits into from
Sep 10, 2020
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
9 changes: 8 additions & 1 deletion packages/matchbox/src/components/Column/Column.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import { display } from 'styled-system';
import { createPropTypes } from '@styled-system/prop-types';
import { ColumnsContext } from '../Columns/context';
import styled from 'styled-components';
import { Box } from '../Box';
import { gutter } from './styles';

const StyledColumn = styled(Box)`
${display}
${gutter}

&:first-child {
Expand All @@ -14,7 +17,7 @@ const StyledColumn = styled(Box)`
`;

const Column = React.forwardRef(function Column(props, ref) {
const { width, children } = props;
const { width, children, className, display } = props;
const { space, collapsed } = React.useContext(ColumnsContext);

let columnWidth = width;
Expand All @@ -29,6 +32,8 @@ const Column = React.forwardRef(function Column(props, ref) {

return (
<StyledColumn
display={display}
className={className}
width={columnWidth}
flex={!width && !collapsed ? '1' : ''}
pt={collapsed ? space : null}
Expand All @@ -46,6 +51,8 @@ Column.displayName = 'Column';
Column.propTypes = {
children: PropTypes.node,
width: PropTypes.oneOfType([PropTypes.oneOf(['content']), PropTypes.number]),
className: PropTypes.string,
Copy link
Contributor

@jonambas jonambas Sep 9, 2020

Choose a reason for hiding this comment

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

I think this works. For your use case you could expose display

import { display } from 'styled-system`;
import { createPropTypes } from '@styled-system/prop-types';

...


const { width, children, className, display } = props;

...

<StyledColumn display={display} />

...

Column.propTypes = {
  ...createPropTypes(display.propNames),
}

Copy link
Contributor

Choose a reason for hiding this comment

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

styled(Box) already includes display so no need to add it to the StyledColumn declaration

...createPropTypes(display.propNames),
};

export default Column;
16 changes: 16 additions & 0 deletions packages/matchbox/src/components/Column/tests/Column.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,20 @@ describe('Columns', () => {
expect(wrapper.find('div').at(3)).toHaveStyleRule('width', `${100 * (2 / 6)}%`);
expect(wrapper.find('div').at(4)).toHaveStyleRule('width', `${100 * (3 / 6)}%`);
});

it('accepts a passed in className', () => {
const wrapper = subject({ className: 'foo' });

expect(wrapper.find('.foo')).toExist();
});

it('accepts passed the passed in `display` prop', () => {
const wrapper = global.mountStyled(
<Columns>
<Column display="none" />
</Columns>,
);

expect(wrapper.find('div').at(2)).toHaveStyleRule('display', 'none');
});
});