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

FoldableCard: Allow custom action button icon #1670

Merged
merged 2 commits into from
Dec 17, 2015

Conversation

jordwest
Copy link
Contributor

This PR adds an icon prop which allows the FoldableCard action button icon to be changed. This will be used for a cog icon in #1126.

Examples

icon="arrow-down"

wordpress_com

#### `icon="cog"`

wordpress_com

### Why not use `actionButton` and `actionButtonExpanded` props?

Although the action button can already be overridden using the actionButton and actionButtonExpanded props, overriding those require that the user also recreates the button and Gridicon and apply appropriate classes. Overriding the default actionButton also removes the screen reader span element.

To get the same functionality, you'd need to do something like:

import Gridicon from 'components/gridicon';
   ...
<FoldableCard
  actionButton={
    <button disabled={ this.props.disabled } className="foldable-card__action foldable-card__expand" onClick={ clickAction }>
      <span className="screen-reader-text">{ this.translate( 'More' ) }</span>
      <Gridicon icon="arrow-down" size={ 24 } />
    </button>
  }
  actionButtonExpanded={
    <button disabled={ this.props.disabled } className="foldable-card__action foldable-card__expand" onClick={ clickAction }>
      <span className="screen-reader-text">{ this.translate( 'More' ) }</span>
      <Gridicon icon="arrow-up" size={ 24 } />
    </button>
  }
>
   ...
</FoldableCard>

With this change, the above can be achieved with:

<FoldableCard icon="arrow-down"> ... </FoldableCard>

This still applies the current CSS animation/transformation, so the icon will appear upside-down when the card is expanded.

@jordwest jordwest added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Components labels Dec 16, 2015
@jordwest jordwest self-assigned this Dec 16, 2015
@@ -31,6 +31,7 @@ render: function() {
##### Optional props
* `actionButton`: a component to substitute the regular expand button
* `actionButtonExpanded`: a component to substitute the regular expand button when the card is expanded. If not provided, we use `actionButton`
* `actionButtonIcon`: a string to set the Gridicon slug for the regular expand button. Defaults to `chevron-down`. Only applies when the `actionButton` or `actionButtonExpanded` props are not set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just use icon here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtias: 👍 much nicer. Changed in the latest commit

@aduth
Copy link
Contributor

aduth commented Dec 17, 2015

Looks good 👍

@aduth aduth added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 17, 2015
jordwest added a commit that referenced this pull request Dec 17, 2015
…on-button-icon

FoldableCard: Allow custom action button icon
@jordwest jordwest merged commit 6cfc5fb into master Dec 17, 2015
@jordwest jordwest deleted the add/foldablecard-custom-action-button-icon branch December 17, 2015 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Components [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants