Skip to content

Commit f81230b

Browse files
committed
refactor(core): one source for the touch, compact and iOS-gate style keys
touchKeys (StyleX defineConsts in utils/touchPresentation.stylex.ts) holds the touch presentation resolver's queries as at-rule keys; every core style imports them instead of spelling the query. A test keeps each key equal to the resolver's constant and fails on a literal spelling in core (another package may only spell it exactly). Outer at-rule blocks become property-level conditions, which an imported key requires; Tab repeats its touch rule inside its hover branch, since StyleX no longer makes the two media keys exclusive by itself. Generated CSS is unchanged for every other file.
1 parent 9d8226d commit f81230b

43 files changed

Lines changed: 443 additions & 210 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/touch-style-keys.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[chore] Core's touch, compact and iOS-gate style keys come from one place: `touchKeys` (StyleX `defineConsts` in `utils/touchPresentation.stylex.ts`), equal to the touch presentation resolver's queries, instead of a literal spelling in each component. No style changes: every rule keeps its query. The keys are also exported as `@astryxdesign/core/utils/touchPresentation.stylex` for other packages (proposed; pending owner review).
6+
7+
@vjeux

‎packages/core/package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@
171171
"types": "./dist/utils/interactionOverlay.stylex.d.ts",
172172
"default": "./dist/utils/interactionOverlay.stylex.js"
173173
},
174+
"./utils/touchPresentation.stylex": {
175+
"source": "./src/utils/touchPresentation.stylex.ts",
176+
"types": "./dist/utils/touchPresentation.stylex.d.ts",
177+
"default": "./dist/utils/touchPresentation.stylex.js"
178+
},
174179
"./docs.mjs": "./docs.mjs",
175180
"./groups.doc.mjs": "./groups.doc.mjs",
176181
"./locales/*.json": "./locales/*.json",

‎packages/core/src/Button/Button.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
6262
import {usePressFeedback} from '../hooks/usePressFeedback';
6363
import {useTranslator} from '../i18n';
6464
import type {ButtonVariantMap} from './index';
65+
import {touchKeys} from '../utils/touchPresentation.stylex';
6566

6667
/**
6768
* Base button styles
@@ -122,7 +123,7 @@ const styles = stylex.create({
122123
// writes `data-astryx-press` instead; see interactionOverlay.stylex.ts.
123124
':active:where(:not(:disabled,[aria-disabled="true"]))': {
124125
default: 'scale(0.98)',
125-
'@media (pointer: coarse)': 'scale(1)',
126+
[touchKeys.touch]: 'scale(1)',
126127
},
127128
'[data-astryx-press="on"]': 'scale(0.98)',
128129
},

‎packages/core/src/Chat/ChatComposerInput.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {Badge, type BadgeProps} from '../Badge';
6969
import {useChatComposerContext} from './ChatContext';
7070
import {themeProps} from '../utils/themeProps';
7171
import {useTranslator} from '../i18n';
72+
import {touchKeys} from '../utils/touchPresentation.stylex';
7273

7374
// =============================================================================
7475
// Types
@@ -266,8 +267,8 @@ const styles = stylex.create({
266267
// -webkit-touch-callout to key the coarse-pointer floor to it.
267268
fontSize: {
268269
default: typeScaleVars['--text-body-size'],
269-
'@media (pointer: coarse)': {
270-
'@supports (-webkit-touch-callout: none)': `max(1rem, ${typeScaleVars['--text-body-size']})`,
270+
[touchKeys.touch]: {
271+
[touchKeys.iosSupports]: `max(1rem, ${typeScaleVars['--text-body-size']})`,
271272
},
272273
},
273274
lineHeight: `${LINE_HEIGHT_PX}px`,
@@ -286,8 +287,8 @@ const styles = stylex.create({
286287
// Same iOS-only floor as the editable region it stands in for.
287288
fontSize: {
288289
default: typeScaleVars['--text-body-size'],
289-
'@media (pointer: coarse)': {
290-
'@supports (-webkit-touch-callout: none)': `max(1rem, ${typeScaleVars['--text-body-size']})`,
290+
[touchKeys.touch]: {
291+
[touchKeys.iosSupports]: `max(1rem, ${typeScaleVars['--text-body-size']})`,
291292
},
292293
},
293294
lineHeight: `${LINE_HEIGHT_PX}px`,

‎packages/core/src/CheckboxInput/CheckboxInput.tsx‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {useIndicator} from '../Indicator';
5555
import {themeProps} from '../utils/themeProps';
5656

5757
import {useMergedRefs} from '../hooks/useMergedRefs';
58+
import {touchKeys} from '../utils/touchPresentation.stylex';
5859

5960
// The touch press's paint, declared by the shared overlay styles on the
6061
// element the controller writes to (`pressedAlpha`) at the press's strength,
@@ -96,7 +97,7 @@ const styles = stylex.create({
9697
default: 'transparent',
9798
[stylex.when.ancestor(':active', indicatorScope)]: {
9899
default: colorVars['--color-overlay-pressed'],
99-
'@media (pointer: coarse)': 'transparent',
100+
[touchKeys.touch]: 'transparent',
100101
},
101102
},
102103
// The touch press, as an image layer over the colour: an image change is
@@ -107,12 +108,12 @@ const styles = stylex.create({
107108
default: null,
108109
[stylex.when.ancestor('[data-astryx-press="on"]', indicatorScope)]: {
109110
default: null,
110-
'@media (pointer: coarse)': pressedOverlayImage,
111+
[touchKeys.touch]: pressedOverlayImage,
111112
},
112113
[stylex.when.ancestor('[data-astryx-press="fading"]', indicatorScope)]:
113114
{
114115
default: null,
115-
'@media (pointer: coarse)': pressedOverlayImage,
116+
[touchKeys.touch]: pressedOverlayImage,
116117
},
117118
},
118119
},
@@ -136,10 +137,8 @@ const styles = stylex.create({
136137
zIndex: 1,
137138
},
138139
inputCoarse: {
139-
'@media (pointer: coarse)': {
140-
minInlineSize: 24,
141-
minBlockSize: 24,
142-
},
140+
minInlineSize: {default: null, [touchKeys.touch]: 24},
141+
minBlockSize: {default: null, [touchKeys.touch]: 24},
143142
},
144143
inputDisabled: {
145144
cursor: 'default',

‎packages/core/src/ClickableCard/ClickableCard.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {usePressFeedback} from '../hooks/usePressFeedback';
5252

5353
import {useMergedRefs} from '../hooks/useMergedRefs';
5454
import {disabledInteractionProps} from '../utils/disabledInteraction';
55+
import {touchKeys} from '../utils/touchPresentation.stylex';
5556
// =============================================================================
5657
// Styles — only the interactive layer, Card handles everything else
5758
// =============================================================================
@@ -96,7 +97,7 @@ const styles = stylex.create({
9697
default: null,
9798
':active': {
9899
default: colorVars['--color-overlay-pressed'],
99-
'@media (pointer: coarse)': 'transparent',
100+
[touchKeys.touch]: 'transparent',
100101
},
101102
'@media (hover: hover)': {
102103
default: null,

‎packages/core/src/CommandPalette/CommandPaletteInput.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {useTranslator} from '../i18n';
4545

4646
import {useMergedRefs} from '../hooks/useMergedRefs';
4747
import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
48+
import {touchKeys} from '../utils/touchPresentation.stylex';
4849
const styles = stylex.create({
4950
wrapper: {
5051
display: 'flex',
@@ -93,8 +94,8 @@ const styles = stylex.create({
9394
// -webkit-touch-callout to key the coarse-pointer floor to it.
9495
fontSize: {
9596
default: typeScaleVars['--text-body-size'],
96-
'@media (pointer: coarse)': {
97-
'@supports (-webkit-touch-callout: none)': `max(1rem, ${typeScaleVars['--text-body-size']})`,
97+
[touchKeys.touch]: {
98+
[touchKeys.iosSupports]: `max(1rem, ${typeScaleVars['--text-body-size']})`,
9899
},
99100
},
100101
lineHeight: typeScaleVars['--text-body-leading'],

‎packages/core/src/ComplexSelector/ComplexSelector.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
6262
import {usePressFeedback} from '../hooks/usePressFeedback';
6363
import type {SizeValue} from '../utils/types';
6464
import {themeProps} from '../utils/themeProps';
65+
import {touchKeys} from '../utils/touchPresentation.stylex';
6566

6667
const styles = stylex.create({
6768
triggerContainer: {
@@ -79,8 +80,8 @@ const styles = stylex.create({
7980
// -webkit-touch-callout to key the coarse-pointer floor to it.
8081
fontSize: {
8182
default: typeScaleVars['--text-label-size'],
82-
'@media (pointer: coarse)': {
83-
'@supports (-webkit-touch-callout: none)': `max(1rem, ${typeScaleVars['--text-label-size']})`,
83+
[touchKeys.touch]: {
84+
[touchKeys.iosSupports]: `max(1rem, ${typeScaleVars['--text-label-size']})`,
8485
},
8586
},
8687
lineHeight: typeScaleVars['--text-label-leading'],
@@ -147,7 +148,7 @@ const styles = stylex.create({
147148
// `data-astryx-press` instead (see interactionOverlay.stylex.ts).
148149
':active': {
149150
default: 'scale(0.98)',
150-
'@media (pointer: coarse)': 'scale(1)',
151+
[touchKeys.touch]: 'scale(1)',
151152
},
152153
'[data-astryx-press="on"]': 'scale(0.98)',
153154
},
@@ -172,7 +173,7 @@ const styles = stylex.create({
172173
default: 'scale(1)',
173174
':active': {
174175
default: 'scale(0.98)',
175-
'@media (pointer: coarse)': 'scale(1)',
176+
[touchKeys.touch]: 'scale(1)',
176177
},
177178
'[data-astryx-press="on"]': 'scale(0.98)',
178179
},

‎packages/core/src/DateInput/DateInput.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ const styles = stylex.create({
124124
// -webkit-touch-callout to key the coarse-pointer floor to it.
125125
fontSize: {
126126
default: typeScaleVars['--text-body-size'],
127-
'@media (pointer: coarse)': {
128-
'@supports (-webkit-touch-callout: none)': `max(1rem, ${typeScaleVars['--text-body-size']})`,
127+
[touchKeys.touch]: {
128+
[touchKeys.iosSupports]: `max(1rem, ${typeScaleVars['--text-body-size']})`,
129129
},
130130
},
131131
lineHeight: typeScaleVars['--text-body-leading'],
@@ -213,6 +213,7 @@ import {focusOutlineStyles} from '../utils/focusOutline.stylex';
213213
import {useLocale, useTranslator} from '../i18n';
214214

215215
import {useMergedRefs} from '../hooks/useMergedRefs';
216+
import {touchKeys} from '../utils/touchPresentation.stylex';
216217
export interface DateInputProps extends Omit<
217218
FieldInputBaseProps<HTMLInputElement>,
218219
'onChange' | 'defaultValue'

‎packages/core/src/DateInput/DateInputTouch.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,10 +2623,10 @@ describe('DateInput — scroll CSS (definition-level)', () => {
26232623
source.indexOf(' monthArrowIcon: {'),
26242624
);
26252625
expect(arrow).toContain(
2626-
"minBlockSize: {default: null, '@media (pointer: coarse)': TOUCH_TARGET}",
2626+
'minBlockSize: {default: null, [touchKeys.touch]: TOUCH_TARGET}',
26272627
);
26282628
expect(arrow).toContain(
2629-
"minInlineSize: {default: null, '@media (pointer: coarse)': TOUCH_TARGET}",
2629+
'minInlineSize: {default: null, [touchKeys.touch]: TOUCH_TARGET}',
26302630
);
26312631
});
26322632

0 commit comments

Comments
 (0)