Skip to content

Adds selector ‘strategy’ plugin option #39

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

Merged
merged 9 commits into from
Mar 26, 2021
Prev Previous commit
Next Next commit
Rename option to strategy with base & class options
  • Loading branch information
chasegiunta committed Mar 25, 2021
commit b221e81eaec8889a9c0f352fd89cd0c2a46cfcfe
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ const { colors, spacing, borderWidth, borderRadius, outline } = defaultTheme

const forms = plugin.withOptions(function (options) {
return function ({ addBase, theme }) {
const swap = function (initial, classes) {
return options && options.useFormClasses === true ? classes : initial
const strategy = options && options.strategy === 'class' ? 'class' : 'base'

const swap = function (baseSelectors, classSelectors) {
return strategy === 'class' ? classSelectors : baseSelectors
}

const baseSelectors =
(options && options.useFormClasses) === true
? '.form-input, .form-textarea, .form-select'
: "[type='text'], [type='email'], [type='url'], [type='password'], [type='number'], [type='date'], [type='datetime-local'], [type='month'], [type='search'], [type='tel'], [type='time'], [type='week'], [multiple], textarea, select"
const baseSelectors = {
class: '.form-input, .form-textarea, .form-select',
base:
"[type='text'],[type='email'], [type='url'], [type='password'], [type='number'], [type='date'], [type='datetime-local'], [type='month'], [type='search'], [type='tel'], [type='time'], [type='week'], [multiple], textarea, select",
}

addBase({
[baseSelectors]: {
[baseSelectors[strategy]]: {
appearance: 'none',
'background-color': '#fff',
'border-color': theme('colors.gray.500', colors.gray[500]),
Expand Down