Skip to content

Commit f424ed5

Browse files
Updated builder with spread pattern; deleted unused interface declaration from component.
1 parent 1121fb5 commit f424ed5

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

src/ak-switch/ak-switch.builder.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1+
import type { ElementRest } from "../types.js";
12
import { SwitchInput } from "./ak-switch.js";
23

4+
import { spread } from "@open-wc/lit-helpers";
5+
36
import { html, TemplateResult } from "lit";
47
import { ifDefined } from "lit/directives/if-defined.js";
58

69
/**
710
* Configuration options for the akSwitch helper function
811
*/
9-
export type SwitchProps = Partial<
10-
Pick<
11-
SwitchInput,
12-
| "name"
13-
| "checked"
14-
| "required"
15-
| "disabled"
16-
| "value"
17-
| "useCheck"
18-
| "showLabel"
19-
| "ariaLabel"
20-
>
21-
> & {
22-
label?: TemplateResult | string;
23-
labelOn?: TemplateResult | string;
24-
icon?: TemplateResult | string;
25-
reverse?: boolean;
26-
};
12+
export type SwitchProps = ElementRest &
13+
Partial<
14+
Pick<
15+
SwitchInput,
16+
| "name"
17+
| "checked"
18+
| "required"
19+
| "disabled"
20+
| "value"
21+
| "useCheck"
22+
| "showLabel"
23+
| "ariaLabel"
24+
>
25+
> & {
26+
label?: TemplateResult | string;
27+
labelOn?: TemplateResult | string;
28+
icon?: TemplateResult | string;
29+
reverse?: boolean;
30+
};
2731

2832
/**
2933
* @summary Helper function to create a Switch component programmatically
@@ -46,6 +50,7 @@ export function akSwitch(options: SwitchProps = {}): TemplateResult {
4650
label,
4751
labelOn,
4852
icon,
53+
...rest
4954
} = options;
5055

5156
const intoSlot = (slot: string, s?: TemplateResult | string) =>
@@ -60,6 +65,7 @@ export function akSwitch(options: SwitchProps = {}): TemplateResult {
6065
//
6166
return html`
6267
<ak-switch
68+
${spread(rest)}
6369
name=${ifDefined(name)}
6470
?checked=${Boolean(checked)}
6571
?required=${Boolean(required)}

src/ak-switch/ak-switch.component.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ import { html, nothing, PropertyValues, TemplateResult } from "lit";
1010
import { property } from "lit/decorators.js";
1111
import { ifDefined } from "lit/directives/if-defined.js";
1212

13-
export interface ISwitchInput {
14-
name?: string;
15-
checked: boolean;
16-
required: boolean;
17-
disabled: boolean;
18-
value?: string | null;
19-
useCheck: boolean;
20-
showLabel: boolean;
21-
ariaLabel: string | null;
22-
}
23-
2413
const CHECK_ICON = "fas fa-check";
2514

2615
/**
@@ -63,7 +52,7 @@ const CHECK_ICON = "fas fa-check";
6352
* @cssprop --pf-v5-c-switch__icon--FontSize - Font size of the check icon
6453
* @cssprop --pf-v5-c-switch__icon--Color - Color of the check icon
6554
*/
66-
export class SwitchInput extends FormAssociatedBooleanMixin(AkLitElement) implements ISwitchInput {
55+
export class SwitchInput extends FormAssociatedBooleanMixin(AkLitElement) {
6756
static readonly styles = [styles];
6857

6958
@property({ type: Boolean, attribute: "use-check" })

src/ak-switch/ak-switch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { akSwitch, type SwitchProps } from "./ak-switch.builder.js";
2-
import { type ISwitchInput, SwitchInput } from "./ak-switch.component.js";
2+
import { SwitchInput } from "./ak-switch.component.js";
33

4-
export { akSwitch, type ISwitchInput, SwitchInput, type SwitchProps };
4+
export { akSwitch, SwitchInput, type SwitchProps };
55

66
window.customElements.define("ak-switch", SwitchInput);
77

0 commit comments

Comments
 (0)