Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use addComponents for class strategy #91

Merged
merged 2 commits into from
Feb 23, 2022
Merged
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
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