Clarity: [CORE/NG] Modularize Clarity

Created on 27 Apr 2017  ยท  4Comments  ยท  Source: vmware/clarity

Currently, we export a single module that contains every single one of our components. It makes it impossible to treeshake Clarity, or even to write unit tests without compiling the whole library.
On top of that, the number of components we have is starting to be too much for a flat structure, so we need to reorganize the project.

Here is the proposed folder structure for clarity-angular/ (which I just realized is poorly named, since it also contains the source for clarity-ui).

 โ”œโ”€ animations (needs a rewrite from scratch)
 โ”œโ”€ close
 โ”œโ”€ conditional
 โ”‚   โ”œโ”€ if-active
 โ”‚   โ”œโ”€ if-expanded
 โ”‚   โ”œโ”€ if-open
 โ”‚   โ””โ”€ ...
 โ”œโ”€ loading
 โ””โ”€ scrolling-service (?)
button
 โ”œโ”€ button-basic (?)
 โ”œโ”€ button-group
 โ””โ”€ button-spinner
code
 โ”œโ”€ example (?)
 โ””โ”€ syntax-highlight
colors (all CSS)
data
 โ”œโ”€ datagrid
 โ”‚   โ””โ”€ (preserve structure for now)
 โ”œโ”€ stack-view
 โ”œโ”€ table
 โ””โ”€ tree-view
drag-drop
emphasis
 โ”œโ”€ alert
 โ”œโ”€ badge
 โ””โ”€ label
forms
 โ”œโ”€ checkbox
 โ”œโ”€ date
 โ”œโ”€ input
 โ”œโ”€ radio
 โ”œโ”€ select
 โ”œโ”€ time
 โ”œโ”€ toggle
 โ””โ”€ ...
icons
layout
 โ”œโ”€ card
 โ”œโ”€ grid
 โ”œโ”€ login
 โ”œโ”€ main-container
 โ”œโ”€ nav
 โ””โ”€ tabs
modal
 โ””โ”€ dialog (?)
popover
 โ”œโ”€ common (private, do not re-export from PopoverModule) 
 โ”œโ”€ dropdown
 โ”œโ”€ signpost
 โ””โ”€ tooltip
progress
 โ”œโ”€ progress-bar
 โ””โ”€ spinner
typography
 โ””โ”€ list
wizard

(?) means the component is either not written yet, not decided on, or possibly not needed anymore.

Each folder declares an Angular module, so that each component can be imported individually by importing its corresponding module. Each folder that contains sub-folders declares a module that exports the corresponding sub-modules.
Of course, modules can depend on one another, but we have to make sure our own modules only import what's strictly necessary. For instance, TreeViewModule will not import all of FormsModule, but only CheckboxModule.

Note that there are a few constraints that we need to respect at all times:

  • If a folder contains sub-folders, it cannot contain an Angular component or directive at its root. That would make it impossible to import said component in isolation.
  • We need to avoid dependency cycles.
  • If we anticipate on a new component, we need to make sure it can be added to this tree without breaking changes.

SCSS files will follow their respective components, but note that contrary to Angular components, they can be at the root of a folder that contains sub-folders.

This should be done without breaking changes, which means our main index.ts and ClarityModule need to export the same classes and components as they did before the reorganization.

Most helpful comment

Thumbs up! For users to import certain components individually will be so nice, great!

All 4 comments

Thumbs up! For users to import certain components individually will be so nice, great!

Any thoughts on making scoped package (e.g. @clarity/angular) just like Angular is doing right now?

@imcotton: We considered it initially, but if I remember correctly there were some internal constraints at VMware that prevented us from doing so.

These constraints might not exist anymore, so I'll raise this with the team and see if it's now something we want to do.

Hi there ๐Ÿ‘‹, this is an automated message. To help Clarity keep track of discussions, we automatically lock closed issues after 14 days. Please look for another open issue or open a new issue with updated details and reference this one as necessary.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hippee-lee picture hippee-lee  ยท  25Comments

reddolan picture reddolan  ยท  27Comments

spitfjre picture spitfjre  ยท  33Comments

reddolan picture reddolan  ยท  121Comments

civanova picture civanova  ยท  25Comments