-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Stepper, CodePane highlighting/scrolling (#843)
- Loading branch information
1 parent
1dd2adf
commit aea2ec0
Showing
11 changed files
with
210 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react'; | ||
import propTypes from 'prop-types'; | ||
import { SlideContext } from '../hooks/use-slide'; | ||
|
||
const Stepper = ({ children: render, values, defaultValue }) => { | ||
const { | ||
state: { currentSlideElement: step } | ||
} = React.useContext(SlideContext); | ||
|
||
const value = step === -1 ? defaultValue : values[step]; | ||
|
||
return render(value, step); | ||
}; | ||
|
||
Stepper.propTypes = { | ||
values: propTypes.array.isRequired, | ||
defaultValue: propTypes.array | ||
}; | ||
|
||
export default Stepper; |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import isComponentType from './is-component-type'; | ||
import Stepper from '../components/stepper'; | ||
|
||
export default function searchChildrenForStepper(children) { | ||
if (!Array.isArray(children)) { | ||
return 0; | ||
} | ||
return children.reduce((memo, current) => { | ||
if (isComponentType(current, Stepper.name)) { | ||
const { values } = current.props; | ||
|
||
memo += Array.isArray(values) ? values.length : 0; | ||
} else if (current?.props?.children?.length > 0) { | ||
memo += searchChildrenForStepper(current.props.children); | ||
} | ||
return memo; | ||
}, 0); | ||
} |
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,46 @@ | ||
import React from 'react'; | ||
import Enzyme from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
import Stepper from '../components/stepper'; | ||
|
||
import searchChildrenForStepper from './search-children-stepper'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('search children for stepper', () => { | ||
it('returns 0 when there are no children', () => { | ||
expect(searchChildrenForStepper([])).toEqual(0); | ||
}); | ||
|
||
it('returns 0 when there are no stepper elements', () => { | ||
expect( | ||
searchChildrenForStepper([ | ||
<div key={0}>not a stepper element</div>, | ||
<div key={1}>nor me</div> | ||
]) | ||
).toEqual(0); | ||
}); | ||
|
||
it('returns the amount of stepper elements', () => { | ||
expect( | ||
searchChildrenForStepper([ | ||
<div key={0}>not a stepper element</div>, | ||
<Stepper key={1} values={[[1, 1]]}> | ||
{() => 'But I have 1 value'} | ||
</Stepper>, | ||
<div key={2} />, | ||
<Stepper | ||
key={3} | ||
values={[ | ||
[1, 1], | ||
[2, 2], | ||
[3, 3] | ||
]} | ||
> | ||
{() => 'And I have 3 values'} | ||
</Stepper> | ||
]) | ||
).toEqual(4); | ||
}); | ||
}); |