Skip to content

Commit

Permalink
feat(Tile): add optional expand/collapse labels for chevron (#7199)
Browse files Browse the repository at this point in the history
* feat(Tile): add optional expand/collapse labels for chevron

* Update packages/react/src/components/Tile/Tile.js

Co-authored-by: emyarod <emyarod@users.noreply.github.com>

* fix(Tile): remove default props

* style(Tile): adjust positioning of chevron

* test(Tile): update PublicAPI snapshot

* style(Tile): remove flex-direction property

Co-authored-by: emyarod <emyarod@users.noreply.github.com>
Co-authored-by: Andrea N. Cardona <andreancardona@gmail.com>
  • Loading branch information
3 people authored Jan 19, 2021
1 parent da821e3 commit d45f466
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/components/src/components/tile/_tile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@

.#{$prefix}--tile__chevron {
position: absolute;
right: 0.5rem;
bottom: 0.5rem;
right: $carbon--spacing-05;
bottom: $carbon--spacing-05;
display: flex;
align-items: flex-end;
height: 1rem;

svg {
margin-left: $carbon--spacing-03;
transform-origin: center;
transition: $duration--fast-02 motion(standard, productive);
fill: $ui-05;
Expand Down
6 changes: 6 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5748,9 +5748,15 @@ Map {
"tileCollapsedIconText": Object {
"type": "string",
},
"tileCollapsedLabel": Object {
"type": "string",
},
"tileExpandedIconText": Object {
"type": "string",
},
"tileExpandedLabel": Object {
"type": "string",
},
},
},
"TileAboveTheFoldContent" => Object {
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/components/Tile/Tile-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const props = {
'Collapsed icon text (tileExpandedIconText)',
'Interact to Collapse tile'
),
tileCollapsedLabel: text('Collapsed icon text (tileCollapsedLabel)'),
tileExpandedLabel: text('Collapsed icon text (tileExpandedLabel)'),
handleClick: action('handleClick'),
light: boolean('Light variant (light)', false),
}),
Expand Down
17 changes: 15 additions & 2 deletions packages/react/src/components/Tile/Tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,20 @@ export class ExpandableTile extends Component {
*/
tileCollapsedIconText: PropTypes.string,

/**
* When "collapsed", a label to appear next to the chevron (e.g., "View more").
*/
tileCollapsedLabel: PropTypes.string,

/**
* The description of the "expanded" icon that can be read by screen readers.
*/
tileExpandedIconText: PropTypes.string,

/**
* When "expanded", a label to appear next to the chevron (e.g., "View less").
*/
tileExpandedLabel: PropTypes.string,
};

static defaultProps = {
Expand Down Expand Up @@ -546,8 +556,10 @@ export class ExpandableTile extends Component {
tileMaxHeight, // eslint-disable-line
tilePadding, // eslint-disable-line
handleClick, // eslint-disable-line
tileCollapsedIconText, // eslint-disable-line
tileExpandedIconText, // eslint-disable-line
tileCollapsedIconText,
tileExpandedIconText,
tileCollapsedLabel,
tileExpandedLabel,
onBeforeClick, // eslint-disable-line
light,
...other
Expand Down Expand Up @@ -599,6 +611,7 @@ export class ExpandableTile extends Component {
{childrenAsArray[0]}
</div>
<div className={`${prefix}--tile__chevron`}>
<span>{isExpanded ? tileExpandedLabel : tileCollapsedLabel}</span>
<ChevronDown16 />
</div>
<div className={`${prefix}--tile-content`}>{childrenAsArray[1]}</div>
Expand Down

0 comments on commit d45f466

Please sign in to comment.