Skip to content

Commit

Permalink
feat(src): change style and add alert message component
Browse files Browse the repository at this point in the history
  • Loading branch information
yehuozhili committed May 21, 2020
1 parent 2094eba commit 21590e7
Show file tree
Hide file tree
Showing 37 changed files with 892 additions and 118 deletions.
15 changes: 13 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ addParameters({
theme: create({
brandTitle: 'BigBear-UI',
brandUrl: 'https://github.com/yehuozhili/bigbear-ui'
})
}),
},
dependencies: {
withStoriesOnly: true,
hideEmpty: true,
}
});
const loaderFn = () => {
return [
require('../src/stories/Welcome.stories.mdx'),
require('../src/components/Button/button.stories.mdx')
require('../src/components/Button/button.stories.mdx'),
require('../src/components/Alert/alert.stories.mdx'),
require('../src/components/Menu/menu.stories.mdx'),
require('../src/components/Menu/menuitem.stories.mdx'),
require('../src/components/Menu/submenu.stories.mdx'),
require('../src/components/Icon/icon.stories.mdx'),
require('../src/components/Transition/transition.stories.mdx'),
require('../src/components/Message/message.stories.mdx'),
]
}
configure(loaderFn, module);
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"module": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"classnames": "^2.2.6"
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
"@fortawesome/react-fontawesome": "^0.1.9",
"classnames": "^2.2.6",
"react-transition-group": "^4.4.1"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand All @@ -43,11 +47,12 @@
"test:nowatch": "cross-env CI=true react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 9009 -s public --docs",
"storybook-nodoc": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook --no-dll --quiet --docs",
"build-ts": "tsc -p tsconfig.build.json",
"build-css": "node-sass ./src/styles/index.scss ./dist/index.css",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"prepublishOnly": "npm run test:nowatch & npm run lint & npm run build"
"prepublishOnly": "npm run test:nowatch & npm run lint & npm run build & npm run changelog"
},
"eslintConfig": {
"extends": "react-app"
Expand Down Expand Up @@ -84,6 +89,7 @@
"@types/node": "^12.12.38",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.7",
"@types/react-transition-group": "^4.2.4",
"coveralls": "^3.1.0",
"cross-env": "^7.0.2",
"cz-conventional-changelog": "^3.2.0",
Expand Down
27 changes: 27 additions & 0 deletions src/components/Alert/_style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.bigbear-alert{
display: flex;
justify-content: center;
flex-direction: column;
position: relative;
padding:10px;
>span{
&:nth-child(1){
font-size: $font-size-lg;
font-weight: $font-weight-bold;
}
svg{
margin-right: 10px;
}
}
>button{
position:absolute;
right:0;
top:0
}
}
@each $key,$val in $theme-colors{
.bigbear-alert-#{$key}{
color:#{nth($val,2)};
@include neufactory-noactive(nth($val,1),nth($val,3),nth($val,4));
}
}
74 changes: 74 additions & 0 deletions src/components/Alert/alert.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Meta, Story, Props ,Preview } from '@storybook/addon-docs/blocks';
import Alert from './alert';
import Icon from '../Icon'

<Meta title='Component|Alert 提示框' component={Alert} />

<br/>

# Alert 提示框
<br/>

## 基本用法

<Preview>
<Story name='alert'>
<Alert title='我是标题'/>
</Story>
</Preview>

## close 与 type

<Preview>
<Story name='alert2'>
<Alert title='我是标题' close={true} type='light'/>
</Story>
<Story name='alert3'>
<Alert title='我是标题' close={true} type="danger" />
</Story>
</Preview>

<Preview>
<Story name='alert6'>
<Alert title='我是标题' close={true} type='info'/>
</Story>
<Story name='alert5'>
<Alert title='我是标题' close={true} type="warning" className='extra class' />
</Story>
</Preview>

## 带图标使用

<Preview>
<Story name='alert7'>
<Alert title='我是标题' close={true} type='dark' icon={<Icon icon='info-circle' theme='light'></Icon>}/>
</Story>
<Story name='alert8'>
<Alert title='我是标题' close type="secondary" className='extra class' icon={<Icon icon='question-circle' theme='light'></Icon>} />
</Story>
</Preview>

## description 描述

<Preview>
<Story name='alert4'>
<Alert title='我是标题' close={true} type='light'
description ='我是长文字我是长文字我是长文字
我是长文字我是长文字我是长文字我是长文字我是
长文字我是长文字我是长文字我是长文字我是
长文字我是长文字我是长文
字我是长文字我是长文字我是长文字我是长
文字我是长文字我是长文字我是长文字
我是长文字我是长文字我是长文字我是长文字我是
长文字我是长文字我是长文字我是长文字我是
长文字我是长文字我是长文
字我是长文字我是长文字我是长文字我是长
文字我是长文字我是长文字我是长文字
'


/>
</Story>
</Preview>

<Props of={Alert} />
77 changes: 73 additions & 4 deletions src/components/Alert/alert.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,79 @@
import React from 'react'
import React, { FC, useState, useEffect, ReactNode } from 'react'
import classNames from 'classnames';
import Button from '../Button';
import Icon from '../Icon';
import Transition from '../Transition';
import { AnimationName } from '../Transition/transition';


const Alert = function(){
export interface AlertProps{
/** 标题 */
title?:string;
/** 类型*/
type?:'primary' | 'default' | 'danger'|'secondary'|'success'|'info'|'light'|'warning'|'dark'
/**是否有关闭按钮*/
close?:boolean;
/** 内容*/
description?:string|null;
/** 动画方向 */
directions?:'left'|'top'|'right'|'bottom';
/** 自动关闭延时时间,0表示不自动关闭 */
autoclosedelay?:number,
/** 额外类名 */
className?:string,
/** 图标 */
icon?:ReactNode;
/**启用开场动画 */
initAnimate?:boolean,
/**是否套一层div */
wrapper?:boolean;
}

export const Alert:FC<AlertProps> = function(props:AlertProps){
const {title,type,description,directions,autoclosedelay,className,initAnimate,wrapper}=props
const classes = classNames('bigbear-alert',`bigbear-alert-${type}`,className?className:'')
const [state,setState]=useState(!initAnimate)
useEffect(()=>{
if(initAnimate){
setState(true)
}
if(autoclosedelay){
setTimeout(() => {
setState(false)
}, autoclosedelay);
}
},[autoclosedelay,initAnimate])
return(
<div>xx</div>
<Transition in={state} animation={`zoom-in-${directions}` as AnimationName}
timeout={300} wrapper={wrapper} >
<div className={classes} >

<span>
{
props.icon&&props.icon
}
{title}</span>
{
description&&<span>{description}</span>
}
{
props.close&&<Button btnType={type} onClick={()=>setState(false)}><Icon icon='times'></Icon></Button>

}
</div>
</Transition>
)
}

export default Alert
Alert.defaultProps={
title:'',
type:'default',
close:false,
description:null,
directions:'top',
autoclosedelay:0,
initAnimate:false,
wrapper:false
}

export default Alert;
2 changes: 2 additions & 0 deletions src/components/Alert/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Alert from './alert'
export default Alert;
21 changes: 10 additions & 11 deletions src/components/Button/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
vertical-align: middle;
background-image: none;
border:$btn-border-width solid transparent;
box-shadow: $btn-box-shadow;

cursor: pointer;
transition: $btn-transition;
@include button-size($btn-padding-x,$btn-padding-y,$btn-font-size,$border-radius);
Expand All @@ -23,6 +23,7 @@
}
}
//size

.btn-size-lg{
@include button-size($btn-padding-x-lg,$btn-padding-y-lg,$btn-font-size-lg,$border-radius-lg)
}
Expand All @@ -33,35 +34,33 @@
@include button-size($btn-padding-x,$btn-padding-y,$btn-font-size,$border-radius)
}
//type
.btn-type-primary{
@include button-style($primary,$primary,$white)
}
.btn-type-danger{
@include button-style($danger,$danger,$white)
}
.btn-type-default{
@include button-style($white,$gray-4,$gray-7,$white,$primary,$primary)
@each $key,$val in $theme-colors{
.btn-type-#{$key}{
@include button-style(nth($val, 1),nth($val,2));
@include neufactory(nth($val, 1),nth($val,3),nth($val,4))
}
}

.btn-type-link{
font-weight: $font-weight-base;
color: $btn-link-color;
text-decoration: $link-decoration;
box-shadow: none;
border:1px dashed lighten($btn-link-color,10%);
@include neufactory($white, $neu-whiteshadow1,$neu-whiteshadow2);
&:hover{
color: $btn-link-hover-color;
text-decoration: $link-hover-decoration;
border:1px dashed lighten( $btn-link-hover-color,10%);
}
&:focus{
text-decoration: $link-hover-decoration;
border:1px dashed lighten( $btn-link-hover-color,10%);
}
&.disabled{
color:$btn-link-disabled-color;
pointer-events: none;
}
}

.btn-type-neu-w-up{
font-weight: $font-weight-bold;
color: $gray-9;
Expand Down
2 changes: 2 additions & 0 deletions src/components/Button/button.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export function NeuWclick(props:PropsWithChildren<{callback:()=>void,style?:CSSP
if(ref){
ref.current.addEventListener('mousedown',downReplace)
ref.current.addEventListener('mouseup',upReplace)
ref.current.addEventListener('mouseleave',upReplace)
}
return()=>{
ref.current?.removeEventListener('mouseup',upReplace);
ref.current?.removeEventListener('mousedown',downReplace)
ref.current?.removeEventListener('mouseleave',downReplace)
}
}
return (
Expand Down
29 changes: 26 additions & 3 deletions 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 NeuWdown,{NeuWclick,Ringclick} from './button.example'

<Meta title='Component|Button 按钮' component={Button} sort={1}/>
<Meta title='Component|Button 按钮' component={Button} />

<br/>

Expand All @@ -15,16 +15,35 @@ import NeuWdown,{NeuWclick,Ringclick} from './button.example'
## 按钮类型 btnType
<br/>

<Preview>
<Preview >
<Story name='default' >
<Button btnType='default' >default</Button>
</Story>
<Story name='primary' >
<Story name='primary' >
<Button btnType='primary'>primary</Button>
</Story>
<Story name='danger'>
<Button btnType='danger'>danger</Button>
</Story>
<Story name='warning'>
<Button btnType='warning'>warning</Button>
</Story>
<Story name='info'>
<Button btnType='info'>info</Button>
</Story>
<Story name='secondary'>
<Button btnType='secondary'>secondary</Button>
</Story>
<Story name='success'>
<Button btnType='success'>success</Button>
</Story>
<Story name='light'>
<Button btnType='light'>light</Button>
</Story>
<Story name='dark'>
<Button btnType='dark'>dark</Button>
</Story>

<Story name='link'>
<Button btnType='link'>link</Button>
</Story>
Expand Down Expand Up @@ -158,6 +177,8 @@ import NeuWdown,{NeuWclick,Ringclick} from './button.example'
## 类型结合示例 example
<br/>

有些时候,可能只需要类名进行状态切换,或者做一些特别效果,需要自行封装,下面是一些效果封装方法。

#### 点击切换按钮类型 click ⬇

<Preview>
Expand Down Expand Up @@ -199,10 +220,12 @@ export function NeuWclick(props:PropsWithChildren<{callback:()=>void,style?:CSSP
if(ref){
ref.current.addEventListener('mousedown',downReplace)
ref.current.addEventListener('mouseup',upReplace)
ref.current.addEventListener('mouseleave',upReplace)
}
return()=>{
ref.current?.removeEventListener('mouseup',upReplace);
ref.current?.removeEventListener('mousedown',downReplace)
ref.current?.removeEventListener('mouseleave',downReplace)
}
}
return (
Expand Down
Loading

0 comments on commit 21590e7

Please sign in to comment.