npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@synergy-design-system/angular

v2.11.6

Published

Angular wrappers for the Synergy Design System

Downloads

1,091

Readme

@synergy-design-system/angular

This package provides Angular wrappers for Synergy Web Components.

It 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, ^17.0.0 and ^18.0.0 as well as Typescript version > 5.0.0.

Known issues and limitations

Got any problems using our Angular wrappers? Please take a look at our list of known issues and limitations before creating a ticket.

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

# Optional: Install the styles utility package
npm install --save @synergy-design-system/styles

# 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 and utility classes. Please include either light or dark theme in your application, for example in a newly installed Angular application, add the following to angular.json:

This example includes the optional @synergy-design-system/styles package. If you do not want to use the styles package, just remove the last import.

{
  "projects": {
    "your-project": {
      "architect": {
        "build": {
          "options": {
            "styles": [
              "@synergy-design-system/tokens/themes/light.css",
              "@synergy-design-system/components/index.css",
              "@synergy-design-system/styles/index.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. Obtaining a reference to the underlying native element (e.g. for usage of methods)

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