Skip to content

Commit 7e5defd

Browse files
committed
Update @stylexjs/stylex to 0.13
1 parent 4fac83c commit 7e5defd

9 files changed

Lines changed: 182 additions & 207 deletions

File tree

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
* @necolas
2-
/packages/scripts/* @necolas @nmn

apps/examples/postcss.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
module.exports = {
99
plugins: {
1010
'postcss-react-strict-dom': {
11-
include: ['src/**/*.{js,jsx,mjs,ts,tsx}']
11+
include: ['src/**/*.{js,jsx,mjs,ts,tsx}'],
12+
useLayers: true
1213
},
1314
autoprefixer: {}
1415
}

package-lock.json

Lines changed: 111 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-strict-dom/babel/preset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function reactStrictPreset(_, options = {}) {
2727
[
2828
styleXPlugin,
2929
{
30+
debug: opts.debug,
3031
dev: opts.dev,
3132
importSources: [{ from: 'react-strict-dom', as: 'css' }],
3233
runtimeInjection: false,
@@ -35,8 +36,7 @@ function reactStrictPreset(_, options = {}) {
3536
rootDir: process.cwd(),
3637
type: 'commonJS'
3738
//themeFileExtension: '.cssvars.js',
38-
},
39-
useRemForFontSize: false
39+
}
4040
}
4141
]
4242
];

packages/react-strict-dom/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
},
3535
"dependencies": {
3636
"@babel/helper-module-imports": "^7.24.7",
37-
"@stylexjs/babel-plugin": "^0.9.3",
38-
"@stylexjs/stylex": "^0.9.3",
37+
"@stylexjs/babel-plugin": "^0.13.0",
38+
"@stylexjs/stylex": "^0.13.0",
3939
"postcss-value-parser": "^4.1.0"
4040
},
4141
"devDependencies": {

packages/react-strict-dom/src/native/stylex/index.js

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ function resolveStyle(
408408
return result;
409409
}
410410

411+
export const __customProperties: MutableCustomProperties = {};
412+
411413
/**
412414
* The create method shim should do initial transforms like
413415
* renaming/expanding/validating properties, essentially all the steps
@@ -433,6 +435,45 @@ function _create<S: { +[string]: { +[string]: mixed } }>(styles: S): {
433435
}
434436
export const create: IStyleX['create'] = _create as $FlowFixMe;
435437

438+
const RE_CAPTURE_VAR_NAME = /^var\(--(.*)\)$/;
439+
export const createTheme = (
440+
baseTokens: Tokens,
441+
overrides: CustomProperties
442+
): CustomProperties => {
443+
const result: MutableCustomProperties = { $$theme: 'theme' };
444+
for (const key in baseTokens) {
445+
const varName: string = baseTokens[key];
446+
const normalizedKey = varName.replace(RE_CAPTURE_VAR_NAME, '$1');
447+
result[normalizedKey] = overrides[key];
448+
}
449+
return result;
450+
};
451+
452+
export const defineConsts = (tokens: {
453+
[string]: string
454+
}): { [string]: string } => {
455+
if (__DEV__) {
456+
errorMsg('css.defineConsts() is not supported.');
457+
}
458+
return tokens;
459+
};
460+
461+
type Tokens = { [string]: string };
462+
let defineVarsCount = 1;
463+
export const defineVars = (tokens: CustomProperties): Tokens => {
464+
const result: Tokens = {};
465+
for (const key in tokens) {
466+
const value = tokens[key];
467+
const customPropName = `${key}__id__${defineVarsCount++}`;
468+
result[key] = `var(--${customPropName})`;
469+
// NOTE: it's generally not a good idea to mutate the default context,
470+
// but defineVars is always called before any component body is evaluated,
471+
// and so it's safe to do so here.
472+
__customProperties[customPropName] = value;
473+
}
474+
return result;
475+
};
476+
436477
export const firstThatWorks = <T: string | number>(
437478
...values: $ReadOnlyArray<T>
438479
): T => {
@@ -442,7 +483,6 @@ export const firstThatWorks = <T: string | number>(
442483
type Keyframes = {
443484
+[key: string]: { +[k: string]: string | number }
444485
};
445-
446486
function _keyframes(k: Keyframes): Keyframes {
447487
if (__DEV__) {
448488
errorMsg('css.keyframes() is not supported.');
@@ -451,9 +491,16 @@ function _keyframes(k: Keyframes): Keyframes {
451491
}
452492
export const keyframes: (Keyframes) => string = _keyframes as $FlowFixMe;
453493

454-
/**
455-
* The spread method shim
456-
*/
494+
type PositionTry = {
495+
+[k: string]: string | number
496+
};
497+
function _positionTry(p: PositionTry): PositionTry {
498+
if (__DEV__) {
499+
errorMsg('css.positionTry() is not supported.');
500+
}
501+
return p;
502+
}
503+
export const positionTry: (PositionTry) => string = _positionTry as $FlowFixMe;
457504

458505
export function props(
459506
this: ResolveStyleOptions,
@@ -645,36 +692,3 @@ export function props(
645692

646693
return nativeProps;
647694
}
648-
649-
type Tokens = { [string]: string };
650-
let count = 1;
651-
const RE_CAPTURE_VAR_NAME = /^var\(--(.*)\)$/;
652-
653-
export const __customProperties: MutableCustomProperties = {};
654-
655-
export const defineVars = (tokens: CustomProperties): Tokens => {
656-
const result: Tokens = {};
657-
for (const key in tokens) {
658-
const value = tokens[key];
659-
const customPropName = `${key}__id__${count++}`;
660-
result[key] = `var(--${customPropName})`;
661-
// NOTE: it's generally not a good idea to mutate the default context,
662-
// but defineVars is always called before any component body is evaluated,
663-
// and so it's safe to do so here.
664-
__customProperties[customPropName] = value;
665-
}
666-
return result;
667-
};
668-
669-
export const createTheme = (
670-
baseTokens: Tokens,
671-
overrides: CustomProperties
672-
): CustomProperties => {
673-
const result: MutableCustomProperties = { $$theme: 'theme' };
674-
for (const key in baseTokens) {
675-
const varName: string = baseTokens[key];
676-
const normalizedKey = varName.replace(RE_CAPTURE_VAR_NAME, '$1');
677-
result[normalizedKey] = overrides[key];
678-
}
679-
return result;
680-
};

packages/react-strict-dom/src/types/styles.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ export type Styles = StyleXArray<
2525

2626
export type IStyleX = $ReadOnly<{
2727
create: TStyleX['create'],
28+
createTheme: TStyleX['createTheme'],
29+
defineConsts: TStyleX['defineConsts'],
30+
defineVars: TStyleX['defineVars'],
2831
firstThatWorks: TStyleX['firstThatWorks'],
2932
keyframes: TStyleX['keyframes'],
33+
positionTry: TStyleX['positionTry'],
3034
props: TStyleX['props'],
31-
defineVars: TStyleX['defineVars'],
32-
createTheme: TStyleX['createTheme'],
3335
...
3436
}>;
3537

packages/react-strict-dom/tests/css-test.native.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,16 @@ describe('properties: general', () => {
584584
);
585585
});
586586

587+
test('positionTryFallbacks', () => {
588+
css.positionTry({
589+
left: 0,
590+
width: 1000
591+
});
592+
expect(console.error).toHaveBeenCalledWith(
593+
expect.stringContaining('css.positionTry() is not supported')
594+
);
595+
});
596+
587597
test('transitionProperty', () => {
588598
const { underTest } = css.create({
589599
underTest: {

patches/@stylexjs+babel-plugin+0.9.3.patch

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)