Margin Considered Harmful

栏目: IT技术 · 发布时间: 4年前

内容简介:We should ban margin from our components. Hear me out.Margin breaks component encapsulation. A well-built component should not affect anything outside itself.Margin makes reusability harder. Good components are usable in any context or layout.

We should ban margin from our components. Hear me out.

Margin breaks component encapsulation. A well-built component should not affect anything outside itself.

Margin makes reusability harder. Good components are usable in any context or layout.

Margin conflicts with how designers think. Designers think about space in relation and context. They define how far a component should be from another component in a specific instance.

By banning margin from all components you have to build more reusable and encapsulated components.

Moving responsibility

Instead of margin I have started using spacer components, which move the responsibility of managing space to the parent-level.

For example, the Braid design system popularized the Stack component :

<Stack space={3}>
  <Item />
  <Item />
  <Item />
</Stack>

Using spacer components has implications that are not obvious a priori .

Spacer components (such as Stack above) can restrict spacing values to steps on a scale. That way, all spacing automatically aligns to the grid.

Spacer components define how far a component should be from another component in a specific instance. You have to define space in relation and context.

Who else thinks about space in relation and context? Designers.

Spacer components bring us closer to how designers think. They make our designs more consistent and they force us to build more reusable and encapsulated components.

Use spacer components. Ban margin.

I am not the first one to realize this. Thanks to @markdalgleish and @michaeltaranto at Seek for paving the way and prompting me to think about it.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

UML基础、案例与应用

UML基础、案例与应用

施穆勒 / 李虎、赵龙刚 / 人民邮电出版社 / 2004-7-1 / 42.00元

本书教读者循序渐进地、系统地学习UML基础知识和应用技术。和前一版相比,本书内容根据UML 2.0进行了补充和更新,随书光盘包含了建模工具Poseidon的试用版。 全书分为三部分24章。第一部分“基础知识”包括第1章到第15章,主要是介绍UML语言的基础知识以及面向对象的概念和思想,还简单介绍了UML在开发过程的应用方法。第二部分“学习案例”包括第16章到第22章,结合实例详细分析了UML的应用......一起来看看 《UML基础、案例与应用》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试