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): add icon property to show icon at start of toast content #23596

Merged
merged 10 commits into from
Jul 23, 2021

Conversation

domske
Copy link
Contributor

@domske domske commented Jul 8, 2021

Pull request checklist

fixes #23524

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

The toast does not allow to display an icon.

What is the new behavior?

You can now optionally specify an icon to show with the toast message.

md

demo-md

ios

demo-ios

Does this introduce a breaking change?

  • Yes
  • No

Other information

I added linter ignore blacklist property comment to allow padding and margin-left. Feel free to change it. I don't know what you prefer.

Should be available in Ionic 5.x

@github-actions github-actions bot added the package: core @ionic/core package label Jul 8, 2021
@EinfachHans
Copy link
Contributor

Maybe better to use icon instead of name Property to allow custom icons?

@domske
Copy link
Contributor Author

domske commented Jul 11, 2021

@EinfachHans

You can already use custom icons with the name attribute.
Just place your svg icons to the Ionic icons svg build folder and you can easily use both (build-in and custom icons) as name.

For example in Angular. You can automatically copy your custom icons with the build.

angular.json

projects {} > app {} > architect {} > build {} > options {} > assets []:

{
  "glob": "**/*.svg",
  "input": "src/assets/custom-icons",
  "output": "./svg"
}

Place e.g. an icon like custom-my-icon.svg to your src assets and you can use the ion-icon (or the toast icon prop) like:

<ion-icon name="custom-my-icon"></ion-icon>

We could replace name with the icon prop. But does it also work with my solution above? I have to test it... Because I use the name solution. It's nicer (names) than src-paths.

Icon Source

We probably should also complete the ion-icon documentation. Because I cannot find the icon prop.
Only in the source code. See docs.

@EinfachHans
Copy link
Contributor

As far as i understand the icon prop could also take for example "assets/..." and determinates if its a asset icon or ionicon. Also the toast button icon uses the icon Property

@domske
Copy link
Contributor Author

domske commented Jul 11, 2021

Ok I replaced the name property with icon. Not yet tested in productive app. But I think it will work since the button icon also uses this property. Tests passed.

Copy link
Contributor

@liamdebeasi liamdebeasi 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 the PR! I have included comments regarding changes which are required in order for this feature to get merged.

Additionally, can you please add some usage examples in the usage directory? You will need to update the angular.md, javascript.md, react.md, stencil.md, and vue.md files, run npm run build, and then push that result.

I think we can add the icon example inside of the existing presentToastWithOptions function in these usage files.

core/src/components/toast/toast.scss Show resolved Hide resolved
Comment on lines 124 to 130
/* stylelint-disable property-blacklist */
margin-left: 15px;

padding: 10px;
/* stylelint-enable property-blacklist */

font-size: 1.4em;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/* stylelint-disable property-blacklist */
margin-left: 15px;
padding: 10px;
/* stylelint-enable property-blacklist */
font-size: 1.4em;
@include margin(0, 0, 0, 15px);
@include padding(10px, 10px, 10px, 10px);

We need to include the mixins here to account for RTL mode. Currently, the styles are not consistent between LTR and RTL modes, but the mixins will handle this switch for us.

Also, no need to add the font size here as it should apply in the same block as .toast-button-icon (see my other comment)

core/src/components/toast/toast.tsx Outdated Show resolved Hide resolved
core/src/components/toast/toast.tsx Outdated Show resolved Hide resolved
core/src/components/toast/toast.tsx Outdated Show resolved Hide resolved
@liamdebeasi liamdebeasi changed the title feat(toast): optional toast icon feat(toast): add icon property to show icon at start of toast content Jul 20, 2021
@liamdebeasi liamdebeasi changed the base branch from main to next July 20, 2021 16:40
@liamdebeasi liamdebeasi changed the base branch from next to main July 20, 2021 16:40
@domske
Copy link
Contributor Author

domske commented Jul 20, 2021

Ok, change requests pushed...

I just wonder:

  • Why this.icon on the first line? It's a simple short path and equal to the the other properties like this.message and this.header. It's the same style. (Not yet changed.)

  • Why lazy={false} and not lazy="false" since aria-hidden="true"? Ok, the type is different (boolean and string) but does this matter here?

Nothing important. I'm just wondering.

@liamdebeasi
Copy link
Contributor

Sorry I had two different PRs open and was referencing the wrong one 🤦 . Ignore the this.icon comment.

The ariaHidden property expects a string: https://github.com/ionic-team/ionicons/blob/master/src/components/icon/icon.tsx#L38
But the lazy property expects a boolean: https://github.com/ionic-team/ionicons/blob/master/src/components/icon/icon.tsx#L82

Since the ariaHidden property eventually gets set as the aria-hidden attribute, we need to accept a string since the aria-hidden attribute cannot accept a boolean (it's just plain HTML at that point)

@domske
Copy link
Contributor Author

domske commented Jul 20, 2021

Ok, please let me know if there are any pending change requests. All change requests were implemented. Or did I miss something?

Copy link
Contributor

@willmartian willmartian left a comment

Choose a reason for hiding this comment

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

Looks good! Just a small docs change from me to reflect the switch from name to icon.

core/src/components/toast/toast.tsx Outdated Show resolved Hide resolved
@liamdebeasi liamdebeasi changed the base branch from main to next July 23, 2021 15:26
Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

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

Great job! We are good to merge when the tests finish.

@liamdebeasi liamdebeasi merged commit df24c8c into ionic-team:next Jul 23, 2021
@liamdebeasi
Copy link
Contributor

Merged. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: toast with icon
4 participants