-
Notifications
You must be signed in to change notification settings - Fork 25
Styleguide
Ryan Johnson edited this page Dec 16, 2019
·
7 revisions
Contribution standards and conventions
For consistency, use spaces instead of tabs for indentation.
Preferred | Maximum |
---|---|
80 chars | 120 chars |
- 80 characters or less is preferred
- 120 characters is absolute maximum line length
- URLs are the only exception to this rule
We must prefix all Element and CSS definitions with hx
or HX
to avoid namespace conflicts and to ensure maximum compatibility with 3rd party libraries.
Format | Example | |
---|---|---|
Element Name | hx-kebab-case |
hx-checkbox , hx-icon , etc. |
Element Class | HXUpperCamelElement |
HXCheckboxElement , HXIconElement , etc. |
CSS Class | .hxLowerCamelCase |
.hxSuccess , .hxSpan-12 , etc. |
Custom Event (public)* | lowereventname |
open , dismiss , panelchange , etc. |
Custom Event (private)* | hxlowereventname |
hxchange , hxdirty , hxtouch , etc. |
* TODO: should ALL custom events be hx
prefixed?
Based on observation, consumers find it more natural to type <hx-parent-child>
rather than <hx-parentchild>
.
- Strive to name custom elements after applicable ARIA roles, if possible.
- e.g.
<hx-tab-list>
is named after thetablist
ARIA role.
- e.g.
- Avoid abbreviations
- e.g.,
<hx-foobar-control>
is preferred over<hx-foobar-ctrl>
- e.g.,
Recommended:
<hx-parent>
<hx-parent-child>...</hx-parent-child>
</hx-parent>
Avoid:
<hx-parent>
<hx-parentchild>...</hx-parentchild>
</hx-parent>
All custom element assets should conform to the following file structure.
.
└ hx-{element-name}/ # e.g., hx-accordion/, hx-accordion-panel/, etc.
├ _shadow.html # Shadow Markup
├ _shadow.scss # Shadow Styles
├ index.js # HXElementName class def
└ index.spec.js # HXElementName unit tests