@chayns-components/typewriter 5.0.0-beta.50 → 5.0.0-beta.53
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/lib/components/typewriter/Typewriter.js +25 -14
- package/lib/components/typewriter/Typewriter.js.map +1 -1
- package/lib/components/typewriter/Typewriter.styles.d.ts +4 -4
- package/lib/components/typewriter/Typewriter.styles.js +16 -4
- package/lib/components/typewriter/Typewriter.styles.js.map +1 -1
- package/package.json +3 -2
|
@@ -14,24 +14,35 @@ const Typewriter = _ref => {
|
|
|
14
14
|
children
|
|
15
15
|
} = _ref;
|
|
16
16
|
const [shownCharCount, setShownCharCount] = (0, _react.useState)(0);
|
|
17
|
-
const
|
|
17
|
+
const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
|
|
18
|
+
const isAnimatingText = shownCharCount !== children.length;
|
|
19
|
+
const handleClick = (0, _react.useCallback)(() => {
|
|
20
|
+
setShouldStopAnimation(true);
|
|
21
|
+
}, []);
|
|
18
22
|
(0, _react.useEffect)(() => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
setShownCharCount(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
let interval;
|
|
24
|
+
if (shouldStopAnimation) {
|
|
25
|
+
setShownCharCount(children.length);
|
|
26
|
+
} else {
|
|
27
|
+
setShownCharCount(0);
|
|
28
|
+
interval = window.setInterval(() => {
|
|
29
|
+
setShownCharCount(prevState => {
|
|
30
|
+
const nextState = prevState + 1;
|
|
31
|
+
if (nextState === children.length) {
|
|
32
|
+
window.clearInterval(interval);
|
|
33
|
+
}
|
|
34
|
+
return nextState;
|
|
35
|
+
});
|
|
36
|
+
}, 35);
|
|
37
|
+
}
|
|
29
38
|
return () => {
|
|
30
39
|
window.clearInterval(interval);
|
|
31
40
|
};
|
|
32
|
-
}, [children.length]);
|
|
33
|
-
const
|
|
34
|
-
return /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter,
|
|
41
|
+
}, [children.length, shouldStopAnimation]);
|
|
42
|
+
const shownText = (0, _react.useMemo)(() => (0, _utils.getSubTextFromHTML)(children, shownCharCount), [children, shownCharCount]);
|
|
43
|
+
return /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter, {
|
|
44
|
+
onClick: handleClick
|
|
45
|
+
}, /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
|
|
35
46
|
dangerouslySetInnerHTML: {
|
|
36
47
|
__html: shownText
|
|
37
48
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Typewriter.js","names":["Typewriter","children","shownCharCount","setShownCharCount","useState","
|
|
1
|
+
{"version":3,"file":"Typewriter.js","names":["Typewriter","children","shownCharCount","setShownCharCount","useState","shouldStopAnimation","setShouldStopAnimation","isAnimatingText","length","handleClick","useCallback","useEffect","interval","window","setInterval","prevState","nextState","clearInterval","shownText","useMemo","getSubTextFromHTML","__html","displayName"],"sources":["../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { getSubTextFromHTML } from './utils';\n\nexport type TypewriterProps = {\n /**\n * The text to type\n */\n children: string;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({ children }) => {\n const [shownCharCount, setShownCharCount] = useState(0);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n\n const isAnimatingText = shownCharCount !== children.length;\n\n const handleClick = useCallback(() => {\n setShouldStopAnimation(true);\n }, []);\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation) {\n setShownCharCount(children.length);\n } else {\n setShownCharCount(0);\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState + 1;\n\n if (nextState === children.length) {\n window.clearInterval(interval);\n }\n\n return nextState;\n });\n }, 35);\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [children.length, shouldStopAnimation]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(children, shownCharCount),\n [children, shownCharCount]\n );\n\n return (\n <StyledTypewriter onClick={handleClick}>\n <StyledTypewriterText\n dangerouslySetInnerHTML={{ __html: shownText }}\n isAnimatingText={isAnimatingText}\n />\n {isAnimatingText && <StyledTypewriterPseudoText>{children}</StyledTypewriterPseudoText>}\n </StyledTypewriter>\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":";;;;;;AAAA;AACA;AAKA;AAA6C;AAAA;AAS7C,MAAMA,UAA+B,GAAG,QAAkB;EAAA,IAAjB;IAAEC;EAAS,CAAC;EACjD,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAG,IAAAC,eAAQ,EAAC,CAAC,CAAC;EACvD,MAAM,CAACC,mBAAmB,EAAEC,sBAAsB,CAAC,GAAG,IAAAF,eAAQ,EAAC,KAAK,CAAC;EAErE,MAAMG,eAAe,GAAGL,cAAc,KAAKD,QAAQ,CAACO,MAAM;EAE1D,MAAMC,WAAW,GAAG,IAAAC,kBAAW,EAAC,MAAM;IAClCJ,sBAAsB,CAAC,IAAI,CAAC;EAChC,CAAC,EAAE,EAAE,CAAC;EAEN,IAAAK,gBAAS,EAAC,MAAM;IACZ,IAAIC,QAA4B;IAEhC,IAAIP,mBAAmB,EAAE;MACrBF,iBAAiB,CAACF,QAAQ,CAACO,MAAM,CAAC;IACtC,CAAC,MAAM;MACHL,iBAAiB,CAAC,CAAC,CAAC;MAEpBS,QAAQ,GAAGC,MAAM,CAACC,WAAW,CAAC,MAAM;QAChCX,iBAAiB,CAAEY,SAAS,IAAK;UAC7B,MAAMC,SAAS,GAAGD,SAAS,GAAG,CAAC;UAE/B,IAAIC,SAAS,KAAKf,QAAQ,CAACO,MAAM,EAAE;YAC/BK,MAAM,CAACI,aAAa,CAACL,QAAQ,CAAC;UAClC;UAEA,OAAOI,SAAS;QACpB,CAAC,CAAC;MACN,CAAC,EAAE,EAAE,CAAC;IACV;IAEA,OAAO,MAAM;MACTH,MAAM,CAACI,aAAa,CAACL,QAAQ,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,CAACX,QAAQ,CAACO,MAAM,EAAEH,mBAAmB,CAAC,CAAC;EAE1C,MAAMa,SAAS,GAAG,IAAAC,cAAO,EACrB,MAAM,IAAAC,yBAAkB,EAACnB,QAAQ,EAAEC,cAAc,CAAC,EAClD,CAACD,QAAQ,EAAEC,cAAc,CAAC,CAC7B;EAED,oBACI,6BAAC,4BAAgB;IAAC,OAAO,EAAEO;EAAY,gBACnC,6BAAC,gCAAoB;IACjB,uBAAuB,EAAE;MAAEY,MAAM,EAAEH;IAAU,CAAE;IAC/C,eAAe,EAAEX;EAAgB,EACnC,EACDA,eAAe,iBAAI,6BAAC,sCAA0B,QAAEN,QAAQ,CAA8B,CACxE;AAE3B,CAAC;AAEDD,UAAU,CAACsB,WAAW,GAAG,YAAY;AAAC,eAEvBtB,UAAU;AAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const StyledTypewriter: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
2
2
|
export declare const StyledTypewriterPseudoText: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
-
|
|
3
|
+
export declare const StyledTypewriterText: import("styled-components").StyledComponent<"div", any, {
|
|
4
4
|
isAnimatingText: boolean;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
} & {
|
|
6
|
+
theme: import("@chayns-components/core/lib/components/color-scheme-provider/ColorSchemeProvider").Theme;
|
|
7
|
+
}, never>;
|
|
@@ -23,20 +23,32 @@ const StyledTypewriterPseudoText = _styledComponents.default.div`
|
|
|
23
23
|
`;
|
|
24
24
|
exports.StyledTypewriterPseudoText = StyledTypewriterPseudoText;
|
|
25
25
|
const StyledTypewriterText = _styledComponents.default.div`
|
|
26
|
-
|
|
26
|
+
color: ${_ref => {
|
|
27
27
|
let {
|
|
28
|
-
|
|
28
|
+
theme
|
|
29
29
|
} = _ref;
|
|
30
|
+
return theme.text;
|
|
31
|
+
}};
|
|
32
|
+
position: ${_ref2 => {
|
|
33
|
+
let {
|
|
34
|
+
isAnimatingText
|
|
35
|
+
} = _ref2;
|
|
30
36
|
return isAnimatingText ? 'absolute' : 'relative';
|
|
31
37
|
}};
|
|
32
38
|
|
|
33
|
-
${
|
|
39
|
+
${_ref3 => {
|
|
34
40
|
let {
|
|
35
41
|
isAnimatingText
|
|
36
|
-
} =
|
|
42
|
+
} = _ref3;
|
|
37
43
|
return isAnimatingText && (0, _styledComponents.css)`
|
|
38
44
|
&:after {
|
|
39
45
|
animation: ${blinkAnimation} 1s steps(5, start) infinite;
|
|
46
|
+
color: ${_ref4 => {
|
|
47
|
+
let {
|
|
48
|
+
theme
|
|
49
|
+
} = _ref4;
|
|
50
|
+
return theme.text;
|
|
51
|
+
}};
|
|
40
52
|
content: '▋';
|
|
41
53
|
margin-left: 0.25rem;
|
|
42
54
|
opacity: 0.85;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Typewriter.styles.js","names":["StyledTypewriter","styled","div","blinkAnimation","keyframes","StyledTypewriterPseudoText","StyledTypewriterText","isAnimatingText","css"],"sources":["../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import styled, { css, keyframes } from 'styled-components';\n\nexport const StyledTypewriter = styled.div`\n position: relative;\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\nexport const StyledTypewriterPseudoText = styled.div`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n`;\n\ntype StyledTypewriterTextProps = {\n isAnimatingText: boolean;\n}
|
|
1
|
+
{"version":3,"file":"Typewriter.styles.js","names":["StyledTypewriter","styled","div","blinkAnimation","keyframes","StyledTypewriterPseudoText","StyledTypewriterText","theme","text","isAnimatingText","css"],"sources":["../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\n\nexport const StyledTypewriter = styled.div`\n position: relative;\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\nexport const StyledTypewriterPseudoText = styled.div`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n isAnimatingText: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.div<StyledTypewriterTextProps>`\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n position: ${({ isAnimatingText }) => (isAnimatingText ? 'absolute' : 'relative')};\n\n ${({ isAnimatingText }) =>\n isAnimatingText &&\n css`\n &:after {\n animation: ${blinkAnimation} 1s steps(5, start) infinite;\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n content: '▋';\n margin-left: 0.25rem;\n opacity: 0.85;\n vertical-align: baseline;\n }\n `}\n`;\n"],"mappings":";;;;;;AACA;AAA2D;AAAA;AAEpD,MAAMA,gBAAgB,GAAGC,yBAAM,CAACC,GAAI;AAC3C;AACA,CAAC;AAAC;AAEF,MAAMC,cAAc,GAAG,IAAAC,2BAAS,CAAC;AACjC;AACA;AACA;AACA,CAAC;AAEM,MAAMC,0BAA0B,GAAGJ,yBAAM,CAACC,GAAI;AACrD;AACA;AACA;AACA,CAAC;AAAC;AAMK,MAAMI,oBAAoB,GAAGL,yBAAM,CAACC,GAA+B;AAC1E,aAAa;EAAA,IAAC;IAAEK;EAAiC,CAAC;EAAA,OAAKA,KAAK,CAACC,IAAI;AAAA,CAAC;AAClE,gBAAgB;EAAA,IAAC;IAAEC;EAAgB,CAAC;EAAA,OAAMA,eAAe,GAAG,UAAU,GAAG,UAAU;AAAA,CAAE;AACrF;AACA,MAAM;EAAA,IAAC;IAAEA;EAAgB,CAAC;EAAA,OAClBA,eAAe,IACf,IAAAC,qBAAG,CAAC;AACZ;AACA,6BAA6BP,cAAe;AAC5C,yBAAyB;IAAA,IAAC;MAAEI;IAAiC,CAAC;IAAA,OAAKA,KAAK,CAACC,IAAI;EAAA,CAAC;AAC9E;AACA;AACA;AACA;AACA;AACA,SAAS;AAAA,CAAC;AACV,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/typewriter",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.53",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"typescript": "^4.9.5"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@chayns-components/core": "^5.0.0-beta.50",
|
|
52
53
|
"@chayns/colors": "^2.0.0",
|
|
53
54
|
"clsx": "^1.2.1",
|
|
54
55
|
"framer-motion": "^6.5.1",
|
|
@@ -62,5 +63,5 @@
|
|
|
62
63
|
"publishConfig": {
|
|
63
64
|
"access": "public"
|
|
64
65
|
},
|
|
65
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "34fbab1560e2bda449b9dbae992115bc51234f99"
|
|
66
67
|
}
|