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 19:39:52 +08:00
|
|
|
[data-content][data-identifier="card"] {
|
|
|
|
z-index: z("max");
|
|
|
|
}
|
|
|
|
|
2019-03-25 20:37:17 +08:00
|
|
|
// shared styles for user and group cards
|
2020-02-13 17:58:17 +08:00
|
|
|
.user-card,
|
|
|
|
.group-card {
|
2019-03-25 20:37:17 +08:00
|
|
|
max-width: 95vw;
|
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 19:39:52 +08:00
|
|
|
margin: 0;
|
2020-08-24 18:02:40 +08:00
|
|
|
max-height: 85vh; // 2.5vh margin-top and margin-bottom. 10vh top
|
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 19:39:52 +08:00
|
|
|
box-sizing: border-box;
|
2019-03-25 20:37:17 +08:00
|
|
|
// avatar - names - controls
|
|
|
|
.first-row {
|
|
|
|
flex-wrap: wrap;
|
|
|
|
.names {
|
2024-08-07 05:47:59 +08:00
|
|
|
flex: 1 1 0;
|
2019-03-25 20:37:17 +08:00
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
2023-06-01 23:17:44 +08:00
|
|
|
.user-card-avatar {
|
|
|
|
flex: 0 0 auto;
|
|
|
|
}
|
2019-03-25 20:37:17 +08:00
|
|
|
.usercard-controls {
|
2023-06-01 23:17:44 +08:00
|
|
|
width: 100%; // always wraps to next line
|
2019-03-25 20:37:17 +08:00
|
|
|
display: flex;
|
2021-04-21 06:34:33 +08:00
|
|
|
flex-wrap: wrap;
|
2023-11-15 06:13:37 +08:00
|
|
|
margin-top: 1em;
|
|
|
|
gap: 0.5em;
|
2019-03-25 20:37:17 +08:00
|
|
|
li {
|
2023-11-15 06:13:37 +08:00
|
|
|
flex: 1 0 45%;
|
|
|
|
min-width: 8em;
|
2020-06-13 04:24:25 +08:00
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
2019-03-31 17:16:40 +08:00
|
|
|
button {
|
2023-11-15 06:13:37 +08:00
|
|
|
margin: 0;
|
|
|
|
.d-button-label {
|
|
|
|
@include ellipsis;
|
|
|
|
}
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-17 00:32:53 +08:00
|
|
|
.names__primary {
|
2022-10-12 21:31:59 +08:00
|
|
|
font-size: var(--font-up-3);
|
2019-03-25 20:37:17 +08:00
|
|
|
.d-icon {
|
2022-10-12 21:31:59 +08:00
|
|
|
font-size: var(--font-down-2);
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|
|
|
|
}
|
2024-07-17 00:32:53 +08:00
|
|
|
.names__secondary {
|
2022-10-12 21:31:59 +08:00
|
|
|
font-size: var(--font-0);
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|
2024-07-17 00:32:53 +08:00
|
|
|
.user-status {
|
2022-10-12 21:31:59 +08:00
|
|
|
font-size: var(--font-down-1);
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// styles for user cards only
|
2020-02-13 17:58:17 +08:00
|
|
|
.user-card {
|
2019-03-25 20:37:17 +08:00
|
|
|
// badges
|
2019-12-10 03:15:47 +08:00
|
|
|
.badge-section {
|
2021-06-22 23:58:03 +08:00
|
|
|
display: flex;
|
|
|
|
align-items: flex-start;
|
2019-12-10 03:15:47 +08:00
|
|
|
flex-wrap: wrap;
|
2021-02-12 02:41:58 +08:00
|
|
|
.user-card-badge-link,
|
|
|
|
.more-user-badges {
|
2019-12-10 03:15:47 +08:00
|
|
|
display: flex;
|
|
|
|
flex: 0 1 50%;
|
|
|
|
max-width: 50%; // for text ellipsis
|
|
|
|
padding: 2px 0;
|
|
|
|
box-sizing: border-box;
|
2021-06-22 23:58:03 +08:00
|
|
|
&:nth-child(odd) {
|
2019-12-10 03:15:47 +08:00
|
|
|
padding-right: 4px;
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|
2019-12-10 03:15:47 +08:00
|
|
|
a {
|
2019-03-25 20:37:17 +08:00
|
|
|
width: 100%;
|
2019-12-10 03:15:47 +08:00
|
|
|
display: flex;
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|
|
|
|
}
|
2019-12-10 03:15:47 +08:00
|
|
|
.user-badge {
|
|
|
|
display: flex;
|
|
|
|
margin: 0;
|
|
|
|
width: 100%;
|
2020-07-02 09:39:40 +08:00
|
|
|
.badge-display-name {
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
2019-12-10 03:15:47 +08:00
|
|
|
}
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|
2020-02-15 05:19:11 +08:00
|
|
|
|
|
|
|
.public-user-fields {
|
|
|
|
@media screen and (max-height: 550px) {
|
|
|
|
max-height: 12vh;
|
|
|
|
}
|
|
|
|
max-height: 40vh;
|
|
|
|
overflow-y: auto;
|
|
|
|
.public-user-field {
|
|
|
|
@include line-clamp(3);
|
|
|
|
}
|
|
|
|
}
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// mobile card cloak
|
|
|
|
.card-cloak {
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
z-index: z("mobile-composer") + 1; // 1101
|
|
|
|
height: 100vh;
|
|
|
|
width: 100vw;
|
|
|
|
background-color: rgba(black, 0.5);
|
|
|
|
animation: fadein 0.2s;
|
2023-09-15 05:31:43 +08:00
|
|
|
@media (prefers-reduced-motion) {
|
|
|
|
animation-duration: 0s;
|
|
|
|
}
|
2019-03-25 20:37:17 +08:00
|
|
|
}
|