1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-11-26 00:35:02 +03:00

Add steps hook

This commit is contained in:
Brent Jackson 2019-03-09 23:01:18 -05:00
parent d6421696de
commit 217bcb369f
3 changed files with 32 additions and 1 deletions

View File

@ -1,7 +1,8 @@
import React from 'react'
import Steps from './Steps'
import useSteps from './useSteps'
export const Appear = props => {
export const _Appear = props => {
const arr = React.Children.toArray(props.children)
return (
<Steps
@ -23,4 +24,21 @@ export const Appear = props => {
)
}
export const Appear = props => {
const arr = React.Children.toArray(props.children)
const step = useSteps(arr.length)
const children = arr.map((child, i) =>
i < step
? child
: React.cloneElement(child, {
style: {
...child.props.style,
visibility: 'hidden',
},
})
)
return <>{children}</>
}
export default Appear

View File

@ -5,3 +5,4 @@ export { Notes } from './Notes'
export { Steps } from './Steps'
export { Appear } from './Appear'
export { withContext, useDeck } from './context'
export useSteps from './useSteps'

View File

@ -0,0 +1,12 @@
import { useContext, useMemo } from 'react'
import { Context } from './context'
export default length => {
const context = useContext(Context)
const { register, index, step } = context
useMemo(() => {
register(index, { steps: length })
}, [length])
return step
}