From d84497ac28b34335ecc15eed36bef18ae520058b Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 22 Jul 2020 14:20:10 +0300 Subject: [PATCH] Rework Button component to pass its label via children content --- .../components/accounts/AccountSwitcher.tsx | 23 ++--- .../app/components/auth/appInfo/AppInfo.tsx | 10 +-- .../app/components/auth/finish/Finish.tsx | 10 +-- .../components/contact/ContactFormPopup.tsx | 4 +- .../contact/SuccessContactFormPopup.tsx | 4 +- .../components/dev/apps/ApplicationsIndex.tsx | 15 ++-- .../apps/applicationForm/ApplicationForm.tsx | 16 ++-- .../dev/apps/list/ApplicationItem.tsx | 26 +++--- .../dev/apps/list/ApplicationsList.tsx | 5 +- .../profile/changeEmail/ChangeEmail.tsx | 16 ++-- .../profile/changePassword/ChangePassword.tsx | 5 +- .../profile/changeUsername/ChangeUsername.tsx | 10 +-- .../multiFactorAuth/MfaDisableForm.tsx | 5 +- .../profile/multiFactorAuth/MfaEnable.tsx | 7 +- .../PasswordRequestForm.tsx | 4 +- .../app/components/ui/form/Button.story.tsx | 81 ++++++++++++----- packages/app/components/ui/form/Button.tsx | 86 ++++++++----------- 17 files changed, 175 insertions(+), 152 deletions(-) diff --git a/packages/app/components/accounts/AccountSwitcher.tsx b/packages/app/components/accounts/AccountSwitcher.tsx index 779b0e1..154b965 100644 --- a/packages/app/components/accounts/AccountSwitcher.tsx +++ b/packages/app/components/accounts/AccountSwitcher.tsx @@ -120,23 +120,12 @@ export class AccountSwitcher extends React.Component { ))} {allowAdd ? ( - ) : null} diff --git a/packages/app/components/auth/appInfo/AppInfo.tsx b/packages/app/components/auth/appInfo/AppInfo.tsx index 06f9d33..8f93536 100644 --- a/packages/app/components/auth/appInfo/AppInfo.tsx +++ b/packages/app/components/auth/appInfo/AppInfo.tsx @@ -1,15 +1,11 @@ import React from 'react'; -import { defineMessages, FormattedMessage as Message } from 'react-intl'; +import { FormattedMessage as Message } from 'react-intl'; import { Button } from 'app/components/ui/form'; import { FooterMenu } from 'app/components/footerMenu'; import appName from './appName.intl'; import styles from './appInfo.scss'; -const messages = defineMessages({ - goToAuth: 'Go to auth', -}); - export default class AppInfo extends React.Component<{ name?: string; description?: string; @@ -51,7 +47,9 @@ export default class AppInfo extends React.Component<{ )}
-
diff --git a/packages/app/components/auth/finish/Finish.tsx b/packages/app/components/auth/finish/Finish.tsx index 74202d1..cd875f9 100644 --- a/packages/app/components/auth/finish/Finish.tsx +++ b/packages/app/components/auth/finish/Finish.tsx @@ -1,5 +1,5 @@ import React, { MouseEventHandler } from 'react'; -import { defineMessages, FormattedMessage as Message } from 'react-intl'; +import { FormattedMessage as Message } from 'react-intl'; import { Helmet } from 'react-helmet-async'; import { connect } from 'app/functions'; @@ -8,10 +8,6 @@ import copy from 'app/services/copy'; import styles from './finish.scss'; -const messages = defineMessages({ - copy: 'Copy', -}); - interface Props { appName: string; code?: string; @@ -58,7 +54,9 @@ class Finish extends React.Component {
{code}
-
) : (
diff --git a/packages/app/components/contact/ContactFormPopup.tsx b/packages/app/components/contact/ContactFormPopup.tsx index 248a970..767f006 100644 --- a/packages/app/components/contact/ContactFormPopup.tsx +++ b/packages/app/components/contact/ContactFormPopup.tsx @@ -120,7 +120,9 @@ const ContactFormPopup: ComponentType = ({ initEmail = '', onSubmit, onCl />
- ); diff --git a/packages/app/components/contact/SuccessContactFormPopup.tsx b/packages/app/components/contact/SuccessContactFormPopup.tsx index 70bdd90..b3ef1a9 100644 --- a/packages/app/components/contact/SuccessContactFormPopup.tsx +++ b/packages/app/components/contact/SuccessContactFormPopup.tsx @@ -30,7 +30,9 @@ const SuccessContactFormPopup: ComponentType = ({ email, onClose }) => (
-
); diff --git a/packages/app/components/dev/apps/ApplicationsIndex.tsx b/packages/app/components/dev/apps/ApplicationsIndex.tsx index 8618c63..b9444f9 100644 --- a/packages/app/components/dev/apps/ApplicationsIndex.tsx +++ b/packages/app/components/dev/apps/ApplicationsIndex.tsx @@ -15,7 +15,6 @@ import ApplicationsList from './list'; const labels = defineMessages({ addNew: 'Add new', - authorization: 'Authorization', }); type Props = { @@ -123,10 +122,11 @@ function Loader({ noApps }: { noApps: boolean }) { + > + + ); @@ -145,12 +145,9 @@ function Guest() { - + + + ); } diff --git a/packages/app/components/dev/apps/applicationForm/ApplicationForm.tsx b/packages/app/components/dev/apps/applicationForm/ApplicationForm.tsx index 3b1795e..918698d 100644 --- a/packages/app/components/dev/apps/applicationForm/ApplicationForm.tsx +++ b/packages/app/components/dev/apps/applicationForm/ApplicationForm.tsx @@ -20,10 +20,7 @@ const messages = defineMessages({ minecraftServer: 'Minecraft server', creatingApplication: 'Creating an application', - createApplication: 'Create application', - updatingApplication: 'Updating an application', - updateApplication: 'Update application', }); type TypeToForm = Record< @@ -115,12 +112,13 @@ export default class ApplicationForm extends React.Component<{ {!!FormComponent && ( - )} diff --git a/packages/app/components/dev/apps/list/ApplicationItem.tsx b/packages/app/components/dev/apps/list/ApplicationItem.tsx index 9f579b5..6939b38 100644 --- a/packages/app/components/dev/apps/list/ApplicationItem.tsx +++ b/packages/app/components/dev/apps/list/ApplicationItem.tsx @@ -16,15 +16,15 @@ const ACTION_DELETE = 'delete'; const actionButtons = [ { type: ACTION_REVOKE_TOKENS, - label: messages.revokeAllTokens, + label: , }, { type: ACTION_RESET_SECRET, - label: messages.resetClientSecret, + label: , }, { type: ACTION_DELETE, - label: messages.delete, + label: , }, ]; @@ -122,13 +122,14 @@ export default class ApplicationItem extends React.Component< {actionButtons.map(({ type, label }) => ( ))} @@ -160,12 +161,13 @@ export default class ApplicationItem extends React.Component<
{isActionPerforming ? (
@@ -193,12 +195,13 @@ export default class ApplicationItem extends React.Component<
{isActionPerforming ? (
@@ -206,13 +209,14 @@ export default class ApplicationItem extends React.Component<
) : ( )}
diff --git a/packages/app/components/dev/apps/list/ApplicationsList.tsx b/packages/app/components/dev/apps/list/ApplicationsList.tsx index 35a0639..bee4891 100644 --- a/packages/app/components/dev/apps/list/ApplicationsList.tsx +++ b/packages/app/components/dev/apps/list/ApplicationsList.tsx @@ -49,10 +49,11 @@ export default class ApplicationsList extends React.Component { + > + +
{applications.map((app) => ( diff --git a/packages/app/components/profile/changeEmail/ChangeEmail.tsx b/packages/app/components/profile/changeEmail/ChangeEmail.tsx index a34cee5..5e5d5fe 100644 --- a/packages/app/components/profile/changeEmail/ChangeEmail.tsx +++ b/packages/app/components/profile/changeEmail/ChangeEmail.tsx @@ -1,6 +1,7 @@ import React, { ReactNode } from 'react'; import { defineMessages, FormattedMessage as Message } from 'react-intl'; import { Helmet } from 'react-helmet-async'; + import { SlideMotion } from 'app/components/ui/motion'; import { ScrollIntoView } from 'app/components/ui/scroll'; import { Input, Button, Form, FormModel, FormError } from 'app/components/ui/form'; @@ -39,8 +40,6 @@ interface FormStepParams { } const labels = defineMessages({ - changeEmailButton: 'Change E‑mail', - sendEmailButton: 'Send E‑mail', codePlaceholder: 'Paste the code here', newEmailPlaceholder: 'Enter new E‑mail', }); @@ -107,12 +106,13 @@ export default class ChangeEmail extends React.Component { {this.renderStepForms()} -
diff --git a/packages/app/components/profile/changePassword/ChangePassword.tsx b/packages/app/components/profile/changePassword/ChangePassword.tsx index 4958e7a..e0956e5 100644 --- a/packages/app/components/profile/changePassword/ChangePassword.tsx +++ b/packages/app/components/profile/changePassword/ChangePassword.tsx @@ -7,7 +7,6 @@ import { BackButton } from '../ProfileForm'; import styles from '../profileForm.scss'; const labels = defineMessages({ - changePasswordButton: 'Change password', newPasswordLabel: 'New password:', repeatNewPasswordLabel: 'Repeat the password:', logoutOnAllDevices: 'Logout on all devices', @@ -99,7 +98,9 @@ export default class ChangePassword extends React.Component {
- diff --git a/packages/app/components/profile/changeUsername/ChangeUsername.tsx b/packages/app/components/profile/changeUsername/ChangeUsername.tsx index f684a92..87aa489 100644 --- a/packages/app/components/profile/changeUsername/ChangeUsername.tsx +++ b/packages/app/components/profile/changeUsername/ChangeUsername.tsx @@ -1,15 +1,11 @@ import React from 'react'; -import { defineMessages, FormattedMessage as Message } from 'react-intl'; +import { FormattedMessage as Message } from 'react-intl'; import { Helmet } from 'react-helmet-async'; import { Input, Button, Form, FormModel } from 'app/components/ui/form'; import { BackButton } from 'app/components/profile/ProfileForm'; import styles from '../profileForm.scss'; -const labels = defineMessages({ - changeUsernameButton: 'Change nickname', -}); - interface Props { username: string; form: FormModel; @@ -72,7 +68,9 @@ export default class ChangeUsername extends React.Component { - diff --git a/packages/app/components/profile/multiFactorAuth/MfaDisableForm.tsx b/packages/app/components/profile/multiFactorAuth/MfaDisableForm.tsx index 6bdc93f..af9ea3f 100644 --- a/packages/app/components/profile/multiFactorAuth/MfaDisableForm.tsx +++ b/packages/app/components/profile/multiFactorAuth/MfaDisableForm.tsx @@ -7,7 +7,6 @@ import mfaStyles from './mfa.scss'; const messages = defineMessages({ codePlaceholder: 'Enter the code here', - disable: 'Disable', }); export default class MfaDisableForm extends React.Component<{ @@ -49,7 +48,9 @@ export default class MfaDisableForm extends React.Component<{ - ); } diff --git a/packages/app/components/profile/multiFactorAuth/MfaEnable.tsx b/packages/app/components/profile/multiFactorAuth/MfaEnable.tsx index 5a5cdbd..71a32ee 100644 --- a/packages/app/components/profile/multiFactorAuth/MfaEnable.tsx +++ b/packages/app/components/profile/multiFactorAuth/MfaEnable.tsx @@ -1,4 +1,6 @@ import React from 'react'; +import { FormattedMessage as Message, defineMessages } from 'react-intl'; + import { Button, FormModel } from 'app/components/ui/form'; import styles from 'app/components/profile/profileForm.scss'; import Stepper from 'app/components/ui/stepper'; @@ -7,7 +9,6 @@ import { ScrollIntoView } from 'app/components/ui/scroll'; import logger from 'app/services/logger'; import { getSecret, enable as enableMFA } from 'app/services/api/mfa'; import { Form } from 'app/components/ui/form'; -import { defineMessages } from 'react-intl'; import Context from '../Context'; import Instructions from './instructions'; @@ -105,7 +106,9 @@ export default class MfaEnable extends React.PureComponent { {this.renderStepForms()} - ); diff --git a/packages/app/components/profile/passwordRequestForm/PasswordRequestForm.tsx b/packages/app/components/profile/passwordRequestForm/PasswordRequestForm.tsx index 6d8b63b..9c43f7b 100644 --- a/packages/app/components/profile/passwordRequestForm/PasswordRequestForm.tsx +++ b/packages/app/components/profile/passwordRequestForm/PasswordRequestForm.tsx @@ -37,7 +37,9 @@ const PasswordRequestForm: ComponentType = ({ form, onSubmit }) => ( /> - ); diff --git a/packages/app/components/ui/form/Button.story.tsx b/packages/app/components/ui/form/Button.story.tsx index f7134fa..8a54b48 100644 --- a/packages/app/components/ui/form/Button.story.tsx +++ b/packages/app/components/ui/form/Button.story.tsx @@ -6,38 +6,77 @@ import Button from './Button'; storiesOf('UI/Form', module).add('Button', () => ( <>
- {' '} + {' '} + {' '} + {' '} +

Disabled buttons

- + {' '} + {' '} + {' '} + {' '} + {' '} + {' '} + {' '} +

Button sizes

-

-
-

Loading button

- {' '} + {' '} + {' '} + {' '} + {' '} + {' '} + {' '} + {' '} +
)); diff --git a/packages/app/components/ui/form/Button.tsx b/packages/app/components/ui/form/Button.tsx index f9524a2..8fe0ada 100644 --- a/packages/app/components/ui/form/Button.tsx +++ b/packages/app/components/ui/form/Button.tsx @@ -1,55 +1,45 @@ -import React from 'react'; +import React, { ComponentType } from 'react'; import clsx from 'clsx'; + import { COLOR_GREEN } from 'app/components/ui'; -import { MessageDescriptor } from 'react-intl'; import { Color } from 'app/components/ui'; import buttons from '../buttons.scss'; -import FormComponent from './FormComponent'; -export default class Button extends FormComponent< - { - // TODO: drop MessageDescriptor support. It should be React.ReactNode only - label: string | MessageDescriptor | React.ReactElement; - block?: boolean; - small?: boolean; - loading?: boolean; - className?: string; - color?: Color; - disabled?: boolean; - component?: string | React.ComponentType; - } & React.ButtonHTMLAttributes -> { - render() { - const { - color = COLOR_GREEN, - block, - small, - disabled, - className, - loading, - label, - component: ComponentProp = 'button', - ...restProps - } = this.props; - - return ( - - {typeof label === 'object' && React.isValidElement(label) ? label : this.formatMessage(label)} - - ); - } +interface Props extends React.ButtonHTMLAttributes { + block?: boolean; + small?: boolean; + loading?: boolean; + className?: string; + color?: Color; + disabled?: boolean; + component?: string | React.ComponentType; } + +const Button: ComponentType = ({ + color = COLOR_GREEN, + block, + small, + disabled, + className, + loading, + component: ComponentProp = 'button', + ...restProps +}) => ( + +); + +export default Button;