Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/constants/code/TextAnimations/textLoopCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const textLoop = {
usage: `import TextLoop from './TextLoop';

<TextLoop
text="React Bits"
text="React Bits"
shape="wave"
speed={90}
direction="forward"
Expand Down
20 changes: 17 additions & 3 deletions src/content/TextAnimations/TextLoop/TextLoop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const buildPath = (shape, curviness, ribbonWidth) => {
};

const TextLoop = ({
text = 'React Bits',
text = 'React Bits',
shape = 'wave',
path,
speed = 90,
Expand Down Expand Up @@ -78,8 +78,22 @@ const TextLoop = ({
const d = useMemo(() => path || buildPath(shape, curviness, ribbonWidth), [path, shape, curviness, ribbonWidth]);

const unit = useMemo(() => {
const base = uppercase ? String(text).toUpperCase() : String(text);
const gap = separator ? `\u00A0${separator}\u00A0` : '\u00A0\u00A0\u00A0';
let base = String(text ?? '');
let sep = separator ?? '';
if (uppercase) {
base = base.toUpperCase();
sep = sep.toUpperCase();
}
if (sep) {
// Strip any separator glyphs already present in the text so each
// repetition is joined by exactly one separator. A duplicated glyph
// breaks the textLength/lengthAdjust fit on the SVG path in stricter
// browsers (e.g. Firefox) and a separator can land on top of a letter.
base = base.split(sep).join('').replace(/[\s\u00A0]+/g, ' ').trim();
} else {
base = base.replace(/[\s\u00A0]+/g, ' ').trim();
}
const gap = sep ? `\u00A0${sep}\u00A0` : '\u00A0\u00A0\u00A0';
return `${base}${gap}`;
}, [text, separator, uppercase]);

Expand Down
4 changes: 2 additions & 2 deletions src/demo/TextAnimations/TextLoopDemo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import TextLoop from '../../content/TextAnimations/TextLoop/TextLoop';
import { textLoop } from '../../constants/code/TextAnimations/textLoopCode';

const DEFAULT_PROPS = {
text: 'React Bits',
text: 'React Bits',
shape: 'wave',
speed: 90,
direction: 'forward',
Expand Down Expand Up @@ -72,7 +72,7 @@ const TextLoopDemo = () => {

const propData = useMemo(
() => [
{ name: 'text', type: 'string', default: '"React Bits"', description: 'The phrase repeated along the curve.' },
{ name: 'text', type: 'string', default: '"React Bits"', description: 'The phrase repeated along the curve.' },
{
name: 'shape',
type: '"wave" | "circle" | "infinity" | "arch" | "line"',
Expand Down
20 changes: 17 additions & 3 deletions src/tailwind/TextAnimations/TextLoop/TextLoop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const buildPath = (shape, curviness, ribbonWidth) => {
};

const TextLoop = ({
text = 'React Bits',
text = 'React Bits',
shape = 'wave',
path,
speed = 90,
Expand Down Expand Up @@ -76,8 +76,22 @@ const TextLoop = ({
const d = useMemo(() => path || buildPath(shape, curviness, ribbonWidth), [path, shape, curviness, ribbonWidth]);

const unit = useMemo(() => {
const base = uppercase ? String(text).toUpperCase() : String(text);
const gap = separator ? `\u00A0${separator}\u00A0` : '\u00A0\u00A0\u00A0';
let base = String(text ?? '');
let sep = separator ?? '';
if (uppercase) {
base = base.toUpperCase();
sep = sep.toUpperCase();
}
if (sep) {
// Strip any separator glyphs already present in the text so each
// repetition is joined by exactly one separator. A duplicated glyph
// breaks the textLength/lengthAdjust fit on the SVG path in stricter
// browsers (e.g. Firefox) and a separator can land on top of a letter.
base = base.split(sep).join('').replace(/[\s\u00A0]+/g, ' ').trim();
} else {
base = base.replace(/[\s\u00A0]+/g, ' ').trim();
}
const gap = sep ? `\u00A0${sep}\u00A0` : '\u00A0\u00A0\u00A0';
return `${base}${gap}`;
}, [text, separator, uppercase]);

Expand Down
20 changes: 17 additions & 3 deletions src/ts-default/TextAnimations/TextLoop/TextLoop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const buildPath = (shape: TextLoopShape, curviness: number, ribbonWidth: number)
};

const TextLoop = ({
text = 'React Bits',
text = 'React Bits',
shape = 'wave',
path,
speed = 90,
Expand Down Expand Up @@ -107,8 +107,22 @@ const TextLoop = ({
const d = useMemo(() => path || buildPath(shape, curviness, ribbonWidth), [path, shape, curviness, ribbonWidth]);

const unit = useMemo(() => {
const base = uppercase ? String(text).toUpperCase() : String(text);
const gap = separator ? `\u00A0${separator}\u00A0` : '\u00A0\u00A0\u00A0';
let base = String(text ?? '');
let sep = separator ?? '';
if (uppercase) {
base = base.toUpperCase();
sep = sep.toUpperCase();
}
if (sep) {
// Strip any separator glyphs already present in the text so each
// repetition is joined by exactly one separator. A duplicated glyph
// breaks the textLength/lengthAdjust fit on the SVG path in stricter
// browsers (e.g. Firefox) and a separator can land on top of a letter.
base = base.split(sep).join('').replace(/[\s\u00A0]+/g, ' ').trim();
} else {
base = base.replace(/[\s\u00A0]+/g, ' ').trim();
}
const gap = sep ? `\u00A0${sep}\u00A0` : '\u00A0\u00A0\u00A0';
return `${base}${gap}`;
}, [text, separator, uppercase]);

Expand Down
20 changes: 17 additions & 3 deletions src/ts-tailwind/TextAnimations/TextLoop/TextLoop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const buildPath = (shape: TextLoopShape, curviness: number, ribbonWidth: number)
};

const TextLoop = ({
text = 'React Bits',
text = 'React Bits',
shape = 'wave',
path,
speed = 90,
Expand Down Expand Up @@ -105,8 +105,22 @@ const TextLoop = ({
const d = useMemo(() => path || buildPath(shape, curviness, ribbonWidth), [path, shape, curviness, ribbonWidth]);

const unit = useMemo(() => {
const base = uppercase ? String(text).toUpperCase() : String(text);
const gap = separator ? `\u00A0${separator}\u00A0` : '\u00A0\u00A0\u00A0';
let base = String(text ?? '');
let sep = separator ?? '';
if (uppercase) {
base = base.toUpperCase();
sep = sep.toUpperCase();
}
if (sep) {
// Strip any separator glyphs already present in the text so each
// repetition is joined by exactly one separator. A duplicated glyph
// breaks the textLength/lengthAdjust fit on the SVG path in stricter
// browsers (e.g. Firefox) and a separator can land on top of a letter.
base = base.split(sep).join('').replace(/[\s\u00A0]+/g, ' ').trim();
} else {
base = base.replace(/[\s\u00A0]+/g, ' ').trim();
}
const gap = sep ? `\u00A0${sep}\u00A0` : '\u00A0\u00A0\u00A0';
return `${base}${gap}`;
}, [text, separator, uppercase]);

Expand Down