0.8.5-0 • Published 4 years ago

@filip.dobrovolny/aws-amplify-ui-components v0.8.5-0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
4 years ago

Amplify UI Components

Amplify UI Components is an open-source UI component library that encapsulates cloud-connected workflows inside of framework-agnostic UI components.

Frameworks

FrameworkPackageVersionREADMEsQuick Start
React@aws-amplify/ui-reactversionREADME.mdReact
Angular@aws-amplify/ui-angularversionREADME.mdAngular
Vue@aws-amplify/ui-vueversionREADME.mdVue
Web Components@aws-amplify/ui-componentsversionREADME.mdWeb Components

Quick Start

In this Quick Start guide you will set up an Authenticator component and the cloud resources required to use it inside of your app.

Prerequisites

Frameworks

React

Installation
yarn add aws-amplify@ui-preview @aws-amplify/ui-react@ui-preview
Usage
import React from 'react';
import Amplify from 'aws-amplify';
import { AmplifyAuthenticator, AmplifySignOut } from '@aws-amplify/ui-react';
import awsconfig from './aws-exports';

Amplify.configure(awsconfig);

const App = () => {
  <AmplifyAuthenticator>
    <div>
      My App
      <AmplifySignOut />
    </div>
  </AmplifyAuthenticator>;
};

Angular

Installation
yarn add aws-amplify@ui-preview @aws-amplify/ui-angular@ui-preview
Usage

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

import { AmplifyUIAngularModule } from '@aws-amplify/ui-angular';
import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';

Amplify.configure(awsconfig);

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

app.component.html

<amplify-authenticator>
  <div>
    My App
    <amplify-sign-out></amplify-sign-out>
  </div>
</amplify-authenticator>

Vue

Installation
yarn add aws-amplify@ui-preview @aws-amplify/ui-vue@ui-preview
Usage

main.ts

import Vue from 'vue';
import App from './App.vue';
import '@aws-amplify/ui-vue';
import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';

Amplify.configure(awsconfig);

new Vue({
  render: h => h(App),
}).$mount('#app');

App.vue

<template>
  <amplify-authenticator>
    <div>
      My App
      <amplify-sign-out></amplify-sign-out>
    </div>
  </amplify-authenticator>
</template>

Web Components

Installation
yarn add aws-amplify@ui-preview @aws-amplify/ui-components@ui-preview
Usage

app.js

import '@aws-amplify/ui-vue';
import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';

Amplify.configure(awsconfig);

index.html

<!DOCTYPE html>
<html lang="en">
  <body>
    <amplify-authenticator>
      <div>
        My App
        <amplify-sign-out></amplify-sign-out>
      </div>
    </amplify-authenticator>

    <script src="app.js"></script>
  </body>
</html>

Components

Customization

Amplify UI Components use slots to allow for component customization. Component customization and slot usage is exemplified below.

Amplify Authenticator

Slots

You can override the components listed above and pass them into these slots to preserve the authenticator state flow.

NameDescription
"sign-in"Content placed inside of the sign in workflow for when a user wants to sign into their account
"confirm-sign-in"Content placed inside of the confirm sign in workflow for when a user needs to confirm the account they signed in with
"sign-up"Content placed inside of the sign up workflow for when a user wants to register a new account
"confirm-sign-up"Content placed inside of the confirm sign up workflow for when a user needs to confirm the account they signed up with
"forgot-password"Content placed inside of the forgot password workflow for when a user wants to reset their password
"require-new-password"Content placed inside of the require new password workflow for when a user is required to update their password
"verify-contact"Content placed inside of the verify-contact workflow for when a user must verify their contact information
"totp-setup"Content placed inside of the totp-setup workflow for when a user opts to use TOTP MFA
"greetings"Content placed inside of the greetings navigation for when a user is signed in

Frameworks

React

import { AmplifyAuthenticator, AmplifySignIn, AmplifySignUp } from '@aws-amplify/ui-react';

const App = () => {
  <AmplifyAuthenticator>
    <AmplifySignIn headerText="My Custom Sign In Header" slot="sign-in" />
    <AmplifySignUp headerText="My Custom Sign Up Header" slot="sign-up" />

    <div>
      My App
      <AmplifySignOut />
    </div>
  </AmplifyAuthenticator>;
};

Alternatively, you can use the withAuthenticator higher-order component (HoC):

import { withAuthenticator } from '@aws-amplify/ui-react';

...

export default withAuthenticator(App);
// or
export default withAuthenticator(App, { /* ...amplifyAuthenticatorSettings */ })
});

Angular

<amplify-authenticator>
  <amplify-sign-in header-text="My Custom Sign In Header" slot="sign-in" />
  <amplify-sign-up header-text="My Custom Sign In Header" slot="sign-up" />

  <div>
    My App
    <amplify-sign-out></amplify-sign-out>
  </div>
</amplify-authenticator>

Vue

<amplify-authenticator>
  <amplify-sign-in header-text="My Custom Sign In Header" slot="sign-in" />
  <amplify-sign-up header-text="My Custom Sign In Header" slot="sign-up" />

  <div>
    My App
    <amplify-sign-out></amplify-sign-out>
  </div>
</amplify-authenticator>

Web Components

<amplify-authenticator>
  <amplify-sign-in header-text="My Custom Sign In Header" slot="sign-in" />
  <amplify-sign-up header-text="My Custom Sign In Header" slot="sign-up" />

  <div>
    My App
    <amplify-sign-out></amplify-sign-out>
  </div>
</amplify-authenticator>

Theming

Theming for the UI components can be achieved by using CSS Variables. You can enable theming in your app by overriding the below mentioned CSS variable values. To do that, add the following code in root css file.

:root{

  --amplify-primary-color: #ff6347;
  --amplify-primary-tint: #ff7359;
  --amplify-primary-shade: #e0573e;

  }

Supported CSS Custom properties

For Typography

Custom PropertiesDefault Value
--amplify-font-family'Amazon Ember', 'Helvetica Neue Light', 'Helvetica Neue', 'Helvetica', 'Arial', 'sans-serif'
--amplify-text-xxs0.75rem
--amplify-text-xs0.81rem
--amplify-text-sm0.875rem
--amplify-text-md1rem
--amplify-text-lg1.5rem
--amplify-text-xl2rem
--amplify-text-xxl2.5rem

For Colors

Custom PropertiesDefault Value
--amplify-primary-color#ff9900
--amplify-primary-contrastvar(--amplify-white)
--amplify-primary-tint#ffac31
--amplify-primary-shade#e88b01
--amplify-secondary-color#152939
--amplify-secondary-contrastvar(--amplify-white)
--amplify-secondary-tint#31465f
--amplify-secondary-shade#1F2A37
--amplify-tertiary-color#5d8aff
--amplify-tertiary-contrastvar(--amplify-white)
--amplify-tertiary-tint#7da1ff
--amplify-tertiary-shade#537BE5
--amplify-grey#828282
--amplify-light-grey#c4c4c4
--amplify-white#ffffff
--amplify-red#dd3f5b
--amplify-blue#099ac8

Amplify Authenticator usernameAlias

The amplify-authenticator component has the ability to sign in or sign up with email or phone_number instead of default username. To achieve this, you first need to setup the userpool to allow email or phone number as the username using the cli workflow or through the Cognito Console. To reflect this in the amplify-authenticator component, you can use the usernameAlias property. It can take one of the three values - email, phone_number or username. Default is set to username.

Usage:

// react
<AmplifyAuthenticator usernameAlias="email" />

// angular, vue or web components
<amplify-authenticator username-alias="phone_number" />

Amplify Authenticator federated

The amplify-authenticator component supports Federated Sign In through Cognito Identity Pools (IDP) with external providers like Amazon, Auth0, Facebook, & Google.

The federated prop implements the FederatedConfig:

export interface FederatedConfig {
  auth0Config?: {
    audience?: string;
    clientID: string;
    domain: string;
    responseType: string;
    redirectUri: string;
    returnTo?: string;
    scope?: string;
  };
  amazonClientId?: string;
  facebookAppId?: string;
  googleClientId?: string;
  oauthConfig?: {
    [key: string]: any;
  };
}

Usage:

const federated = {
  amazonClientId: "your_amazon_client_id",
  facebookAppId: "your_facebook_app_id",
  googleClientId: "your_google_client_id",
  oauthConfig: {
    redirectSignIn: "http://localhost:1234/",
    redirectSignOut: "http://localhost:1234/",
  }
}

// react
<AmplifyAuthenticator federated={federated} />

// angular, vue, or web components
<amplify-authenticator federated={federated} />

Migration Guide

React

Installation
- yarn add aws-amplify-react
+ yarn add @aws-amplify/ui-react@ui-preview
Usage
- import { Authenticator } from 'aws-amplify-react';
+ import { AmplifyAuthenticator } from '@aws-amplify/ui-react';

const App = () => (

+ <AmplifyAuthenticator>
- <Authenticator>
    <div>
      My App
+     <AmplifySignOut />
    </div>
+ </AmplifyAuthenticator>;
- </Authenticator>
);

If you're using the withAuthenticator higher-order component (HoC):

- import { withAuthenticator } from 'aws-amplify-react';
+ import { withAuthenticator } from '@aws-amplify/ui-react';

...

export default withAuthenticator(App);

Note: If you were providing additional options to withAuthenticator (e.g. includeGreetings, authenticatorComponents, federated, theme), these have changed:

amplify-authenticator#properties

Angular

Installation
- yarn add aws-amplify-angular
+ yarn add @aws-amplify/ui-angular@ui-preview
Usage

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
- import { AmplifyAngularModule, AmplifyService } from 'aws-amplify-angular';
+ import { AmplifyUIAngularModule } from '@aws-amplify/ui-angular';
import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';

Amplify.configure(awsconfig);

@NgModule({
  declarations: [AppComponent],
- imports: [AmplifyAngularModule, BrowserModule],
+ imports: [AmplifyUIAngularModule, BrowserModule],
- providers: [AmplifyService],
+ providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

Vue

Installation
- yarn add aws-amplify-vue
+ yarn add @aws-amplify/ui-vue@ui-preview
Usage

main.ts

import Vue from 'vue';
import App from "./App.vue";
- import Amplify, * as AmplifyModules from 'aws-amplify'
- import { AmplifyPlugin } from 'aws-amplify-vue'
+ import '@aws-amplify/ui-vue';
+ import Amplify from 'aws-amplify';
+ import awsconfig from './aws-exports';

Amplify.configure(awsconfig);

new Vue({
  render: h => h(App),
}).$mount('#app');

Built With Stencil