Skip to content

Commit

Permalink
Use addComponents for class strategy (#91)
Browse files Browse the repository at this point in the history
* feat: add styles in bucket based on the strategy

* fix: import `addComponents` callback
  • Loading branch information
FedericoBiccheddu authored Feb 23, 2022
1 parent bb5315c commit 807cd40
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const [baseFontSize, { lineHeight: baseLineHeight }] = defaultTheme.fontSize.bas
const { spacing, borderWidth, borderRadius } = defaultTheme

const forms = plugin.withOptions(function (options = { strategy: 'base' }) {
return function ({ addBase, theme }) {
return function ({ addBase, addComponents, theme }) {
const strategy = options.strategy

const rules = [
Expand Down Expand Up @@ -252,17 +252,20 @@ const forms = plugin.withOptions(function (options = { strategy: 'base' }) {
},
]

addBase(
rules
.map((rule) => {
if (rule[strategy] === null) {
return null
}
const strategyRules = rules
.map((rule) => {
if (rule[strategy] === null) {
return null
}

return { [rule[strategy]]: rule.styles }
})
.filter(Boolean)
)
return { [rule[strategy]]: rule.styles }
})
.filter(Boolean)

;({
'base': addBase,
'class': addComponents
})[strategy](strategyRules)
}
})

Expand Down

1 comment on commit 807cd40

@vercel
Copy link

@vercel vercel bot commented on 807cd40 Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.