postcss-pseudo-classes icon indicating copy to clipboard operation
postcss-pseudo-classes copied to clipboard

Always use restrictTo

Open ai opened this issue 2 years ago • 9 comments

I suggest to always have allow-list of states, because right now we prefix :where(), :not() and many other CSS functions like this.

Even if we blacklist when, new will be added in the future. It is more likely to add new non-interactive pseudo-state.

ai avatar Nov 28 '23 16:11 ai

Good idea! I think that going for an allow-list approach makes sense.

In this case though we shouldn't use restrictTo in my opinion because if a user wants to add a pseudo class to the default ones they will have to rewrite interactiveStates by hand.

Since we want to go for an opt-in (allowlist) approach instead opt-out (blacklist), we should remove the concept of blacklist and restrictTo altogether and perhaps expose a custom option that is a function that should return an array of supported pseudo-classes. This function will get the list of default.

let defaultClasses = [':hover', ':active', ':focus', ':visited', ':focus-visible', ':focus-within'];

if (typeof options.custom === "function") {
   defaultClasses = options.custom(defaultClasses);
   if (false === Array.isArray(defaultClasses)) {
       throw new Error("options.custom: Invalid return value. The function should return an array of strings");
   }
}

giuseppeg avatar Nov 30 '23 09:11 giuseppeg

if you want options.custom can be polymorphic and be either the function above or an Array that will override everything

giuseppeg avatar Nov 30 '23 09:11 giuseppeg

@giuseppeg I updated API to custom

ai avatar Nov 30 '23 09:11 ai

I need to merge it to master to make another PR

ai avatar Nov 30 '23 10:11 ai

I will add changes to that PR to avoid merging

ai avatar Nov 30 '23 10:11 ai

I also moved to modern JS syntax, but I think we need to merge https://github.com/giuseppeg/postcss-pseudo-classes/pull/46 to fix CI.

But these 2 PRs is all changes which I am suggesting. We can merge them and release.

ai avatar Nov 30 '23 10:11 ai

Merged the other, feel free to rebase.

giuseppeg avatar Nov 30 '23 13:11 giuseppeg

Rebased and fixed. Merge and release when you will be ready.

ai avatar Nov 30 '23 14:11 ai

Thanks! Will do it tomorrow morning because I am not home

giuseppeg avatar Nov 30 '23 16:11 giuseppeg