<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jason Melton on Medium]]></title>
        <description><![CDATA[Stories by Jason Melton on Medium]]></description>
        <link>https://medium.com/@cooljasonmelton?source=rss-26697fd0b4be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fESPzIDUPp99n2Og</url>
            <title>Stories by Jason Melton on Medium</title>
            <link>https://medium.com/@cooljasonmelton?source=rss-26697fd0b4be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 18:50:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cooljasonmelton/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Jason Chess — Part 1: Rendering the Board and Pieces]]></title>
            <link>https://levelup.gitconnected.com/building-jason-chess-part-1-rendering-the-board-and-pieces-b6cc039b8433?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6cc039b8433</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sun, 25 Oct 2020 01:41:18 GMT</pubDate>
            <atom:updated>2020-10-28T02:53:05.114Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Jason Chess — Part 1: Rendering the Board and Pieces</h3><h4>An ongoing series about building a React app called Jason Chess, a version of chess where if your name is Jason, you can’t lose.</h4><h3>What Is All This?</h3><p>Over quarantine, I’ve become very addicted to chess. I like how random chance plays a small role in the game. Instead, better players manifest from hours of obsessive study. Getting better at chess has been a great distraction from the world crumbling all around me, lol.</p><p>As an engineer, it’s my job to build solutions to problems, right? Right. Well I’ll identify one problem that exists: whenever I lose at chess. It’s my job to fix this. My solution: Jason Chess.</p><p>Jason Chess is a version of chess where if your name is “Jason”, you can’t lose.</p><p>This blog will follow the development of Jason Chess. It’s my goal to provide you with something instructive or at minimum, I hope you find the some humor in the idea.</p><p>I’m a junior developer so please forgive my imprecisions. If you have any feedback, please comment or to email me at jason.melton2@gmail.com.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yxZ63ZuwmeAxa4jb8GEIxA.png" /></figure><blockquote><a href="https://github.com/cooljasonmelton/jason-chess"><em>jump to the GitHub</em></a></blockquote><h3>Rendering the Board and Pieces</h3><h4>Table of Contents</h4><ul><li>Preliminary Junk</li><li>Basic Layout and Menu</li><li>Rendering the Board</li><li>Rendering the Pieces</li><li>Conclusion</li></ul><h4>Preliminary Junk</h4><p>To get this bad boy started, I set up a create-react-app, deleted default junk, and created a GitHub repository. Before going further, I spent some time planning. I like to write as I plan so I’ll keep some commented out notes in the readme until the project is finished.</p><p>I think of the work in two parts: the logic and the render — very similar to the divide between a front and back end. However, in this case, I won’t have a true back end.</p><p>The logic of the chess board will be an array of eight arrays. Each array will have a length of eight to represent the 64 spaces of a chess board. Pieces will be coded with two character strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*RmRdKtoqPcKNQys0F8bfQg.png" /></figure><p>The render will consist of mapping boardArr into the corresponding components.</p><h4>Basic Layout and Menu</h4><p>For now, I’m going to keep the page simple. There will be two main elements: a chessboard and a menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yxZ63ZuwmeAxa4jb8GEIxA.png" /></figure><p>Later, I will also add a box above and below for entering the player’s name. Remember, if you enter the name “Jason”, then you cannot be checkmated.</p><p>I picked out some colors from <a href="https://coolors.co/0a090c-f0edee-07393c-2c666e-90ddf0">Coolors.co</a> and added height and width to the App component. I also created a class called .cfb (standing for center flex box) that I use to center things throughout the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*mNqZI4RTxxEgDWid5Fel3w.png" /></figure><p>The menu is a simple component, Navbar:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*_JtSh0rnr_g1PDHV-byzBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*hOXgKaDyYINPM-wnU3Lduw.png" /></figure><p>I’ll cover the chessboard in the next two sections.</p><h4>Rendering the Board</h4><p>My plan for the board is this: I will map my boardArr into 64 divs that will be evenly displayed using CSS grid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DIxzsOC-Hlu1PQV3EsndAQ.png" /></figure><p>I’ll show the whole Board component and CSS file and explain my work:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*xvIYfrmfKqVWoy82fxYdaQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*i9sobjG5dT1c8OKt5Osulg.png" /></figure><p>Board gets the boardArr as props. The function renderBoard() maps each rank of boardArr and then each square of each rank to return a div. That way we get our 64 divs.</p><p>I use the function squareClass() to determine the classnames for each square. Light squares get a class of cfb and dark squares get a class of cfb dark. As previously mentioned, cfb adds a centering flex box and dark adds a light blue background-color.</p><p>squareClass() also determines which squares are dark squares. I use the helper function isEven() to do this. Starting from 0, even ranks and odd files are dark while on odd rows, even squares are dark. I find the rank and file of each square and add dark to the appropriate divs.</p><h4>Rendering the Pieces</h4><p>I render the pieces in two steps:</p><ol><li>I create a picture library that can be accessed via an object.</li><li>I create a dynamic function that plugs in the correct image for the string code in the boardArr.</li></ol><p>I found this great <a href="https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces">site</a> for chess piece svgs. I threw the images in a folder and created a file called index.js. There I created an object called pieceObject that accesses the image based on a key corresponding to the string codes in the array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*QryHJt2YaMrXVvQhbsUs6A.png" /></figure><p>Next, I feed this object to a component called PieceImg.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*mQs9kqS7hC7sZHCKJO0usw.png" /></figure><p>PieceImg takes props of piece that will be a code like bp for black pawn or wn for white knight. The pieceObject looks up the corresponding image. Also, if there isn’t a piece code on the square, piece will point be false and I will return an empty div.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*A8ZCBqzAuilnM3HmYlBQOA.png" /></figure><p>Look again at the renderBoard() function in Board. Here you can see the PieceImg is being fed the props of a piece code or false.</p><h4>Conclusion</h4><p>Thanks a ton for reading. Again, I assume there are some great ways to make chess games. I came up with this off the top of my head and grinding out bugs. I’m sure there are better ways so I’d love your feedback. Hit me with a comment or an email — jason.melton2@gmail.com.</p><p>This will be an ongoing project so I may be inconsistent with the blogs, but I appreciate you reading.</p><p>Best, Jason</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6cc039b8433" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/building-jason-chess-part-1-rendering-the-board-and-pieces-b6cc039b8433">Building Jason Chess — Part 1: Rendering the Board and Pieces</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an Animated Counter with React and CSS]]></title>
            <link>https://javascript.plainenglish.io/attempting-to-build-a-cool-animated-counter-with-react-and-css-e37f7f2d47e4?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/e37f7f2d47e4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sun, 18 Oct 2020 02:31:33 GMT</pubDate>
            <atom:updated>2020-10-18T18:59:45.343Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this blog, I attempt to create my own version of an animated counter component that I keep finding all over the web</h4><p>I’ll show you how I went about it, but I would love feedback. Is there a better way to do this?</p><p>Leave a comment or shoot me an email at jason.melton2@gmail.com.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*teuNCFz-eydpbdJ7O0FGmg.gif" /></figure><blockquote><a href="https://github.com/cooljasonmelton/count-comp"><em>the code on Github</em></a></blockquote><h3>Tutorial</h3><h4>Table of Contents</h4><ul><li>Preliminary Junk</li><li>Count Component</li><li>Increment Function</li><li>Conclusion</li></ul><h4>Preliminary Junk</h4><p>I set up a create-react-app, deleted a bunch of default stuff, and a file structure like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/176/1*KaPEgIrkT1PiLX035GTdmA.png" /></figure><p>I added some basic CSS to the App component — height, width, and a flex box to center all its contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*8jyVCbpeKkSHvdKzEukDYg.png" /></figure><p>I also set up a json file containing the data that I will map into Count components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*9wVMcZzn4AjM5MbRexgl3g.png" /></figure><h4>Count Component</h4><p>The object of my Count component is to accept some data about how the count should run and render the animation.</p><p>First, I set up a basic component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*hs7aUwRSi_qEC3P1if3jHg.png" /></figure><p>Count gets props of a data item from data.json. I destructured the label, number, and duration from the props.</p><p>Using JSX, I return the label and number as a header. Later, I will change number so that it animates, but for now I can style the hard-coded version of what I’m building.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*yEO0RCwz7qOx21VQh3n5Ng.png" /></figure><h4>Increment Function</h4><p>I’m going to set up a function that increments from 0 to the desired number in these three steps.</p><ol><li>Set up a useState hook that saves our display number and, when updated, will trigger a render of the component.</li></ol><p>The hook looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*6M4k7SI8nMMPNh4J9pp6IA.png" /></figure><p>I update the JSX to display count instead of number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*FA8nx4tpUGWqomJrTRFlkA.png" /></figure><p>2. Set up a useEffect hook that calculates the count and increment time.</p><p>useEffect() firstly takes an anonymous function that will handle the count. I create variables start and end. start is set to 0.</p><p>Initially, I used number as my end. However, I realized, for very large numbers, a better method would be use to increment only the first three digits of number and paste the the rest back on before updating the count. This way the counter won’t take all night.</p><p>I calculate the rate of each increment by dividing the duration (seconds) by the number of increments I plan on doing and multiply by 1000 to convert to milliseconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*IdcT6TSQ-9-x3u0LEGav2g.png" /></figure><blockquote>Initially, I was hoping to speed up the interval to make up for large numbers, but setInterval() has a minimum duration of 10 milliseconds. Any number less than 10 will reset back to 10.</blockquote><p>3. In that same useEffect hook, I employ setInterval() to increment the count with side effect of re-rendering the component.</p><p>I add one to start and call setCount() to update my useState hook. I convert start to a string and, if it’s a large number, I concat the rest of the number that I previously chopped off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*k8sme5nH_FMNI2KwbO3dzw.png" /></figure><p>The entire component will now look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*KCF8YkAqohCZj8L1aeofdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*P5qgmgC5l1UlpwMrMm6aeA.png" /></figure><h4>Conclusion</h4><p>I read through several articles about this sort of animation and combined their ideas with my instinct to make the abstract reusable component above.</p><p>I am not sure what I came up with is the best method. For example setInterval had limitations I didn’t foresee. I would love some feedback. Feel free to comment or shoot me an email at jason.melton2@gmail.com.</p><p>Best, Jason</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e37f7f2d47e4" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/attempting-to-build-a-cool-animated-counter-with-react-and-css-e37f7f2d47e4">Building an Animated Counter with React and CSS</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Chart.js to Display Poll Data in a Cool Way]]></title>
            <link>https://javascript.plainenglish.io/using-chart-js-to-display-poll-data-in-a-cool-way-56eda587c53b?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/56eda587c53b</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[chartjs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sun, 11 Oct 2020 00:01:42 GMT</pubDate>
            <atom:updated>2020-10-12T08:21:50.863Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s voting time. Get ready to see a million graphs showing poll results of all the various groups — how many left-handed cellists voted green party, how many fiscally liberal vampires want to defund global warming, how many otters publicly opinion that eating is best while lying on your back.</p><p>I used Chart.js to build a bar graph that displays poll results between three counters. In this blog, I’ll show you how I did it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*zqiD41cLpX8X2bYD6Zmeew.gif" /></figure><blockquote><a href="https://github.com/cooljasonmelton/poll-machine"><em>Jump to the GitHub</em></a></blockquote><h3>Tutorial</h3><h4>Table of Contents</h4><ul><li>Preliminary Junk</li><li>HTML &amp; CSS</li><li>JavaScript for Vote Buttons and Results Text</li><li>Applying Chart.js</li><li>Conclusion</li></ul><h4>Preliminary Junk</h4><p>To start, I set up a file for my HTML, CSS, and JavaScript. Then, I installed Chart.js with npm:</p><pre>npm install chart.js --save</pre><p>I ended up with a file structure (minus poll-machine-demo.gif) like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*GRdpgmCxIZvtliJ_YLEKpQ.png" /></figure><h4>HTML &amp; CSS</h4><p>I set up the bones for this project in index.html.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*z9ZOA5ZRXi-yFscosHBMSQ.png" /></figure><p>And of course, I connected my stylesheet, JavaScript file and the Chart.js node module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*_HPsTqp4B7QptQD28ktUrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*iDkxO_xAXxBWJscofS44SA.png" /></figure><p>I added CSS to make the buttons and text show up properly. I added some colors, margins, padding, and put everything in a grid. I’m not going to go into severe detail, but you can find the CSS <a href="https://github.com/cooljasonmelton/poll-machine/blob/main/styles.css">here</a>.</p><h4>JavaScript for Vote Buttons and Results Text</h4><p>With the counter buttons’ HTML and CSS looking decent, I went to work on their functionality.</p><p>First, I grabbed all the buttons and text nodes by their classnames.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*Zr4CddTdsDQbqA3NRulFPA.png" /></figure><blockquote><em>Using </em><em>.getElementsByClassName() returns an </em><em>HTMLCollection type. These are similar to an array, but in order to use array methods like </em><em>map() I have to use the spread operator ( </em><em>... ) to copy the </em><em>HTMLCollection into a new array.</em></blockquote><p>I set up an initial vote count for each button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*AFxfAjNQzGlEI6RGL2_aJQ.png" /></figure><p>With my buttons in an array, I can map over them and give them each an event listener. Whenever, a button is clicked it will the function updateVote()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*NS_rTLTxBPi0LT-hKHhJbg.png" /></figure><p>updateVote() does all the work. Its parameter is the first character ( charAt(0) ) of the button id. This will be &#39;a&#39;, &#39;b&#39;, or &#39;c&#39;. It adds one to the correct result variable.</p><p>Next, I map over my results text. These are an array of paragraph elements I have stored in txtArr. I map this array to display the proper result for each element.</p><p>Finally, I update the chart. I will cover this in the next section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*f-Pu_RlDA8pYxXGUA4XNEg.png" /></figure><h4>Applying Chart.js</h4><p>Chart.js must be applied to a canvas element. I grab the canvas element from the HTML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*7GiL5wgGhBU31xA35KWedw.png" /></figure><p>Next, I make my chart by calling new Chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*JfS_Ljglun7VvwToBatWDg.png" /></figure><p>new Chart takes a canvas element, chartCvs, for its first argument. For its second argument, it takes an object that holds all the chart specifications:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*2xTQBTJV6vHubZnu5ry45A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*YeBhbIx1u430erkQCOJMKQ.png" /></figure><p>The three main keys of the object are type, data, and options.</p><p>type controls the type of graph. Chart.js gives a lot of good options. For this, I went with a simple bar graph by providing the value &#39;bar’.</p><p>The data added differently depending on the type of graph you are making. For each bar, I give information about the color and style of the bar and the data and labels correlating to each letter — A, B, or C.</p><p>Finally, for the options, I create a title, turn off tooltips (a hover box I didn’t like), and give labels and ticks to the scales on the y-axis.</p><h4>Conclusion</h4><p>The graphs of Chart.js display really nicely with detail and smooth transitions. There was a bit of a learning curve for me to get everything working. For this reason, I hard coded a lot of the project. If I were to redo this, I would abstract a lot of this and explore more of what Chart.js offers. There’s a lot more customization that you can apply to a chart.</p><p>Message me if you have any feedback. I would love any suggestions or ideas to better my blog and, of course, the ‘poll machine’. Please comment or feel free to email me at jason.melton2@gmail.com.</p><p>Best, Jason</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56eda587c53b" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/using-chart-js-to-display-poll-data-in-a-cool-way-56eda587c53b">Using Chart.js to Display Poll Data in a Cool Way</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Whipping Up a Rails API Real Quick]]></title>
            <link>https://medium.com/swlh/whipping-up-a-rails-api-real-quick-88cda155d2a4?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/88cda155d2a4</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sun, 04 Oct 2020 03:33:54 GMT</pubDate>
            <atom:updated>2020-10-04T11:22:04.966Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*EoM0qqsXhV8rrPFNlMMitQ.jpeg" /></figure><p>In this blog, I concisely outline the basic steps of creating a Rails RESTful API.</p><blockquote><a href="https://github.com/cooljasonmelton/quick-api"><em>jump to the code on GitHub</em></a></blockquote><h3>Tutorial</h3><h4>Steps</h4><ol><li>Create New Rails Project</li><li>Plan Models / Relationships</li><li>Generate Resources</li><li>Create / Migrate database</li><li>Set Up Controllers</li></ol><h4>1. Create New Rails Project</h4><p>First things first. Assuming Rails is installed, enter the following command into your terminal replacing &lt;my-project&gt; with the current project name.</p><pre>rails new &lt;my-project&gt; --api --database=postgresql</pre><blockquote><strong><em>Flags: </em></strong><em>The </em><em>--api flag will forgo including some of the extra junk a full Rails application has that we do not need. The </em><em>--database flag lets you specify the type of database you prefer. I chose PostgreSQL. If you do not include this flag, the default database will be SQLite.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*RHMbMSsEX9g-h_-cj2n32w.png" /></figure><p>For demonstration, I’ll create an Evil Dog Catcher API. I type out my command and hit enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*42UxXmwOlQkvooncAEb_TA.gif" /></figure><h4>2. Plan Models / Relationships</h4><p>While Rails is installing, it’s a great time to plan the models and relationships. Having a clear idea of these ahead of time can save a lot of headaches.</p><p>For my Evil Dog Catcher API, I am going to have two models: Catchers and Dogs. The relationships will be:</p><ol><li>Catchers have many Dogs.</li><li>Dogs belong to Catchers.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*2YZGNmOq1FPA7ezsIy56Lg.png" /></figure><h4>3. Generate Resources</h4><p>Next, I’ll generate resources. This command quickly sets up migrations, models, controllers, and routes for each model name.</p><pre>rails generate resource &lt;model&gt; &lt;attribute&gt;:&lt;type&gt; &lt;attribute&gt;:&lt;type&gt;</pre><blockquote><strong><em>Tips: </em></strong><em>g is shorthand for </em><em>generate. Also, you can list another model’s name as an attribute with a type of </em><em>references to automatically create that model with a foreign key.</em></blockquote><p>These will be my resource commands:</p><pre>rails g resource catcher name:string city:string<br>rails g resource dog name:string breed:string catcher:references</pre><p>References gives me a foreign key on the Dog model, but I have to manually go into the Catcher model set up a has_many :dogs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*Kteg2QOyfi5eB60PUsPn6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*srNJx7KMN3nldDXR1UqmSg.png" /></figure><h4>4. Create / Migrate database</h4><p>With all our files generated, it’s time to get the database going. First, I double check the migration files to make sure everything looks right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*oT0hb5uPM6JJrFHi_PlUrA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*aFeQDzbFiC7172AdoW5nfw.png" /></figure><blockquote><em>Note line 6 of </em><em>CreateDogs. Because </em><em>null: false, I will not be able to create a dog unless it has the foreign key of a </em><em>Catcher. If you want to be able to create models without this, set </em><em>null: true.</em></blockquote><p>Since everything looks right, I will now create and migrate my database by entering these commands into the terminal:</p><pre>rails db:create<br>rails db:migrate</pre><p>Next, I test my progress in the following steps:</p><ol><li>rails c or rails console opens the console.</li><li>In the console, I create a Catcher instance, Catcher.create(name: &#39;test&#39;), and a Dog instance, Dog.create(name: ‘test’, catcher_id: 1)</li><li>I test the relationship by entering Catcher.find(1).dogs and get:&lt;ActiveRecord::Associations::CollectionProxy [#&lt;Dog id: 1, name: “test”, breed: nil, catcher_id: 1, created_at: “2020–10–04 06:39:15”, updated_at: “2020–10–04 06:39:15”&gt;]&gt;</li></ol><p>If there’s no errors, it’s time for the next step.</p><h4>5. Set Up Controllers</h4><p>For the final step, I will set up a basic controller and test it on the Rails server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*AcylUKuXytxII0QTOlfzkA.png" /></figure><p>Then, I run rails s or rails server in the terminal. I open <a href="http://localhost:3000/catchers">http://localhost:3000/catchers</a> and I see that everything is working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8RFpVtga9qrws40Mj3HsDA.png" /></figure><blockquote><em>For production purposes, you can open the CORS of this API to any website. First, install the CORS gem. Open the Gemfile, uncomment ‘rack-cors’, and run </em><em>bundle install.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*N587n8m81cMMxqOxn80jNA.png" /></figure><blockquote><em>Next, access the </em><em>config/application file. Find the class </em><em>Application and — without altering any of the default code — insert the following:</em></blockquote><pre>config.middleware.insert_before 0, <em>Rack</em>::Cors do<br>    allow do<br>        origins &#39;*&#39;<br>        resource &#39;*&#39;,<br>            :headers =&gt; :any,<br>            :methods =&gt; [:get, :post, :delete, :put, :patch, :options, :head],<br>            :max_age =&gt; 0<br>    end<br>end</pre><blockquote><em>Remember to change the origins before deployment or this API will be available to anyone.</em></blockquote><h4>Conclusion</h4><p>At this point the basic API has been created. The next steps will be to open up the CORS for whatever other sites will pull from it, and I set up the controllers to perform whatever actions you want to perform.</p><p>Hope this is helpful! Mostly I wanted to create a quick reference for setting up an API. If you have suggestions / corrections. Please comment or email me at jason.melton2@gmail.com.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88cda155d2a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/whipping-up-a-rails-api-real-quick-88cda155d2a4">Whipping Up a Rails API Real Quick</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2: Build This Cool Dropdown Menu With React, React Router and CSS]]></title>
            <link>https://medium.com/swlh/part-2-build-this-cool-dropdown-menu-with-react-react-router-and-css-ebdb51ed6acd?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebdb51ed6acd</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sun, 27 Sep 2020 00:03:14 GMT</pubDate>
            <atom:updated>2020-09-27T14:01:43.250Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*NuKHtxQJw_Gxd2RrjiYwgA.png" /></figure><p>After my last <a href="https://medium.com/@jasonmelton_/build-this-cool-dropdown-menu-with-react-react-router-and-css-609214e80a90">blog</a> about building a ~cool~ dropdown menu, I received the suggestion to write a part 2.</p><p><a href="https://dev.to/link2twenty">Andrew Bone</a> pointed out, “Generally, when making a component, the aim is to make it reusable and simple enough that it rarely needs to be revisited.”</p><p>I took the advice to heart. In the following, I show how I refactored my dropdown menu to be just this: reusable and simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*2v-rUct3tE52n5amaPJfcQ.gif" /></figure><blockquote>jump to the code on <a href="https://github.com/cooljasonmelton/dropdown2">GitHub</a></blockquote><h3>Tutorial</h3><p>The goal: take the previous dropdown menu and rewrite the code so it uses any JSON object of menu data to create a dropdown with the same structure and styles as the original.</p><h4>Table of Contents</h4><ul><li>Preliminary Junk</li><li>Mapping a JSON Object</li><li>Dynamic Styles</li><li>Dynamic Routes</li><li>Conclusion</li></ul><h4>Preliminary Junk</h4><p>To start, I <a href="https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/duplicating-a-repository">duplicated</a> the original repository and added a JSON file with some dummy data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*0Nn-5_l12jKzZSdmnHQoIA.png" /></figure><h4>Mapping a JSON Object</h4><p>In order to make the component dynamic, I use map(). Map is a common tool employed in React apps as it can transform an indefinitely sized array of items into JSX. This allows components to be defined abstractly making them reusable.</p><p>Our original Menu component looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*YkKuArT_T1BjJ3DJk8klEw.png" /></figure><p>As you can see, I have each item spelled out with its own div and settings. In the refactored version, I instead use JSX to render the return of mapping the JSON object.</p><p>The return looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*g7mUxv1ImD5buZ9N4BtwsA.png" /></figure><p>I keep the initial menu item in its own div. It will display when the menu is closed and the other menu items will hide behind it. Beneath that, I call the renderMenuItems() function which takes a JSON object as a parameter.</p><p>renderMenuItems() is complicated. I will show the whole function and explain it piece by piece.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*usDCHPigI7oiqNdr51WL1g.png" /></figure><p>I will explain colorArr, colorCounter, and itemStyle in the next section.</p><p>First, notice line 27. On this line, I return a map() of data, the JSON object parameter. map() runs a callback on each item of an array, returning the result of that function in a new array.</p><p>map() can take two parameters. The first parameter is the item from the array. I labeled them item. The second is each item’s index, labeled index.</p><p>Next, see line 39. On this line, I return dynamic JSX for each item in the map(). These will be the divs of our menu items. Each item has an id, name, and route.</p><p>I give them each div the m-item classname, unchanged from the original. They get an onClick event that triggers pushToRoute(). Also the same as the original except the parameter is in the JSON object under route. Each gets a key of the JSON’s id. Finally, I display the JSON object’s name as text in the div.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*LDoM1rNdVTcFRWWfXRM2uA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*j_cG4nUd1GEz_FHQ-59sXA.png" /></figure><p>This will dynamically render as many menu items as there are in the JSON object sent to this component.</p><h4>Dynamic Styles</h4><p>CSS controls the dropdown to work properly. In my original menu, I used a function called setClassNames() to add classnames to the items. Then, I spelled out an individual classname for each item and the specific length I wanted them to drop to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*33_4ESWwPmjjZiuvzWcsRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*NTX-L0X-MgAyYZ-FO3jQ-g.png" /></figure><p>While this functioned correctly, it was not easily reusable. Not only would I have to spell out a new open-# for each additional item, I also use a lot of extra code.</p><p>Since I am now using map() on the menu items, I can work out the styles as I go. There are two parts to the CSS:</p><ol><li>A top set to a size of 1.8em times the number item it is on the list (1.8, 3.6, 5.4, 7.2, etc.).</li><li>One of three color hexes set as a background-color (#9b5de5, #f15bb5, #00BBF9).</li></ol><p>Take a look at renderMenuItems one more time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*2Xk7o5-BjdFO_BBbcG4oIQ.png" /></figure><p>React allows me to add styles to a div as an object written in camelcase syntax of JavaScript.</p><p>Notice on line 35, I set the top. I use the map() index parameter to add a dynamically increasing em size.</p><p>The background-color is a little trickier. I set up an array called colorArr with my 3 color hexes in it. To access these, I set up a counter called colorCounter that I will use to access the colors.</p><p>The colorCounter is initially set to -1. On line 31 inside the map(), I run a ternary where if the counter is less than 2, I add 1 to the counter. If it is over 2, I reset the counter to 0. Thus, the counter will run 0, 1, 2, 0, 1, 2… for as long as the map() goes.</p><p>On line 36, I set the “backgroundColor” to colorArr[colorCounter]. This provides the sequence of colors for the menu items.</p><p>Finally, I need to add the top and background-color properties to the items based on when the top menu item is clicked.</p><p>When clicked, the top menu item toggles openMenu, a useState hook, between true and false.</p><p>On line 42, the style property of the div accepts JSX. I use a ternary here to return the object containing the new top and background-color if openMenu is true. If false, it receives a null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*2v-rUct3tE52n5amaPJfcQ.gif" /></figure><h4>Dynamic Routes</h4><p>The final piece of this is to go back to my Switch statement and render the routes dynamically as well. I can map() the same JSON object in order to set up the corresponding route of each menu item. You can find that on line 25.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*0vuuZyG-PCXGcPSd7B0irQ.png" /></figure><p>Again, what’s missing here are the actual components of the the app that this menu would be applied to. This could be solved by either altering the JSON to include the component’s name or maybe to set up a lookup table that corresponds components to the IDs in the JSON. Something like that.</p><h4>Conclusion</h4><p>It was great to revisit my code and improve on my earlier ideas. Again, thanks to Andrew Bone for challenging me to try this. I feel like I created a much more flexible, reusable tool the second time around.</p><p>If you have any feedback or suggestions, please reach out. Comment or email me at jason.melton2@gmail.com. Regardless of that, thanks for reading. Best, Jason.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebdb51ed6acd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/part-2-build-this-cool-dropdown-menu-with-react-react-router-and-css-ebdb51ed6acd">Part 2: Build This Cool Dropdown Menu With React, React Router and CSS</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build This Cool Dropdown Menu with React, React Router and CSS]]></title>
            <link>https://cooljasonmelton.medium.com/build-this-cool-dropdown-menu-with-react-react-router-and-css-609214e80a90?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/609214e80a90</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sat, 19 Sep 2020 21:26:54 GMT</pubDate>
            <atom:updated>2020-09-19T21:31:00.153Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*NuKHtxQJw_Gxd2RrjiYwgA.png" /></figure><p>How about a sweet dropdown menu to throw in a tight area of your site? Or maybe use it as a simple navigation tool for your minimalistic layout? Or switch to this smaller menu when the screen shrinks to smaller size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*ejXYnvwvkwFCraS1aE8aow.gif" /></figure><blockquote><a href="https://github.com/cooljasonmelton/dropdown">the code on Githu</a>b</blockquote><h3>Tutorial</h3><h4>Table of Contents</h4><ul><li>Preliminary Junk</li><li>Menu Component</li><li>Menu CSS</li><li>React Router</li><li>Conclusion</li></ul><h4>Preliminary Junk</h4><p>To get this going, I made a create-react-app, installed <a href="https://reactrouter.com/web/guides/quick-start">React Router</a>, deleted any unneeded default code, and set up a file structure that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*ZPL3seAB0WEO6ZngKQg-aw.png" /></figure><h4>Menu Component</h4><p>Menu.js contains all the JavaScript and JSX for our dropdown.</p><p>There are essentially four parts:</p><ol><li>A useState hook holding a boolean that dictates if the menu should open. I call this openMenu.</li><li>A function called setClassNames() which conditionally adds classes to the menu items. The CSS of the classes will animate the menu.</li><li>A function called pushToRoute() which employs React Router to render a new component after a menu item is clicked.</li><li>The Menu component’s return JSX for rendering the structure and bringing together all the functionality.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*Li-48B-c-Hk5XdTrefkohg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*nynezF-5t8ZDZ9YSjUZGiw.png" /></figure><h4>Menu CSS</h4><p>The CSS does all the work opening the menu. There are five important parts.</p><p>The .Menu class is the most outer container. It’s important to give it a property of position: relative;.</p><p>The individual menu items will have a position: absolute;, so they will render based on the nearest component with a position. I want the basis of position to be the outer div of our Menu component.</p><p>2.</p><p>The .m-item class is applied to each individual menu item. They are absolutely positioned with an initial top: 0;. This will render all the items on top of each other at the top of the .Menu div.</p><p>I use em units for width and all the properties so I can ensure the items will fit perfectly on top of each other and still be responsive (em units are relative to the font-size of the element).</p><p>For aesthetics, I give them a background-color, box-shadow, padding, border-radius, font-size, and color.</p><p>The flexbox properties vertically and horizontally center the text in each div. The cursor property lets the user know the menu items are clickable. Finally, transition will animate changing properties applied by the setClassNames() function and CSS :hover.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*uJ1W0ABSF3lebHuyUuM_rA.png" /></figure><p>3.</p><p>.m-item:hover adds a small border to the menu items on hover. The added 1 px of border causes the items to move slightly on hover giving them a little bit of life.</p><p>4.</p><p>.m-logo is a special class added to the first menu item. The z-index: 1; brings that div to the top so all other divs will hide underneath it.</p><p>z-index has a default of 0 so if only one item has it, 1 will be enough to bring it to the top of everything.</p><p>5.</p><p>A series of classes called .open-1, .open-2, and .open-3 cause the animation of the drop down. These classes are applied via setClassNames() once the the top menu item is clicked.</p><p>Once clicked, each item will transition to the new properties in their open-# class. Namely, they will drop to the specified top and new background-color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*jwGoBdB1IU_8ExTrZ_kOCw.png" /></figure><h4>React Router</h4><p>All the aesthetic aspects of the Menu component are set up at this point. All that’s left is to set up the React Router so that clicking on the items navigates you to the correct component.</p><p>Let’s wire this up in the following three steps:</p><p>The App.js file is the main run file for the whole project so this is where I set up the basic Router stuff.</p><p>I wrap App&#39;s return with BrowserRouter so the soon-to-be Routes will be available to all components contained.</p><p>I set up a Switch so that when one Route is rendered, the others will be disabled. Then, I define each specific Route needed for the project (obviously , these are made up for the sake of demonstration).</p><p>The Menu component is placed outside the Switch so it will render whenever App is rendering. This makes it an efficient navigation tool, available on any screen of the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*1VDfeyaBEZjXklKewlZs2w.png" /></figure><p>2.</p><p>In our Menu component, I import withRouter and wrap the Menu with it in the export statement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*TkQGBDK0qTNsGqkal0iCnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*M2_GS0qMuOygVpYPRm1Y7g.png" /></figure><p>withRouter gives Menu props that will allow us to manipulate the react-router-dom so we have to give our Menu a parameter of props.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*1vzHhhBiuxtVsFpBIRw5EA.png" /></figure><p>3.</p><p>Finally, I set up the function pushToRoute() which takes a parameter string of a route and pushes our app to that route. Then, it closes the Menu by calling setOpenMen(false).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*363EIaCziGLJvzH9TKkE2g.png" /></figure><p>The menu items call pushToRoute() onClick and there I define the destination.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*LKtHyAT1XjQqePtQbs__bQ.png" /></figure><h4>Conclusion</h4><p>I enjoyed making this menu. It’s a very efficient and easy tool that fits in a number of scenarios. I hope you find some of the concepts useful.</p><p>I love feedback. Got any suggestions? I’d be happy to add your knowledge to my own. Hit me up in the comments or email me: jason.melton2@gmail.com.</p><p>Best! Jason Melton.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=609214e80a90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build This Cool PopUp / Modal with React and CSS]]></title>
            <link>https://cooljasonmelton.medium.com/build-this-cool-popup-modal-with-react-and-css-aee8ceedaf6f?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/aee8ceedaf6f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sun, 13 Sep 2020 01:47:32 GMT</pubDate>
            <atom:updated>2020-09-13T01:47:32.957Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*iuQoaq9LU50KBpBkRCkwDg.gif" /></figure><p>A nicely styled version of an alert(), the modal, the popup. One of the sometimes annoying yet necessary elements of the web.</p><p>For this blog, I created a modal using React and CSS, and I’m going to show you how I went about it.</p><p>I assume there are millions of ways to achieve this. I’d love your feedback if you have any improvements.</p><blockquote>the code on <a href="https://github.com/cooljasonmelton/popup">GitHub</a></blockquote><h3>Tutorial</h3><h4>Table of Contents</h4><ul><li>Preliminary Junk</li><li>CheckOut Component</li><li>PopUp Component</li><li>The Styles</li><li>Conclusion</li></ul><h4>Preliminary Junk</h4><p>To begin, I set up a create-react-app deleted the default junk and set up a file structure like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*1T6edfunYUAA8lrseJLtlw.png" /></figure><p>To make this demo sweet, I set up a fake shopping cart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w7EWxe88U_hOH2h4kNU6AQ.png" /></figure><p>The only thing that functions on this screen is the “Checkout!” button. I’m going to skip the code for this, but you can find it in the <a href="https://github.com/cooljasonmelton/popup">here</a>.</p><h4>CheckOut Component</h4><p>I set up a CheckOut component that has a table displaying the items the user is purchasing and some other stuff for the sake of demoing the popup.</p><p>What’s important for the popup functionality are these lines of code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*4I6aOcIqbuJa7DrHE9HcIg.png" /></figure><p>On line 9, I set up a useState hook for toggling the popup on and off.</p><p>On line 11, I set up a variable called duringPopUp that will conditionally add the style &quot; during-popup&quot; to the elements it is applied to. This class will darken the background-color of those elements. I apply like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*PWCXiKEEoCfpiUvJWyb55Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*HkCXeGVd2frxyQwEblZwsQ.png" /></figure><p>On line 48, I have a line of code that conditionally renders a PopUp component. That component receives setPopUp as props. This way I can toggle the PopUp off from within the PopUp component.</p><h4>PopUp Component</h4><p>My PopUp component is set up like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*0NUUFbj-IBjcFVBMiQ7dJA.png" /></figure><p>The content of PopUp can be whatever you need. I set all the buttons to simply toggle the component off. In reality, if someone wanted more bones, the MORE BONES! button would give them MORE BONES!</p><h4>The Styles</h4><p>Again, I’m going to skip most the styles in CheckOut.css file. Most of them set up the fake cart and make the buttons look a little nicer. Here’s what’s important for the popup.</p><p><em>Darken Background Colors in Checkout.js</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*bQ6ndDTM8sw59mW-wrcB1g.png" /></figure><p>Remember, this style is added when the popUp state is true. It darkens the background-colors wherever it is applied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zsDUXA3ieHn4J64KFr8X8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CTZjkKhw9fhqxUTibfk_oA.png" /></figure><p><em>Styles for elements in PopUp.js</em></p><p>These are the styles for the outer most div in the PopUp container:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*UyShypFhiFrLBnE6EHyCZw.png" /></figure><p>The important piece is position: fixed;. This will cause the component to render exactly where it is positioned by top and left. Since it is fixed, it will stay in the same position even if you scroll.</p><h4>Conclusion</h4><p>Hope this helps you create the most irritating advertisement the web has ever seen. Kidding, of course, but I do hope this helps with your popup design. I’d love some feedback. Hit me up at jason.melton2@gmail.com. Thanks for reading. Best, Jason.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aee8ceedaf6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Simple Loader With CSS and HTML]]></title>
            <link>https://medium.com/swlh/build-a-simple-loader-with-css-and-html-8eaa25183246?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/8eaa25183246</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sat, 05 Sep 2020 23:24:15 GMT</pubDate>
            <atom:updated>2020-09-07T05:54:17.373Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pYX43alZoTP2dQGCzP48uA.png" /></figure><p>The nice thing to do when your website isn’t fully loaded is to play a little animation.</p><p>It lets the user know: “We’re working on it.”</p><p>“We know if it takes more than 2 seconds, you’ll leave forever.”</p><p>“My liege, we graciously offer you ~three blinking dots~.”</p><p>Animations act like a mantra. Like staring into a campfire. It hits your brain jingling keys hit a baby. Something primitive is opened inside, and we’re transported to a place outside of time. And while we’re there, no one notices the load…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*U61pIiBQjh1gjEzGHvQHFQ.gif" /></figure><h3>Tutorial</h3><p>In this blog, I try my hand at recreating various loaders I’ve seen on the web. In doing so, I attempt to make them as simple as possible, so they can easily be imported into your project or you can use the ideas to create your own.</p><blockquote><a href="https://github.com/cooljasonmelton/loaders"><em>The code on Github</em></a></blockquote><h4>Preliminary Junk</h4><p>I set up a file structure that is an HTML file, index.html and a CSS file, index.css. The HTML looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*roSsuoEmOM6FADzkpgh-nQ.png" /></figure><p>I’ll explain each example in more detail when it’s relevant.</p><p>I set up some CSS variables for colors (from <a href="https://coolors.co/1a535c-4ecdc4-f7fff7-ff6b6b-ffe66d">Coolors.co</a>), flexbox, and margins for the general layout of the demo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*exdh-Ldc6_HoWNByYLSI3Q.png" /></figure><h4>Example 1</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*suFhPcxqsI4G4uKNlcBsgg.gif" /></figure><p>Example 1 has the HTML of one div, set up like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*0FSuJfQNWsHSqcBrCVHQMw.png" /></figure><p><strong>Design:</strong> I give it the same size width and height and a border-radius: 50%;. By adding a border, you can see that this creates a circle.</p><p>I style the border-top-color with my accent color, var(--loader-acc-color). This overwrites the initial color in border for just the top of the border.</p><p><strong>Animation:</strong> I set up @keyframes example-one so an element with this animation will rotate from 0 to 360 degrees.</p><p>I give the #example-1 element an animation property. Using the shorthand, I set the duration to 2s, iteration count to infinite, and name as example-one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*wEFOB5aCTWL5A1AuqgkfMw.png" /></figure><h4>Example 2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*Kighp-Az9WPDb8xbcc_iGQ.gif" /></figure><p>For Example 2, the HTML is a div container for three more divs. Each will be a “bar”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*6vrdT2sxafyVj5hqOO1laQ.png" /></figure><p><strong>Design:</strong> #example-2 is given some width, height and flexbox properties to center the bars within.</p><p>Each bar is given a margin, width, and starting height. I give them a background-color and some fancy border stuff for accent.</p><p><strong>Animation:</strong> There are four parts to the example-two animation, divided into 0%, 25%, 50%, and 100%.</p><p>At 0%, the height is set to 2.5em, the same as the initial height of each bar. From 0% to 25%, the height grows to 5em. From 25% to 50%, it shrinks back to 2.5em where it will sustain until 100% when the animation restarts.</p><p>I give each bar an animation property with a duration of 1.5s, iteration count of infinite, and connect it to @keyframes by name, example-two.</p><p>Finally, in order to stagger the play, I grab the individual bars by their IDs. bar-1 gets a delay of 0.25s and bar-2 gets a delay of 0.5s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*IF3Gp3ZSwFqnsSwoDAUxgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*TuaUDcPo89i7Web7qinr1Q.png" /></figure><h4>Example 3</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*sxkAih6m21n-8T6HWnyLUA.gif" /></figure><p>Example 3 is one div.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*feIwmCfbwODl_Gi-Th9Mpg.png" /></figure><p><strong>Design:</strong> I give #example-3 a width: 5em; and height: 1em; to make it a long rectangle. I give it a background-color and some fancy border stuff for an accent.</p><p><strong>Animation:</strong> I use the transform property again, but this time I flip the div from 0 to 180 degrees over its y axis using rotateY(). Then I flip it to 360 degrees, back to its starting position.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*UKeNult2z2A0tFP0vZWrvw.png" /></figure><h4>Example 4</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*ZNdIcCojDbmjVUYmGO4cIA.gif" /></figure><p>Example 4, most complex loader, has HTML of a container div with three children divs. Each child is also a container div for a single div that will be shaped like a ball.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*DJPjvp-6RLrWF3z_tOKZkA.png" /></figure><p><strong>Design:</strong> The outer most container, #example-4 contains flexbox properties to center the loader within.</p><p>Each .ball-container gets the same width as height to make it a square and a margin-right to put some space in between.</p><p>Then, .ball-container gets flexbox properties to center the “ball” inside. This is important because as the ball changes sizes, I want it to remain centered.</p><p>Each .ball gets an initial width and height of 0. A border-radius of 50% turns them into circles, and a background-color makes them visible.</p><p><strong>Animation:</strong> The animation follows the same logic as example-2 except I am manipulating each ball’s height <em>and</em> width.</p><p>From 0% to 20%, they grow from 0 x 0 to 1.5em x 1.5em. I keep them at this size from 20% to 40%. From 40% to 90% they shrink down to 0 x 0, and remain there from 90% to 100%.</p><p>I set each ball to have an animation property with a duration of 1.2s, iteration count of infinite, and name example-four.</p><p>Finally, I grab each ball by their individual ID so I can add an animation-delay to #ball-2 and #ball-3. This staggers the animation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*8mhC--2dzisAZiRXiGxU2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*725YRhtFcJqNJ0zYsxLfCw.png" /></figure><h4>Conclusion</h4><p>Thanks for reading the blog. I hope you found some of it useful.</p><p>At minimum, I hope one of my loaders transported you to that timeless place where — just for a moment — you felt the balance of the universe, tasted a slice of nirvana, inner peace. Best, Jason.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8eaa25183246" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/build-a-simple-loader-with-css-and-html-8eaa25183246">Build a Simple Loader With CSS and HTML</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build This Awesome Password Checklist with React and CSS]]></title>
            <link>https://cooljasonmelton.medium.com/build-this-awesome-password-checklist-with-react-and-css-2b9d7e71108b?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b9d7e71108b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sat, 29 Aug 2020 09:06:11 GMT</pubDate>
            <atom:updated>2020-08-30T05:47:04.447Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xrFC5YYLMFOA5aiT_1wujA.png" /></figure><h3>Build This Cool Password Checklist with React and CSS</h3><p>My other <a href="https://medium.com/swlh/build-this-cool-sign-in-form-with-react-and-css-f9339d14d140">blog</a> about building cool sign up form got a lot of attention, so I decided to write another tutorial for a ~cool form~.</p><p>This is a tutorial for how to build this animated password checklist:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*4kgx6OqEJPulfPL6IYXFzA.gif" /></figure><blockquote><em>The code on </em><a href="https://github.com/cooljasonmelton/password-checklist"><em>GitHub</em></a></blockquote><h3>Tutorial</h3><p>Table of Contents</p><ul><li>Preliminary Junk</li><li>Update Password Form</li><li>MustContainItem Component</li><li>Validation Checklist Functionality</li></ul><h4>Preliminary Junk</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*3qTIqyXZSziFSvHmCOkugQ.png" /></figure><p>To create this demo, I entered create-react-app into my terminal, deleted the preliminary junk, and set up a file structure like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*IWaUuGsJrM2lnJaS44PeMg.png" /></figure><p>I added some basic styles to things and created a class called cfb that adds a flexbox centering the children of an element to which it’s applied. Also, I found out some nice colors using <a href="https://coolors.co/ef476f-ffd166-06d6a0-daf3fc-073b4c">Coolors.co</a>.</p><h4>Update Password Form</h4><p>This project’s purpose is to validate a password as it’s entered into an update form. The first thing I need is a password to validate. In UpdatePasswordContainer.js, I set up a form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*esefjTt_rEFkE2csHjaIKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*joh0a9YYN5VzSewQ3UFEDA.png" /></figure><p>I will explain validatePassword() in detail later, but it checks the password to make sure it meets the requirements.</p><p>The allValid variable enables the submit button if the password passes all requirements.</p><p>Otherwise, this is a fairly typical React form. It’s inputs update the useState hook onChange for each input and then displays the useState variable as its value.</p><h4>MustContainItem Component</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*0D_hP4sLrzBr3LdQ3QK4mw.png" /></figure><p>Each item on the list will be represented by a MustContainItem component which looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*lDHcLW_AlAvAG2g0PumYog.png" /></figure><p>The MustContainItem takes props of data, which is an array containing a string that labels the item and a boolean of whether or not the requirement has been met.</p><p>In the div with class must-item, I put label in a li node. Then I created a div that receives its class from a function called setClass().</p><p>setClass() returns a string of classnames that will conditionally animate a line striking through label based on meetsReq, the boolean from props.</p><p>Here’s the CSS:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*J1sz-nuPa6HTr9FFXHoXmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*8yvbq5eNAjbz0mhy9MCcDA.png" /></figure><p>I give the must-item parent container a position: relative; so that the child li node and must-line div are positioned absolutely on top of each other.</p><p>must-line gets a z-index of 1. It&#39;s positioned on top of must-text which has a z-index of 0. It will cover the text when it appears.</p><p>Initially, must-line gets a width of 0. When I add the class cross-out, the div’s width expands to 100% and, due to transition, the div&#39;s width animates between sizes.</p><h4>Validation Checklist Functionality</h4><p>The final step is to actually check the password to see if it meets the requirements and update all the relevant components.</p><p>First, I set up a useState hook for each requirement that I want to put on a new password. Then, I set up a hook for when all the requirements are met, allValid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*CcO8MtS0EcE9QzPVbXmTmg.png" /></figure><p>Next, I set up an array of arrays. Each of the inner arrays contains the label string and corresponding useState variable to pass to a MustContainItem as props.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*COt7U7TR7E9gkdXQQLrHTQ.png" /></figure><p>I map() this array creating a MustContainItem for each array in the array, passed to the component as props named data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*N1FSfWFj0DPqkqrc86F6HQ.png" /></figure><p>Everything is set up at this point except for the actual validating of the password.</p><p>I check the password after each character is added or deleted in case a required character is added and then later deleted. For this, I used onKeyUp. Each time, a key is lifted, I run the function validatePassword().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*dsbuXcC06c8f1Ql1vNiMDA.png" /></figure><p>validatePassword() runs a series of conditional statements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*EkoIaNv1QpdT9PHhYIvaYA.png" /></figure><p>Each conditional checks the passwordOne variable stored in a useState hook for a different thing. If passwordOne meets the requirement, it updates that specific requirement’s useState hook. If the hook updates, the strikethrough animation is triggered. Viola.</p><p>Hope this is interesting or helpful!<br>Again, you can find all the code <a href="https://github.com/cooljasonmelton/password-checklist">here</a>.<br>Best, Jason.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b9d7e71108b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[If Ruby’s so Happy, What’s %w(a b c)]]></title>
            <link>https://cooljasonmelton.medium.com/if-rubys-so-happy-what-s-w-a-b-c-66cb903ddf39?source=rss-26697fd0b4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/66cb903ddf39</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Jason Melton]]></dc:creator>
            <pubDate>Sat, 22 Aug 2020 08:22:39 GMT</pubDate>
            <atom:updated>2020-08-28T20:08:25.776Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*BNJFIe6uIwDq9xLXw1-GJQ.jpeg" /></figure><p>When I started learning Ruby, I came across this quote about 50 times:</p><blockquote><em>I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language.</em></blockquote><p>According to its creator, Yukihiro Matsumoto, the goal of Ruby is to make programmers happy. For me, that was mostly true. There’s very few reserved words to memorize, tons of useful, baked-in methods, parentheses are often optional. It is a really clean language — to learn and use.</p><p>However, every once in a while, I would come across something like this:</p><pre>%w(a b c)</pre><p>Usually, I would find something like this while I’m in the middle of a bug, skimming docs, looking for a quick solution. Usually time was an issue so if I came across the odd percentage notation, annoyed, I’d skip it and open a new tab.</p><p>I’d think something like: If Ruby’s so happy, then what the hell is this??</p><h3>Ruby Literals</h3><p>“A literal is a special syntax in the Ruby language that creates an object of a specific type.” [ <a href="https://www.thoughtco.com/string-literals-2908302#:~:text=A%20literal%20is%20a%20special,literals%2C%20there%20are%20several%20forms.">1.</a>]</p><p>Everything in Ruby is an object. Strings, integers, arrays and everything else have a class that dictates their identity, state, and behavior. To create an instance of one of these objects from its class, we invoke it with a literal.</p><p>These odd looking % signs are shorthand ways of invoking a literal. For example, %w invokes an array of strings. It works like this:</p><pre>%w(a b c)     # [a, b, c]<br>%w(turtle cat different turtle)  # [turtle, cat, different, turtle]</pre><p>According to a <a href="https://stackoverflow.com/questions/1274675/what-does-warray-mean/1275147#1275147">post</a> on Stack Overflow:</p><blockquote><em>There are other % literals:<br>%r() is another way to write a regular expression.<br>%q() is another way to write a single-quoted string (and can be multi-line, which is useful)<br>%Q() gives a double-quoted string<br>%x() is a shell command<br>%i() gives an array of symbols (Ruby &gt;= 2.0.0)<br>%s() turns foo into a symbol (:foo)</em></blockquote><p>And there’s other notations too. Check this <a href="https://www.w3resource.com/ruby/ruby-literals.php#:~:text=We%20have%20already%20seen%20literals,Booleans%20and%20nil">link</a> for more literals.</p><h3>Conclusion</h3><p>I learned %w isn’t some happiness obfuscating headache. It’s actually another way Ruby gives its user options. It’s honestly pretty nice. Hell yeah, Ruby.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66cb903ddf39" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>