forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 Merge PR DefinitelyTyped#60326 [postcss-mixins] Add types for postc…
…ss-mixins by @MysteryBlokHed * Add types for postcss-mixins * Update return type for MixinFn * Fix MixinObj type
- Loading branch information
1 parent
4583137
commit 063c09f
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Type definitions for postcss-mixins 9.0 | ||
// Project: https://github.com/postcss/postcss-mixins | ||
// Definitions by: Adam Thompson-Sharpe <https://github.com/MysteryBlokHed> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
import { Container, PluginCreator } from 'postcss'; | ||
|
||
declare namespace postcssMixins { | ||
interface Options { | ||
/** | ||
* Define mixins in code instead of with CSS. | ||
* | ||
* For functions: the first parameter is the mixin rule, | ||
* and all others are parameters passed to the mixin. | ||
*/ | ||
mixins?: Record<string, Mixin> | undefined; | ||
/** | ||
* Autoload all mixins from one or more dirs. | ||
* Mixin name will be taken from file name. | ||
*/ | ||
mixinsDir?: string | string[] | undefined; | ||
/** | ||
* Similar to mixinsDir, except you can provide fast-glob syntax | ||
* to target or not to target specific files. | ||
*/ | ||
mixinsFiles?: string | string[] | undefined; | ||
/** | ||
* Remove unknown mixins instead of throwing an error. | ||
* Off by default. | ||
*/ | ||
silent?: boolean | undefined; | ||
} | ||
|
||
/** | ||
* A mixin, either a function or an object | ||
*/ | ||
type Mixin = MixinFn | MixinObj; | ||
type MixinFn = (mixin: Container, ...args: string[]) => MixinObj | void; | ||
// The Exclude here is meant to make sure that you can't assign invalid functions to MixinObj, | ||
// which is possible with Record<string, any> | ||
// tslint:disable-next-line:ban-types | ||
type MixinObj = Record<string, Exclude<Object, Function>>; | ||
} | ||
|
||
declare var postcssMixins: PluginCreator<postcssMixins.Options>; | ||
|
||
export = postcssMixins; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"postcss": "^8.2.14" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import postcss from 'postcss'; | ||
import postcssMixins = require('postcss-mixins'); | ||
|
||
// Using with postcss with and without config | ||
postcss([postcssMixins]); | ||
postcss([postcssMixins()]); | ||
postcss([postcssMixins({})]); | ||
|
||
// Defining mixins | ||
postcssMixins({ | ||
mixins: { | ||
// Modfifying the mixin directly | ||
mixinFn1(mixin, arg1, arg2) { | ||
arg1; // $ExpectType string | ||
arg2; // $ExpectType string | ||
|
||
const rule = postcss.rule(); | ||
rule.append(mixin.nodes); | ||
mixin.replaceWith(rule); | ||
}, | ||
|
||
// Returning new nodes | ||
mixinFn2(_mixin, color) { | ||
return { | ||
top: 10, | ||
'&:hover': { color }, | ||
}; | ||
}, | ||
|
||
// $ExpectError | ||
invalidFn() { | ||
return 1234; | ||
}, | ||
|
||
// Mixin object | ||
mixinObj: { | ||
top: 10, | ||
'&:hover': { color: 'red' }, | ||
}, | ||
}, | ||
}); | ||
|
||
postcssMixins({ mixinsDir: './mixins' }); | ||
postcssMixins({ mixinsDir: ['./mixins'] }); | ||
|
||
postcssMixins({ mixinsFiles: './mixins/!(*.spec.js)' }); | ||
postcssMixins({ mixinsFiles: ['./mixins/!(*.spec.js)'] }); | ||
|
||
postcssMixins({ silent: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["es6", "ES2018.Promise"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"baseUrl": "../", | ||
"typeRoots": ["../"], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": ["index.d.ts", "postcss-mixins-tests.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "@definitelytyped/dtslint/dt.json" } |