Skip to content

Commit 605ba68

Browse files
committed
feat: Added target to LinkButton function
1 parent 0bb251c commit 605ba68

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/components/generic/Button.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ const speicalSyles = [ ButtonStyle.Spinner, ButtonStyle.Progress ];
1010
const enableTuple = (enabled: boolean, color = Color.Grayscaled) => [ Color.Disabled, color ][ enabled ? "values" : "reverse" ]() as [ Color, Color ];
1111

1212
export class ButtonComponent extends ColoredComponent {
13-
prog = createElement("div")
13+
prog = createElement("div");
1414
constructor(string: string | Component) {
1515
super();
1616
this.wrapper.tabIndex = speicalSyles.includes(ButtonStyle.Normal) ? -1 : accessibilityDisableTabOnDisabled();
17-
this.wrapper.classList.add("wbutton", Color.Grayscaled, ButtonStyle.Normal)
17+
this.wrapper.classList.add("wbutton", Color.Grayscaled, ButtonStyle.Normal);
1818
this.wrapper.append(loadingWheel());
19-
this.wrapper.onkeydown = accessibilityButton(this.wrapper)
19+
this.wrapper.onkeydown = accessibilityButton(this.wrapper);
2020
this.wrapper.append(typeof string == "string" ? string : string.draw());
2121
}
22-
setEnabled = (enabled: boolean) => this.wrapper.classList.replace(...enableTuple(enabled))
22+
setEnabled = (enabled: boolean) => this.wrapper.classList.replace(...enableTuple(enabled));
2323
setStyle(style: ButtonStyle, progress?: number) {
2424
this.wrapper.tabIndex = speicalSyles.includes(style) ? -1 : accessibilityDisableTabOnDisabled();
2525
changeClassAtIndex(this.wrapper, style, 2);
@@ -42,8 +42,10 @@ export class ButtonComponent extends ColoredComponent {
4242
this.wrapper.style.justifyContent = type;
4343
return this;
4444
}
45-
asLinkButton(link: string): ButtonComponent {
46-
this.wrapper.href = link;
45+
asLinkButton(url: string, target?: string) {
46+
this.wrapper.href = url;
47+
if (target)
48+
this.wrapper.target = target;
4749
return this;
4850
}
4951
setGrow(value = 1) {
@@ -53,19 +55,19 @@ export class ButtonComponent extends ColoredComponent {
5355
onPromiseClick(func: (env: MouseEvent, e: ButtonComponent) => Promise<void>) {
5456
this.onClick(async (env, e) => {
5557
const cssclass = this.wrapper.classList.item(2);
56-
this.setStyle(ButtonStyle.Spinner)
58+
this.setStyle(ButtonStyle.Spinner);
5759
await func(env, e);
5860
this.setStyle(cssclass as ButtonStyle);
59-
})
61+
});
6062
return this;
6163
}
6264
onClick(func: (env: MouseEvent, e: ButtonComponent) => void) {
6365
if (this.wrapper.classList.contains(Color.Disabled)) return this;
64-
this.wrapper.addEventListener('click', (e) => func(e, this))
66+
this.wrapper.addEventListener('click', (e) => func(e, this));
6567
return this;
6668
}
6769
setColor(color: Color) {
68-
this.setEnabled = (enabled: boolean) => this.wrapper.classList.replace(...enableTuple(enabled, color))
70+
this.setEnabled = (enabled: boolean) => this.wrapper.classList.replace(...enableTuple(enabled, color));
6971
this.wrapper.tabIndex = speicalSyles.includes(this.wrapper.classList[ 3 ] as ButtonStyle) ? -1 : accessibilityDisableTabOnDisabled(color);
7072
changeClassAtIndex(this.wrapper, color, 1);
7173
return this;

src/components/generic/IconButton.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ export class IconButtonComponent extends ColoredComponent {
1818
changeClassAtIndex(this.wrapper, color, 1);
1919
return this;
2020
}
21-
asLinkButton(url: string) {
21+
asLinkButton(url: string, target?: string) {
2222
this.wrapper.href = url;
23+
if (target)
24+
this.wrapper.target = target;
2325
return this;
2426
}
2527
setStyle(_style: ButtonStyle): this {

0 commit comments

Comments
 (0)