Skip to content

Commit

Permalink
feat: adds button highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed Jul 16, 2024
1 parent 07e6490 commit ef72886
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/frontend/Features/Control/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ import axios from 'axios'
import { type ButtonProps } from '@mantine/core'
import { type ControlProps } from '..'
import { controlRoute, controlTitle } from '../lib'
import { useLocalStorage } from '@mantine/hooks'

import cx from 'clsx'
import * as classes from '../Control.css'

interface ButtonControlProps extends ButtonProps, ControlProps {}

const ButtonControl = forwardRef<HTMLButtonElement, ButtonControlProps>((
{ children, edit, control, ...props },
{ children, edit, control, className, ...props },
ref,
) => {
const [lastButtonClicked, setLastButtonClicked] = useLocalStorage<number>({
key: 'last-button-clicked',
defaultValue: undefined,
})
const handleButtonClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault()

Expand All @@ -21,13 +29,16 @@ const ButtonControl = forwardRef<HTMLButtonElement, ButtonControlProps>((
if(!route) return

axios.put(route)

setLastButtonClicked(control.id)
}

return (
<Button
ref={ ref }
onClick={ handleButtonClick }
color={ control?.color ?? undefined }
className={ cx([className, { [classes.lastButtonClicked]: lastButtonClicked === control.id }]) }
{ ...props }
>
{ children || controlTitle(control) }
Expand Down
7 changes: 7 additions & 0 deletions app/frontend/Features/Control/Control.css.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import { vars } from '@/lib'
import { css } from '@linaria/core'

const highlightBorderPx = 4

export const lastButtonClicked = css`
border: ${highlightBorderPx}px solid ${vars.colors.green[4]};
margin: calc(${vars.spacing.xs} - ${highlightBorderPx}px);
`

0 comments on commit ef72886

Please sign in to comment.