-
Notifications
You must be signed in to change notification settings - Fork 850
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
Conversation
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 - We can add modal for example-ui page later if needed |
packages/nextjs/components/Modal.tsx
Outdated
*/ | ||
type ModalProps = { | ||
trigger: JSX.Element; | ||
modalTitle: string; |
There was a problem hiding this comment.
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.
packages/nextjs/components/Modal.tsx
Outdated
type ModalProps = { | ||
trigger: JSX.Element; | ||
modalTitle: string; | ||
modalContent: JSX.Element; |
There was a problem hiding this comment.
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
packages/nextjs/components/Modal.tsx
Outdated
}; | ||
}; | ||
|
||
const Modal: React.FC<ModalProps> = ({ trigger, modalTitle, modalContent, action }) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
packages/nextjs/components/Modal.tsx
Outdated
trigger: JSX.Element; | ||
modalTitle: string; | ||
modalContent: JSX.Element; | ||
action?: { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
@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? |
Yes, we don't need it for now
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 Thanks! |
}; | ||
}; | ||
|
||
const Modal: React.FC<TriggerModalProps> = ({ trigger, name, children, action }) => { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove for now
…itConnectButton and Faucet components.
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! |
Hi @0xChijoke , good job! I don't like two-component nature of 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"> |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
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!
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. |
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 🙌 |
hmm, I'm not very agree, because
Yes, if we want to add modal, we need to add most of the options from daisyui, and also add other components like Thanks @0xChijoke for your efforts and @technophile-04 for review! |
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