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    
Size: Mime:
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// modules
const react_1 = __importDefault(require("react"));
const exotic_1 = require("exotic");
// reusable
const collapse_1 = __importDefault(require("@skava/modules/___dist/collapse"));
const state_1 = require("src/state");
// local
const AccordionTitle_1 = __importDefault(require("./AccordionTitle"));
const AccordionWrap_1 = __importDefault(require("./AccordionWrap"));
const _elements_1 = require("./_elements");
const styles_1 = __importDefault(require("./styles"));
function toAttributes(props, state, instance = exotic_1.EMPTY_OBJ) {
    // @see ./README
    const isVisible = exotic_1.isBoolean(props.isVisible) === true ? props.isVisible : state.isVisible;
    const onToggle = instance.handleToggle;
    return Object.assign({}, props, { isVisible, onToggle });
}
function renderBox(props) {
    const { defaultView, children } = props;
    if (defaultView) {
        return defaultView;
    }
    return react_1.default.createElement(_elements_1.Box, null, children);
}
function toWrapperProps(props, state, instance) {
    const { isVisible, isDefaultVisible } = toAttributes(props, state);
    // const onToggle = instance.handleToggle
    const { title, activeTitle, className, isPlusMinus, isDisabled, shouldShowArrowIcon, id, qa, render, } = props;
    const wrapAttributes = {
        id,
        className,
        isVisible,
        isActive: isVisible,
        isDisabled,
        qa,
    };
    return wrapAttributes;
}
function toTitleProps(props, state, instance) {
    const { isDisabled, isPlusMinus, isVisible, title, shouldShowArrowIcon, qa } = props;
    const activeText = props.activeTitle || title;
    const onToggle = instance.handleToggle;
    return {
        title,
        activeText,
        onToggle,
        isPlusMinus,
        isDisabled,
        shouldShowArrowIcon,
        isActive: isVisible,
        'data-qa': qa,
    };
}
let AccordionBlock = class AccordionBlock extends react_1.default.Component {
    constructor() {
        super(...arguments);
        // unused if we pass in props isVisible
        this.state = state_1.makeCommonState(this.props);
        // @type {React.EventHandler}
        this.handleToggle = event => {
            // if they pass in a handler
            if (exotic_1.isFunction(this.props.onToggle)) {
                this.props.onToggle(event);
            }
            else {
                // we call the default handler
                this.state.handleToggleVisibility();
            }
        };
    }
    // componentDidMount
    componentWillMount() {
        const { isVisible, isDefaultVisible } = this.props;
        if (isDefaultVisible === true || isVisible === true) {
            this.state.show();
        }
    }
    render() {
        const wrapAttributes = toWrapperProps(this.props, this.state, this);
        const passThrough = toTitleProps(this.props, this.state, this);
        const { isVisible } = toAttributes(this.props, this.state, this);
        const { id, render } = this.props;
        return (react_1.default.createElement(AccordionWrap_1.default, Object.assign({}, wrapAttributes),
            react_1.default.createElement(AccordionTitle_1.default, Object.assign({}, passThrough, { key: "accordion-title-component" })),
            react_1.default.createElement(collapse_1.default, { key: "accordion-collapse", isOpen: isVisible }, render(this.props, this.state))));
    }
};
AccordionBlock.defaultProps = {
    title: '',
    // isFindInStore: false,
    defaultView: '',
    shouldShowArrowIcon: true,
    id: undefined,
    render: renderBox,
};
AccordionBlock = __decorate([
    styles_1.default(),
    state_1.observer
], AccordionBlock);
exports.default = AccordionBlock;
//# sourceMappingURL=AccordionBlock.js.map