Skip to content

Commit 45bbf6b

Browse files
committed
Show suggestions for all matchVariant values
1 parent e4c0255 commit 45bbf6b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

packages/tailwindcss/src/compat/plugin-api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ export function buildPluginApi({
245245
return aValue < zValue ? -1 : 1
246246
},
247247
)
248+
249+
designSystem.variants.suggest(name, () =>
250+
Object.keys(options?.values ?? {}).filter((v) => v !== 'DEFAULT'),
251+
)
248252
},
249253

250254
addUtilities(utilities) {

packages/tailwindcss/src/intellisense.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,40 @@ test('Custom @utility and existing utility with names matching theme keys dont g
675675
expect(matches).toHaveLength(1)
676676
expect(classMap.get('text-header')?.modifiers).toEqual(['sm'])
677677
})
678+
679+
test('matchVariant', async () => {
680+
let input = css`
681+
@import 'tailwindcss/utilities';
682+
@plugin "./plugin.js";
683+
`
684+
685+
let design = await __unstable__loadDesignSystem(input, {
686+
loadStylesheet: async (_, base) => ({
687+
path: '',
688+
base,
689+
content: '@tailwind utilities;',
690+
}),
691+
loadModule: async () => ({
692+
path: '',
693+
base: '',
694+
module: plugin(({ matchVariant }) => {
695+
matchVariant('foo', (val) => `&:is(${val})`, {
696+
values: {
697+
DEFAULT: '1',
698+
a: 'a',
699+
b: 'b',
700+
},
701+
})
702+
}),
703+
}),
704+
})
705+
706+
let variants = design.getVariants()
707+
let v1 = variants.find((v) => v.name === 'foo')!
708+
expect(v1).not.toBeUndefined()
709+
710+
expect(v1.hasDash).toEqual(true)
711+
expect(v1.isArbitrary).toEqual(true)
712+
expect(v1.name).toEqual('foo')
713+
expect(v1.values).toEqual(['a', 'b'])
714+
})

0 commit comments

Comments
 (0)