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
https://ory.sh
Apache License 2.0
85 stars 44 forks source link

feat: add href handler for ButtonLink component #103

Closed DASPRiD closed 1 year ago

DASPRiD commented 1 year ago

Fixes #58

This PR adds the option to specify a link handler in order to make use of client side navigation. This is fully backward compatible, without introducing any new parameters which have to be passed around.

This is achieved by extending the type of href in the ButtonLink component to also accept a tuple of a URL and a handler. When this tuple is defined, the default click event will be prevented and the handler will be called with the URL.

In it's simplest form, this allows to easily use React's navigation feature like this:

const Login = () : JSX.Element => {
    const navigate = useNavigate();

    // …

    return (
        <UserAuthCard
          flow={flow}
          flowType="login"
          additionalProps={{ logoutURL: ["/logout", navigate] }}
        />,
    );
};

Checklist

Benehiko commented 1 year ago

Hey @DASPRiD,

I have made some changes to this PR based on my review. Would you review to make sure the changes also look alright from your side? I will let @mszekiel also review the changes before merge.