Component Driven Development is where your UI is built up from a series of components. Each component is a self-contained piece of code that handles its own rendering, state and behaviour.
One popular library that has been overlooked as a component library is Jquery. Not everyone sees it as such, but I'm about to show you how.
What you need from a component
A component should be:
Composable: You should be able to use it in combination with other components.
Stateful: It should be able to manage its own state.
Configurable: It should be able to be configured to behave in different ways.
So such a plugin needs to be able to work amongst the markup of other plugins. We should be able to configure each instance separately. And we should be able to manage the state of each instance separately.
To that end, lets start with the basics:
with this rudimentary plugin, we can now do the following:
But we can make the html DX better by allowing the plugin to be configured via separate data attributes: