1.26.0 • Published 5 days ago

@synergy-design-system/angular v1.26.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

@synergy-design-system/angular

This package provides Angular wrappers for Synergy Web Components.

This package aims for an improved UX when used in Angular applications:

  • Form support
  • Two way data-binding for properties
  • Auto-completion
  • Event handling

We are currently supporting Angular version ^16.2.12 and ^17.0.0 as well as Typescript version > 5.0.0.

Getting started

1. Package installation

Run the following steps to install the required packages.

# Install the required dependencies
npm install --save @synergy-design-system/angular @synergy-design-system/components @synergy-design-system/tokens

# If not already installed, install Angular's peer dependencies
# Install step for angular@17
npm install --save @angular/core@17 @angular/forms@17

# Optional: if icons shall be used, install the assets package
npm install --save @synergy-design-system/assets

2. Add the desired theme to your application

The components will not display correctly without the needed theme. Please include either light or dark theme in your application, for example in a newly installed Angular application, add the following to angular.json:

{
  "projects": {
    "your-project": {
      "architect": {
        "build": {
          "options": {
            "styles": ["@synergy-design-system/tokens/themes/light.css"]
          }
        }
      }
    }
  }
}

3. Load the Synergy Module to load all components

⚠️ This is a convenience feature only and WILL create bigger bundles! It is intended for bootstrapping applications in a quick way. It is recommended that you ship your own NgModule with only needed components. See below for more information!

This library is providing an NgModule named SynergyComponentsModule, which takes care of exporting all available Synergy Components. You may use it in the following way:

// src/app/app.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { AppComponent } from "./app.component";
import { SynergyComponentsModule } from "@synergy-design-system/angular";

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, SynergyComponentsModule],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

You will then be able to use the provided wrappers in the following way:

<!-- src/app/app.component.html -->
<syn-button type="submit"> Submit me </syn-button>

This example will render the provided <syn-button /> Angular component.


4. Usage of the components

All information about which components exist as well as the available properties, events and usage of a component, can be found at components in our documentation. The documentation is written for no specific web framework but only vanilla html and javascript.

An example demo repository with the usage of the Angular wrapper components can be found here.

The naming of the components for Angular is the same as in the documentation.

<!-- Webcomponents example -->
<syn-button> My Button </syn-button>
<!-- Angular wrapper example -->
<syn-button> My Button </syn-button>

5. Usage of attributes

In Angular attributes must be converted from kebab-case to camelCase (e.g. myAttribute instead of my-attribute)

The following two code examples show, how different attributes look like for web components and their Angular wrapper counterpart:

<!-- Webcomponents example -->
<syn-input
  label="Nickname"
  help-text="What would you like people to call you?"
  required
></syn-input>
<!-- Angular wrapper example -->
<syn-input
  label="Nickname"
  helpText="What would you like people to call you?"
  [required]="true"
></syn-input>

6. Usage of events

Custom events are named in the documentation as following: syn-change, syn-clear, ...

In the Angular wrapper these events can be used in two ways: either with the same naming as in the documentation or via camelCase with Event suffix.

syn-change-> synChangeEvent, syn-clear-> synClearEvent, ...

Note: Only for the camelCase variant (e.g. synChangeEvent) Angular will give auto completion in the html.

An example for both event usages are following:

<!-- Angular wrapper with original event name -->
<syn-input (syn-change)="synChange($event)"></syn-input>
<!-- Angular wrapper with specific event name -->
<syn-input (synChangeEvent)="synChange($event)"></syn-input>

If typescript is used, you can get the correct types for components and events from the @synergy-design-system/components package. An example for how these types can be used in case of event handling, is shown below:

<syn-input label="Surname" (synChangeEvent)="synChange($event)"> </syn-input>
  import type { SynChangeEvent, SynInput } from '@synergy-design-system/components';

  synChange(e: SynChangeEvent) {
    const input = e.target as SynInput;
    // Now we get access to all properties, methods etc. of the syn-input
    const surname = input.value;
    doSomething(surname);
  }

7.1. Usage of methods (DEPRECATED)

⛔️ This feature is deprecated, the methods defined below will not be available in the next major version of @synergy-design-system/angular! If you need to call methods on elements, please obtain a reference to the native element as shown below and call the method on the native element itself!

Components can have methods (like focus, click, stepUp, etc. ), which can trigger an action, if they are called.

In Angular they can be used by prefixing each method name with call.

focus -> callFocus, click-> callClick, ...

An example for calling such a method in an Angular component is shown here:

import { Component, ViewChild } from '@angular/core';
import { SynInputComponent } from '@synergy-design-system/angular';

@Component({
  selector: 'home',
  styleUrls: ['./home.styles.css'],
  template: `
    <syn-input #count label="My count" type="number" value="5"></syn-input>
    <syn-button (click)="handleClick()">Increment</syn-button>
  `
})
export class Home {
 @ViewChild('count') count!: SynInputComponent;

  handleClick() {
    // Increment the count via calling the method
    this.count.callStepUp();
  }
}

7.2. Obtaining a reference to the underlying native element

Sometimes, there is a need to interact directly with the underlying native web-component. For this reason, the library exposes a nativeElement property for all angular components.

import { Component, ViewChild } from '@angular/core';
import { SynInputComponent } from '@synergy-design-system/angular';

@Component({
  selector: 'home',
  styleUrls: ['./home.styles.css'],
  template: `
    <syn-input #count label="My count" type="number" value="5"></syn-input>
    <syn-button (click)="handleClick()">Increment</syn-button>
  `
})
export class Home {
 @ViewChild('count') count!: SynInputComponent;

  handleClick() {
    // Increment the count via calling the method
    this.count.nativeElement.stepUp();
  }
}

8. Using synergy components in @angular/forms via SynergyFormsModule

There are two ways to use the Angular wrappers in forms: Either manual by adding a ngDefaultControl to the component or via our custom SynergyFormsModule.

SynergyFormsModule provides automatic support for all currently available Synergy form input elements by wrapping them with custom Angular ValueAccessors.

To use the module, please proceed the following way:

// src/app/app.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { ReactiveFormsModule } from "@angular/forms";
import { AppComponent } from "./app.component";
import {
  SynergyComponentsModule,
  SynergyFormsModule,
} from "@synergy-design-system/angular";

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    SynergyComponentsModule,
    SynergyFormsModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

You will then be able to use the provided wrappers in the following way:

<!-- src/app/app.component.html -->
<syn-input
  formControlName="test"
  type="text"
  name="test"
  [title]="myLabel"
  type="text"
  [required]="true"
>
  <span slot="label"> {{myLabel}} </span>
</syn-input>

Note that all elements that have one of the following attributes will be used as selectors:

  • Elements defining a [formControlName] attribute
  • Elements defining a [formControl] attribute
  • Elements defining a [ngModel] attribute

9. Using two way data binding

Input Controls like <syn-input />, <syn-checkbox /> or <syn-select /> also support Angulars two way data binding on their corresponding value or checked properties.

You can use this in the following way:

// Example empty component with
// one property using two way data binding
import { Component } from "@angular/core";

@Component({
  selector: "home",
  styleUrls: ["./home.styles.css"],
  template: `
    <syn-input [(value)]="inputValue" placeholder="Type something"></syn-input>

    Current Value is: {{ inputValue }}
  `,
})
export class Home {
  inputValue: string = "Type something";
}

Development

To create a new version of this package, proceed in the following way:

  1. Check out the Synergy Design System Repository.
  2. Run pnpm i -r to install all dependencies.
  3. Build the @synergy-design-system/components package (or run pnpm build in the project root to build everything).
  4. Move to to packages/_private/angular-demo and use pnpm start to spin up a local vite project using react and typescript to validate the build.

⚠️ The build process will always try to sync this packages package.json.version field with the latest version from @synergy-design-system/components! Therefore, it is best to not alter the version string

1.25.0

6 days ago

1.24.1

6 days ago

1.26.0

5 days ago

1.24.0

7 days ago

1.23.0

13 days ago

1.23.1

13 days ago

1.22.0

22 days ago

1.21.0

25 days ago

1.20.2

25 days ago

1.19.0

27 days ago

1.17.2

28 days ago

1.18.0

27 days ago

1.17.1

28 days ago

1.20.1

27 days ago

1.20.0

27 days ago

1.17.0

1 month ago

1.16.0

1 month ago

1.15.0

1 month ago

1.14.0

2 months ago

1.13.0

2 months ago

1.12.0

2 months ago

1.11.0

2 months ago

1.10.1

2 months ago

1.9.0

3 months ago

1.10.0

3 months ago

1.8.0

3 months ago

1.7.0

3 months ago

1.6.1

3 months ago

1.6.0

4 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.4.1

4 months ago

1.4.0

4 months ago

1.3.0

4 months ago

1.2.2

4 months ago

1.2.1

4 months ago

1.2.0

4 months ago

1.1.0

4 months ago

1.0.2

5 months ago

1.0.1

6 months ago

1.0.0

6 months ago

1.0.0-main.20

6 months ago

1.0.0-main.18

6 months ago

1.0.0-main.19

6 months ago

1.0.0-main.13

6 months ago

1.0.0-main.16

6 months ago

1.0.0-main.17

6 months ago

1.0.0-main.14

6 months ago

1.0.0-main.15

6 months ago

1.0.0-main.12

6 months ago

1.0.0-main.11

6 months ago

1.0.0-main.10

6 months ago

1.0.0-main.9

6 months ago

1.0.0-main.8

6 months ago

0.1.0

6 months ago