An open source design system that's fully customizable and agent ready
TypeScript
feat(tokens): add --ease-exit, the curve BottomSheet already closes on (#8004)
Kenton Quatmanc9066fe8be31
diff --git a/.changeset/ease-exit-token.md b/.changeset/ease-exit-token.mdnew file mode 100644index 0000000000..114250b7b0--- /dev/null+++ b/.changeset/ease-exit-token.md@@ -0,0 +1,8 @@+---+'@astryxdesign/core': patch+'@astryxdesign/cli': patch+---++[feat] New `--ease-exit` token, `cubic-bezier(0.3, 0, 0.6, 0.6)`: an accelerating curve for things leaving the screen, beside `--ease-standard` for things arriving. `BottomSheet` closes on it at the value it already used, so nothing looks different; a theme can now retune that exit through the token. On a touch screen the sheet keeps its own closing curve. `astryx docs motion`, the easing token table, and the theme template list it. (#8004)++@kentonquatmandiff --git a/packages/cli/assets/docs/motion.doc.mjs b/packages/cli/assets/docs/motion.doc.mjsindex a99a9282bb..143ca4156a 100644--- a/packages/cli/assets/docs/motion.doc.mjs+++ b/packages/cli/assets/docs/motion.doc.mjs@@ -50,7 +50,7 @@ export const docs = {content: [{type: 'prose',- text: 'One easing curve, `--ease-standard`.',+ text: 'Two easing curves. `--ease-standard` decelerates, for things arriving and state changes. `--ease-exit` accelerates, for things leaving: it moves off from rest and leaves fast, so the travel stays visible for the whole duration.',},{type: 'token-ref',diff --git a/packages/cli/assets/docs/tree/tokens-ease.doc.mjs b/packages/cli/assets/docs/tree/tokens-ease.doc.mjsindex ed95f3bde5..0b5d349623 100644--- a/packages/cli/assets/docs/tree/tokens-ease.doc.mjs+++ b/packages/cli/assets/docs/tree/tokens-ease.doc.mjs@@ -36,6 +36,10 @@ export const docs = {["--ease-standard","cubic-bezier(0.24, 1, 0.4, 1)"+ ],+ [+ "--ease-exit",+ "cubic-bezier(0.3, 0, 0.6, 0.6)"]]}diff --git a/packages/cli/assets/docs/tree/tokens.doc.mjs b/packages/cli/assets/docs/tree/tokens.doc.mjsindex 0349b6eb7f..0cdb1efba7 100644--- a/packages/cli/assets/docs/tree/tokens.doc.mjs+++ b/packages/cli/assets/docs/tree/tokens.doc.mjs@@ -2,7 +2,7 @@// AUTO-GENERATED — do not edit manually.// Run: node scripts/generate-token-docs.mjs-// Total: 282 tokens across 15 categories.+// Total: 283 tokens across 15 categories./** @type {import('@astryxdesign/cli/authoring').NamespaceDoc} */export const docs = {diff --git a/packages/cli/assets/theme.template.ts b/packages/cli/assets/theme.template.tsindex dfa1aeaa76..de652e1079 100644--- a/packages/cli/assets/theme.template.ts+++ b/packages/cli/assets/theme.template.ts@@ -217,7 +217,7 @@ export const myTheme = defineTheme({// --radius-* none · inner · element · container · page · chat · full// --shadow-* low/med/high + inset-{hover,selected,success,warning,error}// --duration-* {fast,medium,slow} × {-min, base, -max}- // --ease-standard+ // --ease-* standard (arriving, state) · exit (leaving)// --font-family-* body · heading · code// --font-size-* 4xs … 5xl// --font-weight-* normal · medium · semibold · bolddiff --git a/packages/cli/test/__golden__/no-icon-set/docs-topics.json b/packages/cli/test/__golden__/no-icon-set/docs-topics.jsonindex 0258d46bc7..049e801ebe 100644--- a/packages/cli/test/__golden__/no-icon-set/docs-topics.json+++ b/packages/cli/test/__golden__/no-icon-set/docs-topics.json@@ -201,7 +201,7 @@"usage","best-practices"],- "skeleton": "e648d618f9141bbd7f15bf970ba9e0d41b59ff9ae89e0cbbb2042e98bd5f0109",+ "skeleton": "55910f8bc7dd8e5ba12067f98a5d75bd1d014e8f72c5da34ad8b695658a77236","mentions": []},"principles": {diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.test.tsxindex 900f34051e..8ad6cb50b5 100644--- a/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx+++ b/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx@@ -354,10 +354,13 @@ describe('BottomSheetPanel', () => {** `--ease-standard` is a decelerate curve: on it the sheet was half gone in* 59ms of a 410ms transition and 90% gone in 163ms, so the close was over- * before it could be seen. The closing state therefore carries its own- * accelerating curve, and only the closing state does.+ * before it could be seen. The closing state therefore reads the+ * accelerating `--ease-exit` curve (its default is pinned in+ * theme/tokens.test.ts), and only the closing state does. A touch+ * presentation keeps its own curve, which the exit tokens do not change+ * (spec:AST-090 FR12).*/- it('closes on an accelerating curve of its own, not the entrance timing', () => {+ it('closes on the exit curve, not the entrance timing', () => {const declarationsFor = (element: HTMLElement) => {const classes = new Set(element.className.split(/\s+/));const out: string[] = [];@@ -378,6 +381,35 @@ describe('BottomSheetPanel', () => {}return out.join('\n');};+ // The rules inside an `@media` block with the given condition.+ const mediaDeclarationsFor = (element: HTMLElement, condition: string) => {+ const classes = new Set(element.className.split(/\s+/));+ const out: string[] = [];+ for (const styleSheet of Array.from(document.styleSheets)) {+ let rules: CSSRuleList;+ try {+ rules = styleSheet.cssRules;+ } catch {+ continue;+ }+ for (const rule of Array.from(rules)) {+ if (+ !(rule instanceof CSSMediaRule) ||+ rule.media.mediaText.replace(/\s/g, '') !== condition+ ) {+ continue;+ }+ for (const inner of Array.from(rule.cssRules)) {+ const selector = (inner as CSSStyleRule).selectorText;+ const owner = selector?.match(/^\.([\w-]+)/)?.[1];+ if (owner != null && classes.has(owner)) {+ out.push(inner.cssText);+ }+ }+ }+ }+ return out.join('\n');+ };const {container: closing} = render(<BottomSheetPanel@@ -389,14 +421,25 @@ describe('BottomSheetPanel', () => {Panel content</BottomSheetPanel>,);- const closingRules = declarationsFor(- closing.querySelector('.astryx-bottom-sheet') as HTMLElement,- );- // An accelerating curve: no vertical rise at the start (y1 = 0), so the- // travel lands inside the duration instead of ahead of it.+ const closingSheet = closing.querySelector(+ '.astryx-bottom-sheet',+ ) as HTMLElement;+ const closingRules = declarationsFor(closingSheet);+ // The theme's exit curve, not a curve restated locally.expect(closingRules).toContain(+ 'transition-timing-function: var(--ease-exit)',+ );+ expect(closingRules).not.toContain('cubic-bezier(.3,0,.6,.6)');+ // Under a coarse pointer the close keeps its own curve, so a theme's+ // `--ease-exit` does not reach a touch presentation.+ const coarseClosingRules = mediaDeclarationsFor(+ closingSheet,+ '(pointer:coarse)',+ );+ expect(coarseClosingRules).toContain('transition-timing-function: cubic-bezier(.3,0,.6,.6)',);+ expect(coarseClosingRules).not.toContain('--ease-exit');const {container: resting} = render(<BottomSheetPanel@@ -414,7 +457,7 @@ describe('BottomSheetPanel', () => {expect(restingRules).toContain('transition-timing-function: var(--ease-standard)',);- expect(restingRules).not.toContain('cubic-bezier(.3,0,.6,.6)');+ expect(restingRules).not.toContain('--ease-exit');});describe('container padding', () => {diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.tsxindex 502210f2d1..30fa891638 100644--- a/packages/core/src/BottomSheet/BottomSheetPanel.tsx+++ b/packages/core/src/BottomSheet/BottomSheetPanel.tsx@@ -205,11 +205,11 @@ const styles = stylex.create({* 90% off in 163ms -- the travel is over before the eye has followed it, and* the rest of the duration moves pixels already below the fold.*- * An exit accelerates instead: away from rest, gathering speed, quickest as- * it leaves the screen. The curve is deliberately gentle rather than a hard- * `ease-in` -- it is moving within ~50ms, so the close reads as one- * departure rather than a hesitation and a snap. The duration is the- * entrance's own band, so only the curve differs between the two+ * An exit accelerates instead (`--ease-exit`): away from rest, gathering+ * speed, quickest as it leaves the screen. The curve is deliberately gentle+ * rather than a hard `ease-in` -- it is moving within ~50ms, so the close+ * reads as one departure rather than a hesitation and a snap. The duration+ * is the entrance's own band, so only the curve differs between the two* directions; a shorter band leaves too little visible travel once a theme* scales the motion scale down (neutral's medium is 300ms against 410ms).*/@@ -224,7 +224,13 @@ const styles = stylex.create({default: null,[REDUCED_MOTION_COARSE]: 0,},- transitionTimingFunction: 'cubic-bezier(0.3, 0, 0.6, 0.6)',+ // A pointer presentation closes on the theme's exit curve (spec:AST-090+ // FR12). A touch presentation keeps its own curve, which the exit tokens+ // do not change.+ transitionTimingFunction: {+ default: easeVars['--ease-exit'],+ '@media (pointer: coarse)': 'cubic-bezier(0.3, 0, 0.6, 0.6)',+ },},/*** An exit that cross-fades on a pointer the media query does not cover: adiff --git a/packages/core/src/theme/tokens.stylex.ts b/packages/core/src/theme/tokens.stylex.tsindex df271111d7..d53393e8ed 100644--- a/packages/core/src/theme/tokens.stylex.ts+++ b/packages/core/src/theme/tokens.stylex.ts@@ -316,9 +316,14 @@ export type DurationVarName = keyof typeof durationDefaults;// =============================================================================// Motion Tokens — Easing// =============================================================================+// --ease-standard decelerates: things arriving and state changes.+// --ease-exit accelerates: things leaving. It moves off from rest (no rise at+// the start) and is quickest as the surface leaves, so the travel lands inside+// the duration instead of in its first few frames.export const easeDefaults = {'--ease-standard': 'cubic-bezier(0.24, 1, 0.4, 1)',+ '--ease-exit': 'cubic-bezier(0.3, 0, 0.6, 0.6)',} as const;export const easeVars = stylex.defineVars(easeDefaults);diff --git a/packages/core/src/theme/tokens.test.ts b/packages/core/src/theme/tokens.test.tsindex 9a00bbb741..38ca64736b 100644--- a/packages/core/src/theme/tokens.test.ts+++ b/packages/core/src/theme/tokens.test.ts@@ -102,6 +102,21 @@ describe('resolveThemeToken', () => {);});+ it('resolves the exit curve to its accelerating default and to an override', () => {+ // No rise at the start (y1 = 0): an exit moves off from rest and leaves+ // fast, so its travel stays visible for the whole duration.+ expect(resolveThemeToken(null, '--ease-exit', {mode: 'light'})).toBe(+ 'cubic-bezier(0.3, 0, 0.6, 0.6)',+ );+ const snappyExit = defineTheme({+ name: 'snappy-exit',+ tokens: {'--ease-exit': 'ease-in'},+ });+ expect(resolveThemeToken(snappyExit, '--ease-exit', {mode: 'dark'})).toBe(+ 'ease-in',+ );+ });+it('returns fallback for unknown token names', () => {expect(resolveThemeToken(testTheme, '--missing-token', {