@bionamic/component
v6.0.0
Published
Bionamic component library
Downloads
50
Readme
Bionamic component library
The library is used by the Bionamic application and implements basic components for the JC-Bn system. The JC side is responsible for handling state and actions. The Bn side is responsible for rendering the state and triggering actions from user interactions. Every component has an interface which defines what state and actions are needed to render the component. For components that implement a dedicated JC class, the interface object can be created using the helper "getI..." function. Some of the more basic components (which do not require any state) do not need a JC class, instead, conventient pure interface functions are provided.
Example: MyFirstComponent
Naming
The following is an example of how the different classes for a component should be named.
Interface
Interfaces are named by placing the component name after "I" (which stands for "Interface"). Example: IMyFirstComponent
Interfaces use functions both to get and set values and these functions are prefixed with "get" or "set". Examples: getValue(): () => string; setValue(): (value: string) => void;
JC
JC classes are named by placing the component name after "JC" (which stands for "Javascript Component"). Example: JCMyFirstComponent
The JC class provides an interface function named "getIMyFirstComponent" which returns an interface object (which fulfilles IMyFirstComponent) and can be used to render the corresponding Bn component.
Bn
Bn classes are named by placing the component name after "Bn" (which stands for "Bionamic"). Example: BnMyFirstComponent
Tags
The web component html tags are named by placing the component name (lowercased and split with "-") after "bn-" Example: <bn-my-first-component>
File structure
A component is defined inside a folder (named the lowercased component name, "myfirstcomponent" in this example) in the "src" directory. The folder contains an "interface.ts" file defining the JC-Bn interface and any necessary helper types. The "myfirstcomponent" folder also contains a "jc" folder (containing the JC class and any helper logic) and a "bn" folder (containing the Bn class written as a Lit component).