<?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 Kshitiz Chandra on Medium]]></title>
        <description><![CDATA[Stories by Kshitiz Chandra on Medium]]></description>
        <link>https://medium.com/@kshitiz.chndra?source=rss-a72ef1ab81cd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5Ra03e-Dxv2E6ApR</url>
            <title>Stories by Kshitiz Chandra on Medium</title>
            <link>https://medium.com/@kshitiz.chndra?source=rss-a72ef1ab81cd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:10:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kshitiz.chndra/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[React exercises — fill the missing parts.]]></title>
            <link>https://medium.com/@kshitiz.chndra/react-exercises-fill-the-missing-parts-9d9957177b4f?source=rss-a72ef1ab81cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d9957177b4f</guid>
            <dc:creator><![CDATA[Kshitiz Chandra]]></dc:creator>
            <pubDate>Wed, 04 Nov 2026 14:15:49 GMT</pubDate>
            <atom:updated>2026-11-04T14:15:49.042Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re learning React or working towards becoming a Design Engineer, try solving these exercises yourself.</p><ol><li><strong>Real time search project-</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjhhpWL9DidKbgNiM1uRgQ.jpeg" /></figure><p><strong>Starter code -</strong></p><pre>import { useState } from &quot;react&quot;;<br><br>const projects = [<br>  { id: 1, name: &quot;Portfolio Redesign&quot;, category: &quot;UI Design&quot; },<br>  { id: 2, name: &quot;Music Player&quot;, category: &quot;Development&quot; },<br>  { id: 3, name: &quot;Color Picker&quot;, category: &quot;Experiments&quot; },<br>  { id: 4, name: &quot;Design System&quot;, category: &quot;UI Design&quot; },<br>];<br><br>export default function ProjectGallery() {<br>  const [search, setSearch] = useState(&quot;&quot;);<br>  const [category, setCategory] = useState(&quot;All&quot;);<br><br>  // TODO 1: Derive the projects that match BOTH filters.<br>  // Do not create unnecessary state for filteredProjects.<br><br><br>  return (<br>    &lt;section&gt;<br>      &lt;input<br>        value={search}<br>        onChange={(e) =&gt; {<br>          // TODO 2: Update search state.<br>        }}<br>        placeholder=&quot;Search projects...&quot;<br>      /&gt;<br><br>      {[&quot;All&quot;, &quot;UI Design&quot;, &quot;Development&quot;, &quot;Experiments&quot;].map(<br>        (item) =&gt; (<br>          &lt;button<br>            key={item}<br>            onClick={() =&gt; {<br>              // TODO 3: Update selected category.<br>            }}<br>          &gt;<br>            {item}<br>          &lt;/button&gt;<br>        )<br>      )}<br><br>      &lt;div className=&quot;project-grid&quot;&gt;<br>        {/* TODO 4: Render filtered projects here. */}<br><br>        {/* TODO 5: Show &quot;No projects found&quot; if there<br>            are no matches. */}<br>      &lt;/div&gt;<br>    &lt;/section&gt;<br>  );<br>}</pre><p><strong>2. Multi-select filter dropdown-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iqgxFEcHcIN8oSCwYhA3jg.jpeg" /></figure><p><strong>Starter code -</strong></p><pre>import { useState } from &quot;react&quot;;<br><br>const methods = [<br>  &quot;Credit card&quot;,<br>  &quot;UPI&quot;,<br>  &quot;Net banking&quot;,<br>  &quot;Wallet&quot;,<br>];<br><br>export default function PaymentFilter() {<br>  const [selected, setSelected] = useState([<br>    &quot;Credit card&quot;,<br>  ]);<br>  const [isOpen, setIsOpen] = useState(false);<br><br>  function toggleMethod(method) {<br>    // TODO 1:<br>    // If method is selected, remove it.<br>    // Otherwise, add it.<br>    // Never mutate the existing array.<br>  }<br><br>  function selectAll() {<br>    // TODO 2: Select every method.<br>  }<br><br>  function clearAll() {<br>    // TODO 3: Clear every selection.<br>  }<br><br>  return (<br>    &lt;div className=&quot;filter&quot;&gt;<br>      &lt;button onClick={() =&gt; setIsOpen(!isOpen)}&gt;<br>        Payment method ({selected.length})<br>      &lt;/button&gt;<br><br>      {isOpen &amp;&amp; (<br>        &lt;div className=&quot;dropdown&quot;&gt;<br>          {methods.map((method) =&gt; (<br>            &lt;label key={method}&gt;<br>              &lt;input<br>                type=&quot;checkbox&quot;<br>                checked={selected.includes(method)}<br>                onChange={() =&gt; toggleMethod(method)}<br>              /&gt;<br>              {method}<br>            &lt;/label&gt;<br>          ))}<br><br>          &lt;button onClick={selectAll}&gt;Select all&lt;/button&gt;<br>          &lt;button onClick={clearAll}&gt;Clear&lt;/button&gt;<br>        &lt;/div&gt;<br>      )}<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>3. An interactive shopping cart-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vV9gf3NDaMuPXkVkPDOpPw.jpeg" /></figure><p><strong>Starter code -</strong></p><pre>import { useState } from &quot;react&quot;;<br><br>const initialCart = [<br>  { id: 1, name: &quot;Keyboard&quot;, price: 2500, qty: 1 },<br>  { id: 2, name: &quot;Mouse&quot;, price: 1200, qty: 2 },<br>];<br><br>export default function Cart() {<br>  const [cart, setCart] = useState(initialCart);<br><br>  function changeQuantity(id, amount) {<br>    // TODO 1: Update only the matching item.<br>    // Do not mutate the original item or array.<br>    // Quantity must never fall below 1.<br>  }<br><br>  function removeItem(id) {<br>    // TODO 2: Remove the matching item.<br>  }<br><br>  // TODO 3: Calculate subtotal from current cart state.<br>  // Each item&#39;s contribution = price * qty.<br><br>  return (<br>    &lt;section&gt;<br>      {cart.map((item) =&gt; (<br>        &lt;article key={item.id}&gt;<br>          &lt;h3&gt;{item.name}&lt;/h3&gt;<br>          &lt;p&gt;₹{item.price}&lt;/p&gt;<br><br>          &lt;button<br>            onClick={() =&gt; changeQuantity(item.id, -1)}<br>          &gt;<br>            −<br>          &lt;/button&gt;<br><br>          &lt;span&gt;{item.qty}&lt;/span&gt;<br><br>          &lt;button<br>            onClick={() =&gt; changeQuantity(item.id, 1)}<br>          &gt;<br>            +<br>          &lt;/button&gt;<br><br>          &lt;button onClick={() =&gt; removeItem(item.id)}&gt;<br>            Remove<br>          &lt;/button&gt;<br>        &lt;/article&gt;<br>      ))}<br><br>      {/* TODO 4: Render the subtotal. */}<br><br>      {/* TODO 5: Render a useful empty-cart state. */}<br>    &lt;/section&gt;<br>  );<br>}</pre><p><strong>4. Form with dependent validation-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WcoBeLtf5iFwE_Kmm8fPAg.jpeg" /></figure><p><strong>Starter code -</strong></p><pre>import { useState } from &quot;react&quot;;<br><br>export default function SignupForm() {<br>  const [form, setForm] = useState({<br>    email: &quot;&quot;,<br>    password: &quot;&quot;,<br>    confirmPassword: &quot;&quot;,<br>  });<br><br>  const [errors, setErrors] = useState({});<br>  const [submitted, setSubmitted] = useState(false);<br><br>  function handleChange(e) {<br>    const { name, value } = e.target;<br><br>    // TODO 1: Update only the changed form field.<br>  }<br><br>  function validate() {<br>    const nextErrors = {};<br><br>    // TODO 2: Validate email format.<br>    // TODO 3: Require a password of at least 8 characters.<br>    // TODO 4: Confirm both passwords match.<br><br>    setErrors(nextErrors);<br><br>    // TODO 5: Return whether the form is valid.<br>  }<br><br>  function handleSubmit(e) {<br>    e.preventDefault();<br><br>    // TODO 6: Validate before marking as submitted.<br>    // Invalid forms must not show success.<br>  }<br><br>  return (<br>    &lt;form onSubmit={handleSubmit}&gt;<br>      &lt;input<br>        name=&quot;email&quot;<br>        value={form.email}<br>        onChange={handleChange}<br>        placeholder=&quot;Email&quot;<br>      /&gt;<br>      {errors.email &amp;&amp; &lt;p&gt;{errors.email}&lt;/p&gt;}<br><br>      &lt;input<br>        name=&quot;password&quot;<br>        type=&quot;password&quot;<br>        value={form.password}<br>        onChange={handleChange}<br>        placeholder=&quot;Password&quot;<br>      /&gt;<br>      {errors.password &amp;&amp; &lt;p&gt;{errors.password}&lt;/p&gt;}<br><br>      &lt;input<br>        name=&quot;confirmPassword&quot;<br>        type=&quot;password&quot;<br>        value={form.confirmPassword}<br>        onChange={handleChange}<br>        placeholder=&quot;Confirm password&quot;<br>      /&gt;<br>      {errors.confirmPassword &amp;&amp; (<br>        &lt;p&gt;{errors.confirmPassword}&lt;/p&gt;<br>      )}<br><br>      &lt;button type=&quot;submit&quot;&gt;Create account&lt;/button&gt;<br><br>      {/* TODO 7: Render success feedback only when valid. */}<br>    &lt;/form&gt;<br>  );<br>}</pre><p><strong>5. Product Gallery -</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubHbHFBi_psIJCoksNMCaQ.jpeg" /></figure><p><strong>Starter code -</strong></p><pre><br>import { useState } from &quot;react&quot;;<br><br>const products = [<br>  { id: 1, name: &quot;Mechanical Keyboard&quot;, category: &quot;Accessories&quot;, price: 2500 },<br>  { id: 2, name: &quot;Wireless Mouse&quot;, category: &quot;Accessories&quot;, price: 1200 },<br>  { id: 3, name: &quot;Monitor&quot;, category: &quot;Electronics&quot;, price: 15000 },<br>  { id: 4, name: &quot;USB Hub&quot;, category: &quot;Electronics&quot;, price: 1800 },<br>  { id: 5, name: &quot;Desk Lamp&quot;, category: &quot;Home&quot;, price: 2200 },<br>  { id: 6, name: &quot;Laptop Stand&quot;, category: &quot;Accessories&quot;, price: 1600 },<br>  { id: 7, name: &quot;Headphones&quot;, category: &quot;Electronics&quot;, price: 4500 },<br>  { id: 8, name: &quot;Desk Mat&quot;, category: &quot;Home&quot;, price: 900 },<br>];<br><br>function ProductGallery() {<br>  const [search, setSearch] = useState(&quot;&quot;);<br>  const [category, setCategory] = useState(&quot;All&quot;);<br>  const [maxprice, setMaxprice] = useState(&quot;&quot;);<br>  const [sortstate, setSortstate] = useState(&quot;Default&quot;);<br><br>  // TODO 1: Filter products by search term.<br><br>  // TODO 2: Filter products by category.<br><br>  // TODO 3: Filter products by maximum price.<br>  // Remember that input values are strings.<br><br>  // TODO 4: Combine all three filtering conditions.<br><br>  // TODO 5: Sort the filtered products.<br>  // High to Low and Low to High.<br>  // Do not mutate the original products array.<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Product Gallery&lt;/h1&gt;<br><br>      &lt;input<br>        type=&quot;text&quot;<br>        placeholder=&quot;Search products...&quot;<br>        value={search}<br>        onChange={(e) =&gt; setSearch(e.target.value)}<br>      /&gt;<br><br>      &lt;select<br>        value={category}<br>        onChange={(e) =&gt; setCategory(e.target.value)}<br>      &gt;<br>        &lt;option value=&quot;All&quot;&gt;All Categories&lt;/option&gt;<br>        &lt;option value=&quot;Accessories&quot;&gt;Accessories&lt;/option&gt;<br>        &lt;option value=&quot;Electronics&quot;&gt;Electronics&lt;/option&gt;<br>        &lt;option value=&quot;Home&quot;&gt;Home&lt;/option&gt;<br>      &lt;/select&gt;<br><br>      &lt;input<br>        type=&quot;number&quot;<br>        placeholder=&quot;Maximum price&quot;<br>        value={maxprice}<br>        onChange={(e) =&gt; setMaxprice(e.target.value)}<br>      /&gt;<br><br>      &lt;select<br>        value={sortstate}<br>        onChange={(e) =&gt; setSortstate(e.target.value)}<br>      &gt;<br>        &lt;option value=&quot;Default&quot;&gt;Default&lt;/option&gt;<br>        &lt;option value=&quot;High to Low&quot;&gt;High to Low&lt;/option&gt;<br>        &lt;option value=&quot;Low to High&quot;&gt;Low to High&lt;/option&gt;<br>      &lt;/select&gt;<br><br>      {/* TODO 6: Display the number of matching products. */}<br><br>      {/* TODO 7: Render the sorted products using map(). */}<br><br>      {/* TODO 8: Display an empty state when there are no matches. */}<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default ProductGallery;</pre><p><strong>6. Persistent Shopping Cart-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*izNZSjMJvyG61Zr_x4fttw.jpeg" /></figure><p><strong>Starter code -</strong></p><pre><br>import { useEffect, useState } from &quot;react&quot;;<br><br>const products = [<br>  { id: 1, name: &quot;Keyboard&quot;, price: 2500 },<br>  { id: 2, name: &quot;Mouse&quot;, price: 1200 },<br>  { id: 3, name: &quot;Monitor&quot;, price: 15000 },<br>  { id: 4, name: &quot;Headphones&quot;, price: 4500 },<br>];<br><br>function PersistentShoppingCart() {<br><br>  // TODO 1: Initialize cart state using localStorage.<br>  // If stored cart data exists, load it.<br>  // Otherwise, start with an empty array.<br><br>  const [cart, setCart] = useState([]);<br><br>  // TODO 2: Create a function to add a product to the cart.<br>  // If the product already exists, increase its quantity.<br>  // Otherwise, add it with quantity 1.<br><br>  // TODO 3: Create a function to increase/decrease quantity.<br>  // Quantity should never go below 1.<br><br>  // TODO 4: Create a function to remove a product.<br><br>  // TODO 5: Use useEffect to save the cart to localStorage<br>  // whenever the cart changes.<br><br>  // TODO 6: Calculate the total cart value.<br><br>  // TODO 7: Calculate the total number of items.<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Persistent Shopping Cart&lt;/h1&gt;<br><br>      &lt;h2&gt;Products&lt;/h2&gt;<br><br>      {/* TODO 8: Render products with an Add to Cart button. */}<br><br>      &lt;h2&gt;Your Cart&lt;/h2&gt;<br><br>      {/* TODO 9: Render cart items with quantity controls. */}<br><br>      {/* TODO 10: Add remove buttons. */}<br><br>      {/* TODO 11: Display total items and total price. */}<br><br>      {/* TODO 12: Display an empty cart message. */}<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default PersistentShoppingCart;</pre><p><strong>7. User Directory-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CBXSR7jp45txu3JmoetvCg.jpeg" /></figure><p><strong>Starter code -</strong></p><p><strong>API </strong>: <a href="https://jsonplaceholder.typicode.com/users">https://jsonplaceholder.typicode.com/users</a></p><pre><br>import { useEffect, useState } from &quot;react&quot;;<br><br>function UserDirectory() {<br>  const [users, setUsers] = useState([]);<br>  const [loading, setLoading] = useState(true);<br>  const [error, setError] = useState(null);<br><br>  const [search, setSearch] = useState(&quot;&quot;);<br>  const [city, setCity] = useState(&quot;All&quot;);<br>  const [sortState, setSortState] = useState(&quot;A to Z&quot;);<br>  const [currentPage, setCurrentPage] = useState(1);<br><br>  const usersPerPage = 4;<br><br>  // TODO 1: Fetch users from the API using useEffect.<br><br>  // TODO 2: Handle loading and error states.<br><br>  // TODO 3: Create a list of unique cities from the users array.<br><br>  // TODO 4: Filter users by name or username.<br><br>  // TODO 5: Filter users by city.<br><br>  // TODO 6: Combine search and city filtering.<br><br>  // TODO 7: Sort users alphabetically.<br>  // Support A to Z and Z to A.<br><br>  // TODO 8: Calculate pagination indexes.<br><br>  // TODO 9: Use slice() to get users for the current page.<br><br>  // TODO 10: Calculate the total number of pages.<br><br>  // TODO 11: Reset the current page to 1 when filters change.<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;User Directory&lt;/h1&gt;<br><br>      &lt;input<br>        type=&quot;text&quot;<br>        placeholder=&quot;Search by name or username&quot;<br>        value={search}<br>        onChange={(e) =&gt; setSearch(e.target.value)}<br>      /&gt;<br><br>      &lt;select<br>        value={city}<br>        onChange={(e) =&gt; setCity(e.target.value)}<br>      &gt;<br>        &lt;option value=&quot;All&quot;&gt;All Cities&lt;/option&gt;<br>        {/* TODO 12: Render unique city options. */}<br>      &lt;/select&gt;<br><br>      &lt;select<br>        value={sortState}<br>        onChange={(e) =&gt; setSortState(e.target.value)}<br>      &gt;<br>        &lt;option value=&quot;A to Z&quot;&gt;A to Z&lt;/option&gt;<br>        &lt;option value=&quot;Z to A&quot;&gt;Z to A&lt;/option&gt;<br>      &lt;/select&gt;<br><br>      {/* TODO 13: Show loading message. */}<br><br>      {/* TODO 14: Show error message. */}<br><br>      {/* TODO 15: Render current page users. */}<br><br>      {/* TODO 16: Show empty state when no users match. */}<br><br>      {/* TODO 17: Display current page and total pages. */}<br><br>      &lt;button&gt;Previous&lt;/button&gt;<br>      &lt;button&gt;Next&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default UserDirectory;</pre><p><strong>8. Post Explorer-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4HSONBEALZGhZZsigoO_Kg.jpeg" /></figure><p><strong>Starter code-</strong></p><p>API pattern:</p><p><a href="https://jsonplaceholder.typicode.com/posts/1">https://jsonplaceholder.typicode.com/posts/1</a></p><pre><br>import { useState } from &quot;react&quot;;<br><br>function PostExplorer() {<br>  // TODO 1: Store the input value.<br>  const [input, setInput] = useState(&quot;&quot;);<br><br>  // TODO 2: Store the fetched post data.<br>  const [postData, setPostData] = useState(null);<br><br>  // TODO 3: Store loading state.<br>  const [loadState, setLoadState] = useState(false);<br><br>  // TODO 4: Store error state.<br>  const [errorState, setErrorState] = useState(null);<br><br>  // TODO 5: Create an async fetchPost function.<br><br>  // TODO 6: Use try/catch/finally to handle the request.<br><br>  // TODO 7: Validate that the post ID is an integer between 1 and 100.<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Post Explorer&lt;/h1&gt;<br><br>      &lt;input<br>        type=&quot;number&quot;<br>        placeholder=&quot;Enter post ID (1-100)&quot;<br>        value={input}<br>        onChange={(e) =&gt; setInput(e.target.value)}<br>      /&gt;<br><br>      &lt;button&gt;<br>        Fetch Post<br>      &lt;/button&gt;<br><br>      {/* TODO 8: Display a loading message. */}<br><br>      {/* TODO 9: Display an error message. */}<br><br>      {/* TODO 10: Display post title, body and ID. */}<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default PostExplorer;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d9957177b4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Custom React Color Picker: Recreating Paper’s UI]]></title>
            <link>https://medium.com/@kshitiz.chndra/how-to-build-a-custom-react-color-picker-recreating-papers-ui-4714b7b31666?source=rss-a72ef1ab81cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/4714b7b31666</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kshitiz Chandra]]></dc:creator>
            <pubDate>Fri, 25 Sep 2026 11:55:09 GMT</pubDate>
            <atom:updated>2026-09-25T12:31:10.042Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>A step-by-step breakdown of reverse-engineering a complex, production-grade UI component in React.</strong></p><p>This is what color picker in <a href="https://paper.design/">Paper</a> looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eCTHj40XDlKBCJXKScG-XQ.png" /><figcaption>Color picker in Paper</figcaption></figure><p>We will build this in React from scratch. Let’s see how to build it step by step. We will break this component down into parts and then keep on adding different parts to make it a proper color picker component.</p><p>This will be our flow that we will follow to build our desired component -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgQ-wLr9a15H2xZrwM1N9Q.png" /></figure><h4><strong>1. Starting with color values-</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ot9D5rSjezKtktSiRtyTfQ.png" /></figure><p>As we can see there are so many color values and their representations, we need a mathematical system to allow us to easily convert these values into each other as and when required. For example, if we change the value of R, all other values corresponding to it should change.</p><p>We need some information to represent the color so we introduce HSV which we will treat as our internal source of truth. Now, we don’t have to calculate every color space from scratch. We reuse algebraic conversions, just like algebraic substitution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HCbT7z_1S-bmjkufmT5jeQ.png" /></figure><p>As we can see from above image, we will derive all other states of colors from HSV state. By using AI, we can write all color conversion functions and use it as per our convenience.</p><p>Below are the color conversion functions -</p><pre>export function hsvToRgb({ h, s, v }) {<br>  const c = v * s<br>  const x = c * (1 - Math.abs(((h / 60) % 2) - 1))<br>  const m = v - c<br>  const [r, g, b] = h &lt; 60 ? [c, x, 0] : h &lt; 120 ? [x, c, 0] : h &lt; 180 ? [0, c, x] : h &lt; 240 ? [0, x, c] : h &lt; 300 ? [x, 0, c] : [c, 0, x]<br>  return { r: Math.round((r + m) * 255), g: Math.round((g + m) * 255), b: Math.round((b + m) * 255) }<br>}<br><br>export function rgbToHsv({ r, g, b }) {<br>  const values = [r, g, b].map((v) =&gt; v / 255)<br>  const max = Math.max(...values), min = Math.min(...values), d = max - min<br>  let h = 0<br>  if (d) h = max === values[0] ? 60 * (((values[1] - values[2]) / d) % 6) : max === values[1] ? 60 * ((values[2] - values[0]) / d + 2) : 60 * ((values[0] - values[1]) / d + 4)<br>  return { h: (h + 360) % 360, s: max ? d / max : 0, v: max }<br>}<br><br>export function hslToRgb({ h, s, l }) {<br>  const hue = ((h % 360) + 360) % 360 / 360<br>  const a = s * Math.min(l, 1 - l)<br>  const f = (n) =&gt; {<br>    const k = (n + hue * 12) % 12<br>    return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1))<br>  }<br>  return { r: Math.round(f(0) * 255), g: Math.round(f(8) * 255), b: Math.round(f(4) * 255) }<br>}<br><br>export function rgbToHsl({ r, g, b }) {<br>  const [red, green, blue] = [r, g, b].map((v) =&gt; v / 255)<br>  const max = Math.max(red, green, blue), min = Math.min(red, green, blue), d = max - min<br>  const l = (max + min) / 2<br>  if (!d) return { h: 0, s: 0, l }<br>  const s = d / (1 - Math.abs(2 * l - 1))<br>  let h = max === red ? (green - blue) / d + (green &lt; blue ? 6 : 0) : max === green ? (blue - red) / d + 2 : (red - green) / d + 4<br>  return { h: h * 60, s, l }<br>}<br><br>function rgbToLab({ r, g, b }) {<br>  const linear = [r, g, b].map((value) =&gt; { const v = value / 255; return v &lt;= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4 })<br>  const [x, y, z] = [0.4124, 0.3576, 0.1805, 0.2126, 0.7152, 0.0722, 0.0193, 0.1192, 0.9505].reduce((acc, value, index) =&gt; { const row = Math.floor(index / 3); acc[row] += value * linear[index % 3]; return acc }, [0, 0, 0])<br>  const f = (value) =&gt; value &gt; 0.008856 ? value ** (1 / 3) : 7.787 * value + 16 / 116<br>  const [fx, fy, fz] = [f(x / 0.95047), f(y), f(z / 1.08883)]<br>  return { l: 116 * fy - 16, a: 500 * (fx - fy), b: 200 * (fy - fz) }<br>}<br><br>function labToRgb({ l, a, b }) {<br>  const fy = (l + 16) / 116, fx = a / 500 + fy, fz = fy - b / 200<br>  const finv = (value) =&gt; { const cube = value ** 3; return cube &gt; 0.008856 ? cube : (value - 16 / 116) / 7.787 }<br>  const [x, y, z] = [0.95047 * finv(fx), finv(fy), 1.08883 * finv(fz)]<br>  const linear = [3.2406 * x - 1.5372 * y - 0.4986 * z, -0.9689 * x + 1.8758 * y + 0.0415 * z, 0.0557 * x - 0.204 * y + 1.057 * z]<br>  const convert = (value) =&gt; clamp(255 * (value &lt;= 0.0031308 ? 12.92 * value : 1.055 * value ** (1 / 2.4) - 0.055), 0, 255)<br>  return { r: Math.round(convert(linear[0])), g: Math.round(convert(linear[1])), b: Math.round(convert(linear[2])) }<br>}<br><br>export function rgbToLch(rgb) {<br>  const lab = rgbToLab(rgb)<br>  return { l: lab.l, c: Math.sqrt(lab.a ** 2 + lab.b ** 2), h: (Math.atan2(lab.b, lab.a) * 180 / Math.PI + 360) % 360 }<br>}</pre><p>At this point we have built several individual functions.</p><p>We can now compose them.</p><p>The component shouldn’t have to manually call:</p><p>hsvToRgb()<br>rgbToHsl()<br>rgbToLch()</p><p>everywhere.</p><p>Instead, we create one function:</p><pre>export function formatColor(color) {<br>  const rgb = hsvToRgb(color)<br><br>  const hex = [rgb.r, rgb.g, rgb.b]<br>    .map((v) =&gt; v.toString(16).padStart(2, &#39;0&#39;))<br>    .join(&#39;&#39;)<br>    .toUpperCase()<br><br>  const hsl = rgbToHsl(rgb)<br><br>  const lch = rgbToLch(rgb)<br><br>  return {<br>    rgb,<br>    hex: `#${hex}`,<br>    hsl,<br>    lch,<br>    alpha: Math.round(color.a * 100)<br>  }<br>}</pre><p>Now we can derive one color representation from another as :</p><pre>color<br>  ↓<br>hsvToRgb(color)<br>  ↓<br>rgb<br>  ↓<br>rgbToHsl(rgb)<br>  ↓<br>hsl</pre><p>And:</p><pre>color<br>  ↓<br>hsvToRgb(color)<br>  ↓<br>rgb<br>  ↓<br>rgbToLch(rgb)<br>  ↓<br>lch</pre><h4>Converting RGB back into our internal state -</h4><p>Until now, we have seen HSV → RGB, but what if we want to convert RGB → HSV. For that we need another set of functions which will convert the values to our internal state.</p><pre>export function parseLch(values, current) {<br>  const numbers = values.map(Number)<br>  if (numbers.some((value) =&gt; !Number.isFinite(value))) return current<br>  const h = ((numbers[2] % 360) + 360) % 360<br>  const rgb = labToRgb({ l: clamp(numbers[0], 0, 100), a: clamp(numbers[1], 0, 150) * Math.cos(h * Math.PI / 180), b: clamp(numbers[1], 0, 150) * Math.sin(h * Math.PI / 180) })<br>  return { ...rgbToHsv(rgb), a: current.a }<br>}<br><br>export function parseHex(value, current) {<br>  const parts = value.replace(&#39;#&#39;, &#39;&#39;).split(&#39;/&#39;).map((part) =&gt; part.trim())<br>  const clean = parts[0]<br>  if (!/^[0-9a-f]{6}$/i.test(clean)) return current<br>  const rgb = { r: parseInt(clean.slice(0, 2), 16), g: parseInt(clean.slice(2, 4), 16), b: parseInt(clean.slice(4, 6), 16) }<br>  const alpha = parts[1] ? clamp(parseFloat(parts[1]) / 100) : current.a<br>  return { ...rgbToHsv(rgb), a: Number.isFinite(alpha) ? alpha : current.a }<br>}<br><br>export function parseFormatted(value, format, current) {<br>  const numbers = value.match(/-?\d*\.?\d+/g)?.map(Number) || []<br>  if (format === &#39;hex&#39;) return parseHex(value, current)<br>  if (format === &#39;rgb&#39; &amp;&amp; numbers.length &gt;= 3) return { ...parseRgb(numbers, current), a: numbers[3] === undefined ? current.a : clamp(numbers[3] / 100) }<br>  if (format === &#39;hsl&#39; &amp;&amp; numbers.length &gt;= 3) return { ...parseHsl(numbers, current), a: numbers[3] === undefined ? current.a : clamp(numbers[3] / 100) }<br>  if (format === &#39;oklch&#39; &amp;&amp; numbers.length &gt;= 3) return { ...parseLch([numbers[0], numbers[1], numbers[2]], current), a: numbers[3] === undefined ? current.a : clamp(numbers[3] / 100) }<br>  return current<br>}<br><br>export function parseRgb(values, current) {<br>  const numbers = values.map((value) =&gt; Number(value))<br>  if (numbers.some((value) =&gt; !Number.isFinite(value))) return current<br>  const rgb = { r: clamp(numbers[0], 0, 255), g: clamp(numbers[1], 0, 255), b: clamp(numbers[2], 0, 255) }<br>  return { ...rgbToHsv(rgb), a: current.a }<br>}<br><br>export function parseHsl(values, current) {<br>  const numbers = values.map((value) =&gt; Number(value))<br>  if (numbers.some((value) =&gt; !Number.isFinite(value))) return current<br>  const rgb = hslToRgb({ h: numbers[0], s: clamp(numbers[1], 0, 100) / 100, l: clamp(numbers[2], 0, 100) / 100 })<br>  return { ...rgbToHsv(rgb), a: current.a }<br>}<br><br>export function parseHsv(values, current) {<br>  const numbers = values.map((value) =&gt; Number(value))<br>  if (numbers.some((value) =&gt; !Number.isFinite(value))) return current<br>  return { h: ((numbers[0] % 360) + 360) % 360, s: clamp(numbers[1], 0, 100) / 100, v: clamp(numbers[2], 0, 100) / 100, a: current.a }<br>}<br></pre><p>Collecting everything with formatColor-</p><pre>export function formatColor(color) {<br>  const rgb = hsvToRgb(color)<br>  const hex = [rgb.r, rgb.g, rgb.b].map((v) =&gt; v.toString(16).padStart(2, &#39;0&#39;)).join(&#39;&#39;).toUpperCase()<br>  const hsl = rgbToHsl(rgb)<br>  const lch = rgbToLch(rgb)<br>  return { rgb, hex: `#${hex}`, hsl, lch, alpha: Math.round(color.a * 100) }<br>}</pre><p>Writing the UI to see our color system in action -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M-tsoTK_sPeafYJD9bk-tg.png" /><figcaption>NumericRow</figcaption></figure><p>Let’s just build the color values part for now and see if we are able to translate above information into the code.</p><p>In the code below, we have made a component called NumericRow( ) in which props - label, labels, values, onChange and onCopy are passed so that while building the UI, we can edit values accordingly.</p><pre><br>function NumericRow({ label, labels, values, onChange, onCopy }) {<br>  const [draft, setDraft] = useState(values.map(String))<br><br>  useEffect(() =&gt; setDraft(values.map(String)), [values.join(&#39;|&#39;)])<br><br>  return (<br>    &lt;&gt;<br>      &lt;div className={styles.columnLabels}&gt;<br>        {labels.map((item) =&gt; (<br>          &lt;span key={item}&gt;{item}&lt;/span&gt;<br>        ))}<br>      &lt;/div&gt;<br>      &lt;div className={styles.dataRow}&gt;<br>        &lt;div className={styles.dataInputs}&gt;<br>          {values.map((_, index) =&gt; (<br>            &lt;input<br>              key={`${label}-${index}`}<br>              aria-label={`${label} ${index + 1}`}<br>              value={draft[index]}<br>              inputMode=&quot;decimal&quot;<br>              onChange={(event) =&gt; {<br>                const next = [...draft]<br>                next[index] = event.target.value<br>                setDraft(next)<br>                if (<br>                  next.every(<br>                    (item) =&gt; item !== &#39;&#39; &amp;&amp; Number.isFinite(Number(item))<br>                  )<br>                ) {<br>                  onChange(next)<br>                }<br>              }}<br>              onBlur={() =&gt; {<br>                const next = draft.map((item, itemIndex) =&gt;<br>                  item === &#39;&#39; ? String(values[itemIndex]) : item<br>                )<br>                setDraft(next)<br>                onChange(next)<br>              }}<br>            /&gt;<br>          ))}<br>        &lt;/div&gt;<br>        &lt;button<br>          className={styles.copyButton}<br>          onClick={onCopy}<br>          aria-label={`Copy ${label} values`}<br>        &gt;<br>          &lt;CopyIcon size={15} /&gt;<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br>    &lt;/&gt;<br>  )<br>}<br><br></pre><p>If you copy paste the above code, you have infront of you a simplified component focused purely on displaying and editing the numerical color values, formats, and copy actions.</p><p>After all this, our UI looks like this -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*onSHHha-PRpY1u_sY76X6A.png" /></figure><h4>2. Building actual color square-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AX-LYqQFr56QKgCOXl0mpg.png" /></figure><p>Here is how the color square is built, the UI part of it -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6ruX-QFOglmI9EBeNlvtg.png" /></figure><p>The engineering behind it -</p><p>We need to figure out two things for our thumb to be moved around the color square and the color gets immediately updated. For that we need three things to happen -</p><p><strong>2.1 We need to know the position of Color square in the browser’s coordinate -</strong></p><p>To find the position of color square , we write a function called <strong>pointFromEvent(event, element)</strong>:</p><pre>export function pointFromEvent(event, element) {<br>  const rect = element.getBoundingClientRect()<br><br>  return {<br>    x: clamp((event.clientX - rect.left) / rect.width),<br>    y: clamp((event.clientY - rect.top) / rect.height)<br>  }<br>}</pre><p>Now we have the coordinates (x,y) of the color square.</p><p><strong>2.2. We need to convert that position into a color -</strong></p><p>The coordinates that we obtained, we need to convert them into s and v so that it complies with out internal source of truth — HSV and the other color values corresponding to it can change accordingly.</p><p>So we write a function called <strong>updateSquare </strong>which does two jobs -</p><ul><li>To figure out where inside the square are we clicking</li><li>Convert that position into HSV.</li></ul><pre>const updateSquare = (event) =&gt; {<br>  const point = pointFromEvent(event, squareRef.current)<br><br>  setColor(current =&gt; ({<br>    ...current,<br>    s: point.x,<br>    v: 1 - point.y<br>  }))<br>}</pre><p>For example -</p><p>If,</p><p>point = {x :0.6, y: 0.4}</p><p>Then,</p><pre>setColor(current =&gt; ({<br>  ...current,<br>  s: point.x,<br>  v: 1 - point.y<br>}))</pre><p>Upon substitution,</p><pre>setColor(current =&gt; ({<br>  ...current,<br>  s: 0.6,<br>  v: 1 - 0.4<br>}))</pre><p>Therefore,</p><pre>s: 0.6,<br>v: 0.6</pre><p><strong>2.3. We need to move the thumb to that position-</strong></p><p>Suppose our current color is:</p><p>h: 264, s: 0.6, v: 0.6</p><p>Where should the thumb go?</p><p>Since s is equivalent to x and v is equivalent to y, so :</p><p>left = 0.6</p><p>But CSS doesn’t understand it as 60% across. So, we convert it into percentage:</p><p>left = s * 100</p><p>Therefore, 0.6 x 100 = 60%</p><p>For vertical position:</p><p>top = (1 — v) * 100</p><p>i.e.</p><p>top = (1–0.6) * 100 = 40%</p><p>Instead of hardcoding values, we write it as a code:</p><pre>&lt;div<br>  className={styles.squareThumb}<br>  style={{<br>    left: `${color.s * 100}%`,<br>    top: `${(1 - color.v) * 100}%`,<br>  }}<br>/&gt;</pre><p>So if we write the UI for our color square:</p><pre>  &lt;div className={styles.colorControls}&gt;<br>          &lt;div ref={squareRef} className={styles.square} style={{ backgroundColor: `hsl(${color.h}, 100%, 50%)` }} <br>          onPointerDown={(event) =&gt; { squareRef.current.setPointerCapture(event.pointerId); updateSquare(event) }} <br>          onPointerMove={(event) =&gt; event.buttons === 1 &amp;&amp; updateSquare(event)} <br>          role=&quot;slider&quot; tabIndex=&quot;0&quot; aria-label=&quot;Saturation and brightness&quot;&gt;<br>            &lt;div className={styles.whiteGradient} /&gt;<br>            &lt;div className={styles.blackGradient} /&gt;<br>            &lt;span className={styles.squareThumb} <br>            style={{ left: `${color.s * 100}%`, top: `${(1 - color.v) * 100}%` }} /&gt;<br>          &lt;/div&gt;<br>         <br>        &lt;/div&gt;</pre><p>Now, our UI looks like -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ztgIifX5PBvO5-7hacwPEA.png" /></figure><h4>3. Adding the Hue slider -</h4><p>The square controls S and V. How do we control H?</p><p>Our hue is:</p><p>0° → 360°</p><p>Our slider position is:</p><p>0 → 1</p><p>Therefore:</p><p>H = position × 360</p><p>Our React code becomes:</p><pre>onChange={(value) =&gt; setColor((current) =&gt; ({ ...current, h: value * 360 })) }</pre><p>We can build a reusable slider component which we can also reuse it for opacity. The component doesn’t need to know that it’s controlling hue.</p><p>It only knows:</p><p>I have a value between 0 and 1.<br>The user clicked somewhere.<br>I&#39;ll convert the click into another value between 0 and 1.</p><pre>function VerticalSlider({ label, value, gradient, onChange, invert = true, bg }) {<br>  const ref = useRef(null)<br>  const update = (event) =&gt; {<br>    const point = pointFromEvent(event, ref.current)<br>    onChange(invert ? 1 - point.y : point.y)<br>  }<br>  return &lt;div className={styles.verticalSliderWrap}&gt;<br>    &lt;div ref={ref} className={styles.verticalSlider} style={{ background: gradient }} role=&quot;slider&quot; aria-label={label} aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot; aria-valuenow={Math.round(value * 100)} tabIndex=&quot;0&quot; onPointerDown={(event) =&gt; { ref.current.setPointerCapture(event.pointerId); update(event) }} onPointerMove={(event) =&gt; event.buttons === 1 &amp;&amp; update(event)} onKeyDown={(event) =&gt; { const step = event.shiftKey ? 0.1 : 0.01; if (event.key === &#39;ArrowUp&#39;) onChange(clampValue(value - step, 0, 1)); if (event.key === &#39;ArrowDown&#39;) onChange(clampValue(value + step, 0, 1)); if (event.key === &#39;Home&#39;) onChange(0); if (event.key === &#39;End&#39;) onChange(1) }}&gt;<br>      {bg}<br>      &lt;span className={styles.verticalThumb} style={{ top: `${(invert ? 1 - value : value) * 100}%` }} /&gt;<br>      <br>      <br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>}</pre><p>When using this component for Hue:</p><pre>&lt;VerticalSlider label=&quot;Hue&quot; value={color.h / 360} onChange={(value) =&gt; setColor((current) =&gt; ({ ...current, h: value * 360 }))} <br>            gradient=&quot;linear-gradient(180deg, #ff0000 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)&quot; /&gt;</pre><p>Now, our UI looks like -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q0jMrYPxXqzp6sousjv5WQ.png" /></figure><h4>4. Adding the opacity slider -</h4><p>Our internal alpha range is:</p><p>0 → 1</p><p>The slider is also:</p><p>0 → 1</p><p>So:</p><p>A = normalizedPosition</p><p>No conversion is necessary.</p><p>Our slider can therefore call:</p><pre>onChange={(a) =&gt; setColor((current) =&gt; ({ ...current, a })) }</pre><p>Using the vertical slider component created earlier :</p><pre>&lt;VerticalSlider label=&quot;Opacity&quot; value={color.a} onChange={(a) =&gt; setColor((current) =&gt; ({ ...current, a }))} <br>            gradient={`linear-gradient(180deg, ${data.hex} 0%, transparent 100%) `} bg = {&lt;div className ={styles.checkeredbg}/&gt;} /&gt;</pre><pre><br><br>.checkeredbg{<br>   opacity: 0.5;<br>    position: absolute;<br>    inset: 0;<br>    background:<br>    conic-gradient(<br>        #d9d9d9 25%,<br>        white 0 50%,<br>        #d9d9d9 0 75%,<br>        white 0<br>      );<br>  ;<br>  background-size: 10px 10px;<br>  mix-blend-mode:overlay;<br><br><br>}<br><br>//checkeredbg will give us the checkered pattern which we see in the opacity slider//</pre><p>Now, our UI looks like -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xm5mEEXnd0oR8gWw87Dujw.png" /></figure><h4>5. Scrubbing-</h4><p>Paper allows you to drag labels horizontally to increase/decrease the number.</p><p>If we want to implement this, first we have to solve a mathematical problem:</p><blockquote>How much should a value change when the mouse moves?</blockquote><p>Let’s say we take 160px if mouse movement equal to entire numerical range. We can take any other number too, the number will define the speed of movement.</p><p>So, 160px of mouse movement = entire numerical range</p><p>So for RGB,</p><p>range = 0 → 255</p><p>Therefore:</p><p>1px ≈ 255 / 160</p><p>which gives:</p><p>1px ≈ 1.59</p><p>So the general equations become:</p><pre>valueChange =<br>mouseDelta × (rangeMax - rangeMin) / 160<br><br>newValue =<br>startValue + valueChange<br><br>newValue =<br>startValue<br>+<br>mouseDelta × range / 160<br><br>const delta = event.clientX - startX<br><br>const nextValue =<br>  startValue +<br>  delta * (range[1] - range[0]) / 160</pre><p>We need to modify our NumericRow function mentioned above in Color values part. The modification we want to do is add “ranges” as a prop in the function so that for each color value, we can define the range so that the scrubbing updates the color value accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*izHTwgUtVYIkfhoOXecfLA.png" /><figcaption>NumericRow — Modified (with ranges prop)</figcaption></figure><p>Updating our already defined NumericRow function for scrubbing action -</p><pre>function NumericRow({ label, labels, values, onChange, onCopy, ranges }) {<br>  const scrubRef = useRef(null)<br>  const [draft, setDraft] = useState(values.map(String))<br>  const scrub = (index, event) =&gt; {<br>    if (!scrubRef.current) return<br>    const { startX, startValue } = scrubRef.current<br>    const range = ranges[index]<br>    const delta = event.clientX - startX<br>    const nextValue = clampValue(startValue + delta * (range[1] - range[0]) / 160, range[0], range[1])<br>    const next = values.map((value, valueIndex) =&gt; valueIndex === index ? nextValue : value)<br>    setDraft(next.map((value) =&gt; String(Math.round(value))))<br>    onChange(next)<br><br>  useEffect(() =&gt; setDraft(values.map(String)), [values.join(&#39;|&#39;)])<br>  return (<br>    &lt;&gt;<br>      &lt;div className={styles.columnLabels}&gt;<br>        {labels.map((item, index) =&gt; &lt;span key={item} onPointerDown={(event) =&gt; beginScrub(index, event)} onPointerMove={(event) =&gt; scrub(index, event)} onPointerUp={endScrub} onPointerCancel={endScrub}&gt;{item}&lt;/span&gt;)}<br>      &lt;/div&gt;<br>      &lt;div className={styles.dataRow}&gt;<br>      &lt;div className={styles.dataInputs}&gt;<br>        {values.map((value, index) =&gt; &lt;input key={`${label}-${index}`} aria-label={`${label} ${index + 1}`} value={draft[index]} inputMode=&quot;decimal&quot; onChange={(event) =&gt; { const next = [...draft]; next[index] = event.target.value; setDraft(next); if (next.every((item) =&gt; item !== &#39;&#39; &amp;&amp; Number.isFinite(Number(item)))) onChange(next) }} onBlur={() =&gt; { const next = draft.map((item, itemIndex) =&gt; item === &#39;&#39; ? String(values[itemIndex]) : item); setDraft(next); onChange(next) }} /&gt;)}<br>      &lt;/div&gt;<br>        &lt;button className={styles.copyButton} onClick={onCopy} aria-label={`Copy ${label} values`}&gt;&lt;Copy size={15} /&gt;&lt;/button&gt;<br>      &lt;/div&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><p>Pointer events:</p><p>Beginning the drag (onPointerDown, onPointerMove) -</p><pre>}<br>  const beginScrub = (index, event) =&gt; {<br>    event.preventDefault()<br>    event.currentTarget.setPointerCapture(event.pointerId)<br>    scrubRef.current = { index, startX: event.clientX, startValue: Number(values[index]) }<br>  }<br></pre><p>Ending the drag (onPointerUp, onPointerCancel) -</p><pre>const endScrub = (event) =&gt; {<br>    if (event.currentTarget.hasPointerCapture?.(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId)<br>    scrubRef.current = null<br>  }</pre><p>So now we have a complete working color picker component that looks like this -</p><p>Github — <a href="https://github.com/kshitizengg/custom-color-picker">https://github.com/kshitizengg/custom-color-picker</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jq6U25AU6AGMH7KlZxLEjw.png" /></figure><blockquote>Enjoyed this deep dive? I love dissecting and building production-grade interfaces. If you need a <strong>UI</strong> <strong>Designer/Design Engineer</strong> to bring complex UIs or interactive design tools to life, send me a DM on <a href="https://x.com/kshtz_chndr">Twitter/X (@ksht</a>z_chndr<a href="https://x.com/kshtz_chndr">)!</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4714b7b31666" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Funky text hover effect by Jhey Tompkins]]></title>
            <link>https://medium.com/@kshitiz.chndra/funky-text-hover-effect-by-jhey-tompkins-1cbf5cfcbd3e?source=rss-a72ef1ab81cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cbf5cfcbd3e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Kshitiz Chandra]]></dc:creator>
            <pubDate>Fri, 11 Sep 2026 18:03:56 GMT</pubDate>
            <atom:updated>2026-09-11T18:06:47.164Z</atom:updated>
            <content:encoded><![CDATA[<p>I came across this funky text-hover effect <a href="https://x.com/jh3yy">Jhey </a>created with some clever CSS tricks. I liked it enough to recreate it myself, and along the way, I decided to break down how the whole thing works and how we can build it in React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrrtKm-6y73bhsz0cQHWLQ.png" /></figure><p>The first two lines are regular text inside &lt;span&gt; elements. For the next two lines, we want the characters to jitter on hover, so instead of writing the effect from scratch each time, we turn it into a reusable component.</p><p>Let’s call it Funkification. The component accepts the text and link as props, along with a few controls for customizing the effect: whether to show an icon, how much each character can rotate and move, and how quickly the animation runs. So, now we can use this component and customize it with our inputs without writing everything again and again.</p><pre>&lt;Funkification<br>  text=&quot;Some text&quot;<br>  href=&quot;#&quot;<br>  showIcon={true}<br>  config={{<br>    angle: 5,<br>    offset: 2,<br>    speed: 0.2<br>  }}<br>/&gt;</pre><p>This gives us one reusable component that can produce different variations of the same jitter effect without duplicating the underlying logic.</p><p>Let’s write this component from scratch.</p><pre>const Funkification = ({ text, href, showIcon, config }) =&gt; {<br>  const { angle, offset, speed } = config;<br><br>  <br>  const characters = useMemo(() =&gt; {<br>    return text.split(&#39;&#39;).map((char) =&gt; ({<br>      char: char === &#39; &#39; ? &#39;\u00A0&#39; : char,<br>      style: {<br>        &#39;--r&#39;: Math.floor(Math.random() * (angle * 2 + 1)) - angle,<br>        &#39;--x&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>        &#39;--y&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>      },<br>    }));<br>  }, [text, angle, offset]);<br><br>  <br>  const iconStyle = useMemo(() =&gt; {<br>    return {<br>      &#39;--r&#39;: Math.floor(Math.random() * (angle * 2 + 1)) - angle,<br>      &#39;--x&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>      &#39;--y&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>    };<br>  }, [angle, offset]);<br><br>  return (<br>    &lt;a<br>      href={href}<br>      target=&quot;_blank&quot;<br>      rel=&quot;noopener noreferrer&quot;<br>      className=&quot;jitter-link&quot;<br>      style={{ &#39;--speed&#39;: `${speed}s` }}<br>    &gt;<br>      &lt;span aria-hidden=&quot;true&quot; className=&quot;jitter-content&quot;&gt;<br>        {showIcon &amp;&amp; (<br>          &lt;span className=&quot;char icon&quot; style={iconStyle}&gt;<br>            &lt;LinkIcon /&gt;<br>          &lt;/span&gt;<br>        )}<br>        {characters.map((item, index) =&gt; (<br>          &lt;span key={index} className=&quot;char&quot; style={item.style}&gt;<br>            {item.char}<br>          &lt;/span&gt;<br>        ))}<br>      &lt;/span&gt;<br>      &lt;span className=&quot;sr-only&quot;&gt;{text}&lt;/span&gt;<br>    &lt;/a&gt;<br>  );<br>};</pre><p>Breaking it down -</p><h4>1. Give every character its own random movement</h4><p>The interesting part of the effect is that the characters shouldn’t all move in exactly the same way. Each character needs its own random rotation and X/Y offset.</p><pre>const characters = useMemo(() =&gt; {<br>  return text.split(&#39;&#39;).map((char) =&gt; ({<br>    char: char === &#39; &#39; ? &#39;\u00A0&#39; : char,<br>    style: {<br>      &#39;--r&#39;: Math.floor(Math.random() * (angle * 2 + 1)) - angle,<br>      &#39;--x&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>      &#39;--y&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>    },<br>  }));<br>}, [text, angle, offset]);</pre><p>First, text.split(&#39;&#39;) turns the string into an array of individual characters. We then map over those characters and assign each one three random CSS variables:</p><ul><li>--r controls rotation.</li><li>--x controls horizontal movement.</li><li>--y controls vertical movement.</li></ul><p>The random values are generated within the limits defined by angle and offset. So increasing angle makes the characters rotate more, while increasing offset allows them to move farther.</p><p>We use useMemo so these random values are generated again only when text, angle, or offset changes. Otherwise, every render could produce a completely different set of offsets, making the effect unstable.</p><h4>2. Do the same for the icon</h4><p>The icon is treated separately because it isn’t part of the character array. We generate its random rotation and position using the same angle and offset controls:</p><pre>const iconStyle = useMemo(() =&gt; {<br>  return {<br>    &#39;--r&#39;: Math.floor(Math.random() * (angle * 2 + 1)) - angle,<br>    &#39;--x&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>    &#39;--y&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>  };<br>}, [angle, offset]);</pre><p>This keeps the icon’s behavior consistent with the letters while still allowing us to render it independently.</p><h4>3. Render the link</h4><p>Finally, we put everything inside an &lt;a&gt; element:</p><pre>&lt;a<br>  href={href}<br>  target=&quot;_blank&quot;<br>  rel=&quot;noopener noreferrer&quot;<br>  className=&quot;jitter-link&quot;<br>  style={{ &#39;--speed&#39;: `${speed}s` }}<br>&gt;</pre><p>The href makes the component a reusable link, while --speed passes the animation speed to CSS as a custom property.</p><p>Inside the link, we render the optional icon followed by each character:</p><pre>{showIcon &amp;&amp; (<br>  &lt;span className=&quot;char icon&quot; style={iconStyle}&gt;<br>    &lt;LinkIcon /&gt;<br>  &lt;/span&gt;<br>)}</pre><pre>{characters.map((item, index) =&gt; (<br>  &lt;span key={index} className=&quot;char&quot; style={item.style}&gt;<br>    {item.char}<br>  &lt;/span&gt;<br>))}</pre><p>Each character receives its own --r, -- x, and --y values. The CSS can then use those variables when the link is hovered, creating the jitter without JavaScript having to animate every character.</p><p>Finally, we include a visually hidden version of the original text:</p><pre>&lt;span className=&quot;sr-only&quot;&gt;{text}&lt;/span&gt;</pre><p>This gives screen readers the complete text as normal content while the individually wrapped characters can remain aria-hidden.</p><h4>4. The trick to turn the jitter on</h4><p>Now that we have split the text into individual .char elements and given each character its own random x, y and rotation values, we need a way to control when those values are actually applied.</p><p>If you notice we have introduced a multiplication factor (MF) which we are multiplying with the transformation properties. So when MF is 0,</p><p>x × 0 = 0</p><p>y × 0 = 0</p><p>rotation × 0 = 0</p><p>So the characters remain in their normal positions.</p><pre> .char {<br>    display: inline-block;<br>    transition: transform var(--speed, 0.25s) cubic-bezier(0.5, 1.25, 0.75, 1.25);<br>    transform: <br>      rotate(calc((var(--MF, 0) * var(--r, 0)) * 1deg))<br>      translate(<br>        calc((var(--MF, 0) * var(--x, 0)) * 1%),<br>        calc((var(--MF, 0) * var(--y, 0)) * 1%)<br>      );<br>  }</pre><p>When MF becomes 1 when hovered, those same pre-generated random values are applied:</p><p>x × 1 = x</p><p>y × 1 = y</p><p>rotation × 1 = rotation</p><pre>.jitter-link {<br>  --MF: 0;<br>  color: inherit;<br>  text-decoration: none;<br>  outline: none;<br>}<br><br>.jitter-link:is(:hover, :focus-visible) {<br>  --MF: 1;<br>}</pre><h4>5. Controlling the jitter</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NX6HPDEOr3SUnNjy93i_Q.png" /></figure><p>Now that the jitter effect is working, we can make it interactive by adding range inputs that let us control the angle, offset, and speed.</p><p>First, we define the initial values using React state:</p><pre>  const[angle, setAngle] = useState(15);<br>  const[offset, setOffset] = useState(25);<br>  const[speed, setSpeed] = useState(0.25);<br><br>  const config = {angle, offset, speed }</pre><p>Writing the UI</p><pre>&lt;div className=&#39;controlpanel&#39;&gt;<br>      &lt;div className=&#39;controlgroup&#39;&gt;<br>        &lt;label&gt;Max Angle ({angle}°)&lt;/label&gt;<br>        &lt;input<br>        type = &quot;range&quot;<br>        min = &quot;0&quot;<br>        max = &quot;45&quot;<br>        value = {angle}<br>        onChange={(e) =&gt; setAngle(Number(e.target.value))}<br>        /&gt;<br>      &lt;/div&gt;<br><br>      &lt;div className=&#39;controlgroup&#39;&gt;<br>        &lt;label&gt;Max Offset ({offset})&lt;/label&gt;<br>        &lt;input<br>        type = &quot;range&quot;<br>        min = &quot;0&quot;<br>        max = &quot;100&quot;<br>        value = {offset}<br>        onChange={(e) =&gt; setOffset(Number(e.target.value))}<br>        /&gt;<br>      &lt;/div&gt;<br><br>      &lt;div className=&#39;controlgroup&#39;&gt;<br>        &lt;label&gt;Max speed ({speed})&lt;/label&gt;<br>        &lt;input<br>        type = &quot;range&quot;<br>        min = &quot;0.05&quot;<br>        step=&quot;0.1&quot;<br>        max = &quot;1&quot;<br>        value = {speed}<br>        onChange={(e) =&gt; setSpeed(Number(e.target.value))}<br>        /&gt;<br>      &lt;/div&gt;<br>      <br>    &lt;/div&gt;</pre><p>Here is the complete code, all in one place, so you can copy it, experiment with the values, and make the effect your own.</p><p>JSX</p><pre>import React, { useMemo, useState } from &#39;react&#39;;<br>import &#39;./funky.css&#39;;<br><br>const LinkIcon = () =&gt; (<br>  &lt;svg<br>    xmlns=&quot;http://www.w3.org/2000/svg&quot;<br>    fill=&quot;none&quot;<br>    viewBox=&quot;0 0 24 24&quot;<br>    strokeWidth=&quot;1.5&quot;<br>    stroke=&quot;currentColor&quot;<br>    aria-hidden=&quot;true&quot;<br>  &gt;<br>    &lt;path<br>      strokeLinecap=&quot;round&quot;<br>      strokeLinejoin=&quot;round&quot;<br>      d=&quot;M13.19 8.688a4.5 4.5 0 011.242 7.244l-4.5 4.5a4.5 4.5 0 01-6.364-6.364l1.757-1.757m13.35-.622l1.757-1.757a4.5 4.5 0 00-6.364-6.364l-4.5 4.5a4.5 4.5 0 001.242 7.244&quot;<br>    /&gt;<br>  &lt;/svg&gt;<br>);<br><br>const Funkification = ({ <br>  text, <br>  href ,<br>  showIcon ,<br>  config<br>}) =&gt; {<br><br>  const { angle, offset, speed } = config;<br><br>  const characters = useMemo(() =&gt; {<br>    return text.split(&#39;&#39;).map((char) =&gt; ({<br>      char: char === &#39;&#39; ? &#39;\u00A0&#39; : char,<br>      style: {<br>        &#39;--r&#39;: Math.floor(Math.random() * (angle * 2 + 1)) - angle,<br>        &#39;--x&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>        &#39;--y&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>      },<br>    }));<br>    <br>  }, [text, angle, offset]);<br><br>  const iconStyle = useMemo(() =&gt; {<br>    return {<br>      &#39;--r&#39;: Math.floor(Math.random() * (angle * 2 + 1)) - angle,<br>      &#39;--x&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>      &#39;--y&#39;: Math.floor(Math.random() * (offset * 2 + 1)) - offset,<br>    };<br>  }, [angle, offset]);<br><br>  <br><br>  <br><br>  return (<br>    &lt;a <br>      href={href} <br>      className=&quot;jitter-link&quot; <br>      style={{ &#39;--speed&#39;: `${speed}s` }}<br>    &gt;<br><br>      &lt;span aria-hidden = &quot;true&quot; className=&#39;jitter-content&#39;&gt;<br>        {showIcon &amp;&amp; (<br>          &lt;span className=&#39;char-icon&#39; style = {iconStyle}&gt;<br>            &lt;LinkIcon/&gt;<br>            &lt;/span&gt;<br>        )}<br><br>      <br>        <br>        {characters.map((item, index) =&gt; (<br>          &lt;span key={index} className=&quot;char&quot; style={item.style}&gt;<br>            {item.char}<br>          &lt;/span&gt;<br>        ))}<br><br>      &lt;/span&gt;<br><br>      {/* Screen reader fallback */}<br>      &lt;span className=&quot;sr-only&quot;&gt;{text}&lt;/span&gt;<br>    &lt;/a&gt;<br>  );<br>};<br><br>export default function FunkyText() {<br><br>  const[angle, setAngle] = useState(15);<br>  const[offset, setOffset] = useState(25);<br>  const[speed, setSpeed] = useState(0.25);<br><br>  const config = {angle, offset, speed }<br><br>  return (<br>    &lt;div className=&quot;jitter_container&quot;&gt;<br><br>    &lt;div className=&#39;controlpanel&#39;&gt;<br>      &lt;div className=&#39;controlgroup&#39;&gt;<br>        &lt;label&gt;Max Angle ({angle}°)&lt;/label&gt;<br>        &lt;input<br>        type = &quot;range&quot;<br>        min = &quot;0&quot;<br>        max = &quot;45&quot;<br>        value = {angle}<br>        onChange={(e) =&gt; setAngle(Number(e.target.value))}<br>        /&gt;<br>      &lt;/div&gt;<br><br>      &lt;div className=&#39;controlgroup&#39;&gt;<br>        &lt;label&gt;Max Offset ({offset})&lt;/label&gt;<br>        &lt;input<br>        type = &quot;range&quot;<br>        min = &quot;0&quot;<br>        max = &quot;100&quot;<br>        value = {offset}<br>        onChange={(e) =&gt; setOffset(Number(e.target.value))}<br>        /&gt;<br>      &lt;/div&gt;<br><br>      &lt;div className=&#39;controlgroup&#39;&gt;<br>        &lt;label&gt;Max speed ({speed})&lt;/label&gt;<br>        &lt;input<br>        type = &quot;range&quot;<br>        min = &quot;0.05&quot;<br>        step=&quot;0.1&quot;<br>        max = &quot;1&quot;<br>        value = {speed}<br>        onChange={(e) =&gt; setSpeed(Number(e.target.value))}<br>        /&gt;<br>      &lt;/div&gt;<br>      <br>    &lt;/div&gt;<br><br>      &lt;div className=&quot;info_line&quot;&gt;<br>        &lt;span&gt;JHEY TOMPKINS&lt;/span&gt;<br>      &lt;/div&gt;<br><br>      &lt;div className=&quot;info_line&quot;&gt;<br>        &lt;span&gt;CREATOR AND CODE WRANGLER&lt;/span&gt;<br>      &lt;/div&gt;<br><br><br>      &lt;div className=&quot;info_line&quot;&gt;<br>        &lt;Funkification<br>        text= &quot;+44 7385 959 782&quot;<br>        showIcon={false}<br>        config={config}<br>        /&gt;<br>      &lt;/div&gt;<br><br>      &lt;div className=&quot;info_line&quot; style={{display:&quot;flex&quot;, gap:&quot;2rem&quot;}}&gt;<br>        &lt;Funkification<br>          text=&quot;TWEET&quot;<br>          config={config}<br>          showIcon={true}<br>          <br>        /&gt;<br><br>        &lt;Funkification<br>        text=&quot;WEBSITE&quot;<br>        showIcon={true}<br>        config={config}<br>        /&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>CSS</p><pre>.info_line{<br>    font-size: clamp(2rem, 5vw, 3.5rem);<br>    color:#dddce6;<br>    font-weight: 700;<br>    line-height: 1.1;<br>}<br><br>#root{<br>    display: flex;<br>    align-items: center;<br>    justify-content: center;<br>    background-color: #161414;<br>}<br><br>.jitter_container{<br>    display: flex;<br>    flex-direction: column;<br>    justify-content: center;<br>    align-items: center;<br>    gap: 16px;<br>}<br><br>/* Clips the screen-reader text so it&#39;s invisible visually, but readable by screen readers */<br>.sr-only {<br>    position: absolute;<br>    width: 1px;<br>    height: 1px;<br>    padding: 0;<br>    margin: -1px;<br>    overflow: hidden;<br>    clip: rect(0, 0, 0, 0);<br>    white-space: nowrap;<br>    border-width: 0;<br>  }<br><br>  .char {<br>    display: inline-block;<br>    transition: transform var(--speed, 0.25s) cubic-bezier(0.5, 1.25, 0.75, 1.25);<br>    transform: <br>      rotate(calc((var(--active, 0) * var(--r, 0)) * 1deg))<br>      translate(<br>        calc((var(--active, 0) * var(--x, 0)) * 1%),<br>        calc((var(--active, 0) * var(--y, 0)) * 1%)<br>      );<br>  }<br><br>  .jitter-link {<br>    --active: 0;<br>    color: inherit;<br>    text-decoration: none;<br>    outline: none;<br>  }<br><br>  .jitter-link:is(:hover, :focus-visible) {<br>    --active: 1;<br>  }<br><br>  /* .jitter-link:focus-visible {<br>    outline: 2px dashed hsl(10 100% 50%);<br>    outline-offset: 4px;<br>  } */<br><br>  .jitter_container:has(a:is(:hover, :focus-visible)) :is(span, a):not(:hover, :focus-visible) {<br>    --opacity: 0.1;<br>  }<br><br>  .info_line &gt; :is(span, a) {<br>    opacity: var(--opacity, 1);<br>    transition: opacity 0.2s ease;<br>  }<br><br>  .jitter-content {<br>    display: inline-flex;<br>    align-items: center;<br>    gap: 0.5rem;<br>  }<br><br>  .char-icon {<br>    width: 0.8em;<br>    height: 0.8em;<br>    display: block;<br>  }<br><br>  .controlpanel {<br>    background: #1e1e1e;<br>    border: 1px solid #333;<br>    border-radius: 12px;<br>    padding: 1.5rem;<br>    display: flex;<br>    flex-wrap: wrap;<br>    gap: 1.5rem;<br>    width: 100%;<br>    max-width: 600px;<br>    box-shadow: 0 10px 30px rgba(0,0,0,0.5);<br>  }<br><br>  .controlgroup {<br>    display: flex;<br>    flex-direction: column;<br>    gap: 0.5rem;<br>    flex: 1;<br>    min-width: 150px;<br>  }<br><br>  .controlgroup label {<br>    font-size: 0.85rem;<br>    text-transform: uppercase;<br>    letter-spacing: 1px;<br>    color: #aaa;<br>  }<br><br>  .controlgroup input {<br>    accent-color: hsl(10 100% 50%);<br>    cursor: pointer;<br>  }</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cbf5cfcbd3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>