discourse/plugins/chat/test/javascripts/components
Joffrey JAFFEUX 2a10ea0e3f
DEV: FloatKit (#23650)
This PR introduces three new concepts to Discourse codebase through an addon called "FloatKit":

- menu
- tooltip
- toast


## Tooltips
### Component

Simple cases can be express with an API similar to DButton:

```hbs
<DTooltip 
  @Label={{i18n "foo.bar"}}
  @ICON="check"
  @content="Something"
/>
```

More complex cases can use blocks:

```hbs
<DTooltip>
  <:trigger>
   {{d-icon "check"}}
   <span>{{i18n "foo.bar"}}</span>
  </:trigger>
  <:content>
   Something
  </:content>
</DTooltip>
```

### Service

You can manually show a tooltip using the `tooltip` service:

```javascript
const tooltipInstance = await this.tooltip.show(
  document.querySelector(".my-span"),
  options
)

// and later manual close or destroy it
tooltipInstance.close();
tooltipInstance.destroy();

// you can also just close any open tooltip through the service
this.tooltip.close();
```

The service also allows you to register event listeners on a trigger, it removes the need for you to manage open/close of a tooltip started through the service:

```javascript
const tooltipInstance = this.tooltip.register(
  document.querySelector(".my-span"),
  options
)

// when done you can destroy the instance to remove the listeners
tooltipInstance.destroy();
```

Note that the service also allows you to use a custom component as content which will receive `@data` and `@close` as args:

```javascript
const tooltipInstance = await this.tooltip.show(
  document.querySelector(".my-span"),
  { 
    component: MyComponent,
    data: { foo: 1 }
  }
)
```

## Menus

Menus are very similar to tooltips and provide the same kind of APIs:

### Component

```hbs
<DMenu @ICON="plus" @Label={{i18n "foo.bar"}}>
  <ul>
    <li>Foo</li>
    <li>Bat</li>
    <li>Baz</li>
  </ul>
</DMenu>
```

They also support blocks:

```hbs
<DMenu>
  <:trigger>
    {{d-icon "plus"}}
    <span>{{i18n "foo.bar"}}</span>
  </:trigger>
  <:content>
    <ul>
      <li>Foo</li>
      <li>Bat</li>
      <li>Baz</li>
    </ul>
  </:content>
</DMenu>
```

### Service

You can manually show a menu using the `menu` service:

```javascript
const menuInstance = await this.menu.show(
  document.querySelector(".my-span"),
  options
)

// and later manual close or destroy it
menuInstance.close();
menuInstance.destroy();

// you can also just close any open tooltip through the service
this.menu.close();
```

The service also allows you to register event listeners on a trigger, it removes the need for you to manage open/close of a tooltip started through the service:

```javascript
const menuInstance = this.menu.register(
   document.querySelector(".my-span"),
   options
)

// when done you can destroy the instance to remove the listeners
menuInstance.destroy();
```

Note that the service also allows you to use a custom component as content which will receive `@data` and `@close` as args:

```javascript
const menuInstance = await this.menu.show(
  document.querySelector(".my-span"),
  { 
    component: MyComponent,
    data: { foo: 1 }
  }
)
```


## Toasts

Interacting with toasts is made only through the `toasts` service.

A default component is provided (DDefaultToast) and can be used through dedicated service methods:

- this.toasts.success({ ... });
- this.toasts.warning({ ... });
- this.toasts.info({ ... });
- this.toasts.error({ ... });
- this.toasts.default({ ... });

```javascript
this.toasts.success({
  data: {
    title: "Foo",
    message: "Bar",
    actions: [
      {
        label: "Ok",
        class: "btn-primary",
        action: (componentArgs) => {
          // eslint-disable-next-line no-alert
          alert("Closing toast:" + componentArgs.data.title);
          componentArgs.close();
        },
      }
    ]
  },
});
```

You can also provide your own component:

```javascript
this.toasts.show(MyComponent, {
  autoClose: false,
  class: "foo",
  data: { baz: 1 },
})
```

Co-authored-by: Martin Brennan <mjrbrennan@gmail.com>
Co-authored-by: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com>
Co-authored-by: David Taylor <david@taylorhq.com>
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
2023-09-26 13:39:52 +02:00
..
chat-channel-card-test.js DEV: various improvements to devex on chat (#21612) 2023-05-17 17:49:52 +02:00
chat-channel-leave-btn-test.js DEV: various improvements to devex on chat (#21612) 2023-05-17 17:49:52 +02:00
chat-channel-metadata-test.js DEV: Add last_message_id to channel and thread (#22488) 2023-07-13 10:28:11 +10:00
chat-channel-preview-card-test.js DEV: various improvements to devex on chat (#21612) 2023-05-17 17:49:52 +02:00
chat-channel-row-test.js DEV: Add last_message_id to channel and thread (#22488) 2023-07-13 10:28:11 +10:00
chat-channel-settings-saved-indicator-test.js FEATURE: channels can allow/disallow @all/@here mentions (#19317) 2022-12-05 17:03:51 +01:00
chat-channel-settings-view-test.js REFACTOR: channel retention reminder text (#20310) 2023-02-15 14:50:01 +01:00
chat-channel-status-test.js DEV: various improvements to devex on chat (#21612) 2023-05-17 17:49:52 +02:00
chat-channel-test.js DEV: FloatKit (#23650) 2023-09-26 13:39:52 +02:00
chat-channel-title-test.js Revert "FIX: correctly respects full name settings in channel title (#22566)" (#22569) 2023-07-12 18:46:19 +02:00
chat-composer-dropdown-test.js DEV: Modernize chat's component tests (#19577) 2022-12-22 14:35:18 +01:00
chat-composer-message-details-test.js DEV: various improvements to devex on chat (#21612) 2023-05-17 17:49:52 +02:00
chat-composer-placeholder-test.js UX: improves composer and thread panel (#21210) 2023-04-25 10:23:03 +02:00
chat-composer-upload-test.js UX: improves composer and thread panel (#21210) 2023-04-25 10:23:03 +02:00
chat-composer-uploads-test.js DEV: Correct the app-events service injections (#21413) 2023-05-08 10:48:56 +02:00
chat-emoji-avatar-test.js DEV: Modernize chat's component tests (#19577) 2022-12-22 14:35:18 +01:00
chat-emoji-picker-test.js FIX: relies on native focus behavior in chat emoji picker (#21092) 2023-04-13 20:35:13 +02:00
chat-header-icon-test.js UX: hides header's unread indicator on full page (#23370) 2023-09-02 12:06:40 +02:00
chat-message-avatar-test.js REFACTOR: <ChatMessage> component (#22172) 2023-06-19 09:50:54 +02:00
chat-message-collapser-test.js DEV: Remove lazy-yt and replace with lazy-videos (#20722) 2023-03-29 11:54:25 -04:00
chat-message-info-test.js REFACTOR: <ChatMessage> component (#22172) 2023-06-19 09:50:54 +02:00
chat-message-left-gutter-test.js REFACTOR: <ChatMessage> component (#22172) 2023-06-19 09:50:54 +02:00
chat-message-reaction-test.js DEV: Refactoring chat message actions for ChatMessage component usage in thread panel (#20756) 2023-04-06 15:19:52 +02:00
chat-message-separator-date-test.js FEATURE: Scroll to first message when clicking date in chat (#21926) 2023-06-20 15:58:38 +02:00
chat-message-separator-new-test.js DEV: rework the chat-live-pane (#20519) 2023-03-03 13:09:25 +01:00
chat-message-test.js REFACTOR: <ChatMessage> component (#22172) 2023-06-19 09:50:54 +02:00
chat-message-text-test.js DEV: Remove lazy-yt and replace with lazy-videos (#20722) 2023-03-29 11:54:25 -04:00
chat-modal-archive-channel-test.js DEV: makes chat modals use the new <DModal /> component (#22495) 2023-07-10 13:43:33 +02:00
chat-modal-delete-channel-test.js DEV: makes chat modals use the new <DModal /> component (#22495) 2023-07-10 13:43:33 +02:00
chat-modal-move-message-to-channel-test.js DEV: makes chat modals use the new <DModal /> component (#22495) 2023-07-10 13:43:33 +02:00
chat-notices-test.js DEV: Use Notice API for mention warnings (#23238) 2023-09-01 09:07:23 -05:00
chat-replying-indicator-test.js DEV: various improvements to devex on chat (#21612) 2023-05-17 17:49:52 +02:00
chat-retention-reminder-test.js DEV: rework the chat-live-pane (#20519) 2023-03-03 13:09:25 +01:00
chat-retention-reminder-text-test.js DEV: various improvements to devex on chat (#21612) 2023-05-17 17:49:52 +02:00
chat-thread-participants-test.js UX: hides original message user in thread participants (#23350) 2023-08-31 14:46:37 +02:00
chat-upload-test.js FEATURE: Inline audio player for chat uploads (#20175) 2023-02-06 16:00:03 +10:00
chat-user-avatar-test.js FIX: makes chat user avatar show presence by default (#22490) 2023-07-10 09:36:20 +02:00
chat-user-card-button-test.js DEV: makes user-card-chat-button uses glimmer (#22496) 2023-07-10 14:04:26 +02:00
chat-user-display-name-test.js DEV: Modernize chat's component tests (#19577) 2022-12-22 14:35:18 +01:00
chat-user-info-test.js FIX: Chat member user card rendered out of view (#20332) 2023-02-17 10:14:00 -03:00
collapser-test.js DEV: Modernize chat's component tests (#19577) 2022-12-22 14:35:18 +01:00
dc-filter-input-test.js DEV: Modernize chat's component tests (#19577) 2022-12-22 14:35:18 +01:00