Skip to content

Commit

Permalink
feat(accordion): add align prop to component and skeleton to change h…
Browse files Browse the repository at this point in the history
…eading alignment (#4754)
  • Loading branch information
jendowns authored and asudoh committed Dec 5, 2019
1 parent 5b9c3b3 commit 4b257cb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
14 changes: 14 additions & 0 deletions packages/components/src/components/accordion/_accordion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@
}
}

.#{$prefix}--accordion--start .#{$prefix}--accordion__heading {
// Reverse `$accordion-flex-direction` token:
flex-direction: row;
}

.#{$prefix}--accordion--start .#{$prefix}--accordion__arrow {
// Alters `$accordion-arrow-margin` token:
margin: 2px 0 0 $carbon--spacing-03;
}

.#{$prefix}--accordion--start .#{$prefix}--accordion__content {
margin-left: $carbon--spacing-06;
}

.#{$prefix}--accordion__item--collapsing .#{$prefix}--accordion__content,
.#{$prefix}--accordion__item--expanding .#{$prefix}--accordion__content {
display: block;
Expand Down
20 changes: 18 additions & 2 deletions packages/react/src/components/Accordion/Accordion-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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 {
withKnobs,
boolean,
number,
select,
text,
} from '@storybook/addon-knobs';
import {
default as Accordion,
AccordionItem,
Expand All @@ -28,7 +34,12 @@ storiesOf('Accordion', module)
.add(
'Default',
() => (
<Accordion>
<Accordion
align={select(
'Accordion heading alignment (align)',
['start', 'end'],
'end'
)}>
<AccordionItem
title={text('The title (title)', 'Section 1 title')}
open={boolean('Open the section (open)', false)}
Expand Down Expand Up @@ -80,6 +91,11 @@ storiesOf('Accordion', module)
() => (
<div style={{ width: '500px' }}>
<AccordionSkeleton
align={select(
'Accordion heading alignment (align)',
['start', 'end'],
'end'
)}
open={boolean('Show first item opened (open)', true)}
count={number('Set number of items (count)', 4)}
/>
Expand Down
12 changes: 10 additions & 2 deletions packages/react/src/components/Accordion/Accordion.Skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import deprecate from '../../prop-types/deprecate';

const { prefix } = settings;

function AccordionSkeleton({ open, count, className, ...rest }) {
const classes = cx(`${prefix}--accordion`, `${prefix}--skeleton`, className);
function AccordionSkeleton({ align, open, count, className, ...rest }) {
const classes = cx(`${prefix}--accordion`, `${prefix}--skeleton`, className, {
[`${prefix}--accordion--${align}`]: align,
});
const numSkeletonItems = open ? count - 1 : count;
return (
<ul className={classes} {...rest}>
Expand Down Expand Up @@ -61,11 +63,17 @@ AccordionSkeleton.propTypes = {
* Specify an optional className to add.
*/
className: PropTypes.string,

/**
* Specify the alignment of the accordion heading title and chevron.
*/
align: PropTypes.oneOf(['start', 'end']),
};

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

function AccordionSkeletonItem() {
Expand Down
15 changes: 13 additions & 2 deletions packages/react/src/components/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ import React from 'react';

const { prefix } = settings;

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

Accordion.defaultProps = {
align: 'end',
};

Accordion.propTypes = {
/**
* Pass in the children that will be rendered within the Accordion
Expand All @@ -31,6 +37,11 @@ Accordion.propTypes = {
* Specify an optional className to be applied to the container node
*/
className: PropTypes.string,

/**
* Specify the alignment of the accordion heading title and chevron.
*/
align: PropTypes.oneOf(['start', 'end']),
};

export default Accordion;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

exports[`Accordion should render 1`] = `
<Accordion
align="end"
className="extra-class"
>
<ul
className="bx--accordion extra-class"
className="bx--accordion extra-class bx--accordion--end"
>
<AccordionItem
className="child"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

exports[`AccordionSkeleton should render 1`] = `
<AccordionSkeleton
align="end"
count={4}
open={true}
>
<ul
className="bx--accordion bx--skeleton"
className="bx--accordion bx--skeleton bx--accordion--end"
>
<li
className="bx--accordion__item bx--accordion__item--active"
Expand Down

0 comments on commit 4b257cb

Please sign in to comment.