patternfly / patternfly/patternfly-react
Resolve inconsistencies when forwarding components
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 862
- Fork
- 392
- Merge medio
- 4g 8h
- PR unite (30g)
- 9
Descrizione
Describe the issue. What is the expected and unexpected behavior?
Sometimes as a user you want to be able to pass in your custom component to render instead of the default element. However the API around this varies wildly per component. For example, these are some components we use in our application that need React Router's Link component:
Button
{/* @ts-ignore */}
<Button component={Link} to={toNewClientScope({ realm })}>
{t("createClientScope")}
</Button>
DropdownItem
<DropdownItem
component={<Link to={toDashboard({ realm })}>{t("realmInfo")}</Link>}
/>
BreadcrumbItem
<BreadcrumbItem
render={(props) => (
<Link {...props} to={toRealmSettings({ realm, tab: "keys" })}>
{t("keys")}
</Link>
)}
/>
As you can see there are already three different ways of forwarding a component to render, and some of them are not able to be written in a type-safe manner.
The expected behavior here would be that this is a single and consistent API that is completely type-safe. For example, Styled Components has a as prop which is made type-safe by the definitions and allows the props to be forwarded and type-checked as well:
import styled from 'styled-components'
const Button = styled.button`
background-color: hotpink;
`
<Button component={Link} to={toNewClientScope({ realm })}>
{t("createClientScope")}
</Button>
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Confronta le API di forwarding e il comportamento di TypeScript di Button, DropdownItem e BreadcrumbItem, usando come riferimento le definizioni dei tipi di styled-components collegate nell’issue. Il lavoro è completo quando questi componenti espongono un modo coerente e type-safe per inoltrare un componente personalizzato e le sue props.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- react, typescript
- Ambito
- frontend
- Tipo di issue
- Refactoring
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100