modernc.org/sqlite with Go
Explore how to use modernc.org/sqlite with Go to handle SQLite's single-writer, multiple-reader model, optimize PRAGMA settings, and avoid CGo.
Once when I was on the JetBrains site, I noticed a hover effect that caught my eye. This effect follows the movement of the mouse inside a box and a highlight appears around the cursor. As a Frontend Developer, I immediately had the idea to create this trick myself. I created it in React, because that is the framework I like the most. Now let's see how I made the implementation this component! The project repo can be found on GitHub, in the links at the end of this article.
But what exactly are we talking about? Here's a screenshot from the JetBrains site, the link is also at the end of the article.

First, a summary of how the magic works: is actually a function that continuously follows the movement of the mouse inside the box. So need to be able to determine the exact position of the cursor. And display the highlighting around the cursor. Which we will achieve by changing the background of the Box itself.
As a first step, I created a new React application. I've also included TypeScript in it.
npx create-react-app moving-highlight --template typescript
Then install the necessary libraries that will be used during development. I will now use Styled Components for CSS.
hnpm install --save styled-components
We also want to use icons, for which I chose Fontawesome.
npm install --save @fortawesome/fontawesome-svg-core npm install --save @fortawesome/free-brands-svg-icons npm install --save @fortawesome/free-solid-svg-icons npm install --save @fortawesome/free-regular-svg-icons
Once these steps are done, let's do a little cleanup of our file structure. Delete the App.css file, because as I mentioned we will use Styled Components. Feel free to do the same with the logo.svg file. We won't use this one either, as we will have the Fontawesome icons there. And convert the App.tsx file as follows:
import React from 'react' const App = () => { return ( <div></div> ) } export default App
Then create a folder called components inside the src folder. And inside the components folder, create a file called MovingHighlight.tsx, which will be the component we want to create.
We initialize our component as follows:
const MovingHighlight = () => { return ( <div> <h3>Moving highlight</h3> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p> </div> ) } export default MovingHighlight
Then import it into our App.tsx file:
import React from 'react' import MovingHighlight from './components/MovingHighlight' const App = () => { return ( <div> <MovingHighlight /> </div> ) } export default App
And then add the import for the CSS:
import styled from 'styled-components'
Create a Styled Component called AppContainer with the following CSS rules. Then apply the AppContainer to the div we created earlier.
import React from 'react' import MovingHighlight from './components/MovingHighlight' import styled from 'styled-components' const AppContainer = styled.div` min-height: 100vh; background: rgb(0, 0, 0); padding: 1.25rem; ` const App = () => { return ( <AppContainer> <MovingHighlight /> </AppContainer> ) } export default App
Next, let's get down to the nitty-gritty of adding logic and style to our component.
Let's start with CSS. Our outermost container should be the following and don't forget imports:
import styled from 'styled-components' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faReact } from '@fortawesome/free-brands-svg-icons' const Box = styled.div` color: rgb(255, 255, 255); border: 1px solid rgba(255, 255, 255, 0.7); border-radius: 0.5rem; padding: 0.75rem; cursor: default; max-height: 18rem; `
Then for the icon, the following:
const StyledIcon = styled(FontAwesomeIcon)` opacity: 0.7; `
And finally, for the paragraph:
const StyledText = styled.p` opacity: 0.7; `
Use the Styled Components and add the icon:
return ( <Box> <StyledIcon icon={faReact} size="5x" /> <h3>Moving highlight</h3> <StyledText> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </StyledText> </Box> )
For Box, we will need a useRef, which will be a reference value and an onMouseMove event, which calls a function when moving the mouse pointer over our Box element, and an onMouseLeave event, which calls a function when moving the mouse pointer out of our Box.
These will require the following imports:
import { useState, useRef, MouseEvent } from 'react'
useRef: we need this to determine the position of the mouse inside the Box.
const boxRef = useRef<HTMLInputElement>(null)
For the two events, define the following 3 useState:
const [bgColor, setBgColor] = useState<string>('rgb(0, 0, 0)') const [left, setLeft] = useState<number>(0) const [top, setTop] = useState<number>(0)
onMouseMove: when you move the mouse inside the Box, it will call a function.
Define the following variables:
Finally, change the background of the Box depending on the cursor position, for this, we will use a radial gradient.
const onMouseMoveHandler = (e: MouseEvent<HTMLDivElement>) => { const originalColor = 'rgb(0, 0, 0)' const lightColor = 'rgb(0,163,255)' const gradientSize = 150 setLeft(boxRef.current?.offsetLeft ?? 0) const x = e.pageX - left setTop(boxRef.current?.offsetTop ?? 0) const y = e.pageY - top const xy = x + ' ' + y setBgColor( '-webkit-gradient(radial, ' + xy + ', 0, ' + xy + ', ' + gradientSize + ', from(' + lightColor + '), to(rgba(255,255,255,0.0))), ' + originalColor ) }
onMouseLeave: when the mouse leaves the Box, the highlight should be removed. This is very simple, just change the background color back to its original color.
const onMouseLeaveHandler = () => { setBgColor('rgb(0, 0, 0)') }
Add the attributes and events to the component:
return ( <Box style={{ background: bgColor }} ref={boxRef} onMouseMove={(e: MouseEvent<HTMLDivElement>) => onMouseMoveHandler(e)} onMouseLeave={onMouseLeaveHandler}> <StyledIcon icon={faReact} size="5x" /> <h3>Moving highlight</h3> <StyledText> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </StyledText> </Box> )

Make our application responsive by making the following changes in App.tsx:
const AppContainer = styled.div` min-height: 100vh; background: rgb(0, 0, 0); display: grid; grid-template-columns: repeat(auto-fit, minmax(18.75rem, 1fr)); gap: 1.25rem; padding: 1.25rem; `
Plus add three more times our component:
return ( <AppContainer> <MovingHighlight /> <MovingHighlight /> <MovingHighlight /> <MovingHighlight /> </AppContainer> )

Explore how to use modernc.org/sqlite with Go to handle SQLite's single-writer, multiple-reader model, optimize PRAGMA settings, and avoid CGo.
By understanding the nuances of signal handling in containerized environments, we can prevent unexpected disruptions and maintain robust application performance.
React has become a dominant force in the world of web development, enabling developers to create highly interactive and dynamic user interfaces.