Creating a webforJ Reading Position Indicator

Recently, I was browsing articles on CSS Tricks and came across Reading Position Indicator by Pankaj Parashar. I've seen this type of indicator in articles, blogs, and in lengthy terms and conditions that I've definitely read through thoroughly. I wanted to try recreating a reading position indicator using webforJ, and see if I could build it in less than 100 lines of code.
Including import statements, I managed to keep this project contained within 76 lines of code. Here's how I did it, piece by piece.

The visuals
The main component
I knew immediately which webforJ component I wanted to use for this project: the ProgressBar component. Even though it's the most crucial component, it only took a few lines to get it working the way I wanted.
Apart from the logic that determined how far along the page a user was, all I needed to do was set an initial and a maximum value. I decided to start it at 0 and set a maximum value of 100 to represent completing 100% of the article. I also made the maximum value a variable so I could use it later in the project.
private final Integer maxProgressValue = 100;
private final ProgressBar progressBar = new ProgressBar(0, maxProgressValue);
A persistent Toolbar
Ok, now that I had the component that would show the progression, I wanted to keep it compact, close to an article header, and anchored at the top of the screen. I knew that if I nested my ProgressBar inside a Toolbar, as shown in the ProgressBar in toolbars example, I could achieve my goals for compactness and closeness to the article header.
private final Toolbar toolbar = new Toolbar();
toolbar.add(new H3("Reading Position Indicator"), progressBar);
To keep it anchored, I decided to style my toolbar with CSS, targeting the web component as it appears in the DOM. Using two setStyle() calls for anchoring the toolbar could have saved me some lines of code, as I wouldn't have to use the @StyleSheet annotation or wrap my CSS styling in a selector, but I ultimately decided to keep this project well-organized. I'm glad I made that design choice, because I later decided to style the background color of the Toolbar.
dwc-toolbar {
position: sticky;
top: 0;
background-color: var(--dwc-surface-3);
}
