mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
option to add title to <Button>, use for toot buttons (#197)
This commit is contained in:
parent
664c9aa708
commit
516eeeb43d
@ -112,3 +112,19 @@ exports[`<Button /> renders the props.text instead of children 1`] = `
|
|||||||
foo
|
foo
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`<Button /> renders title if props.title is given 1`] = `
|
||||||
|
<button
|
||||||
|
className="button"
|
||||||
|
disabled={undefined}
|
||||||
|
onClick={[Function]}
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "36px",
|
||||||
|
"lineHeight": "36px",
|
||||||
|
"padding": "0 16px",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
title="foo"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
@ -72,4 +72,11 @@ describe('<Button />', () => {
|
|||||||
|
|
||||||
expect(tree).toMatchSnapshot();
|
expect(tree).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders title if props.title is given', () => {
|
||||||
|
const component = renderer.create(<Button title='foo' />);
|
||||||
|
const tree = component.toJSON();
|
||||||
|
|
||||||
|
expect(tree).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -14,6 +14,7 @@ export default class Button extends React.PureComponent {
|
|||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
style: PropTypes.object,
|
style: PropTypes.object,
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
|
title: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@ -35,26 +36,26 @@ export default class Button extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const style = {
|
let attrs = {
|
||||||
|
className: classNames('button', this.props.className, {
|
||||||
|
'button-secondary': this.props.secondary,
|
||||||
|
'button--block': this.props.block,
|
||||||
|
}),
|
||||||
|
disabled: this.props.disabled,
|
||||||
|
onClick: this.handleClick,
|
||||||
|
ref: this.setRef,
|
||||||
|
style: {
|
||||||
padding: `0 ${this.props.size / 2.25}px`,
|
padding: `0 ${this.props.size / 2.25}px`,
|
||||||
height: `${this.props.size}px`,
|
height: `${this.props.size}px`,
|
||||||
lineHeight: `${this.props.size}px`,
|
lineHeight: `${this.props.size}px`,
|
||||||
...this.props.style,
|
...this.props.style,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const className = classNames('button', this.props.className, {
|
if (this.props.title) attrs.title = this.props.title;
|
||||||
'button-secondary': this.props.secondary,
|
|
||||||
'button--block': this.props.block,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button {...attrs}>
|
||||||
className={className}
|
|
||||||
disabled={this.props.disabled}
|
|
||||||
onClick={this.handleClick}
|
|
||||||
ref={this.setRef}
|
|
||||||
style={style}
|
|
||||||
>
|
|
||||||
{this.props.text || this.props.children}
|
{this.props.text || this.props.children}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
@ -164,6 +164,8 @@ export default class ComposeForm extends ImmutablePureComponent {
|
|||||||
|
|
||||||
let publishText = '';
|
let publishText = '';
|
||||||
let publishText2 = '';
|
let publishText2 = '';
|
||||||
|
let title = '';
|
||||||
|
let title2 = '';
|
||||||
|
|
||||||
const privacyIcons = {
|
const privacyIcons = {
|
||||||
none: '',
|
none: '',
|
||||||
@ -173,7 +175,10 @@ export default class ComposeForm extends ImmutablePureComponent {
|
|||||||
direct: 'envelope',
|
direct: 'envelope',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
title = `${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${this.props.privacy}.short` })}`;
|
||||||
|
|
||||||
if (showSideArm) {
|
if (showSideArm) {
|
||||||
|
// Enhanced behavior with dual toot buttons
|
||||||
publishText = (
|
publishText = (
|
||||||
<span>
|
<span>
|
||||||
{
|
{
|
||||||
@ -185,13 +190,15 @@ export default class ComposeForm extends ImmutablePureComponent {
|
|||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
title2 = `${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${secondaryVisibility}.short` })}`;
|
||||||
publishText2 = (
|
publishText2 = (
|
||||||
<i
|
<i
|
||||||
className={`fa fa-${privacyIcons[secondaryVisibility]}`}
|
className={`fa fa-${privacyIcons[secondaryVisibility]}`}
|
||||||
aria-label={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${secondaryVisibility}.short` })}`}
|
aria-label={title2}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// Original vanilla behavior - no icon if public or unlisted
|
||||||
if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
|
if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
|
||||||
publishText = <span className='compose-form__publish-private'><i className='fa fa-lock' /> {intl.formatMessage(messages.publish)}</span>;
|
publishText = <span className='compose-form__publish-private'><i className='fa fa-lock' /> {intl.formatMessage(messages.publish)}</span>;
|
||||||
} else {
|
} else {
|
||||||
@ -256,6 +263,7 @@ export default class ComposeForm extends ImmutablePureComponent {
|
|||||||
<Button
|
<Button
|
||||||
className='compose-form__publish__side-arm'
|
className='compose-form__publish__side-arm'
|
||||||
text={publishText2}
|
text={publishText2}
|
||||||
|
title={title2}
|
||||||
onClick={this.handleSubmit2}
|
onClick={this.handleSubmit2}
|
||||||
disabled={submitDisabled}
|
disabled={submitDisabled}
|
||||||
/> : ''
|
/> : ''
|
||||||
@ -263,6 +271,7 @@ export default class ComposeForm extends ImmutablePureComponent {
|
|||||||
<Button
|
<Button
|
||||||
className='compose-form__publish__primary'
|
className='compose-form__publish__primary'
|
||||||
text={publishText}
|
text={publishText}
|
||||||
|
title={title}
|
||||||
onClick={this.handleSubmit}
|
onClick={this.handleSubmit}
|
||||||
disabled={submitDisabled}
|
disabled={submitDisabled}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user