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
147 changes: 147 additions & 0 deletions packages/react/src/components/Grid/Column.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
* 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 { settings } from 'carbon-components';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

const { prefix } = settings;

function Column({
as: BaseComponent = 'div',
children,
className: containerClassName,
sm,
md,
lg,
xlg,
max,
...rest
}) {
const columnClassName = getClassNameForBreakpoints([sm, md, lg, xlg, max]);
const className = cx(containerClassName, columnClassName, {
[`${prefix}--col`]: columnClassName.length === 0,
joshblack marked this conversation as resolved.
Show resolved Hide resolved
});

return (
<BaseComponent className={className} {...rest}>
{children}
</BaseComponent>
);
}

const spanPropType = PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
span: PropTypes.number,
joshblack marked this conversation as resolved.
Show resolved Hide resolved
offset: PropTypes.number,
}),
]);

Column.propTypes = {
/**
* Provide a custom element to render instead of the default <div>
*/
as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),

/**
* Specify column span for the `sm` breakpoint (Default breakpoint up to 672px)
* This breakpoint supports 4 columns by default.
*
* @see https://www.carbondesignsystem.com/guidelines/layout#breakpoints
*/
sm: spanPropType,

/**
* Specify column span for the `md` breakpoint (Default breakpoint up to 1056px)
* This breakpoint supports 8 columns by default.
*
* @see https://www.carbondesignsystem.com/guidelines/layout#breakpoints
*/
md: spanPropType,

/**
* Specify column span for the `lg` breakpoint (Default breakpoint up to 1312px)
* This breakpoint supports 16 columns by default.
*
* @see https://www.carbondesignsystem.com/guidelines/layout#breakpoints
*/
lg: spanPropType,

/**
* Specify column span for the `xlg` breakpoint (Default breakpoint up to
* 1584px) This breakpoint supports 16 columns by default.
*
* @see https://www.carbondesignsystem.com/guidelines/layout#breakpoints
*/
xlg: spanPropType,

/**
* Specify column span for the `max` breakpoint. This breakpoint supports 16
* columns by default.
*
* @see https://www.carbondesignsystem.com/guidelines/layout#breakpoints
*/
max: spanPropType,

/**
* Specify a custom className to be applied to the `Column`
*/
className: PropTypes.string,

/**
* Pass in content that will be rendered within the `Column`
*/
children: PropTypes.node,
};

const breakpointNames = ['sm', 'md', 'lg', 'xlg', 'max'];

/**
* @typedef {object} Breakpoint
* @property {number} [span]
* @property {number} [offset]
joshblack marked this conversation as resolved.
Show resolved Hide resolved
*/

/**
* Build the appropriate className for the given set of breakpoints.
* @param {Array<number|Breakpoint>} breakpoints
joshblack marked this conversation as resolved.
Show resolved Hide resolved
* @returns {string}
*/
function getClassNameForBreakpoints(breakpoints) {
const classNames = [];

for (let i = 0; i < breakpoints.length; i++) {
const breakpoint = breakpoints[i];
if (!breakpoint) {
continue;
}

const name = breakpointNames[i];

// 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') {
classNames.push(`${prefix}--col-${name}-${breakpoint}`);
continue;
}

const { span, offset } = breakpoint;
joshblack marked this conversation as resolved.
Show resolved Hide resolved
if (typeof span === 'number') {
classNames.push(`${prefix}--col-${name}-${span}`);
}

if (typeof offset === 'number') {
classNames.push(`${prefix}--offset-${name}-${offset}`);
}
}

return classNames.join(' ');
}

export default Column;
Loading