Got all options working for copying and downloading

This commit is contained in:
Corey 2020-07-30 20:59:48 +08:00
parent cbd30c3447
commit d8b33f059a
4 changed files with 90 additions and 46 deletions

View file

@ -16,7 +16,7 @@
"postcss-loader": "^2.1.1", "postcss-loader": "^2.1.1",
"purgecss-webpack-plugin": "^1.4.0", "purgecss-webpack-plugin": "^1.4.0",
"style-loader": "^0.20.3", "style-loader": "^0.20.3",
"tailwindcss": "^1.4.5", "tailwindcss": "^1.6.0",
"webpack": "^4.29.6", "webpack": "^4.29.6",
"webpack-cli": "^3.3.0", "webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1" "webpack-dev-server": "^3.2.1"

View file

@ -31,7 +31,7 @@
x-ref="searchField" x-ref="searchField"
x-model="search" x-model="search"
x-on:keydown.window.prevent.slash="$refs.searchField.focus()" x-on:keydown.window.prevent.slash="$refs.searchField.focus()"
placeholder="Search 420 System UIcons" x-bind:placeholder="'Search ' + myForData.length + ' System UIcons'"
type="text" type="text"
name="search" name="search"
value="" value=""
@ -45,40 +45,48 @@
<div <div
class="flex flex-col space-y-4 md:space-y-0 md:flex-row border-t border-gray-300 bg-white py-4 px-8 sticky top-0 z-10" class="flex flex-col space-y-4 md:space-y-0 md:flex-row border-t border-gray-300 bg-white py-4 px-8 sticky top-0 z-10"
> >
<label <div class="bg-gray-200 p-1 rounded">
class="inline-flex items-center cursor-pointer rounded px-2 text-sm lg:text-base hover:bg-gray-900 hover:text-white" <label
> class="inline-flex h-full items-center cursor-pointer rounded px-2 text-sm lg:text-base hover:bg-gray-900"
<input :class="downloadType === 'copy-svg' ? 'bg-white shadow' : 'text-blue-500 hover:text-blue-800'"
type="radio" >
class="form-radio" <input
name="clickType" type="radio"
value="copy" class="form-radio"
checked name="copy-svg"
/> x-model="downloadType"
<span class="ml-2">Copy SVG Code</span> :value="'copy-svg'"
</label> checked
<label />
class="inline-flex items-center md:ml-2 lg:ml-4 cursor-pointer rounded px-2 text-sm lg:text-base hover:bg-gray-900 hover:text-white" <span class="ml-2">Copy SVG Code</span>
> </label>
<input <label
type="radio" class="inline-flex h-full items-center md:ml-2 lg:ml-4 cursor-pointer rounded px-2 text-sm lg:text-base hover:bg-gray-900 hover:text-white"
class="form-radio" :class="downloadType === 'copy-cdn' ? 'bg-white shadow' : 'text-blue-500 hover:text-blue-800'"
name="clickType" >
value="link" <input
/> type="radio"
<span class="ml-2">Copy CDN Link</span> class="form-radio"
</label> name="copy-cdn"
<label x-model="downloadType"
class="inline-flex items-center md:ml-2 lg:ml-4 cursor-pointer rounded px-2 text-sm lg:text-base hover:bg-gray-900 hover:text-white" :value="'copy-cdn'"
> />
<input <span class="ml-2">Copy CDN Link</span>
type="radio" </label>
class="form-radio" <label
name="clickType" class="inline-flex h-full items-center md:ml-2 lg:ml-4 cursor-pointer rounded px-2 text-sm lg:text-base hover:bg-gray-900 hover:text-white"
value="download" :class="downloadType === 'download-svg' ? 'bg-white shadow' : 'text-blue-500 hover:text-blue-800'"
/> >
<span class="ml-2">Download SVGs</span> <input
</label> type="radio"
class="form-radio"
name="download-svg"
x-model="downloadType"
:value="'download-svg'"
/>
<span class="ml-2">Download SVGs</span>
</label>
</div>
<button <button
class="flex flex-row items-center ml-auto p-3 rounded bg-black text-white text-sm lg:text-base hover:bg-gray-900 w-full md:w-auto" class="flex flex-row items-center ml-auto p-3 rounded bg-black text-white text-sm lg:text-base hover:bg-gray-900 w-full md:w-auto"
> >
@ -115,8 +123,16 @@
> >
<template x-for="(item, index) in filteredIcons" :key="index"> <template x-for="(item, index) in filteredIcons" :key="index">
<a <a
href="#" href=""
x-bind:href="document.location.protocol +
'//' +
document.location.host +
`/images/` +
item.icon_path +
`.svg`"
x-bind:download="downloadType === 'download-svg' && item.icon_name"
class="flex flex-col relative items-center group justify-center text-gray-700 rounded shadow hover:shadow-xl bg-white cursor-pointer transition duration-150 ease-in-out h-48" class="flex flex-col relative items-center group justify-center text-gray-700 rounded shadow hover:shadow-xl bg-white cursor-pointer transition duration-150 ease-in-out h-48"
@click="handleClick(item, downloadType, $event)"
> >
<img <img
:src="`images/` + item.icon_path + `.svg`" :src="`images/` + item.icon_path + `.svg`"
@ -1258,6 +1274,7 @@
function loadIcons() { function loadIcons() {
return { return {
search: "", search: "",
downloadType: "copy-svg",
myForData: sourceData, myForData: sourceData,
get filteredIcons() { get filteredIcons() {
if (this.search === "") { if (this.search === "") {
@ -1269,6 +1286,32 @@
.includes(this.search.toLowerCase()); .includes(this.search.toLowerCase());
}); });
}, },
handleClick(item, downloadType, event) {
console.log(item.icon_name, downloadType);
if (downloadType === "copy-svg") {
event.preventDefault();
var url =
document.location.protocol +
"//" +
document.location.host +
`/images/` +
item.icon_path +
`.svg`;
fetch(url).then(function (response) {
if (response.ok) {
response.text().then(function (svg) {
navigator.clipboard.writeText(svg);
});
}
});
}
if (downloadType === "copy-cdn") {
event.preventDefault();
var url =
document.location.host + `/images/` + item.icon_path + `.svg`;
navigator.clipboard.writeText(url);
}
},
}; };
} }
</script> </script>

View file

@ -9,6 +9,7 @@ module.exports = {
}, },
variants: { variants: {
scale: ["responsive", "hover", "focus", "group-hover"], scale: ["responsive", "hover", "focus", "group-hover"],
backgroundColor: ["responsive", "hover", "focus", "focus-within"],
}, },
plugins: [ plugins: [
// Some useful comment // Some useful comment

View file

@ -786,10 +786,10 @@ chalk@^2.4.1, chalk@^2.4.2:
escape-string-regexp "^1.0.5" escape-string-regexp "^1.0.5"
supports-color "^5.3.0" supports-color "^5.3.0"
chalk@^4.0.0: "chalk@^3.0.0 || ^4.0.0":
version "4.0.0" version "4.1.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.0.0.tgz#6e98081ed2d17faab615eb52ac66ec1fe6209e72" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a"
integrity sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A== integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==
dependencies: dependencies:
ansi-styles "^4.1.0" ansi-styles "^4.1.0"
supports-color "^7.1.0" supports-color "^7.1.0"
@ -4943,16 +4943,16 @@ svgo@^0.7.0:
sax "~1.2.1" sax "~1.2.1"
whet.extend "~0.9.9" whet.extend "~0.9.9"
tailwindcss@^1.4.5: tailwindcss@^1.6.0:
version "1.4.6" version "1.6.0"
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-1.4.6.tgz#17b37166ccda08d7e7f9ca995ea48ce1e0089700" resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-1.6.0.tgz#cdad8cdd225129ad41bff6aa607aa39ad6524593"
integrity sha512-qV0qInUq1FWih39Bc5CWECdgObSzRrbjGD4ke4kAPSIq6WXrPhv0wwOcUWJgJ66ltT9j+XnSRYikG8WNRU/fTQ== integrity sha512-UZEex5ebsQlCTIBjI0oZITL67HBjOrzMgA4ceLOf8mrBGquLSn7LsO92do1nBSBZBV2Qqpivz9QUwT3zMSQkMA==
dependencies: dependencies:
"@fullhuman/postcss-purgecss" "^2.1.2" "@fullhuman/postcss-purgecss" "^2.1.2"
autoprefixer "^9.4.5" autoprefixer "^9.4.5"
browserslist "^4.12.0" browserslist "^4.12.0"
bytes "^3.0.0" bytes "^3.0.0"
chalk "^4.0.0" chalk "^3.0.0 || ^4.0.0"
color "^3.1.2" color "^3.1.2"
detective "^5.2.0" detective "^5.2.0"
fs-extra "^8.0.0" fs-extra "^8.0.0"