Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RadioButtonGroup prop types #2203

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/RadioButtonGroup/RadioButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import css from './RadioButtonGroup.css';

const propTypes = {
children: PropTypes.node.isRequired,
error: PropTypes.node,
error: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
onBlur: PropTypes.func,
onChange: PropTypes.func,
onFocus: PropTypes.func,
value: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
warning: PropTypes.string
warning: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
};

function RadioButtonGroup(props) {
Expand Down
32 changes: 29 additions & 3 deletions lib/RadioButtonGroup/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,35 @@ Convenient wrapper component for sets of radio buttons. Will pass `name` prop as
The component will automatically render radio buttons within a `<FieldGroup>` with the value for the `label` prop applied as a `<legend>`. Non-`<RadioButton>` children can also be passed for alternative layouts, but **RadioButtons should still be direct descendants**.

## Usage
Example with redux-form `<Field>` component:

Example with react-final-form:
```js
<Field label="Acting as" name="subGroup" component={RadioButtonGroup}>
<RadioButton label="self" id="actingAsSelf" value="self" />
<h4>Sponsor</h4>
<RadioButton label="Abbot, Cody" id="actingSponsor001" value="sponsor001" inline />
<RadioButton label="Doe, John" id="actingSponsor002" value="sponsor002" inline />
<RadioButton label="Martin, Danforth" id="actingSponsor003" value="sponsor003" inline />
<RadioButton label="James, Phillip" id="actingSponsor004" value="sponsor004" inline />
</Field>
```

Example with react-final-form via render-prop:
```js
<Field name="subGroup" render={(props) =>
<RadioButtonGroup {...props} label="Acting as">
<RadioButton label="self" id="actingAsSelf" value="self" />
<h4>Sponsor</h4>
<RadioButton label="Abbot, Cody" id="actingSponsor001" value="sponsor001" inline />
<RadioButton label="Doe, John" id="actingSponsor002" value="sponsor002" inline />
<RadioButton label="Martin, Danforth" id="actingSponsor003" value="sponsor003" inline />
<RadioButton label="James, Phillip" id="actingSponsor004" value="sponsor004" inline />
</RadioButtonGroup>
} />
```

Example with redux-form:
```js
<Field label="Acting as" name="subGroup" component={RadioButtonGroup}>
<RadioButton label="self" id="actingAsSelf" value="self" />
<h4>Sponsor</h4>
Expand All @@ -21,10 +47,10 @@ Example with redux-form `<Field>` component:
Name | type | description | default | required |
--- | --- | --- | --- | --- |
children | node or array of nodes | Set of `<RadioButton>`s for usage. Can include other tags (headers, spans, etc.) | | &#10004;|
error | string | | | |
error | string or node | Error message to display | | |
label | string or node | Content to render in the `<legend>` tag of the created `<fieldset>`. | | |
`onBlur` | func | | |
`onChange` | func | | |
`onFocus` | func | | |
value | string | Sets default value for radio button set - **Not necessary for redux-form - will use the form's initialValues prop instead** | | |
warning | string | | | |
warning | string or node | Warning text to display | | |
Loading