Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box block, VariantProps fix #162

Merged
merged 4 commits into from
Feb 14, 2023
Merged
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
4 changes: 3 additions & 1 deletion react/src/components/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { styled } from '../stitches.config'
import type { VariantProps } from '../utils'

export const Box = styled('div')
export const Box = styled('div', {
display: 'block'
})

export type BoxProps = VariantProps<typeof Box>
5 changes: 4 additions & 1 deletion react/src/components/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ export const Flex = styled(Box, {
}
})

export type FlexVariant = VariantProps<typeof Flex>
export type FlexProps = VariantProps<typeof Flex>

// FIXME[1.0]: remove this alias
export type FlexVariant = FlexProps
Comment on lines +18 to +19
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlexVariant was a typo 😭 so I'm adding FlexProps and aliasing it to FlexVariant so that we don't have to release this as a breaking change. The FIXME[1.0] comment should remind us to remove the alias when we release 1.0.

8 changes: 5 additions & 3 deletions react/src/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import React, { Component, ComponentProps, ComponentType } from 'react'
import React, { ComponentProps, ComponentType } from 'react'

// XXX: export type { VariantProps } from '@stitches/react'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just delete this? also, I think I'm confused on whether the stitches VariantProps is working or causing issues. but down to merge this and see if it fixes the linting errors

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, tbh. It doesn't hurt to keep the comment around as a reminder that we could bring back the stitches type if/when it's fixed upstream, though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm!


export type VariantProps<T> = JSX.IntrinsicAttributes & (T extends ComponentType ? ComponentProps<T> : T)

export function identity (v: any) {
return v
Expand All @@ -21,5 +25,3 @@ export function withFixedProps (
return <Component {...fixed} {...props} />
}
}

export type VariantProps<T, P extends {} = T extends ComponentType ? ComponentProps<T> : T> = T & JSX.IntrinsicAttributes