Add 100 character buffer to read more
This commit is contained in:
parent
c9678c4877
commit
29b4148889
2 changed files with 37 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
import { action } from '@storybook/addon-actions';
|
import { action } from '@storybook/addon-actions';
|
||||||
import { text } from '@storybook/addon-knobs';
|
import { text } from '@storybook/addon-knobs';
|
||||||
|
@ -27,34 +27,49 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
||||||
text: text('text', overrideProps.text || ''),
|
text: text('text', overrideProps.text || ''),
|
||||||
});
|
});
|
||||||
|
|
||||||
story.add('Lots of cake with a cherry on top', () => (
|
function MessageBodyReadMoreTest({
|
||||||
<MessageBodyReadMore
|
text: messageBodyText,
|
||||||
{...createProps({
|
}: {
|
||||||
text: `x${'🍰'.repeat(399)}🍒`,
|
text: string;
|
||||||
})}
|
}): JSX.Element {
|
||||||
|
const [displayLimit, setDisplayLimit] = useState<number | undefined>();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MessageBodyReadMore
|
||||||
|
{...createProps({ text: messageBodyText })}
|
||||||
|
displayLimit={displayLimit}
|
||||||
|
messageExpanded={(_, newDisplayLimit) => setDisplayLimit(newDisplayLimit)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
story.add('Long text + 100 more', () => (
|
||||||
|
<MessageBodyReadMoreTest
|
||||||
|
text={`${'test '.repeat(160)}${'extra '.repeat(10)}`}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
story.add('Cherry overflow', () => (
|
story.add('Lots of cake with some cherries on top', () => (
|
||||||
<MessageBodyReadMore
|
<MessageBodyReadMoreTest text={`x${'🍰'.repeat(399)}${'🍒'.repeat(100)}`} />
|
||||||
{...createProps({
|
));
|
||||||
text: `x${'🍰'.repeat(400)}🍒`,
|
|
||||||
})}
|
story.add('Leafy not buffered', () => (
|
||||||
|
<MessageBodyReadMoreTest text={`x${'🌿'.repeat(450)}`} />
|
||||||
|
));
|
||||||
|
|
||||||
|
story.add('Links', () => (
|
||||||
|
<MessageBodyReadMoreTest
|
||||||
|
text={`${'test '.repeat(176)}https://www.signal.org`}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
story.add('Excessive amounts of cake', () => (
|
story.add('Excessive amounts of cake', () => (
|
||||||
<MessageBodyReadMore
|
<MessageBodyReadMoreTest text={`x${'🍰'.repeat(20000)}`} />
|
||||||
{...createProps({
|
|
||||||
text: `x${'🍰'.repeat(20000)}`,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
));
|
));
|
||||||
|
|
||||||
story.add('Long text', () => (
|
story.add('Long text', () => (
|
||||||
<MessageBodyReadMore
|
<MessageBodyReadMoreTest
|
||||||
{...createProps({
|
text={`
|
||||||
text: `
|
|
||||||
SCENE I. Rome. A street.
|
SCENE I. Rome. A street.
|
||||||
Enter FLAVIUS, MARULLUS, and certain Commoners
|
Enter FLAVIUS, MARULLUS, and certain Commoners
|
||||||
FLAVIUS
|
FLAVIUS
|
||||||
|
@ -151,7 +166,6 @@ story.add('Long text', () => (
|
||||||
Will make him fly an ordinary pitch,
|
Will make him fly an ordinary pitch,
|
||||||
Who else would soar above the view of men
|
Who else would soar above the view of men
|
||||||
And keep us all in servile fearfulness.
|
And keep us all in servile fearfulness.
|
||||||
`,
|
`}
|
||||||
})}
|
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -25,6 +25,7 @@ export type Props = Pick<
|
||||||
|
|
||||||
const INITIAL_LENGTH = 800;
|
const INITIAL_LENGTH = 800;
|
||||||
const INCREMENT_COUNT = 3000;
|
const INCREMENT_COUNT = 3000;
|
||||||
|
const BUFFER = 100;
|
||||||
|
|
||||||
function graphemeAwareSlice(
|
function graphemeAwareSlice(
|
||||||
str: string,
|
str: string,
|
||||||
|
@ -33,7 +34,7 @@ function graphemeAwareSlice(
|
||||||
hasReadMore: boolean;
|
hasReadMore: boolean;
|
||||||
text: string;
|
text: string;
|
||||||
} {
|
} {
|
||||||
if (str.length <= length) {
|
if (str.length <= length + BUFFER) {
|
||||||
return { text: str, hasReadMore: false };
|
return { text: str, hasReadMore: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue