1. children: PropTypes.node,
    2. // type can be things like text, password, (typical input types) as well as select and textarea, providing children as you normally would to those.
    3. type: PropTypes.string,
    4. size: PropTypes.string,
    5. bsSize: PropTypes.string,
    6. state: deprecated(PropTypes.string, 'Please use the prop "valid"'),
    7. valid: PropTypes.bool, // applied the is-valid class when true, does nothing when false
    8. invalid: PropTypes.bool, // applied the is-invalid class when true, does nothing when false
    9. tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
    10. // ref will only get you a reference to the Input component, use innerRef to get a reference to the DOM input (for things like focus management).
    11. innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
    12. static: deprecated(PropTypes.bool, 'Please use the prop "plaintext"'),
    13. plaintext: PropTypes.bool,
    14. addon: PropTypes.bool,
    15. className: PropTypes.string,
    16. cssModule: PropTypes.object,
    17. };
    18. CustomInput.propTypes = {
    19. className: PropTypes.string,
    20. id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
    21. type: PropTypes.string.isRequired, // radio, checkbox, select, range.
    22. label: PropTypes.string, // used for checkbox and radios
    23. inline: PropTypes.bool,
    24. valid: PropTypes.bool, // applied the is-valid class when true, does nothing when false
    25. invalid: PropTypes.bool, // applied the is-invalid class when true, does nothing when false
    26. bsSize: PropTypes.string,
    27. cssModule: PropTypes.object,
    28. children: PropTypes.oneOfType([PropTypes.node, PropTypes.array, PropTypes.func]), // for type="select"
    29. // innerRef would be referenced to select node or input DOM node, depends on type property
    30. innerRef: PropTypes.oneOfType([
    31. PropTypes.object,
    32. PropTypes.string,
    33. PropTypes.func,
    34. ])
    35. };
    36. Form.propTypes = {
    37. children: PropTypes.node,
    38. inline: PropTypes.bool,
    39. // Pass in a Component to override default element
    40. tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), // default: 'form'
    41. innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
    42. className: PropTypes.string,
    43. cssModule: PropTypes.object,
    44. };
    45. FormFeedback.propTypes = {
    46. children: PropTypes.node,
    47. // Pass in a Component to override default element
    48. tag: PropTypes.string, // default: 'div'
    49. className: PropTypes.string,
    50. cssModule: PropTypes.object,
    51. valid: PropTypes.bool, // default: undefined
    52. tooltip: PropTypes.bool
    53. };
    54. FormGroup.propTypes = {
    55. children: PropTypes.node,
    56. // Applied the row class when true, does nothing when false
    57. row: PropTypes.bool,
    58. // Applied the form-check class when true, form-group when false
    59. check: PropTypes.bool,
    60. inline: PropTypes.bool,
    61. // Applied the disabled class when the check and disabled props are true, does nothing when false
    62. disabled: PropTypes.bool,
    63. // Pass in a Component to override default element
    64. tag: PropTypes.string, // default: 'div'
    65. className: PropTypes.string,
    66. cssModule: PropTypes.object,
    67. };
    68. FormText.propTypes = {
    69. children: PropTypes.node,
    70. inline: PropTypes.bool,
    71. // Pass in a Component to override default element
    72. tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), // default: 'small'
    73. color: PropTypes.string, // default: 'muted'
    74. className: PropTypes.string,
    75. cssModule: PropTypes.object,
    76. };

    Form Grid

    1. import React from 'react';
    2. import { Col, Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap';
    3. export default class Example extends React.Component {
    4. render() {
    5. return (
    6. <Form>
    7. <FormGroup row>
    8. <Label for="exampleEmail" sm={2}>Email</Label>
    9. <Col sm={10}>
    10. <Input type="email" name="email" id="exampleEmail" placeholder="with a placeholder" />
    11. </Col>
    12. </FormGroup>
    13. <FormGroup row>
    14. <Label for="examplePassword" sm={2}>Password</Label>
    15. <Col sm={10}>
    16. <Input type="password" name="password" id="examplePassword" placeholder="password placeholder" />
    17. </Col>
    18. </FormGroup>
    19. <FormGroup row>
    20. <Label for="exampleSelect" sm={2}>Select</Label>
    21. <Col sm={10}>
    22. <Input type="select" name="select" id="exampleSelect" />
    23. </Col>
    24. </FormGroup>
    25. <FormGroup row>
    26. <Label for="exampleSelectMulti" sm={2}>Select Multiple</Label>
    27. <Col sm={10}>
    28. <Input type="select" name="selectMulti" id="exampleSelectMulti" multiple />
    29. </Col>
    30. </FormGroup>
    31. <FormGroup row>
    32. <Label for="exampleText" sm={2}>Text Area</Label>
    33. <Col sm={10}>
    34. <Input type="textarea" name="text" id="exampleText" />
    35. </Col>
    36. </FormGroup>
    37. <FormGroup row>
    38. <Label for="exampleFile" sm={2}>File</Label>
    39. <Col sm={10}>
    40. <Input type="file" name="file" id="exampleFile" />
    41. <FormText color="muted">
    42. This is some placeholder block-level help text for the above input.
    43. It's a bit lighter and easily wraps to a new line.
    44. </FormText>
    45. </Col>
    46. </FormGroup>
    47. <FormGroup tag="fieldset" row>
    48. <legend className="col-form-label col-sm-2">Radio Buttons</legend>
    49. <Col sm={10}>
    50. <FormGroup check>
    51. <Label check>
    52. <Input type="radio" name="radio2" />{' '}
    53. Option one is this and that—be sure to include why it's great
    54. </Label>
    55. </FormGroup>
    56. <FormGroup check>
    57. <Label check>
    58. <Input type="radio" name="radio2" />{' '}
    59. Option two can be something else and selecting it will deselect option one
    60. </Label>
    61. </FormGroup>
    62. <FormGroup check disabled>
    63. <Label check>
    64. <Input type="radio" name="radio2" disabled />{' '}
    65. Option three is disabled
    66. </Label>
    67. </FormGroup>
    68. </Col>
    69. </FormGroup>
    70. <FormGroup row>
    71. <Label for="checkbox2" sm={2}>Checkbox</Label>
    72. <Col sm={{ size: 10 }}>
    73. <FormGroup check>
    74. <Label check>
    75. <Input type="checkbox" id="checkbox2" />{' '}
    76. Check me out
    77. </Label>
    78. </FormGroup>
    79. </Col>
    80. </FormGroup>
    81. <FormGroup check row>
    82. <Col sm={{ size: 10, offset: 2 }}>
    83. <Button>Submit</Button>
    84. </Col>
    85. </FormGroup>
    86. </Form>
    87. );
    88. }
    89. }

    Form Grid with Form Row

    Form - 图1

    1. import React from 'react';
    2. import { Col, Row, Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap';
    3. export default class Example extends React.Component {
    4. render() {
    5. return (
    6. <Form>
    7. <Row form>
    8. <Col md={6}>
    9. <FormGroup>
    10. <Label for="exampleEmail">Email</Label>
    11. <Input type="email" name="email" id="exampleEmail" placeholder="with a placeholder" />
    12. </FormGroup>
    13. </Col>
    14. <Col md={6}>
    15. <FormGroup>
    16. <Input type="password" name="password" id="examplePassword" placeholder="password placeholder" />
    17. </FormGroup>
    18. </Col>
    19. </Row>
    20. <FormGroup>
    21. <Label for="exampleAddress">Address</Label>
    22. <Input type="text" name="address" id="exampleAddress" placeholder="1234 Main St"/>
    23. <FormGroup>
    24. <Label for="exampleAddress2">Address 2</Label>
    25. <Input type="text" name="address2" id="exampleAddress2" placeholder="Apartment, studio, or floor"/>
    26. </FormGroup>
    27. <Row form>
    28. <Col md={6}>
    29. <FormGroup>
    30. <Label for="exampleCity">City</Label>
    31. <Input type="text" name="city" id="exampleCity"/>
    32. </FormGroup>
    33. </Col>
    34. <Col md={4}>
    35. <FormGroup>
    36. <Label for="exampleState">State</Label>
    37. <Input type="text" name="state" id="exampleState"/>
    38. </FormGroup>
    39. </Col>
    40. <Col md={2}>
    41. <FormGroup>
    42. <Label for="exampleZip">Zip</Label>
    43. <Input type="text" name="zip" id="exampleZip"/>
    44. </FormGroup>
    45. </Col>
    46. </Row>
    47. <FormGroup check>
    48. <Input type="checkbox" name="check" id="exampleCheck"/>
    49. <Label for="exampleCheck" check>Check me out</Label>
    50. </FormGroup>
    51. <Button>Sign in</Button>
    52. </Form>
    53. );
    54. }
    55. }

    Form Validation

    1. import React from 'react';
    2. import { Form, FormGroup, Label, Input, FormFeedback, FormText } from 'reactstrap';
    3. export default class Example extends React.Component {
    4. render() {
    5. return (
    6. <Form>
    7. <FormGroup>
    8. <Label for="exampleEmail">Input without validation</Label>
    9. <Input />
    10. <FormFeedback>You will not be able to see this</FormFeedback>
    11. <FormText>Example help text that remains unchanged.</FormText>
    12. </FormGroup>
    13. <FormGroup>
    14. <Label for="exampleEmail">Valid input</Label>
    15. <Input valid />
    16. <FormFeedback valid>Sweet! that name is available</FormFeedback>
    17. <FormText>Example help text that remains unchanged.</FormText>
    18. </FormGroup>
    19. <FormGroup>
    20. <Label for="examplePassword">Invalid input</Label>
    21. <Input invalid />
    22. <FormFeedback>Oh noes! that name is already taken</FormFeedback>
    23. <FormText>Example help text that remains unchanged.</FormText>
    24. </FormGroup>
    25. <FormGroup>
    26. <Label for="exampleEmail">Input without validation</Label>
    27. <Input />
    28. <FormFeedback tooltip>You will not be able to see this</FormFeedback>
    29. <FormText>Example help text that remains unchanged.</FormText>
    30. </FormGroup>
    31. <FormGroup>
    32. <Label for="exampleEmail">Valid input</Label>
    33. <Input valid />
    34. <FormFeedback valid tooltip>Sweet! that name is available</FormFeedback>
    35. <FormText>Example help text that remains unchanged.</FormText>
    36. </FormGroup>
    37. <FormGroup>
    38. <Label for="examplePassword">Invalid input</Label>
    39. <Input invalid />
    40. <FormFeedback tooltip>Oh noes! that name is already taken</FormFeedback>
    41. <FormText>Example help text that remains unchanged.</FormText>
    42. </FormGroup>
    43. </Form>
    44. );
    45. }
    46. }

    Input Types

    Form - 图2

    1. import React from 'react';
    2. import { Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap';
    3. export default class Example extends React.Component {
    4. render() {
    5. return (
    6. <Form>
    7. <FormGroup>
    8. <Label for="exampleEmail">Plain Text (Static)</Label>
    9. <Input plaintext value="Some plain text/ static value" />
    10. </FormGroup>
    11. <FormGroup>
    12. <Label for="exampleEmail">Email</Label>
    13. <Input
    14. type="email"
    15. name="email"
    16. id="exampleEmail"
    17. placeholder="with a placeholder"
    18. />
    19. </FormGroup>
    20. <FormGroup>
    21. <Label for="examplePassword">Password</Label>
    22. <Input
    23. type="password"
    24. name="password"
    25. id="examplePassword"
    26. placeholder="password placeholder"
    27. />
    28. </FormGroup>
    29. <FormGroup>
    30. <Label for="exampleUrl">Url</Label>
    31. <Input
    32. type="url"
    33. name="url"
    34. id="exampleUrl"
    35. placeholder="url placeholder"
    36. />
    37. </FormGroup>
    38. <FormGroup>
    39. <Label for="exampleNumber">Number</Label>
    40. <Input
    41. type="number"
    42. name="number"
    43. id="exampleNumber"
    44. placeholder="number placeholder"
    45. />
    46. </FormGroup>
    47. <FormGroup>
    48. <Label for="exampleDatetime">Datetime</Label>
    49. <Input
    50. type="datetime"
    51. name="datetime"
    52. id="exampleDatetime"
    53. placeholder="datetime placeholder"
    54. />
    55. </FormGroup>
    56. <FormGroup>
    57. <Label for="exampleDate">Date</Label>
    58. <Input
    59. type="date"
    60. name="date"
    61. id="exampleDate"
    62. placeholder="date placeholder"
    63. />
    64. </FormGroup>
    65. <FormGroup>
    66. <Label for="exampleTime">Time</Label>
    67. <Input
    68. type="time"
    69. name="time"
    70. id="exampleTime"
    71. placeholder="time placeholder"
    72. />
    73. </FormGroup>
    74. <FormGroup>
    75. <Label for="exampleColor">Color</Label>
    76. <Input
    77. type="color"
    78. name="color"
    79. id="exampleColor"
    80. placeholder="color placeholder"
    81. />
    82. </FormGroup>
    83. <FormGroup>
    84. <Label for="exampleSearch">Search</Label>
    85. <Input
    86. type="search"
    87. name="search"
    88. id="exampleSearch"
    89. placeholder="search placeholder"
    90. />
    91. </FormGroup>
    92. <FormGroup>
    93. <Label for="exampleSelect">Select</Label>
    94. <Input type="select" name="select" id="exampleSelect">
    95. <option>1</option>
    96. <option>2</option>
    97. <option>3</option>
    98. <option>4</option>
    99. <option>5</option>
    100. </Input>
    101. </FormGroup>
    102. <FormGroup>
    103. <Label for="exampleSelectMulti">Select Multiple</Label>
    104. <Input
    105. type="select"
    106. name="selectMulti"
    107. id="exampleSelectMulti"
    108. multiple
    109. >
    110. <option>1</option>
    111. <option>3</option>
    112. <option>4</option>
    113. <option>5</option>
    114. </FormGroup>
    115. <FormGroup>
    116. <Label for="exampleText">Text Area</Label>
    117. <Input type="textarea" name="text" id="exampleText" />
    118. </FormGroup>
    119. <FormGroup>
    120. <Label for="exampleFile">File</Label>
    121. <Input type="file" name="file" id="exampleFile" />
    122. <FormText color="muted">
    123. This is some placeholder block-level help text for the above input.
    124. It's a bit lighter and easily wraps to a new line.
    125. </FormText>
    126. </FormGroup>
    127. <FormGroup check>
    128. <Label check>
    129. <Input type="radio" /> Option one is this and that—be sure to
    130. include why it's great
    131. </Label>
    132. </FormGroup>
    133. <FormGroup check>
    134. <Label check>
    135. <Input type="checkbox" /> Check me out
    136. </Label>
    137. </FormGroup>
    138. </Form>
    139. );
    140. }
    141. }
    1. import React from 'react';
    2. import { Form, FormGroup, Label, Input } from 'reactstrap';
    3. export default class Example extends React.Component {
    4. render() {
    5. return (
    6. <Form>
    7. <FormGroup check inline>
    8. <Label check>
    9. <Input type="checkbox" /> Some input
    10. </Label>
    11. </FormGroup>
    12. <FormGroup check inline>
    13. <Label check>
    14. <Input type="checkbox" /> Some other input
    15. </Label>
    16. </FormGroup>
    17. </Form>
    18. );
    19. }
    20. }

    Input Sizing

    Input Grid Sizing

    Form - 图3

    1. import React from 'react';
    2. import { Col, Form, FormGroup, Label, Input } from 'reactstrap';
    3. export default class Example extends React.Component {
    4. render() {
    5. return (
    6. <Form>
    7. <FormGroup row>
    8. <Label for="exampleEmail" sm={2} size="lg">Email</Label>
    9. <Col sm={10}>
    10. <Input type="email" name="email" id="exampleEmail" placeholder="lg" bsSize="lg" />
    11. </Col>
    12. </FormGroup>
    13. <FormGroup row>
    14. <Label for="exampleEmail2" sm={2}>Email</Label>
    15. <Col sm={10}>
    16. <Input type="email" name="email" id="exampleEmail2" placeholder="default" />
    17. </Col>
    18. </FormGroup>
    19. </Form>
    20. );
    21. }
    22. }
    1. import React from 'react';
    2. import { Button, Form, FormGroup, Label, Input } from 'reactstrap';
    3. export default class Example extends React.Component {
    4. render() {
    5. return (
    6. <Form inline>
    7. <FormGroup>
    8. <Label for="exampleEmail" hidden>Email</Label>
    9. <Input type="email" name="email" id="exampleEmail" placeholder="Email" />
    10. </FormGroup>
    11. {' '}
    12. <FormGroup>
    13. <Label for="examplePassword" hidden>Password</Label>
    14. <Input type="password" name="password" id="examplePassword" placeholder="Password" />
    15. </FormGroup>
    16. {' '}
    17. <Button>Submit</Button>
    18. </Form>
    19. );
    20. }
    21. }

    Custom Inputs

    1. import React from 'react';
    2. import { CustomInput, Form, FormGroup, Label } from 'reactstrap';
    3. export default class Example extends React.Component {
    4. render() {
    5. return (
    6. <Form>
    7. <FormGroup>
    8. <Label for="exampleCheckbox">Checkboxes</Label>
    9. <div>
    10. <CustomInput type="checkbox" id="exampleCustomCheckbox" label="Check this custom checkbox" />
    11. <CustomInput type="checkbox" id="exampleCustomCheckbox2" label="Or this one" />
    12. <CustomInput type="checkbox" id="exampleCustomCheckbox3" label="But not this disabled one" disabled />
    13. <CustomInput type="checkbox" id="exampleCustomCheckbox4" label="Can't click this label to check!" htmlFor="exampleCustomCheckbox4_X" disabled />
    14. </div>
    15. </FormGroup>
    16. <FormGroup>
    17. <Label for="exampleCheckbox">Radios</Label>
    18. <div>
    19. <CustomInput type="radio" id="exampleCustomRadio" name="customRadio" label="Select this custom radio" />
    20. <CustomInput type="radio" id="exampleCustomRadio2" name="customRadio" label="Or this one" />
    21. <CustomInput type="radio" id="exampleCustomRadio3" label="But not this disabled one" disabled />
    22. <CustomInput type="radio" id="exampleCustomRadio4" label="Can't click this label to select!" htmlFor="exampleCustomRadio4_X" disabled />
    23. </div>
    24. </FormGroup>
    25. <FormGroup>
    26. <Label for="exampleCheckbox">Switches</Label>
    27. <div>
    28. <CustomInput type="switch" id="exampleCustomSwitch" name="customSwitch" label="Turn on this custom switch" />
    29. <CustomInput type="switch" id="exampleCustomSwitch2" name="customSwitch" label="Or this one" />
    30. <CustomInput type="switch" id="exampleCustomSwitch3" label="But not this disabled one" disabled />
    31. <CustomInput type="switch" id="exampleCustomSwitch4" label="Can't click this label to turn on!" htmlFor="exampleCustomSwitch4_X" disabled />
    32. </div>
    33. </FormGroup>
    34. <FormGroup>
    35. <Label for="exampleCheckbox">Inline</Label>
    36. <div>
    37. <CustomInput type="checkbox" id="exampleCustomInline" label="An inline custom input" inline />
    38. <CustomInput type="checkbox" id="exampleCustomInline2" label="and another one" inline />
    39. </div>
    40. </FormGroup>
    41. <FormGroup>
    42. <Label for="exampleCustomSelect">Custom Select</Label>
    43. <CustomInput type="select" id="exampleCustomSelect" name="customSelect">
    44. <option value="">Select</option>
    45. <option>Value 1</option>
    46. <option>Value 2</option>
    47. <option>Value 3</option>
    48. <option>Value 4</option>
    49. <option>Value 5</option>
    50. </CustomInput>
    51. </FormGroup>
    52. <FormGroup>
    53. <Label for="exampleCustomMutlipleSelect">Custom Multiple Select</Label>
    54. <CustomInput type="select" id="exampleCustomMutlipleSelect" name="customSelect" multiple>
    55. <option value="">Select</option>
    56. <option>Value 1</option>
    57. <option>Value 2</option>
    58. <option>Value 3</option>
    59. <option>Value 4</option>
    60. <option>Value 5</option>
    61. </CustomInput>
    62. </FormGroup>
    63. <FormGroup>
    64. <Label for="exampleCustomSelectDisabled">Custom Select Disabled</Label>
    65. <CustomInput type="select" id="exampleCustomSelectDisabled" name="customSelect" disabled>
    66. <option value="">Select</option>
    67. <option>Value 1</option>
    68. <option>Value 2</option>
    69. <option>Value 3</option>
    70. <option>Value 4</option>
    71. <option>Value 5</option>
    72. </CustomInput>
    73. </FormGroup>
    74. <FormGroup>
    75. <Label for="exampleCustomMutlipleSelectDisabled">Custom Multiple Select Disabled</Label>
    76. <CustomInput type="select" id="exampleCustomMutlipleSelectDisabled" name="customSelect" multiple disabled>
    77. <option value="">Select</option>
    78. <option>Value 1</option>
    79. <option>Value 2</option>
    80. <option>Value 3</option>
    81. <option>Value 4</option>
    82. <option>Value 5</option>
    83. </CustomInput>
    84. </FormGroup>
    85. <FormGroup>
    86. <Label for="exampleCustomFileBrowser">File Browser</Label>
    87. <CustomInput type="file" id="exampleCustomFileBrowser" name="customFile" />
    88. </FormGroup>
    89. <FormGroup>
    90. <Label for="exampleCustomFileBrowser">File Browser with Custom Label</Label>
    91. <CustomInput type="file" id="exampleCustomFileBrowser" name="customFile" label="Yo, pick a file!" />
    92. </FormGroup>
    93. <FormGroup>
    94. <Label for="exampleCustomFileBrowser">File Browser Disabled</Label>
    95. <CustomInput type="file" id="exampleCustomFileBrowser" name="customFile" disabled />
    96. </FormGroup>
    97. </Form>
    98. );
    99. }
    100. }