Skip to content

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

Description

@paramsinghvc

πŸ’¬ 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions