Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
fix: 修复部分组件无法传递颜色和size
Browse files Browse the repository at this point in the history
  • Loading branch information
Summer-andy committed Dec 21, 2019
1 parent 404618a commit f34e347
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 59 deletions.
6 changes: 4 additions & 2 deletions README-zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { BoxLoading } from 'react-loadingg';
| 组件 | color | speed | size | style |
| -------------------- | ----- | ----- | ----- | ----- |
| BabelLoading |||||
| BlockLoading | 🚧 ||||
| BlockLoading | ||||
| BlockReserveLoading |||||
| BoxLoading |||||
| CircleLoading |||||
Expand All @@ -77,8 +77,10 @@ import { BoxLoading } from 'react-loadingg';
| RollBoxLoading |||||
| RectGraduallyShowLoading |||||
| PointSpreadLoading |||||
| ThreeHorseLoading ||| 🚧 ||
| ThreeHorseLoading ||| ||
| PassThrouthLoading |||||
| CoffeeLoading |||||
| BatteryLoading |||||
#### ⌨️ 组件开发

首次运行项目
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { BoxLoading } from 'react-loadingg';
| components | color | speed | size | style |
| -------------------- | ----- | ----- | ----- | ----- |
| BabelLoading |||||
| BlockLoading | 🚧 ||||
| BlockLoading | ||||
| BlockReserveLoading |||||
| BoxLoading |||||
| CircleLoading |||||
Expand All @@ -79,8 +79,10 @@ import { BoxLoading } from 'react-loadingg';
| RollBoxLoading |||||
| RectGraduallyShowLoading |||||
| PointSpreadLoading |||||
| ThreeHorseLoading ||| 🚧 ||
| ThreeHorseLoading ||| ||
| PassThrouthLoading |||||
| CoffeeLoading |||||
| BatteryLoading |||||
#### ⌨️ Participate in development

Running the project for the first time
Expand Down
34 changes: 34 additions & 0 deletions src/components/BatteryLoading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import styled, { keyframes } from 'styled-components';
import { commonStyle, sizeContainer } from '../utils/style';
const changeSharp = (color, size) => keyframes`
0%{box-shadow: inset 0px 0px 0px ${color};}
100%{box-shadow: inset ${size} 0px 0px ${color}}
`;

const LoadContainer = styled.div`
width: ${props => sizeContainer[props.size] || sizeContainer['default']};
height: 14px;
border: 1px #fff solid;
border-radius: 2px;
position: relative;
animation: ${props =>
changeSharp(props.color || '#00adb5', sizeContainer[props.size] || sizeContainer['default'])}
${props => props.speed || 4}s linear infinite;
&::after {
width: 2px;
height: 7px;
background-color: #fff;
border-radius: 0px 1px 1px 0px;
position: absolute;
content: '';
top: 2px;
right: -4px;
}
`;

const BatteryLoading = ({ style = commonStyle, color, size = 'default', speed }) => {
return <LoadContainer style={style} color={color} size={size} speed={speed}></LoadContainer>;
};

export default BatteryLoading;
38 changes: 19 additions & 19 deletions src/components/BlockLoading/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,74 +19,74 @@ const Rotate = keyframes`
}
`;

const animateFirst = keyframes`
const animateFirst = color => keyframes`
0% {
background: ${$InColor};
}
25% {
background: ${$color};
background: ${color};
}
50% {
background: ${$color};
background: ${color};
}
75% {
background: ${$color};
background: ${color};
}
100% {
background: ${$InColor};
}
`

const animateTwo = keyframes`
const animateTwo = color => keyframes`
0% {
background: ${$color};
background: ${color};
}
25% {
background: ${$InColor};
}
50% {
background: ${$color};
background: ${color};
}
75% {
background: ${$color};
background: ${color};
}
100% {
background: ${$color};
background: ${color};
}
`

const animateThree = keyframes`
const animateThree = color => keyframes`
0% {
background: ${$color};
background: ${color};
}
25% {
background: ${$color};
background: ${color};
}
50% {
background: ${$InColor};
}
75% {
background: ${$color};
background: ${color};
}
100% {
background: ${$color};
background: ${color};
}
`
const animateFour = keyframes`
const animateFour = color => keyframes`
0% {
background: ${$color};
background: ${color};
}
25% {
background: ${$color};
background: ${color};
}
50% {
background: ${$color};
background: ${color};
}
75% {
background: ${$InColor};
}
100% {
background: ${$color};
background: ${color};
}
`

Expand Down
8 changes: 4 additions & 4 deletions src/components/BlockLoading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ const Item = styled.div`
`;

const ItemFirst = styled(Item)`
animation: ${animateFirst} ${props => props.speed / 4 || 2}s infinite ease-in-out;
animation: ${props => animateFirst(props.color || '#00adb5')} ${props => props.speed / 4 || 2}s infinite ease-in-out;
`;

const ItemTwo = styled(Item)`
animation: ${animateTwo} ${props => props.speed / 4 || 2}s infinite ease-in-out;
animation: ${props => animateTwo(props.color || '#00adb5')} ${props => props.speed / 4 || 2}s infinite ease-in-out;
`;

const ItemThree = styled(Item)`
animation: ${animateThree} ${props => props.speed / 4 || 2}s infinite ease-in-out;
animation: ${ props => animateThree(props.color || '#00adb5')} ${props => props.speed / 4 || 2}s infinite ease-in-out;
`;

const ItemFour = styled(Item)`
animation: ${animateFour} ${props => props.speed / 4 || 2}s infinite ease-in-out;
animation: ${ props => animateFour(props.color || '#00adb5')} ${props => props.speed / 4 || 2}s infinite ease-in-out;
`;

const BlockLoading = ({ style = commonStyle, speed, size="default" }) => {
Expand Down
47 changes: 47 additions & 0 deletions src/components/CoffeeLoading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import styled, { keyframes } from 'styled-components';
import { commonStyle, sizeContainer } from '../utils/style';
const changeSharp = keyframes`
0%{
height: 0px;
},
100%{
height: 6px;
}
`;

const LoadContainer = styled.div`
height: ${props => sizeContainer[props.size] || sizeContainer['default']};
width: ${props => sizeContainer[props.size] || sizeContainer['default']};
border: 1px ${props => props.color || '#00adb5'} solid;
border-radius: 0px 0px 5px 5px;
position: relative;
&::after {
content: '';
width: 5px;
height: 12px;
position: absolute;
border: 1px solid ${props => props.color || '#00adb5'};
border-left: none;
border-radius: 0px ${props => sizeContainer[props.size] || sizeContainer['default']} ${props => sizeContainer[props.size] || sizeContainer['default']} 0px;
top: 4px;
left: ${props => sizeContainer[props.size] || sizeContainer['default']};
}
&::before {
content: '';
width: 1px;
height: 6px;
position: absolute;
background-color: ${props => props.color || '#00adb5'};
top: -10px;
left: ${props => props.size === 'small' ? 6 : (props.size === 'large' ? 12 : 8)}px;
box-shadow: 5px 0px 0px 0px ${props => props.color || '#00adb5'}, 5px -5px 0px 0px ${props => props.color || '#00adb5'}, 10px 0px 0px 0px ${props => props.color || '#00adb5'};
animation: ${changeSharp} ${props => props.speed || 1}s linear infinite alternate;
}
`;

const CoffeeLoading = ({ style = commonStyle, color, size = 'default', speed }) => {
return <LoadContainer style={style} color={color} size={size} speed={speed}></LoadContainer>;
};

export default CoffeeLoading;
29 changes: 14 additions & 15 deletions src/components/ThreeHorseLoading/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import React from 'react';
import styled, { keyframes } from 'styled-components';
import { commonStyle } from '../utils/style';
const animation = keyframes`
const animation = width => keyframes`
0%{
transform: translate(-120px);
}
50%{
transform: translate(0);
}
100%{
transform: translate(120px);
}
transform: translate(-${width}px);
}
50%{
transform: translate(0);
}
100%{
transform: translate(${width}px);
}
`;

const Container = styled.div`
width: 120px;
width: ${props => props.size === 'small' ? 60 : (props.size === 'large' ? 100 : 80)}px;
height: 8px;
border-radius: 4px;
margin: 0 auto;
margin-top: 100px;
position: relative;
background: #fff;
overflow: hidden;
Expand All @@ -30,13 +29,13 @@ const ItemSpan = styled.span`
height: 100%;
border-radius: 3px;
background: ${props => props.color || '#00adb5'};
animation: ${animation} ${props => props.speed || 2}s linear infinite;
animation: ${props => animation(props.size === 'small' ? 60 : (props.size === 'large' ? 100 : 80))} ${props => props.speed || 2}s linear infinite;
`;

const ThreeHorseLoading = ({ speed, color, style = commonStyle }) => {
const ThreeHorseLoading = ({ speed, color, style = commonStyle, size="default" }) => {
return (
<Container style={style} color={color}>
<ItemSpan speed={speed} style={style} color={color} />
<Container style={style} color={color} size={size}>
<ItemSpan speed={speed} style={style} color={color} size={size} />
</Container>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export { default as RectGraduallyShowLoading } from './RectGraduallyShowLoading'
export { default as PointSpreadLoading } from './PointSpreadLoading';
export { default as ThreeHorseLoading } from './ThreeHorseLoading';
export { default as PassThrouthLoading } from './PassThrouthLoading'
export { default as CoffeeLoading } from './CoffeeLoading'
export { default as BatteryLoading } from './BatteryLoading'
27 changes: 27 additions & 0 deletions src/stories/BatteryLoading.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs , text, number, radios } from '@storybook/addon-knobs';
import { BatteryLoading } from '~/components';
import Container from './compoment/Container';
storiesOf('BatteryLoading', module)
.addDecorator(withKnobs)
.add('BatteryLoading', () => {
let speed = 1;
let color = '';
speed = number('动画速度(s)')
color = text('颜色')
let size = radios(
'动画尺寸',
{
'small': 'small',
'default': 'default',
'large': 'large'
},
'default'
);
return (
<Container>
<BatteryLoading color={color} speed={speed} size={size}></BatteryLoading>
</Container>
);
});
27 changes: 27 additions & 0 deletions src/stories/CoffeeLoading.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs , text, number, radios } from '@storybook/addon-knobs';
import { CoffeeLoading } from '~/components';
import Container from './compoment/Container';
storiesOf('CoffeeLoading', module)
.addDecorator(withKnobs)
.add('CoffeeLoading', () => {
let speed = 1;
let color = '';
speed = number('动画速度(s)')
color = text('颜色')
let size = radios(
'动画尺寸',
{
'small': 'small',
'default': 'default',
'large': 'large'
},
'default'
);
return (
<Container>
<CoffeeLoading color={color} speed={speed} size={size}></CoffeeLoading>
</Container>
);
});
13 changes: 11 additions & 2 deletions src/stories/ThreeHorseLoading.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, number, text } from '@storybook/addon-knobs';
import { withKnobs, number, text, radios } from '@storybook/addon-knobs';
import { ThreeHorseLoading } from '~/components';
import Container from './compoment/Container';
storiesOf('ThreeHorseLoading', module)
Expand All @@ -11,9 +11,18 @@ storiesOf('ThreeHorseLoading', module)
let speed = 1;
speed = number('动画速度(s)')
let color = text('颜色')
let size = radios(
'动画尺寸',
{
'small': 'small',
'default': 'default',
'large': 'large'
},
'default'
);
return (
<Container>
<ThreeHorseLoading color={color} speed={speed}></ThreeHorseLoading>
<ThreeHorseLoading color={color} speed={speed} size={size}></ThreeHorseLoading>
</Container>
);
}
Expand Down
Loading

0 comments on commit f34e347

Please sign in to comment.