Skip to content

Commit

Permalink
chore: move type Types to stylex.Types.*
Browse files Browse the repository at this point in the history
  • Loading branch information
nmn committed Jan 22, 2025
1 parent e30b857 commit 72ab4b3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
7 changes: 1 addition & 6 deletions packages/stylex/src/VarTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
* @flow strict
*/

export type ValueWithDefault<+T> =
| T
| $ReadOnly<{
default: ValueWithDefault<T>,
[string]: ValueWithDefault<T>,
}>;
import type { ValueWithDefault } from './util-types';

export type CSSSyntax =
| '*'
Expand Down
19 changes: 2 additions & 17 deletions packages/stylex/src/stylex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,6 +35,8 @@ export type {
TransformFunction,
TransformList,
} from './VarTypes';
import type { ValueWithDefault } from './util-types';
export * as Types from './VarTypes';

export type {
VarGroup,
Expand Down
15 changes: 15 additions & 0 deletions packages/stylex/src/util-types.js
Original file line number Diff line number Diff line change
@@ -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<T>,
[string]: ValueWithDefault<T>,
}>;
13 changes: 11 additions & 2 deletions packages/stylex/type-tests/theming1.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down Expand Up @@ -52,7 +53,7 @@ const correctTheme = stylex.createTheme(buttonTokens, {

correctTheme as Theme<typeof buttonTokens, string>;

const result: string = stylex(correctTheme);
const result: string = stylexLegacy(correctTheme);
const result2: $ReadOnly<{
className?: string,
style?: $ReadOnly<{ [string]: string | number }>,
Expand Down Expand Up @@ -141,6 +142,14 @@ const typedTokens = stylex.defineVars({
shortAnimation: stylex.types.time<string | 0>('0.5s'),
});

const _bgColor: StyleXVar<stylex.Types.Color<string>> = typedTokens.bgColor;
const _cornerRadius: StyleXVar<stylex.Types.Length<string | number>> =
typedTokens.cornerRadius;
const _translucent: StyleXVar<stylex.Types.Num<number>> =
typedTokens.translucent;
const _shortAnimation: StyleXVar<stylex.Types.Time<string | 0>> =
typedTokens.shortAnimation;

const correctlyTypedTheme = stylex.createTheme(typedTokens, {
bgColor: stylex.types.color('red'),
cornerRadius: stylex.types.length('4px'),
Expand Down

0 comments on commit 72ab4b3

Please sign in to comment.