Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(link): drop use-link hook as react-aria-components handles client side routing internally #18

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.