<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Fernando Mendoza</title>
    <description>The latest articles on DEV Community by Fernando Mendoza (@fm3ndoza).</description>
    <link>https://dev.to/fm3ndoza</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F136572%2Fa1a36154-67c3-415b-adf7-9577d4fd27d2.jpg</url>
      <title>DEV Community: Fernando Mendoza</title>
      <link>https://dev.to/fm3ndoza</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fm3ndoza"/>
    <language>en</language>
    <item>
      <title>Create an eCommerce app with Ionic, Capacitor, and Commerce.js</title>
      <dc:creator>Fernando Mendoza</dc:creator>
      <pubDate>Thu, 21 Jan 2021 02:47:42 +0000</pubDate>
      <link>https://dev.to/fm3ndoza/create-an-ecommerce-app-with-ionic-capacitor-and-commerce-js-561i</link>
      <guid>https://dev.to/fm3ndoza/create-an-ecommerce-app-with-ionic-capacitor-and-commerce-js-561i</guid>
      <description>&lt;p&gt;For this tutorial, we'll be creating a single-page mobile app to display and purchase products using the Chec API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl3qgk0yruxywhsncgz5e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl3qgk0yruxywhsncgz5e.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we start, create an account at &lt;a href="https://commercejs.com/" rel="noopener noreferrer"&gt;Chec&lt;/a&gt;. Then add a few categories and products and grab a copy of your public API key (Settings &amp;gt; Developer). &lt;/p&gt;

&lt;p&gt;If you don't feel ready to create an account, you can use the test API key provided in their docs:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pk_184625ed86f36703d7d233bcf6d519a4f9398f20048ec&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stack
&lt;/h2&gt;

&lt;p&gt;Here's the stack that we're going to use for our app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ionic: 5.0.0&lt;/li&gt;
&lt;li&gt;Angular: 10.0.0&lt;/li&gt;
&lt;li&gt;Commerce.js: 2.3.0&lt;/li&gt;
&lt;li&gt;Capacitor: 3.0.0 (Beta)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;First, open your terminal and execute the following instruction to create a new Ionic project.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

ionic start IonicCommerce blank &lt;span class="nt"&gt;--type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;angular


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For this guide, we'll use Angular since it's the framework I feel more comfortable with.&lt;/p&gt;

&lt;p&gt;If everything went well, we should have our Ionic project based on the &lt;code&gt;list&lt;/code&gt; template on a new folder called IonicCommerce.&lt;/p&gt;

&lt;p&gt;The Ionic CLI will also ask if we want to add &lt;a href="https://capacitorjs.com/" rel="noopener noreferrer"&gt;Capacitor&lt;/a&gt;. This is optional but if you want to give it a try just make sure to review the required &lt;a href="https://capacitorjs.com/docs/getting-started/dependencies" rel="noopener noreferrer"&gt;dependencies&lt;/a&gt; for each platform. &lt;/p&gt;

&lt;p&gt;At the time of writing this post, the new Capacitor 3.0 is still in beta, for that reason the CLI will install the 2.4 version but I'm curious to try the new version so we'll skip the default integration for now.&lt;/p&gt;

&lt;p&gt;Now open the project in your code editor. For VSCode users run &lt;code&gt;code .&lt;/code&gt; in your command line, or open the app as you normally would do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Commerce.js
&lt;/h2&gt;

&lt;p&gt;Let's &lt;code&gt;cd&lt;/code&gt; into our project &lt;code&gt;cd ./IonicCommerce&lt;/code&gt;, and type &lt;code&gt;npm i @chec/commerce.js&lt;/code&gt; to install the SDK that later will help us working with the Chec API.&lt;/p&gt;

&lt;p&gt;Next, create a service to initialize and expose the Commerce.js instance by running the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

// This will create a file at src/services/commerce-client.service.ts
ionic g service services/commerce-client &lt;span class="nt"&gt;--skipTests&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's import and initialize the commerce.js instance as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Injectable&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Commerce&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@chec/commerce.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;environment&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/environments/environment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CommerceClientService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;mClient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Commerce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;commerceApiKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;production&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This a simple class with three members: a private property called 'mClient', a constructor, and a &lt;code&gt;getter&lt;/code&gt; that will be used later in the app to easily access the commerce.js client.&lt;/p&gt;

&lt;p&gt;When creating the Commerce.js instance we should pass two parameters: the API key that you can grab in your Chec Account and a boolean value to enable/disable the debug mode.&lt;/p&gt;

&lt;p&gt;Notice that we're importing the environment.ts file where we have defined the API key.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// environment.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;environment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;production&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;commerceApiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pk_184625ed86f36703d7d233bcf6d519a4f9398f20048ec&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Currently Typescript support for the Commerce.js SDK is in &lt;a href="https://github.com/chec/commerce.js/tree/feature/commerce.ts" rel="noopener noreferrer"&gt;WIP&lt;/a&gt;, so for now, we'll declare our commerce.js client as &lt;code&gt;any&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Display products
&lt;/h2&gt;

&lt;p&gt;Now that our service is all set, let's create a page to show the product catalog.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

// This will create a new folder under src/pages/products with all the component files.
ionic g page pages/products &lt;span class="nt"&gt;--spec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The first thing that we need to do is to inject our &lt;code&gt;CommerceClientService&lt;/code&gt; into the products page.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;CommerceClientService&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src/app/services/commerce-client.service&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductsPage&lt;/span&gt; &lt;span class="kr"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;OnInit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kr"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;commerce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CommerceClientService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now let's create a function to retrieve the products using our injected &lt;code&gt;CommerceClient&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;


&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;loadProducts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;products&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;commerce&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;products&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;// a network error occurred or something went wrong&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since &lt;code&gt;ngInit&lt;/code&gt; is executed once our component is created, it is the perfect place to invoke our &lt;code&gt;loadProducts&lt;/code&gt; method.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loadProducts&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For our view we're going to use the following structure:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;ion-header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-toolbar&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"dark"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-title&amp;gt;&lt;/span&gt;Products&lt;span class="nt"&gt;&amp;lt;/ion-title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-toolbar&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ion-header&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ion-content&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-list&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-item&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let product of products"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-thumbnail&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"--border-radius: 10px"&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"end"&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"product.media.source"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;[src]=&lt;/span&gt;&lt;span class="s"&gt;"product.media.source"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ion-thumbnail&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;{{ product.name }}&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ product.price.formatted_with_symbol }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;ion-button&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"dark"&lt;/span&gt; &lt;span class="na"&gt;(click)=&lt;/span&gt;&lt;span class="s"&gt;"onBuyNowButtonTouched(product)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          Buy now
        &lt;span class="nt"&gt;&amp;lt;/ion-button&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ion-item&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-list&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ion-content&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Notice the &lt;code&gt;&amp;lt;ion-button&amp;gt;&lt;/code&gt; has a binding to the &lt;code&gt;click&lt;/code&gt; event, so let's add a method to handle it in our component.&lt;/p&gt;

&lt;p&gt;When the button is pressed, we'll take the user to the hosted checkout URL to finish the checkout process.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;onBuyNowButtonTouched&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;checkout_url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;checkout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;__target&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Finally, let's build and serve our app by executing &lt;code&gt;ionic s&lt;/code&gt;. Once the app is up and running, navigate to the &lt;code&gt;/products&lt;/code&gt; path, and if everything is ok you should see the list with all the product catalog!&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: Capacitor 3.0 🌝
&lt;/h2&gt;

&lt;p&gt;Now let's see what Capacitor 3.0 can do for us.&lt;/p&gt;

&lt;p&gt;Install the Capacitor package as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm i @capacitor/core@next @capacitor/cli@next


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Run the following to set the app name and package id.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npx cap init


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Open the &lt;code&gt;src/main.ts&lt;/code&gt; file and import the Capacitor library.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;enableProdMode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;platformBrowserDynamic&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/platform-browser-dynamic&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./app/app.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;environment&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./environments/environment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Add this line&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@capacitor/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;production&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;enableProdMode&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;platformBrowserDynamic&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;bootstrapModule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AppModule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Deploy the app to an iOS simulator by executing the following commands:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm i @capacitor/ios@next
npx cap add ios
ionic build
npx cap run ios


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/q75lEmqVtCc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The cool thing with Capacitor 3.0 is that there's no need to open Xcode in order to build and run the app. The &lt;code&gt;npx cap run ios&lt;/code&gt; will put all the pieces together for us.&lt;/p&gt;

&lt;h2&gt;
  
  
  Last few words
&lt;/h2&gt;

&lt;p&gt;This is just a start to work with Commerce.js. There's so much to be done for a more robust commerce experience. &lt;/p&gt;

&lt;p&gt;With that said, I highly recommend checking out &lt;a href="https://gum.co/ionshop-ui" rel="noopener noreferrer"&gt;IonShop UI Headless&lt;/a&gt;, our premium template that comes with better Commerce.js integration, including customer authentication, cart, variants, and an integrated checkout with payment methods, shipping zones, taxes calculation, and more.&lt;/p&gt;

</description>
      <category>ionic</category>
      <category>angular</category>
      <category>commercejs</category>
      <category>cart</category>
    </item>
    <item>
      <title>How to customize the ion-menu-button in Ionic 5</title>
      <dc:creator>Fernando Mendoza</dc:creator>
      <pubDate>Thu, 29 Oct 2020 18:34:08 +0000</pubDate>
      <link>https://dev.to/fm3ndoza/how-to-customize-the-ion-menu-button-in-ionic-5-hmd</link>
      <guid>https://dev.to/fm3ndoza/how-to-customize-the-ion-menu-button-in-ionic-5-hmd</guid>
      <description>&lt;p&gt;As a quick introduction, the &lt;code&gt;ion-menu-button&lt;/code&gt; is a component that works together with the neat &lt;code&gt;ion-menu&lt;/code&gt;. That means that once added, the &lt;code&gt;ion-menu-button&lt;/code&gt; can open the &lt;code&gt;ion-menu&lt;/code&gt; automatically 🤓. Therefore, we don't need to worry about anything since Ionic will handle the click event internally for us.&lt;/p&gt;

&lt;p&gt;The thing is that sometimes you will have the requirement to show a different icon. Luckily for us, this can be achieved with the help of the &lt;code&gt;ion-icon&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;As many of you might know, this component has the ability to render any of the icons found on the &lt;a href="https://ionicons.com/" rel="noopener noreferrer"&gt;Ionicons&lt;/a&gt; library and custom assets like a local image and even better, an &lt;strong&gt;SVG&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;ion-toolbar&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-buttons&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"start"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-menu-button&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./assets/img/custom-menu.svg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ion-menu-button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-buttons&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-title&amp;gt;&amp;lt;/ion-title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ion-toolbar&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To define a custom asset for our &lt;code&gt;ion-icon&lt;/code&gt; is as easy as just passing the path of our file in the &lt;code&gt;src&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;Since SVG's are just files based on the XML format, let's first create it by opening the command line and running the instruction below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nb"&gt;touch&lt;/span&gt; ./src/assets/img/custom-menu.svg


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, let's open our newly created &lt;code&gt;custom-menu.svg&lt;/code&gt;. You can do this manually using your file explorer, or if you're using VSCode... 😎&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

code ./src/assets/img/custom-menu.svg


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now copy and paste the XML below into the &lt;code&gt;custom-menu.svg&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"22"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"20"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 22 20"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;defs&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
      .cls-1 {
        fill: currentColor;
      }
    &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/defs&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;g&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"translate(-23 -44)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"cls-1"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"22"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"1.8"&lt;/span&gt; &lt;span class="na"&gt;rx=&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"translate(23 44)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"cls-1"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"15"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"1.8"&lt;/span&gt; &lt;span class="na"&gt;rx=&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"translate(23 52)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"cls-1"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"22"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"1.8"&lt;/span&gt; &lt;span class="na"&gt;rx=&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"translate(23 60)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/g&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The cool part is that using this technique it's possible to customize the theme by just adding the &lt;code&gt;color&lt;/code&gt; attribute in the &lt;code&gt;ion-menu-button&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="c"&gt;&amp;lt;!-- Dark color --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"dark"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./assets/img/custom-menu.svg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi5uaado4n5tbljbuukjd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi5uaado4n5tbljbuukjd.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="c"&gt;&amp;lt;!-- Secondary color --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"secondary"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./assets/img/custom-menu.svg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fset3mo5ubg3565ee08y7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fset3mo5ubg3565ee08y7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="c"&gt;&amp;lt;!-- Tertiary color --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"tertiary"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./assets/img/custom-menu.svg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5d7wncgq5n2y92ty48kq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5d7wncgq5n2y92ty48kq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Demo:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://stackblitz.com/edit/ionic-5-custom-ion-menu-button?view=preview" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That's it! As always, I hope you've learned something new today.&lt;/p&gt;

&lt;p&gt;Hasta la próxima!&lt;/p&gt;

</description>
      <category>ionic</category>
      <category>angular</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Styling ion-tabs in Ionic 5</title>
      <dc:creator>Fernando Mendoza</dc:creator>
      <pubDate>Tue, 27 Oct 2020 17:24:37 +0000</pubDate>
      <link>https://dev.to/fm3ndoza/styling-ion-tabs-in-ionic-5-clm</link>
      <guid>https://dev.to/fm3ndoza/styling-ion-tabs-in-ionic-5-clm</guid>
      <description>&lt;p&gt;A couple of weeks ago I was given a design by a client where the tabs UI was quite different compared to the default appearance of the well-known &lt;code&gt;ion-tabs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When I saw the design my first thought was "oh boy here we go again... another UI challenge that probably will be resolved adding &lt;code&gt;position:absolute&lt;/code&gt; and a bit of sweet sugar courtesy of the &lt;code&gt;border-radius&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;Like some of you should know, &lt;code&gt;ion-tabs&lt;/code&gt; is one of the most complex components built in Ionic Framework. This web component is smart enough to manage different stack navigation for each tab declared in our template and in our routing module.&lt;/p&gt;

&lt;p&gt;The good news is that it's also flexible enough to allow us to customize the appearance with some user-defined styles.&lt;/p&gt;

&lt;p&gt;So, after some weird CSS experiments 🌝 the final result ended like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbexk5abm5hhykc9kx4g6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbexk5abm5hhykc9kx4g6.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get this design, the following markup was used:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;ion-tabs&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ion-tab-bar&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"bottom"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-tab-button&lt;/span&gt; &lt;span class="na"&gt;tab=&lt;/span&gt;&lt;span class="s"&gt;"home"&lt;/span&gt; &lt;span class="na"&gt;layout=&lt;/span&gt;&lt;span class="s"&gt;"icon-top"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"search"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;Explore&lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ion-tab-button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;ion-tab-button&lt;/span&gt; &lt;span class="na"&gt;tab=&lt;/span&gt;&lt;span class="s"&gt;"wishlists"&lt;/span&gt; &lt;span class="na"&gt;layout=&lt;/span&gt;&lt;span class="s"&gt;"icon-top"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"gift"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;Wishlists&lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ion-tab-button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;ion-tab-button&lt;/span&gt; &lt;span class="na"&gt;tab=&lt;/span&gt;&lt;span class="s"&gt;"groups"&lt;/span&gt; &lt;span class="na"&gt;layout=&lt;/span&gt;&lt;span class="s"&gt;"icon-top"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"people-circle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;Groups&lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ion-tab-button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;ion-tab-button&lt;/span&gt; &lt;span class="na"&gt;tab=&lt;/span&gt;&lt;span class="s"&gt;"account"&lt;/span&gt; &lt;span class="na"&gt;layout=&lt;/span&gt;&lt;span class="s"&gt;"icon-top"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"person"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;Account&lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ion-tab-button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-tab-bar&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/ion-tabs&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Nothing fancy here. This structure will be very familiar if you already have experience working with tabs in Ionic.&lt;/p&gt;

&lt;p&gt;The real magic happens in the component styles file.&lt;/p&gt;

&lt;p&gt;First, I targeted the &lt;code&gt;ion-tab-bar&lt;/code&gt; element. Since I only needed it to move it slightly from the bottom, I set the &lt;code&gt;position&lt;/code&gt; and the &lt;code&gt;bottom&lt;/code&gt; property to &lt;code&gt;relative&lt;/code&gt; and &lt;code&gt;20px&lt;/code&gt;, respectively.&lt;/p&gt;

&lt;p&gt;Also, the tabs shouldn't fill the whole width, so I modified the &lt;code&gt;width&lt;/code&gt; property to &lt;code&gt;92%&lt;/code&gt; and added &lt;code&gt;margin: 0 auto&lt;/code&gt; to align the element horizontally. Finally, I also set &lt;code&gt;border-radius: 16px&lt;/code&gt; to get that nice corners.&lt;/p&gt;

&lt;p&gt;The last thing was to add a line indicator right above the selected tab. For our fortune, the &lt;code&gt;.tab-selected&lt;/code&gt; class is brought automatically by Ionic, so just by using the pseudo-selector &lt;code&gt;::before&lt;/code&gt; I was able to add the desired indicator.&lt;/p&gt;

&lt;p&gt;By default, the line indicator will be transparent for all the &lt;code&gt;ion-tab-button&lt;/code&gt;, except the one with the &lt;code&gt;.tab-selected&lt;/code&gt; class.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;

&lt;span class="nt"&gt;ion-tab-bar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;92%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-tab-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;--color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;ion-color-medium&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="na"&gt;--color-selected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;ion-color-primary&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;transparent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;.tab-selected&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;ion-color-primary&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Demo:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://stackblitz.com/edit/ionic-5-custom-ion-tabs?view=preview" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>ionic</category>
      <category>angular</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Animating views with Ionic 5 and ion-segment</title>
      <dc:creator>Fernando Mendoza</dc:creator>
      <pubDate>Tue, 20 Oct 2020 20:01:50 +0000</pubDate>
      <link>https://dev.to/fm3ndoza/animating-views-with-ionic-5-and-ion-segment-5bho</link>
      <guid>https://dev.to/fm3ndoza/animating-views-with-ionic-5-and-ion-segment-5bho</guid>
      <description>&lt;p&gt;Hey there,&lt;/p&gt;

&lt;p&gt;This will be a short one where I just want to show you how you can animate views with Ionic 5 and the awesome &lt;code&gt;ion-segment&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;Afterward, you will be able to implement a UI similar to this:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1316798725738635265-225" src="https://platform.twitter.com/embed/Tweet.html?id=1316798725738635265"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1316798725738635265-225');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1316798725738635265&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;So, let's get started.&lt;/p&gt;

&lt;p&gt;For the template, we just need an &lt;code&gt;ion-segment&lt;/code&gt; with two or more &lt;code&gt;ion-segment-button&lt;/code&gt;, and two separated containers. I'll be using two &lt;code&gt;ion-list&lt;/code&gt; but feel free to use a &lt;code&gt;div&lt;/code&gt; or any other element according to your needs.&lt;/p&gt;

&lt;p&gt;Now we need to know when one of the &lt;code&gt;ion-segment-button&lt;/code&gt; is clicked or touched. This is as easy as adding the &lt;code&gt;ionChange&lt;/code&gt; event listener into the &lt;code&gt;ion-segment&lt;/code&gt; and pass a user-defined callback. For this example, mine is called &lt;code&gt;segmentChanged&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also, we use &lt;code&gt;*ngIf&lt;/code&gt; directive to show/hide the &lt;code&gt;ion-list&lt;/code&gt; according to the &lt;code&gt;segment&lt;/code&gt; value. We will change the value of this variable when our &lt;code&gt;segmentChanged&lt;/code&gt; callback is executed, as you will notice in our component file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;ion-segment&lt;/span&gt; &lt;span class="na"&gt;(ionChange)=&lt;/span&gt;&lt;span class="s"&gt;"segmentChanged($event)"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"list1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-segment-button&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"list1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;
      List 1
    &lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-segment-button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-segment-button&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"list2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;
      List 2
    &lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-segment-button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ion-segment&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;ion-list&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"segment === 'list1'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-item&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;List 1&lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-item&amp;gt;&lt;/span&gt;
  ...
&lt;span class="nt"&gt;&amp;lt;/ion-list&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;ion-list&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"segment === 'list2'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-item&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;List 2&lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-item&amp;gt;&lt;/span&gt;
  ...
&lt;span class="nt"&gt;&amp;lt;/ion-list&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app-my-page&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;templateUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-page.page.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;styleUrls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-page.page.scss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyPage&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;segment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;list1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nf"&gt;segmentChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;segment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once you implement the code above, you'll notice that the views are toggled correctly.&lt;/p&gt;

&lt;p&gt;But what about the nice animation that we saw in the video?&lt;/p&gt;

&lt;p&gt;The trick is to add the &lt;a href="https://animate.style/" rel="noopener noreferrer"&gt;animate.css&lt;/a&gt; library into our project and add the animations through CSS classes.&lt;/p&gt;

&lt;p&gt;I first learned &lt;a href="https://devdactic.com/5-animation-packages-ionic/" rel="noopener noreferrer"&gt;this technique&lt;/a&gt; from &lt;a href="https://twitter.com/schlimmson" rel="noopener noreferrer"&gt;Simon Grimm&lt;/a&gt;, a well-known expert and developer in the Ionic community.&lt;/p&gt;

&lt;p&gt;BTW I highly recommend checking out their website to learn more about Ionic and Angular.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Animate.css&lt;/strong&gt; is installed using a two-step process:&lt;/p&gt;

&lt;p&gt;First, open your terminal, navigate to your Ionic project, and run the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm &lt;span class="nb"&gt;install &lt;/span&gt;animate.css


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now open the &lt;code&gt;src/styles.css&lt;/code&gt; and add the following line to import the &lt;code&gt;animate.css&lt;/code&gt; library.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"~animate.css/animate.min.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note: If you don't have a &lt;code&gt;styles.css&lt;/code&gt; file, try to add the import statement in the global.scss file.&lt;/p&gt;

&lt;p&gt;Now, let's go back to our template and add the proper css classes:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;ion-list&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"animate__animated animate__slideInUp animate__fast"&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"segment === 'list1'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-item&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;List 1&lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-item&amp;gt;&lt;/span&gt;
  ...
&lt;span class="nt"&gt;&amp;lt;/ion-list&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;ion-list&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"animate__animated animate__slideInUp animate__fast"&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"segment === 'list2'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-item&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-label&amp;gt;&lt;/span&gt;List 2&lt;span class="nt"&gt;&amp;lt;/ion-label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-item&amp;gt;&lt;/span&gt;
  ...
&lt;span class="nt"&gt;&amp;lt;/ion-list&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And that's it! 😅 You can see the result below:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://stackblitz.com/edit/ionic-5-ion-segment-animated?view=preview" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>ionic</category>
      <category>angular</category>
      <category>javascript</category>
      <category>css</category>
    </item>
    <item>
      <title>How to create an Avatar Card with Ionic 5</title>
      <dc:creator>Fernando Mendoza</dc:creator>
      <pubDate>Fri, 16 Oct 2020 17:29:21 +0000</pubDate>
      <link>https://dev.to/fm3ndoza/how-to-create-an-avatar-card-in-ionic-5-2ipf</link>
      <guid>https://dev.to/fm3ndoza/how-to-create-an-avatar-card-in-ionic-5-2ipf</guid>
      <description>&lt;p&gt;Recently I had been working on a new app and I decided to share the progress on social media. Below is the original tweet, which as a write these lines has almost 2K views.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1316798725738635265-403" src="https://platform.twitter.com/embed/Tweet.html?id=1316798725738635265"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1316798725738635265-403');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1316798725738635265&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;It was also well-received on a popular Facebook group related to Ionic development. So I thought that it will be nice to share more technical stuff with the dev community.&lt;/p&gt;

&lt;p&gt;Some folks were asking mainly about 2 things: how to get the &lt;strong&gt;Avatar Card&lt;/strong&gt; and how to animate the views when the &lt;code&gt;ion-segment-button&lt;/code&gt; is clicked.&lt;/p&gt;

&lt;p&gt;In this post, we will review how to create that nice &lt;strong&gt;Avatar Card&lt;/strong&gt; design.&lt;/p&gt;

&lt;h4&gt;
  
  
  Card Avatar
&lt;/h4&gt;

&lt;p&gt;Before starting make sure that you're using &lt;strong&gt;Ionic 5&lt;/strong&gt;. Note that some classes and icons won't work on previous versions.&lt;/p&gt;

&lt;p&gt;As you can see in the code below, the card template is very straightforward. I added a &lt;code&gt;div&lt;/code&gt; to act as a container for the image and the camera button. Notice that we're also applying the class &lt;code&gt;img-wrapper&lt;/code&gt; in order to style the container and their children easily.&lt;/p&gt;

&lt;h5&gt;
  
  
  Template
&lt;/h5&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;ion-card&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"light"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"img-wrapper"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./assets/imgs/lady_3.jpg"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-button&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"light"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"icon-only"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"camera-outline"&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"medium"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ion-button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ion-card-content&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ion-text-center"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Zahra Zamin&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ion-text&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"medium"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"display: flex;"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ion-justify-content-center"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;ion-icon&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"location-outline"&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"medium"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/ion-icon&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;2345 Street, Ohio, USA.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ion-text&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ion-card-content&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ion-card&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h5&gt;
  
  
  Styles
&lt;/h5&gt;

&lt;p&gt;To put the Avatar at the top-center, we will set the &lt;code&gt;img-wrapper&lt;/code&gt; position to &lt;code&gt;absolute&lt;/code&gt;. This will allow us to move the container from their &lt;em&gt;relative&lt;/em&gt; position using the &lt;code&gt;top&lt;/code&gt; and &lt;code&gt;left&lt;/code&gt; attributes.&lt;/p&gt;

&lt;p&gt;To center our container horizontally the &lt;code&gt;left&lt;/code&gt; property should be equal to &lt;code&gt;50%&lt;/code&gt; and with some &lt;code&gt;transform&lt;/code&gt; magic our &lt;code&gt;img-wrapper&lt;/code&gt; should be good to go.&lt;/p&gt;

&lt;p&gt;It's important to add the following attributes to the &lt;code&gt;ion-card&lt;/code&gt; as well: &lt;code&gt;position: relative&lt;/code&gt; and &lt;code&gt;overflow: visible&lt;/code&gt;. Otherwise, our &lt;code&gt;img-wrapper&lt;/code&gt; will be displayed incorrectly. &lt;/p&gt;

&lt;p&gt;We also added &lt;code&gt;padding-top: 60px&lt;/code&gt; to prevent the &lt;code&gt;ion-card-content&lt;/code&gt; from being displayed below our &lt;code&gt;img-wrapper&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Note that to make the ion-button appear at the bottom-right we set their position to &lt;code&gt;absolute&lt;/code&gt; and also we modified their appearance with CSS variables. To make it circular the key is to set the CSS variable &lt;code&gt;--border-radius: 50%&lt;/code&gt; and set the width and height to the same value, in our case &lt;code&gt;26px&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;

&lt;span class="nt"&gt;ion-card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nf"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="mi"&gt;.2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;24px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nc"&gt;.img-wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nt"&gt;ion-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;--border-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="na"&gt;--border-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;ion-color-light-shade&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="na"&gt;--border-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="na"&gt;--padding-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="na"&gt;--padding-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="na"&gt;--padding-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="na"&gt;--padding-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="na"&gt;--border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;26px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;26px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="nt"&gt;ion-icon&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;14px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;14px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And that's it! 😅 I hope you enjoyed this post and have learned something new. You can follow me on &lt;a href="https://twitter.com/fm3ndoza" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; as well where I share tips about web development and programming in general.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next article 👀, as we will review how to code the &lt;code&gt;ion-segment&lt;/code&gt; with the view animations! 🔥&lt;/p&gt;

</description>
      <category>ionic</category>
      <category>css</category>
      <category>html</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
