Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plasma-b2c, plasma-web): autoResize for TextArea #614

Merged
merged 1 commit into from
Jul 26, 2023

Conversation

kayman233
Copy link
Contributor

@kayman233 kayman233 commented Jul 10, 2023

Добавлена возможность автоматического регулирования высоты поля ввода по длине контента внутри (параметра value) с помощью свойства autoResize.
В этом режиме можно указать крайние значения высоты поля ввода, используя свойства minAuto, maxAuto,
указав их в rem.

const [value, setValue] = React.useState('Значение');

return (
    <TextArea
        placeholder="Введите значение"
        value={value}
        onChange={(e) => {
            setValue(e.target.value);
        }}
        autoResize
        minAuto={3}
        maxAuto={5}
    />
);

ezgif-5-f069f315b1

🐤 Download canary assets:
color
color_asdk_ios-swift--canary.614.5553174292.swift
color_asdk_kotlin--canary.614.5553174292.kt
color_asdk_react-native--canary.614.5553174292.ts
color_asdk_xml--canary.614.5553174292.xml
color_plasma_b2c_ios-swift--canary.614.5553174292.swift
color_plasma_b2c_kotlin--canary.614.5553174292.kt
color_plasma_b2c_react-native--canary.614.5553174292.ts
color_plasma_b2c_xml--canary.614.5553174292.xml
color_sberHealth_ios-swift--canary.614.5553174292.swift
color_sberHealth_kotlin--canary.614.5553174292.kt
color_sberHealth_react-native--canary.614.5553174292.ts
color_sberHealth_xml--canary.614.5553174292.xml
color_sbermarket_business_ios-swift--canary.614.5553174292.swift
color_sbermarket_business_kotlin--canary.614.5553174292.kt
color_sbermarket_business_react-native--canary.614.5553174292.ts
color_sbermarket_business_xml--canary.614.5553174292.xml
color_sbermarket_ios-swift--canary.614.5553174292.swift
color_sbermarket_kotlin--canary.614.5553174292.kt
color_sbermarket_metro_ios-swift--canary.614.5553174292.swift
color_sbermarket_metro_kotlin--canary.614.5553174292.kt
color_sbermarket_metro_react-native--canary.614.5553174292.ts
color_sbermarket_metro_xml--canary.614.5553174292.xml
color_sbermarket_react-native--canary.614.5553174292.ts
color_sbermarket_selgros_ios-swift--canary.614.5553174292.swift
color_sbermarket_selgros_kotlin--canary.614.5553174292.kt
color_sbermarket_selgros_react-native--canary.614.5553174292.ts
color_sbermarket_selgros_xml--canary.614.5553174292.xml
color_sbermarket_wlbusiness_ios-swift--canary.614.5553174292.swift
color_sbermarket_wlbusiness_kotlin--canary.614.5553174292.kt
color_sbermarket_wlbusiness_react-native--canary.614.5553174292.ts
color_sbermarket_wlbusiness_xml--canary.614.5553174292.xml
color_sbermarket_xml--canary.614.5553174292.xml
color_sberonline_ios-swift--canary.614.5553174292.swift
color_sberonline_kotlin--canary.614.5553174292.kt
color_sberonline_react-native--canary.614.5553174292.ts
color_sberonline_xml--canary.614.5553174292.xml
color_sberprime_ios-swift--canary.614.5553174292.swift
color_sberprime_kotlin--canary.614.5553174292.kt
color_sberprime_react-native--canary.614.5553174292.ts
color_sberprime_xml--canary.614.5553174292.xml
shadow
shadow_sbermarket_react-native--canary.614.5553174292.ts
typo
typo_mage_ios-swift--canary.614.5553174292.swift
typo_mage_kotlin--canary.614.5553174292.kt
typo_mage_react-native--canary.614.5553174292.ts
typo_plasma_ios-swift--canary.614.5553174292.swift
typo_plasma_kotlin--canary.614.5553174292.kt
typo_plasma_react-native--canary.614.5553174292.ts
typo_ruler_ios-swift--canary.614.5553174292.swift
typo_ruler_kotlin--canary.614.5553174292.kt
typo_ruler_react-native--canary.614.5553174292.ts
typo_sage_ios-swift--canary.614.5553174292.swift
typo_sage_kotlin--canary.614.5553174292.kt
typo_sage_react-native--canary.614.5553174292.ts
typo_sbermarket_ios-swift--canary.614.5553174292.swift
typo_sbermarket_kotlin--canary.614.5553174292.kt
typo_sbermarket_react-native--canary.614.5553174292.ts
typo_soulmate_ios-swift--canary.614.5553174292.swift
typo_soulmate_kotlin--canary.614.5553174292.kt
typo_soulmate_react-native--canary.614.5553174292.ts
📦 Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install @salutejs/[email protected]
npm install @salutejs/[email protected]
npm install @salutejs/[email protected]
# or 
yarn add @salutejs/[email protected]
yarn add @salutejs/[email protected]
yarn add @salutejs/[email protected]

@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@Salute-Eva
Copy link
Contributor

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from 6196c5b to 60dc603 Compare July 10, 2023 21:35
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from 60dc603 to 5c69b3d Compare July 10, 2023 21:44
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@Salute-Eva
Copy link
Contributor

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from 5c69b3d to eaef928 Compare July 10, 2023 22:03
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@Salute-Eva
Copy link
Contributor

@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@Salute-Eva
Copy link
Contributor

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from c88264d to 4e6a3be Compare July 11, 2023 07:42
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from 4e6a3be to eaef928 Compare July 11, 2023 07:52
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@Salute-Eva
Copy link
Contributor

@kayman233 kayman233 marked this pull request as ready for review July 11, 2023 08:37
@Yakutoc
Copy link
Collaborator

Yakutoc commented Jul 11, 2023

@kayman233 Добавь пожалуйста короткое описание для PR?

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from eaef928 to 4886021 Compare July 13, 2023 07:40
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@Salute-Eva
Copy link
Contributor

@@ -0,0 +1,31 @@
import { useEffect, useRef } from 'react';

const ROOT_FONT_SIZE = 16;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

предлагаю экспортнуть эту переменную из TextArea.tsx, чтобы не следить за этими переменными в двух местах

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from 4886021 to c3c455d Compare July 14, 2023 09:40
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

const inputRef = useRef<HTMLTextAreaElement | null>(null);
const forkRef = useForkRef(inputRef, outerRef);

useAutoResize(autoResize, inputRef, value, minAuto, maxAuto);
Copy link
Collaborator

@neretin-trike neretin-trike Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а что думаешь на счёт выноса этого хука на уровень выше в TextArea.tsx с прокидыванием всех свойств сюда? Чтобы не дублировать эту логику в оба View, т.к. функционал по сути тот же самый

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да, ты прав. Теперь в одном месте всё

@Salute-Eva
Copy link
Contributor

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from c3c455d to 39f3528 Compare July 14, 2023 10:27
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@kayman233 kayman233 force-pushed the kayman233/text-area-autoresize.PLASMA-2032 branch from 39f3528 to f4a1134 Compare July 14, 2023 10:34
@Salute-Eva
Copy link
Contributor

Theme Builder app deployed!

http://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-614/

@Salute-Eva
Copy link
Contributor

@Yeti-or Yeti-or added this pull request to the merge queue Jul 26, 2023
Merged via the queue into dev with commit b292706 Jul 26, 2023
@Yeti-or Yeti-or deleted the kayman233/text-area-autoresize.PLASMA-2032 branch July 26, 2023 07:58
@Salute-Eva
Copy link
Contributor

🚀 This PR is included in version: @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected], @salutejs/[email protected] 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants