-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(progress): ♻️ refactor state & stories
- Loading branch information
1 parent
642f331
commit 56d0cb3
Showing
5 changed files
with
186 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,85 @@ | ||
import React from "react"; | ||
import { Meta } from "@storybook/react"; | ||
import { css, keyframes } from "emotion"; | ||
|
||
import { Progress } from "../Progress"; | ||
import { useProgressState } from "../ProgressState"; | ||
import { | ||
progressStyle, | ||
generateStripe, | ||
progressBarStyle, | ||
createLinearExamples, | ||
} from "./storybook-progress-utils"; | ||
import { StyledProgress } from "./Progress"; | ||
|
||
export default { | ||
title: "Progress/Linear", | ||
} as Meta; | ||
|
||
const examples = createLinearExamples({ | ||
stateHook: useProgressState, | ||
component: Progress, | ||
})(); | ||
export const Default = () => { | ||
return <StyledProgress />; | ||
}; | ||
|
||
export const Default = examples.Default; | ||
export const WithLabel = examples.WithLabel; | ||
export const WithStripe = examples.WithStripe; | ||
export const WithAnimatedStripe = examples.WithAnimatedStripe; | ||
// const examples = createLinearExamples({ | ||
// stateHook: useProgressState, | ||
// component: Progress, | ||
// })(); | ||
|
||
export const WhenIsIndeterminate = () => { | ||
const progress = useProgressState({ value: undefined }); | ||
// export const Default = examples.Default; | ||
// export const WithLabel = examples.WithLabel; | ||
// export const WithStripe = examples.WithStripe; | ||
// export const WithAnimatedStripe = examples.WithAnimatedStripe; | ||
|
||
const progressAnim = keyframes({ | ||
"0%": { left: "-40%" }, | ||
"100%": { left: "100%" }, | ||
}); | ||
// export const WhenIsIndeterminate = () => { | ||
// const progress = useProgressState({ value: undefined }); | ||
|
||
const indeterminateStyles = css({ | ||
...(progress.isIndeterminate && { | ||
position: "absolute", | ||
willChange: "left", | ||
minWidth: "50%", | ||
width: "100%", | ||
height: "100%", | ||
backgroundImage: | ||
"linear-gradient( to right, transparent 0%, #D53F8C 50%, transparent 100% )", | ||
animation: `${progressAnim} 1s ease infinite normal none running`, | ||
}), | ||
}); | ||
// const progressAnim = keyframes({ | ||
// "0%": { left: "-40%" }, | ||
// "100%": { left: "100%" }, | ||
// }); | ||
|
||
return ( | ||
<div style={progressStyle}> | ||
<Progress | ||
{...progress} | ||
style={{ ...progressBarStyle, backgroundColor: "none" }} | ||
className={indeterminateStyles} | ||
/> | ||
</div> | ||
); | ||
}; | ||
// const indeterminateStyles = css({ | ||
// ...(progress.isIndeterminate && { | ||
// position: "absolute", | ||
// willChange: "left", | ||
// minWidth: "50%", | ||
// width: "100%", | ||
// height: "100%", | ||
// backgroundImage: | ||
// "linear-gradient( to right, transparent 0%, #D53F8C 50%, transparent 100% )", | ||
// animation: `${progressAnim} 1s ease infinite normal none running`, | ||
// }), | ||
// }); | ||
|
||
export const WhenIsIndeterminateStripe = () => { | ||
const progress = useProgressState(); | ||
// return ( | ||
// <div style={progressStyle}> | ||
// <Progress | ||
// {...progress} | ||
// style={{ ...progressBarStyle, backgroundColor: "none" }} | ||
// className={indeterminateStyles} | ||
// /> | ||
// </div> | ||
// ); | ||
// }; | ||
|
||
const progressAnim = keyframes({ | ||
"0%": { left: "-40%" }, | ||
"100%": { left: "100%" }, | ||
}); | ||
// export const WhenIsIndeterminateStripe = () => { | ||
// const progress = useProgressState(); | ||
|
||
const indeterminateStyles = css({ | ||
...(progress.isIndeterminate && { | ||
position: "absolute", | ||
willChange: "left", | ||
minWidth: "50%", | ||
width: "100%", | ||
height: "100%", | ||
...generateStripe(), | ||
animation: `${progressAnim} 1s ease infinite normal none running`, | ||
}), | ||
}); | ||
// const progressAnim = keyframes({ | ||
// "0%": { left: "-40%" }, | ||
// "100%": { left: "100%" }, | ||
// }); | ||
|
||
return ( | ||
<div style={progressStyle}> | ||
<Progress | ||
{...progress} | ||
style={{ ...progressBarStyle, backgroundColor: "#D53F8C" }} | ||
className={indeterminateStyles} | ||
/> | ||
</div> | ||
); | ||
}; | ||
// const indeterminateStyles = css({ | ||
// ...(progress.isIndeterminate && { | ||
// position: "absolute", | ||
// willChange: "left", | ||
// minWidth: "50%", | ||
// width: "100%", | ||
// height: "100%", | ||
// ...generateStripe(), | ||
// animation: `${progressAnim} 1s ease infinite normal none running`, | ||
// }), | ||
// }); | ||
|
||
// return ( | ||
// <div style={progressStyle}> | ||
// <Progress | ||
// {...progress} | ||
// style={{ ...progressBarStyle, backgroundColor: "#D53F8C" }} | ||
// className={indeterminateStyles} | ||
// /> | ||
// </div> | ||
// ); | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { css } from "emotion"; | ||
import * as React from "react"; | ||
import { Button } from "reakit"; | ||
|
||
import { | ||
Progress, | ||
useProgressState, | ||
ProgressState, | ||
ProgressInitialState, | ||
} from "../index"; | ||
|
||
export interface StyledProgressInitialState extends ProgressInitialState {} | ||
|
||
export const StyledProgress: React.FC<StyledProgressInitialState> = props => { | ||
const { children, ...rest } = props; | ||
const { value, setValue, ...state } = useProgressState(rest); | ||
console.log("%c state", "color: #735656", state); | ||
|
||
React.useEffect(() => { | ||
const clearId = setInterval(() => { | ||
setValue(prevValue => prevValue + 5); | ||
}, 500); | ||
|
||
if (value === 100) { | ||
clearInterval(clearId); | ||
} | ||
|
||
return () => { | ||
clearInterval(clearId); | ||
}; | ||
}, [setValue, value]); | ||
|
||
return ( | ||
<div> | ||
<div style={progressStyle}> | ||
<Progress | ||
{...state} | ||
value={value} | ||
className={progressBarStyle(state.percent)} | ||
/> | ||
</div> | ||
<br /> | ||
<Button type="reset" onClick={() => setValue(0)}> | ||
Reset | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
const progressStyle: React.CSSProperties = { | ||
background: "rgb(237, 242, 247)", | ||
height: "0.75rem", | ||
width: "400px", | ||
overflow: "hidden", | ||
position: "relative", | ||
}; | ||
|
||
const progressBarStyle = (percent: ProgressState["percent"]) => { | ||
return css({ | ||
transition: "all 0.3s", | ||
backgroundColor: "#3182ce", | ||
width: `${percent}%`, | ||
height: "100%", | ||
}); | ||
}; |