File tree Expand file tree Collapse file tree
ember-primitives/src/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 * otherwise fallback to the uncontrolled toggle
44 */
55export 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}
Original file line number Diff line number Diff line change @@ -65,37 +65,38 @@ export interface Signature {
6565
6666interface 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
7171const 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 */
8987export 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 >;
You can’t perform that action at this time.
0 commit comments