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

Reusable TriggerModal component in RainbowKitCustomConnectButton and Faucet #507

Closed
wants to merge 6 commits into from

Conversation

0xChijioke
Copy link
Contributor

@0xChijioke 0xChijioke commented Aug 26, 2023

Description

Hello! This pull request introduces a reusable TriggerModal component and integrates it into the RainbowKitCustomConnectButton and Faucet components. This modification aims to improve developer/user experience and code reuseability.

video1299019585.mp4

Additional Information

Your ENS/address: chijoke.eth

@rin-st
Copy link
Member

rin-st commented Aug 26, 2023

Hi @0xChijoke , thank you for the pr!

I believe we should ask designers for big changes on the example-ui page.

So in this pr let's polish new modal component and use it for components where we have modals already - RainbowKitCustomConnectButton and Faucet.

We can add modal for example-ui page later if needed

*/
type ModalProps = {
trigger: JSX.Element;
modalTitle: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use that prop for htmlsFor and id attributes but not for title. So I think name or `id' is better.

Title should be in different place, because it can be empty or long with spaces and can break labels/ids.

type ModalProps = {
trigger: JSX.Element;
modalTitle: string;
modalContent: JSX.Element;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about just using children instead of this prop

};
};

const Modal: React.FC<ModalProps> = ({ trigger, modalTitle, modalContent, action }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, it's not only modal, but also trigger. So maybe it should be named like TriggerWithModal? Check prop types name too if you'll change component name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Does TriggerModal work?

trigger: JSX.Element;
modalTitle: string;
modalContent: JSX.Element;
action?: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be two or more buttons, for example "cancel" and "save". So probably we need to include this in content too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, the actions can be included in the modal content.

In the exampe-ui the send is in the modalContent.

The action is optional cause I had a specific use for passing it in.

It can also be removed if there is no need to leave the option there.

@@ -19,6 +20,45 @@ export const ContractInteraction = () => {
},
});

// Define the modal trigger button
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change this file when we'll have designs
#466

@0xChijioke
Copy link
Contributor Author

@rin-st Let me know what you think about the current state of the component.

Should the optional action be removed because that can come with the children?

Would I need to create another PR to leave other files in there original state?

@rin-st
Copy link
Member

rin-st commented Aug 27, 2023

Should the optional action be removed because that can come with the children?

Yes, we don't need it for now

Would I need to create another PR to leave other files in there original state?

No, you can rename this pr and remove changes of other files. We can take those changes if needed from commits history.

When you complete the component, please change custom modals in RainbowKitCustomConnectButton and Faucet

Thanks!

};
};

const Modal: React.FC<TriggerModalProps> = ({ trigger, name, children, action }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name

@@ -0,0 +1,42 @@
/**
* Modal component: A reusable modal component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

trigger: JSX.Element;
name: string;
children: JSX.Element;
action?: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove for now

@0xChijioke 0xChijioke changed the title enhancement(UI): Added a reuseable modal component and used it for the set greeting input. Reusable TriggerModal component in RainbowKitCustomConnectButton and Faucet Aug 27, 2023
@0xChijioke 0xChijioke closed this Aug 28, 2023
@0xChijioke 0xChijioke reopened this Aug 28, 2023
@0xChijioke
Copy link
Contributor Author

0xChijioke commented Aug 28, 2023

Hello @rin-st,

While refactoring the RainbowKitConnectButton component, I encountered a scenario where rendering the trigger separately from the modal body would be beneficial.

To address this, I've split the component into two parts and introduced a new folder called TriggerWithModal. Within this folder, you'll find the Trigger and Modal components, each serving their specific roles and enhancing modularity.

I've already utilized this structure in both the RainbowKitConnectButton and Faucet components. Your feedback on this approach and any potential adjustments would be greatly appreciated.

Thanks!

@rin-st
Copy link
Member

rin-st commented Aug 29, 2023

Hi @0xChijoke , good job!

I don't like two-component nature of TriggerWithModal but it seems in this case it's a good solution.

I've tested your branch and found that modal doesn't close on click outside, as it was before. Fix it, please

@@ -82,49 +84,42 @@ export const Faucet = () => {

return (
<div>
<label htmlFor="faucet-modal" className="btn btn-primary btn-sm px-2 rounded-full font-normal normal-case">
<Trigger id="faucet-modal" className="btn btn-primary btn-sm px-2 rounded-full font-normal normal-case">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it's better to move id to constant outside of component and use it in both trigger and modal

@@ -134,10 +136,10 @@ export const RainbowKitCustomConnectButton = () => {
)}
</li>
<li>
<label htmlFor="qrcode-modal" className="btn-sm !rounded-xl flex gap-3 py-3">
<Trigger id="qrcode-modal" className="btn-sm !rounded-xl flex gap-3 py-3">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've incorporated the changes you mentioned.

I've also added an option for the modal to be closed on outside clicks(true by default), considering its reusability.

This way, the modal can be used in various scenarios, allowing builders to choose the preferred behaviour.

Your patience and guidance are much appreciated. Looking forward to your feedback!

@technophile-04
Copy link
Collaborator

Hey guys thanks, but I don't see much advantages of adding this component :

With DaisyUI v3 modal:

<button onClick={() => window.faucet_modal.showModal()} className="...">
   ...
  <span>Faucet</span>
</button>

<dialog id={"faucet_modal"} className="modal">
  <form method="dialog" className="modal-box">
    ...
  </form>
</dialog>

With this component :

<Trigger id={FAUCET_MODAL_ID} className="...">
  ...
  <span>Faucet</span>
</Trigger>

<Modal id={FAUCET_MODAL_ID}>
  ...
</Modal>

Since we are using a component library (daisyUI v3) I think it's not worth creating our own micro components unless we have good reason to or there is something that is not present / not working in daisyUI

Also, I think by creating this component we are just abstracting 1-2 lines of code, I think its we let user use daisy UI and learn/customize as they want

What do you guys think?

@0xChijioke
Copy link
Contributor Author

Hey guys thanks, but I don't see much advantages of adding this component :

With DaisyUI v3 modal:

<button onClick={() => window.faucet_modal.showModal()} className="...">
   ...
  <span>Faucet</span>
</button>

<dialog id={"faucet_modal"} className="modal">
  <form method="dialog" className="modal-box">
    ...
  </form>
</dialog>

With this component :

<Trigger id={FAUCET_MODAL_ID} className="...">
  ...
  <span>Faucet</span>
</Trigger>

<Modal id={FAUCET_MODAL_ID}>
  ...
</Modal>

Since we are using a component library (daisyUI v3) I think it's not worth creating our own micro components unless we have good reason to or there is something that is not present / not working in daisyUI

Also, I think by creating this component we are just abstracting 1-2 lines of code, I think its we let user use daisy UI and learn/customize as they want

What do you guys think?

I share your perspective. While the initial intention was to simplify modal usage, it seems that introducing custom components might actually lead to unnecessary complexity.

@technophile-04
Copy link
Collaborator

I share your perspective. While the initial intention was to simplify modal usage, it seems that introducing custom components might actually lead to unnecessary complexity.

Yeah, but tysm @0xChijoke for questing on this !! Also, Chijoke would really appreciate creating an issue or discussion before creating a new feature PR so that we can iterate and brainstorm on it if it is really required / others can put suggestions/improvements on it too 🙌

Really feel bad closing this PR but appreciate it !! Also, tysm to Rinat for reviewing this 🙌

@rin-st
Copy link
Member

rin-st commented Aug 29, 2023

I think by creating this component we are just abstracting 1-2 lines of code, I think its we let user use daisy UI and learn/customize as they want

hmm, I'm not very agree, because

  • why to force users to learn something if we can avoid it? yes it's a small thing, but it can take let's say 5-10 mins to configure it instead of two imports. Users can forget to add clickoutside and so on
  • we have at least two modals for now, and if we want for example add shadow we need to do it in two places instead of one

Yes, if we want to add modal, we need to add most of the options from daisyui, and also add other components like Button and other simple things. It simplifies development but we need to think if we really need it.

Thanks @0xChijoke for your efforts and @technophile-04 for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants