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/search

v1.0.2

Published

### 介绍

Downloads

2

Readme

Search 搜索

介绍

用于搜索场景的输入框组件。

引入

import Vue from 'vue';
import Search from '@ophiuchus/search';

Vue.use(Search);

代码演示

基础用法

v-model 用于控制搜索框中的文字,background 可以自定义搜索框外部背景色。

<sf-search v-model="value" placeholder="请输入搜索关键词" />
export default {
  data() {
    return {
      value: '',
    };
  },
};

事件监听

Search 组件提供了 searchcancel 事件,search 事件在点击键盘上的搜索/回车按钮后触发,cancel 事件在点击搜索框右侧取消按钮时触发。

<form action="/">
  <sf-search
    v-model="value"
    show-action
    placeholder="请输入搜索关键词"
    @search="onSearch"
    @cancel="onCancel"
  />
</form>
import Toast  from '@ophiuchus/toast';

export default {
  data() {
    return {
      value: '',
    };
  },
  methods: {
    onSearch(val) {
      Toast(val);
    },
    onCancel() {
      Toast('取消');
    },
  },
};

Tips: 在 sf-search 外层增加 form 标签,且 action 不为空,即可在 iOS 输入法中显示搜索按钮。

搜索框内容对齐

通过 input-align 属性设置搜索框内容的对齐方式,可选值为 centerright

<sf-search
  v-model="value"
  placeholder="请输入搜索关键词"
  input-align="center"
/>

禁用搜索框

通过 disabled 属性禁用搜索框。

<sf-search v-model="value" disabled placeholder="请输入搜索关键词" />

自定义背景色

通过 background 属性可以设置搜索框外部的背景色,通过 shape 属性设置搜索框的形状,可选值为 round

<sf-search
  v-model="value"
  shape="round"
  background="#4fc08d"
  placeholder="请输入搜索关键词"
/>

自定义按钮

使用 action 插槽可以自定义右侧按钮的内容。使用插槽后,cancel 事件将不再触发。

<sf-search
  v-model="value"
  show-action
  label="地址"
  placeholder="请输入搜索关键词"
  @search="onSearch"
>
  <template #action>
    <div @click="onSearch">搜索</div>
  </template>
</sf-search>

API

Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | label | 搜索框左侧文本 | string | - | | shape | 搜索框形状,可选值为 round | string | square | | background | 搜索框外部背景色 | string | #f2f2f2 | | maxlength | 输入的最大字符数 | number | string | - | | placeholder | 占位提示文字 | string | - | | clearable | 是否启用清除图标,点击清除图标后会清空输入框 | boolean | true | | clear-trigger | 显示清除图标的时机,always 表示输入框不为空时展示,focus 表示输入框聚焦且不为空时展示 | string | focus | | autofocus | 是否自动聚焦,iOS 系统不支持该属性 | boolean | false | | show-action | 是否在搜索框右侧显示取消按钮 | boolean | false | | action-text | 取消按钮文字 | boolean | 取消 | | disabled | 是否禁用输入框 | boolean | false | | readonly | 是否将输入框设为只读 | boolean | false | | error | 是否将输入内容标红 | boolean | false | | input-align | 输入框内容对齐方式,可选值为 center right | string | left | | left-icon | 输入框左侧图标名称或图片链接 | string | search | | right-icon | 输入框右侧图标名称或图片链接 | string | - |

Events

| 事件名 | 说明 | 回调参数 | | ------ | -------------------- | ------------------------------ | | search | 确定搜索时触发 | value: string (当前输入的值) | | input | 输入框内容变化时触发 | value: string (当前输入的值) | | focus | 输入框获得焦点时触发 | event: Event | | blur | 输入框失去焦点时触发 | event: Event | | clear | 点击清除按钮后触发 | event: Event | | cancel | 点击取消按钮时触发 | - |

Slots

| 名称 | 说明 | | ---------- | ------------------------------------------------------- | | left | 自定义左侧内容(搜索框外) | | action | 自定义右侧内容(搜索框外),设置show-action属性后展示 | | label | 自定义左侧文本(搜索框内) | | left-icon | 自定义左侧图标(搜索框内) | | right-icon | 自定义右侧图标(搜索框内) |

样式变量

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

| 名称 | 默认值 | 描述 | | -------------------------------- | ------------------ | ---- | | @search-padding | 10px @padding-sm | - | | @search-background-color | @white | - | | @search-content-background-color | @gray-1 | - | | @search-input-height | 34px | - | | @search-label-padding | 0 5px | - | | @search-label-color | @text-color | - | | @search-label-font-size | @font-size-md | - | | @search-left-icon-color | @gray-6 | - | | @search-action-padding | 0 @padding-xs | - | | @search-action-text-color | @text-color | - | | @search-action-font-size | @font-size-md | - |

常见问题

在桌面端点击清除按钮无效?

清除按钮监听是的移动端 Touch 事件,参见桌面端适配