Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Patch #474

Merged
merged 3 commits into from
Oct 12, 2023
Merged

Patch #474

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
3 changes: 3 additions & 0 deletions example/storybook/src/components/nb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ export const config = createConfig({
100: 1,
},
} as const,
globalStyle: {
variants: {},
},
themes: {
'2000s': {
colors: {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gluestack-style/react",
"description": "A universal & performant styling library for React Native, Next.js & React",
"version": "1.0.3",
"version": "1.0.4",
"keywords": [
"React Native",
"Next.js",
Expand Down
66 changes: 42 additions & 24 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,7 @@ export type ExtendedConfigType = {
/*********************** GLOBAL STYLE TYPES ****************************************/

export type GlobalVariantAliasesProps<Aliases, Tokens> =
| RemoveNever<{
[key in keyof Aliases]?: Aliases[key] extends keyof RNStyledProps
? Aliases[key] extends keyof PropertyTokenType
? PropertyTokenType[Aliases[key]] extends keyof Tokens
?
| StringifyToken<keyof Tokens[PropertyTokenType[Aliases[key]]]>
| ExtendRNStyle<RNStyledProps, Aliases[key]>
: never
: any
: any;
}>
| AliasesProps<RNStyledProps, Aliases, Tokens>
| RNStyledProps;

export type GlobalVariantSx<Aliases, Tokens, Variants, PLATFORM = ''> = Partial<
Expand Down Expand Up @@ -812,21 +802,30 @@ export type RemoveNever<T> = {
[K in FilteredKeys<T>]: T[K];
};

type WithNegativeValue<T> = T extends string | number ? T | `-${T}` : T;
// Mapping tokens with scale value of alaises
export type AliasesProps<GenericComponentStyles = Aliases> = RemoveNever<{
export type AliasesProps<
GenericComponentStyles = RNStyledProps,
Aliases = GSConfig['aliases'],
Tokens = GSConfig['tokens']
> = RemoveNever<{
[key in keyof Aliases]?: Aliases[key] extends keyof GenericComponentStyles
? PropertyTokenType[Aliases[key]] extends 'sizes'
? //@ts-expect-error
PropertyTokenType[Aliases[key]] extends 'sizes'
?
| StringifyToken<
keyof GSConfig['tokens'][PropertyTokenType[Aliases[key]]]
>
| StringifyToken<keyof GSConfig['tokens']['space']>
| WithSizeNegativeValue<Tokens>
| ExtendRNStyle<GenericComponentStyles, Aliases[key]>
:
| StringifyToken<
keyof GSConfig['tokens'][PropertyTokenType[Aliases[key]]]
: //@ts-expect-error
PropertyTokenType[Aliases[key]] extends 'space'
?
| WithNegativeValue<
//@ts-expect-error
StringifyToken<keyof Tokens[PropertyTokenType[Aliases[key]]]>
>
| ExtendRNStyle<GenericComponentStyles, Aliases[key]>
: //@ts-expect-error
| StringifyToken<keyof Tokens[PropertyTokenType[Aliases[key]]]>
| ExtendRNStyle<GenericComponentStyles, Aliases[key]>
: never;
}>;

Expand Down Expand Up @@ -887,15 +886,34 @@ export type ExtendRNStyle<GenericComponentStyles, key> =
: //@ts-ignore
GenericComponentStyles[key];

export type TokenizedRNStyleProps<GenericComponentStyles> = {
type WithSizeNegativeValue<Tokens> = keyof Tokens extends 'sizes'
? WithNegativeValue<
//@ts-expect-error
| StringifyToken<keyof Tokens['sizes']>
//@ts-expect-error
| StringifyToken<keyof Tokens['space']>
>
: //@ts-expect-error
WithNegativeValue<StringifyToken<keyof Tokens['space']>>;

export type TokenizedRNStyleProps<
GenericComponentStyles,
Tokens = GSConfig['tokens']
> = {
[key in keyof GenericComponentStyles]?: key extends keyof PropertyTokenType
? PropertyTokenType[key] extends 'sizes'
?
| StringifyToken<keyof GSConfig['tokens']['space']>
| StringifyToken<keyof GSConfig['tokens'][PropertyTokenType[key]]>
| WithSizeNegativeValue<Tokens>
| ExtendRNStyle<GenericComponentStyles, key>
: PropertyTokenType[key] extends 'space'
?
| WithNegativeValue<
//@ts-expect-error
StringifyToken<keyof Tokens[PropertyTokenType[key]]>
>
| ExtendRNStyle<GenericComponentStyles, key>
: //@ts-ignore
| StringifyToken<keyof GSConfig['tokens'][PropertyTokenType[key]]>
| StringifyToken<keyof Tokens[PropertyTokenType[key]]>
| ExtendRNStyle<GenericComponentStyles, key>
: GenericComponentStyles[key];
};
Expand Down