Adding a new component
To add a new component to this project, and to its showcase powered by storybook, follow the following simple guidelines. Throughout this guide, we will pretend to be adding a new component called myComponent.
Note: the project is build of 3 different projects:
- onap-ui-common - contains HTML and SCSS files for all components
- onap-ui-angular - contains Angular components according to the HTML defined in onap-ui-common
- onap-ui-react - contains React components according to the HTML defined in onap-ui-common
In your forked repository, after making sure your master
branch is synced with original repository's master
, create a new branch named feature/myComponent.
Note: This should be done in all 3 projects: onap-ui-common, onap-ui-angular, onap-ui-react
- Under the components directory (onap-ui-common) at the root of the project, create a new directory with the name of your component.
- Create one .scss file, declaring the appropriate classes and rules for your component, following the css guidelines in terms of hierarchy and naming methodology. Make sure to name your file by the following convention: _myComponent.scss.
- Create multiple .html files, one for each of the possible styles of your component, using the classes you declared in the .scss file.
Add the appropriate import for your new .scss file in scss/_components.scss:
@import ../components/myComponent.scss;
The next step is to use your html and scss structure and implement them in React and Angular.
See onap-ui-react project for more details
Create a new folder with component name under src/angular. Inside the folder create component module, ts file and HTML file. Keep the names according to the rule: MyComponent.component.ts, and implement the component. Make sure to exporting your component.
Note: due to issues compiling the HTML files, all HTML files as extension of .ts
Create component typescript file
// src/angular/MyComponent/my-component.component.ts
import { Component, Input } from "@angular/core";
import { template } from "./my-component.component.html";
@Component({
selector: "my-component",
template: template
})
export class MyComponent {
@Input() public testId: string;
@Input() public text: string;
constructor() {}
public onClick = (e): void => {
// Do something
}
}
Create component HTML file
// src/angular/MyComponent/my-component.component.html.ts
export const template = `
<button class="my-button [attr.data-tests-id]="testId">{{ text }}</button>
`;
Create component module file
// src/angular/MyComponent/my-component.module.ts
import { NgModule } from "@angular/core";
import { MyComponent } from "./my-component.component";
@NgModule({
declarations: [MyComponent],
imports: [],
exports: [MyComponent],
})
export class MyComponentModule {}
Export the component in src\angular\components.ts file
// src/angular/components.ts
export { MyComponent } from "./src/angular/my-component/my-component.component";
See Adding a component to storybook.
Push your branch to your fork's origin/feature/myComponent, and create a new pull request from your fork to the original repo.
If your changes require a new release to npm
, please contact the administrators.
Hurray! your component is live at the showcase, and if it was released can be consumed from npm.