-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(@aws-amplify/amplify-ui-components): authenticator slotted toast #7601
feat(@aws-amplify/amplify-ui-components): authenticator slotted toast #7601
Conversation
The logic behind the component name Note that the slot name in Open to better suggestions! |
Codecov Report
@@ Coverage Diff @@
## main #7601 +/- ##
=======================================
Coverage 74.13% 74.13%
=======================================
Files 215 215
Lines 13450 13450
Branches 2641 2641
=======================================
Hits 9971 9971
Misses 3280 3280
Partials 199 199 Continue to review full report at Codecov.
|
Hi! Thanks a lot for diving deep into this. Apologies this got long time to respond also. I'm a bit against creating a new component though:
So I think we want to keep it simple in this case, but please feel free to disagree! @ericclemmons, what do you think? |
Thanks for taking a look @wlee221. You don't need to apologise for taking time to get to it!
I would view it in the same way as Could you help me identify the error handling logic in
For life cycle methods, are you referring to stencil's lifecycle methods? If so, could you help me understand what you mean when you say "we need to manage" these? It is likely something I haven't understood about web components or stencil. If you're referring simply to the hub listeners that
I think this is actually a positive for this solution since it demonstrates that no additional complexity has been added in that regard. I'm not sure how I ended up writing so much text sorry! But the tl;dr would be that |
Hi @Luke-Davies, thanks for the detailed response!
I see, so this is more about separating the logic from
Yes. #7522 discusses this, but in tl;dr, inserting web components into a slot is very unpredictable. But Line 178 in 7790e8f
would catch those errors, so I'm good.
This is a good catch!
My point was that having
Don't worry, I (unnecessarily) write 5 paragraph essays to my PRs and issues too 😛
Edit: We want to keep the solution simple in this case; see comment below. |
packages/amplify-ui-components/src/components/amplify-auth-alert/amplify-auth-alert.tsx
Outdated
Show resolved
Hide resolved
packages/amplify-ui-components/src/components/amplify-auth-alert/amplify-auth-alert.tsx
Outdated
Show resolved
Hide resolved
packages/amplify-ui-components/src/components/amplify-auth-alert/amplify-auth-alert.tsx
Outdated
Show resolved
Hide resolved
packages/amplify-ui-components/src/components/amplify-authenticator/amplify-authenticator.tsx
Outdated
Show resolved
Hide resolved
packages/amplify-ui-components/src/components/amplify-auth-alert/amplify-auth-alert.tsx
Outdated
Show resolved
Hide resolved
...onents/src/components/amplify-authenticator/__snapshots__/amplify-authenticator.spec.ts.snap
Outdated
Show resolved
Hide resolved
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.
LGTM, with some nits 👍 Also, can you add slot documentation at the top of amplify-authenticator
? Something like
Line 27 in ac0ef4b
* @slot sign-in - Content placed inside of the sign in workflow for when a user wants to sign into their account |
Hi @Luke-Davies, I have gave this more thought and also synced internally on this pull request. I apologize about taking back my previous comment, but we want to move away from creating a new component for this case. Our goal for issue #6479 was to be able to hide toast, which a simple slot addition in You brought up a good point about code-splitting and removing unnecessary Hub event. For code-splitting, I stand by my previous point that That being said, thanks a lot for diving deep and putting a lot of thought into this! Sorry again for taking back what I said -- It's really that we want to prioritize simpler solution for this use case. Let's go back to #7129 and continue there! |
Sorry for only just getting back to this @wlee221. Thanks for the detailed explanation, that makes a lot of sense. Would it be better to adapt this PR to remove the new component? I can just drop the commits from my fork and reimplement it. That seems to make more sense based on the names of the two PRs. I'll hold off until I hear back. |
@Luke-Davies, it would be totally fine to use this PR. |
ed68dc5
to
fe1bf9f
Compare
@wlee221 see brand-new branch history. Let me know if the name "alert" is ok for the slot. Or do we want "toast"? I'll update the PR description next although I think the example is exactly the same. |
Now the hardest part... naming! I'm thinking about |
data-test="authenticator-error" | ||
/> | ||
) : null} | ||
<slot name="alert"> |
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.
Can we have this.toastMessage &&
check here in line 190 so the slot isn't always visible?
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 thought about this but came to the conclusion that it would restrict the slot to only render based on how authenticator's default slot works.
A rushed example to illustrate what I mean:
<AmplifyAuthenticator>
<div slot="alert">
{authErrMsg && ( // authErrMsg is the same as authenticators toastMessage
<MyFancyAlert msg={authErrMsg} handleClose={() => setAuthErrMsg('')} />
)}
{showInactiveSignOutMsg && (
<MyFancyAlert msg={"You were signed out due to inactivity."} handleClose={() => setShowInactiveSignOutMsg(false)} />
)}
</div>
</AmplifyAuthenticator>
That example wouldn't work if we move this.toastMessage &&
down a line.
The "inactive sign out" bits could be moved outside the authenticator, but then so could the authErrMsg
bit and that would leave me wondering how much benefit there is to the slot approach vs the props approach.
That said, most usages will look like the example I put in the description so I might be over thinking this.
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 guess one counter argument to what I've said would be that, without moving this.toastMessage &&
, there's nothing to stop people abusing this slot for non-notification purposes.
I'm really starting to wonder if the prop
approach may be the better option here. It seems like with the slot approach we have a choice between either a slot that is really open - so more customisation at the risk of being mis-used - or a slot that is pretty restrictive - i.e. can only really do the same as what the default component does functionality-wise.
Either way I think I've talked myself into the change you've suggested.
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.
You bring up a good point -- I really like your inactivity example. I'm also in agreement with the prop
approach. Instead of having a limited slot / too open of a slot, we can just have hideToast
and user can do whatever.
I think this is a better developer experience 1) for customers just trying to hide toast, and 2) customers trying to customize toast
, because they have more flexibility on their notification
implementation. Custom implementation can be placed anywhere and can be reused outside AmplifyAuthenticator
for general notification purpose:
const MyAuth: React.FC = ({ children }) => {
return (
<div>
<MyAlert />
<AmplifyAuthenticator>
// ...........
</AmplifyAuthenticator>
</div>
);
}
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.
Agreed. How do we proceed now? I could write an explanation on #7129 outlining why props may be a better choice? Or should I leave this with yourself for now @wlee221?
If the consensus is still slots, it would just be a question of whether it is a limited or open slot.
If there is agreement on props then I believe #7129 is good to go, although we could make a minor improvement which I'll discuss there.
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 go ahead and use props
since we're in agreement. We can move over to #7129, and thanks for your responsiveness over this!
I've just noticed I missed the |
packages/amplify-ui-components/src/components/amplify-authenticator/amplify-authenticator.tsx
Show resolved
Hide resolved
Closed in favour of #7129 |
This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Issue #, if available: #6479
Description of changes:
Following discussions on PR #7129 and issue #6479, this PR offers a slotted approach to toast customisation in the
amplify-authenticator
component.This PR has been updated. The example is the same however.
Rather than just wrapping theamplify-toast
in a slot however, this PR introduces a new component:amplify-auth-alert
.Introducing this component has the following benefits:Removes thehandleToastEvent
logic fromamplify-authenticator
, therefore reducing the logic/responsibility in this component.amplify-auth-alert
can be used outside/without theamplify-authenticator
if desired.Provides a clean example of an alert component inamplify-auth-alert
for anyone looking to roll their own alert component.React (ts) example:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.