UNPKG

apeman-react-list

Version:
89 lines (73 loc) 1.7 kB
/** * List component. * @class ApList */ 'use strict' import React, {PropTypes as types} from 'react' import classnames from 'classnames' import {ApSpinner} from 'apeman-react-spinner' /** @lends ApList */ const ApList = React.createClass({ // -------------------- // Specs // -------------------- propTypes: { /** Shows spin */ spinning: types.bool, /** Theme of spinner */ spinner: types.string, /** Min height of list */ minHeight: types.number, /** Mark as empty */ empty: types.bool, /** Alt text to show when empty */ alt: types.string }, mixins: [], statics: {}, getInitialState () { return {} }, getDefaultProps () { return { spinning: false, spinner: ApSpinner.DEFAULT_THEME, minHeight: null, empty: false, alt: 'Not data found' } }, render () { const s = this let { props } = s return ( <ul className={ classnames('ap-list', { 'ap-list-empty': !!props.empty }, props.className) } style={ Object.assign({ minHeight: props.minHeight }, props.style) }> <ApSpinner enabled={ props.spinning } className="ap-list-spinner" /> { props.children } { props.empty ? s._renderAlt(props.alt) : null } </ul> ) }, // -------------------- // Lifecycle // -------------------- // ------------------ // Custom // ------------------ // ------------------ // Private // ------------------ _renderAlt (text) { return ( <div className="ap-list-alt">{ text }</div> ) } }) export default ApList;