material design
For now it totally went with material components for the web.
- Because it's from google, which invented material design
- It's the successor of material design lite, which I used before.
- It has good constructs for building modules
Material design : material_design Material components for web : material_web Material components architecture : material_components
architecture
MDC Web is split into packages which can be either:
- subsystems: usually some css style or motion
- component: bound to a html component
Components tend to rely on subsystem packages, but rarely on other component packages.
Each component should be usable separate from any other component.
Subsystems
Subsystems usually end up altering css , and use sass for that, each package compiles it's sass files into a single .css file.
Components
components have two pieces:
- Foundation: this is to reuse foundation code across multiple systems like react or angular.
- Adapter: this is an interface with all the foundations methods, there can be many implementations of the adapter.
The relation between the two is : Foundation has-a adapter.
getting started
On the website, the example to build is a component called redblue-toggle. This is a very simple button that alternates between the two colors.
It is advised to code the component as a simple prototype, not worrying about turning it into a foundation yet.
You can view a running example at codepen : redblue_start
The important code snippets are :
| red blue example | |
|---|---|
This is the entry within your html page, the "redblue-toggle__color" class will bind to the toggle functionality. This is the prototype for that :
CSS is :
So this would tie the button to the code in this line :
| code | |
|---|---|
To make this applicable to different frameworks we need to split it into one Foundation and (possibly) more adapters. The example takes a sub step by replacing interface functions with lines like :
| toggle | |
|---|---|
Then this fake function is mapped onto an Adapter method signature :
SOMEHOW_GET_ATTRIBUTE(attr: string) => string getAttr(attr: string) => string
I leave this for now, since I realize this is not what I expected it to be, nor do I need it. These are not modules as i want, but these are for creating components fitting multiple framework. I will definitely choose 1 framework and also the only one to use it. .. maybe later.