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