Making My Own HSL Grabber #60
-
|
Hey John 👋 I had a go at creating my own // Menu: HSL
// Description: Convert any color to HSL.
// Author: Jhey Tompkins
// Twitter: @jh3yy
let { setSelectedText } = await kit('text')
const Color = await npm('color')
const stringColor = await arg('Color String:', (input) => {
try {
const value = Color(input).hsl() || input
return [
{
name: `hsl: ${value}`,
value,
info: `<div style="background-color: ${input}; height: 100px;
width: 100px;">${input || ''}</div>`,
},
]
} catch (err) {
return err
}
})
setSelectedText(stringColor)This "sort of" works. Based on your example, I'd thought that I'd get a square with the right color being shown? But, in my logs I get And I'm unable to copy the content on click 🤔 Is there a particular format required for |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
@jh3y Here's what I came up with. Any questions? // Menu: HSL
// Description: Convert any color to HSL.
// Author: Jhey Tompkins
// Twitter: @jh3yy
let { setSelectedText } = await kit("text")
const Color = await npm("color")
const createHTML = color =>
`<div class="h-full text-xs flex justify-center items-center" style="background-color: ${color}"><span class="p-2">${
color || ""
}</span></div>`
const createChoices = (input, value) => {
return [
{
name: `hsl: ${value}`,
value: value,
//I renamed "info" to "html"
html: createHTML(input),
},
]
}
const hslArray = await arg("Color String:", input => {
let hsl = input
try {
hsl = Color(input).hsl()
} catch {
//catch error and return whatever
return createChoices(input, "Invalid color")
}
//The HSL lib was returning an object with a "color" prop as an Array
return createChoices(input, hsl.color.join(" "))
})
setSelectedText(hslArray) |
Beta Was this translation helpful? Give feedback.
-
|
@jh3y That "execution error means" the "Allow Kit to control System Events" prompt was dismissed the first time it popped up. You can enable it here: Re: Tailwind. Yes! Most tailwind classes are available. Let me know if there are any missing that you might need and I'll whitelist them in the build. |
Beta Was this translation helpful? Give feedback.

Install hsl-refactored
@jh3y Here's what I came up with. Any questions?