Making WordPress.org


Ignore:
Timestamp:
03/01/2017 06:08:54 PM (7 years ago)
Author:
obenland
Message:

Plugin Directory: Update React client with latest changes.

This is largely a cleanup commit with some WIP around switching to node-wpapi.

File:
1 edited

Legend:

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

    r4223 r5024  
    1 import React from 'react';
     1/**
     2 * External dependencies.
     3 */
     4import React, { Component, PropTypes } from 'react';
     5import { identity } from 'lodash';
     6import { localize } from 'i18n-calypso';
    27
    3 export default React.createClass( {
    4     displayName: 'Stars',
     8export class Stars extends Component {
     9    static propTypes = {
     10        rating: PropTypes.number,
     11        translate: PropTypes.func,
     12    };
    513
    6     fillStars( rating ) {
    7         const template = '<span class="%1$s"></span>';
     14    static defaultProps = {
     15        rating: 0,
     16        translate: identity,
     17    };
     18
     19    /**
     20     * Returns filled stars representative of rating.
     21     *
     22     * @param {Number} rating Plugin rating.
     23     * @return {String} Rating stars.
     24     */
     25    fillStars = ( rating ) => {
    826        let counter = rating * 2,
    927            output = '',
     
    1331            switch ( counter ) {
    1432                case 0:
    15                     output += template.replace( '%1$s', 'dashicons dashicons-star-empty' );
     33                    output += '<span class="dashicons dashicons-star-empty"></span>';
    1634                    break;
    1735
    1836                case 1:
    19                     output += template.replace( '%1$s', 'dashicons dashicons-star-half' );
     37                    output += '<span class="dashicons dashicons-star-half"></span>';
    2038                    counter--;
    2139                    break;
    2240
    2341                default:
    24                     output += template.replace( '%1$s', 'dashicons dashicons-star-filled' );
     42                    output += '<span class="dashicons dashicons-star-filled"></span>';
    2543                    counter -= 2;
    2644            }
     
    2846
    2947        return output;
    30     },
     48    };
    3149
    3250    render() {
    33         const titleTemplate = '%s out of 5 stars',
    34             title = titleTemplate.replace( '%s', this.props.rating / 20 );
     51        const { rating, translate } = this.props;
     52        const stars =  Math.round( rating / 0.5 ) * 0.5;
    3553
    3654        return (
    3755            <div
    3856                className="wporg-ratings"
    39                 aria-label={ title }
    40                 data-title-template={ titleTemplate }
    41                 data-rating={ this.props.rating / 20 }
    42                 dangerouslySetInnerHTML={ { __html: this.fillStars( Math.round( this.props.rating / 10 ) / 2 ) } }
    43             ></div>
    44         )
     57                aria-label={ translate( '%(stars)s out of 5 stars', { args: { stars } } ) }
     58                dangerouslySetInnerHTML={ { __html: this.fillStars( stars ) } }
     59            />
     60        );
    4561    }
    46 } );
     62}
     63
     64export default localize( Stars );
Note: See TracChangeset for help on using the changeset viewer.