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

Custom theme-based TypeScript Intellisense #6

Closed
nandorojo opened this issue Jul 14, 2020 · 26 comments · Fixed by #124
Closed

Custom theme-based TypeScript Intellisense #6

nandorojo opened this issue Jul 14, 2020 · 26 comments · Fixed by #124

Comments

@nandorojo
Copy link
Owner

Another goal of this library is to have a script that detects your theme, and builds TypeScript intellisense into your components based on your custom theme values. But this isn't made yet. I'd love help with it.

For example, if you have a theme like this:

export default {
  colors: {
    primary: 'blue',
    muted: '#e8e8e8',
  },
};

Then you would get intellisense like this:

^ The gif might take sec to load.

I think this could be achieved with some TypeScript wizardry, where a command line takes in the theme file and generates a typescript hidden file in your repository. This hidden file would globally declare values that override the sx prop, injecting in type suggestions. The command would probably be placed in a given project's postinstall, so that it runs every time you run yarn or npm install

@slorber recommended I look here.

I think generating something like this would work?

Xiy9U6kv

@nandorojo
Copy link
Owner Author

This requires some TypeScript codegen wizardry that I just don't have. I'll probably close this until some TS genius stumbles upon it and can solve it.

@nandorojo
Copy link
Owner Author

There's an exciting theme UI PR which seems like it could solve this system-ui/theme-ui#1090. Still have to look more into it, but I've re-opened this issue.

@nandorojo
Copy link
Owner Author

@nandorojo
Copy link
Owner Author

After many months, I'm excited to say that this feature is close to landing. @hasparus has been hard at work with many great additions to theme-ui, and one of them will address this issue. This means our sx prop will get strict types based on our theme.

To follow: system-ui/theme-ui#1090

@nandorojo
Copy link
Owner Author

#72

@nandorojo
Copy link
Owner Author

Alright, let's make this happen.

@nandorojo nandorojo reopened this Sep 27, 2021
@nandorojo
Copy link
Owner Author

nandorojo commented Sep 27, 2021

Gosh, this is sooo hard with all of theme-ui's complex types in the way rn.

@cmaycumber I think this is the start of v3 of Dripsy. Remove theme-ui altogether, copy over the types ourselves, and have great type safety.

(I accidentally wrote this on the other thread first)

@nandorojo
Copy link
Owner Author

nandorojo commented Sep 27, 2021

@cmaycumber
Copy link
Contributor

@nandorojo Have you seen react-native-styled-variants: https://styled-variants.vercel.app/

@nandorojo
Copy link
Owner Author

Haha yeah good timing. I'd want to make sure that the type creator there from the custom theme is performant. For massive TS objects, you can get into slow performance if you recurse too much (see millsp/ts-toolbelt#154)

@nandorojo
Copy link
Owner Author

Looks like TS performance has improved for this, which is good news microsoft/TypeScript#45711

@cmaycumber
Copy link
Contributor

Haha yeah good timing. I'd want to make sure that the type creator there from the custom theme is performant. For massive TS objects, you can get into slow performance if you recurse too much (see millsp/ts-toolbelt#154)

That makes a lot of sense. We should definitely make sure that's the case. I wonder if we can build off of some of the work from react-native-styled-variants.

@nandorojo
Copy link
Owner Author

nandorojo commented Sep 27, 2021

Yeah, I wrote more about my vision for how this could work at #72 a while ago

I feel like a good UX is

const theme = createTheme({
  ...
})

type MyTheme = typeof theme

declare module 'dripsy' {
  interface UserTheme extends MyTheme {}
}

But I'm open to anything, also could make it like the styled variants for sure. The one missing piece is adding all of the custom scales p, px, etc)

@cmaycumber
Copy link
Contributor

I think that's definitely a good UX imo. Let me reread #72. I'm super pumped to get this started

@nandorojo nandorojo mentioned this issue Sep 27, 2021
Merged
32 tasks
@nandorojo
Copy link
Owner Author

Starting at #124

@nandorojo
Copy link
Owner Author

Screen Shot 2021-09-27 at 5 12 04 PM

Omg. still work to do here but...

@nandorojo
Copy link
Owner Author

Adding variant support too...

Screen Shot 2021-09-27 at 6 17 55 PM

Theme here (just to mock)

Screen Shot 2021-09-27 at 6 18 13 PM

@nandorojo
Copy link
Owner Author

Screen Shot 2021-09-27 at 6 47 19 PM

Screen Shot 2021-09-27 at 6 47 11 PM

Gradient support working...

@nandorojo
Copy link
Owner Author

Screen Shot 2021-09-27 at 7 10 32 PM

Added sx prop as a function support (not sure why tbh, but why not)

@nandorojo
Copy link
Owner Author

I published the first version of this at 3.0.0, would love help testing:

yarn add dripsy@canary

@nandorojo
Copy link
Owner Author

2 things left:

  1. Make sure that the Tokenizer is actually performant
  2. Maybe add per-scale styles? As in, bg only sees scales from the theme.colors. It's just a lot of time / effort.

@nandorojo
Copy link
Owner Author

Screen Shot 2021-09-28 at 6 01 33 PM

Shorthand support working...

@nandorojo
Copy link
Owner Author

Screen Shot 2021-09-28 at 6 08 16 PM

Props now narrow down to the specific themeKey for a given style 😎

@rafaelrinaldi
Copy link

Popping in to say I thoroughly appreciate all the work being put into this. It will be such a great addition to Dripsy!

@nandorojo
Copy link
Owner Author

Thanks, glad you think so! You can see more details at #124

@nandorojo
Copy link
Owner Author

Will be closed with the release of v3.

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

Successfully merging a pull request may close this issue.

3 participants