Create Tailwind Plugin Class That Generates Various Hover And Focus States

Currently I’m using the @apply like so to create a simple error class I can add to input elements to highlight them.

.error{
    @apply 
    outline
    outline-red-500
    focus:outline
    focus:outline-red-500
    focus:outline-2
    focus:ring-red-500 
    focus:ring-1
}

However, I want more flexibility. I want to be able to provide a custom color and have the variants recommended to me in vs code intellisense. For example adding the class error-purple-800 should result in the equivalent of this code

.error-purple-800{
    @apply 
    outline
    outline-purple-800
    focus:outline
    focus:outline-purple-800
    focus:outline-2
    focus:ring-purple-800
    focus:ring-1
}

So I was trying to include a plugin in my tailwind.config.js to accomplish this

  plugins: [
    require('./css/tailwind_plugins/error'),
  ],

And sofar my error.js looks something like this

function errorPlugin({ addUtilities, e, theme, variants }) {
  const colors = theme('colors')
  const errorUtilities = Object.keys(colors).reduce((acc, color) => {
    const colorShades = colors[color]
    if (typeof colorShades === 'object') {
      Object.keys(colorShades).forEach(shade => {
        acc[`.error-${color}-${shade}`] = {
          outline: `2px solid ${colorShades[shade]}`,
          'outline-offset': '2px',
          'focus:outline': `2px solid ${colorShades[shade]}`,
          'focus:ring': `${colorShades[shade]} 1px`,
        }
      })
    } else {
      acc[`.error-${color}`] = {
        outline: `2px solid ${colorShades}`,
        'outline-offset': '2px',
        'focus:outline': `2px solid ${colorShades}`,
        'focus:ring': `${colorShades} 1px`,
      }
    }
    return acc
  }, {})

  addUtilities(errorUtilities, variants('outline', ['responsive', 'hover', 'focus']))
}

module.exports = errorPlugin

However, there are two problems I’m running into.

Issue One

Whatever styles I generate in this plugin are only applied directly to the element, they don’t actually include the focus styles for example. focus:outline for example is not a real css style and doesn’t work. I know that these plugins do work with variants though and so i could add the classes error-purple-800 & focus:error-purple-800 to get closer to my desired result. However, I want a solution that only requires me to add a single class in order to have both the base and focus styles applied.

Issue Two

My original tailwind css uses the ring classes which are abit confusing to me in terms of what they should translate too for normal css and more so how to integrate them into my plugin properly.

@apply 
focus:ring-purple-800
focus:ring-1

If anyone could help with this it would be greatly appreciated.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật