Giter VIP home page Giter VIP logo

blog's Introduction

Anurag's GitHub stats

blog's People

Contributors

wilsonyiyi avatar

Watchers

 avatar

blog's Issues

【Antd源码系列】栅格系统

Row的实现简单的堆加了样式,样式规则row-{flex布局}-{flex水平/垂直方向}

render() {
    const { type, justify, align, className, ...others } = this.props;
    const classes = classNames({
      row: true,
      [`row-${type}`]: type,
      [`row-${type}-${justify}`]: justify,
      [`row-${type}-${align}`]: align,
      [className]: className,
    });
    return <div {...others} className={classes}>{ this.props.children }</div>;
 },

Col的实现。之前一致对pull和push的概念模糊,业务中使用率不高。刚想了下,如果都以左侧起点作为参照点,push即远离左侧,pull即拉向左侧(往左侧靠)。

 render() {
    const { span, order, offset, push, pull, className, ...others } = this.props;
    const classes = classNames({
      [`col-${span}`]: span,
      [`col-order-${order}`]: order,
      [`col-offset-${offset}`]: offset,
      [`col-push-${push}`]: push,
      [`col-pull-${pull}`]: pull,
      [className]: className,
    });
    return <div {...others} className={classes}>{ this.props.children }</div>;
},

核心样式代码,一个循环解决栅格系统的样式问题

.loop-grid-columns(@index) when (@index > 0) {
  .col-@{index} {
    width: percentage((@index / @grid-columns));
  }
  .col-push-@{index} {
    left: percentage((@index / @grid-columns));
  }
  .col-pull-@{index} {
    right: percentage((@index / @grid-columns));
  }
  .col-offset-@{index} {
    margin-left: percentage((@index / @grid-columns));
  }
  .col-order-@{index} {
    order: @index;
  }
  .loop-grid-columns((@index - 1));
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.