Add new ring utilities for custom focus styles and rounded outlines (#2747)

* Add ring utilities

* Remove redundant shadows, add 5% and 95% to opacity scale

* Undo changes to build file

* Update boxShadow.test.js
This commit is contained in:
Adam Wathan 2020-11-09 16:39:49 -05:00 • committed by GitHub
parent d39ecc56f1
commit d4fcd2eb8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 27032 additions and 1928 deletions

32
src/plugins/ringColor.js Normal file
View file

@ -0,0 +1,32 @@
import _ from 'lodash'
import flattenColorPalette from '../util/flattenColorPalette'
import nameClass from '../util/nameClass'
import { toRgba } from '../util/withAlphaVariable'
export default function () {
return function ({ addUtilities, theme, variants }) {
const colors = flattenColorPalette(theme('ringColor'))
const utilities = _.fromPairs(
_.map(_.omit(colors, 'DEFAULT'), (value, modifier) => {
try {
const [r, g, b, a] = toRgba(value)
return [
nameClass('ring', modifier),
{
'--ring-opacity': a === undefined ? '1' : a,
'--ring-color': `rgba(${r}, ${g}, ${b}, var(--ring-opacity))`,
},
]
} catch (_error) {
return [
nameClass('ring', modifier),
{
'--ring-color': value,
},
]
}
})
)
addUtilities(utilities, variants('ringColor'))
}
}