Skip to content

Commit

Permalink
Merge pull request #1555 from kiva/VUE-223_kv-icon-slimsprite
Browse files Browse the repository at this point in the history
VUE-223 KvIcon: dynamically inline most icons, sprite common icons
  • Loading branch information
ryan-ludwig authored Mar 31, 2020
2 parents 6966f65 + cb58fe6 commit 08bb146
Show file tree
Hide file tree
Showing 250 changed files with 781 additions and 4,389 deletions.
96 changes: 49 additions & 47 deletions .storybook/stories/GenericPromoBanner.stories.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,8 @@
import Vue from 'vue'
import StoryRouter from 'storybook-vue-router';
import { select, text } from '@storybook/addon-knobs';
import { text } from '@storybook/addon-knobs';
import GenericPromoBanner from '@/components/WwwFrame/PromotionalBanner/Banners/GenericPromoBanner';

const iconKeySelect = {
browse: "browse-toggle",
corporate: "corporate-engagement",
curved: "curved-arrow",
dedicate: "dedicate-heart",
distribution: "distribution",
edit: "edit",
email: "email",
filter: "filter",
filters: "filters-toggle",
filters: "filters",
globe: "globe",
grants: "grants",
grid: "grid",
half: "half-star",
handshake: "handshake",
iwd: "iwd-flower",
kiva: "kiva-card",
kivapromise: "kiva-promise",
leaf: "leaf",
leaves: "leaves",
line: "line-graph",
list: "list",
lock: "lock",
magnify: "magnify-glass",
map: "map",
match: "match",
nearme: "nearme",
paypal: "paypal",
pdf: "pdf",
pencil: "pencil",
present: "present",
refresh: "refresh",
secure: "secure-lock",
slideshow: "slideshow-dot",
small: "small-x",
sort: "sort",
star: "star",
tags: "tags-checkmark",
triangle: "triangle",
woman: "woman",
x: "x",
};

// import plugins
import kivaPlugins from '@/plugins';
Vue.use(kivaPlugins)
Expand All @@ -70,7 +26,7 @@ export const Default = () => ({
props: {
iconKey: {
type: String,
default: select('Icon Key', iconKeySelect, 'present')
default: 'present'
},
promoBannerContent: {
type: Object,
Expand All @@ -82,7 +38,6 @@ export const Default = () => ({
};
}
},

},
template: `
<div>
Expand All @@ -95,3 +50,50 @@ export const Default = () => ({
</div>
`,
});


export const AllIcons = () => ({
components: {
GenericPromoBanner,
},
props: {
iconKey: {
type: String,
default: 'present'
},
promoBannerContent: {
type: Object,
default() {
return {
kvTrackEvent: [],
link: `${text('Link', 'http://kiva.org')}`,
richText: decodeHTML(`${text('Banner Text', 'Amazing! Thanks to you, we funded <u>ALL U.S. loans</u> today! Click here to support others who need your help.')}`),
};
}
},
},
data() {
return {
icons: [
"present",
"kiva-card",
"monthly-good",
"iwd-flower",
"confirmation",
"info",
"question",
]
}
},
template: `
<div>
<generic-promo-banner
v-for="icon in icons"
:icon-key="icon"
:promo-banner-content="promoBannerContent"
/>
<br/>
<p class="subheader">Banner text supports basic html tags</p>
</div>
`,
});
94 changes: 94 additions & 0 deletions .storybook/stories/KvIcon.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import KvIcon from '@/components/Kv/KvIcon';

function getFilenames(r) {
return r.keys().map((filename) => {
let str = filename;
str = str.substring(2); // remove ./
str = str.substring(0, str.length - 4); // remove .svg
return str;
});
}

export default {
title: 'Kv/KvIcon',
component: KvIcon,
};

export const Default = () => ({
components: {
KvIcon
},
template: `
<div>
<kv-icon name="print" style="width: 10rem; fill: orange;" />
</div>
`,
});

export const inlined = () => ({
components: {
KvIcon
},
data() {
return {
iconNames: getFilenames(require.context('@/assets/icons/inline/', true, /\.svg$/))
}
},
template: `
<ul style="
list-style: none;
display: grid;
grid-gap: 3rem;
grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
">
<li
v-for="iconName in iconNames"
:key="iconName"
style="
display: grid;
grid-template-rows: 7rem auto;
align-items: center;
text-align: center;
font-size: 0.75rem;
"
>
<kv-icon :name="iconName" />
<div>{{ iconName }}</div>
</li>
</ul>
`,
});

export const fromSprite = () => ({
components: {
KvIcon
},
data() {
return {
iconNames: getFilenames(require.context('@/assets/icons/sprite/', true, /\.svg$/))
}
},
template: `
<ul style="
list-style: none;
display: grid;
grid-gap: 3rem;
grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
">
<li
v-for="iconName in iconNames"
:key="iconName"
style="
display: grid;
grid-template-rows: 7rem auto;
align-items: center;
text-align: center;
font-size: 0.75rem;
"
>
<kv-icon :name="iconName" :from-sprite="true" />
<div>{{ iconName }}</div>
</li>
</ul>
`,
});
7 changes: 4 additions & 3 deletions .storybook/stories/KvTooltip.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import KvTooltip from '@/components/Kv/KvTooltip';
import IconQuestionMark from '@/assets/inline-svgs/icons/question-mark.svg';
import KvIcon from '@/components/Kv/KvIcon';

export default {
title: 'Kv/KvTooltip',
Expand Down Expand Up @@ -29,11 +29,12 @@ export const Default = () => ({
export const QuestionMarkIcon = () => ({
components: {
KvTooltip,
IconQuestionMark,
KvIcon,
},
template: `
<div>
<icon-question-mark
<kv-icon
name="question"
id="question"
style="fill: #d8d8d8; width: 1rem;"
/>
Expand Down
4 changes: 2 additions & 2 deletions build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = {
},
{
test: /\.(png|jpe?g|gif|svg|ico)(\?.*)?$/,
exclude: [resolve('src/assets/icons'), resolve('src/assets/inline-svgs/')],
exclude: [resolve('src/assets/icons/inline/'), resolve('src/assets/inline-svgs/')],
loader: 'url-loader',
options: {
limit: 1, // 10000 is default but we'd need to exclude apple-touch-icons,
Expand All @@ -98,7 +98,7 @@ module.exports = {
},
{
test: /\.svg$/,
include: [resolve('src/assets/inline-svgs/')],
include: [resolve('src/assets/icons/inline/'), resolve('src/assets/inline-svgs/')],
use: [
'babel-loader',
{
Expand Down
Loading

0 comments on commit 08bb146

Please sign in to comment.