import { Checkbox as CosmosCheckbox, CheckboxGroup, FieldValueList, Text, withConfiguration, BooleanDisplay } from '@pega/cosmos-react-core'; import type { PConnFieldProps } from './PConnProps'; import './create-nonce'; // includes in bundle import handleEvent from './event-utils'; import StyledPegaDxilMyBooleanWrapper from './styles'; // interface for props interface PegaDxilMyBooleanProps extends PConnFieldProps { // If any, enter additional props that only exist on TextInput here displayAsStatus?: boolean; isTableFormatter?: boolean; hasSuggestions?: boolean; variant?: any; formatter: string; caption: string; trueLabel: string; falseLabel: string; } // interface for StateProps object interface StateProps { value: string; hasSuggestions: boolean; } interface ActionsProps { onClick: any; } // Duplicated runtime code from Constellation Design System Component // props passed in combination of props from property panel (config.json) and run time props from Constellation // any default values in config.pros should be set in defaultProps at bottom of this file function PegaDxilMyBoolean(props: PegaDxilMyBooleanProps) { const { getPConnect, value = false, label = '', helperText = '', caption, validatemessage, hideLabel, testId, additionalProps = {}, displayMode, variant = 'inline', trueLabel, falseLabel } = props; const pConn = getPConnect(); const actions = pConn.getActionsApi(); const actionsProps = pConn.getActionsApi() as unknown as ActionsProps; const stateProps = pConn.getStateProps() as StateProps; const propName: string = stateProps.value; let { readOnly = false, required = false, disabled = false } = props; [readOnly, required, disabled] = [readOnly, required, disabled].map(prop => prop === true || (typeof prop === 'string' && prop === 'true')); let status: 'error' | 'success' | 'warning' | 'pending' | undefined; if (validatemessage !== '') { status = 'error'; } const aCosmosCheckbox = ( { handleEvent(actions, 'changeNblur', propName, event.target.checked); }} onBlur={(event: { target: { checked: any } }) => { pConn.getValidationApi().validate(event.target.checked); }} data-testid={testId} /> ); const parentTestId = testId === '' ? `${testId}-parent` : testId; let displayComponent; if (displayMode) { displayComponent = ; } if (displayMode === 'DISPLAY_ONLY') { return {displayComponent}; } if (displayMode === 'LABELS_LEFT') { return ( ); } if (displayMode === 'STACKED_LARGE_VAL') { return ( {displayComponent} ) } ]} /> ); } return ( {aCosmosCheckbox} ); } export default withConfiguration(PegaDxilMyBoolean);