-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Any future plans on adding types? #12
Comments
Hello @ryee-dev, to be clear, I am not a TypeScript user so I can't maintain types. Adding types in the core of the library is too risky if core maintainers are not TypeScript friendly. That said, types of xstyled will have to be in https://github.com/DefinitelyTyped/DefinitelyTyped. At least at start. |
Has anyone tried whether it's compatible with |
Yes it should be compatible with |
I wrote this The only thing is that declare module '@xstyled/styled-components' {
import styled from 'styled-components'
export * from 'styled-components'
export default styled
} Also did the same for declare module '@xstyled/system' {
export * from 'styled-system'
} |
Hi all, I think I've about cracked the
Edit: see an updated version (and discuss issues/bugs) in this gist declare module '@xstyled/styled-components' {
import styled, { StyledComponent, DefaultTheme } from 'styled-components'
export * from 'styled-components'
interface Breakpoints {
xs: any
sm: any
md: any
lg: any
xl: any
}
type BreakpointObject<ArgType> = {
[Key in keyof Breakpoints]?: ArgType
}
type WithBreakpointArgs<Props> = {
[Key in keyof Props]?: Props[Key] | BreakpointObject<Props[Key]>
}
type FlexArgs =
| 'flex-start'
| 'center'
| 'flex-end'
| 'space-around'
| 'space-between'
interface BoxPropsBase {
/* Display */
display:
| 'block'
| 'inline-block'
| 'inline'
| 'flex'
| 'grid'
| 'none'
| 'inherit'
| 'initial'
/* Color */
color: string
backgroundColor: string
/* Margins */
margin: number
m: number
marginTop: number
mt: number
marginRight: number
mr: number
marginBottom: number
mb: number
marginLeft: number
ml: number
mx: number
my: number
/* Padding */
padding: number
p: number
paddingTop: number
pt: number
paddingRight: number
pr: number
paddingBottom: number
pb: number
paddingLeft: number
pl: number
px: number
py: number
/* Space & Layout */
space: number
width: number | string
/* Grid */
row: boolean
col: boolean | number
/* Flex */
justifyContent: FlexArgs
alignItems: FlexArgs
}
/* adds support for { xs: arg } and makes all props optional */
export type BoxProps = WithBreakpointArgs<BoxPropsBase>
export const Box: StyledComponent<
'div',
DefaultTheme,
WithBreakpointArgs<BoxProps>
>
export default styled
} This supports using the <Box margin={2}>:)</Box>
<Box margin={{ xs: 1, xl: 3 }}>:)</Box> You can also create your own const Wrapper = styled(Box)`
// ...
`
<Wrapper mt={2} /> To Do:
Anyone out there want to goof around with this and report back if things are working or not? @neoziro , OK if we use this issue to track this stuff until it's to a point where we can add it to the DefinitelyTyped repository? |
Yes programatically you have access to the system props, or just https://www.smooth-code.com/open-source/smooth-ui/docs/box/#box-2
Yes of course, feel free to use it to track the work! |
Hi all, I've added updated definitions in this gist: https://gist.github.com/good-idea/96576e16c650c3730c53844d266d7149 This includes all possible props for Box, as well as definitions for all Feel free to try them in your project, and add any comments/bugs in a comment in the gist. When it's been tested a little bit, I'll submit it to DefinitelyTyped. |
I am not a TypeScript user, it looks good but I can't review it. I don't add it to the repository because it wouldn't be maintained. |
@neoziro yup, no problem! I'm going to use them in my projects for a bit - maybe gather some feedback from any others who might be using them - and when they're ready to go I'll publish them in a separate package. |
@good-idea I've got a very rough draft of typings for |
@stevejay these look great. I'm not familiar enough with |
@good-idea There's a description comparing the two packages here. Basically |
@good-idea FYI I got the |
Cool! I'll tidy up my types and submit those as well. |
@good-idea Is there any progress on this? |
@wa4-fearless-otter sorry, i never got around to this --- i might not be able to for a little while. In the meantime, the gist i linked to above covers most cases |
I had a go at some types for I basically took @good-idea's approach and replaced the The Note: I added optional typing for your custom theme, near the top of the gist Edit Edit 2 Reasoning: I changed the types of According to this TypeScript issue, we can't easily merge the declaration from ...
import styled_, { StyledComponent } from '@emotion/styled'
...
export const Box: StyledComponent<
React.ComponentPropsWithRef<'div'>,
WithBreakpointArgs<BoxProps>,
Theme
>
...
const styled: typeof styled_ & {
Box: typeof Box,
aBox: CreateStyledComponentBase<
React.ComponentPropsWithRef<'a'>,
WithBreakpointArgs<BoxProps>,
Theme
>,
...
} I can now use the const Text = styled.pBox`
font-size: 1
` I'd love some input on whether |
Hey! I've been a long-time user of styled-components and thought I'd give xstyled a try since I could totally relate and understand the motivation behind it!
But regarding the topic of this issue, would it be possible to import styled-components/styled-system's preexisting type library? And if not, are there future plans to add types?
Anyways, I really appreciate your work on this library!
The text was updated successfully, but these errors were encountered: