Skip to content

Commit c90a1b5

Browse files
committed
naming convention docs
1 parent 0869178 commit c90a1b5

File tree

3 files changed

+136
-7
lines changed

3 files changed

+136
-7
lines changed

content/foundations/primitives/naming-convention.mdx

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: Token names
3+
description:
4+
An explanation of Primer's design token naming convention.
5+
---
6+
7+
## Intro
8+
9+
Naming things is hard. Primer design tokens are named using a consistent convention to make it easier to understand what they do and how they should be used at a glance.
10+
11+
img of token breakdown
12+
13+
## Categories
14+
15+
Our naming convention is broken down into three categories: **base, component/pattern, functional**. Each category is a subset of the over-arching convention.
16+
17+
Across all categories, the `property` value is always required. This value specifies exactly how a token is indended to be applied to a UI.
18+
19+
<img width="960" alt="graphic listing out namespace, pattern, variant, property, variant, and scale all color coded to match ADR docs" src="https://github.com/primer/react/assets/18661030/d89da86b-5b9d-43f2-b745-126fe35ea500" />
20+
21+
### Base
22+
23+
Base tokens are the lowest level tokens and map directly to a raw value.
24+
25+
<img width="960" alt="a graphic illustrating five words, uniquely colored and displayed left to right in a horizontal direction. Words are prefix, namespace (with an asterix), property (with an asterix), variant and scale. Followed by color coded tokens, which will be described in the next section." src="https://github.com/primer/react/assets/18661030/3bffcdaf-60f1-4824-b30c-25951f2d5156" />
26+
27+
28+
#### Example `base` tokens
29+
30+
```
31+
brand-base-color-lime-5
32+
base-size-4
33+
base-color-green-5
34+
base-fontWeight-semibold
35+
```
36+
37+
### Functional
38+
39+
Functional tokens represent global UI patterns.
40+
41+
<img width="960" alt="a graphic illustrating six words, each uniquely color coded and displayed left to right in a horizontal direction. Words are prefix, type, property (with an asterix), variant and scale. Followed by example tokens that are similarly color coded and will be described again in the next section." src="https://github.com/primer/react/assets/18661030/7124ced5-96d1-4479-996a-641579a2cd4c" />
42+
43+
#### Example `functional` tokens
44+
45+
```
46+
bgColor-inset
47+
borderColor-default
48+
brand-borderWidth-thin
49+
boxShadow-inset-thick
50+
```
51+
52+
### Component/pattern
53+
54+
Component/pattern represents component and pattern specific tokens which should only be used in component CSS.
55+
56+
<img width="960" alt="a graphic illustrating six words, each uniquely color coded and displayed left to right in a horizontal direction. Words are prefix, pattern, variant, type, property (with an asterix) and scale. Followed by similarly color coded tokens, which will be described again in the next section." src="https://github.com/primer/react/assets/18661030/d1d77c2f-e8c4-4d38-b295-1231bc82648f" />
57+
58+
59+
#### Example `component`/`pattern` tokens
60+
61+
```
62+
control-danger-bgColor-hover
63+
button-primary-bgColor-rest
64+
brand-control-xsmall-paddingInline-normal
65+
text-codeInline-fontSize
66+
```
67+
68+
## Convention breakdown
69+
70+
### Prefix
71+
72+
<img width="960" alt="wip" src="https://github.com/primer/react/assets/18661030/7519380f-7cd2-4304-87b9-5556f4801af8" />
73+
74+
Prefix provides top-level encapsulation of a particular flavor of Primer, such as Primer Brand. It can be used for protected base tokens like Brand color scales, or value overrides for traditional Primer tokens in order to avoid collisions.
75+
76+
`brand`: used for marketing/brand specific tokens.
77+
78+
### Namespace
79+
80+
<img width="960" alt="wip" src="https://github.com/primer/react/assets/18661030/50899a02-1fac-474c-b99c-426d6853c92c" />
81+
82+
Namespace creates a scope used to identify how a token may be used. For example, `base` tokens are the lowest level and are generally used as a reference for functional tokens (the next step above).
83+
84+
`base`: represents global, constant values. These are the lowest level tokens and map directly to a raw value.
85+
86+
### Pattern
87+
88+
<img width="960" alt="wip" src="https://github.com/primer/react/assets/18661030/abc16bcd-64e3-43a7-bca6-82a31190acf1" />
89+
90+
Pattern represents a group of design decisions, or a specific Primer component. Whenever possible, aim to use a name that is generic enough to influence related components. In the example below, the item `control` can be used for multiple types of controls like buttons, inputs, or interactive action list items.
91+
92+
For pattern and component names that are multi-word, use camelCase to separate each word.
93+
94+
### Variant
95+
96+
<img width="960" alt="wip" src="https://github.com/primer/react/assets/18661030/6d105711-c815-488d-997c-dfd639cb8123" />
97+
98+
Variant can be used to either modify the **pattern** or **property**. Only one variant is allowed per token. It typically represents a stylistic variant of a token such as color (danger) or size (small).
99+
100+
101+
### Property (required)
102+
103+
<img width="960" alt="wip" src="https://github.com/primer/react/assets/18661030/87514222-3db7-4e98-bd81-5ce8d40d2529" />
104+
105+
Property is used to represent an item’s style. It usually matches a [CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference#index), but it can also store other conceptual definitions such as `size`, `minTarget`, etc. Use camelCase for multi-word properties.
106+
107+
### Scale
108+
109+
<img width="960" alt="wip" src="https://github.com/primer/react/assets/18661030/9a1e8baf-66e2-494c-9ff3-0655d285f145" />
110+
111+
Scale represents ordinals to describe things like state, density, thickness, range, and speed. Scale names strive to follow our [size naming convention standards](https://github.com/github/primer/blob/main/adrs/2022-02-09-size-naming-guidelines.md).
112+
113+
### Token name block delimiters
114+
115+
Individual name blocks for each token should be separated with a single character that is relevant to each Primer framework. For example, use the `-` dash character for CSS variables and `.` dot character for JavaScript.
116+
117+
<DoDontContainer>
118+
<Do>
119+
<img
120+
width="464"
121+
alt=""
122+
src="https://github.com/primer/react/assets/18661030/3694b514-2bcf-4c62-8dc2-c4bc8a3a83f4"
123+
/>
124+
<Caption>Use dashes to separate words.</Caption>
125+
</Do>
126+
<Dont>
127+
<img
128+
width="464"
129+
alt=""
130+
src="https://github.com/primer/react/assets/18661030/15959269-4ac8-4075-88f4-788b91e6ce20"
131+
/>
132+
<Caption>Don't use other characters to separate words.</Caption>
133+
</Dont>
134+
</DoDontContainer>

src/@primer/gatsby-theme-doctocat/nav.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111
- title: Primitives
112112
url: /foundations/primitives
113113
children:
114-
- title: Naming convention
115-
url: /foundations/primitives/naming-convention
114+
- title: Token names
115+
url: /foundations/primitives/token-names
116116
- title: Color
117117
url: /foundations/primitives/color
118118
- title: Size

0 commit comments

Comments
 (0)