Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui / dist / components / atoms / Button / renderProps.js
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

const tslib_1 = require("tslib");

const react_1 = tslib_1.__importDefault(require("react"));

const Empty_1 = require("../Empty");

const exotic_1 = require("exotic");

const utils_1 = require("@skava/utils");

const MaterialIcon_1 = require("../MaterialIcon");

const styled_1 = require("./styled");

const deps_1 = require("./deps");
/**
 * @description rendering a text if that is not a icon breed
 */


function defaultRenderText(props, state) {
  const {
    text,
    breedType
  } = props;

  if (exotic_1.isEmpty(text) || breedType === 'icon') {
    return react_1.default.createElement(Empty_1.Empty, null);
  } else {
    return react_1.default.createElement(styled_1.ButtonLabel, {
      content: text,
      "aria-label": "label"
    });
  }
}

exports.defaultRenderText = defaultRenderText;
/**
 * @description rendering the icon => if the breedType text has "icon"
 */

function defaultRenderIcon(iconDetails, state) {
  const {
    iconType,
    direction
  } = iconDetails; // const attributes = { [direction]: true }
  // return <Icons breedType={iconType} {...attributes} />

  return react_1.default.createElement(MaterialIcon_1.MaterialIcon, {
    type: iconType
  });
}

exports.defaultRenderIcon = defaultRenderIcon;

function defaultRenderIconWrapper(props, state) {
  const {
    breedType,
    iconAlignType,
    renderIcon,
    iconType,
    direction
  } = props;
  const iconPos = deps_1.getFlexOrderByAlignType(iconAlignType);
  const icon = renderIcon({
    iconType,
    direction
  }, state);

  if (breedType.indexOf('icon') === -1) {
    return react_1.default.createElement(Empty_1.Empty, null);
  } else {
    return react_1.default.createElement(styled_1.ButtonIcon, {
      orderArrange: iconPos
    }, icon);
  }
}

exports.defaultRenderIconWrapper = defaultRenderIconWrapper;
/**
 * @description rendering the button
 */

function defaultRenderChildren(props, state) {
  const {
    text,
    breedType,
    iconAlignType,
    iconType,
    direction,
    renderIcon,
    renderText,
    renderIconWrapper
  } = props;
  const textProps = Object.seal({
    text,
    breedType
  });
  const iconWrapperProps = Object.seal({
    breedType,
    iconAlignType,
    renderIcon,
    iconType,
    direction
  });
  const textWrapper = renderText(textProps, state);
  const icon = renderIconWrapper(iconWrapperProps, state);
  const children = react_1.default.createElement(react_1.default.Fragment, null, icon, textWrapper);
  return children;
}

exports.defaultRenderChildren = defaultRenderChildren;
/**
 * @description rendering the button
 */

function defaultRenderWrap(props, state) {
  const {
    className,
    children,
    renderChildren,
    dataQa,
    to
  } = props,
        remainingProps = tslib_1.__rest(props, ["className", "children", "renderChildren", "dataQa", "to"]);

  const childrenProps = utils_1.omit(props, ['renderChildren']);
  const child = children || renderChildren(childrenProps, state);
  const removableProps = ['breedType', 'iconType', 'iconAlignType', 'renderChildren', 'renderIcon', 'renderIconWrapper', 'renderText', 'renderWrap', 'text'];
  const buttonElementProps = utils_1.omit(remainingProps, removableProps);

  const view = viewProps => {
    if (viewProps.isLink === true) {
      return react_1.default.createElement(styled_1.LinkWrapper, {
        className: className,
        role: "link"
      }, react_1.default.createElement(styled_1.StyledLink, {
        to: to
      }, child));
    } else {
      return react_1.default.createElement(styled_1.StyledButton, Object.assign({
        className: className,
        "data-qa": dataQa
      }, buttonElementProps), child);
    }
  };

  return view(props);
}

exports.defaultRenderWrap = defaultRenderWrap; //# sourceMappingURL=renderProps.js.map