Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@stylexjs/stylex/src/stylex.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
StyleX$DefineConsts,
StyleXArray,
StyleXClassNameFor,
StyleXSxProp,
StyleXStyles,
StyleXStylesWithout,
StyleXVar,
Expand All @@ -51,6 +52,7 @@ export type {
StaticStylesWithout,
StyleXArray,
StyleXClassNameFor,
StyleXSxProp,
StyleXStyles,
StyleXStylesWithout,
StyleXVar,
Expand Down
14 changes: 14 additions & 0 deletions packages/@stylexjs/stylex/src/types/StyleXTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ export type StyleXStylesWithout<CSS extends UserAuthoredStyles> = StyleXStyles<
Omit<CSSPropertiesWithExtras, keyof CSS>
>;

export type StyleXSxProp = StyleXArray<
| null
| undefined
| boolean
| CompiledStyles
| Readonly<[CompiledStyles, InlineStyles]>
>;

declare module 'react' {
interface DOMAttributes<T> {
sx?: StyleXSxProp;
}
}

declare const StyleXVarGroupTag: unique symbol;
export type VarGroup<
Tokens extends { [key: string]: any },
Expand Down
4 changes: 4 additions & 0 deletions packages/@stylexjs/stylex/src/types/StyleXTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ export type StyleXStylesWithout<
out CSS extends { readonly [string]: unknown },
> = StyleXStyles<Omit<CSSPropertiesWithExtras, keyof CSS>>;

export type StyleXSxProp = StyleXArray<
?CompiledStyles | boolean | Readonly<[CompiledStyles, InlineStyles]>,
>;

export type VarGroup<
out Tokens extends { readonly [string]: unknown },
out _ID extends string = string,
Expand Down
26 changes: 24 additions & 2 deletions packages/typescript-tests/src/test1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*
*/

/* eslint-disable no-unused-vars */
/* eslint-disable no-unused-vars, react/no-unknown-property */

import * as React from 'react';
import * as stylex from '@stylexjs/stylex';
import type { StaticStyles } from '@stylexjs/stylex';
import type { StaticStyles, StyleXSxProp } from '@stylexjs/stylex';

type Props = {
xstyle?: StaticStyles;
Expand All @@ -21,6 +21,10 @@ function Component({ xstyle }: Props) {
return <div {...stylex.props(xstyle)} />;
}

function PlainComponent() {
return null;
}

const styles = stylex.create({
base: {
color: 'red',
Expand All @@ -34,3 +38,21 @@ function OtherComponent() {
function OtherComponent2() {
return <Component xstyle={[styles.base, undefined]} />;
}

function SxComponent() {
return <div sx={styles.base} />;
Comment thread
mjames-c marked this conversation as resolved.
}

function SxComponentMultiStyle() {
return <div sx={[styles.base, undefined]} />;
}

function InvalidSxValue() {
// @ts-expect-error - `sx` only accepts StyleX styles.
return <div sx="not-stylex" />;
}

function CustomComponentSx() {
// @ts-expect-error - `sx` is only transformed on lowercase JSX host elements.
return <PlainComponent sx={styles.base} />;
}
Comment thread
mjames-c marked this conversation as resolved.