discourse/app/assets/stylesheets/mobile/components/user-card.scss
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

115 lines
2.3 KiB
SCSS

[data-content][data-identifier="card"] {
z-index: z("max");
}
// shared styles for user and group cards
.user-card,
.group-card {
max-width: 95vw;
margin: 0;
max-height: 85vh; // 2.5vh margin-top and margin-bottom. 10vh top
box-sizing: border-box;
// avatar - names - controls
.first-row {
flex-wrap: wrap;
.names {
flex: 1 1 auto;
box-sizing: border-box;
}
.user-card-avatar {
flex: 0 0 auto;
}
.usercard-controls {
width: 100%; // always wraps to next line
--usercard-control-margin: 0.25em;
display: flex;
flex-wrap: wrap;
margin: 1em calc(var(--usercard-control-margin) * -1) 0;
li {
flex: 1 0 calc(50% - (var(--usercard-control-margin) * 2));
min-width: 0;
margin: 0 var(--usercard-control-margin);
&:empty {
display: none;
}
button {
@include ellipsis;
margin-bottom: calc(var(--usercard-control-margin) * 2);
}
}
}
}
h1 {
font-size: var(--font-up-3);
.d-icon {
font-size: var(--font-down-2);
}
}
h2 {
font-size: var(--font-0);
}
h3 {
font-size: var(--font-down-1);
}
}
// styles for user cards only
.user-card {
// badges
.badge-section {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
.user-card-badge-link,
.more-user-badges {
display: flex;
flex: 0 1 50%;
max-width: 50%; // for text ellipsis
padding: 2px 0;
box-sizing: border-box;
&:nth-child(odd) {
padding-right: 4px;
}
a {
width: 100%;
display: flex;
}
}
.user-badge {
display: flex;
margin: 0;
width: 100%;
.badge-display-name {
overflow: hidden;
text-overflow: ellipsis;
}
}
}
.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);
}
}
}
// 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;
@media (prefers-reduced-motion) {
animation-duration: 0s;
}
}