Skip to content

Commit

Permalink
refactor(deps): make dependencies explicit
Browse files Browse the repository at this point in the history
Make govuk-frontend a package dependency, and import its helpers and width-container into SCSS,
where they're used.

Stop building `.govuk-textarea` in SCSS, instead just apply it onto the element directly.

Mark jQuery as a peer dependency, as it's necessary for the JavaScript to work but not bundled as
part of the package.

BREAKING CHANGE: The package now explicitly depends on govuk-frontend >=3.0.0. If you
already have govuk-frontend installed, ensure that you're using a compatible version.

fixes #147
  • Loading branch information
gregtyler committed Dec 16, 2021
1 parent fac61c1 commit f467039
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package/moj/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ if('contentEditable' in document.documentElement) {
};

MOJFrontend.RichTextEditor.prototype.getEnhancedHtml = function(val) {
return this.getToolbarHtml() + '<div class="moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>';
return this.getToolbarHtml() + '<div class="govuk-textarea moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>';
};

MOJFrontend.RichTextEditor.prototype.hideDefault = function() {
Expand Down
2 changes: 2 additions & 0 deletions package/moj/all.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "node_modules/govuk-frontend/govuk/base";

@import "settings/all";
@import "helpers/all";
@import "objects/all";
Expand Down
2 changes: 2 additions & 0 deletions package/moj/components/cookie-banner/_cookie-banner.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "node_modules/govuk-frontend/govuk/objects/width-container";

.moj-cookie-banner {
display: none;
@include govuk-font(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@
}

.moj-rich-text-editor__content {
@extend .govuk-textarea;
min-height: 130px;
outline: none;
overflow: auto;
resize: vertical;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if('contentEditable' in document.documentElement) {
};

MOJFrontend.RichTextEditor.prototype.getEnhancedHtml = function(val) {
return this.getToolbarHtml() + '<div class="moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>';
return this.getToolbarHtml() + '<div class="govuk-textarea moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>';
};

MOJFrontend.RichTextEditor.prototype.hideDefault = function() {
Expand Down
4 changes: 4 additions & 0 deletions package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"access": "public"
},
"dependencies": {
"govuk-frontend": "^3.0.0 || ^4.0.0",
"moment": "^2.27.0"
},
"peerDependencies": {
"jquery": "^3.6.0"
}
}
2 changes: 2 additions & 0 deletions src/moj/all.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "node_modules/govuk-frontend/govuk/base";

@import "settings/all";
@import "helpers/all";
@import "objects/all";
Expand Down
2 changes: 2 additions & 0 deletions src/moj/components/cookie-banner/_cookie-banner.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "node_modules/govuk-frontend/govuk/objects/width-container";

.moj-cookie-banner {
display: none;
@include govuk-font(16);
Expand Down
3 changes: 1 addition & 2 deletions src/moj/components/rich-text-editor/_rich-text-editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@
}

.moj-rich-text-editor__content {
@extend .govuk-textarea;
min-height: 130px;
outline: none;
overflow: auto;
resize: vertical;
}
}
2 changes: 1 addition & 1 deletion src/moj/components/rich-text-editor/rich-text-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if('contentEditable' in document.documentElement) {
};

MOJFrontend.RichTextEditor.prototype.getEnhancedHtml = function(val) {
return this.getToolbarHtml() + '<div class="moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>';
return this.getToolbarHtml() + '<div class="govuk-textarea moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>';
};

MOJFrontend.RichTextEditor.prototype.hideDefault = function() {
Expand Down
3 changes: 0 additions & 3 deletions test.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/**
* This file is used in CI to test that the moj-frontend can be imported and built.
*
* The govuk-frontend source is also required because we use some of their mixins.
*/
@import "node_modules/govuk-frontend/govuk/all";
@import "node_modules/@ministryofjustice/frontend/moj/all";

0 comments on commit f467039

Please sign in to comment.