operational-ui: TopBarSelect types are broken
Consider following code example
import { BarChartIcon, TableIcon, TopbarSelect } from "@operational/components"
const displayItems = [{ label: "Table", icon: TableIcon }, { label: "Bar Chart", icon: BarChartIcon }]
const [activeDisplay, setActiveDisplay] = React.useState<any>("Table")
;<TopbarSelect
label="Display:"
selected={activeDisplay}
items={displayItems}
onChange={setActiveDisplay}
/>
It doesn’t work without any in React.useState
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (15 by maintainers)
Hi 👋🏻 Can I take this one too ?
@march213 consider following code (standard React)
React standard components have to deal with event, because they are building blocks. But in our case we can simplify API and onChange can be called with value directly instead of event. (Does it make sense so far?)
So we should be able to write something like this
But our type system says that onChange can be called with ReactNode as well. Does it even make sense to have ReactNode provided to onChange? 🤔 How we gonna use ReactNode in state? (I mean generally we can, but we should not unless there is a specific reason for it).
So my idea is that
onChangetype signature should be(label: string) => voidThis sometimes happens https://www.youtube.com/watch?v=_UZFI-8D5uA
@ImogenF Thank you !
@march213 Go for it!
Yes you can.
Please do not change the type signature of
IContextMenuItem. This is used widely internally and ~could be~ is a significant breaking change.Further, sometimes the labels of these items (even in
TopbarSelect) are not directly equal to the value. Imagine a list where you want to show user-readable labels but have machine-readable values. In this case, you’d want to passnewItem.valuetoonChangeinstead of its label.For these reasons, I think passing just a label is a little naïve compared to passing the entire item and letting the user deal with it however they want.
For consistency across our app, I propose the following interface for
TopbarSelect:This should make things more compatible.
Thank you 😊 It makes perfect sense. I will simplify type signature.
I was confusing about using ReactNode, but I wasn’t sure about use cases.