Skip to content

Commit 040d1b7

Browse files
authored
Custom button cleanup & toolbar button styles (#1794)
Closes #1791 https://github.com/webrecorder/browsertrix/assets/5727389/54a4d9a2-9e68-4cbd-9cef-8a73a6106043 | Screenshots | | --- | | <img width="145" alt="Screenshot 2024-05-08 at 6 13 53 PM" src="https://github.com/webrecorder/browsertrix/assets/5727389/35efd4b5-2a59-4fd2-8a62-904eedad98f9"> |
1 parent e853b62 commit 040d1b7

File tree

6 files changed

+80
-49
lines changed

6 files changed

+80
-49
lines changed

frontend/src/components/ui/button.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable lit/binding-positions */
22
/* eslint-disable lit/no-invalid-html */
3+
import clsx from "clsx";
34
import { css } from "lit";
45
import { customElement, property } from "lit/decorators.js";
56
import { ifDefined } from "lit/directives/if-defined.js";
@@ -8,6 +9,8 @@ import { html, literal } from "lit/static-html.js";
89
import { TailwindElement } from "@/classes/TailwindElement";
910
import { tw } from "@/utils/tailwind";
1011

12+
type Variant = "neutral" | "danger";
13+
1114
/**
1215
* Custom styled button
1316
*
@@ -21,8 +24,18 @@ export class Button extends TailwindElement {
2124
@property({ type: String })
2225
type: "submit" | "button" = "button";
2326

27+
// TODO unify button styling & variants - there are probably a few different
28+
// approaches for difference button use cases, but we'll figure that out in
29+
// the future when we work more on our UI library.
30+
// See also https://github.com/webrecorder/browsertrix/issues/1550
2431
@property({ type: String })
25-
variant: "primary" | "danger" | "neutral" = "neutral";
32+
variant: Variant = "neutral";
33+
34+
@property({ type: Boolean })
35+
filled = false;
36+
37+
@property({ type: String })
38+
size: "small" | "medium" = "medium";
2639

2740
@property({ type: String })
2841
label?: string;
@@ -39,9 +52,6 @@ export class Button extends TailwindElement {
3952
@property({ type: Boolean })
4053
loading = false;
4154

42-
@property({ type: Boolean })
43-
icon = false;
44-
4555
static styles = css`
4656
:host {
4757
display: inline-block;
@@ -57,18 +67,28 @@ export class Button extends TailwindElement {
5767
const tag = this.href ? literal`a` : literal`button`;
5868
return html`<${tag}
5969
type=${this.type === "submit" ? "submit" : "button"}
60-
class=${[
61-
tw`flex h-6 cursor-pointer items-center justify-center gap-2 rounded-sm text-center font-medium transition-all disabled:cursor-not-allowed disabled:text-neutral-300`,
62-
this.icon ? tw`min-h-8 min-w-8 px-1` : tw`h-6 px-2`,
63-
this.raised ? tw`shadow-sm` : "",
64-
{
65-
primary: tw`bg-blue-50 text-blue-600 shadow-blue-800/20 hover:bg-blue-100`,
66-
danger: tw`shadow-danger-800/20 bg-danger-50 text-danger-600 hover:bg-danger-100`,
67-
neutral: tw`text-neutral-600 hover:text-blue-600`,
68-
}[this.variant],
69-
]
70-
.filter(Boolean)
71-
.join(" ")}
70+
class=${clsx(
71+
tw`flex h-6 cursor-pointer items-center justify-center gap-2 text-center font-medium outline-3 outline-offset-1 outline-primary transition focus-visible:outline disabled:cursor-not-allowed disabled:text-neutral-300`,
72+
this.size === "medium"
73+
? tw`min-h-8 min-w-8 rounded-sm`
74+
: tw`min-h-6 min-w-6 rounded-md`,
75+
this.raised && tw`border shadow-sm`,
76+
this.filled
77+
? [
78+
tw`text-white`,
79+
{
80+
neutral: tw`border-primary-800 bg-primary-500 shadow-primary-800/20 hover:bg-primary-600`,
81+
danger: tw`shadow-danger-800/20 border-danger-800 bg-danger-500 hover:bg-danger-600`,
82+
}[this.variant],
83+
]
84+
: [
85+
this.raised && tw`bg-white`,
86+
{
87+
neutral: tw`border-gray-300 text-gray-600 hover:text-primary-600`,
88+
danger: tw`shadow-danger-800/20 border-danger-300 bg-danger-50 text-danger-600 hover:bg-danger-100`,
89+
}[this.variant],
90+
],
91+
)}
7292
?disabled=${this.disabled}
7393
href=${ifDefined(this.href)}
7494
aria-label=${ifDefined(this.label)}

frontend/src/components/ui/copy-button.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ export class CopyButton extends LitElement {
6060
@sl-hide=${this.stopProp}
6161
@sl-after-hide=${this.stopProp}
6262
>
63-
<sl-icon-button
64-
name=${this.isCopied ? "check-lg" : this.name ? this.name : "copy"}
65-
label=${msg("Copy to clipboard")}
63+
<btrix-button
64+
size="small"
6665
@click=${this.onClick}
6766
?disabled=${!this.value && !this.getValue}
68-
></sl-icon-button>
67+
class="inline"
68+
raised
69+
>
70+
<sl-icon
71+
name=${this.isCopied ? "check-lg" : this.name ? this.name : "copy"}
72+
label=${msg("Copy to clipboard")}
73+
></sl-icon>
74+
</btrix-button>
6975
</sl-tooltip>
7076
`;
7177
}

frontend/src/components/ui/copy-field.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { localized } from "@lit/localize";
2+
import clsx from "clsx";
23
import { css, html } from "lit";
3-
import { customElement, property } from "lit/decorators.js";
4-
import { classMap } from "lit/directives/class-map.js";
4+
import { customElement, property, queryAssignedNodes } from "lit/decorators.js";
55

66
import { TailwindElement } from "@/classes/TailwindElement";
7+
import { tw } from "@/utils/tailwind";
78

89
/**
910
* Copy text to clipboard on click
@@ -49,26 +50,27 @@ export class CopyField extends TailwindElement {
4950
}
5051
`;
5152

52-
get _slottedChildren() {
53-
const slot = this.shadowRoot?.querySelector("slot[name=label]");
54-
return (slot as HTMLSlotElement | null | undefined)?.assignedElements();
55-
}
53+
@queryAssignedNodes({ slot: "label" })
54+
private readonly slottedChildren: Element[] | undefined;
5655

5756
render() {
5857
return html`
59-
<div role="group">
58+
<div
59+
role="group"
60+
class=${clsx(
61+
tw`rounded border`,
62+
this.filled && tw`bg-slate-50`,
63+
this.monostyle && tw`font-monostyle`,
64+
)}
65+
>
6066
<label
61-
class="${classMap({
62-
hidden: !this.label && !this._slottedChildren,
63-
})} mb-1.5 inline-block font-sans text-xs leading-[1.4] text-neutral-800"
67+
class="${clsx(
68+
"mb-1.5 inline-block font-sans text-xs leading-[1.4] text-neutral-800",
69+
!this.label && !this.slottedChildren?.length && tw`hidden`,
70+
)} "
6471
><slot name="label">${this.label}</slot></label
6572
>
66-
<div
67-
class="${classMap({
68-
"bg-slate-50": this.filled,
69-
"font-monostyle": this.monostyle,
70-
})} relative inline-flex w-full items-stretch justify-start rounded border"
71-
>
73+
<div class="relative inline-flex w-full items-stretch justify-start">
7274
<slot name="prefix"></slot>
7375
<span
7476
aria-hidden=${this.hideContentFromScreenReaders}
@@ -82,6 +84,7 @@ export class CopyField extends TailwindElement {
8284
.content=${this.buttonContent}
8385
.getValue=${this.getValue}
8486
.hoist=${this.hoist}
87+
class="m-1 flex"
8588
></btrix-copy-button>
8689
</div>
8790
</div>

frontend/src/features/crawl-workflows/queue-exclusion-form.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,10 @@ export class QueueExclusionForm extends LiteElement {
147147
: ""}
148148
</sl-input>
149149
</div>
150-
<div class="flex-0 w-10 pt-1 text-center">
150+
<div class="flex-0 w-10 text-center">
151151
<btrix-button
152-
variant="primary"
152+
variant="neutral"
153153
raised
154-
icon
155154
?disabled=${!this.inputValue ||
156155
this.isRegexInvalid ||
157156
this.isSubmitting}

frontend/src/pages/org/archived-item-qa/archived-item-qa.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,11 +872,14 @@ export class ArchivedItemQA extends TailwindElement {
872872
placement="bottom-start"
873873
>
874874
<btrix-button
875-
icon
876-
variant=${!this.splitView ? "primary" : "neutral"}
875+
raised
876+
?filled=${!this.splitView}
877+
size="small"
877878
@click="${() => (this.splitView = !this.splitView)}"
879+
class="m-0.5"
880+
aria-pressed=${!this.splitView}
878881
>
879-
<sl-icon name="vr" label=${msg("Split view")}></sl-icon>
882+
<sl-icon name="vr"></sl-icon>
880883
</btrix-button>
881884
</sl-tooltip>
882885
</div>

frontend/src/pages/org/collection-detail.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,14 @@ export class CollectionDetail extends LiteElement {
300300
class="mb-2"
301301
.value="${publicReplayUrl}"
302302
hideContentFromScreenReaders
303+
hoist
303304
>
304-
<sl-tooltip slot="prefix" content=${msg("Open in New Tab")}>
305+
<sl-tooltip slot="prefix" content=${msg("Open in New Tab")} hoist>
305306
<sl-icon-button
306307
href=${publicReplayUrl}
307308
name="box-arrow-up-right"
308309
target="_blank"
310+
class="m-px"
309311
>
310312
</sl-icon-button>
311313
</sl-tooltip>
@@ -323,12 +325,11 @@ export class CollectionDetail extends LiteElement {
323325
</p>
324326
<div class="relative mb-5 rounded border bg-slate-50 p-3 pr-9">
325327
<btrix-code value=${embedCode}></btrix-code>
326-
<div
327-
class="absolute right-1.5 top-1.5 rounded border bg-white shadow-sm"
328-
>
328+
<div class="absolute right-1 top-1">
329329
<btrix-copy-button
330330
.getValue=${() => embedCode}
331331
content=${msg("Copy Embed Code")}
332+
hoist
332333
></btrix-copy-button>
333334
</div>
334335
</div>
@@ -340,12 +341,11 @@ export class CollectionDetail extends LiteElement {
340341
</p>
341342
<div class="relative mb-5 rounded border bg-slate-50 p-3 pr-9">
342343
<btrix-code language="javascript" value=${importCode}></btrix-code>
343-
<div
344-
class="absolute right-1.5 top-1.5 rounded border bg-white shadow-sm"
345-
>
344+
<div class="absolute right-1 top-1">
346345
<btrix-copy-button
347346
.getValue=${() => importCode}
348347
content=${msg("Copy JS")}
348+
hoist
349349
></btrix-copy-button>
350350
</div>
351351
</div>

0 commit comments

Comments
 (0)