From 671a27d147c1b821d9ccc5c88a00bf8cd5500c16 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Tue, 29 Nov 2022 18:44:50 +0800 Subject: [PATCH] style(console): fix multi-text input margin (#2546) --- .../src/components/FormField/index.tsx | 14 +- .../MultiTextInput/index.module.scss | 12 +- .../src/components/MultiTextInput/index.tsx | 26 ++- .../MultiTextInputField/index.module.scss | 5 + .../components/MultiTextInputField/index.tsx | 34 ++++ .../UriInputField/index.module.scss | 17 +- .../mdx-components/UriInputField/index.tsx | 103 ++++++------ .../components/Settings.tsx | 148 ++++++++---------- 8 files changed, 212 insertions(+), 147 deletions(-) create mode 100644 packages/console/src/components/MultiTextInputField/index.module.scss create mode 100644 packages/console/src/components/MultiTextInputField/index.tsx diff --git a/packages/console/src/components/FormField/index.tsx b/packages/console/src/components/FormField/index.tsx index a17c3704f..620fb2ed2 100644 --- a/packages/console/src/components/FormField/index.tsx +++ b/packages/console/src/components/FormField/index.tsx @@ -11,21 +11,29 @@ import Spacer from '../Spacer'; import Tooltip from '../Tooltip'; import * as styles from './index.module.scss'; -type Props = { +export type Props = { title: AdminConsoleKey | ReactElement; children: ReactNode; isRequired?: boolean; className?: string; + headlineClassName?: string; tooltip?: AdminConsoleKey; }; -const FormField = ({ title, children, isRequired, className, tooltip }: Props) => { +const FormField = ({ + title, + children, + isRequired, + className, + tooltip, + headlineClassName, +}: Props) => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const tipRef = useRef(null); return (
-
+
{typeof title === 'string' ? t(title) : title}
{tooltip && (
diff --git a/packages/console/src/components/MultiTextInput/index.module.scss b/packages/console/src/components/MultiTextInput/index.module.scss index d70a04d68..3110f2f5b 100644 --- a/packages/console/src/components/MultiTextInput/index.module.scss +++ b/packages/console/src/components/MultiTextInput/index.module.scss @@ -5,14 +5,20 @@ margin-top: _.unit(2); } + .firstFieldWithMultiInputs { + padding-right: _.unit(9); + } + .deletableInput { display: flex; align-items: center; > :first-child { - @include _.form-text-field; - margin-right: _.unit(2); - flex-shrink: 0; + flex: 1; + } + + > :not(:first-child) { + margin-left: _.unit(2); } } diff --git a/packages/console/src/components/MultiTextInput/index.tsx b/packages/console/src/components/MultiTextInput/index.tsx index 90ce7c422..0e61ed2f8 100644 --- a/packages/console/src/components/MultiTextInput/index.tsx +++ b/packages/console/src/components/MultiTextInput/index.tsx @@ -1,4 +1,6 @@ import type { AdminConsoleKey } from '@logto/phrases'; +import { conditional } from '@silverhand/essentials'; +import classNames from 'classnames'; import type { KeyboardEvent } from 'react'; import { useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -12,16 +14,25 @@ import TextInput from '../TextInput'; import * as styles from './index.module.scss'; import type { MultiTextInputError } from './types'; -type Props = { +export type Props = { title: AdminConsoleKey; value?: string[]; onChange: (value: string[]) => void; onKeyPress?: (event: KeyboardEvent) => void; error?: MultiTextInputError; placeholder?: string; + className?: string; }; -const MultiTextInput = ({ title, value, onChange, onKeyPress, error, placeholder }: Props) => { +const MultiTextInput = ({ + title, + value, + onChange, + onKeyPress, + error, + placeholder, + className, +}: Props) => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const [deleteFieldIndex, setDeleteFieldIndex] = useState(); @@ -47,10 +58,15 @@ const MultiTextInput = ({ title, value, onChange, onKeyPress, error, placeholder }; return ( -
+
{fields.map((fieldValue, fieldIndex) => ( - // eslint-disable-next-line react/no-array-index-key -
+
1 && fieldIndex === 0 && styles.firstFieldWithMultiInputs + )} + >
& { + formFieldClassName?: FormFieldProps['className']; + }; + +const MultiTextInputField = ({ + title, + isRequired, + tooltip, + formFieldClassName, + value, + ...rest +}: Props) => ( + 1 && styles.headlineWithMultiInputs)} + > + + +); + +export default MultiTextInputField; diff --git a/packages/console/src/mdx-components/UriInputField/index.module.scss b/packages/console/src/mdx-components/UriInputField/index.module.scss index 05254a4b0..1b8cea632 100644 --- a/packages/console/src/mdx-components/UriInputField/index.module.scss +++ b/packages/console/src/mdx-components/UriInputField/index.module.scss @@ -5,13 +5,16 @@ align-items: flex-start; position: relative; + .field { + flex: 1; + + .multiTextInput { + flex: 1; + } + } + .saveButton { - position: absolute; - left: calc(556px + _.unit(3)); - top: 0; + flex-shrink: 0; + margin: _.unit(6) 0 0 _.unit(2); } } - -.field { - width: 556px; -} diff --git a/packages/console/src/mdx-components/UriInputField/index.tsx b/packages/console/src/mdx-components/UriInputField/index.tsx index 19c2f35e3..bb71ad9be 100644 --- a/packages/console/src/mdx-components/UriInputField/index.tsx +++ b/packages/console/src/mdx-components/UriInputField/index.tsx @@ -9,8 +9,8 @@ import useSWR from 'swr'; import Button from '@/components/Button'; import FormField from '@/components/FormField'; -import MultiTextInput from '@/components/MultiTextInput'; import { convertRhfErrorMessage, createValidatorForRhf } from '@/components/MultiTextInput/utils'; +import MultiTextInputField from '@/components/MultiTextInputField'; import TextInput from '@/components/TextInput'; import type { RequestError } from '@/hooks/use-api'; import useApi from '@/hooks/use-api'; @@ -69,31 +69,33 @@ const UriInputField = ({ appId, name, title, isSingle = false }: Props) => { return (
- - !value || uriValidator(value), - message: t('errors.invalid_uri_format'), - }, - }), - }} - render={({ field: { onChange, value = [] }, fieldState: { error, isDirty } }) => { - const errorObject = convertRhfErrorMessage(error?.message); + !value || uriValidator(value), + message: t('errors.invalid_uri_format'), + }, + }), + }} + render={({ field: { onChange, value = [] }, fieldState: { error, isDirty } }) => { + const errorObject = convertRhfErrorMessage(error?.message); - return ( -
- {isSingle && ( + return ( +
+ {isSingle && ( + { onKeyPress(event, value); }} /> - )} - {!isSingle && ( - { - onKeyPress(event, value); - }} - /> - )} -
- ); - }} - /> - + )} +
+ ); + }} + />
); diff --git a/packages/console/src/pages/ApplicationDetails/components/Settings.tsx b/packages/console/src/pages/ApplicationDetails/components/Settings.tsx index 3f34d88c4..3eb1d7796 100644 --- a/packages/console/src/pages/ApplicationDetails/components/Settings.tsx +++ b/packages/console/src/pages/ApplicationDetails/components/Settings.tsx @@ -6,9 +6,9 @@ import { useTranslation } from 'react-i18next'; import CopyToClipboard from '@/components/CopyToClipboard'; import FormCard from '@/components/FormCard'; import FormField from '@/components/FormField'; -import MultiTextInput from '@/components/MultiTextInput'; import type { MultiTextInputRule } from '@/components/MultiTextInput/types'; import { createValidatorForRhf, convertRhfErrorMessage } from '@/components/MultiTextInput/utils'; +import MultiTextInputField from '@/components/MultiTextInputField'; import TextInput from '@/components/TextInput'; import { uriOriginValidator } from '@/utilities/validator'; @@ -71,89 +71,77 @@ const Settings = ({ data }: Props) => { )} {applicationType !== ApplicationType.MachineToMachine && ( - - ( - - )} - /> - + ( + + )} + /> )} {applicationType !== ApplicationType.MachineToMachine && ( - - ( - - )} - /> - + ( + + )} + /> )} {applicationType !== ApplicationType.MachineToMachine && ( - - !value || uriOriginValidator(value), - message: t('errors.invalid_origin_format'), - }, - }), - }} - render={({ field: { onChange, value }, fieldState: { error } }) => ( - - )} - /> - + !value || uriOriginValidator(value), + message: t('errors.invalid_origin_format'), + }, + }), + }} + render={({ field: { onChange, value }, fieldState: { error } }) => ( + + )} + /> )} );