mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
* UX: Icons: Remove IconCheck and fa-check * update jest snapshots * Update story * Remove dead CSS * Update ui/components/app/account-menu/account-menu.component.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/components/app/dropdowns/network-dropdown.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/components/app/modals/metametrics-opt-in-modal/metametrics-opt-in-modal.component.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/pages/settings/networks-tab/networks-list-item/networks-list-item.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/pages/settings/networks-tab/networks-list-item/networks-list-item.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/pages/permissions-connect/redirect/permissions-redirect.component.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/pages/send/send-content/add-recipient/domain-input.component.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/pages/onboarding-flow/metametrics/metametrics.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/components/app/modals/transaction-confirmed/transaction-confirmed.component.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/components/app/modals/metametrics-opt-in-modal/metametrics-opt-in-modal.component.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Fix jest snapshots * Update sizes of network andd account menu checks * Fix ICON_SIZES in account menu * Improvements * Use IconColor * Use IconColor * Lint * Update snapshots --------- Co-authored-by: George Marshall <george.marshall@consensys.net>
92 lines
2.6 KiB
JavaScript
92 lines
2.6 KiB
JavaScript
import classnames from 'classnames';
|
|
import PropTypes from 'prop-types';
|
|
import React, { Component } from 'react';
|
|
import { Color } from '../../../helpers/constants/design-system';
|
|
import { getAccountNameErrorMessage } from '../../../helpers/utils/accounts';
|
|
import { ButtonIcon, ICON_NAMES } from '../../component-library';
|
|
|
|
export default class EditableLabel extends Component {
|
|
static propTypes = {
|
|
onSubmit: PropTypes.func.isRequired,
|
|
defaultValue: PropTypes.string,
|
|
className: PropTypes.string,
|
|
accounts: PropTypes.array,
|
|
};
|
|
|
|
static contextTypes = {
|
|
t: PropTypes.func,
|
|
};
|
|
|
|
state = {
|
|
isEditing: false,
|
|
value: this.props.defaultValue || '',
|
|
};
|
|
|
|
async handleSubmit(isValidAccountName) {
|
|
if (!isValidAccountName) {
|
|
return;
|
|
}
|
|
|
|
await this.props.onSubmit(this.state.value);
|
|
this.setState({ isEditing: false });
|
|
}
|
|
|
|
renderEditing() {
|
|
const { isValidAccountName, errorMessage } = getAccountNameErrorMessage(
|
|
this.props.accounts,
|
|
this.context,
|
|
this.state.value,
|
|
this.props.defaultValue,
|
|
);
|
|
|
|
return (
|
|
<div className={classnames('editable-label', this.props.className)}>
|
|
<input
|
|
type="text"
|
|
required
|
|
dir="auto"
|
|
value={this.state.value}
|
|
onKeyPress={(event) => {
|
|
if (event.key === 'Enter') {
|
|
this.handleSubmit(isValidAccountName);
|
|
}
|
|
}}
|
|
onChange={(event) => this.setState({ value: event.target.value })}
|
|
data-testid="editable-input"
|
|
className={classnames('large-input', 'editable-label__input', {
|
|
'editable-label__input--error': !isValidAccountName,
|
|
})}
|
|
autoFocus
|
|
/>
|
|
<ButtonIcon
|
|
iconName={ICON_NAMES.CHECK}
|
|
className="editable-label__icon-button"
|
|
onClick={() => this.handleSubmit(isValidAccountName)}
|
|
/>
|
|
<div className="editable-label__error editable-label__error-amount">
|
|
{errorMessage}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
renderReadonly() {
|
|
return (
|
|
<div className={classnames('editable-label', this.props.className)}>
|
|
<div className="editable-label__value">{this.state.value}</div>
|
|
<ButtonIcon
|
|
iconName={ICON_NAMES.EDIT}
|
|
ariaLabel={this.context.t('edit')}
|
|
data-testid="editable-label-button"
|
|
onClick={() => this.setState({ isEditing: true })}
|
|
color={Color.iconDefault}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
render() {
|
|
return this.state.isEditing ? this.renderEditing() : this.renderReadonly();
|
|
}
|
|
}
|