[Glitch] Profile redesign: Add Intl.Segmenter fallback
Port 9a076359b9dd1a58ebf084d7b9361a3882ba4857 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
a70fd75a1a
commit
37b4329c75
@ -1,9 +1,9 @@
|
|||||||
import { useMemo } from 'react';
|
|
||||||
|
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
import { length } from 'stringz';
|
||||||
|
|
||||||
import { polymorphicForwardRef } from '@/types/polymorphic';
|
import { polymorphicForwardRef } from '@/types/polymorphic';
|
||||||
|
|
||||||
import classes from './styles.module.scss';
|
import classes from './styles.module.scss';
|
||||||
@ -14,8 +14,6 @@ interface CharacterCounterProps {
|
|||||||
recommended?: boolean;
|
recommended?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const segmenter = new Intl.Segmenter();
|
|
||||||
|
|
||||||
export const CharacterCounter = polymorphicForwardRef<
|
export const CharacterCounter = polymorphicForwardRef<
|
||||||
'span',
|
'span',
|
||||||
CharacterCounterProps
|
CharacterCounterProps
|
||||||
@ -31,10 +29,7 @@ export const CharacterCounter = polymorphicForwardRef<
|
|||||||
},
|
},
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
const currentLength = useMemo(
|
const currentLength = length(currentString);
|
||||||
() => [...segmenter.segment(currentString)].length,
|
|
||||||
[currentString],
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<Component
|
<Component
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user