Skip to content

Commit d774fd1

Browse files
authored
Merge pull request #4 from factorial-io/refactor/improve-configuration-and-add-optional-settings
refactor!: improve configuration and add optional settings
2 parents 205f182 + 6a4387f commit d774fd1

File tree

8 files changed

+425
-127
lines changed

8 files changed

+425
-127
lines changed

.eslintrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ module.exports = {
3333
"jsdoc/require-param-description": 0,
3434
"jsdoc/require-returns-description": 0,
3535
},
36+
settings: {
37+
jsdoc: {
38+
mode: "typescript",
39+
},
40+
},
3641
};

README.md

+39-25
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
alt="Drupal Logo"
77
src="https://www.drupal.org/files/Wordmark_blue_RGB.png">
88

9-
To eliminate the need for different places for breakpoints and only maintain a single source of truth for those, this `node_module` extracts the breakpoints defined in the currently used drupal themes breakpoint file and generates grouped `customProperties` and a separate `js` object with all necessary parameters.
9+
To eliminate the need for different places for breakpoints and only maintain a single source of truth for those, this `node_module` extracts the breakpoints defined in the currently used Drupal themes breakpoint file and generates grouped `customProperties` and a separate `js` object with all necessary parameters.
1010

11-
If the draft `@custom-media` (See: https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media) or PostCSS (See: https://github.com/postcss/postcss) Custom-media (See: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-media) plugin is already used, media queries can be written with `customProperties`. So any declaration of media queries within stylesheets is omitted and maintainability is increased.
11+
If the draft [`@custom-media`](https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media) or [PostCSS](https://github.com/postcss/postcss) with [Custom-Media](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-media) plugin is already used, media queries can be written with `customProperties`. So any declaration of media queries within stylesheets is omitted and maintainability is increased.
1212

1313
## Installation
1414

@@ -17,27 +17,41 @@ Install as a `devDependency` with `yarn` or `npm` like:
1717
```sh
1818
yarn add --dev `@factorial-io/drupal-breakpoints-css`
1919
# or
20-
npm install --save `@factorial-io/drupal-breakpoints-css`
20+
npm install --sav-dev `@factorial-io/drupal-breakpoints-css`
2121
```
2222

2323
## Configuration
2424

25-
In your themes root folder, besides your already defined breakpoints file from drupal, add a `.breakpoints.yml` configuration file. The following properties are mandatory:
25+
In your themes root folder, besides your already defined breakpoints file from Drupal, add a `breakpoints.config.yml` configuration file. The following properties are mandatory:
2626

2727
```js
28-
/**
29-
* @type {object}
30-
* @property {object} paths - Relativ to the themes root folder ...
31-
* @property {string} paths.breakpoints - ...path to drupals breakpoint file
32-
* @property {string} paths.css - ...path to your final css file
33-
* @property {string} paths.js - ...path to your final js file
34-
* @property {string} themeName - Drupals custom theme name
35-
* @property {string} extractTo
36-
* @property {boolean} js - (default true), should generate js file?
37-
* @property {boolean} css - (default true), should generate css file?
38-
*/
28+
// ./lib/types.d.ts
29+
export interface UserConfig {
30+
drupal: {
31+
path: string,
32+
themeName: string,
33+
};
34+
js?: {
35+
enabled?: boolean,
36+
path?: string,
37+
es6?: "commonjs" | "module",
38+
};
39+
css?: {
40+
enabled?: boolean,
41+
path?: string,
42+
element?: string,
43+
};
44+
options?: {
45+
mediaQuery?: boolean,
46+
resolution?: boolean,
47+
minWidth?: boolean,
48+
maxWidth?: boolean,
49+
};
50+
}
3951
```
4052

53+
You could validate your configuration files with the help of [JSON Schema Store](https://www.schemastore.org/json) and e.g [Visual Studio Code](https://code.visualstudio.com/) [YAML Extension](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml).
54+
4155
## Usage
4256

4357
Just run `yarn drupal-breakpoints-css start` or `npm run drupal-breakpoints-css start`. Thats it :)
@@ -71,34 +85,34 @@ theme_name.lg:
7185
```
7286
7387
```css
74-
/* Generated css file */
75-
html {
76-
--ThemeName-small-query: "only screen and (max-width: 47.9375rem)";
88+
/* Generated CSS file */
89+
:root {
90+
--ThemeName-small-mediaQuery: "only screen and (max-width: 47.9375rem)";
7791
--ThemeName-small-resolution: "2x";
7892
--ThemeName-small-maxWidth: "47.9375rem";
79-
--ThemeName-medium-query: "only screen and (min-width: 48rem) and (max-width: 63.9375rem)";
93+
--ThemeName-medium-mediaQuery: "only screen and (min-width: 48rem) and (max-width: 63.9375rem)";
8094
--ThemeName-medium-resolution: "2x";
8195
--ThemeName-medium-minWidth: "48rem";
8296
--ThemeName-medium-maxWidth: "63.9375rem";
83-
--ThemeName-Group-large-query: "only screen and (min-width: 64rem) and (max-width: 89.9375rem)";
97+
--ThemeName-Group-large-mediaQuery: "only screen and (min-width: 64rem) and (max-width: 89.9375rem)";
8498
--ThemeName-Group-large-resolution: "2x";
8599
--ThemeName-Group-large-minWidth: "64rem";
86100
--ThemeName-Group-large-maxWidth: "89.9375rem";
87101
}
88102
```
89103

90104
```js
91-
// Generated js file
105+
// Generated JS file
92106
const BREAKPOINTS = {
93-
"ThemeName-small-query": "only screen and (max-width: 47.9375rem)",
107+
"ThemeName-small-mediaQuery": "only screen and (max-width: 47.9375rem)",
94108
"ThemeName-small-resolution": "2x",
95109
"ThemeName-small-maxWidth": "47.9375rem",
96-
"ThemeName-medium-query":
110+
"ThemeName-medium-mediaQuery":
97111
"only screen and (min-width: 48rem) and (max-width: 63.9375rem)",
98112
"ThemeName-medium-resolution": "2x",
99113
"ThemeName-medium-minWidth": "48rem",
100114
"ThemeName-medium-maxWidth": "63.9375rem",
101-
"ThemeName-Group-large-query":
115+
"ThemeName-Group-large-mediaQuery":
102116
"only screen and (min-width: 64rem) and (max-width: 89.9375rem)",
103117
"ThemeName-Group-large-resolution": "2x",
104118
"ThemeName-Group-large-minWidth": "64rem",
@@ -109,7 +123,7 @@ export default BREAKPOINTS;
109123

110124
## Acknowledgements
111125

112-
This **Script** uses open source software and would not have been possible without the excellent work of the [Drupal](https://www.drupal.org), [Eslint](https://babeljs.io/team), [Prettier](https://unifiedjs.com/community/member/) and [debug-js](https://github.com/debug-js/debug) teams! Thanks a lot!
126+
This **Script** uses open source software and would not have been possible without the excellent work of the [Drupal](https://www.drupal.org), [Eslint](https://babeljs.io/team), [deepmerge](https://github.com/TehShrike/deepmerge) and [Prettier](https://unifiedjs.com/community/member/) teams! Thanks a lot!
113127

114128
## Sponsored by
115129

lib/defaultConfig.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
drupal: {
3+
path: "",
4+
themeName: "",
5+
},
6+
js: {
7+
enabled: true,
8+
path: "./breakpoints.js",
9+
type: "module",
10+
},
11+
css: {
12+
enabled: true,
13+
path: "./breakpoints.css",
14+
element: ":root",
15+
},
16+
options: {
17+
mediaQuery: true,
18+
resolution: true,
19+
minWidth: true,
20+
maxWidth: true,
21+
},
22+
};

0 commit comments

Comments
 (0)