Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function plugin(options?: Partial<{ className: string; target: 'modern' | 'legacy' }>): {
declare function plugin(options?: Partial<{ className: string; target: 'modern' | 'legacy'; color: string; scale: string }>): {
handler: () => void
}

Expand Down
17 changes: 16 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const plugin = require('tailwindcss/plugin')
const merge = require('lodash.merge')
const castArray = require('lodash.castarray')
const isPlainObject = require('lodash.isplainobject')
const styles = require('./styles')
const { commonTrailingPseudos } = require('./utils')

Expand Down Expand Up @@ -69,7 +70,7 @@ function configToCss(config = {}, { target, className, modifier, prefix }) {
}

module.exports = plugin.withOptions(
({ className = 'prose', target = 'modern' } = {}) => {
({ className = 'prose', target = 'modern', color, scale } = {}) => {
return function ({ addVariant, addComponents, theme, prefix }) {
let modifiers = theme('typography')

Expand Down Expand Up @@ -116,6 +117,20 @@ module.exports = plugin.withOptions(
)
}

// Inject default gray/color scale
const safeColor =
isPlainObject(modifiers[color]) && isPlainObject(modifiers[color].css)
? color
: 'gray'
modifiers.DEFAULT.css.push(modifiers[safeColor].css)

// Inject default type scale
const safeScale =
isPlainObject(modifiers[scale]) && Array.isArray(modifiers[scale].css)
? scale
: 'base'
modifiers.DEFAULT.css.push(...modifiers[safeScale].css)

addComponents(
Object.keys(modifiers).map((modifier) => ({
[modifier === 'DEFAULT' ? `.${className}` : `.${className}-${modifier}`]: configToCss(
Expand Down