docs/integrating-into-frameworks.md
MDC Web was designed to be integrated as easily as possible into any and all web frameworks. This document will walk you through strategies for integrating components into various types of frameworks.
We maintain a list of component libraries, which wrap MDC Web for other frameworks, in our main README (under the MDC Web on other frameworks document). Each library must:
There are two approaches you can take for integrating our components into frameworks: the simple approach and the advanced approach. Both have their benefits and drawbacks, and are explained below.
The easiest way to integrate MDC Web into frameworks is to use our vanilla components directly. This works well for frameworks which assume they will be executed within the context of a browser, such as angular v1, backbone.js, or even things such as jQuery plugins.
The simple approach can be outlined as follows:
mdcComponent.mdcComponent
property.mdcComponent.destroy() to clean up the MDC Web component.This general approach will work for almost all basic use-cases. For an example of this approach, check out this plunk which shows how to wrap our text field within an angular v1 component, as well as our button (with a ripple) within an attribute directive.
Note that this approach will also work for custom elements. Use connectedCallback for initialization
and disconnectedCallback for destruction.
Many modern front-end libraries/frameworks, such as react and angular, wind up targeting more than just a web browser. For these frameworks - and for some highly advanced application architectures - a more robust approach is required. We provide foundations and adapters to accommodate this use case.
If you are interested in wrapping our components using foundations/adapters, you should first read through our architecture overview in order to familiarize yourself with the general concepts behind them.
Every component comes with a complementary foundation class, which is usually called
MDCComponentFoundation, where MDCComponent is the name of a component. For example, we have an
MDCMenuFoundation that is used by our
MDCMenu component, and which are both exported
publicly.
In order to implement a component via a foundation, take the following steps:
mdcFoundation.mdcFoundation.init()mdcFoundation.destroy()Because of the nature of our components, some of the adapter APIs can be quite complex. However, we are working as hard as we can to make writing adapters as easy and predictable as possible:
util objects which
implement those methods.Please file an issue with us if there are certain snags you've ran into trying to implement an adapter, or if you feel that we can provide better guidance on a particular problem. This is definitely something we want to know about.