Skip to content

Commit

Permalink
Merge branch 'master' into 2042_search-button-styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Jen Downs authored Jul 2, 2019
2 parents f255b73 + 74656d8 commit d742b13
Show file tree
Hide file tree
Showing 18 changed files with 975 additions and 429 deletions.
3 changes: 2 additions & 1 deletion packages/cli/src/commands/ci-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function check(args, env) {
stdio: 'inherit',
};
const tasks = [
'yarn format:diff --loglevel=silent',
'yarn format:diff',
'yarn lint --quiet',
`yarn bundler check --ignore '**/@(node_modules|examples|components|react)/**' 'packages/**/*.scss'`,
`cross-env BABEL_ENV=test yarn test --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
Expand All @@ -39,6 +39,7 @@ async function check(args, env) {
} catch (error) {
console.log(error.stdout);
console.log(error.stderr);
console.log(error);
process.exit(1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/components/docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -4081,7 +4081,7 @@ $carbon--theme--g90: (
disabled-01: #3d3d3d,
disabled-02: #565656,
disabled-03: #8c8c8c,
highlight: #061f80,
highlight: #054ada,
skeleton-01: #353535,
skeleton-02: #565656,
brand-01: #0062ff,
Expand Down Expand Up @@ -4156,7 +4156,7 @@ $carbon--theme--g100: (
disabled-01: #282828,
disabled-02: #3d3d3d,
disabled-03: #6f6f6f,
highlight: #061f80,
highlight: #0530ad,
skeleton-01: #353535,
skeleton-02: #3d3d3d,
brand-01: #0062ff,
Expand Down
8 changes: 5 additions & 3 deletions packages/react/src/components/Accordion/Accordion-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { withKnobs, boolean, number, text } from '@storybook/addon-knobs';
import Accordion from '../Accordion';
import AccordionItem from '../AccordionItem';
import {
default as Accordion,
AccordionItem,
AccordionSkeleton,
} from '../Accordion';
import Select from '../Select';
import SelectItem from '../SelectItem';
import AccordionSkeleton from '../Accordion/Accordion.Skeleton';

const props = {
onClick: action('onClick'),
Expand Down
69 changes: 0 additions & 69 deletions packages/react/src/components/Accordion/Accordion-test.js

This file was deleted.

42 changes: 21 additions & 21 deletions packages/react/src/components/Accordion/Accordion.Skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@

import PropTypes from 'prop-types';
import React from 'react';
import SkeletonText from '../SkeletonText';
import { ChevronRight16 } from '@carbon/icons-react';
import { settings } from 'carbon-components';
import SkeletonText from '../SkeletonText';
import deprecate from '../../prop-types/deprecate';

const { prefix } = settings;

export default function AccordionSkeleton(props) {
const Item = () => (
<li className={`${prefix}--accordion__item`}>
<button type="button" className={`${prefix}--accordion__heading`}>
<ChevronRight16 className={`${prefix}--accordion__arrow`} />
<SkeletonText className={`${prefix}--accordion__title`} />
</button>
</li>
);
function AccordionSkeleton(props) {
const numSkeletonItems = props.open ? props.count - 1 : props.count;
return (
<ul className={`${prefix}--accordion ${prefix}--skeleton`}>
{props.open ? (
{props.open && (
<li
className={`${prefix}--accordion__item ${prefix}--accordion__item--active`}>
<button type="button" className={`${prefix}--accordion__heading`}>
Expand All @@ -37,15 +31,9 @@ export default function AccordionSkeleton(props) {
<SkeletonText width="95%" />
</div>
</li>
) : (
<Item />
)}
{Array.from({
length: props.count
? props.count - 1
: AccordionSkeleton.defaultProps.count,
}).map((v, i) => (
<Item key={`skeleton-accordion-item-${props.uid}-${i}`} />
{Array.from({ length: numSkeletonItems }).map((_, i) => (
<AccordionSkeletonItem key={i} />
))}
</ul>
);
Expand All @@ -65,11 +53,23 @@ AccordionSkeleton.propTypes = {
/**
* Set unique identifier to generate unique item keys
*/
uid: PropTypes.any,
uid: deprecate(PropTypes.any),
};

AccordionSkeleton.defaultProps = {
open: true,
count: 4,
uid: '',
};

function AccordionSkeletonItem() {
return (
<li className={`${prefix}--accordion__item`}>
<button type="button" className={`${prefix}--accordion__heading`}>
<ChevronRight16 className={`${prefix}--accordion__arrow`} />
<SkeletonText className={`${prefix}--accordion__title`} />
</button>
</li>
);
}

export default AccordionSkeleton;
12 changes: 6 additions & 6 deletions packages/react/src/components/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
* 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';
import classnames from 'classnames';
import { settings } from 'carbon-components';

const { prefix } = settings;

const Accordion = ({ children, className, ...other }) => {
const classNames = classnames(`${prefix}--accordion`, className);
function Accordion({ children, className: customClassName, ...rest }) {
const className = cx(`${prefix}--accordion`, customClassName);
return (
<ul {...other} className={classNames}>
<ul className={className} {...rest}>
{children}
</ul>
);
};
}

Accordion.propTypes = {
/**
Expand Down
121 changes: 121 additions & 0 deletions packages/react/src/components/Accordion/AccordionItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* 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 { ChevronRight16 } from '@carbon/icons-react';
import { settings } from 'carbon-components';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React, { useEffect, useState } from 'react';
import { match, keys } from '../../internal/keyboard';

const { prefix } = settings;
const defaultRenderExpando = props => <button {...props} />;

function AccordionItem({
children,
className: customClassName,
iconDescription = 'Expand/Collapse',
open = false,
onHeadingClick,
renderExpando: Expando = defaultRenderExpando,
title = 'title',
...rest
}) {
const [isOpen, setIsOpen] = useState(open);
const className = cx({
[`${prefix}--accordion__item`]: true,
[`${prefix}--accordion__item--active`]: isOpen,
[customClassName]: !!customClassName,
});

useEffect(() => {
setIsOpen(open);
}, [open]);

// When the AccordionItem heading is clicked, toggle the open state of the
// panel
function onClick(event) {
const nextValue = !isOpen;
setIsOpen(nextValue);
if (onHeadingClick) {
// TODO: normalize signature, potentially:
// onHeadingClick :: (event: Event, state: { isOpen: Boolean }) => any
onHeadingClick({ isOpen: nextValue, event });
}
}

// If the AccordionItem is open, and the user hits the ESC key, then close it
function onKeyDown(event) {
if (isOpen && match(event, keys.Escape)) {
setIsOpen(false);
}
}

return (
<li className={className} {...rest}>
<Expando
aria-expanded={isOpen}
className={`${prefix}--accordion__heading`}
onClick={onClick}
onKeyDown={onKeyDown}
title={iconDescription}
type="button">
<ChevronRight16
aria-label={iconDescription}
className={`${prefix}--accordion__arrow`}
/>
<div className={`${prefix}--accordion__title`}>{title}</div>
</Expando>
<div className={`${prefix}--accordion__content`}>{children}</div>
</li>
);
}

AccordionItem.propTypes = {
/**
* Provide the contents of your AccordionItem
*/
children: PropTypes.node,

/**
* Specify an optional className to be applied to the container node
*/
className: PropTypes.string,

/**
* The accordion title.
*/
title: PropTypes.node,

/**
* The callback function to render the expando button.
* Can be a React component class.
*/
renderExpando: PropTypes.func,

/**
* The description of the expando icon.
*/
iconDescription: PropTypes.string,

/**
* `true` to open the expando.
*/
open: PropTypes.bool,

/**
* The handler of the massaged `click` event.
*/
onClick: PropTypes.func,

/**
* The handler of the massaged `click` event on the heading.
*/
onHeadingClick: PropTypes.func,
};

export default AccordionItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* 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 { mount } from 'enzyme';
import React from 'react';
import { default as Accordion, AccordionItem } from '../';

describe('Accordion', () => {
it('should render', () => {
const wrapper = mount(
<Accordion className="extra-class">
<AccordionItem className="child" title="Heading A">
Panel A
</AccordionItem>
<AccordionItem className="child" title="Heading B">
Panel B{' '}
</AccordionItem>
<AccordionItem className="child" title="Heading C">
Panel C
</AccordionItem>
</Accordion>
);

expect(wrapper).toMatchSnapshot();
});
});
Loading

0 comments on commit d742b13

Please sign in to comment.