import {FormattedMessage, intlShape, defineMessages} from 'react-intl'; import PropTypes from 'prop-types'; import React from 'react'; import Box from '../box/box.jsx'; import PlayButton from '../../containers/play-button.jsx'; import styles from './library-item.css'; import classNames from 'classnames'; import bluetoothIconURL from './bluetooth.svg'; import internetConnectionIconURL from './internet-connection.svg'; import favoriteInactiveIcon from './favorite-inactive.svg'; import favoriteActiveIcon from './favorite-active.svg'; const messages = defineMessages({ favorite: { defaultMessage: 'Favorite', description: 'Alt text of icon in costume, sound, and extension libraries to mark an item as favorite.', id: 'tw.favorite' }, unfavorite: { defaultMessage: 'Unfavorite', description: 'Alt text of icon in costume, sound, and extension libraries to unmark an item as favorite.', id: 'tw.unfavorite' } }); /* eslint-disable react/prefer-stateless-function */ class LibraryItemComponent extends React.PureComponent { render () { const favoriteMessage = this.props.intl.formatMessage( this.props.favorite ? messages.unfavorite : messages.favorite ); const favorite = ( ); return this.props.featured ? (
{this.props.disabled ? (
) : null}
{this.props.insetIconURL ? (
) : null}
{this.props.name}
{this.props.description}
{(this.props.docsURI || this.props.samples) && (
{this.props.docsURI && ( )} {this.props.samples && ( )}
)} {this.props.credits && this.props.credits.length > 0 && (
{' '} {this.props.credits.map((credit, index) => ( {credit} {index !== this.props.credits.length - 1 && ( ', ' )} ))}
)} {this.props.bluetoothRequired || this.props.internetConnectionRequired || this.props.collaborator ? (
{this.props.bluetoothRequired || this.props.internetConnectionRequired ? (
{this.props.bluetoothRequired ? ( ) : null} {this.props.internetConnectionRequired ? ( ) : null}
) : null}
{this.props.collaborator ? (
{this.props.collaborator}
) : null}
) : null} {favorite}
) : ( {/* Layers of wrapping is to prevent layout thrashing on animation */} {this.props.name} {this.props.showPlayButton ? ( ) : null} {favorite} ); } } /* eslint-enable react/prefer-stateless-function */ LibraryItemComponent.propTypes = { intl: intlShape, bluetoothRequired: PropTypes.bool, collaborator: PropTypes.string, description: PropTypes.oneOfType([ PropTypes.string, PropTypes.node ]), disabled: PropTypes.bool, extensionId: PropTypes.string, featured: PropTypes.bool, hidden: PropTypes.bool, iconURL: PropTypes.string, insetIconURL: PropTypes.string, internetConnectionRequired: PropTypes.bool, isPlaying: PropTypes.bool, name: PropTypes.oneOfType([ PropTypes.string, PropTypes.node ]), credits: PropTypes.arrayOf(PropTypes.oneOfType([ PropTypes.string, PropTypes.node ])), docsURI: PropTypes.string, samples: PropTypes.arrayOf(PropTypes.shape({ href: PropTypes.string, text: PropTypes.string })), favorite: PropTypes.bool, onFavorite: PropTypes.func, onBlur: PropTypes.func.isRequired, onClick: PropTypes.func.isRequired, onFocus: PropTypes.func.isRequired, onKeyPress: PropTypes.func.isRequired, onMouseEnter: PropTypes.func.isRequired, onMouseLeave: PropTypes.func.isRequired, onPlay: PropTypes.func.isRequired, onStop: PropTypes.func.isRequired, showPlayButton: PropTypes.bool }; LibraryItemComponent.defaultProps = { disabled: false, showPlayButton: false }; export default LibraryItemComponent;