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

feature: added support for custom convertion options #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"args": [
"-p",
"-s",
"app-ynet",
// "blazer",
// "ynetnews",
// "vesty",
// "pplus",
// "yplus"
],
"cwd": "C:\\projects\\wcm_front",
"program": "C:\\projects\\wcm_front\\tools\\siteCssBuilder\\siteCssBuilder.js"
}
]
}
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,53 @@ Default Options:
- `landscape` (Boolean) Adds `@media (orientation: landscape)` with values converted via `landscapeWidth`.
- `landscapeUnit` (String) Expected unit for `landscape` option
- `landscapeWidth` (Number) Viewport width for landscape orientation.
- `customConvertionOptions` (Array of Custom Convertion Objects):
- `viewportWidth` (Number) The width of the viewport.
- `viewportUnit` (String) Expected units.
- `matchSelectors` (Array of Regex) The selector we want to be converted
- `atRule` (Object) used to locate the media query:
- `name` (string) query type. for example 'media'.
- `params` (string) exact query params. for example 'only screen and (max-width: 1040px)'.

#### customConvertionOptions

Use this option if you want to use a different convertion options on the same css file.
You can use:
1. an atRule - object with two fileds (params: string, name: string) - which will convert every rule under this media query.
2. a selector - matchSelectors array with each selector you want to convert in this settings.
3. both - for cases you want to convert specific selector inside the atRule.`

Example:
```js
const pxToViewportOptions = {
viewportWidth: 640,
viewportUnit: 'vw',
propList: ['*'],
selectorBlackList: [/-pf$/],
mediaQuery: true,
customConvertionOptions: [
{
/* Will convert the selector .tablet and all of his sons to 'vw' based on a viewport width of 1536. */
viewportWidth: 1536,
viewportUnit: 'vw',
matchSelectors: [/^.tablet\s/],
},
{
/* Will convert all rules under '@media only screen and (max-width: 961px)' to 'vw' based on a viewport width of 961. */
atRule: { params: 'only screen and (max-width: 961px)', name: 'media' },
viewportWidth: 961,
viewportUnit: 'vw',
},
{
/* Will convert all rules containing the selectors .tablet2 and .tablet3 thats under '@media only screen and (max-width: 961px)' to 'vw' based on a viewport width of 1040. */
atRule: { params: 'only screen and (max-width: 1040px)', name: 'media' },
viewportWidth: 1040,
viewportUnit: 'vw',
matchSelectors: [/^.tablet2\s/, /^.tablet3\s/],
}
]
}
```

> `exclude` and `include` can be set together, and the intersection of the two rules will be taken.

Expand Down
Loading