Skip to content

Commit ab5ab6b

Browse files
Adding base motion tokens for duration and easing (#1080)
* working on motion * vrt fix * fix for durations in seconds * fix test * rm duplicate output * add missing references
1 parent fab6044 commit ab5ab6b

File tree

9 files changed

+104
-10
lines changed

9 files changed

+104
-10
lines changed

.changeset/thin-birds-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/primitives': minor
3+
---
4+
5+
Adding motion tokens

.github/workflows/visual_regression_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
sleep 5
4545
4646
- name: Run Visual Regression Tests
47-
uses: docker://mcr.microsoft.com/playwright:v1.47.1-jammy
47+
uses: docker://mcr.microsoft.com/playwright:v1.49.0-jammy
4848
env:
4949
STORYBOOK_URL: 'http://172.17.0.1:6006'
5050
with:

scripts/buildTokens.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const getStyleDictionaryConfig: StyleDictionaryConfigGenerator = (
2929
source, // build the special formats
3030
include,
3131
log: {
32-
warnings: 'warn', // 'warn' | 'error' | 'disabled'
33-
verbosity: 'verbose', // 'default' | 'silent' | 'verbose'
32+
warnings: 'disabled', // 'warn' | 'error' | 'disabled'
33+
verbosity: 'silent', // 'default' | 'silent' | 'verbose'
3434
errors: {
3535
brokenReferences: 'throw', // 'throw' | 'console'
3636
},
@@ -157,7 +157,11 @@ export const buildDesignTokens = async (buildOptions: ConfigGeneratorOptions): P
157157
const extendedSD = await PrimerStyleDictionary.extend(
158158
getStyleDictionaryConfig(
159159
`functional/motion/motion`,
160-
[`src/tokens/functional/motion/*.json5`],
160+
[
161+
`src/tokens/functional/motion/*.json5`,
162+
// `src/tokens/base/motion/timing.json5`,
163+
// `src/tokens/base/motion/easing.json5`,
164+
],
161165
[`src/tokens/base/motion/*.json5`],
162166
buildOptions,
163167
{

src/tokens/base/motion/easing.json5

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
base: {
3+
easing: {
4+
linear: {
5+
$value: [0, 0, 1, 1],
6+
$type: 'cubicBezier',
7+
$description: 'Ideal for non-movement properties, like opacity or background color.',
8+
},
9+
easeIn: {
10+
$value: [0.7, 0.1, 0.75, 0.9],
11+
$type: 'cubicBezier',
12+
$description: 'Ideal for movement that starts on the page and ends off the page.',
13+
},
14+
easeOut: {
15+
$value: [0.16, 1, 0.3, 1],
16+
$type: 'cubicBezier',
17+
$description: 'Ideal for movement that starts off the page and ends on the page.',
18+
},
19+
easeInOut: {
20+
$value: [0.6, 0, 0.2, 1],
21+
$type: 'cubicBezier',
22+
$description: 'Ideal for movement that starts and ends on the page.',
23+
},
24+
},
25+
},
26+
}

src/tokens/base/motion/timing.json5

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
base: {
3+
duration: {
4+
'0': {
5+
$value: '0ms',
6+
$type: 'duration',
7+
},
8+
'75': {
9+
$value: '75ms',
10+
$type: 'duration',
11+
},
12+
'200': {
13+
$value: '200ms',
14+
$type: 'duration',
15+
},
16+
'300': {
17+
$value: '300ms',
18+
$type: 'duration',
19+
},
20+
'400': {
21+
$value: '400ms',
22+
$type: 'duration',
23+
},
24+
'500': {
25+
$value: '500ms',
26+
$type: 'duration',
27+
},
28+
'600': {
29+
$value: '600ms',
30+
$type: 'duration',
31+
},
32+
'700': {
33+
$value: '700ms',
34+
$type: 'duration',
35+
},
36+
'800': {
37+
$value: '800ms',
38+
$type: 'duration',
39+
},
40+
'900': {
41+
$value: '900ms',
42+
$type: 'duration',
43+
},
44+
'1000': {
45+
$value: '1000ms',
46+
$type: 'duration',
47+
},
48+
},
49+
},
50+
}

src/tokens/functional/motion/loading.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
loading: {
88
delay: {
99
default: {
10-
$value: '1000ms',
10+
$value: '{base.duration.1000}',
1111
$type: 'duration',
1212
$description: 'The amount of time to wait before showing a loading indicator or announcing a loading state to assistive technologies.',
1313
},

src/tokens/functional/motion/patterns.json5

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77
spinner: {
88
duration: {
99
rotation: {
10-
$value: '1000ms',
10+
$value: '{base.duration.1000}',
1111
$type: 'duration',
1212
$description: 'The amount of time it takes the "Spinner" loading indicator to make a full 360deg rotation',
1313
},
1414
},
15+
easing: {
16+
rotation: {
17+
$value: '{base.easing.linear}',
18+
$type: 'cubicBezier',
19+
$description: 'The easing curve for the "Spinner" loading indicator rotation',
20+
},
21+
},
1522
},
1623
skeletonLoader: {
1724
shimmer: {
1825
duration: {
1926
scale: {
20-
$value: '1000ms',
27+
$value: '{base.duration.1000}',
2128
$type: 'duration',
2229
$description: 'The amount of times it takes the "shimmer" effect to go from the start (left) of the skeleton loader to the end (right)',
2330
},

src/transformers/durationToCss.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Transformer: durationToCss', () => {
3636
expect(() =>
3737
durationToCss.transform(
3838
getMockToken({
39-
value: '1s',
39+
value: '1sec',
4040
}),
4141
{},
4242
{},

src/transformers/durationToCss.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ export const durationToCss: Transform = {
1515
transform: (token: TransformedToken, _config: PlatformConfig, options: Config) => {
1616
const valueProp = options.usesDtcg ? '$value' : 'value'
1717
// throw an error if token value is not a string or does not end with `ms`
18-
if (typeof token[valueProp] !== `string` || !token[valueProp].endsWith(`ms`)) {
19-
throw new Error(`duration token value must be a string with an "ms" unit`)
18+
if (typeof token[valueProp] !== `string` || !(token[valueProp].endsWith(`ms`) || token[valueProp].endsWith(`s`))) {
19+
throw new Error(
20+
`duration token value must be a string with an "ms" || "s" unit, invalid token: ${token.name} with value: ${token[valueProp]}`,
21+
)
2022
}
2123
// get value
2224
let value = parseInt(token[valueProp].replace('ms', ''))

0 commit comments

Comments
 (0)