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

Make it easy to prototype with a component based architecture #585

Open
wants to merge 1 commit into
base: main
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
2 changes: 2 additions & 0 deletions app/assets/sass/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ $govuk-global-styles: true;
// Components that aren't in Frontend
@import "components/cookie-banner";

@import "../../components/all";

// Add extra styles here, or re-organise the Sass files in whichever way makes most sense to you
1 change: 1 addition & 0 deletions app/components/_all.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "example-component/example-component";
1 change: 1 addition & 0 deletions app/components/example-component/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Example component
9 changes: 9 additions & 0 deletions app/components/example-component/_example-component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.app-example-component {
@include govuk-font(
$size: 24,
$weight: bold
);
background-color: govuk-colour('pink');
color: govuk-colour('white');
padding: govuk-spacing(6);
}
3 changes: 3 additions & 0 deletions app/components/example-component/example-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function ExampleComponent() {
console.log('Example component');
}
3 changes: 3 additions & 0 deletions app/components/example-component/macro.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro appExampleComponent(params) %}
{%- include "./template.njk" -%}
{% endmacro %}
3 changes: 3 additions & 0 deletions app/components/example-component/template.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="app-example-component">
{{params.text}}
</div>
1 change: 1 addition & 0 deletions app/views/includes/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<script src="/public/javascripts/jquery-1.11.3.js"></script>
<script src="/node_modules/govuk-frontend/all.js"></script>
<script src="/public/javascripts/application.js"></script>
<script src="/public/javascripts/example-component/example-component.js"></script>

{% if useAutoStoreData %}
<script src="/public/javascripts/auto-store-data.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions app/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
{% from "textarea/macro.njk" import govukTextarea %}
{% from "warning-text/macro.njk" import govukWarningText %}

{% from "example-component/macro.njk" import appExampleComponent %}

{% block head %}
{% include "includes/head.html" %}
{% endblock %}
Expand Down
39 changes: 39 additions & 0 deletions docs/views/examples/component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "layout.html" %}

{% block pageTitle %}
Getting started - GOV.UK Prototype Kit
{% endblock %}

{% block beforeContent %}
{{ govukBreadcrumbs({
items: [
{
text: "GOV.UK Prototype Kit",
href: "/docs"
}
]
}) }}
{% endblock %}

{% block content %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

<h1 class="govuk-heading-xl">Components</h1>

{{appExampleComponent({text: 'Example component text'})}}

</div>


</div>


{% endblock %}

{% block pageScripts %}
<script>
new ExampleComponent();
</script>
{% endblock %}
1 change: 1 addition & 0 deletions docs/views/includes/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<script src="/public/javascripts/jquery-1.11.3.js"></script>
<script src="/node_modules/govuk-frontend/all.js"></script>
<script src="/public/javascripts/docs.js"></script>
<script src="/public/javascripts/example-component/example-component.js"></script>

{% if useAutoStoreData %}
<script src="/public/javascripts/auto-store-data.js"></script>
Expand Down
3 changes: 3 additions & 0 deletions docs/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
{% from "textarea/macro.njk" import govukTextarea %}
{% from "warning-text/macro.njk" import govukWarningText %}

{% from "example-component/macro.njk" import appExampleComponent %}

{% block head %}
{% include "includes/head.html" %}
{% if doNotTrackEnabled == false and promoMode == 'true' and gtmId %}
Expand Down Expand Up @@ -108,5 +110,6 @@

{% block bodyEnd %}
{% include "includes/scripts.html" %}
{% block pageScripts %}{% endblock %}
<!-- GOV.UK Prototype Kit {{releaseVersion}} -->
{% endblock %}
3 changes: 2 additions & 1 deletion gulp/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"docsAssets" : "docs/assets/",
"v6Assets": "app/v6/assets/",
"nodeModules": "node_modules/",
"lib": "lib/"
"lib": "lib/",
"components" : "app/components/"
}
}
7 changes: 7 additions & 0 deletions gulp/copy-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ gulp.task('copy-assets', function () {
.pipe(gulp.dest(config.paths.public))
})

gulp.task('copy-component-js', function () {
return gulp.src([
config.paths.components + '**/*.js'
])
.pipe(gulp.dest(config.paths.public + 'javascripts/'))
})

gulp.task('copy-assets-documentation', function () {
return gulp.src(['!' + config.paths.docsAssets + 'sass{,/**/*}',
config.paths.docsAssets + '/**'])
Expand Down
1 change: 1 addition & 0 deletions gulp/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gulp.task('generate-assets', function (done) {
runSequence('clean',
'sass',
'copy-assets',
'copy-component-js',
'sass-documentation',
'copy-assets-documentation',
'sass-v6',
Expand Down
10 changes: 7 additions & 3 deletions gulp/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ const gulp = require('gulp')
const config = require('./config.json')

gulp.task('watch-sass', function () {
return gulp.watch(config.paths.assets + 'sass/**', {cwd: './'}, ['sass'])
return gulp.watch([
config.paths.components + '/**',
config.paths.assets + 'sass/**'], {cwd: './'}, ['sass'])
})

gulp.task('watch-assets', function () {
return gulp.watch([config.paths.assets + 'images/**',
config.paths.assets + 'javascripts/**'], {cwd: './'}, ['copy-assets'])
return gulp.watch([
config.paths.components + '/**',
config.paths.assets + 'images/**',
config.paths.assets + 'javascripts/**'], {cwd: './'}, ['copy-assets', 'copy-component-js'])
})

// Backward compatibility with Elements
Expand Down
6 changes: 4 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ var appViews = [
path.join(__dirname, '/node_modules/govuk-frontend/'),
path.join(__dirname, '/node_modules/govuk-frontend/components'),
path.join(__dirname, '/app/views/'),
path.join(__dirname, '/lib/')
path.join(__dirname, '/lib/'),
path.join(__dirname, '/app/components/')
]

var nunjucksAppEnv = nunjucks.configure(appViews, {
Expand Down Expand Up @@ -120,7 +121,8 @@ if (useDocumentation) {
path.join(__dirname, '/node_modules/govuk-frontend/'),
path.join(__dirname, '/node_modules/govuk-frontend/components'),
path.join(__dirname, '/docs/views/'),
path.join(__dirname, '/lib/')
path.join(__dirname, '/lib/'),
path.join(__dirname, '/app/components/')
]

var nunjucksDocumentationEnv = nunjucks.configure(documentationViews, {
Expand Down