Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,27 +636,17 @@ function registerPlugins(plugins, context) {
return output.map((value) => ({ raw: value, extension: 'html' }))
}

// Generate a list of strings for autocompletion purposes. Colors will have a
// tuple with options, e.g.:
// ['uppercase', 'lowercase', ['bg-red', { color: 'rgb(255 0 0)' }]]
context.completions = function () {
// TODO: Try and detect color from components?
// TODO: Should we provide a simple "public api" file with functions?
// Generate a list of strings for autocompletion purposes, e.g.
// ['uppercase', 'lowercase', ...]
context.getClassList = function () {
let output = []

for (let util of classList) {
if (Array.isArray(util)) {
let [utilName, options] = util
let isColor = [].concat(options.type).includes('color')

if (isColor) {
for (let [value, color] of Object.entries(options?.values ?? {})) {
output.push([formatClass(utilName, value), { color }])
}
} else {
for (let value of Object.keys(options?.values ?? {})) {
output.push(formatClass(utilName, value))
}
for (let value of Object.keys(options?.values ?? {})) {
output.push(formatClass(utilName, value))
}
} else {
output.push(util)
Expand Down
25 changes: 0 additions & 25 deletions tests/completions.test.js

This file was deleted.

18 changes: 18 additions & 0 deletions tests/getClassList.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import resolveConfig from '../src/public/resolve-config'
import { createContext } from '../src/lib/setupContextUtils'

it('should generate every possible class, without variants', () => {
let config = {}

let context = createContext(resolveConfig(config))
expect(context.getClassList()).toBeInstanceOf(Array)

// Verify we have a `container` for the 'components' section.
expect(context.getClassList()).toContain('container')

// Verify we handle the DEFAULT case correctly
expect(context.getClassList()).toContain('border')

// Verify we handle negative values correctly
expect(context.getClassList()).toContain('-inset-1/4')
})