You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/cookbook/editable-svg-icons.md
+32-32Lines changed: 32 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,26 @@
1
-
# Editable SVG Icon Systems
1
+
# 編集可能な SVG アイコンシステム
2
2
3
-
## Base Example
3
+
## 基本的な例
4
4
5
-
There are many ways to create an SVG Icon System, but one method that takes advantage of Vue's capabilities is to create editable inline icons as components. Some of the advantages of this way of working is:
First, we'll create a folder for all of the icons, and name them in a standardized fashion for easy retrieval:
13
+
まず、すべてのアイコンを入れるフォルダを作り、検索しやすいように一定のルールで命名します:
14
14
15
15
-`components/icons/IconBox.vue`
16
16
-`components/icons/IconCalendar.vue`
17
17
-`components/icons/IconEnvelope.vue`
18
18
19
-
Here's an example repo to get you going, where you can see the entire setup: [https://github.com/sdras/vue-sample-svg-icons/](https://github.com/sdras/vue-sample-svg-icons/)
We'll create a base icon (`IconBase.vue`) component that uses a slot.
23
+
スロットを利用した基本となるアイコン(`IconBase.vue`)コンポーネントを作成します。
24
24
25
25
```html
26
26
<template>
@@ -40,9 +40,9 @@ We'll create a base icon (`IconBase.vue`) component that uses a slot.
40
40
</template>
41
41
```
42
42
43
-
You can use this base icon as is- the only thing you might need to update is the `viewBox`depending on the `viewBox`of your icons. In the base, we're making the `width`, `height`, `iconColor`, and name of the icon props so that it can be dynamically updated with props. The name will be used for both the `<title>`content and its `id`for accessibility.
The`currentColor`property that's the default on the fill will make the icon inherit the color of whatever text surrounds it. We could also pass in a different color as a prop if we wish.
Keeping icons in components comes in very handy when you'd like to animate them, especially on an interaction. Inline SVGs have the highest support for interaction of any method. Here's a very basic example of an icon that's animated on click:
We're applying `refs`to the groups of paths we need to move, and as both sides of the scissors have to move in tandem, we'll create a function we can reuse where we'll pass in the `refs`. The use of GreenSock helps resolve animation support and `transform-origin`issues across browser.
Designers may change their minds. Product requirements change. Keeping the logic for the entire icon system in one base component means you can quickly update all of your icons and have it propagate through the whole system. Even with the use of an icon loader, some situations require you to recreate or edit every SVG to make global changes. This method can save you that time and pain.
This type of SVG icon system is really useful when you have a number of icons that are used in different ways throughout your site. If you're repeating the same icon many times on one page (e.g. a giant table with a delete icon in each row), it might make more sense to have all of the sprites compiled into a sprite sheet and use `<use>`tags to load them.
These tools bundle SVGs at compile time, but make them a little harder to edit during runtime, because `<use>`tags can have strange cross-browser issues when doing anything more complex. They also leave you with two nested `viewBox`properties and thus two coordinate systems. This makes the implementation a little more complex.
0 commit comments