11import * as React from 'react' ;
2- import styles from '@patternfly/react-styles/css/components/Check/check' ;
3- import { css } from '@patternfly/react-styles' ;
42import { PickOptional } from '../../helpers/typeUtils' ;
5- import { getOUIAProps , OUIAProps , getDefaultOUIAId } from '../../helpers' ;
3+ import { OUIAProps } from '../../helpers' ;
4+ import { Checkbox } from '../Checkbox' ;
65
76export interface MenuToggleCheckboxProps
87 extends Omit < React . HTMLProps < HTMLInputElement > , 'type' | 'onChange' | 'disabled' | 'checked' > ,
@@ -33,7 +32,7 @@ export interface MenuToggleCheckboxProps
3332 ouiaSafe ?: boolean ;
3433}
3534
36- class MenuToggleCheckbox extends React . Component < MenuToggleCheckboxProps , { ouiaStateId : string } > {
35+ class MenuToggleCheckbox extends React . Component < MenuToggleCheckboxProps > {
3736 static displayName = 'MenuToggleCheckbox' ;
3837 static defaultProps : PickOptional < MenuToggleCheckboxProps > = {
3938 isValid : true ,
@@ -43,66 +42,24 @@ class MenuToggleCheckbox extends React.Component<MenuToggleCheckboxProps, { ouia
4342
4443 constructor ( props : MenuToggleCheckboxProps ) {
4544 super ( props ) ;
46- this . state = {
47- ouiaStateId : getDefaultOUIAId ( MenuToggleCheckbox . displayName )
48- } ;
4945 }
5046
51- handleChange = ( event : React . FormEvent < HTMLInputElement > ) => {
52- this . props . onChange ( ( event . target as HTMLInputElement ) . checked , event ) ;
53- } ;
54-
55- calculateChecked = ( ) => {
56- const { isChecked, defaultChecked } = this . props ;
57- if ( isChecked === null ) {
58- // return false here and the indeterminate state will be set to true through the ref
59- return false ;
60- } else if ( isChecked !== undefined ) {
61- return isChecked ;
62- }
63- return defaultChecked ;
64- } ;
65-
6647 render ( ) {
6748 const {
68- className,
69- isValid,
70- isDisabled,
71- isChecked,
7249 children,
73- ouiaId,
74- ouiaSafe,
7550 /* eslint-disable @typescript-eslint/no-unused-vars */
7651 onChange,
77- defaultChecked,
78- id,
7952 ...props
8053 } = this . props ;
81- const text = children && (
82- < span className = { css ( styles . checkLabel , className ) } aria-hidden = "true" id = { id } >
83- { children }
84- </ span >
85- ) ;
54+
8655 return (
87- < label className = { css ( styles . check , ! children && styles . modifiers . standalone , className ) } htmlFor = { id } >
88- < input
89- className = { css ( styles . checkInput ) }
90- { ...( this . calculateChecked ( ) !== undefined && { onChange : this . handleChange } ) }
91- name = { id }
92- type = "checkbox"
93- ref = { ( elem ) => elem && ( elem . indeterminate = isChecked === null ) }
94- aria-invalid = { ! isValid }
95- disabled = { isDisabled }
96- { ...( defaultChecked !== undefined ? { defaultChecked } : { checked : isChecked } ) }
97- { ...getOUIAProps (
98- MenuToggleCheckbox . displayName ,
99- ouiaId !== undefined ? ouiaId : this . state . ouiaStateId ,
100- ouiaSafe
101- ) }
102- { ...props }
103- />
104- { text }
105- </ label >
56+ // @ts -ignore
57+ < Checkbox
58+ onChange = { ( event : React . FormEvent < HTMLInputElement > , checked : boolean ) => onChange ( checked , event ) }
59+ isLabelWrapped
60+ label = { children }
61+ { ...props }
62+ > </ Checkbox >
10663 ) ;
10764 }
10865}
0 commit comments