Replies: 6 comments 6 replies
-
@vnys api-extractor ran into problems trying to decipher the "release" tags when using compound components also |
Beta Was this translation helpful? Give feedback.
-
List of the compound components with their respective sub components in our library that don't provide correct prop types in the intellisense in the IDE (if the sub components are not mentioned here they are OK):
|
Beta Was this translation helpful? Give feedback.
-
One other problem discovered with using Typescript, Compound Components and letting our users extend our components can be confusing naming for exported Typescript Props when deconstructing from our library. Example using
|
Beta Was this translation helpful? Give feedback.
-
Proposed solution 1Keep compound components and update rest to match.
CostLow, we only need to fix naming of exposed sub-components and update stories accordingly. UsageAlternative 1import { Table } from '@equinor/eds-core-react'
<Table>
<Table.Row>
<Table.Cell>Text</Table.Cell>
</Table.Row>
</Table> Alternative 2import { Table } from '@equinor/eds-core-react'
const { Row, Cell } = Table
<Table>
<Row>
<Cell>Text</Cell>
</Row>
</Table> |
Beta Was this translation helpful? Give feedback.
-
Proposed solution 2Deprecate compound components in favour of more streamlined approach. This will make component names more verbose.
CostMedium, we need to remove compound components boilerplates and rename several components. Affected stories will also need to be changed. UsageAlternative 1import { Table, TableCell, TableRow } from '@equinor/eds-core-react'
<Table>
<TableRow>
<TableCell>Text</TableCell>
<TableRow>
</Table> |
Beta Was this translation helpful? Give feedback.
-
As a user, I'll take compound components over the alternative any day. It just makes much more sense to me, and seems like a cleaner, more modern approach. The only problem i had with it, was that I couldn't find any info on handling subcomponents in Storybook or in the storefront. If you do decide to keep it, please provide an example or notify us users. If not in the Storybook Stories themselves, then at least in the intro article or the developers-article in the Storefront. |
Beta Was this translation helpful? Give feedback.
-
Some of the components in the EDS have a parent child relationship. It does not make sense, for example, to use a
<Cell />
component outside the context of the<Table />
component. To make this relationship clear in code, and also to share implicit state using the Context API between a component and it’s sub components, we have used the pattern of compound components.Kent C. Dodds explains the rationale behind this pattern in his blog post React Hooks: Compound Components.
…and this is an example of how we use this pattern in the EDS Core React library
The way we’ve implemented this, using
<Table />
as an example is that we have the following file structure:…then index.js is where we tie all the sub components together with the parent component like so:
…and then the consumer could use destructuring to pick out the sub components:
…or use dot notation:
This pattern has proved to work quite well, but in the process of refactoring all the components to Typescript, we’ve run into some problems with intellisense and compound types – and it does seem that this pattern is not particularly popular in typescript projects – most likely because of similar issues. The main problem is that if we rewrite the above in typescript, like so:
…then the intellisense you get in VS Code for example, is no longer the types of the
<Table />
component, but the compound types, which isn’t very helpful and just adds a lot of unnecessary noise.Diondre Edwards wrote a blog post about how to implement the pattern in typescript, but by looking at the Github repo the sub components are not properties on the parent component in the same way they are in Kent D. Todds original code – which is perhaps where we need to do things differently. Also worth noting the last comment in the original example:
The alternative then could be to rename all the sub components to something like
<TableHead />
,<TableBody />
and so forth – but the drawback is that it would make it more verbose to use the library for the consumers. A different approach could be to not export the compound types by using the@internal
or@ignore
tag in a JSDoc comment – at least we should investigate if that mitigates the problem.Beta Was this translation helpful? Give feedback.
All reactions