1.0.7 • Published 2 years ago

@alifd/mobile-layout v1.0.7

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

介绍

一套面向移动端的布局解决方案。🔗 使用文档

目标:不再写任何布局 CSS 代码

特性:

  • 支持栅栏布局,并可自定义 BreakPoints
  • 弹性的容器计算,完美适配各类屏幕(手表/手机/平板/桌面)
  • 大小布局模式拆分,逻辑清晰,布局灵活
  • 完美支持小程序(微信、支付宝、钉钉)

大布局

  • <Page>: 页
    • <Page.Header>: 序章
    • <Page.Content>: 内容
    • <Page.Footer>: 终章
  • <Section>: 章
  • <Block>: 区块

小布局

  • <Cell>: 单元格,主轴默认为 垂直方向的 flex 排版
  • <Row>: 行
  • <Col>: 列
  • <Grid>: 网格

段落&文本

  • <P>: 段落
  • <Text>: 文本

大布局模式

用于在页面栅栏系统的上构建出整个页面的骨架,其最终产物的是一组响应式布局的空容器。

代码:

<Page
  breakPoints={[
    {
      width: 200,
      maxContentWidth: 200,
      numberOfColumns: 1,
    },
    {
      width: 320,
      maxContentWidth: 320,
      numberOfColumns: 2,
    },
    {
      width: 750,
      maxContentWidth: 750,
      numberOfColumns: 4,
    },
    {
      width: 1125,
      maxContentWidth: 1125,
      numberOfColumns: 8,
    },
    {
      width: Infinity,
      maxContentWidth: Infinity,
      numberOfColumns: 12,
    },
  ]}
>
  <Section>
    <Block span={6}>...</Block>
    <Block span={6}>...</Block>
  </Section>
</Page>

Block 列宽计算规则

组件会根据页面宽度自动计算栅栏数量和 Block 的列宽,计算逻辑为:

以屏幕宽度从 12 列模式收缩到 8 列为例, 6,4,2,4 布局, 子元素的列宽会经历如下调整:

小布局模式

小布局指按照 RowColGrid 相互嵌套的方式,将 Block 内部切割为多个内容区域的规范和操作方式。

独立单元格

<Cell />

横向拆分

<Row>
  <Cell />
  <Cell />
</Row>

纵向拆分

<Col>
  <Cell />
  <Cell />
</Col>

网格拆分

<Grid cols="{2}">
  <Cell />
  <Cell />
  <Cell />
  <Cell />
</Grid>

复合拆分

<Row>
  <Cell />
  <Col>
    <Cell />
    <Cell />
  </Col>
</Row>

段落&文本

在单个 Cell 中对组件进行横向排版。如文本居中对齐:

<p align="center">
  <Text type="h1">文本</Text>
  <Text type="body1">文本</Text>
  <button>button</button>
</p>

使用

1. 安装

npm install @alifd/mobile-layout --save

2. 导入 Fusion Mobile 主题

引入 Fusion Mobile 的主题,此主题可以通过 Fusion 站点定制生成,或者使用默认主题:

import { Page, Section, Block, Row, Cell, P, Text } from '@alife/mobile-layout';
import { Button } from '@alifd/meet';

// 导入一套 Fusion 移动端主题 (参见 Fusion 官网介绍)
import '@alifd/meet/es/core/index.css';

<Page>
  <Section>
    <Block span={2}>
      <Row>
        <Cell>
          <Button>按钮 1</Button>
        </Cell>
        <Cell>
          <Button>按钮 2</Button>
        </Cell>
      </Row>
    </Block>
    <Block span={2}>
      <Cell verAlign="middle">
        <P align="right">
          <Text>文本</Text>
          <Text>文本</Text>
        </P>
      </Cell>
    </Block>
  </Section>
</Page>;

3. 注意事项

建议使用 “自然布局” 为整个页面布局,以达到最优效果,所有的内容都渲染在支持的容器中

API

Page

页面

参数含义类型默认值
prefixCSS 类名前缀,stringpro-layout-
noPadding禁用页面内边距,包括 Header, Content, FooterBooleanfalse
noBlockCorner禁用区块的边角(通常在无页面内容间隙时使用)Booleanfalse
sectionGapHeader、Footer、Nav、Aside 和章节之间间隙Number-
blockGapSection 中栅栏布局间隙Number-
gridGap小布局间隙(包含行、列、网格布局)Number-
children子元素RaxNode-
breakPoints断点信息BreakPoint[]-
onBreakPointChange断点变更回调(curBreakPoint, oldBreakPoint, breakPoints)=>void
BreakPoint

断点配置信息,通过传入一组断点信息,来配置页面在不同页面尺寸下的展示模式(栅栏列数 + 内容区域最大宽)。

参数含义类型默认值
width断点适配的最大屏幕宽度Number-
maxContentWidth适配屏幕下最大内容宽度Number-
numberOfColumns栅栏列数Number-

Page.Header

序章

参数含义类型默认值
mode背景色 'lining' / 'surface' / 'transparent'Enumsurface
noBottomPadding隐藏默认底部内边距Boolean-
divider展示分割线Boolean-
children子元素RaxNode-

Page.Footer

终章

参数含义类型默认值
mode背景色 'lining' / 'surface' / 'transparent'Enumsurface
noTopPadding隐藏默认顶部内边距Boolean-
divider展示分割线Boolean-
fixed固定在底部Boolean
children子元素RaxNode-

Page.Content

内容

参数含义类型默认值
children子元素RaxNode-

Section

参数含义类型默认值
title标题RaxNode-
titleAlign标题位置,可选值 left/centerEnum-
extra附加区域(标题右侧)RaxNode-
gap自定义内部区块(Block)的间隙Number-
children子元素RaxNode-

Block

区块(节)

参数含义类型默认值
mode背景模式,可选值 transparent(自动移除内边距和标题)/surface/liningEnum-
title标题RaxNode-
titleAlign标题位置,可选值 left/centerEnum-
extra附加区域(标题右侧)RaxNode-
divider展示标题与内容之间的分割线Boolean-
bordered展示边框Boolean-
noPadding移除内边距Booleanfalse
span列宽Number-
width指定宽度Number-
contentClassName有标题时,内容区域的样式名string-
contentStyle有标题时,内容区域的自定义样式CSSProperties-
children子元素RaxNode-

Row

参数含义类型默认值
width指定宽度Number-
autoFit根据内容自适应宽度(当作为行列布局的子元素时生效)Boolean-
verAlign垂直对齐方式, 可选值:top/middle/bottom/stretch/baselineEnum-
gap自定义元素间间距Number-
children子元素RaxNode-

Col

参数含义类型默认值
autoFit根据内容自适应宽度(当作为行列布局的子元素时生效)Boolean-
align水平对齐方式, 可选值:left/center/right/stretchEnum-
gap自定义元素间间距Number-
children子元素RaxNode-

Grid

网格

参数含义类型默认值
cols指定列数number
rows指定行数number
minWidth单元格最小宽度number
maxWidth单元格最大宽度number
rowGap单元格行间距, 可选值: small/medium/large/数值Enum
colGap单元格列间距, 可选值: small/medium/large/数值Enum
renderItem手动渲染单个单元格内容(rowIndex,colIndex)=>RaxNode
children子元素,默认应为 CellRaxNode-

Cell

单元格,其内容默认为 flex 纵向布局

参数含义类型默认值
width指定宽度Number-
autoFit根据内容自适应宽度(当作为行列布局的子元素时生效)Boolean-
gap自定义内部元素的行解析Number0
align内容水平对齐方式, 可选值: left/center/rightEnum-
verAlign内容垂直对齐方式, 可选值: top/middle/bottom/space-between/space-around/space-evenlyEnum-
block使用 block 布局Boolean-
children子元素RaxNode-

区别:

  • <Cell> 设置 gap 时,每一行的高度是自适应的
  • <Col> 设置 gap 时,默认每一行的高度是等分的

Space

空间间隙

参数说明类型默认值
direction组件自身布局模式,可选: hoz/verEnumhoz
size尺寸, 可选: small/medium/large/NumberEnummedium
children子元素RaxNode

P

段落

参数说明类型默认值
align水平方向对齐模式 left/center/right/space-between/space-around/space-evenlyEnum'left'
verAlign垂直方向对齐模式 top/middle/bottom/baselineEnum'baseline'
spacing子元素间保持水平间距, 可选: small/medium/large/falseEnummedium
verMargin除 Text 节点外子元素间保持垂直外边距Booleantrue
beforeMargin段前外边距(第一个子元素无效)Number0
afterMargin段尾外边距(最后一个子元素无效)Number0
children子元素RaxNode-

Text

文本

参数说明类型默认值
type约束字体大小 overline/caption/body1/body2/title/h1/h2/h3/h4/h5/h6Enum
delete添加删除线样式Booleanfalse
mark添加标记样式Booleanfalse
underline添加下划线样式Booleanfalse
strong是否加粗Booleanfalse
code添加代码样式Booleanfalse
color颜色String-

CSS 变量

变量名说明默认值
--color-transparent前景色transparent
--color-surface前景色#fff
--color-lining衬色#f0f0f0
--page-padding-lr页面左右内边距var(--s-3)
--page-padding-tb页面上下内边距var(--s-3)
--page-header-divider-colorheader 分割线颜色var(--color-line1-1)
--page-block-corner区块圆角尺寸var(--corner-0)
--page-block-padding-lr区块左右内边距var(--s-3)
--page-block-padding-tb区块上下内边距var(--s-3)
--page-section-title-font-color章节标题颜色var(--color-text1-4)
--page-section-extra-font-color章节附加内容文本颜色var(--color-text1-2)
--page-block-title-font-color区块标题颜色var(--color-text1-4)
--page-block-extra-font-color区块附加内容文本颜色var(--color-text1-2)
--page-section-gap章间隙var(--s-3)
--page-block-gap区块间隙var(--s-2)
--page-block-border-width区块边框宽度var(--line-1)
--page-block-border-color区块边框颜色var(--color-line1-1)
--page-grid-gap小布局间隙var(--s-1)
--page-p-small-spacing段落子元素的水平小间距var(--s-1)
--page-p-medium-spacing段落子元素的水平中间距var(--s-2)
--page-p-large-spacing段落子元素的水平大间距var(--s-4)
--page-p-el-margin段落子元素的上下间距var(--s-1)
--page-p-font-color段落默认字体色var(--color-text1-4)

在大布局模式下,如果需要支持较大屏幕, 则 CSS 单位需要视情况选择 rpxpx

1.0.7

2 years ago

1.0.6

2 years ago

1.0.6-beta.1

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.3-beta.2

2 years ago

1.0.3-beta.1

2 years ago

1.0.1-beta.1

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0-beta.8

2 years ago

1.0.0-beta.7

2 years ago

1.0.0-beta.6

2 years ago

1.0.0-beta.5

2 years ago

1.0.0-beta.4

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.1

2 years ago