Skip to content

Commit

Permalink
fix(frontend): lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Vibes-INS committed Jul 22, 2024
1 parent 31e7d18 commit 76e19a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 41 deletions.
59 changes: 29 additions & 30 deletions frontend/src/components/ui/primitives/hover-card.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
'use client'
import type { Assign } from '@ark-ui/react'
import { HoverCard } from '@ark-ui/react/hover-card'
import { type HoverCardVariantProps, hoverCard } from 'styled-system/recipes'
import { hoverCard, type HoverCardVariantProps } from 'styled-system/recipes'
import type { ComponentProps, HTMLStyledProps } from 'styled-system/types'

import { createStyleContext } from '@/lib/create-style-context'

const { withRootProvider, withContext } = createStyleContext(hoverCard)

export type RootProviderProps = ComponentProps<typeof RootProvider>
export const RootProvider = withRootProvider<
Assign<HoverCard.RootProviderProps, HoverCardVariantProps>
>(HoverCard.RootProvider)
export const RootProvider = withRootProvider<Assign<HoverCard.RootProviderProps, HoverCardVariantProps>>(
HoverCard.RootProvider,
)

export type RootProps = ComponentProps<typeof Root>
export const Root = withRootProvider<Assign<HoverCard.RootProps, HoverCardVariantProps>>(
HoverCard.Root,
export const Root = withRootProvider<Assign<HoverCard.RootProps, HoverCardVariantProps>>(HoverCard.Root)

export const Arrow = withContext<HTMLDivElement, Assign<HTMLStyledProps<'div'>, HoverCard.ArrowBaseProps>>(
HoverCard.Arrow,
'arrow',
)

export const ArrowTip = withContext<HTMLDivElement, Assign<HTMLStyledProps<'div'>, HoverCard.ArrowTipBaseProps>>(
HoverCard.ArrowTip,
'arrowTip',
)

export const Arrow = withContext<
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, HoverCard.ArrowBaseProps>
>(HoverCard.Arrow, 'arrow')

export const ArrowTip = withContext<
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, HoverCard.ArrowTipBaseProps>
>(HoverCard.ArrowTip, 'arrowTip')

export const Content = withContext<
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, HoverCard.ContentBaseProps>
>(HoverCard.Content, 'content')

export const Positioner = withContext<
HTMLDivElement,
Assign<HTMLStyledProps<'div'>, HoverCard.PositionerBaseProps>
>(HoverCard.Positioner, 'positioner')

export const Trigger = withContext<
HTMLButtonElement,
Assign<HTMLStyledProps<'button'>, HoverCard.TriggerBaseProps>
>(HoverCard.Trigger, 'trigger')
export const Content = withContext<HTMLDivElement, Assign<HTMLStyledProps<'div'>, HoverCard.ContentBaseProps>>(
HoverCard.Content,
'content',
)

export const Positioner = withContext<HTMLDivElement, Assign<HTMLStyledProps<'div'>, HoverCard.PositionerBaseProps>>(
HoverCard.Positioner,
'positioner',
)

export const Trigger = withContext<HTMLButtonElement, Assign<HTMLStyledProps<'button'>, HoverCard.TriggerBaseProps>>(
HoverCard.Trigger,
'trigger',
)

export { HoverCardContext as Context } from '@ark-ui/react/hover-card'
16 changes: 5 additions & 11 deletions frontend/src/lib/create-style-context.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
createContext,
type ElementType,
forwardRef,
type ForwardRefExoticComponent,
type PropsWithoutRef,
type RefAttributes,
createContext,
forwardRef,
useContext,
} from 'react'
import { cx } from 'styled-system/css'
Expand All @@ -21,7 +21,7 @@ export const createStyleContext = <R extends Recipe>(recipe: R) => {
const StyleContext = createContext<Record<Slot<R>, string> | null>(null)

const withRootProvider = <P extends {}>(Component: ElementType) => {
const StyledComponent = (props: P) => {
function StyledComponent(props: P) {
const [variantProps, otherProps] = recipe.splitVariantProps(props)
const slotStyles = recipe(variantProps) as Record<Slot<R>, string>

Expand All @@ -45,11 +45,7 @@ export const createStyleContext = <R extends Recipe>(recipe: R) => {

return (
<StyleContext.Provider value={slotStyles}>
<StyledComponent
{...otherProps}
ref={ref}
className={cx(slotStyles?.[slot], props.className)}
/>
<StyledComponent {...otherProps} ref={ref} className={cx(slotStyles?.[slot], props.className)} />
</StyleContext.Provider>
)
})
Expand All @@ -66,9 +62,7 @@ export const createStyleContext = <R extends Recipe>(recipe: R) => {
const StyledComponent = styled(Component)
const StyledSlotComponent = forwardRef<T, P>((props, ref) => {
const slotStyles = useContext(StyleContext)
return (
<StyledComponent {...props} ref={ref} className={cx(slotStyles?.[slot], props.className)} />
)
return <StyledComponent {...props} ref={ref} className={cx(slotStyles?.[slot], props.className)} />
})
// @ts-expect-error
StyledSlotComponent.displayName = Component.displayName || Component.name
Expand Down

0 comments on commit 76e19a7

Please sign in to comment.