From 4500e2c439d6853a8a8a38b4d565390469d938f4 Mon Sep 17 00:00:00 2001 From: Alexey Safronov Date: Wed, 2 Mar 2022 13:52:23 +0300 Subject: [PATCH] Web: Components: Added truncate helper --- .../sub-components/helpers.js | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/asc-web-components/input-with-chips/sub-components/helpers.js b/packages/asc-web-components/input-with-chips/sub-components/helpers.js index 0849f9e596..c50b0bc8f0 100644 --- a/packages/asc-web-components/input-with-chips/sub-components/helpers.js +++ b/packages/asc-web-components/input-with-chips/sub-components/helpers.js @@ -75,27 +75,21 @@ export const getChipsFromString = (value) => { ); }; +export const truncate = (str) => + str?.length > MAX_EMAIL_LENGTH + ? str?.slice(0, MAX_EMAIL_LENGTH) + "..." + : str; + export const sliceEmail = (it) => { if (typeof it === "string") { + const res = truncate(it); return { - label: - it.length > MAX_EMAIL_LENGTH - ? it.slice(0, MAX_EMAIL_LENGTH) + "..." - : it, - value: - it.length > MAX_EMAIL_LENGTH - ? it.slice(0, MAX_EMAIL_LENGTH) + "..." - : it, + label: res, + value: res, }; } return { - label: - it?.label?.length > MAX_LABEL_LENGTH - ? it?.label?.slice(0, MAX_LABEL_LENGTH) + "..." - : it?.label, - value: - it?.value?.length > MAX_VALUE_LENGTH - ? it?.value?.slice(0, MAX_VALUE_LENGTH) + "..." - : it?.value, + label: truncate(it?.label), + value: truncate(it?.value), }; };