🚀
Getting started with Atomico
This guide will know the essentials to start developing webcomponents with Atomico
Thanks for being here and getting started with Atomico. Let's talk a little about what Atomico offers today:
  1. 1.
    Development agility, Atomico's functional approach simplifies code at all stages of development.
  2. 2.
    Lightweight inside and out, Atomico allows you to create a component with less code and with a low dependency impact. Approximately 3kb.
  3. 3.
    Really fast, Atomico has a good performance in the browser and an agile development experience. Let's understand what a webcomponent created with Atomico looks like:
1
// IMPORT
2
import { c, html, css } from "atomico";
3
4
// WEBCOMPONENT
5
function component({ message }) {
6
return html`<host shadowDom>${message}</host>`;
7
}
8
9
// WEBCOMPONENT PROPERTIES AND ATTRIBUTES
10
component.props = {
11
message: String,
12
};
13
14
// WEBCOMPONENT APPEARANCE
15
component.styles = css`
16
:host {
17
font-size: 30px;
18
}
19
`;
20
21
// DEFINITION OF THE WEBCOMPONENT AS A TAG
22
customElements.define("my-component", c(component));
Copied!
Let's analyze the code in parts ...

Import

1
import { c, html, css } from "atomico";
Copied!
What have we imported?
  1. 1.
    c: Function that transforms the functional component into a standard customElement.
  2. 2.
    html: Function to declare the template of our component, you can also use JSX.
  3. 3.
    css: Function that allows creating the CSSStyleSheet (CSS) for our component as long as it declares the shadowDom.

Webcomponent

1
function component({ message }) {
2
return html`<host shadowDom>${message}</host>`;
3
}
Copied!
Our component function receives all the props (Properties and Attributes) declared in component.props, the component function declares all the logic and template of the webcomponent. An important rule within Atomico is "every component created with Atomico must always return the tag".

Reactive properties and attributes of the webcomponent

Atomico detects the prop (Properties and Attributes) of the component thanks to the association of the props object, this through the use of index and value allows you to define:
  1. 1.
    index: Name of the property and attribute.
  2. 2.
    value: type of the prop.
1
component.props = {
2
message: String,
3
};
Copied!
From the example we can infer that Atomico will create in our webcomponent a property and attribute called message and this can only receive values of the String type.

Appearance of the webcomponent.

Atomico detects the static styles of your component thanks to the association of the styles property:
1
component.styles = css`
2
:host {
3
font-size: 30px;
4
}
5
`;
Copied!
styles accepts individual or list CSSStyleSheet (CSS) values, the return from the css function is a standard CSSStyleSheet, so it can be shared outside of Atomico.

Definition of your webcomponent

1
customElements.define("my-component", c(component));
Copied!
To create our standard customElement we will have to deliver our functional component to the c function of the Atomico module, the c function will generate as a return a customElement that can be defined or extended.

Example

WebComponents.dev
WebComponents.dev