-
-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
affects: @varlet/cli, @varlet/ui
- Loading branch information
Showing
12 changed files
with
527 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# Icon | ||
|
||
### Intro | ||
```html | ||
Font based icon library, also support web images. | ||
``` | ||
Font icons are from [Material Design Icon](https://materialdesignicons.com/) | ||
|
||
### Install | ||
|
||
```js | ||
import { createApp } from 'vue'; | ||
import { Icon } from '@varlet/ui'; | ||
|
||
createApp().use(Icon) | ||
``` | ||
|
||
### Icon Size | ||
|
||
```html | ||
<var-icon name="checkbox-marked-circle" /> | ||
<var-icon name="checkbox-marked-circle" :size="26"/> | ||
``` | ||
|
||
### Icon Color | ||
|
||
```html | ||
<var-icon name="checkbox-marked-circle" color="#2979ff" /> | ||
<var-icon name="checkbox-marked-circle" color="#2979ff" :size="26"/> | ||
``` | ||
|
||
### Use Image | ||
|
||
```html | ||
When the name passed in is a URL the img tag is displayed in cover mode. | ||
Size is the width and height of the image. | ||
``` | ||
|
||
```html | ||
<var-icon name="https://varlet-ui.github.io/cat.jpg" :size="32" /> | ||
``` | ||
|
||
### Events | ||
|
||
```html | ||
<var-icon | ||
name="checkbox-marked-circle" | ||
color="#2979ff" | ||
@click="() => Snackbar.success('Click success')" | ||
/> | ||
``` | ||
|
||
```js | ||
import { Snackbar } from '@varlet/ui' | ||
|
||
export default { | ||
setup() { | ||
return { Snackbar } | ||
}, | ||
} | ||
``` | ||
|
||
### Icon Animation | ||
|
||
```html | ||
When Transition (MS) is set and the icon is toggled by its name, trigger a toggle animation。 | ||
``` | ||
|
||
```html | ||
<var-icon color="#2979ff" :name="name" :transition="300" :size="30" /> | ||
``` | ||
|
||
```js | ||
export default { | ||
setup() { | ||
const name = ref('information') | ||
|
||
const toggle = () => { | ||
name.value = name.value === 'information' | ||
? 'checkbox-marked-circle' | ||
: 'information' | ||
} | ||
|
||
return { | ||
name, | ||
toggle | ||
} | ||
}, | ||
} | ||
``` | ||
|
||
### Custom Icons | ||
```html | ||
First you need to set up your own font and install it into your project. | ||
Let's assume that we extend a font named my-icons. | ||
``` | ||
|
||
```css | ||
/* Set the font */ | ||
@font-face { | ||
font-family: "my-icons"; | ||
src: url("https://xxx.my-icons.eot"); | ||
src: url("https://xxx.my-icons.eot") format("embedded-opentype"), | ||
url("https://xxx.my-icons.woff2") format("woff2"), | ||
url("https://xxx.my-icons.woff") format("woff"), | ||
url("https://xxx.my-icons.ttf") format("truetype"); | ||
font-weight: normal; | ||
font-style: normal; | ||
} | ||
|
||
/* Font style */ | ||
.my-icon--set, | ||
.my-icon--set::before { | ||
position: relative; | ||
display: inline-block; | ||
font: normal normal normal 14px/1 "my-icons"; | ||
font-size: inherit; | ||
text-rendering: auto; | ||
-webkit-font-smoothing: antialiased; | ||
} | ||
|
||
/* Font names map code points */ | ||
.my-icon-hot::before { | ||
content: "\F000"; | ||
} | ||
``` | ||
|
||
```html | ||
Here you have successfully extended your icon library. | ||
So my-icon is your font namespace. | ||
You can use it this way: | ||
<var-icon namespace="my-icon" name="hot" /> | ||
``` | ||
|
||
## API | ||
|
||
### Props | ||
|
||
| Prop | Description | Type | Default | | ||
| --- | --- | --- | --- | | ||
| `name` | icon name | _string_ | `-` | | ||
| `size` | icon size | _string \| number_ | `-` | | ||
| `color` | icon color, Only applies to font icons | _string_ | `-` | | ||
| `namespace` | Icon namespace, extensible custom icon library | _string_ | `var-icon` | | ||
| `transition` | Transition animation time(ms) | _string \| number_ | `0` | | ||
|
||
### Events | ||
|
||
| Event | Description | Arguments | | ||
| --- | --- | --- | | ||
| `click` | Triggered when you click on the icon | `event: Event` | | ||
|
||
### Theme Variables | ||
#### The following LESS variables can be overridden at build time to modify the theme style | ||
|
||
| Variable | Default | | ||
| --- | --- | | ||
| `@icon-size` | `20px` | |
Oops, something went wrong.