forked from learningequality/kolibri-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
klogo.vue
215 lines (187 loc) · 6.96 KB
/
klogo.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<template>
<DocsPageTemplate apiDocs>
<DocsPageSection title="Overview" anchor="#overview">
<p><code>KLogo</code> displays the Kolibri logo and provides functionality to manipulate it such as setting its dimensions, color scheme, animation, and background.</p>
</DocsPageSection>
<DocsPageSection title="Usage" anchor="#usage">
<h3>Default display</h3>
<p>Shows Kolibri logo.</p>
<DocsShow>
<KLogo
ref="defaultLogoNoBackground"
altText="Kolibri Logo"
:size="150"
/>
<div style="width: 100%; text-align: center; display: none;">
<KButton @click="saveSVG('defaultLogoNoBackground')">
Save SVG
</KButton>
</div>
</DocsShow>
<DocsShowCode language="html">
<KLogo
altText="Kolibri logo"
:size="150"
/>
</DocsShowCode>
<h3>Display with backgrounds</h3>
<p>Shows Kolibri logo with background.</p>
<DocsShow>
<KLogo
ref="defaultLogoWithBackground"
altText="Kolibri Logo with background"
:showBackground="true"
:size="150"
/>
<div style="width: 100%; text-align: center; display: none;">
<KButton @click="saveSVG('defaultLogoWithBackground')">
Save SVG
</KButton>
</div>
</DocsShow>
<DocsShowCode language="html">
<KLogo
altText="Kolibri Logo with background"
:showBackground="true"
:size="150"
/>
</DocsShowCode>
<p>Shows Kolibri logo with rectangular background.</p>
<DocsShow>
<KLogo
ref="defaultLogoWithRectBackground"
altText="Kolibri Logo with rectangular background"
backgroundStyle="rect"
:showBackground="true"
:size="150"
/>
<div style="width: 100%; text-align: center; display: none;">
<KButton @click="saveSVG('defaultLogoWithRectBackground')">
Save SVG
</KButton>
</div>
</DocsShow>
<DocsShowCode language="html">
<KLogo
altText="Kolibri Logo with rectangular background"
backgroundStyle="rect"
:showBackground="true"
:size="150"
/>
</DocsShowCode>
<h3>Display with animation</h3>
<p>Shows Kolibri logo with loading animation.</p>
<DocsShow>
<KLogo
altText="Kolibri Logo with loading animation"
:animate="true"
:size="150"
/>
</DocsShow>
<DocsShowCode language="html">
<KLogo
altText="Kolibri Logo with loading animation"
:animate="true"
:size="150"
/>
</DocsShowCode>
<h3>Display with different color schemes</h3>
<p>Different color schemes can be used - but only with the showBackground prop. Note the transparent lines for the monochrome logos.</p>
<DocsShow>
<template
v-for="colorScheme in ['monoBlack', 'monoWhite', 'monoPrimary', 'monoSecondary', 'whiteGrey', 'blackGrey']"
>
<p :key="`text${colorScheme}`">
Color scheme: {{ colorScheme }}
</p>
<KLogo
:ref="`${colorScheme}LogoWithBackground`"
:key="colorScheme"
class="halfsquare-background"
:colorScheme="colorScheme"
altText="Kolibri Logo"
:showBackground="true"
:size="150"
/>
<div
:key="`button${colorScheme}`"
style="width: 100%; text-align: center; display: none;"
>
<KButton @click="saveSVG(`${colorScheme}LogoWithBackground`)">
Save SVG
</KButton>
</div>
</template>
</DocsShow>
<h3>Dimensions</h3>
<p>
You can apply the most common dimensions to the image container via the props <DocsInternalLink href="/kimg#prop:size">
<code>size</code>
</DocsInternalLink>, <DocsInternalLink href="/kimg#prop:maxSize">
<code>maxSize</code>
</DocsInternalLink>, and <DocsInternalLink href="/kimg#prop:minSize">
<code>minSize</code>
</DocsInternalLink>. Values may be either numbers or strings consisting of a numeral and a valid unit. The following units are supported: <code>%, cm, em, ex, ch, in, lh, mm, px, rem, rlh, vh, vw</code>. If you don't provide a unit, <code>px</code> will be used by default.
</p>
<DocsShowCode language="html">
<KLogo
altText="A hummingbird logo"
size="250px"
maxSize="10vw"
:minSize="25"
/>
</DocsShowCode>
<h3>Alternative text</h3>
<p>Alternative text (<code>altText</code>) is required for the logo image. When creating it, consider the following:</p>
<ul>
<li>If the logo is used as a flat image, you can use the string "Kolibri logo"</li>
<li>If the the logo is used as a link, then the alternative text needs to give the context where the link is leading (for example "Go to home page", or similar)</li>
</ul>
</DocsPageSection>
</DocsPageTemplate>
</template>
<script>
// Note for developers, to utilize the saveSVG method, select all of:
// style="width: 100%; text-align: center; display: none;"
// and replace with:
// style="width: 100%; text-align: center;"
// we keep this hidden for future usage, but it doesn't need to be here all the time.
export default {
methods: {
saveSVG(refName) {
const svgElement = this.$refs[refName].$el || this.$refs[refName][0].$el;
// Get the SVG data as a string
const svgData = svgElement.outerHTML;
// Create a Blob from the SVG data
const blob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' });
// Create a URL for the Blob
const url = URL.createObjectURL(blob);
// Create a temporary anchor (`<a>`) element
const downloadLink = document.createElement('a');
// Set the download attribute to the desired file name
downloadLink.download = `${refName}.svg`;
// Set the href to the Blob URL
downloadLink.href = url;
// Append the anchor to the document
document.body.appendChild(downloadLink);
// Programmatically click the anchor to trigger the download
downloadLink.click();
// Clean up by revoking the Blob URL and removing the anchor from the document
URL.revokeObjectURL(url);
downloadLink.remove();
},
},
};
</script>
<style scoped>
.halfsquare-background {
background-size: 10px 10px; /* size of the squares */
background-image:
linear-gradient(45deg, #ffffff 50%, #F5F5F5 50%),
linear-gradient(45deg, #F5F5F5 50%, #ffffff 50%);
background-position:
0 0, /* this is the position of the first pattern */
5px 5px; /* this position offsets the second pattern to create the checker effect */
background-repeat: repeat;
}
</style>