Skip to content

Commit

Permalink
add static svg sprite sheet file (#1763)
Browse files Browse the repository at this point in the history
Co-authored-by: Cristiano Rastelli <cristiano.rastelli@hashicorp.com>
Co-authored-by: Alex <alex-ju@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 3, 2023
1 parent 8016109 commit c1a46a3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-singers-prove.md
@@ -0,0 +1,5 @@
---
"@hashicorp/flight-icons": minor
---

Added static SVG sprite sheet file
Expand Up @@ -26,7 +26,16 @@ export async function generateBundleSVGSprite({ config, catalog } : { config: Co
const sprites = svgstore({
// see https://github.com/svgstore/svgstore#options for details
renameDefs: false, // we already create unique IDs (using the icon name) in the SVGO step
svgAttrs: { width: '0', height: '0', class: 'flight-sprite-container', 'aria-hidden': 'true' },
svgAttrs: {
width: '0',
height: '0',
// some browsers will not correctly render remote <use> references unless the remote document has the correct namespace
xmlns: "http://www.w3.org/2000/svg",
// Next.js expects there to be a viewBox attribute to calculate dimensions; while this isn't actually useful in the case of an SVG sprite, it does prevent Next.js from throwing an error about being unable to parse the file
viewBox: "0 0 0 0",
class: 'flight-sprite-container',
'aria-hidden': 'true'
},
});

// add the SVGs to the sprite
Expand All @@ -51,4 +60,11 @@ export async function generateBundleSVGSprite({ config, catalog } : { config: Co

// update the SVG "module"
await fs.writeFile(`${config.mainFolder}/svg-sprite/svg-sprite-module.js`, svgModuleContent);

let svgFileContent = '<!--\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n-->\n\n';
svgFileContent += '<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->\n';
svgFileContent += `${svgSpriteContent}\n`;

// update the SVG file
await fs.writeFile(`${config.mainFolder}/svg-sprite/svg-sprite.svg`, svgFileContent);
}
2 changes: 1 addition & 1 deletion packages/flight-icons/svg-sprite/svg-sprite-module.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions packages/flight-icons/svg-sprite/svg-sprite.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

2 comments on commit c1a46a3

@vercel
Copy link

@vercel vercel bot commented on c1a46a3 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hds-showcase – ./packages/components

hds-showcase.vercel.app
hds-components-hashicorp.vercel.app
hds-showcase-hashicorp.vercel.app
hds-showcase-git-main-hashicorp.vercel.app

@vercel
Copy link

@vercel vercel bot commented on c1a46a3 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.