discourse/app/assets/stylesheets/common/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
..
sidebar/edit-navigation-menu UX: align tags to top in modal (#23055) 2023-08-10 10:26:25 +02:00
_index.scss DEV: FloatKit (#23650) 2023-09-26 13:39:52 +02:00
add-pm-participants.scss DEV: Upgrade the so-called share-and-invite modal (#23574) 2023-09-14 10:50:50 +02:00
admin-post-menu.scss DEV: FloatKit (#23650) 2023-09-26 13:39:52 +02:00
badges.scss FIX: Adjust badge overflow ellipsis (#23086) 2023-08-14 11:10:02 -05:00
banner.scss UX: Styling changes to global banner (#16191) 2022-03-15 16:19:55 +01:00
bookmark-list.scss DEV: Use more css vars (#18561) 2022-10-12 16:05:42 +02:00
bookmark-modal.scss UX: fix bookmark modal footer layout (#22766) 2023-07-25 06:42:29 +08:00
buttons.scss DEV: FloatKit (#23650) 2023-09-26 13:39:52 +02:00
calendar-date-time-input.scss DEV: Move calendar date + time picker from local dates into core component (#23023) 2023-08-11 13:05:44 +10:00
char-counter.scss FEATURE: Add word count and indicator when exceeded max (#19367) 2023-02-20 12:06:43 +01:00
color-input.scss FEATURE: Use native color-picker (#15748) 2022-02-01 11:18:13 -03:00
conditional-loading-section.scss A11Y: disable non-essential CSS animations for reduced-motion users (#23571) 2023-09-14 17:31:43 -04:00
convert-to-public-topic-modal.scss
d-lightbox.scss A11Y: disable non-essential CSS animations for reduced-motion users (#23571) 2023-09-14 17:31:43 -04:00
d-toggle-switch.scss A11Y: Improvements to <DToggleSwitch/> component (#23514) 2023-09-11 11:26:41 -07:00
date-input.scss UX: Fix date input icon display issues (#14369) 2021-09-17 12:07:10 -04:00
date-picker.scss UX: Normalize sizing for inputs, buttons, dropdowns (#14226) 2021-09-09 11:01:56 -04:00
date-time-input-range.scss UX: Normalize sizing for inputs, buttons, dropdowns (#14226) 2021-09-09 11:01:56 -04:00
date-time-input.scss UX: Normalize sizing for inputs, buttons, dropdowns (#14226) 2021-09-09 11:01:56 -04:00
download-calendar.scss DEV: FloatKit (#23650) 2023-09-26 13:39:52 +02:00
footer-nav.scss REFACTOR: move shadow vars to css custom props (#22094) 2023-06-13 16:38:31 -04:00
form-template-field.scss UX: fix form template error label position (#23208) 2023-08-24 11:09:47 -03:00
group-member-dropdown.scss DEV: Set containing block for Popper dropdowns (#20745) 2023-03-20 15:26:20 -04:00
groups-form-membership-fields.scss
hashtag.scss FIX: Add hashtag placeholder when chat message sent (#23287) 2023-08-30 11:31:34 +10:00
horizontal-overflow-nav.scss UX: move vertical admin plugin nav to horizontal overflow nav (#20319) 2023-02-17 10:21:30 -05:00
iframed-html.scss Merge pull request from GHSA-vw39-6w7q-gfx5 2020-02-27 11:47:15 -06:00
ignored-user-list.scss UX: fix color preference layout (#21346) 2023-05-03 10:11:52 +08:00
keyboard_shortcuts.scss Revert "A11Y: Improve setting focus to post" (#23311) 2023-08-29 09:24:16 -04:00
more-topics.scss FIX: Remove border radius on more topics container buttons: (#23314) 2023-08-29 12:02:38 -05:00
navs.scss FIX: Adjust border-radius in multiple locations (#23278) 2023-08-25 16:09:18 -05:00
offline-indicator.scss FEATURE: Offline indicator (#21369) 2023-06-05 11:08:04 -05:00
pick-files-button.scss DEV: add pick-files-button component (#13764) 2021-07-16 21:50:50 +04:00
relative-time-picker.scss UX: Fix local-dates styling (#12085) 2021-02-15 10:44:30 +00:00
svg.scss DEV: Remove xlink hrefs (#15059) 2021-11-25 15:22:43 +11:00
tap-tile.scss UX: highlight vars updates (#20346) 2023-02-21 10:15:49 +01:00
time-input.scss FEATURE: automatic dark mode (#10341) 2020-08-03 22:57:10 -04:00
time-shortcut-picker.scss UX: fix time pickers input width on mobile (#21170) 2023-04-19 10:08:24 -05:00
topic-query-filter.scss UX: Make input on /filter route full width (#20952) 2023-04-04 14:10:39 +10:00
user-card.scss DEV: FloatKit (#23650) 2023-09-26 13:39:52 +02:00
user-info.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
user-status-message.scss DEV: FloatKit (#23650) 2023-09-26 13:39:52 +02:00
user-status-picker.scss FEATURE: user status emoji (#17025) 2022-06-22 18:15:33 +04:00
user-stream-item.scss DEV: common CSS property for content backgrounds (#23467) 2023-09-08 12:07:04 -04:00
user-stream.scss UX: remove unneeded margin from user stream (#11964) 2021-02-04 14:39:43 +11:00
widget-dropdown.scss REFACTOR: improve poll info layout (#22353) 2023-07-05 12:20:18 -04:00