Replies: 1 comment 2 replies
-
I agree with the last solution. It must mean something also that the bigger component libraries I think mostly use that pattern. That also all said, semantically, if an OverflowMenuItem exists, I think it should be as close as possible to where it will be used, ie OverflowMenu folder. If a generic OverflowMenuItem has to also exist, I would name it something more generic like ListBoxItem or something (not sure what exactly), and then if required, OverflowMenu can import and extend it. To me this is a bit of a higher-order problem. I would not really consider the export combination option, as I think it breaks a bit of the encapsulation. Index files should be very dumb imo |
Beta Was this translation helpful? Give feedback.
-
For some components we have this pattern:
Items that "belong" to a parent component like in this example the
Item
are attached to the parent component and can be used with "Parent.Item".Currently all this is defined and exported inside the folder of the "parent" like
lib/components/OverflowMenu
:Because the item is defined inside the
components/OverflowMenu
folder and it would be possible to create a new folder/component with the same name (components/OverflowMenuItem
) creating a name conflict with the global hooks, we decided to use the underline naming convention for the needed global hooks, like:useOverflowMenu_Item
anduseOverflowMenuItem
can coexist.I do not really like the underline naming.
One Idea I had is to instead not define the item inside
components/OverflowMenu
and make the hierarchy more flat by moving the Item outside tocomponents/OverflowMenuItem
.Then connect them just before exporting, for example in
lib/main.ts
:But also this still has a downside: If the consumer does not use all composition elements, like for example only
<OverflowMenu>
is used but<OverflowMenu.Item>
is not, the code of<OverflowMenu.Item>
would still land in the final bundle as it is attached toOverflowMenu
.The only solution to this would be to stop using this pattern and instead simply go with:
I don't see any real disadvantage here as also autocomplete would help to find which composition components are in the namespace by typing
<OverflowMenu
, right?Beta Was this translation helpful? Give feedback.
All reactions