From ea61a1949c24b5d3b2f0caee0b1d58660e96ecc5 Mon Sep 17 00:00:00 2001 From: Andy Vo Date: Mon, 6 Jun 2022 21:47:46 -0400 Subject: [PATCH 1/4] chore(Form): completed conversion of form examples to ts --- .../src/components/Form/FormGroup.tsx | 2 +- .../src/components/Form/examples/Form.md | 1283 +---------------- .../components/Form/examples/FormBasic.tsx | 122 ++ .../Form/examples/FormFieldGroups.tsx | 324 +++++ .../src/components/Form/examples/FormGrid.tsx | 66 + .../Form/examples/FormGroupLabelInfo.tsx | 72 + .../Form/examples/FormHorizontal.tsx | 112 ++ .../Form/examples/FormHorizontalHelper.tsx | 15 + .../Form/examples/FormHorizontalStacked.tsx | 11 + .../components/Form/examples/FormInvalid.tsx | 47 + .../examples/FormInvalidWithFormAlert.tsx | 52 + .../Form/examples/FormLimitWidth.tsx | 122 ++ .../components/Form/examples/FormSections.tsx | 44 + .../Form/examples/FormValidated.tsx | 60 + 14 files changed, 1060 insertions(+), 1272 deletions(-) create mode 100644 packages/react-core/src/components/Form/examples/FormBasic.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormFieldGroups.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormGrid.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormGroupLabelInfo.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormHorizontal.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormHorizontalHelper.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormHorizontalStacked.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormInvalid.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormInvalidWithFormAlert.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormLimitWidth.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormSections.tsx create mode 100644 packages/react-core/src/components/Form/examples/FormValidated.tsx diff --git a/packages/react-core/src/components/Form/FormGroup.tsx b/packages/react-core/src/components/Form/FormGroup.tsx index 77139da4011..0bf029f3c75 100644 --- a/packages/react-core/src/components/Form/FormGroup.tsx +++ b/packages/react-core/src/components/Form/FormGroup.tsx @@ -40,7 +40,7 @@ export interface FormGroupProps extends Omit, 'l /** Icon displayed to the left of the helper text when the field is invalid. */ helperTextInvalidIcon?: React.ReactNode; /** ID of the included field. It has to be the same for proper working. */ - fieldId: string; + fieldId?: string; /** Sets the role of the form group. Pass in "radiogroup" when the form group contains multiple * radio inputs, or pass in "group" when the form group contains multiple of any other input type. */ diff --git a/packages/react-core/src/components/Form/examples/Form.md b/packages/react-core/src/components/Form/examples/Form.md index 3f70a41d01d..5a2edfe76d9 100644 --- a/packages/react-core/src/components/Form/examples/Form.md +++ b/packages/react-core/src/components/Form/examples/Form.md @@ -42,1319 +42,60 @@ import TrashIcon from '@patternfly/react-icons/dist/esm/icons/trash-icon'; ### Basic -```js -import React from 'react'; -import { Form, FormGroup, TextInput, Checkbox, Popover, ActionGroup, Button, Radio } from '@patternfly/react-core'; -import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon'; - -class SimpleForm extends React.Component { - constructor(props) { - super(props); - this.state = { - value1: '', - value2: '', - value3: '' - }; - this.handleTextInputChange1 = value1 => { - this.setState({ value1 }); - }; - this.handleTextInputChange2 = value2 => { - this.setState({ value2 }); - }; - this.handleTextInputChange3 = value3 => { - this.setState({ value3 }); - }; - } - - render() { - const { value1, value2, value3 } = this.state; - - return ( -
- - The{' '} - - name - {' '} - of a{' '} - - Person - - - } - bodyContent={ -
- Often composed of{' '} - - givenName - {' '} - and{' '} - - familyName - - . -
- } - > - - - } - isRequired - fieldId="simple-form-name-01" - helperText="Include your middle name if you have one." - > - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- ); - } -} +```ts file="./FormBasic.tsx" ``` ### Horizontal -```js -import React from 'react'; -import { - Form, - FormGroup, - TextInput, - TextArea, - FormSelect, - FormSelectOption, - Checkbox, - ActionGroup, - Button, - Radio -} from '@patternfly/react-core'; - -class HorizontalForm extends React.Component { - constructor(props) { - super(props); - this.state = { - value: 'please choose', - value1: '', - value2: '', - value3: '' - }; - this.onChange = (value, event) => { - this.setState({ value }); - }; - this.handleTextInputChange1 = value1 => { - this.setState({ value1 }); - }; - this.handleTextInputChange2 = value2 => { - this.setState({ value2 }); - }; - this.handleTextInputChange3 = value3 => { - this.setState({ value3 }); - }; - this.options = [ - { value: 'select one', label: 'Select one', disabled: false }, - { value: 'mr', label: 'Mr', disabled: false }, - { value: 'miss', label: 'Miss', disabled: false }, - { value: 'mrs', label: 'Mrs', disabled: false }, - { value: 'ms', label: 'Ms', disabled: false }, - { value: 'dr', label: 'Dr', disabled: false }, - { value: 'other', label: 'Other', disabled: false } - ]; - } - - render() { - const { value1, value2, value3 } = this.state; - - return ( -
- - - - - - - - - {this.options.map((option, index) => ( - - ))} - - - -