mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 04:23:39 +08:00
2a10ea0e3f
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>
457 lines
8.4 KiB
SCSS
457 lines
8.4 KiB
SCSS
// --------------------------------------------------
|
|
// Buttons
|
|
// --------------------------------------------------
|
|
|
|
// Base
|
|
// --------------------------------------------------
|
|
|
|
@mixin btn(
|
|
$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)
|
|
) {
|
|
@include form-item-sizing;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin: 0;
|
|
font-weight: normal;
|
|
color: $text-color;
|
|
background-color: $bg-color;
|
|
background-image: linear-gradient(
|
|
to bottom,
|
|
rgba(0, 0, 0, 0),
|
|
rgba(0, 0, 0, 0)
|
|
);
|
|
border-radius: var(--d-button-border-radius);
|
|
transition: background 0.25s, color 0.25s;
|
|
cursor: pointer;
|
|
.d-icon {
|
|
color: $icon-color;
|
|
margin-right: 0.45em;
|
|
transition: color 0.25s;
|
|
// For Windows High Contrast (see whcm.scss for more)
|
|
@media (forced-colors: active) {
|
|
color: ButtonText;
|
|
}
|
|
}
|
|
.d-button-label + .d-icon {
|
|
margin-left: 0.45em;
|
|
margin-right: 0;
|
|
}
|
|
&.no-text {
|
|
.d-icon {
|
|
margin-right: 0;
|
|
}
|
|
}
|
|
@include hover {
|
|
background-color: $hover-bg-color;
|
|
color: $hover-text-color;
|
|
.d-icon {
|
|
color: $hover-icon-color;
|
|
// For Windows High Contrast (see whcm.scss for more)
|
|
@media (forced-colors: active) {
|
|
color: Highlight;
|
|
}
|
|
}
|
|
}
|
|
&:focus {
|
|
outline: none;
|
|
background-color: $hover-bg-color;
|
|
color: $hover-text-color;
|
|
.d-icon {
|
|
color: $hover-icon-color;
|
|
@media (forced-colors: active) {
|
|
color: Highlight;
|
|
}
|
|
}
|
|
|
|
&:focus-visible {
|
|
@include darken-background($hover-bg-color, 0.1);
|
|
}
|
|
}
|
|
&[href] {
|
|
color: $text-color;
|
|
&:focus {
|
|
color: $hover-text-color;
|
|
}
|
|
}
|
|
.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,
|
|
&:active,
|
|
&.btn-active {
|
|
@include darken-background($bg-color, 0.3);
|
|
color: $hover-text-color;
|
|
.d-icon {
|
|
color: $hover-icon-color;
|
|
}
|
|
}
|
|
&[disabled],
|
|
&.disabled {
|
|
&:not(.is-loading) {
|
|
opacity: 0.4;
|
|
}
|
|
&:hover {
|
|
color: $text-color;
|
|
background: $bg-color;
|
|
.d-icon {
|
|
color: $icon-color;
|
|
}
|
|
}
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.loading-container {
|
|
display: none;
|
|
margin: 0 6.75px 0 0;
|
|
}
|
|
|
|
&.is-loading {
|
|
&.btn-text {
|
|
.d-button-label {
|
|
font-size: var(--font-down-2);
|
|
}
|
|
|
|
&.btn-small {
|
|
.loading-icon {
|
|
font-size: var(--font-down-1);
|
|
margin-right: 0.2em;
|
|
}
|
|
}
|
|
}
|
|
|
|
.loading-icon {
|
|
animation: rotate-forever 1s infinite linear, fadein 1s;
|
|
}
|
|
}
|
|
}
|
|
|
|
.btn.hidden {
|
|
display: none;
|
|
}
|
|
|
|
// Default button
|
|
// --------------------------------------------------
|
|
|
|
.btn {
|
|
@include btn;
|
|
}
|
|
|
|
// Primary button
|
|
// --------------------------------------------------
|
|
|
|
.btn-primary {
|
|
@include btn(
|
|
$text-color: var(--secondary),
|
|
$bg-color: var(--tertiary),
|
|
$icon-color: var(--secondary),
|
|
$hover-bg-color: var(--tertiary-hover),
|
|
$hover-icon-color: var(--secondary)
|
|
);
|
|
}
|
|
|
|
// Danger button
|
|
// --------------------------------------------------
|
|
|
|
.btn-danger {
|
|
@include btn(
|
|
$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)
|
|
);
|
|
}
|
|
|
|
// ✘ and ✔ buttons
|
|
// --------------------------------------------------
|
|
|
|
.btn.cancel {
|
|
@include btn(
|
|
$text-color: var(--secondary),
|
|
$bg-color: var(--danger),
|
|
$icon-color: var(--secondary),
|
|
$hover-bg-color: var(--danger-hover),
|
|
$hover-icon-color: var(--secondary)
|
|
);
|
|
}
|
|
|
|
.btn.ok {
|
|
@include btn(
|
|
$text-color: var(--secondary),
|
|
$bg-color: var(--success),
|
|
$icon-color: var(--secondary),
|
|
$hover-bg-color: var(--success-hover),
|
|
$hover-icon-color: var(--secondary)
|
|
);
|
|
}
|
|
|
|
// Social buttons
|
|
// --------------------------------------------------
|
|
|
|
.btn-social {
|
|
color: #000;
|
|
background: #fff;
|
|
border: 1px solid transparent;
|
|
border-radius: var(--d-border-radius);
|
|
&:hover,
|
|
&:focus {
|
|
box-shadow: var(--shadow-card);
|
|
outline: 1px solid #000;
|
|
}
|
|
&[href] {
|
|
color: var(--secondary);
|
|
}
|
|
&:before {
|
|
margin-right: 9px;
|
|
font-size: var(--font-0);
|
|
}
|
|
.d-icon,
|
|
&.btn:hover .d-icon {
|
|
color: #000;
|
|
}
|
|
&.google_oauth2 {
|
|
background: var(--google);
|
|
color: #333;
|
|
// non-FA SVG icon for Google in login-buttons.hbs
|
|
.d-icon {
|
|
opacity: 0.9;
|
|
}
|
|
&:hover,
|
|
&:focus {
|
|
color: currentColor;
|
|
}
|
|
}
|
|
|
|
&.cas {
|
|
.d-icon {
|
|
color: var(--cas);
|
|
}
|
|
&:hover {
|
|
.d-icon {
|
|
color: var(--cas);
|
|
}
|
|
}
|
|
}
|
|
&.twitter {
|
|
.d-icon {
|
|
color: var(--twitter);
|
|
}
|
|
&:hover {
|
|
.d-icon {
|
|
color: var(--twitter);
|
|
}
|
|
}
|
|
}
|
|
&.github {
|
|
.d-icon {
|
|
color: var(--github);
|
|
}
|
|
&:hover {
|
|
.d-icon {
|
|
color: var(--github);
|
|
}
|
|
}
|
|
}
|
|
&.discord {
|
|
.d-icon {
|
|
color: var(--discord);
|
|
}
|
|
&:hover {
|
|
.d-icon {
|
|
color: var(--discord);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Button Sizes
|
|
// --------------------------------------------------
|
|
|
|
// Small
|
|
|
|
.btn-small {
|
|
font-size: var(--font-down-1);
|
|
min-height: 20px;
|
|
}
|
|
|
|
// Large
|
|
|
|
.btn-large {
|
|
font-size: var(--font-up-1);
|
|
}
|
|
|
|
// Bonus Buttons
|
|
// --------------------------------------------------
|
|
|
|
.btn-flat {
|
|
background: transparent;
|
|
border: 0;
|
|
line-height: var(--line-height-small);
|
|
transition: background 0.25s, color 0.25s;
|
|
.d-icon {
|
|
color: var(--primary-low-mid);
|
|
transition: color 0.25s;
|
|
}
|
|
@include hover {
|
|
background: transparent;
|
|
color: var(--primary);
|
|
.d-icon {
|
|
color: var(--primary);
|
|
}
|
|
}
|
|
&.close {
|
|
padding: 0;
|
|
background: transparent;
|
|
font-size: var(--font-up-3);
|
|
.d-icon {
|
|
color: var(--primary-high);
|
|
}
|
|
@include hover {
|
|
background: transparent;
|
|
.d-icon {
|
|
color: var(--primary);
|
|
}
|
|
}
|
|
}
|
|
&.btn-text {
|
|
color: var(--tertiary);
|
|
&[disabled] {
|
|
&,
|
|
&:hover,
|
|
&.btn-hover,
|
|
&:focus {
|
|
color: var(--primary);
|
|
}
|
|
}
|
|
&:not([disabled]) {
|
|
&:hover,
|
|
&.btn-hover,
|
|
&:focus {
|
|
color: var(--tertiary-hover);
|
|
}
|
|
|
|
&:active,
|
|
&.btn-active {
|
|
@include darken-background(transparent, 0.2);
|
|
}
|
|
}
|
|
}
|
|
&:focus {
|
|
outline: none;
|
|
background: var(--primary-low);
|
|
.d-icon {
|
|
color: var(--primary);
|
|
}
|
|
}
|
|
}
|
|
|
|
.btn-link {
|
|
background: transparent;
|
|
border: 0;
|
|
padding: 0;
|
|
color: var(--tertiary);
|
|
.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;
|
|
}
|
|
}
|
|
|
|
.btn-transparent {
|
|
background: none;
|
|
border: 0;
|
|
color: var(--primary);
|
|
|
|
&.btn-primary,
|
|
&.btn-primary:focus,
|
|
&.btn-primary:hover {
|
|
.d-icon {
|
|
color: var(--tertiary) !important;
|
|
}
|
|
}
|
|
&.btn-danger,
|
|
&.btn-danger:focus,
|
|
&.btn-danger:hover {
|
|
.d-icon {
|
|
color: var(--danger) !important;
|
|
}
|
|
}
|
|
&.btn-success,
|
|
&.btn-success:focus,
|
|
&.btn-success:hover {
|
|
.d-icon {
|
|
color: var(--success) !important;
|
|
}
|
|
}
|
|
|
|
.discourse-no-touch & {
|
|
&:hover {
|
|
color: var(--primary);
|
|
background: var(--d-hover);
|
|
.d-icon {
|
|
color: var(--primary);
|
|
}
|
|
}
|
|
}
|
|
|
|
&:focus {
|
|
color: var(--primary);
|
|
background: var(--d-hover);
|
|
.d-icon {
|
|
color: var(--primary);
|
|
}
|
|
}
|
|
|
|
&:focus-visible {
|
|
color: var(--primary);
|
|
background: var(--d-hover);
|
|
.d-icon {
|
|
color: var(--primary);
|
|
}
|
|
}
|
|
}
|
|
|
|
.btn-mini-toggle {
|
|
border-radius: var(--d-border-radius);
|
|
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);
|
|
}
|
|
}
|
|
}
|