2013-02-05 14:16:51 -05:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Buttons
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Base
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2019-12-13 14:09:48 -05:00
|
|
|
@mixin btn(
|
2020-08-03 22:57:10 -04:00
|
|
|
$text-color: var(--primary),
|
|
|
|
$bg-color: var(--primary-low),
|
|
|
|
$icon-color: var(--primary-high),
|
|
|
|
$hover-text-color: var(--secondary),
|
|
|
|
$hover-bg-color: var(--primary-medium),
|
|
|
|
$hover-icon-color: var(--primary-low)
|
2019-12-13 14:09:48 -05:00
|
|
|
) {
|
2021-09-09 11:01:56 -04:00
|
|
|
@include form-item-sizing;
|
2021-01-27 16:17:08 -05:00
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2013-02-05 14:16:51 -05:00
|
|
|
margin: 0;
|
2019-12-13 14:09:48 -05:00
|
|
|
font-weight: normal;
|
|
|
|
color: $text-color;
|
2024-01-09 18:33:50 -05:00
|
|
|
&:visited {
|
|
|
|
// covers cases where we add button classes to links
|
|
|
|
color: $text-color;
|
|
|
|
}
|
2023-05-22 17:03:34 -04:00
|
|
|
background-color: $bg-color;
|
|
|
|
background-image: linear-gradient(
|
|
|
|
to bottom,
|
|
|
|
rgba(0, 0, 0, 0),
|
|
|
|
rgba(0, 0, 0, 0)
|
|
|
|
);
|
2022-11-16 11:35:09 -05:00
|
|
|
border-radius: var(--d-button-border-radius);
|
2024-06-20 13:51:20 -04:00
|
|
|
transition: var(--d-button-transition);
|
2013-02-05 14:16:51 -05:00
|
|
|
cursor: pointer;
|
2019-01-31 13:59:49 -05:00
|
|
|
.d-icon {
|
2019-12-13 14:09:48 -05:00
|
|
|
color: $icon-color;
|
|
|
|
margin-right: 0.45em;
|
2024-06-20 13:51:20 -04:00
|
|
|
transition: var(--d-button-transition);
|
2022-10-17 10:07:46 -04:00
|
|
|
// For Windows High Contrast (see whcm.scss for more)
|
|
|
|
@media (forced-colors: active) {
|
|
|
|
color: ButtonText;
|
|
|
|
}
|
2021-10-18 13:17:27 -04:00
|
|
|
}
|
|
|
|
.d-button-label + .d-icon {
|
|
|
|
margin-left: 0.45em;
|
|
|
|
margin-right: 0;
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
2013-05-07 14:25:41 -04:00
|
|
|
&.no-text {
|
2019-07-22 10:31:21 -04:00
|
|
|
.d-icon {
|
2013-05-07 14:25:41 -04:00
|
|
|
margin-right: 0;
|
|
|
|
}
|
|
|
|
}
|
2019-10-28 16:04:29 -04:00
|
|
|
@include hover {
|
2023-05-22 17:03:34 -04:00
|
|
|
background-color: $hover-bg-color;
|
2019-12-13 14:09:48 -05:00
|
|
|
color: $hover-text-color;
|
2019-10-28 16:04:29 -04:00
|
|
|
.d-icon {
|
2019-12-13 14:09:48 -05:00
|
|
|
color: $hover-icon-color;
|
2022-10-17 10:07:46 -04:00
|
|
|
// For Windows High Contrast (see whcm.scss for more)
|
|
|
|
@media (forced-colors: active) {
|
|
|
|
color: Highlight;
|
|
|
|
}
|
2018-10-04 17:15:37 -04:00
|
|
|
}
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
2021-02-03 11:45:54 -05:00
|
|
|
&:focus {
|
|
|
|
outline: none;
|
2023-05-22 17:03:34 -04:00
|
|
|
background-color: $hover-bg-color;
|
2021-02-03 11:45:54 -05:00
|
|
|
color: $hover-text-color;
|
|
|
|
.d-icon {
|
|
|
|
color: $hover-icon-color;
|
2022-10-17 10:07:46 -04:00
|
|
|
@media (forced-colors: active) {
|
|
|
|
color: Highlight;
|
|
|
|
}
|
2021-02-03 11:45:54 -05:00
|
|
|
}
|
2023-08-07 16:46:10 -04:00
|
|
|
|
|
|
|
&:focus-visible {
|
|
|
|
@include darken-background($hover-bg-color, 0.1);
|
|
|
|
}
|
2021-02-03 11:45:54 -05:00
|
|
|
}
|
2024-01-09 14:16:48 -05:00
|
|
|
|
2023-05-22 17:03:34 -04:00
|
|
|
.discourse-no-touch &:active:not(:hover):not(:focus),
|
|
|
|
.discourse-no-touch &.btn-active:not(:hover):not(:focus),
|
|
|
|
&:active:not(:hover):not(:focus),
|
|
|
|
&.btn-active:not(:hover):not(:focus) {
|
|
|
|
@include darken-background($bg-color, 0.6);
|
|
|
|
color: $hover-text-color;
|
|
|
|
.d-icon {
|
|
|
|
color: $hover-icon-color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.discourse-no-touch &:active,
|
|
|
|
.discourse-no-touch &.btn-active,
|
2019-12-13 14:09:48 -05:00
|
|
|
&:active,
|
|
|
|
&.btn-active {
|
2023-05-22 17:03:34 -04:00
|
|
|
@include darken-background($bg-color, 0.3);
|
|
|
|
color: $hover-text-color;
|
|
|
|
.d-icon {
|
|
|
|
color: $hover-icon-color;
|
|
|
|
}
|
2019-12-13 14:09:48 -05:00
|
|
|
}
|
2018-06-08 05:49:31 -04:00
|
|
|
&[disabled],
|
|
|
|
&.disabled {
|
2021-09-17 09:36:57 -04:00
|
|
|
&:not(.is-loading) {
|
|
|
|
opacity: 0.4;
|
|
|
|
}
|
2018-06-08 05:49:31 -04:00
|
|
|
&:hover {
|
2019-12-13 14:09:48 -05:00
|
|
|
color: $text-color;
|
|
|
|
background: $bg-color;
|
2019-01-31 13:59:49 -05:00
|
|
|
.d-icon {
|
2019-12-13 14:09:48 -05:00
|
|
|
color: $icon-color;
|
2019-01-31 13:59:49 -05:00
|
|
|
}
|
2018-06-08 05:49:31 -04:00
|
|
|
}
|
2014-02-12 23:06:49 -05:00
|
|
|
cursor: not-allowed;
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
2020-03-30 17:17:00 -04:00
|
|
|
|
|
|
|
.loading-container {
|
|
|
|
display: none;
|
|
|
|
margin: 0 6.75px 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.is-loading {
|
|
|
|
&.btn-text {
|
|
|
|
.d-button-label {
|
2022-10-12 09:31:59 -04:00
|
|
|
font-size: var(--font-down-2);
|
2020-03-30 17:17:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
&.btn-small {
|
|
|
|
.loading-icon {
|
2022-10-12 09:31:59 -04:00
|
|
|
font-size: var(--font-down-1);
|
2020-03-30 17:17:00 -04:00
|
|
|
margin-right: 0.2em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.loading-icon {
|
|
|
|
animation: rotate-forever 1s infinite linear, fadein 1s;
|
|
|
|
}
|
|
|
|
}
|
2019-12-13 14:09:48 -05:00
|
|
|
}
|
2017-05-11 14:47:08 -04:00
|
|
|
|
2019-12-13 14:09:48 -05:00
|
|
|
.btn.hidden {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default button
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
.btn {
|
|
|
|
@include btn;
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Primary button
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
.btn-primary {
|
2019-12-13 14:09:48 -05:00
|
|
|
@include btn(
|
2020-08-03 22:57:10 -04:00
|
|
|
$text-color: var(--secondary),
|
|
|
|
$bg-color: var(--tertiary),
|
|
|
|
$icon-color: var(--secondary),
|
|
|
|
$hover-bg-color: var(--tertiary-hover),
|
|
|
|
$hover-icon-color: var(--secondary)
|
2019-12-13 14:09:48 -05:00
|
|
|
);
|
2013-02-14 02:56:13 -05:00
|
|
|
}
|
2013-02-14 02:47:19 -05:00
|
|
|
|
2013-02-14 02:56:13 -05:00
|
|
|
// Danger button
|
|
|
|
// --------------------------------------------------
|
2013-02-14 02:47:19 -05:00
|
|
|
|
2013-02-14 02:56:13 -05:00
|
|
|
.btn-danger {
|
2019-12-13 14:09:48 -05:00
|
|
|
@include btn(
|
2020-08-03 22:57:10 -04:00
|
|
|
$text-color: var(--secondary),
|
|
|
|
$bg-color: var(--danger),
|
|
|
|
$icon-color: var(--danger-low),
|
|
|
|
$hover-bg-color: var(--danger-hover),
|
|
|
|
$hover-icon-color: var(--danger-low)
|
2019-12-13 14:09:48 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ✘ and ✔ buttons
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
.btn.cancel {
|
|
|
|
@include btn(
|
2020-08-03 22:57:10 -04:00
|
|
|
$text-color: var(--secondary),
|
|
|
|
$bg-color: var(--danger),
|
|
|
|
$icon-color: var(--secondary),
|
|
|
|
$hover-bg-color: var(--danger-hover),
|
|
|
|
$hover-icon-color: var(--secondary)
|
2019-12-13 14:09:48 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
.btn.ok {
|
|
|
|
@include btn(
|
2020-08-03 22:57:10 -04:00
|
|
|
$text-color: var(--secondary),
|
|
|
|
$bg-color: var(--success),
|
|
|
|
$icon-color: var(--secondary),
|
|
|
|
$hover-bg-color: var(--success-hover),
|
|
|
|
$hover-icon-color: var(--secondary)
|
2019-12-13 14:09:48 -05:00
|
|
|
);
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Social buttons
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2021-03-30 14:16:50 -04:00
|
|
|
.btn-social {
|
2021-02-10 15:53:18 -05:00
|
|
|
color: #000;
|
2021-03-30 14:16:50 -04:00
|
|
|
background: #fff;
|
2021-02-10 15:53:18 -05:00
|
|
|
border: 1px solid transparent;
|
2022-11-16 11:35:09 -05:00
|
|
|
border-radius: var(--d-border-radius);
|
2021-03-30 14:16:50 -04:00
|
|
|
&:hover,
|
|
|
|
&:focus {
|
2023-06-13 16:38:31 -04:00
|
|
|
box-shadow: var(--shadow-card);
|
2021-03-30 14:16:50 -04:00
|
|
|
outline: 1px solid #000;
|
2018-01-22 21:19:38 -05:00
|
|
|
}
|
2013-02-05 14:16:51 -05:00
|
|
|
&[href] {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--secondary);
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
&:before {
|
2015-07-21 01:46:33 -04:00
|
|
|
margin-right: 9px;
|
2022-10-12 09:31:59 -04:00
|
|
|
font-size: var(--font-0);
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
2021-08-03 07:48:21 -04:00
|
|
|
.d-icon,
|
|
|
|
&.btn:hover .d-icon {
|
|
|
|
color: #000;
|
|
|
|
}
|
2018-06-08 05:49:31 -04:00
|
|
|
&.google_oauth2 {
|
2020-08-03 22:57:10 -04:00
|
|
|
background: var(--google);
|
2018-10-24 22:11:19 -04:00
|
|
|
color: #333;
|
2018-11-26 16:49:57 -05:00
|
|
|
// non-FA SVG icon for Google in login-buttons.hbs
|
|
|
|
.d-icon {
|
|
|
|
opacity: 0.9;
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
2021-02-03 11:45:54 -05:00
|
|
|
&:hover,
|
|
|
|
&:focus {
|
2024-06-20 13:51:20 -04:00
|
|
|
color: inherit;
|
2019-03-15 17:20:52 -04:00
|
|
|
}
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
2021-02-10 15:53:18 -05:00
|
|
|
|
2013-05-23 16:40:50 -04:00
|
|
|
&.cas {
|
2021-02-10 15:53:18 -05:00
|
|
|
.d-icon {
|
|
|
|
color: var(--cas);
|
|
|
|
}
|
|
|
|
&:hover {
|
|
|
|
.d-icon {
|
|
|
|
color: var(--cas);
|
|
|
|
}
|
|
|
|
}
|
2013-05-23 16:40:50 -04:00
|
|
|
}
|
2013-02-05 14:16:51 -05:00
|
|
|
&.twitter {
|
2021-02-10 15:53:18 -05:00
|
|
|
.d-icon {
|
|
|
|
color: var(--twitter);
|
|
|
|
}
|
|
|
|
&:hover {
|
|
|
|
.d-icon {
|
|
|
|
color: var(--twitter);
|
|
|
|
}
|
2019-03-15 17:20:52 -04:00
|
|
|
}
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
2013-02-25 23:28:32 -05:00
|
|
|
&.github {
|
2021-02-10 15:53:18 -05:00
|
|
|
.d-icon {
|
|
|
|
color: var(--github);
|
|
|
|
}
|
|
|
|
&:hover {
|
|
|
|
.d-icon {
|
|
|
|
color: var(--github);
|
|
|
|
}
|
2019-03-15 17:20:52 -04:00
|
|
|
}
|
2013-02-25 23:28:32 -05:00
|
|
|
}
|
2019-08-30 05:54:19 -04:00
|
|
|
&.discord {
|
2021-02-10 15:53:18 -05:00
|
|
|
.d-icon {
|
|
|
|
color: var(--discord);
|
|
|
|
}
|
|
|
|
&:hover {
|
|
|
|
.d-icon {
|
|
|
|
color: var(--discord);
|
|
|
|
}
|
2019-08-30 05:54:19 -04:00
|
|
|
}
|
|
|
|
}
|
2024-03-08 11:47:59 -05:00
|
|
|
// https://developers.facebook.com/docs/facebook-login/userexperience/#buttondesign
|
|
|
|
// if you are unable to use Facebook blue, revert to black and white.
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Button Sizes
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Small
|
|
|
|
|
|
|
|
.btn-small {
|
2021-09-09 11:01:56 -04:00
|
|
|
font-size: var(--font-down-1);
|
2020-02-19 12:38:46 -05:00
|
|
|
min-height: 20px;
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Large
|
|
|
|
|
|
|
|
.btn-large {
|
2021-09-09 11:01:56 -04:00
|
|
|
font-size: var(--font-up-1);
|
2013-02-14 02:56:13 -05:00
|
|
|
}
|
2017-07-24 17:31:14 -04:00
|
|
|
|
2021-04-07 16:15:07 -04:00
|
|
|
// Bonus Buttons
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2017-07-24 17:31:14 -04:00
|
|
|
.btn-flat {
|
|
|
|
background: transparent;
|
|
|
|
border: 0;
|
2022-10-12 10:05:42 -04:00
|
|
|
line-height: var(--line-height-small);
|
2024-06-20 13:51:20 -04:00
|
|
|
transition: var(--d-button-transition);
|
2017-07-27 15:03:41 -04:00
|
|
|
.d-icon {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--primary-low-mid);
|
2024-06-20 13:51:20 -04:00
|
|
|
transition: var(--d-button-transition);
|
2019-01-31 13:59:49 -05:00
|
|
|
}
|
2023-10-30 12:44:38 -04:00
|
|
|
.discourse-no-touch & {
|
|
|
|
&:hover,
|
|
|
|
&:focus {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--primary);
|
2023-10-30 12:44:38 -04:00
|
|
|
.d-icon {
|
|
|
|
color: var(--primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
&:hover {
|
|
|
|
background: transparent;
|
|
|
|
}
|
|
|
|
&:focus {
|
|
|
|
background: var(--primary-low);
|
2019-10-28 16:04:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
&.close {
|
|
|
|
background: transparent;
|
2023-11-15 05:14:47 -05:00
|
|
|
font-size: var(--font-up-2);
|
2019-10-28 16:04:29 -04:00
|
|
|
.d-icon {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--primary-high);
|
2019-10-28 16:04:29 -04:00
|
|
|
}
|
2023-10-30 12:44:38 -04:00
|
|
|
.discourse-no-touch & {
|
|
|
|
&:hover,
|
|
|
|
&:focus {
|
|
|
|
background: transparent;
|
|
|
|
.d-icon {
|
|
|
|
color: var(--primary);
|
|
|
|
}
|
2019-01-31 15:13:22 -05:00
|
|
|
}
|
2019-01-31 13:59:49 -05:00
|
|
|
}
|
2023-11-15 05:14:47 -05:00
|
|
|
&:focus {
|
|
|
|
background: transparent;
|
|
|
|
.d-icon {
|
|
|
|
color: var(--primary);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 11:37:32 -04:00
|
|
|
}
|
2022-08-15 15:06:03 -04:00
|
|
|
&.btn-text {
|
|
|
|
color: var(--tertiary);
|
|
|
|
&[disabled] {
|
|
|
|
&,
|
|
|
|
&:hover,
|
|
|
|
&.btn-hover,
|
|
|
|
&:focus {
|
|
|
|
color: var(--primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
&:not([disabled]) {
|
|
|
|
&:hover,
|
|
|
|
&.btn-hover,
|
|
|
|
&:focus {
|
|
|
|
color: var(--tertiary-hover);
|
|
|
|
}
|
2021-03-18 08:29:27 -04:00
|
|
|
|
2022-08-15 15:06:03 -04:00
|
|
|
&:active,
|
|
|
|
&.btn-active {
|
2023-05-22 17:03:34 -04:00
|
|
|
@include darken-background(transparent, 0.2);
|
2022-08-15 15:06:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-18 08:29:27 -04:00
|
|
|
&:focus {
|
|
|
|
outline: none;
|
2021-05-24 04:10:01 -04:00
|
|
|
background: var(--primary-low);
|
2021-03-18 08:29:27 -04:00
|
|
|
.d-icon {
|
2021-05-24 04:10:01 -04:00
|
|
|
color: var(--primary);
|
2021-03-18 08:29:27 -04:00
|
|
|
}
|
|
|
|
}
|
2024-03-12 23:15:12 -04:00
|
|
|
&.back-button {
|
|
|
|
margin-bottom: 1em;
|
|
|
|
}
|
2017-07-24 17:31:14 -04:00
|
|
|
}
|
2019-10-31 15:36:24 -04:00
|
|
|
|
|
|
|
.btn-link {
|
|
|
|
background: transparent;
|
|
|
|
border: 0;
|
|
|
|
padding: 0;
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--tertiary);
|
2022-12-19 18:56:51 -05:00
|
|
|
.discourse-no-touch & {
|
|
|
|
&:hover {
|
|
|
|
color: var(--tertiary);
|
|
|
|
background: transparent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
&:focus {
|
|
|
|
color: var(--tertiary);
|
|
|
|
background: transparent;
|
|
|
|
}
|
|
|
|
&:focus-visible {
|
|
|
|
color: var(--tertiary);
|
|
|
|
background: transparent;
|
|
|
|
@include default-focus;
|
|
|
|
}
|
2019-10-31 15:36:24 -04:00
|
|
|
}
|
2021-04-07 16:15:07 -04:00
|
|
|
|
2023-12-01 22:21:22 -05:00
|
|
|
@mixin btn-colors($btn-color) {
|
|
|
|
color: var(--#{$btn-color});
|
|
|
|
.d-icon {
|
2024-06-20 13:51:20 -04:00
|
|
|
color: inherit;
|
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 07:39:52 -04:00
|
|
|
}
|
2023-12-01 22:21:22 -05:00
|
|
|
&:focus,
|
|
|
|
&:focus-visible {
|
|
|
|
color: var(--#{$btn-color}-hover);
|
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 07:39:52 -04:00
|
|
|
}
|
|
|
|
.discourse-no-touch & {
|
|
|
|
&:hover {
|
2023-12-01 22:21:22 -05:00
|
|
|
color: var(--#{$btn-color}-hover);
|
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 07:39:52 -04:00
|
|
|
}
|
|
|
|
}
|
2023-12-01 22:21:22 -05:00
|
|
|
}
|
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 07:39:52 -04:00
|
|
|
|
2023-12-01 22:21:22 -05:00
|
|
|
.btn-transparent {
|
|
|
|
&,
|
|
|
|
&.btn-default {
|
|
|
|
background: transparent !important;
|
|
|
|
border: 0;
|
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 07:39:52 -04:00
|
|
|
color: var(--primary);
|
|
|
|
.d-icon {
|
2023-12-01 22:21:22 -05:00
|
|
|
color: var(--primary-high);
|
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 07:39:52 -04:00
|
|
|
}
|
2023-12-01 22:21:22 -05:00
|
|
|
&:focus,
|
|
|
|
&:focus-visible {
|
|
|
|
color: var(--tertiary-hover);
|
|
|
|
.d-icon {
|
2024-06-20 13:51:20 -04:00
|
|
|
color: inherit;
|
2023-12-01 22:21:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.discourse-no-touch & {
|
|
|
|
&:hover {
|
|
|
|
color: var(--tertiary-hover);
|
|
|
|
.d-icon {
|
2024-06-20 13:51:20 -04:00
|
|
|
color: inherit;
|
2023-12-01 22:21:22 -05:00
|
|
|
}
|
|
|
|
}
|
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 07:39:52 -04:00
|
|
|
}
|
|
|
|
}
|
2023-12-01 22:21:22 -05:00
|
|
|
&.btn-primary {
|
|
|
|
@include btn-colors("tertiary");
|
|
|
|
}
|
|
|
|
&.btn-danger {
|
|
|
|
@include btn-colors("danger");
|
|
|
|
}
|
|
|
|
&.btn-success {
|
|
|
|
@include btn-colors("success");
|
|
|
|
}
|
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 07:39:52 -04:00
|
|
|
}
|
|
|
|
|
2021-04-07 16:15:07 -04:00
|
|
|
.btn-mini-toggle {
|
2022-11-16 11:35:09 -05:00
|
|
|
border-radius: var(--d-border-radius);
|
2021-04-07 16:15:07 -04:00
|
|
|
padding: 0.4em 0.467em;
|
|
|
|
.d-icon {
|
2024-02-29 05:47:07 -05:00
|
|
|
color: var(--primary-medium);
|
2021-04-07 16:15:07 -04:00
|
|
|
}
|
|
|
|
@include hover {
|
|
|
|
.d-icon {
|
|
|
|
color: var(--primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|