-
Notifications
You must be signed in to change notification settings - Fork 6
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
With plugins, auto-completion requires manual TypeScript typings in Twind configuration (error highlighting and hover information work fine out of the box) #8
Comments
I know. I'm currently working on re-writing the plugin to support custom auto-completion for plugins. The plugins you mentioned will be updated to support this. It will look something like this for custom plugins: import type { ThemeSection, FromTheme } from 'twind'
declare module 'twind' {
interface Theme {
scrollSnap: ThemeSection
}
interface Variants {
ltr: string
}
interface Plugins {
'scroll-snap': 'none' | 'x' | 'y' | FromTheme<'scrollSnap'>
}
} I update this issue once I have updated this plugin. |
This should now work. I will update the plugins in the next days. |
The latest update warns about unknown tokens by highlighting keywords with a squiggly orange underline. That's great, thank you! :) Taking the "@twind/forms" plugin as an example, is there anything we should configure in order to register the additional tokens, or does this happen automatically? (no rush to implement this if not done already, just wondering ;) |
Until I have updated the plugin or someone provides a PR... You can try this: declare module 'twind' {
interface Plugins {
'form-input': ''
}
} Take a look at the defintions for the core plugins: https://github.com/tw-in-js/twind/blob/main/src/types/completion.ts#L128 |
Mhmm, I have tried different techniques, to no avail :(
Have you successfully managed to augment the |
Yes. Sorry for the lack of documentation. Create a import { forms, formInput } from '@twind/forms'
/** @type {import('twind').Configuration} */
export default {
plugins: { forms, 'form-input': formInput}
} Downside: Currently only the simple name can be inferred – meaning no params: This can be done in any file that is included in the typescript compilation. Lets put into the config: import { forms, formInput } from '@twind/forms'
/** @type {import('twind').Configuration} */
export default {
plugins: { forms, 'form-input': formInput}
}
declare module 'twind' {
interface Plugins {
// forms should have been detected from setup – not need to add it
// forms: ''
// We want to add sm and lg modifiers to the form-input
'form-input':
| '' // plain form-input
| 'sm' // form-input-sm
| 'lg' // form-input-lg
}
} Downside: A lot of extra types. mapleLeaf and I are thinking of creating a plugin API that would allow detecting all possible class names from the plugin directly. No need for types. PS You should use the import { setup } from 'twind'
import config from '../twind.config`
setup(config) The issue I just now realized is that autocompletion and diagnostic/hover use different ways.
Maybe I need to adjust the |
Brilliant, this works :) (I am using the Just a note specific to Preact WMR: the No big deal though, I just added // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export { default } from './public/twind.config.ts'; By the way, I love that the config file can be TypeScript instead of Javascript! 👍 |
Yes I can see how that could help. For example right now with the declare module 'twind' {
interface Plugins {
prose: '' | 'xl';
}
} ...both the grouped and non-grouped syntax work fine with autocompletion, error squiggly underline, and hover info (i.e. raw CSS preview): tw`prose prose-xl lg:prose-xl`
tw`prose(& xl lg:xl)`; ...however if I use |
I'm aware of this. That's why the default config lookup will |
I hope so 😄 |
I filed this separate issue so that we can track it separately: #12 |
|
Sorry, just a copy-paste typo. I will correct it right now in my message (dash instead of colon) |
Correction (if I am not mistaken): tw`prose(& xl lg:xl)`; |
FYI, I have been testing the latest versions of Twind libs. I just want to confirm that without any additional plugin configuration in
The only feature that requires the additional "manual" Typescript typings is auto-completion:
I am changing this issue's title to reflect this. |
For example, there is no auto-completion for
form-input
from@twind/forms
, orlg:prose-xl
from@twind/typography
. Thank you :)The text was updated successfully, but these errors were encountered: