discourse/app/assets/stylesheets/common/base
Joffrey JAFFEUX 0623ac684a
DEV: FloatKit (#23541)
Second iteration of https://github.com/discourse/discourse/pull/23312 with a fix for embroider not resolving an export file using .gjs extension.

---

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-12 15:50:26 +02:00
..
_index.scss DEV: FloatKit (#23541) 2023-09-12 15:50:26 +02:00
_topic-list.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
about.scss
activation.scss DEV: Use more css vars (#18561) 2022-10-12 16:05:42 +02:00
alert.scss UX: highlight vars updates (#20346) 2023-02-21 10:15:49 +01:00
bbcode.scss
cat_reorder.scss
category-list.scss FIX: add category colors back to categories pages (#21977) 2023-06-07 12:57:10 -04:00
code_highlighting.scss UX: update hljs-builtin-name highlight (#16859) 2022-05-18 15:55:40 +02:00
colorpicker.scss
compose.scss UX: fix tag chooser width when there are multiple tags (#23432) 2023-09-06 16:01:03 +05:30
composer-user-selector.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
crawler_layout.scss UX: Style edits (#19927) 2023-02-15 11:02:16 -06:00
d-icon.scss
d-image-grid.scss UX: Better alignment for experimental grids (#22066) 2023-06-13 09:25:46 -04:00
dialog.scss REFACTOR: move shadow vars to css custom props (#22094) 2023-06-13 16:38:31 -04:00
directory.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
discourse.scss DEV: Move theme-error-handler initializer to service (#23534) 2023-09-12 14:07:03 +01:00
edit-category.scss DEV: Apply form template to categories (#20337) 2023-02-23 11:18:14 -08:00
edit-topic-timer-modal.scss DEV: Convert edit-topic-timer modal to component-based API (#23252) 2023-08-25 12:17:34 -05:00
ember-select.scss
emoji.scss UX: improve emoji alignment for text (#19815) 2023-01-30 14:07:08 +01:00
empty-state.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
exception.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
explain-reviewable.scss
faqs.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
group.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
groups.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
header.scss UX: remove boostrap mode rounded corners (#23132) 2023-08-17 14:59:45 -06:00
history.scss DEV: Convert theme-change modal to component-based API (#22964) 2023-08-03 15:01:40 -05:00
lightbox.scss UX: remove rounded border on hover lightbox (#22080) 2023-06-13 13:31:28 +02:00
login.scss DEV: Don't render header on invites page (#22138) 2023-06-16 09:42:00 +08:00
magnific-popup.scss UX: force long filenames to wrap in lightbox (#22091) 2023-06-13 13:34:14 -04:00
menu-panel.scss FIX: Adjust border-radius in multiple locations (#23278) 2023-08-25 16:09:18 -05:00
modal.scss UX: fix bookmark modal footer layout (#22766) 2023-07-25 06:42:29 +08:00
new-user.scss DEV: Refactor GroupNotificationsButton into userPrivateMessages.group route (#21930) 2023-06-07 06:22:50 +08:00
not-found.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
onebox.scss FIX: add mobile specific stylesheet for onebox (#23329) 2023-08-31 10:35:28 +10:00
personal-message.scss FEATURE: control topic width with variables (#18743) 2022-10-25 14:45:37 -04:00
popup-menu.scss REFACTOR: move shadow vars to css custom props (#22094) 2023-06-13 16:38:31 -04:00
redirection.scss DEV: Use more css vars (#18561) 2022-10-12 16:05:42 +02:00
request_access.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
request-group-membership-form.scss
reviewables.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
rtl.scss FEATURE: Serve RTL versions of admin and plugins CSS bundles for RTL locales (#21876) 2023-06-01 05:27:11 +03:00
search-menu.scss DEV: FloatKit (#23541) 2023-09-12 15:50:26 +02:00
search.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
share_link.scss UX: Move post date under title in share-modal (#16455) 2022-04-27 16:36:08 +03:00
shared-drafts.scss
sidebar-custom-section.scss UX: visual indicator for reorder sidebar links mode (#22379) 2023-07-04 09:56:52 +10:00
sidebar-footer.scss FIX: restore sidebar footer background (#21956) 2023-06-06 14:46:08 -04:00
sidebar-more-section-links.scss UX: Remove section heading for community section (#22405) 2023-07-11 09:40:37 +08:00
sidebar-section-link.scss UX: Remove section heading for community section (#22405) 2023-07-11 09:40:37 +08:00
sidebar-section.scss DEV: FloatKit (#23541) 2023-09-12 15:50:26 +02:00
sidebar.scss DEV: FloatKit (#23541) 2023-09-12 15:50:26 +02:00
static-login.scss REFACTOR: move shadow vars to css custom props (#22094) 2023-06-13 16:38:31 -04:00
tagging.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
tooltip.scss REFACTOR: move shadow vars to css custom props (#22094) 2023-06-13 16:38:31 -04:00
topic-admin-menu.scss A11Y: Use button in d-modal-cancel component (#17938) 2022-08-17 09:39:28 +08:00
topic-post.scss DEV: FloatKit (#23541) 2023-09-12 15:50:26 +02:00
topic-summary.scss Revert "UX: Simplify and redesign summary skeleton (#22965)" (#23012) 2023-08-08 07:55:37 -05:00
topic.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
upload.scss
user-badges.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
user-tips.scss DEV: FloatKit (#23541) 2023-09-12 15:50:26 +02:00
user.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00