Skip to content

Commit 703fca1

Browse files
committed
Switch needs configurable thumb
1 parent d6bc0ae commit 703fca1

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

ember-primitives/src/components/-private/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* otherwise fallback to the uncontrolled toggle
44
*/
55
export function toggleWithFallback(
6-
uncontrolledToggle: (...args: unknown[]) => void,
7-
6+
uncontrolledToggle: undefined | ((...args: any[]) => void) | (() => void),
87
controlledToggle?: (...args: any[]) => void,
98
...args: unknown[]
109
) {
1110
if (controlledToggle) {
1211
return controlledToggle(...args);
1312
}
1413

15-
uncontrolledToggle(...args);
14+
uncontrolledToggle?.(...args);
1615
}

ember-primitives/src/components/switch.gts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,38 @@ export interface Signature {
6565

6666
interface ControlSignature {
6767
Element: HTMLInputElement;
68-
Args: { id: string; checked?: boolean; onChange: () => void };
68+
Args: { id: string; checked?: ReturnType<typeof cell<boolean>>; onChange: () => void };
6969
}
7070

7171
const Checkbox: TOC<ControlSignature> = <template>
72-
{{#let (cell @checked) as |checked|}}
73-
<input
74-
id={{@id}}
75-
type="checkbox"
76-
role="switch"
77-
checked={{checked.current}}
78-
aria-checked={{checked.current}}
79-
data-state={{if checked.current "on" "off"}}
80-
{{on "click" (fn toggleWithFallback checked.toggle @onChange)}}
81-
...attributes
82-
/>
83-
{{/let}}
72+
<input
73+
id={{@id}}
74+
type="checkbox"
75+
role="switch"
76+
checked={{@checked.current}}
77+
aria-checked={{@checked.current}}
78+
data-state={{if @checked.current "on" "off"}}
79+
{{on "click" (fn toggleWithFallback @checked.toggle @onChange)}}
80+
...attributes
81+
/>
8482
</template>;
8583

8684
/**
8785
* @public
8886
*/
8987
export const Switch: TOC<Signature> = <template>
9088
<div ...attributes data-prim-switch>
91-
{{! @glint-nocheck }}
9289
{{#let (uniqueId) as |id|}}
93-
{{yield
94-
(hash
95-
Control=(component Checkbox checked=@checked id=id onChange=@onChange)
96-
Label=(component Label for=id)
97-
)
98-
}}
90+
{{#let (cell @checked) as |checked|}}
91+
{{! @glint-nocheck }}
92+
{{yield
93+
(hash
94+
isChecked=checked.current
95+
Control=(component Checkbox checked=checked id=id onChange=@onChange)
96+
Label=(component Label for=id)
97+
)
98+
}}
99+
{{/let}}
99100
{{/let}}
100101
</div>
101102
</template>;

0 commit comments

Comments
 (0)