-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathWrapper.jsx
24 lines (21 loc) · 960 Bytes
/
Wrapper.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React, {useState } from 'react';
import { Log, VisualizerProvider } from '../src';
const StateToggle = ({testId, checked, setChecked}) => {
const onChange = ({currentTarget}) => setChecked(currentTarget.checked);
return <input type='checkbox' data-testid={testId} checked={checked} onChange={onChange}/>;
};
// Wrapper to add VisualizerProvider and log, with buttons for showing/hiding child and updating child prop.
export const Wrapper = ({renderChild}) => {
const [isShowingChild, setIsShowingChild] = useState(true);
const [propValue, setPropValue] = useState(false);
return (
<VisualizerProvider>
<div>
<StateToggle testId='show-child-checkbox' checked={isShowingChild} setChecked={setIsShowingChild}/>
<StateToggle testId='prop-value-checkbox' checked={propValue} setChecked={setPropValue}/>
{isShowingChild && renderChild({prop: true})}
<Log/>
</div>
</VisualizerProvider>
);
};