
/**
 * ISC License (ISC)
 *
 * Copyright (c) 2018, Brandon D. Sara (https://bsara.pro/)
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

import React     from 'react';
import PropTypes from 'prop-types';

import { pickGlobalHtmlAttirbuteProps } from '../utils';

import './LinearLayout.css';



export default function LinearLayout(props) {
  const isDirectionVertical = (props.direction === 'v' || props.direction === 'vert' || props.direction === 'vertical');

  return (
    <div {...pickGlobalHtmlAttirbuteProps(props)} styleName={`linear-layout ${isDirectionVertical ? 'linear-layout-vertical' : 'linear-layout-horizontal'}`} className={props.className} ref={props.domRef}>
      {props.children}
    </div>
  );
}


LinearLayout.propTypes = {
  id:        PropTypes.oneOfType([ PropTypes.number, PropTypes.string ]),
  className: PropTypes.string,
  style:     PropTypes.object,
  domRef:    PropTypes.func,

  direction: PropTypes.oneOf([ 'h', 'horiz', 'horizontal', 'v', 'vert', 'vertical' ])
};
