From 324868b5f30181a541eeae81f73c9c0486664bfd Mon Sep 17 00:00:00 2001 From: jinoosss Date: Thu, 17 Oct 2024 02:44:26 +0900 Subject: [PATCH 1/8] feat: add memo input components --- .../src/assets/warning-info.svg | 27 ++++++++++ .../memo-input/memo-input.spec.tsx | 26 ++++++++++ .../memo-input/memo-input.stories.tsx | 15 ++++++ .../memo-input/memo-input.styles.ts | 43 ++++++++++++++++ .../transfer-input/memo-input/memo-input.tsx | 49 +++++++++++++++++++ .../transfer-input/transfer-input.spec.tsx | 13 +++-- .../transfer-input/transfer-input.stories.tsx | 10 ++-- .../transfer-input/transfer-input.styles.ts | 48 +++--------------- .../transfer-input/transfer-input.tsx | 34 ++++++++++--- .../popup/wallet/transfer-input/index.tsx | 45 ++++++++--------- packages/adena-extension/src/styles/theme.ts | 9 ++-- 11 files changed, 234 insertions(+), 85 deletions(-) create mode 100644 packages/adena-extension/src/assets/warning-info.svg create mode 100644 packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.spec.tsx create mode 100644 packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.stories.tsx create mode 100644 packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.styles.ts create mode 100644 packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.tsx diff --git a/packages/adena-extension/src/assets/warning-info.svg b/packages/adena-extension/src/assets/warning-info.svg new file mode 100644 index 000000000..bf5acbe3d --- /dev/null +++ b/packages/adena-extension/src/assets/warning-info.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + diff --git a/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.spec.tsx b/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.spec.tsx new file mode 100644 index 000000000..50c34d552 --- /dev/null +++ b/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.spec.tsx @@ -0,0 +1,26 @@ +import { GlobalPopupStyle } from '@styles/global-style'; +import theme from '@styles/theme'; +import { render } from '@testing-library/react'; +import { RecoilRoot } from 'recoil'; +import { ThemeProvider } from 'styled-components'; +import MemoInput, { MemoInputProps } from './memo-input'; + +describe('MemoInput Component', () => { + it('MemoInput render', () => { + const args: MemoInputProps = { + memo: '132123123123', + onChangeMemo: () => { + return; + }, + }; + + render( + + + + + + , + ); + }); +}); diff --git a/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.stories.tsx b/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.stories.tsx new file mode 100644 index 000000000..cf3bd5b2f --- /dev/null +++ b/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.stories.tsx @@ -0,0 +1,15 @@ +import { action } from '@storybook/addon-actions'; +import { Meta, StoryObj } from '@storybook/react'; +import MemoInput, { type MemoInputProps } from './memo-input'; + +export default { + title: 'components/transfer/MemoInput', + component: MemoInput, +} as Meta; + +export const Default: StoryObj = { + args: { + memo: '132123123123', + onChangeMemo: action('change memo'), + }, +}; diff --git a/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.styles.ts b/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.styles.ts new file mode 100644 index 000000000..d6bd6b73f --- /dev/null +++ b/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.styles.ts @@ -0,0 +1,43 @@ +import mixins from '@styles/mixins'; +import { fonts, getTheme } from '@styles/theme'; +import styled from 'styled-components'; + +export const MemoInputWrapper = styled.div` + ${mixins.flex({ align: 'normal', justify: 'normal' })}; + width: 100%; + height: auto; + gap: 12px; + + .memo-input { + ${mixins.flex({ direction: 'row', justify: 'normal' })}; + width: 100%; + height: auto; + padding: 12px 16px; + ${fonts.body2Reg}; + background-color: ${getTheme('neutral', '_9')}; + border: 1px solid ${getTheme('neutral', '_7')}; + border-radius: 30px; + width: 100%; + resize: none; + } + + .warning-wrapper { + ${mixins.flex({ direction: 'row', justify: 'normal' })}; + width: 100%; + border-radius: 8px; + border: 1px solid ${getTheme('red', '_8')}0d; + background-color: ${getTheme('red', '_8')}1a; + padding: 12px 20px; + gap: 10px; + + .icon-warning { + width: 14px; + } + + .warning-text { + width: 100%; + ${fonts.body2Reg}; + color: ${getTheme('red', '_8')}; + } + } +`; diff --git a/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.tsx b/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.tsx new file mode 100644 index 000000000..390fe0e57 --- /dev/null +++ b/packages/adena-extension/src/components/pages/transfer-input/memo-input/memo-input.tsx @@ -0,0 +1,49 @@ +import React, { useRef } from 'react'; + +import IconWarning from '@assets/warning-info.svg'; +import { MemoInputWrapper } from './memo-input.styles'; + +export interface MemoInputProps { + memo: string; + onChangeMemo: (memo: string) => void; +} + +const WARNING_TEXT = 'A memo is required when sending tokens to a centralized exchange.'; + +const MemoInput: React.FC = ({ memo, onChangeMemo }) => { + const inputRef = useRef(null); + + const handleResizeHeight = (): void => { + if (!inputRef.current) { + return; + } + + inputRef.current.style.height = 'auto'; + inputRef.current.style.height = inputRef.current.scrollHeight + 'px'; + }; + + const onChangeMemoTextArea = (memo: string): void => { + onChangeMemo(memo); + handleResizeHeight(); + }; + + return ( + +