desy-html 7.3.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/_global.foot.njk +0 -23
- package/docs/_global.head.njk +13 -331
- package/docs/_macro.example-render.njk +40 -15
- package/docs/_macro.render-caller.njk +2 -2
- package/docs/_macro.show-code-from-file.njk +57 -0
- package/docs/_template.examples.njk +1 -1
- package/docs/estilos.html +15 -14
- package/docs/index.html +12 -0
- package/gulpfile.js +18 -3
- package/package.json +5 -2
- package/src/css/styles.css +1 -1
- package/src/js/filters/filter-caller.js +6 -0
- package/src/js/filters/highlight.js +14 -0
- package/src/js/filters/index.js +10 -0
- package/src/js/globals/get-html-code-from-example.js +29 -0
- package/src/js/globals/get-html-code-from-file.js +26 -0
- package/src/js/globals/get-nunjucks-code-from-example.js +32 -0
- package/src/js/globals/get-nunjucks-code-from-file.js +24 -0
- package/src/js/globals/index.js +14 -0
- package/src/js/index.js +21 -0
- package/src/templates/components/accordion/_examples.accordion.njk +108 -104
- package/src/templates/components/accordion-history/_examples.accordion-history.njk +116 -112
- package/src/templates/components/alert/_examples.alert.njk +10 -6
- package/src/templates/components/breadcrumbs/_examples.breadcrumbs.njk +52 -52
- package/src/templates/components/button/_examples.button.njk +71 -71
- package/src/templates/components/button-loader/_examples.button-loader.njk +72 -72
- package/src/templates/components/card/_examples.card.njk +43 -43
- package/src/templates/components/character-count/_examples.character-count.njk +35 -33
- package/src/templates/components/checkboxes/_examples.checkboxes.njk +200 -201
- package/src/templates/components/collapsible/_examples.collapsible.njk +24 -9
- package/src/templates/components/date-input/_examples.date-input.njk +14 -14
- package/src/templates/components/description-list/_examples.description-list.njk +45 -44
- package/src/templates/components/details/_examples.details.njk +17 -16
- package/src/templates/components/dialog/_examples.dialog.njk +5 -6
- package/src/templates/components/dropdown/_examples.dropdown.njk +34 -35
- package/src/templates/components/error-message/_examples.error-message.njk +8 -2
- package/src/templates/components/error-summary/_examples.error-summary.njk +19 -19
- package/src/templates/components/fieldset/_examples.fieldset.njk +27 -25
- package/src/templates/components/file-upload/_examples.file-upload.njk +7 -7
- package/src/templates/components/footer/_examples.footer.njk +24 -24
- package/src/templates/components/footer/_template.footer.njk +1 -1
- package/src/templates/components/header/_examples.header.njk +12 -12
- package/src/templates/components/header-mini/_examples.header-mini.njk +5 -5
- package/src/templates/components/hint/_examples.hint.njk +4 -4
- package/src/templates/components/input/_examples.input.njk +68 -65
- package/src/templates/components/input-group/_examples.input-group.njk +15 -17
- package/src/templates/components/item/_examples.item.njk +21 -20
- package/src/templates/components/label/_examples.label.njk +11 -9
- package/src/templates/components/links-list/_examples.links-list.njk +34 -34
- package/src/templates/components/listbox/_examples.listbox.njk +146 -146
- package/src/templates/components/media-object/_examples.media-object.njk +7 -7
- package/src/templates/components/menu-horizontal/_examples.menu-horizontal.njk +54 -54
- package/src/templates/components/menu-navigation/_examples.menu-navigation.njk +65 -66
- package/src/templates/components/menu-vertical/_examples.menu-vertical.njk +71 -71
- package/src/templates/components/menubar/_examples.menubar.njk +42 -42
- package/src/templates/components/modal/_examples.modal.njk +21 -15
- package/src/templates/components/modal/_template.modal.njk +5 -5
- package/src/templates/components/nav/_examples.nav.njk +66 -66
- package/src/templates/components/notification/_examples.notification.njk +14 -13
- package/src/templates/components/pagination/_examples.pagination.njk +7 -6
- package/src/templates/components/pill/_examples.pill.njk +29 -29
- package/src/templates/components/radios/_examples.radios.njk +153 -142
- package/src/templates/components/searchbar/_examples.searchbar.njk +13 -13
- package/src/templates/components/select/_examples.select.njk +63 -63
- package/src/templates/components/skip-link/_examples.skip-link.njk +4 -4
- package/src/templates/components/spinner/_examples.spinner.njk +11 -11
- package/src/templates/components/status/_examples.status.njk +4 -4
- package/src/templates/components/status-item/_examples.status-item.njk +21 -21
- package/src/templates/components/table/_examples.table.njk +58 -56
- package/src/templates/components/table-advanced/_examples.table-advanced.njk +83 -83
- package/src/templates/components/tabs/_examples.tabs.njk +30 -29
- package/src/templates/components/textarea/_examples.textarea.njk +28 -27
- package/src/templates/components/toggle/_examples.toggle.njk +10 -11
- package/src/templates/components/tooltip/_examples.tooltip.njk +9 -9
- package/src/templates/components/tree/_examples.tree.njk +58 -57
- package/src/js/prism/clipboard.min.js +0 -7
- package/src/js/prism/prism-copy-to-clipboard.min.js +0 -1
- package/src/js/prism/prism-normalize-whitespace.min.js +0 -1
- package/src/js/prism/prism-toolbar.min.js +0 -1
- package/src/js/prism/prism-twig.min.js +0 -1
- package/src/js/prism/prism-yaml.min.js +0 -1
- package/src/js/prism/prism.min.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "desy-html",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "desy-html contains the code you need to start building a user interface for Gobierno de Aragón government webapps.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Desy (SDA Servicios Digitales de Aragón)",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@tailwindcss/typography": "^0.5.7",
|
|
38
38
|
"autoprefixer": "^10.0.2",
|
|
39
39
|
"hex-rgb": "^5.0.0",
|
|
40
|
+
"highlight.js": "^11.7.0",
|
|
40
41
|
"npm-run-all": "^4.1.5",
|
|
41
42
|
"postcss": "^8.2.15",
|
|
42
43
|
"postcss-cli": "^10.0.0",
|
|
@@ -51,7 +52,9 @@
|
|
|
51
52
|
"gulp-footer": "^2.0.2",
|
|
52
53
|
"gulp-nunjucks-render": "^2.2.3",
|
|
53
54
|
"gulp-postcss": "^9.0.1",
|
|
54
|
-
"gulp-strip-css-comments": "^2.0.0"
|
|
55
|
+
"gulp-strip-css-comments": "^2.0.0",
|
|
56
|
+
"js-beautify": "^1.14.7",
|
|
57
|
+
"outdent": "^0.8.0"
|
|
55
58
|
},
|
|
56
59
|
"optionalDependencies": {
|
|
57
60
|
"win-node-env": "^0.6.1"
|
package/src/css/styles.css
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const hljs = require('highlight.js')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Format code with syntax highlighting
|
|
5
|
+
*
|
|
6
|
+
* @param {string} code - Code in plain text
|
|
7
|
+
* @param {string} [language] - Code programming language
|
|
8
|
+
* @returns {string} Code with syntax highlighting
|
|
9
|
+
*/
|
|
10
|
+
function highlight (code, language) {
|
|
11
|
+
return hljs.highlight(code.trim(), { language: language || 'plaintext' }).value
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = highlight
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const beautify = require('js-beautify')
|
|
2
|
+
/**
|
|
3
|
+
* Component HTML code (formatted)
|
|
4
|
+
*
|
|
5
|
+
* @param {string} componentName - Component name
|
|
6
|
+
* @param {unknown} params - Component macro params
|
|
7
|
+
* @param {unknown} pathName - path name
|
|
8
|
+
*/
|
|
9
|
+
function getHTMLCodeFromExample (componentName, params, pathName) {
|
|
10
|
+
const templatePath = `${pathName}s/${componentName}/_template.${componentName}.njk`;
|
|
11
|
+
|
|
12
|
+
// Render to HTML
|
|
13
|
+
const html = this.env.render(templatePath, { params }).trim()
|
|
14
|
+
|
|
15
|
+
// Default beautify options
|
|
16
|
+
const options = beautify.html.defaultOptions()
|
|
17
|
+
|
|
18
|
+
return beautify.html(html, {
|
|
19
|
+
indent_size: 2,
|
|
20
|
+
// Ensure nested labels in headings are indented properly
|
|
21
|
+
inline: options.inline.filter((tag) => !['label'].includes(tag)),
|
|
22
|
+
// Remove blank lines
|
|
23
|
+
max_preserve_newlines: 0,
|
|
24
|
+
// Ensure attribute wrapping in header SVG is preserved
|
|
25
|
+
wrap_attributes: 'preserve'
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = getHTMLCodeFromExample
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const beautify = require('js-beautify')
|
|
2
|
+
/**
|
|
3
|
+
* Component HTML code (formatted)
|
|
4
|
+
*
|
|
5
|
+
* @param {string} templatePath - Path to nunjucks file. Eg: `includes/_loremipsum-large.njk`;
|
|
6
|
+
*/
|
|
7
|
+
function getHTMLCodeFromFile (templatePath) {
|
|
8
|
+
|
|
9
|
+
// Render to HTML
|
|
10
|
+
const html = this.env.render(templatePath).trim()
|
|
11
|
+
|
|
12
|
+
// Default beautify options
|
|
13
|
+
const options = beautify.html.defaultOptions()
|
|
14
|
+
|
|
15
|
+
return beautify.html(html, {
|
|
16
|
+
indent_size: 2,
|
|
17
|
+
// Ensure nested labels in headings are indented properly
|
|
18
|
+
inline: options.inline.filter((tag) => !['label'].includes(tag)),
|
|
19
|
+
// Remove blank lines
|
|
20
|
+
max_preserve_newlines: 0,
|
|
21
|
+
// Ensure attribute wrapping in header SVG is preserved
|
|
22
|
+
wrap_attributes: 'preserve'
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = getHTMLCodeFromFile
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const { outdent } = require('outdent')
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Component Nunjucks code (formatted)
|
|
6
|
+
*
|
|
7
|
+
* @param {string} componentName - Component name
|
|
8
|
+
* @param {unknown} params - Component macro params
|
|
9
|
+
* @returns {string} Nunjucks code
|
|
10
|
+
*/
|
|
11
|
+
function getNunjucksCodeFromExample (componentName, params, pathName) {
|
|
12
|
+
const macroName = kebabCaseToPascalCase(componentName)
|
|
13
|
+
|
|
14
|
+
return outdent`
|
|
15
|
+
{% from "${pathName}s/${componentName}/macro.njk" import ${pathName}${macroName} %}
|
|
16
|
+
|
|
17
|
+
{{ ${pathName}${macroName}(${
|
|
18
|
+
JSON.stringify(params, undefined, 2)
|
|
19
|
+
}) }}
|
|
20
|
+
`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function kebabCaseToPascalCase (value) {
|
|
24
|
+
return value
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.split('-')
|
|
27
|
+
// capitalize each 'word'
|
|
28
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
29
|
+
.join('')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = getNunjucksCodeFromExample
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { outdent } = require('outdent')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Component Nunjucks code (formatted)
|
|
5
|
+
* Uses node.js to read the content of a file, display it as code.
|
|
6
|
+
* @param {string} templatePath - Path to nunjucks file. Eg: `includes/_loremipsum-large.njk`;
|
|
7
|
+
* @returns {string} Nunjucks code
|
|
8
|
+
*/
|
|
9
|
+
function getNunjucksCodeFromFile (templatePath) {
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
let codeFromFile
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
codeFromFile = fs.readFileSync(`src/templates/${templatePath}`, 'utf8');
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error(err);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return outdent`
|
|
20
|
+
${codeFromFile}
|
|
21
|
+
`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = getNunjucksCodeFromFile
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nunjucks globals
|
|
3
|
+
*/
|
|
4
|
+
const getHTMLCodeFromExample = require('./get-html-code-from-example.js')
|
|
5
|
+
const getNunjucksCodeFromExample = require('./get-nunjucks-code-from-example.js')
|
|
6
|
+
const getHTMLCodeFromFile = require('./get-html-code-from-file.js')
|
|
7
|
+
const getNunjucksCodeFromFile = require('./get-nunjucks-code-from-file.js')
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
getNunjucksCodeFromExample,
|
|
11
|
+
getHTMLCodeFromExample,
|
|
12
|
+
getNunjucksCodeFromFile,
|
|
13
|
+
getHTMLCodeFromFile
|
|
14
|
+
}
|
package/src/js/index.js
CHANGED
|
@@ -41,3 +41,24 @@ notificationComponent(aria);
|
|
|
41
41
|
radioButtonComponent(aria);
|
|
42
42
|
checkBoxComponent(aria);
|
|
43
43
|
|
|
44
|
+
|
|
45
|
+
//Using the browser API to copy code to the clipboard
|
|
46
|
+
const copyButtons = document.querySelectorAll('[data-module = "c-button-copy"]');
|
|
47
|
+
copyButtons.forEach(button => {
|
|
48
|
+
button.addEventListener("click", async (event) => {
|
|
49
|
+
await copyCode(button);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
async function copyCode(button) {
|
|
54
|
+
const code = button.nextElementSibling.innerText;
|
|
55
|
+
await navigator.clipboard.writeText(code);
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
button.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" class="self-center mr-2" aria-hidden="true" width="1em" height="1em"><path d="M13.714 42.857A6.857 6.857 0 0 1 8.4 40.183L.857 31.646a3.429 3.429 0 0 1 .309-4.869A3.429 3.429 0 0 1 6 27.12l7.063 7.989a.72.72 0 0 0 .617.308.789.789 0 0 0 .617-.274L42.103 6.206a3.429 3.429 0 0 1 4.937 4.731L18.926 40.526a6.651 6.651 0 0 1-5.212 2.331Z" fill="currentColor"></path></svg> Copiado';
|
|
58
|
+
},100)
|
|
59
|
+
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
button.innerHTML = "Copiar código";
|
|
62
|
+
},2500)
|
|
63
|
+
|
|
64
|
+
}
|