From 72ab4b3f1d57e4e3419da953884c7718b5e78a2a Mon Sep 17 00:00:00 2001 From: Naman Goel Date: Tue, 21 Jan 2025 19:41:30 -0800 Subject: [PATCH] chore: move type Types to stylex.Types.* --- packages/stylex/src/VarTypes.js | 7 +------ packages/stylex/src/stylex.js | 19 ++----------------- packages/stylex/src/util-types.js | 15 +++++++++++++++ packages/stylex/type-tests/theming1.js.flow | 13 +++++++++++-- 4 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 packages/stylex/src/util-types.js diff --git a/packages/stylex/src/VarTypes.js b/packages/stylex/src/VarTypes.js index bda409b0b..9e9cb0f0c 100644 --- a/packages/stylex/src/VarTypes.js +++ b/packages/stylex/src/VarTypes.js @@ -7,12 +7,7 @@ * @flow strict */ -export type ValueWithDefault<+T> = - | T - | $ReadOnly<{ - default: ValueWithDefault, - [string]: ValueWithDefault, - }>; +import type { ValueWithDefault } from './util-types'; export type CSSSyntax = | '*' diff --git a/packages/stylex/src/stylex.js b/packages/stylex/src/stylex.js index 471e5c112..9d5f8352c 100644 --- a/packages/stylex/src/stylex.js +++ b/packages/stylex/src/stylex.js @@ -21,23 +21,6 @@ import type { MapNamespaces, } from './StyleXTypes'; import type { - ValueWithDefault, - Angle, - Color, - Url, - Image, - Integer, - LengthPercentage, - Length, - Percentage, - Num, - Resolution, - Time, - TransformFunction, - TransformList, -} from './VarTypes'; -export type { - ValueWithDefault, Angle, Color, Url, @@ -52,6 +35,8 @@ export type { TransformFunction, TransformList, } from './VarTypes'; +import type { ValueWithDefault } from './util-types'; +export * as Types from './VarTypes'; export type { VarGroup, diff --git a/packages/stylex/src/util-types.js b/packages/stylex/src/util-types.js new file mode 100644 index 000000000..ae8029d19 --- /dev/null +++ b/packages/stylex/src/util-types.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + */ + +export type ValueWithDefault<+T> = + | T + | $ReadOnly<{ + default: ValueWithDefault, + [string]: ValueWithDefault, + }>; diff --git a/packages/stylex/type-tests/theming1.js.flow b/packages/stylex/type-tests/theming1.js.flow index c2e63f6e5..897b3b0ef 100644 --- a/packages/stylex/type-tests/theming1.js.flow +++ b/packages/stylex/type-tests/theming1.js.flow @@ -10,7 +10,8 @@ /* eslint-disable no-unused-vars */ import * as React from 'react'; -import stylex from '../src/stylex'; +import * as stylex from '../src/stylex'; +import stylexLegacy from '../src/stylex'; import type { StyleXVar, VarGroup, Theme } from '../src/StyleXTypes'; const DARK = '@media (prefers-color-scheme: dark)'; @@ -52,7 +53,7 @@ const correctTheme = stylex.createTheme(buttonTokens, { correctTheme as Theme; -const result: string = stylex(correctTheme); +const result: string = stylexLegacy(correctTheme); const result2: $ReadOnly<{ className?: string, style?: $ReadOnly<{ [string]: string | number }>, @@ -141,6 +142,14 @@ const typedTokens = stylex.defineVars({ shortAnimation: stylex.types.time('0.5s'), }); +const _bgColor: StyleXVar> = typedTokens.bgColor; +const _cornerRadius: StyleXVar> = + typedTokens.cornerRadius; +const _translucent: StyleXVar> = + typedTokens.translucent; +const _shortAnimation: StyleXVar> = + typedTokens.shortAnimation; + const correctlyTypedTheme = stylex.createTheme(typedTokens, { bgColor: stylex.types.color('red'), cornerRadius: stylex.types.length('4px'),