aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/svg.js
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-03-14 12:09:06 +0800
committerGitHub <noreply@github.com>2023-03-14 12:09:06 +0800
commite82f1b15c7120ad13fd3b67cf7e2c6cb9915c22d (patch)
tree1da00ac20e4f62bf55bbf68e914d27cd1920a5d6 /web_src/js/svg.js
parentb942838bd486f5d3919a14a128efe22fc55c6112 (diff)
downloadgitea-e82f1b15c7120ad13fd3b67cf7e2c6cb9915c22d.tar.gz
gitea-e82f1b15c7120ad13fd3b67cf7e2c6cb9915c22d.zip
Refactor dashboard repo list to Vue SFC (#23405)
Similar to #23394 The dashboard repo list mixes jQuery/Fomantic UI/Vue together, it's very diffcult to maintain and causes unfixable a11y problems. This PR uses two steps to refactor the repo list: 1. move `data-` attributes to JS object and use Vue data as much as possible https://github.com/go-gitea/gitea/pull/23405/commits/d3adc0dcacf7de87b9819277e6598ac3993bbfa3 2. move the code into a Vue SFC https://github.com/go-gitea/gitea/pull/23405/commits/7ebe55df6e67adfd272a4bf0a96ad6688edf661f Total: +516 −585 Screenshots: <details> ![image](https://user-images.githubusercontent.com/2114189/224271457-a23e05be-d7d3-4247-a803-f0ee30c36f44.png) ![image](https://user-images.githubusercontent.com/2114189/224271504-76fbd3da-4d7a-4725-b0d1-fbff83caac63.png) ![image](https://user-images.githubusercontent.com/2114189/224271845-f007cadf-6c49-46bd-a65c-a3fc75bdba3b.png) </details> --------- Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Diffstat (limited to 'web_src/js/svg.js')
-rw-r--r--web_src/js/svg.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/web_src/js/svg.js b/web_src/js/svg.js
index 6476f16bfb..9eabca3fd3 100644
--- a/web_src/js/svg.js
+++ b/web_src/js/svg.js
@@ -31,8 +31,17 @@ import octiconSkip from '../../public/img/svg/octicon-skip.svg';
import octiconMeter from '../../public/img/svg/octicon-meter.svg';
import octiconBlocked from '../../public/img/svg/octicon-blocked.svg';
import octiconSync from '../../public/img/svg/octicon-sync.svg';
+import octiconFilter from '../../public/img/svg/octicon-filter.svg';
+import octiconPlus from '../../public/img/svg/octicon-plus.svg';
+import octiconSearch from '../../public/img/svg/octicon-search.svg';
+import octiconArchive from '../../public/img/svg/octicon-archive.svg';
+import octiconStar from '../../public/img/svg/octicon-star.svg';
+import giteaDoubleChevronLeft from '../../public/img/svg/gitea-double-chevron-left.svg';
+import giteaDoubleChevronRight from '../../public/img/svg/gitea-double-chevron-right.svg';
+import octiconChevronLeft from '../../public/img/svg/octicon-chevron-left.svg';
+import octiconOrganization from '../../public/img/svg/octicon-organization.svg';
-export const svgs = {
+const svgs = {
'octicon-blocked': octiconBlocked,
'octicon-check-circle-fill': octiconCheckCircleFill,
'octicon-chevron-down': octiconChevronDown,
@@ -66,14 +75,25 @@ export const svgs = {
'octicon-triangle-down': octiconTriangleDown,
'octicon-x': octiconX,
'octicon-x-circle-fill': octiconXCircleFill,
+ 'octicon-filter': octiconFilter,
+ 'octicon-plus': octiconPlus,
+ 'octicon-search': octiconSearch,
+ 'octicon-archive': octiconArchive,
+ 'octicon-star': octiconStar,
+ 'gitea-double-chevron-left': giteaDoubleChevronLeft,
+ 'gitea-double-chevron-right': giteaDoubleChevronRight,
+ 'octicon-chevron-left': octiconChevronLeft,
+ 'octicon-organization': octiconOrganization,
};
+// TODO: use a more general approach to access SVG icons. At the moment, developers must check, pick and fill the names manually, most of the SVG icons in assets couldn't be used directly.
+
const parser = new DOMParser();
const serializer = new XMLSerializer();
-// retrieve a HTML string for given SVG icon name, size and additional classes
+// retrieve an HTML string for given SVG icon name, size and additional classes
export function svg(name, size = 16, className = '') {
- if (!(name in svgs)) return '';
+ if (!(name in svgs)) throw new Error(`Unknown SVG icon: ${name}`);
if (size === 16 && !className) return svgs[name];
const document = parser.parseFromString(svgs[name], 'image/svg+xml');