Handle the `DEFAULT` case for `matchVariant` (#635)

* handle the `DEFAULT` case

* Prettier

Co-authored-by: Brad Cornes <hello@bradley.dev>
master
Robin Malfait 2022-10-19 19:18:06 +02:00 committed by GitHub
parent a12e3ae686
commit 3f9762e003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -216,7 +216,10 @@ export function completionsFromClassList(
.filter((value) => !existingVariants.includes(`${variant.name}-${value}`)) .filter((value) => !existingVariants.includes(`${variant.name}-${value}`))
.map((value) => .map((value) =>
variantItem({ variantItem({
label: `${variant.name}${variant.hasDash ? '-' : ''}${value}${sep}`, label:
value === 'DEFAULT'
? `${variant.name}${sep}`
: `${variant.name}${variant.hasDash ? '-' : ''}${value}${sep}`,
detail: variant.selectors({ value }).join(', '), detail: variant.selectors({ value }).join(', '),
}) })
) )
@ -845,7 +848,9 @@ function provideVariantsDirectiveCompletions(
let possibleVariants = state.variants.flatMap((variant) => { let possibleVariants = state.variants.flatMap((variant) => {
if (variant.values.length) { if (variant.values.length) {
return variant.values.map((value) => `${variant.name}${variant.hasDash ? '-' : ''}${value}`) return variant.values.map((value) =>
value === 'DEFAULT' ? variant.name : `${variant.name}${variant.hasDash ? '-' : ''}${value}`
)
} }
return [variant.name] return [variant.name]
}) })

View File

@ -34,7 +34,9 @@ export function getInvalidVariantDiagnostics(
let possibleVariants = state.variants.flatMap((variant) => { let possibleVariants = state.variants.flatMap((variant) => {
if (variant.values.length) { if (variant.values.length) {
return variant.values.map((value) => `${variant.name}${variant.hasDash ? '-' : ''}${value}`) return variant.values.map((value) =>
value === 'DEFAULT' ? variant.name : `${variant.name}${variant.hasDash ? '-' : ''}${value}`
)
} }
return [variant.name] return [variant.name]
}) })

View File

@ -7,7 +7,9 @@ export function getVariantsFromClassName(
): { variants: string[]; offset: number } { ): { variants: string[]; offset: number } {
let allVariants = state.variants.flatMap((variant) => { let allVariants = state.variants.flatMap((variant) => {
if (variant.values.length) { if (variant.values.length) {
return variant.values.map((value) => `${variant.name}${variant.hasDash ? '-' : ''}${value}`) return variant.values.map((value) =>
value === 'DEFAULT' ? variant.name : `${variant.name}${variant.hasDash ? '-' : ''}${value}`
)
} }
return [variant.name] return [variant.name]
}) })