frst-components 0.22.20 → 0.22.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3321,7 +3321,7 @@ const InputText$4 = styled__default["default"].div `
3321
3321
  width: 100%;
3322
3322
  height: ${({ height }) => height || '20px'};
3323
3323
  outline: 0;
3324
- color: ${({ theme, isPlaceholder }) => !isPlaceholder ? theme.colors.neutralsGrey1 : theme.colors.neutralsGrey4};
3324
+ color: ${({ theme }) => theme.colors.neutralsGrey1};
3325
3325
  font-family: 'Work Sans';
3326
3326
  font-style: normal;
3327
3327
  font-weight: normal;
@@ -3333,7 +3333,26 @@ const InputText$4 = styled__default["default"].div `
3333
3333
 
3334
3334
 
3335
3335
  padding: 0;
3336
- margin: ${({ isPlaceholder }) => isPlaceholder ? '10px 4px 10px 15px' : '10px 4px 40px 15px'};
3336
+ margin: 10px 4px 40px 15px;
3337
+ border: none;
3338
+ `;
3339
+ const InputPlaceholder = styled__default["default"].div `
3340
+ width: 100%;
3341
+ height: ${({ height }) => height || '20px'};
3342
+ outline: 0;
3343
+ color: ${({ theme }) => theme.colors.neutralsGrey4};
3344
+ font-family: 'Work Sans';
3345
+ font-style: normal;
3346
+ font-weight: normal;
3347
+ font-size: 16px;
3348
+ letter-spacing: -0.02em;
3349
+ border: 1px solid ${({ theme }) => theme.colors.neutralsGrey3};
3350
+ overflow: hidden;
3351
+ background-color: inherit;
3352
+
3353
+
3354
+ padding: 0;
3355
+ margin: 10px 4px 10px 15px;
3337
3356
  border: none;
3338
3357
  `;
3339
3358
  styled__default["default"].div `
@@ -3407,7 +3426,7 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3407
3426
  const [showMention, setShowMention] = React.useState(false);
3408
3427
  const [inputSearch, setInputSearch] = React.useState('');
3409
3428
  const divInputRef = React.useRef(null);
3410
- const mainContainerRef = React.useRef(null);
3429
+ const divPlaceholder = React.useRef(null);
3411
3430
  const mentionTopPosition = `${(divInputRef.current?.clientHeight ?? 15) + 20}px`;
3412
3431
  const [textLength, setTextLength] = React.useState(0);
3413
3432
  const [isPlaceholder, setPlaceholder] = React.useState(false);
@@ -3566,45 +3585,43 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3566
3585
  setTextLength(count);
3567
3586
  return count;
3568
3587
  };
3569
- const clearDivContent = () => {
3570
- if (!divInputRef.current)
3571
- return;
3572
- console.log(`active element = ${document.activeElement}`);
3573
- if ((divInputRef.current.childNodes.length === 0 && !focus)) {
3574
- // create a textnode with the placeholder
3575
- divInputRef.current.innerText = placeholder;
3576
- setPlaceholder(true);
3577
- }
3578
- else if (!focus && divInputRef.current.childNodes.length >= 1) {
3579
- // loop over all child element and check if they are empty
3580
- let isEmpty = true;
3588
+ const areChildrenEmpty = () => {
3589
+ // return if divInputRef has child empty
3590
+ let isEmpty = false;
3591
+ //if divInputRef is not focused
3592
+ const isFocused = divInputRef.current === document.activeElement;
3593
+ if (divInputRef.current && !isFocused) {
3581
3594
  divInputRef.current.childNodes.forEach((child) => {
3582
- if (child.textContent !== '' && child.textContent != placeholder) {
3583
- isEmpty = false;
3584
- setPlaceholder(false);
3585
- }
3586
- else if (child.textContent === placeholder) {
3587
- divInputRef.current.blur();
3595
+ console.log(divInputRef.current.childNodes);
3596
+ console.log(divInputRef.current.innerText);
3597
+ console.log(child.textContent);
3598
+ if (child.textContent.length <= 0) {
3599
+ isEmpty = true;
3588
3600
  }
3589
3601
  });
3590
- // if they are empty show the placeholder
3591
- if (isEmpty) {
3592
- // create a textnode with the placeholder
3593
- divInputRef.current.innerText = placeholder;
3594
- setPlaceholder(true);
3595
- }
3596
3602
  }
3597
- else if (divInputRef.current.innerText === placeholder) {
3598
- // create a paragraph node
3599
- divInputRef.current.innerHTML = '';
3600
- // clear complete the div
3601
- divInputRef.current.innerText = '';
3602
- const p = document.createElement('p');
3603
- const br = document.createElement('br');
3604
- p.appendChild(br);
3605
- divInputRef.current.appendChild(p);
3603
+ return isEmpty;
3604
+ };
3605
+ const handlePlaceholderInputText = (isPlaceHolderFocus = false) => {
3606
+ // if divInputRef has any element hide the placeholder
3607
+ if (isPlaceHolderFocus) {
3608
+ divPlaceholder.current?.style.setProperty('display', 'none');
3609
+ divInputRef.current.style.setProperty('display', 'block');
3610
+ divInputRef.current.focus();
3606
3611
  setPlaceholder(false);
3607
3612
  }
3613
+ else {
3614
+ if (!areChildrenEmpty()) {
3615
+ divPlaceholder.current?.style.setProperty('display', 'none');
3616
+ divInputRef.current.style.setProperty('display', 'block');
3617
+ setPlaceholder(false);
3618
+ }
3619
+ else {
3620
+ divPlaceholder.current?.style.setProperty('display', 'block');
3621
+ divInputRef.current.style.setProperty('display', 'none');
3622
+ setPlaceholder(true);
3623
+ }
3624
+ }
3608
3625
  };
3609
3626
  React.useEffect(() => {
3610
3627
  divInputRef.current?.addEventListener('input', resizeDiv);
@@ -3613,8 +3630,10 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3613
3630
  };
3614
3631
  }, []);
3615
3632
  React.useEffect(() => {
3616
- if (!replyMentionedUser || !divInputRef?.current)
3633
+ if (!replyMentionedUser || !divInputRef?.current) {
3634
+ handlePlaceholderInputText();
3617
3635
  return;
3636
+ }
3618
3637
  divInputRef.current?.focus();
3619
3638
  const selection = window.getSelection();
3620
3639
  if (selection && selection.rangeCount > 0) {
@@ -3625,44 +3644,41 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3625
3644
  const spaceNode = document.createTextNode('\u00A0'); // Unicode for non-breaking space
3626
3645
  addMentionToRangeAndSpaceNode(range, spaceNode, mentionedUser);
3627
3646
  createNewRangeAndMoveCursorToTheEnd(selection, spaceNode);
3647
+ handlePlaceholderInputText();
3628
3648
  }
3629
3649
  }, [replyMentionedUser]);
3630
- React.useEffect(() => {
3631
- setPlaceholder(false);
3632
- if ((!value || value.length <= 0) && !focus && !replyMentionedUser) {
3633
- divInputRef.current.innerText = placeholder;
3634
- setPlaceholder(true);
3635
- resizeDiv();
3636
- }
3637
- }, [value]);
3638
- React.useEffect(() => {
3639
- if (!divInputRef.current)
3640
- return;
3641
- clearDivContent();
3642
- }, [focus]);
3643
3650
  React.useEffect(() => {
3644
3651
  setStyleLimitExceeded(textLength > limit);
3645
3652
  }, [textLength]);
3646
3653
  React.useEffect(() => {
3647
- if (!divInputRef.current || !mainContainerRef.current)
3654
+ if (!divInputRef.current || !divPlaceholder.current)
3648
3655
  return;
3649
- divInputRef.current.addEventListener('mousedown', () => {
3650
- setFocus(true);
3656
+ document.addEventListener('mousedown', () => {
3657
+ handlePlaceholderInputText();
3651
3658
  });
3652
- divInputRef.current.addEventListener('focus', () => {
3653
- setFocus(true);
3659
+ document.addEventListener('focus', () => {
3660
+ handlePlaceholderInputText();
3654
3661
  });
3655
- divInputRef.current.addEventListener('blur', () => {
3656
- setFocus(false);
3662
+ document.addEventListener('blur', () => {
3663
+ handlePlaceholderInputText();
3664
+ });
3665
+ divPlaceholder.current.addEventListener('mousedown', () => {
3666
+ handlePlaceholderInputText(true);
3667
+ });
3668
+ divPlaceholder.current.addEventListener('focus', () => {
3669
+ handlePlaceholderInputText(true);
3670
+ });
3671
+ divPlaceholder.current.addEventListener('blur', () => {
3672
+ handlePlaceholderInputText(true);
3657
3673
  });
3658
- mainContainerRef.current.addEventListener('mousedown', () => {
3659
- setFocus(true);
3674
+ divInputRef.current.addEventListener('mousedown', () => {
3675
+ handlePlaceholderInputText();
3660
3676
  });
3661
- mainContainerRef.current.addEventListener('focus', () => {
3662
- setFocus(true);
3677
+ divInputRef.current.addEventListener('focus', () => {
3678
+ handlePlaceholderInputText();
3663
3679
  });
3664
- mainContainerRef.current.addEventListener('blur', () => {
3665
- setFocus(false);
3680
+ divInputRef.current.addEventListener('blur', () => {
3681
+ handlePlaceholderInputText();
3666
3682
  });
3667
3683
  //capture the cursor position on arrow up and down or left and right and check if it´s close to the @ key
3668
3684
  divInputRef.current.addEventListener('keyup', (event) => {
@@ -3671,23 +3687,32 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3671
3687
  }
3672
3688
  });
3673
3689
  return () => {
3674
- divInputRef.current?.removeEventListener('mousedown', () => {
3675
- setFocus(true);
3690
+ document.removeEventListener('mousedown', () => {
3691
+ handlePlaceholderInputText();
3692
+ });
3693
+ document.removeEventListener('focus', () => {
3694
+ handlePlaceholderInputText();
3695
+ });
3696
+ document.removeEventListener('blur', () => {
3697
+ handlePlaceholderInputText();
3698
+ });
3699
+ divPlaceholder.current.removeEventListener('mousedown', () => {
3700
+ handlePlaceholderInputText(true);
3676
3701
  });
3677
- divInputRef.current?.removeEventListener('focus', () => {
3678
- setFocus(true);
3702
+ divPlaceholder.current.removeEventListener('focus', () => {
3703
+ handlePlaceholderInputText(true);
3679
3704
  });
3680
- divInputRef.current?.removeEventListener('blur', () => {
3681
- setFocus(false);
3705
+ divPlaceholder.current.removeEventListener('blur', () => {
3706
+ handlePlaceholderInputText(true);
3682
3707
  });
3683
- mainContainerRef.current?.removeEventListener('mousedown', () => {
3684
- setFocus(true);
3708
+ divInputRef.current.removeEventListener('mousedown', () => {
3709
+ handlePlaceholderInputText();
3685
3710
  });
3686
- mainContainerRef.current?.removeEventListener('focus', () => {
3687
- setFocus(true);
3711
+ divInputRef.current.removeEventListener('focus', () => {
3712
+ handlePlaceholderInputText();
3688
3713
  });
3689
- mainContainerRef.current?.removeEventListener('blur', () => {
3690
- setFocus(false);
3714
+ divInputRef.current.removeEventListener('blur', () => {
3715
+ handlePlaceholderInputText();
3691
3716
  });
3692
3717
  //capture the cursor position on arrow up and down or left and right and check if it´s close to the @ key
3693
3718
  divInputRef.current.removeEventListener('keyup', (event) => {
@@ -3699,7 +3724,7 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3699
3724
  }, []);
3700
3725
  return {
3701
3726
  handleInput,
3702
- clearDivContent,
3727
+ handlePlaceholderInputText,
3703
3728
  focus,
3704
3729
  showMention,
3705
3730
  setShowMention,
@@ -3711,7 +3736,7 @@ const useInputHook = ({ limit, placeholder, onSendMentions, onContentFormat, onC
3711
3736
  textLength,
3712
3737
  isPlaceholder,
3713
3738
  styleLimitExceeded,
3714
- mainContainerRef
3739
+ divPlaceholder
3715
3740
  };
3716
3741
  };
3717
3742
 
@@ -3891,10 +3916,10 @@ const Mentions = (mention) => {
3891
3916
  };
3892
3917
 
3893
3918
  function InputComment$1({ placeholder, onChange, limit, users, showCharacterCounter, styles, onSendMentions, onContentFormat, onContentUnformat, disabled, className, value, replyMentionedUser, group_uuid, limitMessageExceeded }) {
3894
- const { mainContainerRef, handleInput, isPlaceholder, focus, divInputRef, handleMentionUser, mentionTopPosition, setShowMention, showMention, textLength, styleLimitExceeded } = useInputHook({ limit, placeholder, onContentFormat, onContentUnformat, onSendMentions, onChange, value, replyMentionedUser });
3895
- return (jsxRuntime.jsx(styled.ThemeProvider, { theme: FRSTTheme, children: jsxRuntime.jsxs("div", { ref: mainContainerRef, style: { minHeight: '48px', ...styles }, tabIndex: 0, children: [jsxRuntime.jsxs(InputWrapper$2, { focus: focus, tabIndex: 1, isPlaceholder: isPlaceholder, isInputLimit: styleLimitExceeded, children: [jsxRuntime.jsx(InputText$4, { tabIndex: 2, contentEditable: true, ref: divInputRef, onKeyUpCapture: (event) => {
3919
+ const { divPlaceholder, handleInput, isPlaceholder, focus, divInputRef, handleMentionUser, mentionTopPosition, setShowMention, showMention, textLength, styleLimitExceeded } = useInputHook({ limit, placeholder, onContentFormat, onContentUnformat, onSendMentions, onChange, value, replyMentionedUser });
3920
+ return (jsxRuntime.jsx(styled.ThemeProvider, { theme: FRSTTheme, children: jsxRuntime.jsxs("div", { style: { minHeight: '48px', ...styles }, tabIndex: 0, children: [jsxRuntime.jsxs(InputWrapper$2, { focus: focus, tabIndex: 1, isPlaceholder: isPlaceholder, isInputLimit: styleLimitExceeded, children: [jsxRuntime.jsx(InputText$4, { tabIndex: 2, contentEditable: true, ref: divInputRef, onKeyUpCapture: (event) => {
3896
3921
  handleInput(event);
3897
- }, "data-text": "enter", isPlaceholder: isPlaceholder, suppressContentEditableWarning: true, children: jsxRuntime.jsx("p", { children: jsxRuntime.jsx("br", {}) }) }), showMention && users && users.length > 0 && jsxRuntime.jsx(Mentions, { users: users, top: mentionTopPosition, onSelect: (user) => {
3922
+ }, "data-text": "enter", suppressContentEditableWarning: true, children: jsxRuntime.jsx("p", { children: jsxRuntime.jsx("br", {}) }) }), jsxRuntime.jsx(InputPlaceholder, { style: { display: 'none' }, contentEditable: true, ref: divPlaceholder, children: placeholder }), showMention && users && users.length > 0 && jsxRuntime.jsx(Mentions, { users: users, top: mentionTopPosition, onSelect: (user) => {
3898
3923
  setShowMention(false);
3899
3924
  handleMentionUser(user);
3900
3925
  } })] }), jsxRuntime.jsx(HelperContainer, { children: !isPlaceholder ?
@@ -10,10 +10,10 @@ interface IEmojiWindow {
10
10
  }
11
11
  interface TextArea {
12
12
  height?: string;
13
- isPlaceholder?: boolean;
14
13
  }
15
14
  export declare const InputWrapper: import("styled-components").StyledComponent<"div", any, Wrapper, never>;
16
15
  export declare const InputText: import("styled-components").StyledComponent<"div", any, TextArea, never>;
16
+ export declare const InputPlaceholder: import("styled-components").StyledComponent<"div", any, TextArea, never>;
17
17
  export declare const SmileIcon: import("styled-components").StyledComponent<"div", any, {}, never>;
18
18
  export declare const HelperContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
19
19
  export declare const HelperText: import("styled-components").StyledComponent<"span", any, {
@@ -1 +1 @@
1
- {"version":3,"file":"inputCommentStyles.d.ts","sourceRoot":"","sources":["../../../../src/components/input-comment/inputCommentStyles.ts"],"names":[],"mappings":"AAQA,UAAU,OAAO;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,UAAU,YAAY;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mBAAmB,CAAC,EAAE,GAAG,CAAA;CAC5B;AACD,UAAU,QAAQ;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CAE3B;AAED,eAAO,MAAM,YAAY,yEAoBxB,CAAA;AAED,eAAO,MAAM,SAAS,0EAkBrB,CAAA;AAED,eAAO,MAAM,SAAS,oEAiBrB,CAAA;AACD,eAAO,MAAM,eAAe,oEAG3B,CAAA;AACD,eAAO,MAAM,UAAU;mBAA8B,OAAO;SAkB3D,CAAA;AAED,eAAO,MAAM,WAAW,8EAWvB,CAAC;AACF,eAAO,MAAM,mBAAmB,oEAK/B,CAAA;AAGD,eAAO,MAAM,yBAAyB,qEAIrC,CAAA"}
1
+ {"version":3,"file":"inputCommentStyles.d.ts","sourceRoot":"","sources":["../../../../src/components/input-comment/inputCommentStyles.ts"],"names":[],"mappings":"AAQA,UAAU,OAAO;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,UAAU,YAAY;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,mBAAmB,CAAC,EAAE,GAAG,CAAA;CAC5B;AACD,UAAU,QAAQ;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAElB;AAED,eAAO,MAAM,YAAY,yEAoBxB,CAAA;AAED,eAAO,MAAM,SAAS,0EAkBrB,CAAA;AACD,eAAO,MAAM,gBAAgB,0EAkB5B,CAAA;AACD,eAAO,MAAM,SAAS,oEAiBrB,CAAA;AACD,eAAO,MAAM,eAAe,oEAG3B,CAAA;AACD,eAAO,MAAM,UAAU;mBAA8B,OAAO;SAkB3D,CAAA;AAED,eAAO,MAAM,WAAW,8EAWvB,CAAC;AACF,eAAO,MAAM,mBAAmB,oEAK/B,CAAA;AAGD,eAAO,MAAM,yBAAyB,qEAIrC,CAAA"}
@@ -12,7 +12,7 @@ interface IInputHook {
12
12
  }
13
13
  export declare const useInputHook: ({ limit, placeholder, onSendMentions, onContentFormat, onContentUnformat, onChange, value, replyMentionedUser }: IInputHook) => {
14
14
  handleInput: (event: React.KeyboardEvent) => void;
15
- clearDivContent: () => void;
15
+ handlePlaceholderInputText: (isPlaceHolderFocus?: boolean) => void;
16
16
  focus: boolean;
17
17
  showMention: boolean;
18
18
  setShowMention: React.Dispatch<React.SetStateAction<boolean>>;
@@ -24,7 +24,7 @@ export declare const useInputHook: ({ limit, placeholder, onSendMentions, onCont
24
24
  textLength: number;
25
25
  isPlaceholder: boolean;
26
26
  styleLimitExceeded: boolean;
27
- mainContainerRef: React.MutableRefObject<HTMLDivElement>;
27
+ divPlaceholder: React.MutableRefObject<HTMLDivElement>;
28
28
  };
29
29
  export {};
30
30
  //# sourceMappingURL=useInputHook.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInputHook.d.ts","sourceRoot":"","sources":["../../../../src/components/input-comment/useInputHook.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,UAAU,UAAU;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IAC5C,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1C,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAC5B;AAED,eAAO,MAAM,YAAY,oHAAqH,UAAU;yBA4HxH,mBAAmB;;;;;;;;;8BA/Ed,IAAI;;;;;CAoTxC,CAAA"}
1
+ {"version":3,"file":"useInputHook.d.ts","sourceRoot":"","sources":["../../../../src/components/input-comment/useInputHook.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,UAAU,UAAU;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IAC5C,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1C,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAC5B;AAED,eAAO,MAAM,YAAY,oHAAqH,UAAU;yBA4HxH,mBAAmB;sDAmFQ,OAAO;;;;;;;;8BAlK7B,IAAI;;;;;CAiUxC,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "frst-components",
3
3
  "homepage": "http://FRST-Falconi.github.io/storybook.frstfalconi.com",
4
- "version": "0.22.20",
4
+ "version": "0.22.21",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",