Skip to content

Commit

Permalink
Move useHighlightAnimation to ui package
Browse files Browse the repository at this point in the history
  • Loading branch information
Youakeem committed Sep 18, 2024
1 parent 2fc4697 commit 00be299
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 32 deletions.
11 changes: 9 additions & 2 deletions apps/store/src/components/Combobox/Combobox.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import clsx from 'clsx'
import { useCombobox } from 'downshift'
import { useState, useMemo, useDeferredValue, useId } from 'react'
import { ChevronIcon, CrossIconSmall, Text, xStack, theme, WarningTriangleIcon } from 'ui'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'
import {
ChevronIcon,
CrossIconSmall,
Text,
xStack,
theme,
WarningTriangleIcon,
useHighlightAnimation,
} from 'ui'
import {
wrapper,
wrapperExpanded,
Expand Down
3 changes: 1 addition & 2 deletions apps/store/src/components/DebugDialog/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import styled from '@emotion/styled'
import { useEffect, useState } from 'react'
import { Text, theme } from 'ui'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'
import { Text, theme, useHighlightAnimation } from 'ui'

export const CopyToClipboard = (props: { label: string; children: string }) => {
const { highlight, animationProps } = useHighlightAnimation<HTMLButtonElement>()
Expand Down
3 changes: 1 addition & 2 deletions apps/store/src/components/InputDay/InputDay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { sv } from 'date-fns/locale'
import { useTranslation } from 'next-i18next'
import { type CSSProperties, startTransition, useId, useState } from 'react'
import { useInput, DayPicker, type SelectSingleEventHandler } from 'react-day-picker'
import { ChevronIcon, Text, LockIcon, theme } from 'ui'
import { ChevronIcon, Text, LockIcon, theme, useHighlightAnimation } from 'ui'
import { LoadingDots } from '@/components/LoadingDots/LoadingDots'
import { convertToDate } from '@/utils/date'
import { Language } from '@/utils/l10n/types'
import { useCurrentLocale } from '@/utils/l10n/useCurrentLocale'
import { useFormatter } from '@/utils/useFormatter'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'
import { trigger, label, iconWrapper, chevronIcon, popoverContent, dayPicker } from './InputDay.css'

import 'react-day-picker/dist/style.css'
Expand Down
3 changes: 1 addition & 2 deletions apps/store/src/components/InputRadio/InputRadio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
type ComponentProps,
type ComponentPropsWithoutRef,
} from 'react'
import { Text } from 'ui'
import { Text, useHighlightAnimation } from 'ui'
import { RadioIndicatorIcon } from '@/features/priceCalculator/RadioIndicatorIcon'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'
import { horizontalRadioGroup, card, item, paddedItem, radioButton } from './InputRadio.css'

type Option = { label: string; value: string; autoFocus?: boolean }
Expand Down
10 changes: 8 additions & 2 deletions apps/store/src/components/InputSelect/InputSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
import { assignInlineVars } from '@vanilla-extract/dynamic'
import { clsx } from 'clsx'
import { type ChangeEventHandler, useId } from 'react'
import { ChevronIcon, InputBase, type InputBaseProps, type UIColorKeys, getColor } from 'ui'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'
import {
ChevronIcon,
InputBase,
type InputBaseProps,
type UIColorKeys,
getColor,
useHighlightAnimation,
} from 'ui'
import {
chevronIcon,
inputLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import styled from '@emotion/styled'
import * as RadioGroup from '@radix-ui/react-radio-group'
import type { MouseEventHandler } from 'react'
import { type ComponentProps } from 'react'
import { Text, theme } from 'ui'
import { Text, theme, useHighlightAnimation } from 'ui'
import { Pillow } from '@/components/Pillow/Pillow'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'

type RootProps = RadioGroup.RadioGroupProps

Expand Down
3 changes: 1 addition & 2 deletions apps/store/src/components/StepperInput/StepperInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
useState,
useId,
} from 'react'
import { MinusIcon, PlusIcon, xStack, yStack } from 'ui'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'
import { MinusIcon, PlusIcon, useHighlightAnimation, xStack, yStack } from 'ui'
import { outerWrapper, select, inputLabel, stepButton } from './StepperInput.css'

export type StepperInputProps = {
Expand Down
11 changes: 9 additions & 2 deletions apps/store/src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import clsx from 'clsx'
import type { ChangeEventHandler, InputHTMLAttributes, MouseEventHandler, ReactNode } from 'react'
import { useId, useRef, useState } from 'react'
import { sprinkles } from 'ui/src/theme/sprinkles.css'
import { LockIcon, Text, WarningTriangleIcon, theme, yStack, CrossIcon } from 'ui'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'
import {
LockIcon,
Text,
WarningTriangleIcon,
theme,
yStack,
CrossIcon,
useHighlightAnimation,
} from 'ui'
import {
deleteButton,
input,
Expand Down
3 changes: 1 addition & 2 deletions apps/store/src/components/ToggleCard/ToggleCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { ReactNode } from 'react'
import { useId } from 'react'
import { Space } from 'ui'
import { Space, useHighlightAnimation } from 'ui'
import { SpaceFlex } from '@/components/SpaceFlex/SpaceFlex'
import { Switch, type SwitchProps } from '@/components/Switch'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'
import { wrapper, checkboxHeader, labelText } from './ToggleCard.css'

type Props = SwitchProps & {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from './components/Tabs/Tabs'
export { responsiveVariants } from './utils/responsiveVariants/responsiveVariants'
export * from './utils/responsiveVariants/repsonsiveVariants.types'
export { visuallyHidden } from './utils/visuallyHidden.css'
export { useHighlightAnimation } from './utils/useHighlightAnimation'

export * from './icons'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
'use client'

import { type KeyboardEvent, useCallback, useRef, useState, useEffect } from 'react'
import { theme } from 'ui'
import { theme } from '../theme/theme'

const SIGNAL_GREEN_FILL_HSLA = theme.colors.signalGreenFill
.replace('hsl', 'hsla')
.replace(')', ', 0.99)')

const EXCLUDE_SET = new Set([
'Tab',
'Enter',
'ArrowDown',
'ArrowUp',
'ArrowRight',
'ArrowLeft',
'Shift',
'Alt',
'Meta',
'Control',
])

export function useHighlightAnimation<Element extends HTMLElement>() {
const ref = useRef<Element | null>(null)
const [backgroundColor, setBackgroundColor] = useState<string>(theme.colors.translucent1)
Expand Down Expand Up @@ -44,16 +57,3 @@ export function useHighlightAnimation<Element extends HTMLElement>() {

return { highlight, animationProps: { ref } } as const
}

const EXCLUDE_SET = new Set([
'Tab',
'Enter',
'ArrowDown',
'ArrowUp',
'ArrowRight',
'ArrowLeft',
'Shift',
'Alt',
'Meta',
'Control',
])

0 comments on commit 00be299

Please sign in to comment.