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

Incomplete Guide for using xstyled.custom.ts for creating custom xstyled utils #422

Open
paramsinghvc opened this issue Jul 9, 2024 · 1 comment

Comments

@paramsinghvc
Copy link

💬 Questions and Help

Hi,
I'm using xstyled for my project and keen on using some utils like centerAlign, clearFix etc to be used as props on x elements as
<x.div centerAlign clearfix ....

I'm using it in a TS project and following this guide https://xstyled.dev/docs/adding-new-utilities/
and https://xstyled.dev/docs/typescript/
It says to create the xstyled.config.js but what to do with it I'm not sure. I created it in the project root but it doesn't seem to work. Also, TS is not able to identify the custom prop of centerAlign added. The TS guide only talks about custom theme types.

Below is my xstyled.cutom.js looks like.

import { createCss, system, compose, style } from '@xstyled/styled-components';

export const clearfix = style({
  prop: 'clearfix',
  css: () => ({
    '&::after': {
      display: 'block',
      content: '',
      clear: 'both',
    },
  }),
});

export const foo = style({
  prop: ['foo'],
  css: ['paddingTop', 'paddingBottom'],
})

export const { css, styled, x, createGlobalStyle } = createCss(compose(system, clearfix, foo));

So, a complete guide or a sandbox would be great.
Here's a sandbox https://codesandbox.io/p/sandbox/xstyled-v2-playground-forked-q7dy59

Screenshot 2024-07-09 at 13 29 40
@paramsinghvc
Copy link
Author

@gregberge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant