@primer/primitives 11.7.1 → 11.8.0-rc.036a9e18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,18 +65,26 @@
65
65
 
66
66
  ### Motion
67
67
 
68
- | Keyword | Rule |
69
- | ------- | -------------------------------------------------------------- |
70
- | MUST | Use motion for interactive state changes (hover, focus, press) |
71
- | MUST | Keep animations ≤300ms for UI interactions |
72
- | MUST | Respect `prefers-reduced-motion` media query |
73
- | MUST | Provide instant alternatives when motion is reduced |
74
- | SHOULD | Use 100-200ms for micro-interactions |
75
- | SHOULD | Use 200-300ms for state changes |
76
- | NEVER | Exceed 500ms for UI interactions |
77
- | NEVER | Use motion purely for decoration |
78
- | NEVER | Create indefinitely looping motion without user control |
79
- | NEVER | Rely solely on motion to convey information |
68
+ ```
69
+ --motion-[property]-[semantic]
70
+ ├── property: duration | easing | transition
71
+ └── semantic: micro | short | medium | long (duration)
72
+ hover | enter | exit | move | linear (easing)
73
+ hover | stateChange | enter | exit (transition)
74
+ ```
75
+
76
+ | Keyword | Rule |
77
+ | ------- | -------------------------------------------------------------------------- |
78
+ | MUST | Use `motion.transition.*` tokens for interactive state changes |
79
+ | MUST | Keep animations ≤`motion.duration.medium` (300ms) for UI interactions |
80
+ | MUST | Respect `prefers-reduced-motion` media query |
81
+ | MUST | Provide instant alternatives when motion is reduced |
82
+ | SHOULD | Use `motion.duration.micro` (100ms) for hover and focus micro-interactions |
83
+ | SHOULD | Use `motion.duration.short` (200ms) for state changes |
84
+ | NEVER | Exceed `motion.duration.long` (500ms) for UI interactions |
85
+ | NEVER | Use motion purely for decoration |
86
+ | NEVER | Create indefinitely looping motion without user control |
87
+ | NEVER | Rely solely on motion to convey information |
80
88
 
81
89
  ### Typography
82
90
 
@@ -126,10 +134,10 @@
126
134
 
127
135
  ## Decision Tree: Easing Selection
128
136
 
129
- 1. Is element entering/exiting viewport? → ease-out (default)
130
- 2. Is element moving/morphing on screen? → ease-in-out
131
- 3. Is this a hover state change? → ease
132
- 4. Is this constant motion (loaders)? → linear
137
+ 1. Is element entering/exiting viewport? → `motion.easing.enter` / `motion.easing.exit`
138
+ 2. Is element moving/morphing on screen? → `motion.easing.move`
139
+ 3. Is this a hover state change? → `motion.easing.hover`
140
+ 4. Is this constant motion (loaders)? → `motion.easing.linear`
133
141
 
134
142
  ---
135
143
 
@@ -148,11 +156,11 @@
148
156
  font: var(--text-body-shorthand-medium);
149
157
  cursor: pointer;
150
158
 
151
- /* Motion: MUST be <300ms */
159
+ /* Motion: Use functional motion tokens */
152
160
  transition:
153
- background-color 150ms ease,
154
- box-shadow 150ms ease,
155
- transform 100ms ease;
161
+ background-color var(--motion-transition-hover),
162
+ box-shadow var(--motion-transition-hover),
163
+ transform var(--motion-transition-hover);
156
164
  }
157
165
 
158
166
  /* State: Hover */
@@ -429,6 +429,73 @@ Display font stack for headings and titles. Same as sansSerif but semantically d
429
429
  **U:** display-text, heading, title
430
430
  **R:** Use for headings and display text. Prefer over sansSerif for titles.
431
431
 
432
+ ## Motion
433
+
434
+ ### motion-duration-long
435
+ Longer duration for complex multi-step animations or large-scale layout shifts. Use sparingly.
436
+ **U:** complex-animation, layout-shift, multi-step
437
+ **R:** Use sparingly for complex animations. NEVER use for simple UI interactions.
438
+
439
+ ### motion-duration-medium
440
+ Standard duration for elements entering or exiting the viewport, such as modals and dropdowns.
441
+ **U:** dropdown-appear, modal-open, tooltip-show
442
+ **R:** Use for elements entering or leaving the viewport. Maximum recommended duration for UI interactions.
443
+
444
+ ### motion-duration-micro
445
+ Fast micro-interactions like hover, focus ring, and color shifts.
446
+ **U:** color-shift, focus-ring, hover-transition
447
+ **R:** Use for instantaneous feedback on hover and focus states.
448
+
449
+ ### motion-duration-short
450
+ Quick transitions for state changes like expand/collapse, toggles, and visibility changes.
451
+ **U:** expand-collapse, toggle, visibility-change
452
+ **R:** Use for interactive state changes that need to feel responsive.
453
+
454
+ ### motion-easing-enter
455
+ Decelerating easing for elements entering the viewport or appearing on screen.
456
+ **U:** element-appearing, enter-animation, modal-open
457
+ **R:** RECOMMENDED default for enter animations. Element decelerates into its final position.
458
+
459
+ ### motion-easing-exit
460
+ Accelerating easing for elements exiting the viewport or leaving the screen.
461
+ **U:** element-leaving, exit-animation, modal-close
462
+ **R:** Use for elements leaving the viewport. Element accelerates away.
463
+
464
+ ### motion-easing-hover
465
+ Easing for hover state changes and micro-interactions.
466
+ **U:** button-hover, hover-state, micro-interaction
467
+ **R:** Use for hover state changes.
468
+
469
+ ### motion-easing-linear
470
+ Constant motion with no acceleration. Use for continuous animations like progress bars or loaders.
471
+ **U:** continuous-animation, loader, progress-bar
472
+ **R:** Use only for constant, uninterrupted motion.
473
+
474
+ ### motion-easing-move
475
+ Smooth easing for elements moving or morphing within the viewport.
476
+ **U:** morph-animation, position-change, size-change
477
+ **R:** Use for elements that move or change shape on screen.
478
+
479
+ ### motion-transition-enter
480
+ Transition for elements entering the viewport, such as modals, dropdowns, and tooltips.
481
+ **U:** dropdown-appear, modal-open, tooltip-show
482
+ **R:** Use for elements appearing on screen. Element decelerates into final position.
483
+
484
+ ### motion-transition-exit
485
+ Transition for elements exiting the viewport, such as closing modals and dismissing dropdowns.
486
+ **U:** dropdown-dismiss, modal-close, tooltip-hide
487
+ **R:** Use for elements leaving the screen. Shorter than enter to feel snappy.
488
+
489
+ ### motion-transition-hover
490
+ Transition for hover state changes on interactive elements like buttons and links.
491
+ **U:** button-hover, interactive-hover, link-hover
492
+ **R:** Use for all hover state transitions. Keeps interactions feeling instantaneous.
493
+
494
+ ### motion-transition-stateChange
495
+ Transition for state changes like toggles, expand/collapse, and visibility changes.
496
+ **U:** accordion, expand-collapse, toggle
497
+ **R:** Use for interactive elements that change between states.
498
+
432
499
  ## Overlay
433
500
 
434
501
  Tokens for modals, dialogs, popovers, and dropdown menus.
@@ -501,6 +568,38 @@ Extra small resting shadow for minimal elevation
501
568
  **U:** badge, chip, small-card
502
569
  **R:** Use for very subtle elevation on small elements. Provides minimal lift from surface. Do NOT use for interactive elements needing clear affordance.
503
570
 
571
+ ## Space
572
+
573
+ ### space-lg
574
+ Spacious spacing for major layout divisions and visual separation between content blocks.
575
+ **U:** gap, margin, padding
576
+ **R:** Spacious (16px). Use for major layout divisions, visual separation between content blocks, and primary container margins.
577
+
578
+ ### space-md
579
+ Relaxed spacing for breathing room and comfortable internal container space.
580
+ **U:** gap, margin, padding
581
+ **R:** Relaxed (12px). Use for comfortable container padding, relaxed layouts, section separators, and breathing room in dense layouts.
582
+
583
+ ### space-sm
584
+ Default spacing for most UI elements. Comfortable visual density for standard component layouts.
585
+ **U:** gap, margin, padding
586
+ **R:** Default (8px). Use for standard component spacing, flex/grid item separation, container padding, and most element margins.
587
+
588
+ ### space-xl
589
+ Expansive spacing for large sections and top-level structure separation.
590
+ **U:** gap, margin, padding
591
+ **R:** Expansive (24px). Use for large section separation, top-level layout structure, major page divisions, and expansive breathing room.
592
+
593
+ ### space-xs
594
+ Compact spacing for small badges, tight internal spacing, and minimal breathing room.
595
+ **U:** gap, margin, padding
596
+ **R:** Compact (4px). Use for small component spacing, tight list separations, badge padding, and minimal internal margins.
597
+
598
+ ### space-xxs
599
+ Ultra-compact spacing for form field separators and tight visual divisions.
600
+ **U:** gap, margin, padding
601
+ **R:** Ultra-compact (2px). Use for form field separators, tight dividers, and minimal breathing room between small elements.
602
+
504
603
  ## Spinner
505
604
 
506
605
  Loading spinner size and stroke tokens.
package/README.md CHANGED
@@ -40,6 +40,9 @@ All available imports:
40
40
  /* motion */
41
41
  @import '@primer/primitives/dist/css/base/motion/motion.css';
42
42
 
43
+ /* spacing */
44
+ @import '@primer/primitives/dist/css/functional/spacing/space.css';
45
+
43
46
  /* color */
44
47
  @import '@primer/primitives/dist/css/functional/themes/light.css';
45
48
  @import '@primer/primitives/dist/css/functional/themes/light-tritanopia.css';
@@ -53,6 +56,8 @@ All available imports:
53
56
  ```
54
57
 
55
58
  > **Note:** Motion CSS imports are required for components with animations, such as `Spinner` from `@primer/react`. If you're experiencing issues with animated components appearing static, ensure you've imported the motion CSS files.
59
+ >
60
+ > **Note:** Spacing tokens provide a unified semantic scale for `gap`, `padding`, and `margin`. Import `functional/spacing/space.css` to use `--space-*` tokens in your components.
56
61
 
57
62
  ## Design token data
58
63
 
@@ -22,6 +22,10 @@ export const transitionToCss = {
22
22
  }
23
23
  // check required properties
24
24
  checkRequiredTokenProperties(value, ['duration', 'timingFunction']);
25
- return `${value.duration} ${cubicBezierArrayToCss(value.timingFunction, token.path)} ${value.delay ? value.delay : ''}`.trim();
25
+ // timingFunction may already be a CSS string if resolved from a cubicBezier reference
26
+ const timing = typeof value.timingFunction === 'string'
27
+ ? value.timingFunction
28
+ : cubicBezierArrayToCss(value.timingFunction, token.path);
29
+ return `${value.duration} ${timing} ${value.delay ? value.delay : ''}`.trim();
26
30
  },
27
31
  };
@@ -0,0 +1,15 @@
1
+ :root {
2
+ --motion-duration-long: var(--base-duration-500); /** Longer duration for complex multi-step animations or large-scale layout shifts. Use sparingly. */
3
+ --motion-duration-medium: var(--base-duration-300); /** Standard duration for elements entering or exiting the viewport, such as modals and dropdowns. */
4
+ --motion-duration-micro: var(--base-duration-100); /** Fast micro-interactions like hover, focus ring, and color shifts. */
5
+ --motion-duration-short: var(--base-duration-200); /** Quick transitions for state changes like expand/collapse, toggles, and visibility changes. */
6
+ --motion-easing-enter: var(--base-easing-easeOut); /** Decelerating easing for elements entering the viewport or appearing on screen. */
7
+ --motion-easing-exit: var(--base-easing-easeIn); /** Accelerating easing for elements exiting the viewport or leaving the screen. */
8
+ --motion-easing-hover: var(--base-easing-ease); /** Easing for hover state changes and micro-interactions. */
9
+ --motion-easing-linear: var(--base-easing-linear); /** Constant motion with no acceleration. Use for continuous animations like progress bars or loaders. */
10
+ --motion-easing-move: var(--base-easing-easeInOut); /** Smooth easing for elements moving or morphing within the viewport. */
11
+ --motion-transition-enter: var(--motion-duration-medium) var(--motion-easing-enter); /** Transition for elements entering the viewport, such as modals, dropdowns, and tooltips. */
12
+ --motion-transition-exit: var(--motion-duration-short) var(--motion-easing-exit); /** Transition for elements exiting the viewport, such as closing modals and dismissing dropdowns. */
13
+ --motion-transition-hover: var(--motion-duration-micro) var(--motion-easing-hover); /** Transition for hover state changes on interactive elements like buttons and links. */
14
+ --motion-transition-stateChange: var(--motion-duration-short) var(--motion-easing-move); /** Transition for state changes like toggles, expand/collapse, and visibility changes. */
15
+ }
@@ -0,0 +1,8 @@
1
+ :root {
2
+ --space-lg: 1rem; /** Spacious spacing for major layout divisions and visual separation between content blocks. */
3
+ --space-md: 0.75rem; /** Relaxed spacing for breathing room and comfortable internal container space. */
4
+ --space-sm: 0.5rem; /** Default spacing for most UI elements. Comfortable visual density for standard component layouts. */
5
+ --space-xl: 1.5rem; /** Expansive spacing for large sections and top-level structure separation. */
6
+ --space-xs: 0.25rem; /** Compact spacing for small badges, tight internal spacing, and minimal breathing room. */
7
+ --space-xxs: 0.125rem; /** Ultra-compact spacing for form field separators and tight visual divisions. */
8
+ }
@@ -6,6 +6,7 @@
6
6
  @import './base/size/size.css';
7
7
  @import './base/size/z-index.css';
8
8
  @import './base/typography/typography.css';
9
+ @import './functional/motion/motion.css';
9
10
  @import './functional/size/border.css';
10
11
  @import './functional/size/breakpoints.css';
11
12
  @import './functional/size/radius.css';
@@ -13,4 +14,5 @@
13
14
  @import './functional/size/size-fine.css';
14
15
  @import './functional/size/size.css';
15
16
  @import './functional/size/z-index.css';
17
+ @import './functional/spacing/space.css';
16
18
  @import './functional/typography/typography.css';