AVO 🥑 — A BEM Dialect Using Data Attributes
Attribute Value-Object
AVO 🥑 is a syntactive varient of BEM’s Block, Element, Modifier constructs. AVO is an initialism for “Attribute Value-Objects”.
As a BEM dialect, AVO observes the concepts of BEM but uses data attribute syntax that reduced (template) repetition and improves template legibility (particularly when used in legacy codebases or with utility class libraries).
Contents
- Attribute Value-Object
- Video
- Goals
- Attribute
- Value (boolean)
- Value-object (enumerable)
- Value-object (unbounded)
- Relative
Video
Watch me demonstrate this syntax in a LIVE YouTube session. {% youtube-video ‘https://youtu.be/XoBZAc1d43Y?t=63’ %}
Goals
AVO 🥑 uses data attribute selectors to achieve 5 primary goals:
- Enable copy-paste of large code examples — from docs to code — in React/JSX or HTML template
- Improve legibility of view code by reducing, in-template, selector duplication
- Facilitate migration of code with automated tools like grep, find-and-replace, and jscodeshift — by providing first class attribute selectors over class name strings
- Eliminate (as much as possible) the likelihood of selector collision between new selectors and legacy codebases
- Clarify the relationship of composed elements by segmenting “modifier” selectors into attribute namespaces
Attribute
AVO 🥑 elements use empty attribute selectors for BEM Blocks.
CSS
HTML
Value (boolean)
AVO 🥑 extensions use the ~=
attribute selector for booleans BEM Modifiers.
Key-only values (like mention
above) are inferred to be true
, like in BEM.
CSS
HTML
Value-object (enumerable)
AVO 🥑 extensions also use the ~=
attribute selector for enumerable, key-value BEM Modifiers.
CSS
HTML
Value-object (unbounded)
AVO 🥑 extensions use the *=
attribute selectors for keys with unkown values.
This allows for indeterminate values status:<undefined>
to be extended with inline styles.
CSS
HTML
Warning
While available, this isn’t recommended. Using a fixed set of values is preferred.
If you want to provide a default, consider instead providing an explicit unknown
selector:
Relative
AVO 🥑 extensions use a --
delimiter for BEM Elements.
root-element--composed-element
The example below introduces a header that includes avatar styles that are composed with the data-avatar
Block.0