Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | 9x 39x 39x 15x 24x 24x 24x 24x 24x 9x 9x 9x 39x 39x 2x 2x 37x 37x 9x 39x 39x 39x 39x 39x 9x 9x | import React from 'react'; import PropTypes from 'prop-types'; import { ControlGroup, ControlLabel, getAssistiveText, PlainText, } from 'src/elements/forms/utils'; import { removeSomeProps } from 'src/utils/componentHelpers'; import { defaultControlStyles } from 'src/utils/styledHelpers'; import { CheckboxFieldComponent } from './component'; const renderControlGroupLabel = propsFromControlGroup => { const { activeColor, bg, controlId, controlLabelProps, disabled, labelText, plainText, isRequired, validationError, } = propsFromControlGroup; if (!labelText) { return null; } const labelCaption = !isRequired ? labelText : `${labelText}*`; const defaultPositionProps = { height: 'auto', position: 'relative', top: 'auto', }; const positionProps = !plainText ? defaultPositionProps : ''; const labelProps = { activeColor, bg, ...controlLabelProps, disabled, htmlFor: controlId, validationError, ...positionProps, }; return ( <ControlLabel {...labelProps}> {labelCaption} </ControlLabel> ); }; const propsToTrim = [ 'activeColor', 'assistiveText', 'assistiveTextProps', 'bg', 'controlGroupProps', 'controlId', 'controlLabelProps', 'isRequired', 'labelText', 'plainText', 'validationError', ]; const plainTextPropsToTrim = [ 'flexDirection', 'name', 'onChange', 'options', 'wrapperProps', ...propsToTrim, ]; const renderValueOrComponent = propsFromComponent => { const { controlId, defaultValue, disabled, flexDirection, plainText, value, } = propsFromComponent; if (plainText) { const plainTextProps = { ...removeSomeProps(propsFromComponent, plainTextPropsToTrim), }; return (<PlainText {...plainTextProps} />); } const childProps = { id: controlId, ...removeSomeProps(propsFromComponent, propsToTrim) }; return ( <CheckboxFieldComponent {...childProps} disabled={disabled} flexDirection={flexDirection} value={value || defaultValue} /> ); }; const CheckboxField = props => { const { activeColor, assistiveText, assistiveTextProps, bg, controlGroupProps, controlId, controlLabelProps, disabled, isRequired, labelText, plainText, validationError, } = props; const additionalControlGroupProps = { ...controlGroupProps, controlId, }; const labelProps = { activeColor, bg, controlId, controlLabelProps, disabled, isRequired, labelText, plainText, validationError, }; const assistiveProps = { assistiveText, isRequired }; return ( <ControlGroup {...additionalControlGroupProps} assistiveText={getAssistiveText(assistiveProps)} assistiveTextProps={assistiveTextProps} validationError={validationError} > {renderControlGroupLabel(labelProps)} {renderValueOrComponent({ ...props, plainText })} </ControlGroup> ); }; CheckboxField.propTypes = { /** Defines the color for the label and border color when the focus is in the control. */ activeColor: PropTypes.string, /** Provides helper text for the control. When provided with no `assistiveText`, `isRequired` will add a default '*Required` helper text. When provided with `validationError`, `assistiveText`'s value will not be displayed on the UI. */ assistiveText: PropTypes.oneOfType([ PropTypes.object, PropTypes.string, ]), /** Allows for custom props to be passed down to the `AsssistiveText` component. */ assistiveTextProps: PropTypes.object, bg: PropTypes.string, /** Allows for custom props to be passed down to the `ControlGroup` component. */ controlGroupProps: PropTypes.object, /** Will pass its value to the control's `id` as well as the label's `htmlFor`. * @deprecated Do not use! Use `name` instead! */ controlId: PropTypes.string, /** Allows for custom props to be passed down to the `ControlLabel` component. */ controlLabelProps: PropTypes.object, /** Basic HTML attribute, needed for styling. */ disabled: PropTypes.bool, flexDirection: PropTypes.oneOfType([ PropTypes.string, PropTypes.array, ]), fontFamily: PropTypes.string, /** This will add an asterisk (*) to the `labelText` and provided `assistiveText` if none is provided. */ isRequired: PropTypes.bool, /** The string value displayed on top of the control in the `ControlLabel` component. */ labelText: PropTypes.string, /** Used to render a dropdown control as a `PlainText` element. */ plainText: PropTypes.bool, /** Error text that will appear below the control when validation fires. */ validationError: PropTypes.oneOfType([ PropTypes.bool, PropTypes.string, ]), /** Allows for custom props to be passed down to the `CheckboxGroupWrapper` component. */ wrapperProps: PropTypes.object, }; CheckboxField.defaultProps = { activeColor: defaultControlStyles.activeColor, assistiveText: '', assistiveTextProps: {}, bg: defaultControlStyles.bg, controlGroupProps: {}, controlId: '', controlLabelProps: {}, disabled: false, flexDirection: 'column', fontFamily: 'base', isRequired: false, labelText: '', plainText: false, validationError: '', wrapperProps: {}, }; /** @component */ export { CheckboxField }; |