ipfs / ipfs-gui

Creating standards and patterns for IPFS that are simple, accessible, reusable, and beautiful
105 stars 17 forks source link

Shared React component library #76

Closed olizilla closed 4 years ago

olizilla commented 5 years ago

We want to reuse our UI componets across at least ipfs-webui, ipfs-desktop, ipfs-share-files. We want to define the patterns we have to creating our presentational components, in terms of component styling, and overrides, and i18n and bundling locale dictionaries when the componet is used in an app.

We believe we want a shared component library. A dev experience of

import { CidInfo, LoadingIndicator } from ipfs-gui

would be nice, epecially if it could automagically sort out adding the additional i18n keys to the bundle.

Prior art:

Puzzle pieces:

Next steps:

Starting from the gui-team principles... take a look at https://github.com/ipfs-shipyard/ipld-explorer-components

olizilla commented 5 years ago

Previous issues

olizilla commented 5 years ago

Also, it's worth noting that pulling components into a shared library can harm the dev experience if means you often have to npm link the component library into your app so you can fix the shared components to work in your new use-case. I learn towards avoiding making overly generic components in favour of sharing good composable basic ones. If a component ends up with numerous props to customise it, and internal logic to deal with the variety, splitting it out into 2 simpler components is usually easier to reason about.

Worth considering

GiladShoham commented 5 years ago

Hi all, I’m Gilad and I’m a core maintainer at Bit. I will happily shed some light on Bit’s sorcery :slightly_smiling_face: I think it can be a useful solution to this problem. For example, here’s an example of what Grommet are in the process of doing with Bit: https://bit.dev/grommet.

As you can see, every component can now be reused in other projects and even developed from multiple projects at the same time while changes can be synced. All the components are available in the collection and can be shared, discovered and playd with. This will not require any refactoring for the library. You can learn more here: https://docs.bit.dev/whybit/for-libs.html. Alternatively you can even save the need for the library altogether and just share components from different places into one collection.

What do you think? I’d love to help

olizilla commented 5 years ago

Thanks @GiladShoham we're testing Bit out! @cwaring @fsdiogo can you add your feedback here as you go?

fsdiogo commented 5 years ago

The learning curve seems quite low as the commands are all Git-like 👍

In a few minutes we had a collection with a few components, imported them from Bit and they worked out-of-the-box in our apps, so that is awesome 👌✨

A pain point we experienced is when we have dependencies higher up in the tree: we're using Tachyons and others and importing them in a global CSS file. So, to make our components "stylezed" in Bit, we've got to import those libs in each component on our collection (AFAIK). Is there a way to import a dependency globally to our collection?

GiladShoham commented 5 years ago

I'm happy to see that you find Bit easy to use :) It's humbling to see an awesome team liking it!

We are working right now on the ability to add dependencies globally. So you can add Tachyons as a dependency to all components (or a subset...). It is part of the overrides feature (that is already merged). I expect it to be available in the next couple of weeks.

I can update you on its availability here if you'd like.

fsdiogo commented 5 years ago

Awesome! Please do @GiladShoham!

olizilla commented 5 years ago

Storybook is getting docs n blocks n mdx - https://medium.com/storybookjs/storybook-docs-sneak-peak-5be78445094a

ericronne commented 5 years ago

Any update on tachyons (&c) support, @GiladShoham? Thanks!

cwaring commented 5 years ago

@ericronne and I kicked around some ideas on this today and concluded that Bit neatly helps us achieve the goals we have for the first version of our component library. So I'm going to run an extended test based on ipfs-webui soon 👌

GiladShoham commented 5 years ago

@fsdiogo @olizilla @ericronne @cwaring I'm happy to hear you find Bit useful for your project :)

We've just published a new version for Bit (14.1.0). It supports a new workflow for manipulating Bit's automated dependency definition. It allows forcing a dependency to all components, even if they don't explicitly require it.

How to force a component dependency

I'll assume that you are already tracking the styles component, and name it styles-component.

Edit the workspace configuration and add the overrides key. Note that you can set it for specific components or groups of components.

{
  "bit": {
      "overrides": {
          "*": { // Add the css-component as dependency to all workspace components
              "dependencies": {
                  "@bit/css-component": "+" // bit defines the version automatically, as defined in the workspace
              }
          },
          "utils/*": { // if there are some components that don't need the dependency, you can use the override to remove dependencies
              "dependencies": {
                  "@bit/css-component": "-"
              }
          }
      }
  }
}

You can read a bit more about it here.

  1. short description
  2. Overriding component dependencies
  3. Setting specific component configurations

If you need any help, you can open an issue in the main git repo, comment to this thread, or say 'hi' on gitter.

cwaring commented 5 years ago

Thank you @GiladShoham, this looks ideal. I'll test it out and let you know how we get on :)

jessicaschilling commented 4 years ago

Closing in favor of https://github.com/ipfs/ipfs-gui/issues/29 (and linking to this issue inside it as well, so work isn't lost).