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

[Toast] Add tone, actionOnComponent and leadingIcon props to Toast #11431

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

lone-star
Copy link
Contributor

@lone-star lone-star commented Jan 11, 2024

WHY are these changes introduced?

We would like to add more customisation to the current Toast component:

  • tone: this allows us to provide specific tones for styling.
  • actionOnComponent: this makes the whole component clickable instead of having a link inside
  • leadingIcon: we can use custom icons in the component.

WHAT is this pull request doing?

Magic tone

We can change the tone of the toast to magic

Screenshot 2024-01-11 at 20 19 45

Action on component

The whole component is now clickable.

action-on-component.mp4

Leading icon

In this example, we have both the magic tone, the leading icon, and the Action On Component

magic-leading-icon.mp4

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

🎩 checklist

@alex-page
Copy link
Member

alex-page commented Jan 14, 2024

@lone-star how can we consolidate error with your proposal for tone? I know this would be a breaking change but error does a lot of the features you want to suggest in this PR. Adds an icon, changes the color etc.

What is the timeline for this change and what priority is it? I would like to think a bit more about the existing toast functionality and how we can consolidate it with the new proposals.

@lone-star
Copy link
Contributor Author

Thanks for looking at the PR Alex!

You are exactly right, I decomposed the error UI changes in order to make them work for tone, so we would be able to consolidate the both with a tone=error|tone. Then with a leadingIcon={...}.

I left the error as is in order to keep things backward compatible, but we could change it.

The timelines for this are quite urgent. It would be good to have a resolution as soon as possible.

More context: Together with @sainihas and @jameswfindlater, we have been discussing the need for a different sort of notification component for Polaris. The Toast component is only used for ephemeral messages, and we would like to have more permanent notifications for the user. It is also important for those more permanent notifications to integrate well with the current Toast UI. For the moment we are introducing these changes, but we anticipate further iterations on the Toast component.

@elsom25
Copy link

elsom25 commented Jan 15, 2024

+1 this is a critical piece of the Taxonomy mission. I do think there'll be an evolved answer overtime as magic patterns are solidified more but this feels like a reasonable stepping stone (particularly given the decomposition).

@alex-page
Copy link
Member

alex-page commented Jan 15, 2024

Thanks @lone-star and @elsom25. Would there be any interest to do a follow up PRs to:

  1. Add error to tone as a non breaking change, deprecate error prop and create a migration for error to tone and leadingIcon
  2. In v13 branch remove error as a breaking change

It's a lot of work on our team to keep the library as small as it is meant to be. I am aligned with this change but don't want the follow up work to disappear. I understand you are moving fast but these consolidations are super important to stop our props bloating. Let me know.

@elsom25
Copy link

elsom25 commented Jan 15, 2024

It seems sensible to me if this feels worth a breaking change from your vantage-point. Magic-toning seems to be something that's propagating to many elements in polaris at this point so also feels broadly in-line (but I'll defer to @lone-star here)

@lone-star
Copy link
Contributor Author

@alex-page Happy to make those PRs, the direction seems clear and straightforward.

I've raised an issue here that contains the changes you requested: #11451 (not sure about the right labels)

Please let me know if there is anything else, then I'll fix the conflicts and update the current PR.

@heyjoethomas
Copy link
Contributor

  1. What is the TLDR UX for making the Toast clickable? Seems like a strange pattern to me. Is there a flow or general pattern documented/laid out somewhere?
  2. Would love to learn more about the needs for a more permanent notification type.

@alenaiouguina
Copy link

@heyjoethomas you can check out the prototype here to get a bit more context on the pattern and why we're introducing it for the taxonomy mission (magic autofill is a core experience of this new product). It also illustrates why there's a need for a more permanent toast for magic specifically within the context of winter editions launch.

We'll work with polaris team on the component for a persistent toast post-editions.

@lone-star lone-star force-pushed the ben/test-toast branch 2 times, most recently from 20edc4f to 077680e Compare January 18, 2024 11:17
@lone-star
Copy link
Contributor Author

Rebased to update with the icon changes.
Is there anything I can do to help this PR progress?

@alex-page
Copy link
Member

@lone-star I wanted to ask if this could be a wrapper with overrides in magic-ui? Does this feature need to be accessible to 3P developers? Just want to make sure we are adding to Polaris for the right reasons.

@lone-star
Copy link
Contributor Author

Thanks for your feedback Alex. Here are some of my investigation, as well as my understanding. Happy to be corrected if there are mistakes.

Could we use a separate component to display the magic messages?

I initially prototyped a separate component. Unfortunately the page that displays this component also uses the Polaris Toast. Since the Toast component uses a fixed positioning (similar to the component that I want to use), the two of them overlap.

The only way is therefore to integrate with the current Polaris Toast manager so that we don't have overlapping fixed components. I believe this to be true both for the proposed Magic toast (in this PR), and for the permanent component that @alenaiouguina is referring to here. Some pages already have overlaps between Toast and floating pills (ie: Variant Card, cc @sainihas). So we don't want to introduce yet another ugly UI. More so since we expect user actions to trigger both a magic Toast and a standard Toast in a closely timed manner. It's essential then for us to be able to stack toasts.

Could we integrate with the ToastManager with a wrapper?

There are 2 options there:

  • Using global selectors: In the current Toast API, is no way to differentiate a "Magic" toast from a Normal toast, other than the text content itself (I don't see any ID or way to manually select a specific toast in the DOM). Even if we could, we would need to completely update the DOM in order to build the UI.
  • Overriding the Frame component (that includes the ToastManager): 😨 I don't think that's an option.

Do we want to expose to 3P?

We are already exposing magic tones to 3P, and I expect us to expose this feature in the future (as for all the other magic UI elements). Since the Toast component itself is already being deprecated in favour of the AppBridge toast API, this won't change what 3P use in the immediate term. I assume that once we have had the opportunity to rework the feature we'll be able to expose it to 3P in AppBridge.

Copy link
Member

@chloerice chloerice left a comment

Choose a reason for hiding this comment

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

Hey @lone-star, thanks for contributing! The magic tone looks great ✨ I've provided detailed suggestions to simplify and align the API additions with the rest of the system.

@lone-star lone-star force-pushed the ben/test-toast branch 2 times, most recently from 8615bb6 to 3a0109c Compare January 22, 2024 12:35
@lone-star
Copy link
Contributor Author

Thank you for the feedback, I've updated the PR

Copy link
Contributor

@matallo matallo left a comment

Choose a reason for hiding this comment

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

Code and 🎩 (while pairing) LGTM! Minor non-blocking comments

<Icon source={AlertCircleIcon} tone="inherit" />
</div>
) : null;
let leadingIconMarkup;
Copy link
Contributor

Choose a reason for hiding this comment

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

these are quite similar, maybe stylistic but can we set it as a const but use the ternary in the source prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It actually makes readability more messy due to typescript:

With the following:

const leadingIconMarkup =
  error || icon ? (
    <div className={styles.LeadingIcon}>
      <Icon source={error ? AlertCircleIcon : icon} tone="inherit" />
    </div>
  ) : null;

Typescript will complain that the source prop cannot be undefined. That's because it is unable to pickup the logic where source=icon only if error is nullish and that means that icon is defined. The solution for this involves adding some additional conditionals, and that makes readability really bad because we get multiple levels of nested ternary. I'd rather have a let with 2 conditional, a single level of nesting and a bit of repetition.

@lone-star
Copy link
Contributor Author

/snapit

Copy link
Contributor

🫰✨ Thanks @lone-star! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/polaris-migrator@0.0.0-snapshot-release-20240124105023
yarn add @shopify/polaris@0.0.0-snapshot-release-20240124105023
yarn add @shopify/polaris-tokens@0.0.0-snapshot-release-20240124105023
yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20240124105023

Add the following options to the Toast component:
- tone
- onClick
- icon
@lone-star lone-star merged commit f9b9fa4 into main Jan 24, 2024
12 checks passed
@lone-star lone-star deleted the ben/test-toast branch January 24, 2024 21:21
chloerice pushed a commit that referenced this pull request Jan 26, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/polaris-icons@8.1.0

### Minor Changes

- [#11478](#11478)
[`b786bb93c`](b786bb9)
Thanks [@Rusty-UX](https://github.com/Rusty-UX)! - Added
DatabaseConnectIcon

## @shopify/polaris@12.11.0

### Minor Changes

- [#11474](#11474)
[`26b3afb3d`](26b3afb)
Thanks [@mrcthms](https://github.com/mrcthms)! - [BulkActions and
SelectAllActions] Ensure backwards compatibilility after prop
reorganisation between components


- [#11497](#11497)
[`d50cc6d91`](d50cc6d)
Thanks [@mrcthms](https://github.com/mrcthms)! - Improved test
reliability for non-rolled up actions in `ActionMenu`


- [#10981](#10981)
[`2dcc73f1a`](2dcc73f)
Thanks [@mrcthms](https://github.com/mrcthms)! - Updated the sticky
behaviour of BulkActions, SelectAllActions, and Pagination for our
tables and lists


- [#11441](#11441)
[`74174b6c1`](74174b6)
Thanks [@mrcthms](https://github.com/mrcthms)! - Improved the logic of
action rollup and calculation of available space in `ActionMenu` and
`Tabs`


- [#11491](#11491)
[`ac004fc97`](ac004fc)
Thanks [@lgriffee](https://github.com/lgriffee)! - [`Button`] Remove
underline from `monochromePlain` default state


- [#11486](#11486)
[`02a6d9b18`](02a6d9b)
Thanks
[@translation-platform](https://github.com/apps/translation-platform)! -
Updated translations for SearchField suffix within IndexFilters


- [#11344](#11344)
[`c9abd3c0c`](c9abd3c)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Added
Polaris Tokens for Mobile typography


- [#11412](#11412)
[`f1b44ab57`](f1b44ab)
Thanks [@mrcthms](https://github.com/mrcthms)! - [TextField] Updated the
TextField with new `autoSize` and `loading` props


- [#11431](#11431)
[`f9b9fa4e8`](f9b9fa4)
Thanks [@lone-star](https://github.com/lone-star)! - Added `tone`,
`icon`, and `onClick` props to `Toast`

### Patch Changes

- [#11464](#11464)
[`2ee7dbd30`](2ee7dbd)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Updated `Button`
shadow tokens and replaced hardcoded box-shadow values


- [#11504](#11504)
[`1910c6975`](1910c69)
Thanks [@mrcthms](https://github.com/mrcthms)! - Updated Page Header to
only ensure no wrapping of the title when the title is relatively short


- [#11473](#11473)
[`6579537e4`](6579537)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Fixed focus ring
size for plain and plain monochrome Button variants


- [#11487](#11487)
[`4aabf7c1a`](4aabf7c)
Thanks [@yurm04](https://github.com/yurm04)! - [Modal] Fixed Footer
position to bottom of container


- [#11466](#11466)
[`1953b6935`](1953b69)
Thanks [@mrcthms](https://github.com/mrcthms)! - [TextField] Fixed
positional issue of loading indicator when no clear button is present


- [#11462](#11462)
[`2febd60f1`](2febd60)
Thanks [@sophschneider](https://github.com/sophschneider)! - Lowered the
z-index of `Filter`s container to be below `Card` shadow bevel


- [#11467](#11467)
[`75cbcd70b`](75cbcd7)
Thanks [@kyledurand](https://github.com/kyledurand)! - Increased
contrast on Tooltip underline


- [#11482](#11482)
[`59371946c`](5937194)
Thanks
[@translation-platform](https://github.com/apps/translation-platform)! -
[SearchField] Updated translation

- Updated dependencies
\[[`2ee7dbd30`](2ee7dbd),
[`c9abd3c0c`](c9abd3c),
[`b786bb93c`](b786bb9)]:
    -   @shopify/polaris-tokens@8.6.0
    -   @shopify/polaris-icons@8.1.0

## @shopify/polaris-tokens@8.6.0

### Minor Changes

- [#11344](#11344)
[`c9abd3c0c`](c9abd3c)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Added
Polaris Tokens for Mobile typography

### Patch Changes

- [#11464](#11464)
[`2ee7dbd30`](2ee7dbd)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Updated `Button`
shadow tokens and replaced hardcoded box-shadow values

## @shopify/stylelint-polaris@15.1.0

### Minor Changes

- [#11344](#11344)
[`c9abd3c0c`](c9abd3c)
Thanks [@aaronccasanova](https://github.com/aaronccasanova)! - Updated
`typography` `declaration-property-value-disallowed-list` to support
Polaris Tokens `text` variants

### Patch Changes

- Updated dependencies
\[[`2ee7dbd30`](2ee7dbd),
[`c9abd3c0c`](c9abd3c)]:
    -   @shopify/polaris-tokens@8.6.0

## @shopify/polaris-migrator@0.27.1

### Patch Changes

- Updated dependencies
\[[`c9abd3c0c`](c9abd3c),
[`2ee7dbd30`](2ee7dbd),
[`c9abd3c0c`](c9abd3c)]:
    -   @shopify/stylelint-polaris@15.1.0
    -   @shopify/polaris-tokens@8.6.0

## polaris.shopify.com@0.62.0

### Minor Changes

- [#11506](#11506)
[`c19b0f638`](c19b0f6)
Thanks [@lgriffee](https://github.com/lgriffee)! - Added ability to mark
prop values as deprecated

### Patch Changes

- [#11457](#11457)
[`966d1901e`](966d190)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Added fallback to
no active icon on Icons page when not a valid icon name is used in the
search param


- [#11466](#11466)
[`1953b6935`](1953b69)
Thanks [@mrcthms](https://github.com/mrcthms)! - [TextField] Fixed
positional issue of loading indicator when no clear button is present


- [#11461](#11461)
[`d26df7eb0`](d26df7e)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Added deprecation
warning to old icon names informing users to use the new icon name


- [#11467](#11467)
[`75cbcd70b`](75cbcd7)
Thanks [@kyledurand](https://github.com/kyledurand)! - Increased
contrast on Tooltip underline

- Updated dependencies
\[[`26b3afb3d`](26b3afb),
[`2ee7dbd30`](2ee7dbd),
[`1910c6975`](1910c69),
[`d50cc6d91`](d50cc6d),
[`6579537e4`](6579537),
[`2dcc73f1a`](2dcc73f),
[`74174b6c1`](74174b6),
[`4aabf7c1a`](4aabf7c),
[`ac004fc97`](ac004fc),
[`1953b6935`](1953b69),
[`02a6d9b18`](02a6d9b),
[`c9abd3c0c`](c9abd3c),
[`2febd60f1`](2febd60),
[`b786bb93c`](b786bb9),
[`75cbcd70b`](75cbcd7),
[`f1b44ab57`](f1b44ab),
[`f9b9fa4e8`](f9b9fa4),
[`59371946c`](5937194)]:
    -   @shopify/polaris@12.11.0
    -   @shopify/polaris-tokens@8.6.0
    -   @shopify/polaris-icons@8.1.0

## polaris-for-vscode@0.9.4

### Patch Changes

- Updated dependencies
\[[`2ee7dbd30`](2ee7dbd),
[`c9abd3c0c`](c9abd3c)]:
    -   @shopify/polaris-tokens@8.6.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
AnnaCheba pushed a commit to AnnaCheba/polaris that referenced this pull request Apr 22, 2024
…hopify#11431)

<!--
  ☝️How to write a good PR title:
- Prefix it with [ComponentName] (if applicable), for example: [Button]
  - Start with a verb, for example: Add, Delete, Improve, Fix…
  - Give as much context as necessary and as little as possible
  - Open it as a draft if it’s a work in progress
-->

### WHY are these changes introduced?

We would like to add more customisation to the current Toast component:
- tone: this allows us to provide specific tones for styling.
- actionOnComponent: this makes the whole component clickable instead of
having a link inside
- leadingIcon: we can use custom icons in the component.

### WHAT is this pull request doing?

#### Magic tone

We can change the tone of the toast to `magic`

<img width="224" alt="Screenshot 2024-01-11 at 20 19 45"
src="https://github.com/Shopify/polaris/assets/78884/43f7809d-5348-425a-a4cc-3aaa797fffb8">

#### Action on component

The whole component is now clickable.


https://github.com/Shopify/polaris/assets/78884/56e06a79-8e37-40d9-becf-828e8aa5c9f0

#### Leading icon

In this example, we have both the magic tone, the leading icon, and the
Action On Component



https://github.com/Shopify/polaris/assets/78884/64ec9807-a340-472e-918d-d881c20d0172


### How to 🎩

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#install-dependencies-and-build-workspaces)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

### 🎩 checklist

- [x] Tested a
[snapshot](https://github.com/Shopify/polaris/blob/main/documentation/Releasing.md#-snapshot-releases)
- [x] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [x] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [x] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [x] Updated the component's `README.md` with documentation changes
- [x] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide
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.

8 participants