Skip to content

Commit

Permalink
Changed button label to button text, added prop and fixed examples (#…
Browse files Browse the repository at this point in the history
…1160)

* Changed button label to button text, added prop and fixed examples

* put gulpfile back

* Update Button.Primary.Example.tsx

* Update Button.Primary.Example.tsx
  • Loading branch information
micahgodbolt authored and dzearing committed Mar 2, 2017
1 parent 76ec5a9 commit bd867cf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ButtonDefaultExample extends React.Component<IButtonProps, {}> {
disabled={ disabled }
icon='Add'
description='I am a description'
label='Create account'
text='Create account'
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export class ButtonPrimaryExample extends React.Component<IButtonProps, {}> {
<PrimaryButton
data-automation-id='test'
disabled={ disabled }
>Create account</PrimaryButton>
text='Create account'
/>
</div>
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class BaseButton extends BaseComponent<IButtonProps, {}> implements IButt
return React.createElement(
tag,
buttonProps,
React.createElement('div', { className: css( this.classNames.base + '-flexContainer', styles.flexContainer, this.classNames.flexContainer) },
React.createElement('div', { className: css(this.classNames.base + '-flexContainer', styles.flexContainer, this.classNames.flexContainer) },
this.onRenderIcon(),
this.onRenderLabel(),
this.onRenderDescription(),
Expand All @@ -127,27 +127,26 @@ export class BaseButton extends BaseComponent<IButtonProps, {}> implements IButt
}

protected onRenderLabel() {
let { children, label } = this.props;
let { children, text } = this.props;

// For backwards compat, we should continue to take in the label content from children.
if (label === undefined && typeof (children) === 'string') {
label = children;
// For backwards compat, we should continue to take in the text content from children.
if (text === undefined && typeof (children) === 'string') {
text = children;
}

return label ? (
return text && (
<span className={ css(`${this.classNames.base}-label`, this.classNames.label) } id={ this._labelId } >
{ label }
{ text }
</span>
) : (null);
);
}

protected onRenderChildren() {
let { children, label } = this.props;
let { children } = this.props;

// There is no label and the label will be rendered, we don't want the label to appear twice.
// If there is a label and the children are of type string it was likely intentional and both
// should render.
if (label === undefined && typeof (children) === 'string') {
// If children is just a string, either it or the text will be rendered via onRenderLabel
// If children is another component, it will be rendered after text
if (typeof (children) === 'string') {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export interface IButtonProps extends React.HTMLProps<HTMLButtonElement | HTMLAn
*/
ariaDescription?: string;

/**
* Text to render button label. If text is supplied, it will override any string in button children. Other children components will be passed through after the text.
*/
text?: string;

/**
* The button icon shown in command or hero type.
* Deprecated at v1.2.3, to be removed at >= v2.0.0. Use IconButton instead.
Expand Down

0 comments on commit bd867cf

Please sign in to comment.