Making WordPress.org


Ignore:
Timestamp:
12/04/2016 05:14:43 PM (10 years ago)
Author:
obenland
Message:

Plugin Directory: Provide focus styles and context for favorite button.

Fixes #2294.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin/favorite-button/button.jsx

    r4223 r4467  
    11import React from 'react';
     2import { connect } from 'react-redux';
     3import includes from 'lodash/includes';
    24
    3 export default React.createClass( {
     5const FavoriteButton = React.createClass( {
    46        displayName: 'FavoriteButton',
    57
    6         getInitialState: function() {
    7                 return {
    8                         favorite: this.props.initialFavorite
    9                 };
    10         },
    11 
    128        toggleFavorite( event ) {
    13                 const component = this,
    14                         $button = jQuery( event.target );
     9                const $button = jQuery( event.target );
    1510
    1611                this.props.toggleFavorite( event );
    … …  
    1813                $button.addClass( 'is-animating' ).one( 'animationend', function() {
    1914                        $button.toggleClass( 'is-animating favorited' );
    20                         component.setState( { favorite: ! component.state.favorite } );
    2115                } );
    2216        },
    … …  
    2519                let classNames = [ 'plugin-favorite-heart' ];
    2620
    27                 if ( this.state.favorite ) {
     21                if ( this.props.favorite ) {
    2822                        classNames.push( 'favorited' );
    2923                }
    … …  
    3226                        <div className="plugin-favorite">
    3327                                <button type="button" className={ classNames.join( ' ' ) } onClick={ this.toggleFavorite } >
    34                                         <span className="screen-reader-text">{ `Favorite ${ this.props.plugin.name }` }</span>
     28                                        <span className="screen-reader-text">
     29                                                { this.props.favorite
     30                                                        ? `Unfavorite ${ this.props.plugin.name }`
     31                                                        : `Favorite ${ this.props.plugin.name }`
     32                                                }
     33                                        </span>
    3534                                </button>
    3635                        </div>
    … …  
    3837        }
    3938} );
     39
     40export default connect(
     41        ( state, { plugin } ) => ( {
     42                favorite: includes( state.favorites, plugin.slug )
     43        } ),
     44)( FavoriteButton );
Note: See TracChangeset for help on using the changeset viewer.