Description
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:
- https://github.com/olizilla/ipfs-react - An example component library, looking at a single component in styled system vs tachyons. Folks were more in favour of tachyons. @fsdiogo proposed a postcss based alternative
- Has an example of per component i18n but it needs a few more examples to really see if that pattern works.
- https://github.com/ipfs-shipyard/ipld-explorer-components - The working baseline. It's components are used from both ipld-explorer and ipfs-webui. A new component library needs to deal with the issues that are currently handled by ipld-explorer-components
Puzzle pieces:
- i18next and react-i18next for loading the right locale dictionary at run time.
- transifex for managing our locale dictionaries - https://www.transifex.com/ipfs/
tx
for pulling locale dictionaries from transifex- tachyons - used across all our existing components and many of our websites.
- redux-bundler - lets us publish and reuse chunks of redux plumbing. The interactions in exploring ipld data are defined in a bundle in ipld-explore-components and re-used in both the webui and ipld-explorer.
Next steps:
Starting from the gui-team principles... take a look at https://github.com/ipfs-shipyard/ipld-explorer-components
- update storybook to the fancy new one.
- add the circle ci build process to it. Have it publish the storybook in PR. Comment out the dnslink update step, until we decide on a domain for it.
- Pull some components from ipfs-webui into ipld-explorer-components (will be renamed later) and import them from webui
- Define the pattern for exporting re-usable components that use tachyons for styling, but allow the use site to overide the style of the containing element. This is probably just
export const Thing = ({className, children, ...props}) => {
return <div className={`bg-gray charcoal ${className}` ...props>{children}</div>
}
to start with, but it has the problem that if ma4
is the default, and the caller tries to apply ma2
as an override it will not work as the class will end up with both in its class list, and then its down to document order in the css file as to which one wins, in this example, the default ma4
occurs after ma2
so it does not apply. I think we can figure out a neat solution to that tho.
- Define the component api for i18n. Right now we export components that expect a
t
function and call that with i18n key names that they need. Alternatives are to create props for each label that appears in the component, and then write a container that maps those props to i18n keys. This could be neat if we use thepath/to/the/Component.fooLabel
as the key. In general you want to make it easy to have sensible defaults and possible to override them when the compent is used in a different setting. It's worth highlighting that really atomic components like<Button>
should not have any awareness of i18n, as their text will change with every use case, but something like a<DeleteButtonWithConfirmation/>
might benefit from sharing good default explanation text, that would need localising.