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    
ui-component-library / dist / 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("atoms/Empty");
const exotic_1 = require("exotic");
const omit_1 = require("@skava/modules/___dist/utils/omit");
const styled_1 = require("./styled");
const Icons_1 = __importDefault(require("atoms/Icons"));
const deps_1 = require("./deps");
/**
 * @description rendering a text if that is not a icon breed
 */
function renderText(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.renderText = renderText;
/**
 * @description rendering the icon => if the breedType text has "icon"
 */
function renderIcon(iconDetails, state) {
    const { iconType, direction } = iconDetails;
    const attributes = { [direction]: true };
    return react_1.default.createElement(Icons_1.default, Object.assign({ breedType: iconType }, attributes));
}
exports.renderIcon = renderIcon;
function renderIconWrapper(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(styled_1.ButtonIcon, { orderArrange: iconPos }, icon);
    }
    else {
        return react_1.default.createElement(Empty_1.Empty, null);
    }
}
exports.renderIconWrapper = renderIconWrapper;
/**
 * @description rendering the button
 */
function renderChildren(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.renderChildren = renderChildren;
/**
 * @description rendering the button
 */
function renderWrap(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 = (props) => {
        if (props.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.renderWrap = renderWrap;
//# sourceMappingURL=renderProps.js.map