npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ophiuchus/badge

v1.0.1

Published

### 介绍

Downloads

2

Readme

Badge 徽标

介绍

在右上角展示徽标数字或小红点。

引入

import Vue from 'vue';
import Badge from '@ophiuchus/badge';

Vue.use(Badge);

代码演示

基础用法

设置 content 属性后,Badge 会在子元素的右上角显示对应的徽标,也可以通过 dot 来显示小红点。

<sf-badge :content="5">
  <div class="child" />
</sf-badge>
<sf-badge :content="10">
  <div class="child" />
</sf-badge>
<sf-badge content="Hot">
  <div class="child" />
</sf-badge>
<sf-badge dot>
  <div class="child" />
</sf-badge>

<style>
  .child {
    width: 40px;
    height: 40px;
    background: #f2f3f5;
    border-radius: 4px;
  }
</style>

最大值

设置 max 属性后,当 content 的数值超过最大值时,会自动显示为 {max}+

<sf-badge :content="20" max="9">
  <div class="child" />
</sf-badge>
<sf-badge :content="50" max="20">
  <div class="child" />
</sf-badge>
<sf-badge :content="200" max="99">
  <div class="child" />
</sf-badge>

自定义颜色

通过 color 属性来设置徽标的颜色。

<sf-badge :content="5" color="#1989fa">
  <div class="child" />
</sf-badge>
<sf-badge :content="10" color="#1989fa">
  <div class="child" />
</sf-badge>
<sf-badge dot color="#1989fa">
  <div class="child" />
</sf-badge>

自定义徽标内容

通过 content 插槽可以自定义徽标的内容,比如插入一个图标。

<sf-badge>
  <div class="child" />
  <template #content>
    <sf-icon name="success" class="badge-icon" />
  </template>
</sf-badge>
<sf-badge>
  <div class="child" />
  <template #content>
    <sf-icon name="cross" class="badge-icon" />
  </template>
</sf-badge>
<sf-badge>
  <div class="child" />
  <template #content>
    <sf-icon name="ellipsis" class="badge-icon" />
  </template>
</sf-badge>
.badge-icon {
  display: block;
  font-size: 10px;
  line-height: 16px;
}

独立展示

当 Badge 没有子元素时,会作为一个独立的元素进行展示。

<sf-badge :content="20" />

<sf-badge :content="200" max="99" />

API

Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | content | 徽标内容 | number | string | - | | color | 徽标背景颜色 | string | #ee0a24 | | dot | 是否展示为小红点 | boolean | false | | max | 最大值,超过最大值会显示 {max}+,仅当 content 为数字时有效 | number | string | - |

Slots

| 名称 | 说明 | | ------- | ---------------- | | default | 徽标包裹的子元素 | | content | 自定义徽标内容 |

样式变量

组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制

| 名称 | 默认值 | 描述 | | --- | --- | --- | | @badge-size | 16px | - | | @badge-color | @white | - | | @badge-padding | 0 3px | - | | @badge-font-size | @font-size-sm | - | | @badge-font-weight | @font-weight-bold | - | | @badge-border-width | @border-width-base | - | | @badge-background-color | @red | - | | @badge-dot-color | @red | - | | @badge-dot-size | 8px | - | | @badge-font-family | -apple-system-font, Helvetica Neue, Arial, sans-serif | - |