added web component
This commit is contained in:
atisawd 2018-07-07 08:51:13 +05:30
parent 059bdba25e
commit 2a18efb31d
21 changed files with 259 additions and 73 deletions

View file

@ -8,11 +8,9 @@ _High Quality web friendly icons_
'Boxicons' is a carefully designed open source iconset with 700+ icons. It's crafted to look enrich your website/app experience. 'Boxicons' is a carefully designed open source iconset with 700+ icons. It's crafted to look enrich your website/app experience.
_Announcing Boxicons v1.5.1!_ _Announcing Boxicons v1.5.2!_
Solid icons have been added with a seperate logos category Load the icons as web component , load only the icons you need .
You can check out the detailed documentation [here](https://boxicons.com/get-started)
## Installation ## Installation
@ -25,7 +23,7 @@ $ npm install boxicons --save
import the module import the module
```javscript ```javscript
import 'boxicons/css/boxicons.css'; import 'boxicons/dist/boxicons.js';
``` ```
## Usage ## Usage
@ -44,10 +42,10 @@ Instead of installing you may use the remote version
```html ```html
<head> <head>
<link rel="stylesheet" <link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/boxicons@1.5.1/css/boxicons.min.css"> href="https://cdn.jsdelivr.net/npm/boxicons@latest/css/boxicons.min.css">
<!-- or --> <!-- or -->
<link rel="stylesheet" <link rel="stylesheet"
href="https://unpkg.com/boxicons@1.5.1/css/boxicons.min.css"> href="https://unpkg.com/boxicons@latest/css/boxicons.min.css">
</head> </head>
``` ```
@ -59,6 +57,58 @@ Instead of installing you may use the remote version
<i class="bx bxs-hot"></i> <i class="bx bxs-hot"></i>
<i class="bx bxl-facebook-square"></i> <i class="bx bxl-facebook-square"></i>
``` ```
### Using via Web Component
Boxicons includes a Custom Element that makes using icons easy and efficient. To use it, add the `box-icon-element.js` file to the page:
```html
<script src="https://unpkg.com/boxicons@latest/dist/box-icon-element.js"></script>
```
To use an icon, add the `<box-icon>` element to the location where the icon should be displayed:
```html
<box-icon name="hot"></box-icon>
```
To use solid icons or logos add attribute `type` as solid or logo
```html
<box-icon name="hot" type="solid"></box-icon>
<box-icon name="facebook-square" type="logo"></box-icon>
```
The `<box-icon>` custom element supports the following attributes:
```html
<box-icon
name="adjust|alarms|etc...."
color="blue|red|etc..."
size="xs|sm|md|lg|cssSize"
rotate="90|180|270"
flip="horizontal|vertical"
border="square|circle"
animation="spin|tada|etc..."
type = "regular|solid|logo"
pull = "left|right"
></box-icon>
```
- `name` : (REQUIRED) the name of the icon to be displayed
- `color`: A color for the icon.
- `size`: The size for the icon. It supports one of two types of values:
- One of the followign shortcuts: `xs`, `sm`, `md`, `lg`
- A css unit size (ex. `60px`)
- `rotate`: one of the following values: `90`, `180`, `270`
- `flip`: one of the following values: `horizontal`, `vertical`
- `border`: one of the following values: `square`, `circle`
- `animation`: One of the following values: `spin`, `tada`, `flashing`, `burst`, `fade-left`, `fade-right`, `spin-hover`, `tada-hover`, `flashing-hover`, `burst-hover`, `fade-left-hover`, `fade-right-hover`
- `type`: one of the following values: `regular`,`solid`, `logo`
- `pull`: one of the following values: `left`,`right`
The Custom Element class (`BoxIconElement`) exposes the following static members:
- `tagName`: property that holds the HTML element tag name. Default: `box-icon`
- `defined([tagName])`: Defines the Element in the custom element registry using either the tagName provided on input or the (default) the one defined on the Class.
- `cdnUrl`: property that holds the URL that will be used to retrieve the images. URL should point to the folder that contains the images. example: `//unpkg.com/boxicons@1.5.2/svg` (no trailing forward slash)
- `getIconSvg(iconName)`: method used to retrieve the SVG image. Should return a Promise that resolves with the SVG source (String).
[Check out all the icons here!](https://boxicons.com) [Check out all the icons here!](https://boxicons.com)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/boxicons.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -36,7 +36,7 @@
<link rel="stylesheet" <link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/boxicons@1.5.1/css/boxicons.min.css"> href="https://cdn.jsdelivr.net/npm/boxicons@latest/css/boxicons.min.css">
<link rel="shortcut icon" href="static/img/favicon.ico?v=3" > <link rel="shortcut icon" href="static/img/favicon.ico?v=3" >
@ -75,6 +75,6 @@
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="static/dist/bundle.js?v=2" async></script> <script src="static/dist/bundle.js?v=3" async></script>
</body> </body>
</html> </html>

View file

@ -1,6 +1,6 @@
{ {
"name": "boxicons", "name": "boxicons",
"version": "1.5.1", "version": "1.5.2",
"private": true, "private": true,
"description": "High Quality web friendly icons", "description": "High Quality web friendly icons",
"scripts": { "scripts": {

View file

@ -42,13 +42,20 @@ TEMPLATE.innerHTML = `
width: auto; width: auto;
height: auto; height: auto;
} }
:host([pull=left]) #icon {
:host([shape=square]) #icon { float: left;
margin-right: .3em!important;
}
:host([pull=right]) #icon {
float: right;
margin-left: .3em!important;
}
:host([border=square]) #icon {
padding: .25em; padding: .25em;
border: .07em solid rgba(0,0,0,.1); border: .07em solid rgba(0,0,0,.1);
border-radius: .25em; border-radius: .25em;
} }
:host([shape=circle]) #icon { :host([border=circle]) #icon {
padding: .25em; padding: .25em;
border: .07em solid rgba(0,0,0,.1); border: .07em solid rgba(0,0,0,.1);
border-radius: 50%; border-radius: 50%;
@ -74,7 +81,7 @@ export class BoxIconElement extends HTMLElement {
static get cdnUrl() { static get cdnUrl() {
// BUILD.DATA.VERSION is injected by webpack during a build. // BUILD.DATA.VERSION is injected by webpack during a build.
// Value is same as package.json#version property. // Value is same as package.json#version property.
return `//unpkg.com/boxicons@${BUILD.DATA.VERSION}/svg`; return `//unpkg.com/boxicons@latest/svg`;
} }
/** /**
* The html tag name to be use * The html tag name to be use
@ -87,10 +94,12 @@ export class BoxIconElement extends HTMLElement {
'name', 'name',
'color', 'color',
'size', 'size',
'type',
'rotate', 'rotate',
'flip', 'flip',
'animation', 'animation',
'shape', 'border',
'pull'
]; ];
} }
@ -102,8 +111,15 @@ export class BoxIconElement extends HTMLElement {
* *
* @return {Promise<String, Error>} * @return {Promise<String, Error>}
*/ */
static getIconSvg(iconName) { static getIconSvg(iconName,type) {
const iconUrl = `${this.cdnUrl}/${iconName}.svg`; var iconUrl = `${this.cdnUrl}/regular/bx-${iconName}.svg`;
console.log(type);
if(type==='solid'){
iconUrl = `${this.cdnUrl}/solid/bxs-${iconName}.svg`;
}
else if(type==='logo'){
iconUrl = `${this.cdnUrl}/logos/bxl-${iconName}.svg`;
}
if (iconUrl && CACHE[iconUrl]) { if (iconUrl && CACHE[iconUrl]) {
return CACHE[iconUrl]; return CACHE[iconUrl];
} }
@ -140,7 +156,7 @@ export class BoxIconElement extends HTMLElement {
constructor() { constructor() {
super(); super();
this.$ui = this.attachShadow({ mode: 'open' }); this.$ui = this.attachShadow({ mode: 'open' });
//this.$ui.appendChild(this.ownerDocument.importNode(TEMPLATE.content, true)); this.$ui.appendChild(this.ownerDocument.importNode(TEMPLATE.content, true));
if (usingShadyCss()) { if (usingShadyCss()) {
GLOBAL.ShadyCSS.styleElement(this); GLOBAL.ShadyCSS.styleElement(this);
} }
@ -162,6 +178,9 @@ export class BoxIconElement extends HTMLElement {
case 'size': case 'size':
handleSizeChange(this, oldVal, newVal); handleSizeChange(this, oldVal, newVal);
break; break;
case 'type':
handleTypeChange(this, oldVal, newVal);
break;
case 'rotate': case 'rotate':
if (oldVal) { if (oldVal) {
$iconHolder.classList.remove(`${CSS_CLASS_PREFIX_ROTATE}${oldVal}`); $iconHolder.classList.remove(`${CSS_CLASS_PREFIX_ROTATE}${oldVal}`);
@ -202,7 +221,7 @@ function handleNameChange(inst, oldVal, newVal) {
state.$iconHolder.textContent = ''; state.$iconHolder.textContent = '';
if (newVal) { if (newVal) {
inst.constructor.getIconSvg(newVal) inst.constructor.getIconSvg(newVal,state.type)
.then((iconData) => { .then((iconData) => {
if (state.currentName === newVal) { if (state.currentName === newVal) {
state.$iconHolder.innerHTML = iconData; state.$iconHolder.innerHTML = iconData;
@ -213,7 +232,20 @@ function handleNameChange(inst, oldVal, newVal) {
}); });
} }
} }
function handleTypeChange(inst, oldVal, newVal) {
const state = inst._state;
if (state.type) {
state.type = null;
}
if (newVal && (newVal==='solid' || newVal==='logo')) {
state.type = newVal;
}
else{
state.type = 'regular';
}
}
function handleSizeChange(inst, oldVal, newVal) { function handleSizeChange(inst, oldVal, newVal) {
const state = inst._state; const state = inst._state;

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
static/boxicons-1.5.2.zip Normal file

Binary file not shown.

View file

@ -156,7 +156,74 @@
opacity: 0; opacity: 0;
} }
} }
@-webkit-keyframes fade-up
{
0%
{
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 1;
}
75%
{
-webkit-transform: translateY(-20px);
transform: translateY(-20px);
opacity: 0;
}
}
@keyframes fade-up
{
0%
{
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 1;
}
75%
{
-webkit-transform: translateY(-20px);
transform: translateY(-20px);
opacity: 0;
}
}
@-webkit-keyframes fade-down
{
0%
{
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 1;
}
75%
{
-webkit-transform: translateY(20px);
transform: translateY(20px);
opacity: 0;
}
}
@keyframes fade-down
{
0%
{
-webkit-transform: translateY(0);
transform: translateY(0);
opacity: 1;
}
75%
{
-webkit-transform: translateY(20px);
transform: translateY(20px);
opacity: 0;
}
}
@-webkit-keyframes tada @-webkit-keyframes tada
{ {
from from
@ -277,7 +344,26 @@
-webkit-animation: burst 1.5s infinite linear; -webkit-animation: burst 1.5s infinite linear;
animation: burst 1.5s infinite linear; animation: burst 1.5s infinite linear;
} }
.bx-fade-up
{
-webkit-animation: fade-up 1.5s infinite linear;
animation: fade-up 1.5s infinite linear;
}
.bx-fade-up-hover:hover
{
-webkit-animation: fade-up 1.5s infinite linear;
animation: fade-up 1.5s infinite linear;
}
.bx-fade-down
{
-webkit-animation: fade-down 1.5s infinite linear;
animation: fade-down 1.5s infinite linear;
}
.bx-fade-down-hover:hover
{
-webkit-animation: fade-down 1.5s infinite linear;
animation: fade-down 1.5s infinite linear;
}
.bx-fade-left .bx-fade-left
{ {
-webkit-animation: fade-left 1.5s infinite linear; -webkit-animation: fade-left 1.5s infinite linear;

View file

@ -440,10 +440,28 @@ line-height: inherit;
{ {
font-size: 2.25rem!important; font-size: 2.25rem!important;
} }
.bx-fw{
width: 1.2857142857em;
font-size: 1.2857142857em;
height: 0.8em;
line-height: 0.8em;
vertical-align: middle;
margin-top: -0.2em!important;
}
.bx-lg .bx-lg
{ {
font-size: 3.0rem!important; font-size: 3.0rem!important;
} }
.bx-pull-left{
float: left;
margin-right: .3em!important;
}
.bx-pull-right{
float: right;
margin-left: .3em!important;
}
.bx-rotate-90 .bx-rotate-90
{ {
transform: rotate(90deg); transform: rotate(90deg);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -9,7 +9,7 @@ module.exports = {
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, 'dist'),
library: 'BoxIconElement', library: 'BoxIconElement',
libraryTarget: 'umd', libraryTarget: 'umd',
filename: 'box-icon-element.js', filename: 'boxicons.js',
}, },
devtool: 'source-map', devtool: 'source-map',
module: { module: {