Skip to content

Commit

Permalink
feat: added text overrides on Field
Browse files Browse the repository at this point in the history
Signed-off-by: Haris Spahija <haris.spahija@pon.com>
  • Loading branch information
HarisSpahijaPon committed Nov 21, 2019
1 parent 4808ec2 commit c81ed3d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions package/src/components/Field/v1/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ class Field extends Component {
isRequired: PropTypes.bool,
label: PropTypes.node,
labelClassName: PropTypes.string,
labelFor: PropTypes.string
labelFor: PropTypes.string,
/**
* The text for the "Optional" label text.
*/
optionalLabelText: PropTypes.string,
};

static defaultProps = {
Expand All @@ -76,7 +80,8 @@ class Field extends Component {
labelClassName: undefined,
labelFor: undefined,
isOptional: false,
isRequired: false
isRequired: false,
optionalLabelText: "Optional"
};

getClassName() {
Expand All @@ -87,12 +92,12 @@ class Field extends Component {
}

renderLabel() {
const { errors, label, labelClassName, labelFor, isOptional } = this.props;
const { errors, label, labelClassName, labelFor, isOptional, optionalLabelText } = this.props;

return (
<StyledLabel className={labelClassName} errors={errors} htmlFor={labelFor}>
{label}
{isOptional ? " (Optional)" : null}
{isOptional ? ` (${optionalLabelText})` : null}
</StyledLabel>
);
}
Expand Down

0 comments on commit c81ed3d

Please sign in to comment.