@charset "utf-8";
@import "../core/variables";
@import "../core/classes";

// 定义常见弹性布局
@mixin _flex {
    height: 100%;
    &,
    .flex-inherit {
        @include flexbox(map-get($flex, box));
        @include flex-direction(map-get($flex, direction));
        overflow: hidden;
    }
    > .flex,
    .flex-inherit,
    .flex-inherit > .flex {
        @include flex(1, column);
        position: relative;
    }
    > .flex,
    .flex-inherit > .flex {
        @include overflow;
        // 用于解决flex无法将动态高度继承给子元素
        // 这里单独处理flex的子元素为yo-flex的情况,yo-flex通过绝对定位拉伸来得到高度
        // 请使用 flex-inherit 的方式来进行嵌套(推荐)
        > .yo-flex {
            @include fullscreen;
        }
    }
}

/**
 * @module layout
 * @method yo-flex
 * @description 构造弹性布局使用方法,可以是横向和纵向
 * @demo http://doyoe.github.io/Yo/demo/layout/yo-flex.html
 * @param {String} $name 为新的扩展定义一个名称
 * @param {String} $box 指定块级或者行级弹性盒
 * @param {String} $direction 指定是水平或者垂直布局
 */

@mixin yo-flex(
    $name: default,
    $box: default,
    $direction: default) {
    // 区别是否新增实例还是修改本身
    @if $name == default {
        $name: "";
    } @else {
        $name: "-#{$name}";
    }
    // 如果值为default,则取config的定义
    @if $box == default {
        $box: map-get($flex, box);
    }
    @if $direction == default {
        $direction: map-get($flex, direction);
    }
    .yo-flex#{$name} {
        &,
        .flex-inherit {
            // 如果$box不等于config预设,则重绘弹性盒类型
            @if $box != map-get($flex, box) {
                @include flexbox($box);
            }
            // 如果$direction不等于config预设,则重绘方向
            @if $direction != map-get($flex, direction) {
                @include flex-direction($direction);
            }
        }
        > .flex,
        .flex-inherit,
        .flex-inherit > .flex {
            // 如果$direction不等于config预设,则重绘方向
            @if $direction != map-get($flex, direction) {
                @include flex(1, $direction);
            }
        }
        // 增量扩展
        @content;
    }
}

// 调用本文件时载入弹性布局基础构造
.yo-flex {
    @include _flex;
}