twin.examples icon indicating copy to clipboard operation
twin.examples copied to clipboard

`tw` and `css` props don't work in Goober example

Open sampotts opened this issue 3 years ago • 8 comments

I could be missing something here but I can't get Preact + Goober to work with the tw or css props. Even the example ends up with the same output:

image

sampotts avatar Nov 23 '20 03:11 sampotts

There's some overly light documentation for Goober + Twin at the moment - sorry about that.

Currently Goober doesn't offer a css prop so you'd need to use styled-components as the example uses.

Works

  • styled import
  • tw import
  • +tw prop
  • +css prop
  • +tw.div shorthand

~~Doesn’t~~

  • ~tw prop~
  • ~css prop~
  • ~tw.div shorthand~

Edit: I've updated the example so twins general API is now working with Goober.

ben-rogerson avatar Nov 23 '20 08:11 ben-rogerson

All good 👍 I'd love to help out but wouldn't know where to start with it. Goober looks great, being so small. I can work around these limitations for now 👍

sampotts avatar Nov 24 '20 00:11 sampotts

Oh yeah, and when you couple it with Preact then you're cooking 👍

ben-rogerson avatar Nov 24 '20 01:11 ben-rogerson

One more thing, I noticed I get a TypeScript warning/error when using styled. Any ideas?

image

I have a twin.d.ts containing this:

import 'twin.macro';

import { css as cssImport, styled as styledImport } from 'goober';

declare module 'twin.macro' {
  // The styled and css imports
  const styled: typeof styledImport;
  const css: typeof cssImport;
}

// The 'as' prop on styled components
declare global {
  namespace JSX {
    interface IntrinsicAttributes<T> extends DOMAttributes<T> {
      as?: string;
    }
  }
}

sampotts avatar Dec 07 '20 01:12 sampotts

Hey Sam, I've got no immediate ideas but does the "styled.div" syntax throw the same error?

ben-rogerson avatar Dec 07 '20 12:12 ben-rogerson

I did try that but it throws:

Property 'div' does not exist on type 'StyledFunction'.ts(2339)

The styled('div') syntax works, it just throws a TypeScript error so it probably requires some hacking of the types I think.

sampotts avatar Dec 07 '20 12:12 sampotts

If you come up with anything please let me know :) I'd assist but I'm not great with this topic.

ben-rogerson avatar Dec 07 '20 20:12 ben-rogerson

I'll have a tinker and see what I can come up with.

sampotts avatar Dec 07 '20 22:12 sampotts