Making WordPress.org

Changeset 4467


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

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

Fixes #2294.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins
Files:
6 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 );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin/favorite-button/index.jsx

    r4223 r4467  
    11import React from 'react';
    2 import { connect } from 'react-redux';
    3 import includes from 'lodash/includes';
    42
    53import FavoriteButton from './button';
     
    108} from 'actions/index';
    119
    12 const FavoriteButtonContainer = React.createClass( {
     10export default React.createClass( {
    1311    componentDidMount() {
    1412        this.getFavorites();
     
    3432
    3533    render() {
    36         return <FavoriteButton { ...this.props } toggleFavorite={ this.toggleFavorite } />;
     34        return <FavoriteButton toggleFavorite={ this.toggleFavorite } />;
    3735    }
    3836} );
    39 
    40 const mapStateToProps = ( state, ownProps ) => ( {
    41     initialFavorite: includes( state.favorites, ownProps.plugin.slug )
    42 } );
    43 
    44 export default connect( mapStateToProps )( FavoriteButtonContainer );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin/favorite-button/style.scss

    r4224 r4467  
    6969        }
    7070
     71        &:focus {
     72            outline: thin dotted;
     73        }
     74
    7175        &:hover,
    7276        &:focus {
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/css/style-rtl.css

    r4466 r4467  
    21712171}
    21722172
     2173.plugin-favorite .plugin-favorite-heart:focus {
     2174  outline: thin dotted;
     2175}
     2176
    21732177.plugin-favorite .plugin-favorite-heart:hover, .plugin-favorite .plugin-favorite-heart:focus {
    21742178  text-decoration: none;
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/css/style.css

    r4466 r4467  
    21712171}
    21722172
     2173.plugin-favorite .plugin-favorite-heart:focus {
     2174  outline: thin dotted;
     2175}
     2176
    21732177.plugin-favorite .plugin-favorite-heart:hover, .plugin-favorite .plugin-favorite-heart:focus {
    21742178  text-decoration: none;
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php

    r4410 r4467  
    6868            if ( is_user_logged_in() ) :
    6969                $url = Template::get_favourite_link( $post );
     70                $is_favorited = Tools::favorited_plugin( $post );
    7071                ?>
    7172                <div class="plugin-favorite">
    72                     <a href="<?php echo esc_url( $url ); ?>" class="plugin-favorite-heart<?php echo Tools::favorited_plugin( $post ) ? ' favorited' : ''; ?>"></a>
     73                    <a href="<?php echo esc_url( $url ); ?>" class="plugin-favorite-heart<?php echo $is_favorited ? ' favorited' : ''; ?>">
     74                        <span class="screen-reader-text">
     75                            <?php printf( $is_favorited ? __( 'Favorite %s' ) : __( 'Unfavorite %s' ), get_the_title() ); ?>
     76                        </span>
     77                    </a>
    7378                    <script>
    7479                        jQuery( '.plugin-favorite-heart' )
Note: See TracChangeset for help on using the changeset viewer.