• 用emotion写个grid组件


    1.Grid组件

    import styled from '@emotion/styled/macro';
    
    export const Grid = styled.div`
      display: flex;
      flex-wrap: wrap;
      &.align-top      { align-items: flex-start; }
      &.align-middle   { align-items: center; }
      &.align-bottom   { align-items: flex-end; }
      &.align-stretch  { align-items: stretch; }
      &.align-baseline { align-items: baseline; }
      &.justify-left     { justify-content: flex-start; }
      &.justify-center   { justify-content: center; }
      &.justify-right    { justify-content: flex-end; }
      &.justify-between  { justify-content: space-between; }
      &.justify-around   { justify-content: space-around; }
    
      &>div{
        margin-left: ${props => props.gutter};
        margin-right: ${props => props.gutter};
      }
    `;
    
    export const Cell = styled.div`
      box-sizing: border-box;
      flex-shrink: 0;
      &.with-fill        {  0; min- 0; flex-grow: 1; }
      &.with-1of12    {  calc(100% * 1 / 12); }
      &.with-2of12    {  calc(100% * 2 / 12); }
      &.with-3of12    {  calc(100% * 3 / 12); }
      &.with-4of12    {  calc(100% * 4 / 12); }
      &.with-5of12    {  calc(100% * 5 / 12); }
      &.with-6of12    {  calc(100% * 6 / 12); }
      &.with-7of12    {  calc(100% * 7 / 12); }
      &.with-8of12    {  calc(100% * 8 / 12); }
      &.with-9of12    {  calc(100% * 9 / 12); }
      &.with-10of12   {  calc(100% * 10 / 12); }
      &.with-11of12   {  calc(100% * 11 / 12); }
      &.with-12of12   {  100%; }
      &.with-2of10    {  calc(100% * 2 / 10); }
    
      // border: 1px solid #f00;
    `;

    参考 grd

    2.使用

    import React, { Component } from 'react';
    
    import { Grid, Cell } from '../../src/components/Grid';
    
    class GridDemo extends Component {
      state = {}
    
      render() {
        return (
          <div>
            <Grid className="justify-center align-middle" gutter=".5rem">
              <Cell className="with-3of12">
                3
                <div>div</div>
              </Cell>
              <Cell className="with-3of12">3</Cell>
              <Cell className="with-3of12">3</Cell>
            </Grid>
          </div>
        );
      }
    }
    
    export default GridDemo;

    效果:

  • 相关阅读:
    小结
    五种常见的 PHP 设计模式
    php克隆 自动加载
    小知识点
    php抽象 与接口
    php静态
    iOS开发零碎笔记
    iOS开发错误日志
    Objective-C:Foundation框架-常用类-NSObject
    Objective-C:Foundation框架-常用类-NSDate
  • 原文地址:https://www.cnblogs.com/susu8/p/10375760.html
Copyright © 2020-2023  润新知