-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1177 from sgratch/pf5-mig-replace-formgroup-with-…
…formGroupWithHelpText 🐾 Update to PF5 - part 1
- Loading branch information
Showing
31 changed files
with
283 additions
and
218 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/common/src/components/FormGroupWithHelpText/FormGroupWithHelpText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
FormGroup, | ||
FormGroupProps, | ||
FormHelperText, | ||
HelperText, | ||
HelperTextItem, | ||
} from '@patternfly/react-core'; | ||
|
||
export interface FormGroupWithHelpTextProps extends FormGroupProps { | ||
/** | ||
* Sets the FormGroup validated. If you set to success, text color of helper text will be modified to indicate valid state. | ||
* If set to error, text color of helper text will be modified to indicate error state. | ||
* If set to warning, text color of helper text will be modified to indicate warning state. | ||
*/ | ||
validated?: 'success' | 'warning' | 'error' | 'default'; | ||
/** | ||
* Helper text regarding the field. It can be a simple text or an object. | ||
*/ | ||
helperText?: React.ReactNode; | ||
/** | ||
* Helper text after the field when the field is invalid. It can be a simple text or an object. | ||
*/ | ||
helperTextInvalid?: React.ReactNode; | ||
} | ||
|
||
/** | ||
* Convert the formGroup validated mode into the variant styling of the helper text item | ||
* If validated mode was not set or if it's the 'default', set the variant styling to 'indeterminate' | ||
* for being consistent with PF4 behavior | ||
*/ | ||
const validatedToVariant = (validated) => | ||
!validated || validated === 'default' ? 'indeterminate' : validated; | ||
|
||
/** | ||
* A FormGroup component that supports helperTexts | ||
* | ||
* This component wraps the FormGroup with an option to use the following helper text related properties | ||
* (since not supported anymore as part of the FormGroup component in PatternFly 5): | ||
* helperText, helperTextInvalid, validated | ||
* | ||
* `See` https://www.patternfly.org/get-started/release-highlights/#helper-text | ||
* | ||
* [<img src="static/media/src/components-stories/assets/github-logo.svg"><i class="fi fi-brands-github"> | ||
* <font color="green">View component source on GitHub</font>](https://github.com/kubev2v/forklift-console-plugin/blob/main/packages/common/src/components/FormGroupWithHelpText/FormGroupWithHelpText.tsx) | ||
*/ | ||
export const FormGroupWithHelpText: React.FC<FormGroupWithHelpTextProps> = ({ | ||
label, | ||
isRequired, | ||
fieldId, | ||
labelIcon, | ||
role, | ||
children, | ||
validated, | ||
helperText, | ||
helperTextInvalid, | ||
}) => { | ||
const helperTextMsg = validated === 'error' && helperTextInvalid ? helperTextInvalid : helperText; | ||
const variant = validatedToVariant(validated); | ||
|
||
return ( | ||
<FormGroup | ||
label={label} | ||
isRequired={isRequired} | ||
fieldId={fieldId} | ||
labelIcon={labelIcon} | ||
role={role} | ||
> | ||
{children} | ||
<FormHelperText isHidden={false}> | ||
<HelperText> | ||
<HelperTextItem variant={variant}>{helperTextMsg}</HelperTextItem> | ||
</HelperText> | ||
</FormHelperText> | ||
</FormGroup> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/common/src/components/FormGroupWithHelpText/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @index(['./*', /__/g], f => `export * from '${f.path}';`) | ||
export * from './FormGroupWithHelpText'; | ||
// @endindex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.