🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@_nu/react-button

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@_nu/react-button

NU 「 no-ui 」 组件库系统 nu-system,按钮组件 React 实现

Source
npmnpm
Version
0.0.4
Version published
Weekly downloads
39
-15.22%
Maintainers
1
Weekly downloads
 
Created
Source

nu-react-button

npm package

这是 NU 「 no-ui 」 组件库系统 nu-system,按钮组件 React 实现。

怎么用?

yarn add @_nu/react-button @_nu/vanilla-button

二次封装

/* @components/Button/index.js */
import NuButton from "@_nu/react-button";
import "@_nu/vanilla-button";     // 样式组件
import "@_nu/vanilla-button/css/skins/bootstrap.css"; // bootstrap 皮肤 
// import './style.css'; // 你自定义的css样式
NuButton.defaultProps.color = "primary";  // 自定义默认颜色
NuButton.defaultProps.variant = "ghost";  // 自定义默认变体
export default NuButton;

因为 NuButton 是纯逻辑组件本身不会输出任何样式,在实际项目中使用需要二次封装。 这里采用的是 nu-button 里面的 bootstrap 皮肤。

使用

import Button from "./components/Button";

const Page=()=>{    
    return (
     <div>
        <Button ghost large>一个大的幽灵按钮</Button>                
        <Button href="/nu-button" ghost large>一个大的幽灵主按钮</Button>
     </div>     
    );
};

export default Page;

DOM 结构

<Button>hello</Button>
<Button href="." title="hello">hello</Button>

上面的代码会被渲染成如下的 HTML 结构。

<button class="nu_button" type="button" ><span>hello</span></button>
<a class="nu_button" href="." title="hello"><span>hello</span></a>

Api

props类型默认值功能
baseClassstring'nu_btn'按钮默认选择器
hrefstring-跳转链接
typestring'button'按钮类型
componentstring | func | object'button'外壳组件
disabledboolean-不可用按钮
loadingboolean-loading按钮
capsuleboolean-圆角按钮
circleboolean-正圆按钮
blockboolean-占一行的按钮
color'default' | 'primary' | 'secondary'
'warning' | 'success' | 'danger'
'default'按钮颜色
primaryboolean-主按钮
secondaryboolean-次级按钮
warningboolean-警告按钮
successboolean-成功按钮
dangerboolean-危险按钮
variant'fill' | 'ghost' | 'link''fill'按钮变体
fillboolean-实心按钮
ghostboolean-幽灵按钮
linkboolean-链接按钮
largeboolean-大按钮
middleboolean-中号按钮
smallboolean-小按钮

并且除了上表中的属性,其它属性都会直接传到原生 button 上。

如何配合路由组件使用

import { Link } from "@reach/router";
import NuButton from "@y-fe/nu-button-react";
import "@y-fe/nu-button";
import './style.css';

// 自定义标签
NuButton.defaultProps.component = Link;

export default NuButton;

如何修改样式?

nu-button-react 会将上所有的 boolean 属性,基于以下的 「 class 映射表 」添加对应的 class 到按钮上。

想要自定义样式,只需要围绕对应选择器进行开发即可, 样式定义规则可以查看 nu-button

propsclass
baseClass.nu_btn
primary._primary
secondary._secondary
warning._warning
success._success
danger._danger
fill._fill
ghost._ghost
link._link
disabled._disabled
loading._loading
large._large
middle._middle
small._small
capsule._capsule
block._block

Keywords

react-component

FAQs

Package last updated on 30 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts