From c766125fe85f8e2e5106bb6364b709b2955db341 Mon Sep 17 00:00:00 2001
From: chapoi <101828855+chapoi@users.noreply.github.com>
Date: Wed, 22 Nov 2023 16:04:19 +0100
Subject: [PATCH] UX: add BEM documentation to styleguide (#24512)
* UX: add BEM documentation to styleguide
* grammar fix
Co-authored-by: Jarek Radosz
+ The guidelines outlines below strive to bring structure and consistency to
+ our classnames. Additionally, with this approach the nesting of css is
+ firmly reduced. BEM stands for:
+ Syntax
+ BEM
+
+
+
We use a slightly modified version of the BEM classname format.
+d-modal
+ A block is a standalone component. Blocks can be used within blocks. It + should be a "top-level" element, which could be used in its entirety in + another place of the app. It has no dependencies on any parent class.
+d-modal__header
+
+ An element is a part of a block that can not be used outside that context.
+ They because it depends on the parent class and can not be used standalone
+ outside this context. In the example above, an element with class
+ d-modal__header
+ will only work within the d-modal block, but not when placed elsewhere.
+
--success
,
+ --large
,--inline
,
+ --highlighted
+ + A modifier is used mainly for changing the appearance, if different than the + default. It is less than an element, and has no html structure of it own. + Meaning, it can only exist when applied to an element (or potentially a + block). +
+In classic BEM, a modifier looks like:
+ d-modal__header--success
. This can quickly turn into very
+ verbose HTML. Imagine an already long block-element name, for example:
+
+
+ class="chat-message-creator__search-container"
+
+ class="chat-message-creator__search-container
+ chat-message-creator__search-container--highlighted
+ chat-message-creator__search-container--inline"
+
+ class="chat-message-creator__search-container --highlighted
+ --inline"
+
is-foo
= example: is-openhas-foo
= example: has-errorsEven though the BEM convention avoids nesting, we can use SCSS to write the + code nested. This is to taste, but I find it easier to read and write, + because it will keep all relevant elements and modifiers grouped together + and avoids unnecessary repetition of the block class.
\ No newline at end of file