Comments (5)
Can you share the props configuration?
from react-view.
const props = {
isOpen: {
type: PropTypes.Boolean,
value: false,
stateful: true,
},
button: {
type: PropTypes.ReactNode,
value: `<EuiButton
iconType="arrowDown"
iconSide="right"
onClick={() => setIsOpen(!isOpen)}
>
Show popover
</EuiButton>`,
},
children: {
type: PropTypes.ReactNode,
value: `<div style={{ width: "300px" }}>
Popover content that’s wider than the default
width
</div>`,
},
};
This is the minimal configuration after removing all non-affecting factors
from react-view.
You can observe the code and the demo for more clarifications.
from react-view.
@tajo is the way I am doing things not the correct one?
from react-view.
So, the problem is that there is no connection between EuiButton
's onClick
and the react-view's state. When you click on it, react-view has no idea it happened and that's why the knob or source code are not updated.
Fortunately, there is a concept for this in react-view that lets you establishing this connection. We call it state hooks. However, this assumes simpler scenarios where the onClick
like handler is the top level prop. In your case, it's buried inside of the button
prop and EuiButton
component.
Luckily, we have one use-case like that in Base Web's Progress Steps. So we built an escape hatch where you can write a custom AST visitor to correctly target and instrument the deep onClick
handler.
So your button prop configuration should look like this:
button: {
type: PropTypes.ReactNode,
value: `...`,
propHook: ({getInstrumentOnChange, fnBodyAppend}) => ({
JSXAttribute(path: any) {
if (path.get('name').node.name === 'onClick') {
fnBodyAppend(
path.get('value'),
getInstrumentOnChange('!isOpen', 'isOpen')
);
}
},
}),
},
This is more involved API assuming the deep knowledge of react-view. The advantage is, it can deal with pretty much anything (AST traverse is super flexible). A gist:
- Take the
button
prop's AST and traverse it - Match all
JSXAttribute
nodes - If the attr name is
onClick
add a secret (filtered out of the code snippet) instrumentation call that takes!isOpen
value and updates theisOpen
state.getInstrumentOnChange
andfnBodyAppend
are AST related helper functions so you don't have to write even more code.
Feel free to re-open if you have more issues.
from react-view.
Related Issues (20)
- Allow 'code inside the return statement' to be returned instead of whole code
- Add support for numeric literal types
- IE11 support? HOT 1
- docs: Advance examples HOT 1
- build: Not able to server render. HOT 3
- Nested dependency is packaged and published through github which is a potential security risk HOT 2
- Dependency version issue HOT 3
- Latest version v2.3.4 in registry.npmjs.org is different from v2.3.4 release in github HOT 1
- How to change the theme? HOT 2
- Does not work with latest Next.js HOT 5
- Would you consider supporting multiple statements? HOT 2
- Option to disable editing in Editor
- useView doesn't work in next js HOT 10
- Can't resolve 'fs'. in next js@11 HOT 1
- Missing Undefined check in React.useState()
- On useView knobProps don't change if config change
- Support for TypeScript code snippets with knobs HOT 1
- Boolean props that default to undefined can’t be explicitly set to false
- Can't resolve 'linguist-languages/data/JavaScript' in Next 12.2.3
- React useRef hook code not generated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-view.