{
  "post": {
    "title": "Behind the Scenes: Buttons",
    "shortTitle": "Behind the Scenes: Buttons",
    "status": 200,
    "description": "A blog post explaining how I did most of the ui on this website",
    "linkSlug": "bts/button",
    "guid": "7ff00adf-5c3a-4465-b3e0-650f39502b72",
    "firstCreated": "2026-09-20T00:00:00.000Z",
    "lastModified": "2026-11-03T16:00:00.000Z",
    "permalinkSlug": "buttons",
    "showInFeed": true,
    "content": [
      {
        "type": "Markdown",
        "value": [
          "# Buttons",
          "### My least favourite way to center a div"
        ],
        "alt": "page introduction",
        "extraStyle": {
          "minHeight": "7.5rem"
        }
      },
      {
        "type": "Markdown",
        "value": [
          "## The Challenge",
          "here is the code for *rainbow mode*",
          "~~~css",
          ".rainbow {",
          "  background: linear-gradient(in hsl longer hue 90deg, red 0 100%);",
          "  background-size: 200% auto;",
          "  background-clip: text;",
          "  animation: rainbow 10s linear infinite;",
          "  color: transparent;",
          "}",
          "~~~",
          "",
          "",
          "the important line here is the `background-clip: text` what we do is draw the entire screen as a rainbow and then clip everything but the text.",
          "",
          "Then we make the text transparent and all we are left with is the rainbow effect behind it. This however limits everything to being exclusively text",
          "",
          ""
        ],
        "alt": "explaining the challenge with setting up buttons as ui elements ",
        "extraStyle": {
          "minHeight": "25rem"
        }
      },
      {
        "type": "Markdown",
        "value": [
          "## The UI",
          "",
          "My first attempt to make buttons was just to use ascii boxes to draw around them which works but people expect that buttons change when hovered over and so it was confusing when they stayed the same.",
          "",
          "The first thing I tried was changing which boxes I used (there are a plethora), but at the small scale it was hard to notice the difference, that's when I decided to have them change size as well. ",
          "To do this I intentionally left a bunch of space around the default button which would be filled out by the full button.",
          "",
          "~~~typescript",
          "  const button = () => {",
          "    const buttonRows = [",
          "//two rows here are nothing but space",
          "      `   ${gap}   `,",
          "      ` ╭─${line}─╮ `,",
          "      ` │ ${text} │ `,",
          "      ` ╰─${line}─╯ `,",
          "      `   ${gap}   `,",
          "//aditionally there is one space at the beginning and end of each string",
          "    ];",
          "    return buttonRows.join(\"\\n\");",
          "  };",
          "",
          "  const hoverButton = () => {",
          "    const buttonRows = [",
          "      `╔──${line}──╗`,",
          "      `│  ${gap}  │`,",
          "      `│  ${text}  │`,",
          "      `│  ${gap}  │`,",
          "      `╚──${line}──╝`,",
          "    ];",
          "    return buttonRows.join(\"\\n\");",
          "  };",
          "",
          "~~~",
          "",
          "then it was as simple as hooking them up to the state and it works",
          "",
          "Ideally they would work just via css but for now it's in JS. You have to pick your battles."
        ],
        "extraStyle": {
          "minHeight": "60rem"
        },
        "alt": "explaining the challenge with setting up buttons as ui elements "
      },
      {
        "type": "Markdown",
        "value": [
          "### Changing buttons",
          "",
          "Go ahead and press these buttons for a bit and see how they change text when you do"
        ],
        "extraStyle": {
          "minHeight": "5rem"
        },
        "alt": "explaining how I got the buttons to change their labels"
      },
      {
        "type": "ModeButtons",
        "value": {
          "Dark Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=dark",
            "MIMEtype": "text/html"
          },
          "Light Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=light",
            "MIMEtype": "text/html"
          },
          "Rainbow Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=rainbow",
            "MIMEtype": "text/html"
          },
          "Terminal Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=terminal",
            "MIMEtype": "text/html"
          },
          "Markdown": {
            "url": "https://lucas-leprince.com/bts/button.md",
            "MIMEtype": "text/markdown"
          },
          "JWT": {
            "url": "https://lucas-leprince.com/api/bts/button/token",
            "MIMEtype": "application/jwt"
          },
          "Database": {
            "url": "https://lucas-leprince.com/database.json",
            "MIMEtype": "json"
          }
        }
      },
      {
        "type": "Markdown",
        "value": [
          "the problem I was facing was that as the label  were changing the width of the buttons.\nI'm sure you're clever and realized that and are currently yelling at the screen saying just have a set width which I did do but that ended up making the buttons padded weirdly"
        ],
        "alt": "explaining how I got the buttons to change their labels",
        "extraStyle": {
          "minHeight": "4rem"
        }
      },
      {
        "type": "ModeButtons",
        "value": {
          "Dark Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=dark",
            "MIMEtype": "text/html"
          },
          "Light Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=light",
            "MIMEtype": "text/html"
          },
          "Rainbow Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=rainbow",
            "MIMEtype": "text/html"
          },
          "Terminal Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=terminal",
            "MIMEtype": "text/html"
          },
          "Markdown": {
            "url": "https://lucas-leprince.com/bts/button.md",
            "MIMEtype": "text/markdown"
          },
          "JWT": {
            "url": "https://lucas-leprince.com/api/bts/button/token",
            "MIMEtype": "application/jwt"
          },
          "Database": {
            "url": "https://lucas-leprince.com/database.json",
            "MIMEtype": "json"
          }
        }
      },
      {
        "type": "Markdown",
        "value": [
          "After all that I arrived at this final iteration"
        ],
        "alt": "leading into the conclusion",
        "extraStyle": {
          "minHeight": "2.5rem"
        }
      },
      {
        "type": "ModeButtons",
        "value": {
          "Dark Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=dark",
            "MIMEtype": "text/html"
          },
          "Light Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=light",
            "MIMEtype": "text/html"
          },
          "Rainbow Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=rainbow",
            "MIMEtype": "text/html"
          },
          "Terminal Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=terminal",
            "MIMEtype": "text/html"
          },
          "Markdown": {
            "url": "https://lucas-leprince.com/bts/button.md",
            "MIMEtype": "text/markdown"
          },
          "JWT": {
            "url": "https://lucas-leprince.com/api/bts/button/token",
            "MIMEtype": "application/jwt"
          },
          "Database": {
            "url": "https://lucas-leprince.com/database.json",
            "MIMEtype": "json"
          }
        }
      },
      {
        "type": "Markdown",
        "value": [
          "### the horrors",
          "Now is time to show you the code that I think is very gross but is (to my understanding) the best solution here",
          "~~~html",
          " <div",
          "   style={{",
          "     position: \"relative\",",
          "     left: \"50%\",",
          "     top: \"50%\",",
          "     width: \"0\",",
          "     height: \"0\",",
          "     display: \"flex\",",
          "     justifyContent: \"center\",",
          "     alignItems: \"center\",",
          "   }}",
          " >",
          "   <pre",
          "     style={{",
          "       position: \"relative\",",
          "       right: \"50%\",",
          "       bottom: \"50%\",",
          "       width: \"fit-content\",",
          "     }}",
          "   >",
          "     {text}",
          "   </pre>",
          " </div>",
          " {hover ? <pre>{hoverButton()}</pre> : <pre>{button()}</pre>}",
          "~~~",
          "This code will forever haunt my nightmares and I will do my best to explain why."
        ],
        "alt": "explaining how I got the buttons to change their labels",
        "extraStyle": {
          "minHeight": "5rem"
        }
      },
      {
        "type": "asciiArt",
        "value": {
          "name": "buttonBoxDrawing",
          "mdFallback": "boxDrawing",
          "ariaRole": "img",
          "style": {
            "height": "28rem"
          },
          "artOptions": [
            {
              "class": "",
              "art": [
                "you might be tempted to do something like this",
                "   ┌───────────  box 1  ─────────────┐",
                "   │  ┌───────── box 2 ───────────┐  │",
                "   │  │                           │  │",
                "   │  │                           │  │",
                "   │  │                           │  │",
                "   │  │                           │  │",
                "   │  │                           │  │",
                "   │  └───────────────────────────┘  │",
                "   └─────────────────────────────────┘",
                " ",
                "  however this is what the current code does",
                "   ┌───────────  box 1  ─────────────┐",
                "   │  ┌───────── box 3 ───────────┐  │",
                "   │  │                           │  │",
                "   │  │                           │  │",
                "   │  │          box 2            │  │",
                "   │  │                           │  │",
                "   │  │                           │  │",
                "   │  └───────────────────────────┘  │",
                "   └─────────────────────────────────┘",
                "     where box 2 is 0px by 0px in size"
              ]
            }
          ]
        },
        "alt": "a series of box arts showing how the buttons are actually composed of three boxes with the middle one being 0px by 0px"
      },
      {
        "type": "Markdown",
        "value": [
          "Unfortunately that's where I was stuck for the longest time",
          "#### Other things I tried",
          "* `position:absolute` - the problem is that this breaks the `background-clip:text` of *rainbow mode* which is the whole reason we are in this mess in the first place",
          "* 'display:flex' - this would solve the problem except that once again either the button or the text have to be position absolute",
          "Ultimately the conclusion I came to is that we need to use `position:relative` ",
          "and the only real way to have  `position:relative` not cause weird spacing issues is by  having it take up no space at all"
        ],
        "alt": "explaining other things I had tried",
        "extraStyle": {
          "minHeight": "15rem"
        }
      },
      {
        "type": "Markdown",
        "value": [
          "### Redemption",
          "A week after I threw in the towel I discovered [this site](https://www.joshwcomeau.com/css/center-a-div/#centering-a-stack-of-elements-8) talking about how to center a div. At the time I was showing someone the depths of CSS but then I saw something",
          "but then I saw that you can actually stack elements into the same grid box and realized this was the nice clean solution I was looking for",
          "~~~html",
          "<div",
          " style={{",
          "    display: \"grid\",",
          "    placeContent: \"center\",",
          "    placeItems: \"center\",",
          "  }}",
          ">",
          "  <div",
          "    style={{",
          "      gridRow: \"1\",",
          "      gridColumn: \"1\",",
          "    }}",
          "  >",
          "    <pre>{text}</pre>",
          "  </div>",
          "  {hover ? (",
          "    <pre",
          "      style={{",
          "        gridRow: \"1\",",
          "        gridColumn: \"1\",",
          "      }}",
          "    >",
          "      {hoverButton()}",
          "    </pre>",
          "  ) : (",
          "    <pre",
          "      style={{",
          "        gridRow: \"1\",",
          "        gridColumn: \"1\",",
          "      }}",
          "    >",
          "      {button()}",
          "    </pre>",
          "</div>",
          "~~~",
          "and while yes it is certainly more code than before it is more accurate to what I want which is 'make one box and shove everything into it'",
          "I think that's a lesson I keep learning, that if you have to wrestle the CSS too much it is likely that taking a more declarative approach will pay off in the end"
        ],
        "alt": "explaining the final solution I came upon"
      },
      {
        "type": "Buttons",
        "alt": "Button To decide where to go next",
        "value": {
          "Return Home": {
            "url": "https://lucas-leprince.com/index.json",
            "MIMEType": "application/json"
          },
          "Behind the scenes": {
            "url": "https://lucas-leprince.com/bts.json",
            "MIMEType": "application/json"
          }
        }
      },
      {
        "type": "ModeButtons",
        "value": {
          "Dark Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=dark",
            "MIMEtype": "text/html"
          },
          "Light Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=light",
            "MIMEtype": "text/html"
          },
          "Rainbow Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=rainbow",
            "MIMEtype": "text/html"
          },
          "Terminal Mode": {
            "url": "https://lucas-leprince.com/bts/button?mode=terminal",
            "MIMEtype": "text/html"
          },
          "Markdown": {
            "url": "https://lucas-leprince.com/bts/button.md",
            "MIMEtype": "text/markdown"
          },
          "JWT": {
            "url": "https://lucas-leprince.com/api/bts/button/token",
            "MIMEtype": "application/jwt"
          },
          "Database": {
            "url": "https://lucas-leprince.com/database.json",
            "MIMEtype": "json"
          }
        }
      },
      {
        "type": "ProgressTracker",
        "progress": {
          "url": "https://lucas-leprince.com/progress.json",
          "MIMEtype": "application/json"
        }
      }
    ],
    "footer": {
      "GitHub": "https://github.com/LePetitPrince-4",
      "GitLab": "https://gitlab.com/LePetitPrince4",
      "LinkedIn": "https://www.linkedin.com/in/lucas-leprince/",
      "PGP key": "https://lucas-leprince.com/pgp-key",
      "RSS Feed": "https://lucas-leprince.com/feed",
      "Sitemap": "https://lucas-leprince.com/sitemap.xml"
    },
    "permalink": "https://lucas-leprince.com/permalink/v1/7ff00adf-5c3a-4465-b3e0-650f39502b72/json",
    "permalinks": {
      "v1": "https://lucas-leprince.com/permalink/v1/7ff00adf-5c3a-4465-b3e0-650f39502b72/json",
      "v2": "https://lucas-leprince.com/permalink/v2/buttons/json"
    }
  }
}