Skip to content

Spinner changes #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/components/spinner/Spinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React,{Component} from 'react'
import flywheel from './images/flywheel.gif'
import pinwheel from './images/pinwheel.gif'
import glowring from './images/glowring.gif'
import turnsign from './images/turnsign.gif'



const switchSpinner=(type,children)=>{
switch (type){
case 'flywheel':
return <div><img src={flywheel} alt="Fly wheel" /></div>

case 'pinwheel':
return <img src={pinwheel} alt="Pin Wheel" />

case 'glowring':
return <img src={glowring} alt="Glow Ring" />

case 'turnsign':
return <img src={turnsign} alt="Turn Sign" />
}
}


const Spinner=(props)=>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please de-structure your props for better code readability. e.g.
const Spinner = ({type, children}) => {}

return (<>{switchSpinner(props.type,props.children)}</>)
}

Spinner.defaultProps={
type:'flywheel'
}

export default Spinner
Binary file added src/components/spinner/images/flywheel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/components/spinner/images/glowring.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/components/spinner/images/pinwheel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/components/spinner/images/turnsign.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions src/demos/SpinnerDemo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useState, useEffect } from 'react'
import Spinner from '../components/spinner/Spinner'
import spinnerDocPath from '../docs/spinner.md'
import ReactMarkdown from 'react-markdown'

const SpinnerDemo=()=>{
const [markdown,setMarkdown]=useState('')

useEffect(()=>{
fetch(spinnerDocPath).then((response)=> response.text()).then((text)=>{
setMarkdown(text)
})

})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not adding anything in the dependencies array? Not providing that in useEffect will lead to serious issues of memory leaks and can cause the performance.


return (<>
<div><ReactMarkdown source={markdown}/>
<Spinner />
<Spinner type="glowring"/>
<Spinner type="pinwheel"/>
<Spinner type="turnsign"/></div>
</>)

}

export default SpinnerDemo
21 changes: 21 additions & 0 deletions src/docs/spinner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Usage
```
import React from 'react'
import Heading from '../components/Heading'

function App() {
return (
<div className="App">
<Heading type='h3'> I'm an h3 header </Heading>
</div>
);
}
```
## Properties

Property | Type | Required | Default value | Description
:--- | :--- | :--- | :--- | :---
`children`|children|no|empty| Text/children of heading
`type`|string|no|flywheel| pinwheel,glowring,turnsign,flywheel

### Demo