Skip to content

Commit f98e52f

Browse files
Update easing curves (#1151)
* update easing
1 parent dbbb594 commit f98e52f

File tree

7 files changed

+102
-39
lines changed

7 files changed

+102
-39
lines changed

.changeset/early-starfishes-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/primitives': patch
3+
---
4+
5+
Update easing curves

docs/storybook/stories/Motion/Base.stories.tsx

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import baseMotionTokens from '../../../../dist/docs/base/motion/motion.json'
44
import {DataTable, Table} from '@primer/react/drafts'
55
import {InlineCode} from '../StorybookComponents/InlineCode/InlineCode'
66
import {getTokensByName} from '../utilities/getTokensByName'
7+
import {CubicBezier} from '../StorybookComponents/BezierCurve/BezierCurve'
8+
import {Card} from '../StorybookComponents/Card/Card'
79

810
export default {
911
title: 'Motion/Base',
@@ -36,7 +38,7 @@ export const Base = () => {
3638
field: 'name',
3739
rowHeader: true,
3840
renderCell: row => {
39-
return <InlineCode value={row.name} copyClipboard />
41+
return <InlineCode value={row.name} cssVar={true} copyClipboard />
4042
},
4143
},
4244
{
@@ -58,39 +60,29 @@ export const Base = () => {
5860
]}
5961
/>
6062
</Table.Container>
61-
<Table.Container>
62-
<h2 id="easing">Base easing</h2>
63-
<DataTable
64-
aria-labelledby="easing"
65-
data={data.filter(item => item.type === 'cubicBezier')}
66-
columns={[
67-
{
68-
header: 'Token',
69-
field: 'name',
70-
rowHeader: true,
71-
renderCell: row => {
72-
return <InlineCode value={row.name} copyClipboard />
73-
},
74-
},
75-
{
76-
header: 'Output value',
77-
field: 'value',
78-
rowHeader: true,
79-
renderCell: row => {
80-
return <p>{JSON.stringify(row.value)}</p>
81-
},
82-
},
83-
{
84-
header: 'Source value',
85-
field: 'original',
86-
rowHeader: true,
87-
renderCell: row => {
88-
return <p>{JSON.stringify(row.original.$value)}</p>
89-
},
90-
},
91-
]}
92-
/>
93-
</Table.Container>
63+
64+
<h2 id="easing">Base easing</h2>
65+
<div style={{display: 'flex', flexDirection: 'row', alignItems: 'start', gap: 8}}>
66+
{data
67+
.filter(item => item.type === 'cubicBezier')
68+
.map(item => (
69+
<Card
70+
key={item.name}
71+
style={{
72+
display: 'flex',
73+
flexDirection: 'column',
74+
alignItems: 'center',
75+
gap: 8,
76+
minWidth: 200,
77+
maxWidth: 300,
78+
}}
79+
>
80+
<CubicBezier bezier={item.value} />
81+
<p>[{item.value.join(', ')}]</p>
82+
<InlineCode value={item.name} cssVar={true} copyClipboard />
83+
</Card>
84+
))}
85+
</div>
9486
</>
9587
)
9688
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, {useRef, useEffect} from 'react'
2+
3+
export const CubicBezier = ({bezier}: {bezier: [number, number, number, number]}) => {
4+
const canvasRef = useRef(null)
5+
const padding = 20
6+
const lineWidth = '6'
7+
const fillStart = 'purple'
8+
const fillEnd = 'blue'
9+
10+
// Convert CSS cubic-bezier array to control points
11+
const [x1, y1, x2, y2] = bezier
12+
const p0 = {x: padding, y: 500 - padding}
13+
const p1 = {
14+
x: x1 * (500 - 2 * padding) + padding,
15+
y: 500 - (y1 * (500 - 2 * padding) + padding),
16+
}
17+
const p2 = {
18+
x: x2 * (500 - 2 * padding) + padding,
19+
y: 500 - (y2 * (500 - 2 * padding) + padding),
20+
}
21+
const p3 = {x: 500 - padding, y: padding}
22+
23+
useEffect(() => {
24+
const canvas = canvasRef.current
25+
const ctx = canvas.getContext('2d')
26+
ctx.clearRect(0, 0, canvas.width, canvas.height)
27+
28+
// Create gradient
29+
const gradient = ctx.createLinearGradient(p0.x, p0.y, p3.x, p3.y)
30+
gradient.addColorStop(0, fillStart)
31+
gradient.addColorStop(1, fillEnd)
32+
33+
// Draw bezier curve
34+
ctx.strokeStyle = gradient
35+
ctx.lineWidth = lineWidth
36+
ctx.lineCap = 'round'
37+
ctx.beginPath()
38+
ctx.moveTo(p0.x, p0.y)
39+
ctx.bezierCurveTo(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y)
40+
ctx.stroke()
41+
}, [p0, p1, p2, p3])
42+
43+
return <canvas ref={canvasRef} width={500} height={500} />
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.Card {
2+
border-radius: var(--borderRadius-default);
3+
border-color: var(--borderColor-default);
4+
border-width: 1px;
5+
border-style: solid;
6+
padding: 16px;
7+
8+
* {
9+
max-width: 100%;
10+
}
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React, {ReactNode} from 'react'
2+
import './Card.css'
3+
4+
interface CardProps extends React.Component {
5+
children: ReactNode
6+
style: React.CSSProperties
7+
}
8+
9+
export const Card = ({children, style}: CardProps) => {
10+
return (
11+
<div className="Card" style={style}>
12+
{children}
13+
</div>
14+
)
15+
}

src/tokens/base/motion/easing.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$description: 'Ideal for movement that starts on the page and ends off the page.',
1313
},
1414
easeOut: {
15-
$value: [0.16, 1, 0.3, 1],
15+
$value: [0.3, 0.8, 0.6, 1],
1616
$type: 'cubicBezier',
1717
$description: 'Ideal for movement that starts off the page and ends on the page.',
1818
},

src/tokens/base/motion/timing.json5

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
$value: '0ms',
66
$type: 'duration',
77
},
8-
'75': {
9-
$value: '75ms',
10-
$type: 'duration',
11-
},
128
'100': {
139
$value: '100ms',
1410
$type: 'duration',

0 commit comments

Comments
 (0)