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

Add basic Toast component #487

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

willm0602
Copy link

Adds a basic version of a toast component that wraps Notifications and includes them on the bottom

Wanted to also leave a couple of notes before this gets merged

  • I wasn't able to find any tests for components specifically in the codebase. Is there anywhere I can add these before we merge these?
  • When I was testing this out, I wasn't able to initially since I got an issue, 'TZ' is not recognized as an internal or external command, operable program or batch file. I modified the test script in package.json to be SET TZ=UTC+4 vitest and that let the test suite run, but failed on six-issues, not sure if it's an issue with developing on windows OS

chrome_7oGfLfmPJR

Copy link

stackblitz bot commented Sep 21, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented Sep 21, 2024

🦋 Changeset detected

Latest commit: e26bfa3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-ux Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Sep 21, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
svelte-ux ✅ Ready (View Log) Visit Preview e26bfa3

@techniq
Copy link
Owner

techniq commented Sep 22, 2024

I wasn't able to find any tests for components specifically in the codebase. Is there anywhere I can add these before we merge these?

I currently only have vitest setup for unit tests (mostly utils, example format.test.ts).

I would like to setup playwright for integration/browser tests and integrated into the CI pipeline, similar to shadcn-svelte and melt-ui's setup, but haven't had the time to tackle it yet. If that is an initiative you would like to get started, I would kindly review a PR 😁

When I was testing this out, I wasn't able to initially since I got an issue, 'TZ' is not recognized as an internal or external command, operable program or batch file. I modified the test script in package.json to be SET TZ=UTC+4 vitest and that let the test suite run, but failed on six-issues, not sure if it's an issue with developing on windows OS

Sadly most of the development occurs on Mac and thus a unix environment (and usually zsh or bash terminal). With that said, one of our contributors was using Windows and leveraging the WSL (he actually was the one to add the timezone environment variable, although he also switched to Mac later on).

I don't hear of much Windows open source development happening without using WSL nowadays, but I'm also pretty detached from that ecosystem (switched to Mac 10+ years ago).

If you're not using WSL, I would recommend setting it up and see if you have a better experience.

Copy link
Owner

@techniq techniq left a comment

Choose a reason for hiding this comment

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

@willm0602 Thanks for the PR!

I left some notes, some of which might not be worth addressing in this PR, but thought it was helpful to put my thoughts down to see what future improvements, etc.

Other ideas we chatted about in Discord (putting here to more easily track) were:

  • When you pointerover a notification, we should stop the timeout and on pointerout we start/resume in case you are interacting with it (or just needed more time to read the message
  • Consider integrating Progress / ProgressCircle to show the countdown (probably best when we add the variant support)

@@ -0,0 +1,5 @@
---
'svelte-ux': minor
Copy link
Owner

Choose a reason for hiding this comment

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

If you do not select any packages when prompted for major and minor, it will produce a patch changeset (I think the flow is a little odd to be honest, but that's driven by the changesets project).

The flow is different when using changesets in a multi-package monorepo (like Svelte UX)...

image

vs a single-package repo (like LayerChart at the moment)...

image

The single package is much more straight forward.
At some point LayerChart might become multi-package.

Copy link
Owner

Choose a reason for hiding this comment

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

With that said you can manually edit this .md file and just change minor to patch (all the CLI does is help you write this file, including generating a filename)

Comment on lines 5 to 8
export type Toast = {
text: string;
timeAdded: Date;
};
Copy link
Owner

Choose a reason for hiding this comment

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

Not to feature creep this too much, but also consider a little bit more future state, I'm thinking the the type could be:

export type Toast = {
  title: string;
  description?: string;
  actions?: Record<string, Function>; // this will need more thought to support primary styling, etc
  icon?: IconInput;
  variant?: string;
  timeAdded: Date;
};

variant would need to wait til #86 is tackled, but it's not a big lift (mostly just taking the styles from the doc examples. See ToggleGroup for a semi-related example (there are other components with variant as well).

image

*/
const toastStore = writable<Toast[]>([]);

export function addToast(text: string, durationInMS = DEFAULT_TOAST_TIME_IN_MS) {
Copy link
Owner

Choose a reason for hiding this comment

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

We would want to change text: string into an object to support the various additional inputs (description, icon, actions, etc)

import Notification from './Notification.svelte';
</script>

<div class="fixed bottom-0 left-1/2 translate-x-[-50%] z-50 gap-y-4">
Copy link
Owner

Choose a reason for hiding this comment

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

I could see us adding a placement prop to control which of the 8 corners/edges to place the notifications (at least top-left, top, top-right, bottom-left, bottom, bottom-right).

you can see some examples of this in Drawer and Badge

Copy link
Owner

Choose a reason for hiding this comment

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

It would also be good if Toast supported class overrides, either directly (<Toast classes={...}>) or via settings.

To support this, you would need to add a classes prop and also getting the classes defined in settings(...) using...

<script>
  ...

  export let classes: {
    root?: string;
    actions?: string;
    // ...any other internal element/component you might want to pass a class to
  } = {};
  const settingsClasses = getComponentClasses('Toast');
</script>

and change...

<div class="fixed bottom-0 left-1/2 translate-x-[-50%] z-50 gap-y-4">

to

<div
    class={cls(
      'Toast',
      'fixed bottom-0 left-1/2 translate-x-[-50%] z-50 gap-y-4',
      settingsClasses.root,
      classes.root,
      $$props.class
    )}
>

@techniq
Copy link
Owner

techniq commented Sep 22, 2024

Few other ideas I forgot to mention. It might make sense to put an instance of the toastStore in settings() like we do for themes, locales, nav drawer, etc. We could also consider adding an instance of <Toast> within <AppLayout> wired up to this instance.

@willm0602
Copy link
Author

@techniq started working on the changes and got an issue where I can't get the toasters to appear over the elements of the app layout that used fixed position (so the side and topnav) even after adjusting the z-indexes

image

Was wondering if you had any ideas for fixing this?

@techniq
Copy link
Owner

techniq commented Sep 25, 2024

@techniq started working on the changes and got an issue where I can't get the toasters to appear over the elements of the app layout that used fixed position (so the side and topnav) even after adjusting the z-indexes

image Was wondering if you had any ideas for fixing this?

Modal elements like Drawer and Dialog "portal" their content to the bottom of <body> via the portal action and doing similar within Notification should solve the issue.

@techniq
Copy link
Owner

techniq commented Oct 4, 2024

@willm0602 I started work on improving/simplifying the Notification component by support props (not requiring but still supporting slots) such as <Notification title="..." description="..." actions={...}> and also supporting color/variant/etc props. Take a look at the PR preview.

I also have a PR to use @layerstack/* packages for most all svelte stores/actions/etc. I'll plan to merge these hopefully in the next few days (the later is a much bigger change).

This will impact your PR some, but not sure where toastStore should live just yet (it's rather tied to Svelte UX Toast/Notification and not sure it makes much sense to be within @layerstack/*. In some ways I think of it similar to AppBar/AppLayout/NavItem and their use of showDrawer within settings.

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.

2 participants