import classNames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; import Box from '../box/box.jsx'; import Label from '../forms/label.jsx'; import Input from '../forms/input.jsx'; import BufferedInputHOC from '../forms/buffered-input-hoc.jsx'; import DirectionPicker from '../../containers/direction-picker.jsx'; import {injectIntl, intlShape, defineMessages, FormattedMessage} from 'react-intl'; import {STAGE_DISPLAY_SIZES} from '../../lib/layout-constants.js'; import {isWideLocale} from '../../lib/locale-utils.js'; import styles from './sprite-info.css'; import xIcon from './icon--x.svg'; import yIcon from './icon--y.svg'; import showIcon from './icon--show.svg'; import hideIcon from './icon--hide.svg'; const BufferedInput = BufferedInputHOC(Input); const messages = defineMessages({ spritePlaceholder: { id: 'gui.SpriteInfo.spritePlaceholder', defaultMessage: 'Name', description: 'Placeholder text for sprite name' } }); class SpriteInfo extends React.Component { shouldComponentUpdate (nextProps) { return ( this.props.rotationStyle !== nextProps.rotationStyle || this.props.disabled !== nextProps.disabled || this.props.name !== nextProps.name || this.props.stageSize !== nextProps.stageSize || this.props.visible !== nextProps.visible || // Only update these if rounded value has changed Math.round(this.props.direction) !== Math.round(nextProps.direction) || Math.round(this.props.size) !== Math.round(nextProps.size) || Math.round(this.props.x) !== Math.round(nextProps.x) || Math.round(this.props.y) !== Math.round(nextProps.y) ); } render () { const { stageSize } = this.props; const sprite = ( ); const showLabel = ( ); const sizeLabel = ( ); const labelAbove = isWideLocale(this.props.intl.locale); const spriteNameInput = ( ); const xPosition = (
{ (stageSize === STAGE_DISPLAY_SIZES.large) ?
: null }
); const yPosition = (
{ (stageSize === STAGE_DISPLAY_SIZES.large) ?
: null }
); if (stageSize === STAGE_DISPLAY_SIZES.small) { return (
{spriteNameInput}
{xPosition} {yPosition}
); } return (
{xPosition} {yPosition}
{ stageSize === STAGE_DISPLAY_SIZES.large ?
); } } SpriteInfo.propTypes = { direction: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), disabled: PropTypes.bool, intl: intlShape, name: PropTypes.string, onChangeDirection: PropTypes.func, onChangeName: PropTypes.func, onChangeRotationStyle: PropTypes.func, onChangeSize: PropTypes.func, onChangeX: PropTypes.func, onChangeY: PropTypes.func, onClickNotVisible: PropTypes.func, onClickVisible: PropTypes.func, onPressNotVisible: PropTypes.func, onPressVisible: PropTypes.func, rotationStyle: PropTypes.string, size: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), stageSize: PropTypes.oneOf(Object.keys(STAGE_DISPLAY_SIZES)).isRequired, visible: PropTypes.bool, x: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), y: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]) }; export default injectIntl(SpriteInfo);