<?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: molarity69</title>
    <description>The latest articles on DEV Community by molarity69 (@molarity69).</description>
    <link>https://dev.to/molarity69</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%2F964015%2F8d38b133-3d06-44c7-ac89-dd0ebfa03c9b.png</url>
      <title>DEV Community: molarity69</title>
      <link>https://dev.to/molarity69</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/molarity69"/>
    <language>en</language>
    <item>
      <title>How to manipulate ion2-calendar CSS in an Ionic 6 project.</title>
      <dc:creator>molarity69</dc:creator>
      <pubDate>Tue, 20 Dec 2022 11:17:52 +0000</pubDate>
      <link>https://dev.to/molarity69/how-to-manipulate-ion2-calendar-css-in-an-ionic-6-project-38go</link>
      <guid>https://dev.to/molarity69/how-to-manipulate-ion2-calendar-css-in-an-ionic-6-project-38go</guid>
      <description>&lt;h4&gt;
  
  
  Hello fellow &lt;strong&gt;coders&lt;/strong&gt;! Welcome to my first post!
&lt;/h4&gt;

&lt;p&gt;Many modern apps are in need of a calendar for time management, appointment booking, scheduling, you name it.&lt;/p&gt;

&lt;p&gt;In my case it was a surveillance schedule app of a company I worked for and I had to make it look pretty. So I searched online for the available open source options to help me get started quick and came across &lt;a href="https://github.com/hsuanxyz/ion2-calendar" rel="noopener noreferrer"&gt;ion2-calendar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After long hours of frustration through trial and error I finally found out how to access the CSS properties of the &lt;strong&gt;ion2-calendar&lt;/strong&gt; components, so I share my hard gained wisdom to hopefully save some time from another struggling coding soul that didn't find a better solution online.&lt;/p&gt;

&lt;p&gt;Don't get me wrong, it's one of &lt;strong&gt;the best&lt;/strong&gt; tools but it is lacking the proper amount of up-to-date examples to help newbies, hence the present post!&lt;/p&gt;

&lt;h5&gt;
  
  
  Note: If you're reading this far into the future you might want to check out the last section of this post too.
&lt;/h5&gt;

&lt;p&gt;The following example is for &lt;strong&gt;CSS manipulation&lt;/strong&gt; of said &lt;strong&gt;Ionic 6&lt;/strong&gt; project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;In &lt;strong&gt;&lt;code&gt;global.scss&lt;/code&gt;&lt;/strong&gt; file add any of the following according to your needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  !IMPORTANT!
&lt;/h3&gt;

&lt;p&gt;Make sure you always use the !important command after every property you need to change otherwise you won't see any changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* for the background and the main container of the calendar */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* top bar of month and arrows */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.md.icon-small.hydrated&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* forward and backward arrows */&lt;/span&gt;
    &lt;span class="py"&gt;--ionicon-stroke-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* for making the arrows bold */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.transparent&lt;/span&gt; &lt;span class="nc"&gt;.week-title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* weekday names */&lt;/span&gt;
    &lt;span class="err"&gt;li&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
      &lt;span class="c"&gt;/* inner text */&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.days-box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* the container of the days */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.switch-btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* month name */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.days-btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* button and background of each day */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.days&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* each day container */&lt;/span&gt;
    &lt;span class="err"&gt;p&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;/* inner text */&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.days&lt;/span&gt; &lt;span class="nc"&gt;.today&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* today's date */&lt;/span&gt;
    &lt;span class="err"&gt;p&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;/* inner text */&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.days&lt;/span&gt; &lt;span class="nc"&gt;.on-selected&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* selected day */&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt; &lt;span class="cp"&gt;!important&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;20%&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="err"&gt;p&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;margin-bottom&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;important&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ion-calendar&lt;/span&gt; &lt;span class="nc"&gt;.days&lt;/span&gt; &lt;span class="nc"&gt;.last-month-day&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* last and next months month's day */&lt;/span&gt;
    &lt;span class="err"&gt;p&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;/* inner text */&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I left some properties in the .on-selected class as an example. &lt;/p&gt;

&lt;p&gt;Since you get the hang of it it's a matter of minutes to code the best looking calendar. I hope this helped!&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Happy coding!&lt;/strong&gt;
&lt;/h4&gt;

&lt;h2&gt;
  
  
  For future readers
&lt;/h2&gt;

&lt;p&gt;In case any of this information not being relevant in the future, due to updates, the way I discovered about these containers and CSS classes and subclasses is the following command,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngAfterViewInit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;CalendarPage.ngAfterViewInit()&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="cm"&gt;/* the line below */&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;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ion-calendar&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;placed in the parent components ngAfterViewInit method.&lt;br&gt;
Inspect your app in the browser and see the results in the console.&lt;/p&gt;

&lt;p&gt;Follow the &lt;em&gt;children&lt;/em&gt; attribute "maze" and pay attention to the &lt;em&gt;classList&lt;/em&gt; attribute too in order to know how to refer to them in the CSS.&lt;br&gt;
It's good practice using it when you need to know the structure of a packaged component you didn't write yourself, so keep it in mind.&lt;/p&gt;

&lt;h4&gt;
  
  
  EDIT
&lt;/h4&gt;

&lt;p&gt;I totally forgot that you can get the exact same information, as with the above command, by opening the DOM tree in your browsers Dev Tools.&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
      <category>sqlite</category>
      <category>mongodb</category>
    </item>
  </channel>
</rss>
