mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
This commit adds a component for showing an API key. Usage:
```jinja
{{ from 'components/api-key.html' import api_key }}
{{ api_key('e1b0751388f3cd0fc9982c701acdb3c2') }}
```
Depending on the user’s browser, it works in three different ways.
No Javascript
---
The API key is shown on the page.
Older browsers with Javascript
---
The API key is hidden, and users can click a button to reveal it.
Newer browsers that support copying to clipboard without Flash
---
As above, but when the key is shown there is a button which copies it to the
clipboard. This is acheived by using
[this polyfill](https://www.npmjs.com/package/query-command-supported)
to reliably detect browser support for the ‘copy’ command.
The styling of the component is a bit different to the initial sketch. I think
a grey button works better than green. Green feels like it’s going to take you
somewhere else.
94 lines
2.5 KiB
JavaScript
94 lines
2.5 KiB
JavaScript
// GULPFILE
|
|
// - - - - - - - - - - - - - - -
|
|
// This file processes all of the assets in the "src" folder
|
|
// and outputs the finished files in the "dist" folder.
|
|
|
|
// 1. LIBRARIES
|
|
// - - - - - - - - - - - - - - -
|
|
var gulp = require('gulp'),
|
|
plugins = require('gulp-load-plugins')(),
|
|
|
|
// 2. CONFIGURATION
|
|
// - - - - - - - - - - - - - - -
|
|
paths = {
|
|
src: 'app/assets/',
|
|
dist: 'app/static/',
|
|
templates: 'app/templates/',
|
|
npm: 'node_modules/'
|
|
};
|
|
|
|
// 3. TASKS
|
|
// - - - - - - - - - - - - - - -
|
|
|
|
// Move GOV.UK template resources
|
|
|
|
gulp.task('copy:govuk_template:template', () => gulp.src('bower_components/govuk_template/views/layouts/govuk_template.html')
|
|
.pipe(gulp.dest(paths.templates))
|
|
);
|
|
|
|
gulp.task('copy:govuk_template:assets', () => gulp.src('bower_components/govuk_template/assets/**/*')
|
|
.pipe(gulp.dest(paths.dist))
|
|
);
|
|
|
|
gulp.task('javascripts', () => gulp
|
|
.src([
|
|
paths.npm + 'govuk_frontend_toolkit/javascripts/govuk/modules.js',
|
|
paths.npm + 'govuk_frontend_toolkit/javascripts/govuk/selection-buttons.js',
|
|
paths.src + 'javascripts/apiKey.js',
|
|
paths.src + 'javascripts/dropdown.js',
|
|
paths.src + 'javascripts/highlightTags.js',
|
|
paths.src + 'javascripts/main.js'
|
|
])
|
|
.pipe(plugins.babel({
|
|
presets: ['es2015']
|
|
}))
|
|
.pipe(plugins.uglify())
|
|
.pipe(plugins.addSrc.prepend([
|
|
paths.npm + 'jquery/dist/jquery.min.js',
|
|
paths.npm + 'query-command-supported/dist/queryCommandSupported.min.js'
|
|
]))
|
|
.pipe(plugins.concat('all.js'))
|
|
.pipe(gulp.dest(paths.dist + 'javascripts/'))
|
|
);
|
|
|
|
gulp.task('sass', () => gulp
|
|
.src(paths.src + '/stylesheets/main*.scss')
|
|
.pipe(plugins.sass({
|
|
outputStyle: 'compressed',
|
|
includePaths: [
|
|
paths.npm + 'govuk-elements-sass/public/sass/',
|
|
paths.npm + 'govuk_frontend_toolkit/stylesheets/'
|
|
]
|
|
}))
|
|
.pipe(gulp.dest(paths.dist + '/stylesheets'))
|
|
);
|
|
|
|
|
|
// Copy images
|
|
|
|
gulp.task('images', () => gulp
|
|
.src([
|
|
paths.src + 'images/**/*',
|
|
paths.npm + 'govuk_frontend_toolkit/images/**/*'
|
|
])
|
|
.pipe(gulp.dest(paths.dist + '/images'))
|
|
);
|
|
|
|
|
|
// Watch for changes and re-run tasks
|
|
gulp.task('watchForChanges', function() {
|
|
gulp.watch(paths.src + 'javascripts/**/*', ['javascripts']);
|
|
gulp.watch(paths.src + 'stylesheets/**/*', ['sass']);
|
|
gulp.watch(paths.src + 'images/**/*', ['images']);
|
|
});
|
|
|
|
// Default: compile everything
|
|
gulp.task('default',
|
|
['copy:govuk_template:template', 'copy:govuk_template:assets', 'javascripts', 'sass', 'images']
|
|
);
|
|
|
|
// Optional: recompile on changes
|
|
gulp.task('watch',
|
|
['default', 'watchForChanges']
|
|
);
|