Before you begin, please review our contribution guidelines:)
This documentation is intended for developers who wish to contribute to the core of the framework.
If you are looking to use the framework, please refer to the general documentation.
To start developing in sib-core
, you need:
# 1. Install the dependencies
npm install
# 2. Build the framework
npm run build:dev
# 3. Launch a web server
npm run serve
You can now see examples at http://127.0.0.1:3000.
To develop new features for sib-core
, you can add an HTML example file in /examples
directory and link it in /index.html
.
Don't forget to import the framework:
<script type="module" src="../dist/index.js"></script>
You can now write HTML using sib-core
and test it in your browser.
You can test the API by running:
npm run test
Here is a simplified schema of how the API works to create a component:
static get name() {
return 'string';
}
The static name
getter returns a string that will be used to register the component tag name or the mixin name. This getter is required.
static get use() {
return [Mixin];
}
The static use
getter return an array of mixins to install. The mixin compositor install mixin recursively.
static get attributes() {
return {
myProp: {
type: String,
default: '',
callback(newValue, oldValue) {
//
},
required: false,
}
}
}
To declare an attribute, use the static attributes
getter. It should return an object where each property will be bound with its kebab-case equivalent. Example: myProp
is bound to my-prop
. Each property should be an object with the following :
- type
- description: The JavaScript type of your attribute data
- required: false
- default: String
- default
- description: A default value
- required: false
- default: undefined
- required
- description: Indicates if this attribute required. If
true
, an error is thrown if not provided - required: false
- default: false
- description: Indicates if this attribute required. If
- callback
- description: A function invoked when the attribute changed. It receives 2 arguments :
newValue
,oldValue
. - required: false
- default: undefined
- description: A function invoked when the attribute changed. It receives 2 arguments :
The mixin compositor registers all attribute recursively, keeping the last declaration.
static get initialState() {
return {
click: 0,
};
}
The static `initialState`` getter should return an object containing the initial state of the component. The mixin compositor recursively merges the initial state, ensuring that the last declaration is preserved.
Every property in the initial state could be watched by the component in order to provide reactivity.
created() {
console.log('component is created');
}
Available hook:
- created
- attached
- detached
Each hook is a function. The mixin compositor appends hooks. If a deeper mixin registers a created hook, its function will be called before the current created hook.
myMethod() {
console.log('Hi!');
}
To declare methods, simply add a method to your mixin. The mixin compositor retains the last declared method.
Here is a simplified schema of the organization and the responsibilities of the classes of the core classes:
A solid-display
component can show a list of resources and apply various filters to sort, group, and otherwise transform these resources. Below is a schema illustrating the sequence of these transformations:
A widget is a small component responsible for managing a value. Widgets are composed and built on demand when the developer requests them. The widget name is parsed and analyzed to add the appropriate mixins. Here is a schema showing how this process works:
Values are provided to a widget through its value
attribute. For the widgets defined by sib-core, the value can have different types:
string
: This is the most common and encouraged use caseboolean
(checkbox): The value is converted to string ('true'
or'false'
)number
(input number): The value is converted to a stringcontainer
(multiple, multiple form): The value is converted to@id
and resolved by the widget
Custom widgets, which still use the old API, can accept the following types:
string
resource
Proxycontainer
Proxy
With display widgets, you can retrieve the value through its HTML attribute:
const value = widgetElement.getAttribute('value');
// or thanks to the core API
const value = widgetElement.component.value;
For form widgets, where the value can be changed by the user, you can retrieve it as follows:
const value = widgetElement.component.getValue();
Under the hood, the core locates elements with a `data-holder`` attribute and retrieves the value from their properties, rather than their attributes, which hold the initial value of the widget.
A widget can have:
- 1
data-holder
element (simple inputs) - 2
data-holder
elements (range filter inputs) - multiple
data-holder
elements (multiple-form)
Help us to improve the documentation! Feel free to ask for clarification or ask questions. This helps us to improve our documentation.
Thanks you!