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 / src / components / atoms / Button / renderProps.js
Size: Mime:
"use strict";

var __rest = this && this.__rest || function (s, e) {
  var t = {};

  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
  return t;
};

var __importDefault = this && this.__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};

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

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

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

const exotic_1 = require("exotic");

const omit_1 = require("uxui-modules/utils/omit");

const Icons_1 = __importDefault(require("../Icons"));

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 react_1.default.createElement(Icons_1.default, Object.assign({
    breedType: iconType
  }, attributes));
}

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,
    to
  } = props,
        remainingProps = __rest(props, ["className", "children", "renderChildren", "to"]);

  const childrenProps = omit_1.omit(props, ['renderChildren']);
  const child = children || renderChildren(childrenProps, state);
  const removableProps = ['breedType', 'iconType', 'iconAlignType', 'renderChildren', 'renderIcon', 'renderIconWrapper', 'renderText', 'renderWrap', 'text'];
  const buttonElementProps = omit_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
      }, buttonElementProps), child);
    }
  };

  return view(props);
}

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