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

feat(toast): Toast implementation #3103

Merged
merged 1 commit into from
Jun 24, 2019
Merged

Conversation

benouat
Copy link
Member

@benouat benouat commented Apr 4, 2019

My final attempt at implementing Bootstrap Toast

The PR basically introduce:

  • <ngb-toast> component. it just render bootstrap markup, with some inputs, and one single output that emit after a given delay in ms.
  • NgbToastConfig to override any of the default config values used to initialise above inputs.
  • An overview page, explaining what are toast, how to use them, and also a full fledged how-to tutorial showing how to implement a global toast service inside any application.

DISCLAIMER: this PR only introduce a declarative way of creating a toast. Don't look around for any NgbToastService, there is none! I did not implement it on purpose. If you really think it should be done, I am just waiting, go come challenge me !! 😆

@codecov-io
Copy link

codecov-io commented Apr 5, 2019

Codecov Report

Merging #3103 into master will increase coverage by 0.05%.
The diff coverage is 97.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3103      +/-   ##
==========================================
+ Coverage   92.03%   92.09%   +0.05%     
==========================================
  Files          91       94       +3     
  Lines        3052     3087      +35     
  Branches      504      508       +4     
==========================================
+ Hits         2809     2843      +34     
  Misses        179      179              
- Partials       64       65       +1
Flag Coverage Δ
#e2e 62.94% <48.57%> (-0.17%) ⬇️
#unit 89.55% <97.14%> (+0.08%) ⬆️
Impacted Files Coverage Δ
src/index.ts 100% <ø> (ø) ⬆️
src/toast/toast.module.ts 100% <100%> (ø)
src/toast/toast-config.ts 100% <100%> (ø)
src/toast/toast.ts 96.42% <96.42%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a2d0cc...3245b70. Read the comment docs.

@benouat benouat force-pushed the feat/toast branch 2 times, most recently from ecc1d58 to 7350230 Compare April 5, 2019 10:21
Copy link
Member

@fbasso fbasso left a comment

Choose a reason for hiding this comment

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

Thanks for your PR @benouat ! I let a couple of comments in my review, mainly typo fixes.

demo/src/app/app.module.ts Show resolved Hide resolved
src/toast/toast.spec.ts Outdated Show resolved Hide resolved
src/toast/toast.spec.ts Outdated Show resolved Hide resolved
src/toast/toast.spec.ts Outdated Show resolved Hide resolved
src/toast/toast.ts Outdated Show resolved Hide resolved
@fbasso
Copy link
Member

fbasso commented May 23, 2019

I'm not also 100% sure that letting the widget visibility managed only by the developer is a good thing. I mean, for some use cases, it can render thing more complex than expected.

For example, what about a stateless message, as something the app wants to display a notification few seconds, and let the widget 'die' by itself.

As a developer, I would expect something like:

<ngb-toast delay="1000" autohide="true">
  I am a simple static toast.
</ngb-toast>

... and that's it !

I need more time to thing about it :)

Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

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

Hey @benouat!

Looks good as a starting API and we'll see if we need a service later.

Left some comments and most notably the big ones are:

  • we should have a demo where clicking on the cross would close the toast (simple one)
  • in the overview we should state somewhere early in the beginning that it's up to you to position toasts (like bootstrap does)
  • some tests will become invalid if you simplify autohide

Cheers,
Max

package.json Outdated
@@ -81,7 +81,7 @@
"@types/marked": "^0.6.1",
"@types/node": "~8.9.4",
"@types/prismjs": "^1.9.0",
"bootstrap": "4.0.0",
"bootstrap": "4.2.1",
Copy link
Member

Choose a reason for hiding this comment

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

Please don't forget to remove from this commit before merging. Same for yarn.lock changes

Copy link
Member Author

Choose a reason for hiding this comment

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

I am confused... this change is dependant on that. without bootstrap@4.2.1 toast won't work... I really don't like to bump this version in another commit...

Copy link
Member

Choose a reason for hiding this comment

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

I mean we have several other PRs waiting that need BS 4.2 or 4.3. We won't bump BS in all of them I guess.

Just wanted to have a separate commit/PR with the bump of dependencies. Locally when testing/reviewing it's not a problem to bump it manually.

src/toast/toast.scss Outdated Show resolved Hide resolved
src/toast/toast.scss Outdated Show resolved Hide resolved
src/toast/toast.ts Outdated Show resolved Hide resolved
src/toast/toast.scss Show resolved Hide resolved
src/toast/toast.spec.ts Outdated Show resolved Hide resolved

it('should emit hide output after default delay (500ms)', fakeAsync(() => {
const fixture = createTestComponent(`<ngb-toast header="header" (hide)="hide()">body</ngb-toast>`);
tick(500);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe check that is wasn't emitted before ? Same for the next test

@@ -0,0 +1,40 @@
import {Injectable} from '@angular/core';

export type AriaLiveValue = 'polite' | 'alert';
Copy link
Member

Choose a reason for hiding this comment

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

Don't see much utility in this type personally.

  • it is used only in this file
  • it makes documentation more complex

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed it, but I have to duplicate the type info for Typescript to be happy.
For example, I am not keen about ariaLive: 'polite' | 'alert' = 'polite'; either... but without it does not compile

Copy link
Member

Choose a reason for hiding this comment

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

The big upside for me would be the change in this:

Screen Shot 2019-05-28 at 10 27 22

It would just say type: 'polite' | 'alert'

@benouat
Copy link
Member Author

benouat commented May 28, 2019

@peterblazejewicz @fbasso @maxokorokov thanks to all of you for your reviews!
I have addressed all your comments, and just pushed again.

@maxokorokov @fbasso

  • I removed the weird part regarding autohide and close button.
  • I added a new demo to illustrate clicking on close. (and added a disclaimer to the first 2 demos clicking close won't do anything)
  • regarding the formatting stuff... I left it as it is, I really want to take 5.0-rc as an opportunity to clean up everything related to clang.
  • I removed the bootstrap bumping version from package.json

I'll open another PR to change slightly the big demo. I'll update the danger toast to be [autohide]="false" and only disappear when clicked on the body (to illustrate closing without using × and (hide))

@benouat benouat requested a review from maxokorokov May 28, 2019 09:23
@maxokorokov maxokorokov modified the milestones: 5.0, 5.0.0-rc.0 Jun 3, 2019
@benouat benouat merged commit bd1e9fb into ng-bootstrap:master Jun 24, 2019
mijohnsmith pushed a commit to mijohnsmith/ng-bootstrap that referenced this pull request Jun 27, 2019
Implementation of twbs/bootstrap##22980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants