ory / elements

Ory Elements is a component library that makes building login, registration and account pages for Ory a breeze. Check out the components library on Chromatic https://www.chromatic.com/library?appId=63b58e306cfd32348fa48d50

Home Page:https://ory.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide way to use client-side router for additionalProps links

omarhachach opened this issue · comments

Preflight checklist

Describe your problem

Having the additonalProps links be an <a> tag forces a full refresh each time. This is a UX problem, as we want to utilize our client-side router.

Describe your ideal solution

I imagine a way to either pass the component itself to the ThemeProvider. I.e. having the Provider accept a linkComponent:

export type ThemeProviderProps = {
  theme?: "light" | "dark"
  themeOverrides?: Partial<Theme>
  children?: React.ReactNode
  LinkComponent?: React.ElementType
}

This only has the issue of having the differing navigation libraries not having the same support certain features (children for links, having href vs to as the link prop etc.), so I am not in favor of this way. (Although, this could be omitted by defining your own component which wraps your link component)

Two more idiomatic solutions would have having either the ThemeProvider or UserAuthCard itself accept a constructor like so:

interface LinkProps {
    children: React.ReactNode
    link: string
    icon?: React.ReactNode
    props?: object
}

export type RegistrationSectionAdditionalProps = {
  loginURL?: string | (props: LinkProps) => JSX.Element
}

This way any component can be used, with a string just using a <a> tag.

The other idiomatic solution would be to accept an onClickHandler which could then use the navigation library's navigation functionality:

export type RegistrationSectionAdditionalProps = {
  loginURL?: string | (link: string) => void
}

Workarounds or alternatives

None

Version

v0.0.1-alpha.27

Additional Context

I'm available to help with this feature.