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

Grid component react #4894

Merged
merged 42 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
20e4bb3
feat(grid): add hiding columns with width 0
zachhardesty7 Aug 15, 2019
1290f60
docs(grid): add example of hiding columns
zachhardesty7 Aug 15, 2019
6a746be
docs(grid): fix incorrect `bleed` info and typos
zachhardesty7 Aug 15, 2019
031d46a
docs(grid): add link to live demo website
zachhardesty7 Aug 15, 2019
cd46e13
feat(grid): implement functional React component
zachhardesty7 Aug 15, 2019
176d0a9
chore(grid): add generated files
zachhardesty7 Oct 3, 2019
0d8c4ad
fix(docs): storybook support load CSF & add sort
zachhardesty7 Oct 7, 2019
203655c
docs(Grid): update valid props
zachhardesty7 Oct 7, 2019
e9020ac
docs(Grid): add initial story & style margins
zachhardesty7 Oct 7, 2019
9de2fd2
docs(Grid): clean up doc styles & knob controls
zachhardesty7 Nov 11, 2019
1c84f6a
docs(Grid): add color knobs, pass thru params
zachhardesty7 Nov 12, 2019
ae19981
docs(Grid): fix minor fullwidth disp bug
zachhardesty7 Nov 12, 2019
af7b92e
test(Grid): add smoke tests for root el
zachhardesty7 Nov 12, 2019
fd48342
test(Grid): add basic row and col tests
zachhardesty7 Dec 16, 2019
302fd8a
test(Grid): fix wrappers & update index snapshot
zachhardesty7 Dec 16, 2019
a54fc63
feat(Grid): use layout's breakpoints
zachhardesty7 Dec 16, 2019
7e5d938
chore(Grid): port all tests, add 'as' prop
zachhardesty7 Dec 16, 2019
0a945ff
docs(Grid): include stories from #3892
zachhardesty7 Dec 17, 2019
acd0d48
feat(Grid): support obj syntax & rm offset props
zachhardesty7 Dec 28, 2019
35d8769
fix(Grid): add missing @carbon/layout pkg
zachhardesty7 Jan 11, 2020
021e1a0
feat(Grid): rm `noGutter` prop for later PR
zachhardesty7 Jan 12, 2020
573727e
chore(Grid): revert storybook to 5.2.1
zachhardesty7 Jan 12, 2020
279bc1d
chore(Grid): convert to recommended syntax
zachhardesty7 Jan 12, 2020
179e50b
chore(Grid): inline array gen helper
zachhardesty7 Jan 12, 2020
d591165
fix(Grid): update incorrect prop types
zachhardesty7 Jan 15, 2020
d12c3ef
chore(Grid): update import format
zachhardesty7 Jan 15, 2020
9afd776
Revert sass.md
zachhardesty7 Jan 15, 2020
d6e6bf9
Revert _mixins.scss
zachhardesty7 Jan 15, 2020
54d56d5
Revert App.js
zachhardesty7 Jan 15, 2020
0017c8f
refactor(grid): split out files and update Column
joshblack Jan 21, 2020
ee23e15
refactor(grid): update test suite for grid components
joshblack Jan 22, 2020
8384714
docs(grid): update story for grid
joshblack Jan 22, 2020
9c65ae4
Merge branch 'master' of github.com:carbon-design-system/carbon into …
joshblack Jan 22, 2020
0833e0b
fix(react): update entrypoint with grid components
joshblack Jan 22, 2020
898df9e
fix(grid): convert story offset to prop obj
zachhardesty7 Jan 22, 2020
520e9aa
fix(react): update with missing prop values
joshblack Jan 27, 2020
36b923e
Merge branch 'master' of github.com:carbon-design-system/carbon into …
joshblack Jan 27, 2020
5bbab2b
Merge branch 'master' into grid-component-react
joshblack Jan 27, 2020
e65f750
chore(project): sync offline mirror
joshblack Jan 27, 2020
3efc941
Merge branch 'grid-component-react' of github.com:zachhardesty7/carbo…
joshblack Jan 27, 2020
95d3135
Merge branch 'master' into grid-component-react
joshblack Jan 27, 2020
34c2cbf
Merge branch 'master' into grid-component-react
joshblack Jan 29, 2020
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
8 changes: 8 additions & 0 deletions packages/react/src/components/Grid/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function Column({
}

const spanPropType = PropTypes.oneOfType([
PropTypes.bool,
PropTypes.number,
PropTypes.shape({
span: PropTypes.number,
joshblack marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -124,6 +125,13 @@ function getClassNameForBreakpoints(breakpoints) {

const name = breakpointNames[i];

// If our breakpoint is a boolean, the user has specified that the column
// should be "auto" at this size
if (typeof breakpoint === 'boolean') {
joshblack marked this conversation as resolved.
Show resolved Hide resolved
classNames.push(`${prefix}--col-${name}`);
joshblack marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

// If our breakpoint is a number, the user has specified the number of
// columns they'd like this column to span
if (typeof breakpoint === 'number') {
Expand Down
255 changes: 0 additions & 255 deletions packages/react/src/components/Grid/Grid-test.js

This file was deleted.

108 changes: 108 additions & 0 deletions packages/react/src/components/Grid/__tests__/Column-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { render, cleanup } from '@carbon/test-utils/react';
import { settings } from 'carbon-components';
import React from 'react';
import { Column } from '../';

const { prefix } = settings;

describe('Column', () => {
afterEach(cleanup);

it('should support a custom element as the root node', () => {
const { container } = render(<Column as="section" />);
expect(container.firstChild.tagName).toBe('SECTION');
});

it('should include a custom className', () => {
const { container } = render(<Column className="test" />);
expect(container.firstChild.classList.contains('test')).toBe(true);
});

it('should pass un-used props to the top-level node that is rendered', () => {
const { container } = render(<Column id="test" />);
expect(container.firstChild.getAttribute('id')).toBe('test');
});

it('should render `children` that are given', () => {
const { container } = render(
<Column>
<span id="test">Test</span>
</Column>
);
const testNode = container.querySelector('#test');
expect(testNode).toBeInstanceOf(HTMLElement);
});

it('should default to rendering a column that auto-spans', () => {
const { container } = render(<Column />);
expect(container.firstChild.classList.contains(`${prefix}--col`)).toBe(
true
);
});

it('should set the column span per breakpoint with a number', () => {
const breakpoints = ['sm', 'md', 'lg', 'xlg', 'max'];
const spans = [1, 2, 3, 4, 5];
const props = {};

for (let i = 0; i < breakpoints.length; i++) {
const name = breakpoints[i];
props[name] = spans[i];
}

const { container } = render(<Column {...props} />);
const { firstChild: column } = container;

for (let i = 0; i < column.classList.length; i++) {
const name = breakpoints[i];
const span = spans[i];
const className = column.classList[i];
expect(className).toEqual(expect.stringContaining(`col-${name}-${span}`));
}
});

it('should set the column span to auto if a boolean is provided for a breakpoint', () => {
joshblack marked this conversation as resolved.
Show resolved Hide resolved
const breakpoints = ['sm', 'md', 'lg', 'xlg', 'max'];
const props = {};

for (let i = 0; i < breakpoints.length; i++) {
const name = breakpoints[i];
props[name] = true;
}

const { container } = render(<Column {...props} />);
const { firstChild: column } = container;
for (let i = 0; i < column.classList.length; i++) {
const name = breakpoints[i];
const className = column.classList[i];
expect(className).toEqual(expect.stringContaining(`col-${name}`));
}
});

it.each(['sm', 'md', 'lg', 'xlg', 'max'])(
'should support specifying column span and offset as an object for breakpoint %s',
breakpoint => {
const { container } = render(
React.createElement(Column, {
[breakpoint]: {
span: 1,
offset: 1,
},
})
);
expect(container.firstChild.className).toEqual(
expect.stringContaining(`col-${breakpoint}-1`)
);
expect(container.firstChild.className).toEqual(
expect.stringContaining(`offset-${breakpoint}-1`)
);
}
);
});
Loading