Skip to content

Commit

Permalink
fix(link): drop use-link hook as react-aria-components handles client…
Browse files Browse the repository at this point in the history
… side routing internally
  • Loading branch information
PHILLIPS71 committed Apr 16, 2024
1 parent ee1ff5e commit c46f4d3
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 49 deletions.
1 change: 0 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
},
"devDependencies": {
"@jest/types": "^29.6.3",
"@react-types/shared": "^3.22.1",
"@storybook/addon-backgrounds": "^8.0.1",
"@storybook/addon-essentials": "8.0.1",
"@storybook/addon-interactions": "8.0.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/components/link/Link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ const Component: Meta<typeof Link> = {
}

const defaultProps = {
href: 'www.giantnodes.com',
...link.defaultVariants,
}

export const Default: StoryFn = (args: LinkProps) => <Link {...args}>There were 2 errors with your submission</Link>
export const Default: StoryFn = (args: LinkProps) => <Link {...args}>Default Link</Link>

Default.args = {
...defaultProps,
}
Expand Down
8 changes: 1 addition & 7 deletions packages/react/src/components/link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ import { link } from '@giantnodes/theme'
import React from 'react'
import { Link } from 'react-aria-components'

import { useDomRef } from '@/hooks/use-dom-ref'
import { useLink } from '@/hooks/use-link.hook'

type ComponentProps = ComponentWithoutAs<'a'> & LinkProps

const Component = React.forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
const { children, className } = props

const dom = useDomRef(ref)
const { ...rest } = useLink(props, dom)
const { children, className, ...rest } = props

const slots = React.useMemo(() => link({}), [])

Expand Down
13 changes: 1 addition & 12 deletions packages/react/src/hooks/use-design-system.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { RouterProvider } from '@react-aria/utils'

import { createContext } from '@/utilities/context'

export type UseDesignSystemProps = React.PropsWithChildren & {
/**
* Provides a client side router to all components that contain links
*/
navigate?: (path: string) => void
}

export type UseDesignSystemReturn = ReturnType<typeof useDesignSystem>

export const useDesignSystem = ({ navigate, children }: UseDesignSystemProps) => {
export const DesignSystemProvider: React.FC<UseDesignSystemProps> = ({ navigate, children }) => {
let contents = children

if (navigate) {
Expand All @@ -20,10 +16,3 @@ export const useDesignSystem = ({ navigate, children }: UseDesignSystemProps) =>

return contents
}

export const [DesignSystemContext, useDesignSystemContext] = createContext<UseDesignSystemReturn>({
name: 'DesignSystemContext',
strict: true,
errorMessage:
'useDesignSystemContext: `context` is undefined. Seems you forgot to wrap component within <DesignSystem.Provider />',
})
25 changes: 0 additions & 25 deletions packages/react/src/hooks/use-link.hook.ts

This file was deleted.

4 changes: 1 addition & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c46f4d3

Please sign in to comment.