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

Replace nuxtjs/svg with nuxtjs/svg-sprite #2135

Merged
merged 5 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ const config: NuxtConfig = {
"@nuxt/typescript-build",
"@nuxtjs/composition-api/module",
"@nuxtjs/style-resources",
"@nuxtjs/svg",
"@nuxtjs/svg-sprite",
"@nuxtjs/eslint-module",
"@pinia/nuxt",
Expand Down
1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"@nuxtjs/redirect-module": "^0.3.1",
"@nuxtjs/sentry": "^7.1.4",
"@nuxtjs/sitemap": "^2.4.0",
"@nuxtjs/svg": "^0.4.0",
"@nuxtjs/svg-sprite": "0.5.2",
"@pinia/nuxt": "0.2.1",
"@popperjs/core": "^2.11.2",
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/components/VBrand/VBrand.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="flex flex-row items-center">
<!-- Using `flex` to place two SVGs side by side. -->
<span class="inline-flex h-[1em] flex-row gap-[0.4em]" aria-hidden="true">
<OpenverseLogo class="h-full w-auto" />
<OpenverseBrand class="h-full w-auto" />
<VSvg class="h-full w-auto" viewBox="0 0 50 42" name="logo" />
<VSvg class="h-full w-auto" viewBox="0 0 215 42" name="brand" />
</span>
<span v-if="srText" class="sr-only">{{ srText }}</span>
</div>
Expand All @@ -13,18 +13,15 @@
<script lang="ts">
import { defineComponent } from "vue"

import OpenverseLogo from "~/assets/logo.svg?inline"
import OpenverseBrand from "~/assets/brand.svg?inline"

import VSvg from "~/components/VSvg/VSvg.vue"
/**
* Render the openverse logo and wordmark next to each other, while being
* accessible to screen-readers.
*/
export default defineComponent({
name: "VBrand",
components: {
OpenverseLogo,
OpenverseBrand,
VSvg,
},
props: {
/**
Expand Down
16 changes: 5 additions & 11 deletions frontend/src/components/VFourOhFour.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<template>
<div class="error grid overflow-x-hidden">
<svg
<VSvg
class="z-0 pointer-events-none col-start-1 row-start-1 -mx-[15%] fill-dark-charcoal opacity-5 lg:mx-15 lg:-mt-20"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 1320 569"
aria-hidden="true"
focusable="false"
>
<use :href="`${Oops}#oops`" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this href have been deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the <VSvg> component handles finding the hrefs now, and we do not use the id of the inner SVG path. We only need to pass the name of the file to use it as an SVG.

</svg>

name="oops"
/>
<div
class="page-404 col-start-1 row-start-1 flex flex-col justify-self-stretch px-6 lg:max-w-2xl lg:justify-self-center lg:px-0"
>
Expand Down Expand Up @@ -51,15 +46,15 @@ import { ALL_MEDIA } from "~/constants/media"
import VLink from "~/components/VLink.vue"
import VSkipToContentContainer from "~/components/VSkipToContentContainer.vue"
import VStandaloneSearchBar from "~/components/VHeader/VSearchBar/VStandaloneSearchBar.vue"

import Oops from "~/assets/oops.svg"
import VSvg from "~/components/VSvg/VSvg.vue"

export default defineComponent({
name: "VFourOhFour",
components: {
VLink,
VSkipToContentContainer,
VStandaloneSearchBar,
VSvg,
},
props: ["error"],
setup() {
Expand All @@ -83,7 +78,6 @@ export default defineComponent({

return {
handleSearch,
Oops,
}
},
head: {},
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/components/VHeader/VHomeLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
"
class="h-12 px-4 text-[1.125rem]"
>
<OpenverseLogoAndWordmark class="h-[1em] w-auto" />
<VSvg
name="logo_and_wordmark"
class="h-[1em] w-auto"
viewBox="0 0 226 34"
/>
</VButton>
</template>

<script lang="ts">
import { type PropType, defineComponent } from "vue"

import VButton from "~/components/VButton.vue"

import OpenverseLogoAndWordmark from "~/assets/logo_and_wordmark.svg?inline"
import VSvg from "~/components/VSvg/VSvg.vue"

/**
* The home link for the internal header. Shows the Openverse logo and wordmark,
Expand All @@ -30,8 +33,8 @@ import OpenverseLogoAndWordmark from "~/assets/logo_and_wordmark.svg?inline"
export default defineComponent({
name: "VHomeLink",
components: {
OpenverseLogoAndWordmark,
VButton,
VSvg,
},
props: {
/**
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/components/VHeader/VWordPressLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="label-regular flex flex-row items-center gap-1"
>
<template #wordpress>
<WordPress />
<VSvg name="wordpress" class="h-6 w-6" width="24" height="24" />
</template>
</i18n>
</VLink>
Expand All @@ -22,12 +22,11 @@
import { PropType } from "vue"

import VLink from "~/components/VLink.vue"

import WordPress from "~/assets/wordpress.svg?inline"
import VSvg from "~/components/VSvg/VSvg.vue"

export default {
name: "VWordPressLink",
components: { VLink, WordPress },
components: { VLink, VSvg },
props: {
mode: {
type: String as PropType<"dark" | "light">,
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/components/VRadio/VRadio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
:checked="isChecked"
@input="handleInput"
/>
<Radiomark
<VSvg
name="radiomark"
class="radiomark absolute start-0 h-5 w-5 text-dark-charcoal opacity-0 transition-opacity"
focusable="false"
width="20"
height="20"
aria-hidden="true"
/>
<!-- @slot Label content goes here -->
<slot />
Expand All @@ -24,15 +23,14 @@
<script lang="ts">
import { computed, defineComponent } from "vue"

import Radiomark from "~/assets/radiomark.svg?inline"

import VSvg from "~/components/VSvg/VSvg.vue"
/**
* Renders a radio input field, useful for choosing one of a few options that
* can all be presented on the screen at once.
*/
export default defineComponent({
name: "VRadio",
components: { Radiomark },
components: { VSvg },
inheritAttrs: false,
model: {
prop: "modelValue",
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/components/VSvg/VSvg.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<SvgIcon :name="`images/${name}`" aria-hidden="true" focusable="false" />
</template>

<script lang="ts">
import { defineComponent } from "vue"
/**
* Displays the given SVG image.
*/
export default defineComponent({
name: "VSvg",
props: {
/**
* name of the SVG in `assets/svg/raw/images`
*/
name: {
type: String,
required: true,
},
},
})
</script>
66 changes: 66 additions & 0 deletions frontend/src/components/VSvg/meta/VSvg.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
ArgsTable,
Canvas,
Description,
Meta,
Story,
} from "@storybook/addon-docs"

import VSvg from "~/components/VSvg/VSvg.vue"

import spriteData from "~svgsprite/sprites.json"

<Meta title="Components/VSvg" component={VSvg} />

export const svgImages = spriteData.filter(
(sprite) => sprite.name === "images"
)[0].symbols

export const Template = (args) => ({
template: `<VSvg v-bind="args" />`,
components: { VSvg },
setup() {
return { args }
},
})

# SVG images

<Description of={VSvg} />

<ArgsTable of={VSvg} />

To display the svg, pass the name of the svg file as a prop, and add `viewbox`
or `width`/`height` pair.

```html
<VSvg name="image-name" />
```

<Canvas>
<Story
name="Default"
args={{
name: "wordpress",
width: "100",
height: "100",
}}
argTypes={{
name: {
options: svgImages,
control: { type: "select" },
},
viewbox: {
control: { type: "text" },
},
width: {
control: { type: "text" },
},
height: {
control: { type: "text" },
},
}}
>
{Template.bind({})}
</Story>
</Canvas>
1 change: 1 addition & 0 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"src/components/VFilters/**.vue",
"src/components/VHomeGallery/**.vue",
"src/components/VIcon/**.vue",
"src/components/VSvg/**.vue",
"src/components/VIconButton/**.vue",
"src/components/VInputField/**.vue",
"src/components/VItemGroup/**.vue",
Expand Down