Skip to content

Commit

Permalink
update types, improve composition
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Jul 22, 2021
1 parent ba17840 commit 7537ebc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
24 changes: 21 additions & 3 deletions packages/core/tests/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ global({

const PotatoButton = css({
variants: {
peace: {
mercy: {
color: 'MediumOrchid',
},
trust: {
color: 'Turquoise',
},
},
variant: {
blue: {
backgroundColor: '$gray100',
Expand All @@ -92,7 +100,11 @@ const PotatoButton = css({
],
})

const two = css({
PotatoButton({
peace: 'mercy',
})

const two = css(PotatoButton, {
$$max: '2px',
width: '$$max',
variants: {
Expand All @@ -119,8 +131,14 @@ const two = css({
],
})

two({ variant: 'green' })
two({ variant: 'red' })
two({

})

// two({
// variant: 'red'
// })

// two({ variant: 'blue' })

// type test = StitchesVariants<typeof PotatoButton>
Expand Down
14 changes: 7 additions & 7 deletions packages/core/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,17 @@ export interface CreatedCss<
/** Returns a function that applies styles and variants for a specific class. */
css: {
<
Variant extends {
Variants extends {
[name in string]: {
[pair in index]: Style<C>
}
},
Args extends Variant[]
Args extends Variants[]
>(
...composers: {
[K in keyof Args]:
| {
[IS_COMPONENT]: true
[$$VARIANTS]: Args[K]
}
| (
& OmitKey<Style<C>, 'variants'>
Expand All @@ -216,7 +216,7 @@ export interface CreatedCss<
*
* @see https://stitches.dev/docs/variants
*/
variants?: Args[K] | Variant,
variants?: Args[K] | Variants,
compoundVariants?: (
& {
[Name in Exclude<keyof Args[K], 'css'>]?: Widen<keyof Args[K][Name]>
Expand Down Expand Up @@ -262,7 +262,7 @@ export interface CreatedCss<
className: string
selector: string

[IS_COMPONENT]: true
[$$VARIANTS]: Variants
}
}

Expand All @@ -271,9 +271,9 @@ export interface CreatedCss<
}
}

declare const IS_COMPONENT: unique symbol
declare const $$VARIANTS: unique symbol

type IS_COMPONENT = typeof PrivatePropertyValue
type $$VARIANTS = typeof PrivatePropertyValue

/* ========================================================================== */

Expand Down
28 changes: 17 additions & 11 deletions packages/react/types/styled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,27 @@ export interface CreatedCss<
/** Returns a function that applies styles and variants for a specific class. */
css: {
<
Variant extends {
Variants extends {
[name in string]: {
[pair in index]: Style<C>
}
},
Args extends Variant[]
Args extends Variants[]
>(
...composers: {
[K in keyof Args]: (
[K in keyof Args]:
| {
[$$VARIANTS]: Args[K]
}
| (
& OmitKey<Style<C>, 'variants'>
& {
/**
* Variants configure conditional styles of the component.
*
* @see https://stitches.dev/docs/variants
*/
variants?: Args[K] | Variant,
variants?: Args[K] | Variants,
compoundVariants?: (
& {
[Name in Exclude<keyof Args[K], 'css'>]?: Widen<keyof Args[K][Name]>
Expand Down Expand Up @@ -257,23 +261,25 @@ export interface CreatedCss<
) & {
className: string
selector: string

[$$VARIANTS]: Variants
}
}

/** Returns a function that applies styles and variants for a specific class. */
styled: {
<
Variant extends {
Variants extends {
[name in string]: {
[pair in index]: Style<C>
}
},
Args extends Variant[]
Args extends Variants[]
>(
...composers: {
[K in keyof Args]:
| {
[IS_COMPONENT]: true
[$$VARIANTS]: Args[K]
}
| (
& OmitKey<Style<C>, 'variants'>
Expand All @@ -283,7 +289,7 @@ export interface CreatedCss<
*
* @see https://stitches.dev/docs/variants
*/
variants?: Args[K] | Variant,
variants?: Args[K] | Variants,
compoundVariants?: (
& {
[Name in Exclude<keyof Args[K], 'css'>]?: Widen<keyof Args[K][Name]>
Expand Down Expand Up @@ -329,7 +335,7 @@ export interface CreatedCss<
className: string
selector: string

[IS_COMPONENT]: true
[$$VARIANTS]: Variants
}
}

Expand All @@ -338,9 +344,9 @@ export interface CreatedCss<
}
}

declare const IS_COMPONENT: unique symbol
declare const $$VARIANTS: unique symbol

type IS_COMPONENT = typeof PrivatePropertyValue
type $$VARIANTS = typeof PrivatePropertyValue

/* ========================================================================== */

Expand Down

0 comments on commit 7537ebc

Please sign in to comment.