Skip to content

Commit

Permalink
重构 scopedClassMaker x2
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankFang committed Apr 19, 2019
1 parent 871e97a commit 1e63d1f
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions lib/helpers/classes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,16 @@ interface ClassToggles {

function scopedClassMaker(prefix: string) {

return function (name: string | ClassToggles, options?: Options) {
const namesObject = (typeof name === 'string' || name === undefined) ?
{[name]: name} :
name;

const scoped = Object
.entries(namesObject)
return (name: string | ClassToggles, options?: Options) =>
Object
.entries(name instanceof Object ? name : {[name]: name})
.filter(kv => kv[1] !== false)
.map(kv => kv[0])
.map(name => [prefix, name]
.filter(Boolean)
.join('-'))
.concat(options && options.extra || [])
.join(' ');

if (options && options.extra) {
return [scoped, options && options.extra].filter(Boolean).join(' ');
} else {
return scoped;
}
};

}

export {scopedClassMaker};

0 comments on commit 1e63d1f

Please sign in to comment.