1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/app/modals/new-account-modal/new-account-modal.component.js
Garrett Bear 065c499753
update ButtonIcon to TS (#18448)
* update ButtonIcon to TS

lint updates

fix lint issues

add ref

fix as prop

test updates

* box and icon updates for support

* Update ui/components/component-library/text-field/README.mdx

Co-authored-by: George Marshall <george.marshall@consensys.net>

* fix disabled

* update types for as

* update readme

* fix storybook

* george changes to button icon

* revert headerbase

* box prop back to HTMLElementTagNameMap

---------

Co-authored-by: George Marshall <george.marshall@consensys.net>
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
2023-04-12 08:55:24 -07:00

83 lines
2.2 KiB
JavaScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Button from '../../../ui/button/button.component';
import { ButtonIcon } from '../../../component-library/button-icon/deprecated';
import { ICON_NAMES } from '../../../component-library/icon/deprecated';
export default class NewAccountModal extends Component {
static contextTypes = {
t: PropTypes.func,
};
static propTypes = {
hideModal: PropTypes.func.isRequired,
newAccountNumber: PropTypes.number.isRequired,
onSave: PropTypes.func.isRequired,
};
state = {
alias: this.context.t('newAccountNumberName', [
this.props.newAccountNumber,
]),
};
onChange = (e) => {
this.setState({
alias: e.target.value,
});
};
onSubmit = () => {
this.props.onSave(this.state.alias).then(this.props.hideModal);
};
onKeyPress = (e) => {
if (e.key === 'Enter' && this.state.alias) {
this.onSubmit();
}
};
render() {
const { t } = this.context;
return (
<div className="new-account-modal">
<div className="new-account-modal__content">
<div className="new-account-modal__content__header">
{t('newAccount')}
<ButtonIcon
className="new-account-modal__content__header-close"
ariaLabel={t('close')}
onClick={this.props.hideModal}
iconName={ICON_NAMES.CLOSE}
/>
</div>
<div className="new-account-modal__input-label">
{t('accountName')}
</div>
<input
type="text"
className="new-account-modal__input"
onChange={this.onChange}
onKeyPress={this.onKeyPress}
value={this.state.alias}
autoFocus
/>
</div>
<div className="new-account-modal__footer">
<Button type="secondary" onClick={this.props.hideModal}>
{t('cancel')}
</Button>
<Button
type="primary"
onClick={this.onSubmit}
disabled={!this.state.alias}
>
{t('save')}
</Button>
</div>
</div>
);
}
}