-
Notifications
You must be signed in to change notification settings - Fork 195
Class Naming Conventions
Our naming convention is based on SUIT: https://github.com/suitcss/suit/blob/master/doc/naming-conventions.md
-
-ItemGroup
, whereItem
is the class of items being grouped.spectrum-FieldGroup
.spectrum-ButtonGroup
- Grouped items don't need to have special classnames and can be targeted directly
The component name for a collection of something should be named according to the UI design pattern it represents -- no fancy suffixes are required.
- Collection of tabs:
.spectrum-Tabs
- Collection of menu options:
.spectrum-Menu
- Collection of miller columns:
.spectrum-MillerColumns
Items in collections, however, should be consistently named as follows:
- Tab:
.spectrum-Tabs-item
- Menu option:
.spectrum-Menu-item
- Miller column:
.spectrum-MillerColumns-item
Although you may be tempted to call a Tab .spectrum-Tab
, it's inconsistent with other collections whose items aren't given individual names.
Sub-elements inside of collection items should be camelCase, prefixed with item
.
spectrum-Tabs-itemLabel
If the inner-most list is different than the outer list, it ought to be a separate component, such as in the case of .spectrum-MillerColumns
. The column is given the .spectrum-MillerColumns-item
class, and the list within it is given the .spectrum-FileList
class, with .spectrum-FileList-items
inside of it.
If the nested list is visually identical at all levels, simply nest the component within itself to go a level deeper, such as in .spectrum-TreeView
.
Don't just target .spectrum-Icon
, UI icons or icons nested in components deserve their own class, such as .spectrum-Accordion-indicator
.
A header is a logical group of mixed content (text, buttons, icons, etc) that appears at the top of something.
A heading is a text-only bit that denotes a sub-section (a chapter).
A title is the overall name of something (the book). A title can appear in a header, as in the Dialog and Calendar.
We updated the naming of some components and sub elements to be more consistent, and recorded the changes and reasoning into rules:
- How to target sub-elements that are already their own components
-
.spectrum-ActionMenu-popover
- when used inside of another component and changed in a way that’s unique to that component, but there is a possibility of the changed component being nested within itself or used more than once
- when targeting the element by its classname would cause excessive and unnecessary specificity
- i.e. Tooltip that’s inside of a wizard to indicate the name of a step, but you want to allow other tooltips that should not have the custom CSS
-
.spectrum-ActionMenu .spectrum-Popover
- when used inside of another component and changed in a way that’s unique to this component, target with descendant selector
-
.spectrum-Popover--someVariant
- when used inside of another component and changed in a way that’s common between components, add a variant
- i.e. same changes required inside of ActionMenu AND inside of Dropdown, then add a variant
-
- option vs item: Should all options be items?
- Everything should be items
- Chevron vs icon vs indicator vs separator
- icon when conveying information
- the type of of an Alert
- the action performed by a button
- discloses menu
- deletes thing
- has children
- separator when separating
- between breadcrumbs
- indicator when indicating state
- on accordion
- icon when conveying information
- When to use
.is-state
-
.is-selected
in the “down” state- for a button that triggers a menu, when the menu is open, the button .is-selected
-
.is-focused
- only when required because :focus-within is not available in the browser
-