Skip to content

Commit

Permalink
feat(menu): initial implement menu component
Browse files Browse the repository at this point in the history
  • Loading branch information
yehuozhili committed May 15, 2020
1 parent 659e369 commit 33a29c7
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 34 deletions.
1 change: 0 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ module.exports = {
},
};


66 changes: 41 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,60 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
# bigbear-ui
bigbear-ui是个人制作的拟物化小型轻量级ui库

## Available Scripts
![npm](https://img.shields.io/npm/v/bigbear-ui)
![npm bundle size](https://img.shields.io/bundlephobia/min/bigbear-ui)
![npm](https://img.shields.io/npm/dt/bigbear-ui)
[![Build Status](https://travis-ci.com/yehuozhili/bigbear-ui.svg?branch=master)](https://travis-ci.com/yehuozhili/bigbear-ui)
[![Coverage Status](https://coveralls.io/repos/github/yehuozhili/bigbear-ui/badge.svg?branch=master)](https://coveralls.io/github/yehuozhili/bigbear-ui?branch=master)

In the project directory, you can run:
✨ 特性

### `npm start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
- 📕 详细的文档与介绍
- 🎨 使用富有特色的Neumorphism拟物化风格
- 📦 开箱即用的高质量 React 组件
- 🔥 使用 TypeScript 开发,提供完整的类型定义文件

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `npm test`
<br/>

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
## 安装
使用 npm 或 yarn 安装

### `npm run build`
```
$ npm install bigbear-ui --save
```

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.
## 引入样式

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!
```
import 'bigbear-ui/dist/index.css';
```

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
## 在线文档

### `npm run eject`
https://yehuozhili.github.io/bigbear-ui/

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
<br/>

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
## 本地文档

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
下载代码,npm安装,使用`npm run storybook`即可获得本地文档。
```
git clone https://github.com/yehuozhili/bigbear-ui.git
npm install
npm run storybook
```

## Learn More
## 制作初衷

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
制作一个属于自己的组件库应该是每个前端人员都有的梦想,有时候自己写出某些好的组件也想记录下来。

To learn React, check out the [React documentation](https://reactjs.org/).

## 仍在开发中

<br/>


组件库仍不完善,处于初级阶段。
2 changes: 1 addition & 1 deletion src/components/Button/button.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Meta, Story, Props ,Preview } from '@storybook/addon-docs/blocks';
import Button from './button';
import SwichButtonType,{FastSwitchBttonType} from './button.example'

<Meta title='Component|Button-按钮组件' component={Button} />
<Meta title='Component|Button 按钮' component={Button} />

<br/>

Expand Down
1 change: 0 additions & 1 deletion src/components/Button/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react";
import { render,fireEvent } from "@testing-library/react";
import Button, { ButtonProps } from './button';


const defaultProps={
onClick:jest.fn()
}
Expand Down
26 changes: 26 additions & 0 deletions src/components/Menu/_style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.bigbear-menu{
display: flex;
flex-wrap: wrap;
padding-left: 0;
list-style: none;
border-bottom:$menu-border-width solid $menu-border-color;
box-shadow: $menu-box-shadow;
.bigbear-menuitem{
padding:$menu-item-padding-y $menu-item-padding-x;
cursor: pointer;
transition: $menu-transition;
&:hover,&:focus{
text-decoration: none;
}
&.isdisabled{
color:$menu-item-disabled-color;
pointer-events: none;
cursor: default;
}
&.isactive,&:hover{
color:$menu-item-active-color;
border-bottom: $menu-item-active-border-width solid $menu-item-active-color;
}
}

}
27 changes: 27 additions & 0 deletions src/components/Menu/menu.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Meta, Story, Props ,Preview } from '@storybook/addon-docs/blocks';
import Menu from './menu';
import MenuItem from './menuitem'

<Meta title='Component|Menu 菜单' component={Menu} />

<br/>

# Menu 菜单
<br/>


<Preview>
<Story name='default' >
<Menu defaultIndex={0} onSelect={(index)=>{console.log(index)}}>
<MenuItem index={0}>item1</MenuItem>
<MenuItem index={1}>item2</MenuItem>
<MenuItem index={2}>item3</MenuItem>
</Menu>

</Story>
</Preview>

<br/>

## 菜单类型 btnType
<br/>
29 changes: 26 additions & 3 deletions src/components/Menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react'
import React, { createContext, useState } from 'react'

import classNames from 'classnames'


type MenuMode='horizontal' | 'vertical'
type SelectCallback =(selectedIndex:number)=>void;

export interface MenuProps{
defaultIndex?:number;
className?:string;
Expand All @@ -13,18 +15,39 @@ export interface MenuProps{
}

const Menu:React.FC<MenuProps>=(props)=>{
const {className,mode,style,children,defaultIndex}=props
const {className,mode,style,children,defaultIndex,onSelect}=props
const [currentActive,setActive]=useState(defaultIndex)
const classes =classNames('bigbear-menu',className,{
'menu-vertical':mode==='vertical'
})
const handleClick=(index:number)=>{
setActive(index)
if(onSelect)onSelect(index)
}
const passedContext:IMenuContext={
index:currentActive?currentActive:0,
onSelect:handleClick
}
return(
<ul className={classes} style={style}>
<MenuContext.Provider value={passedContext}>
{children}
</MenuContext.Provider>
</ul>
)
}

interface IMenuContext{
index:number;
onSelect?:SelectCallback;
}

export const MenuContext = createContext<IMenuContext>({index:0})

Menu.defaultProps={
defaultIndex:0,
mode:'horizontal'
}
export default Menu;
export default Menu;


35 changes: 35 additions & 0 deletions src/components/Menu/menuitem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useContext } from 'react'
import {MenuContext} from './menu'
import classNames from 'classnames'


export interface MenuItemProps{
index:number;
disabled?:boolean;
className?:string;
style?:React.CSSProperties
}





const MenuItem : React.FC<MenuItemProps> =(props)=>{
const {index ,disabled,className,style,children}= props;
const context =useContext(MenuContext)
const classes = classNames('bigbear-menuitem',className,{
'isdisabled':disabled,
'isactive':context.index===index
})
const handleClick=()=>{
if(context.onSelect&&!disabled){
context.onSelect(index)
}
}
return (
<li className={classes} style={style} onClick={handleClick}>
{children}
</li>
)
}
export default MenuItem
31 changes: 29 additions & 2 deletions src/stories/Welcome.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
<Meta title='Introduction|bigbear-ui'/>

# bigbear-ui
- bigbear-ui是个人制作的拟物化小型轻量级ui库
bigbear-ui是个人制作的拟物化小型轻量级ui库

![npm](https://img.shields.io/npm/v/bigbear-ui)
![npm bundle size](https://img.shields.io/bundlephobia/min/bigbear-ui)
![npm](https://img.shields.io/npm/dt/bigbear-ui)
[![Build Status](https://travis-ci.com/yehuozhili/bigbear-ui.svg?branch=master)](https://travis-ci.com/yehuozhili/bigbear-ui)
[![Coverage Status](https://coveralls.io/repos/github/yehuozhili/bigbear-ui/badge.svg?branch=master)](https://coveralls.io/github/yehuozhili/bigbear-ui?branch=master)


<Subtitle>✨ 特性</Subtitle>
Expand All @@ -29,6 +35,27 @@ $ npm install bigbear-ui --save
import 'bigbear-ui/dist/index.css';
```

也可以只引入样式,不引入js,在您的组件里加上相应的类名,便会有效果了。
## 在线文档

https://yehuozhili.github.io/bigbear-ui/

<br/>

## 本地文档

下载代码,npm安装,使用`npm run storybook`即可获得本地文档。
```
git clone https://github.com/yehuozhili/bigbear-ui.git
npm install
npm run storybook
```

## 制作初衷

制作一个属于自己的组件库应该是每个前端人员都有的梦想,有时候自己写出某些好的组件也想记录下来。

<br/>

## 仍在开发中

组件库仍不完善,处于初级阶段。
6 changes: 5 additions & 1 deletion src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
@import "reboot";

//button
@import "../components/Button/style"
@import "../components/Button/style";


//menu
@import "../components/Menu/style";

0 comments on commit 33a29c7

Please sign in to comment.