Skip to content

Commit

Permalink
Merge pull request #27 from IATI/inline-icons
Browse files Browse the repository at this point in the history
Inline icons
  • Loading branch information
tillywoodfield authored Dec 11, 2024
2 parents 4b8feb1 + cd247bf commit 1dcc152
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 37 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"files": [
"src/scss/**/*.scss",
"src/assets/**/*",
"dist/css/**/*.css",
"dist/js/**/*.js"
],
Expand Down
5 changes: 1 addition & 4 deletions src/scss/components/brand-background/_brand-background.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
@use "../../tokens/screens" as *;

.iati-brand-background {
$var-background-image: --background-image;
#{$var-background-image}: url("/src/assets/svg/marque-white.svg");

background-color: $color-teal-90;
display: grid;
@media (min-width: $screen-md) {
&:after {
content: "";
grid-area: 1/-1;
background-image: var($var-background-image);
background-image: url("@assets/svg/marque-white.svg");
background-repeat: no-repeat;
background-position: right 2rem top;
background-size: 32.3rem auto;
Expand Down
5 changes: 3 additions & 2 deletions src/scss/components/button/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
background-color: $color-teal-80;
}

&__icon {
width: 1rem;
&__icon,
& .iati-icon {
height: 1rem;
}

&--light {
Expand Down
3 changes: 1 addition & 2 deletions src/scss/components/button/button.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Meta, StoryObj } from "@storybook/web-components";
import iconInfoUrl from "../../../assets/svg/icon-info.svg";

import { html } from "lit";

Expand Down Expand Up @@ -38,7 +37,7 @@ export const WithIcon: Story = {
render: () => html`
<button class="iati-button iati-button--light">
<span>Info</span>
<img class="iati-button__icon" src="${iconInfoUrl}" alt="" />
<i class="iati-icon iati-icon--info"></i>
</button>
`,
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
font-family: $font-stack-heading;
color: $color-grey-90;
font-weight: 600;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none'%3E%3Cpath stroke='%23121212' stroke-linecap='square' stroke-width='1.3' d='M10 19c4.9706 0 9-4.0294 9-9 0-4.97056-4.0294-9-9-9-4.97056 0-9 4.02944-9 9 0 4.9706 4.02944 9 9 9Z'/%3E%3Cpath stroke='%23121212' stroke-linecap='round' stroke-linejoin='bevel' stroke-width='1.3' d='M9.99984 18.991C12.3938 16.8114 13.5908 13.8144 13.5908 10c0-3.81433-1.197-6.81133-3.59096-8.99097-2.394 2.17964-3.591 5.17664-3.591 8.99097 0 3.8144 1.197 6.8114 3.591 8.991Z'/%3E%3Cpath stroke='%23121212' stroke-linecap='round' stroke-width='1.3' d='M1.44991 7.29993H18.5499M1.44991 12.6999H18.5499'/%3E%3C/svg%3E");
background-image: url("@assets/svg/icon-globe.svg");
background-repeat: no-repeat;
background-position: 0.5em center;
}
Expand Down
4 changes: 2 additions & 2 deletions src/scss/components/footer/footer.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { html } from "lit";
import { CountrySwitcher } from "../../components/country-switcher/country-switcher.stories";
import {
Facebook,
Linkedin,
LinkedIn,
X,
Youtube,
} from "../../components/icon/icon.stories";
Expand Down Expand Up @@ -67,7 +67,7 @@ export const Footer: Story = {
href="https://www.linkedin.com/company/international-aid-transparency-initiative/"
aria-label="LinkedIn"
>
${Linkedin.render?.call({ ...args })}
${LinkedIn.render?.call({ ...args })}
</a>
<a href="https://x.com/IATI_aid" aria-label="X">
${X.render?.call({ ...args })}
Expand Down
6 changes: 2 additions & 4 deletions src/scss/components/header/header.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { Meta, StoryObj } from "@storybook/web-components";
import { html } from "lit";
import iconInfoUrl from "../../../assets/svg/icon-info.svg";
import iconSearchUrl from "../../../assets/svg/icon-search.svg";
import logoColourUrl from "../../../assets/svg/logo-colour.svg";
import { CountrySwitcher } from "../../components/country-switcher/country-switcher.stories";
import { Open as MenuToggle } from "../../components/menu-toggle/menu-toggle.stories";
Expand Down Expand Up @@ -62,11 +60,11 @@ export const Header: Story = {
${CountrySwitcher.render?.call({ ...args })}
<button class="iati-button iati-button--light hide--mobile-nav">
<span>Help Docs</span>
<img class="iati-button__icon" src="${iconInfoUrl}" alt="" />
<i class="iati-icon iati-icon--info"></i>
</button>
<button class="iati-button iati-button--light">
<span>Search</span>
<img class="iati-button__icon" src="${iconSearchUrl}" alt="" />
<i class="iati-icon iati-icon--search"></i>
</button>
${MenuToggle.render?.call({ ...args })}
</div>
Expand Down
20 changes: 16 additions & 4 deletions src/scss/components/icon/_icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@
background-position: center;
background-size: 100%;

&--info {
background-image: url("@assets/svg/icon-info.svg");
}

&--search {
background-image: url("@assets/svg/icon-search.svg");
}

&--globe {
background-image: url("@assets/svg/icon-globe.svg");
}

&--youtube {
background-image: url("/src/assets/svg/youtube-logo.svg");
background-image: url("@assets/svg/youtube-logo.svg");
aspect-ratio: 1.2 / 1;
}

&--x {
background-image: url("/src/assets/svg/x-logo.svg");
background-image: url("@assets/svg/x-logo.svg");
}

&--linkedin {
background-image: url("/src/assets/svg/linkedin-logo.svg");
background-image: url("@assets/svg/linkedin-logo.svg");
}

&--facebook {
background-image: url("/src/assets/svg/facebook-logo.svg");
background-image: url("@assets/svg/facebook-logo.svg");
}
}
35 changes: 17 additions & 18 deletions src/scss/components/icon/icon.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@ import { html } from "lit";

const meta: Meta = {
title: "Components/Icon",
parameters: {
backgrounds: {
default: "dark",
},
},
};

export default meta;
type Story = StoryObj;

export const Youtube: Story = {
render: () => html`<i class="iati-icon iati-icon--youtube"></i>`,
};

export const X: Story = {
render: () => html`<i class="iati-icon iati-icon--x"></i>`,
};

export const Linkedin: Story = {
render: () => html`<i class="iati-icon iati-icon--linkedin"></i>`,
const createStory = (variant: string, background = "light") => {
const classes = `iati-icon iati-icon--${variant}`;
return {
parameters: {
backgrounds: {
default: background,
},
},
render: () => html`<i class=${classes}></i>`,
};
};

export const Facebook: Story = {
render: () => html`<i class="iati-icon iati-icon--facebook"></i>`,
};
export const Info: Story = createStory("info");
export const Search: Story = createStory("search");
export const Globe: Story = createStory("globe");
export const Youtube: Story = createStory("youtube", "dark");
export const X: Story = createStory("x", "dark");
export const LinkedIn: Story = createStory("linkedin", "dark");
export const Facebook: Story = createStory("facebook", "dark");
6 changes: 6 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "path";
import { NodePackageImporter } from "sass";
import { fileURLToPath } from "url";
import { defineConfig } from "vite";

export default defineConfig({
Expand Down Expand Up @@ -32,4 +33,9 @@ export default defineConfig({
},
},
},
resolve: {
alias: {
"@assets": fileURLToPath(new URL("./src/assets", import.meta.url)),
},
},
});

0 comments on commit 1dcc152

Please sign in to comment.