@tamagui/text 1.0.1-beta.21 → 1.0.1-beta.211
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/cjs/Headings.js +80 -0
- package/dist/cjs/Headings.js.map +7 -0
- package/dist/cjs/Paragraph.js +1 -0
- package/dist/cjs/Paragraph.js.map +1 -1
- package/dist/cjs/SizableText.js +3 -1
- package/dist/cjs/SizableText.js.map +2 -2
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/wrapChildrenInText.js +99 -0
- package/dist/cjs/wrapChildrenInText.js.map +7 -0
- package/dist/cjs/wrapChildrenInText.test.js +33 -0
- package/dist/cjs/wrapChildrenInText.test.js.map +7 -0
- package/dist/esm/Headings.js +50 -0
- package/dist/esm/Headings.js.map +7 -0
- package/dist/esm/Paragraph.js +0 -0
- package/dist/esm/Paragraph.js.map +1 -1
- package/dist/esm/SizableText.js +3 -2
- package/dist/esm/SizableText.js.map +2 -2
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types.js +1 -0
- package/dist/{cjs/Texts.js.map → esm/types.js.map} +0 -0
- package/dist/esm/wrapChildrenInText.js +69 -0
- package/dist/esm/wrapChildrenInText.js.map +7 -0
- package/dist/esm/wrapChildrenInText.test.js +32 -0
- package/dist/esm/wrapChildrenInText.test.js.map +7 -0
- package/dist/jsx/.tamagui-dynamic-eval-Headings.js.js +42 -0
- package/dist/jsx/.tamagui-dynamic-eval-Paragraph.js.js +10 -0
- package/dist/jsx/.tamagui-dynamic-eval-SizableText.js.js +15 -0
- package/dist/jsx/Headings.js +50 -0
- package/dist/jsx/Headings.js.map +7 -0
- package/dist/jsx/Paragraph.js +1 -0
- package/dist/jsx/Paragraph.js.map +7 -0
- package/dist/jsx/SizableText.js +4 -2
- package/dist/jsx/SizableText.js.map +7 -0
- package/dist/jsx/index.js +4 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/types.js +1 -0
- package/dist/{esm/Texts.js.map → jsx/types.js.map} +0 -0
- package/dist/jsx/wrapChildrenInText.js +64 -0
- package/dist/jsx/wrapChildrenInText.js.map +7 -0
- package/dist/jsx/wrapChildrenInText.test.js +29 -0
- package/dist/jsx/wrapChildrenInText.test.js.map +7 -0
- package/package.json +18 -7
- package/src/Headings.tsx +48 -0
- package/src/Paragraph.tsx +12 -0
- package/src/SizableText.tsx +17 -0
- package/src/index.tsx +5 -0
- package/src/types.ts +13 -0
- package/src/wrapChildrenInText.test.tsx +40 -0
- package/src/wrapChildrenInText.tsx +76 -0
- package/types/Headings.d.ts +1452 -0
- package/types/Paragraph.d.ts +17 -15
- package/types/SizableText.d.ts +8 -8
- package/types/index.d.ts +3 -0
- package/types/types.d.ts +12 -0
- package/types/wrapChildrenInText.d.ts +10 -0
- package/types/wrapChildrenInText.test.d.ts +2 -0
- package/dist/cjs/Texts.js +0 -1
- package/dist/esm/Texts.js +0 -1
- package/dist/jsx/Texts.js +0 -0
- package/types/Paragraph.d.ts.map +0 -1
- package/types/SizableText.d.ts.map +0 -1
- package/types/Texts.d.ts +0 -1
- package/types/Texts.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { styled } from "@tamagui/core";
|
|
2
|
+
import { SizableText } from "./SizableText";
|
|
3
|
+
const Paragraph = styled(SizableText, {
|
|
4
|
+
name: "Paragraph",
|
|
5
|
+
tag: "p",
|
|
6
|
+
selectable: true,
|
|
7
|
+
cursor: "text"
|
|
8
|
+
});
|
|
9
|
+
export { Paragraph };
|
|
10
|
+
//# sourceMappingURL=Paragraph.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Text, getFont, styled } from "@tamagui/core";
|
|
2
|
+
const SizableText = styled(Text, {
|
|
3
|
+
name: "SizableText",
|
|
4
|
+
fontFamily: "$body",
|
|
5
|
+
variants: {
|
|
6
|
+
size: getFont
|
|
7
|
+
},
|
|
8
|
+
defaultVariants: {
|
|
9
|
+
size: "$4"
|
|
10
|
+
}
|
|
11
|
+
}, {
|
|
12
|
+
inlineWhenUnflattened: /* @__PURE__ */new Set(["fontFamily"])
|
|
13
|
+
});
|
|
14
|
+
export { SizableText };
|
|
15
|
+
//# sourceMappingURL=SizableText.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { styled } from "@tamagui/core";
|
|
2
|
+
import { Paragraph } from "./Paragraph";
|
|
3
|
+
const Heading = styled(Paragraph, {
|
|
4
|
+
tag: "span",
|
|
5
|
+
name: "Heading",
|
|
6
|
+
accessibilityRole: "header",
|
|
7
|
+
fontFamily: "$heading",
|
|
8
|
+
size: "$8",
|
|
9
|
+
margin: 0
|
|
10
|
+
});
|
|
11
|
+
const H1 = styled(Heading, {
|
|
12
|
+
name: "H1",
|
|
13
|
+
tag: "h1",
|
|
14
|
+
size: "$10"
|
|
15
|
+
});
|
|
16
|
+
const H2 = styled(Heading, {
|
|
17
|
+
name: "H2",
|
|
18
|
+
tag: "h2",
|
|
19
|
+
size: "$9"
|
|
20
|
+
});
|
|
21
|
+
const H3 = styled(Heading, {
|
|
22
|
+
name: "H3",
|
|
23
|
+
tag: "h3",
|
|
24
|
+
size: "$8"
|
|
25
|
+
});
|
|
26
|
+
const H4 = styled(Heading, {
|
|
27
|
+
name: "H4",
|
|
28
|
+
tag: "h4",
|
|
29
|
+
size: "$7"
|
|
30
|
+
});
|
|
31
|
+
const H5 = styled(Heading, {
|
|
32
|
+
name: "H5",
|
|
33
|
+
tag: "h5",
|
|
34
|
+
size: "$6"
|
|
35
|
+
});
|
|
36
|
+
const H6 = styled(Heading, {
|
|
37
|
+
name: "H6",
|
|
38
|
+
tag: "h6",
|
|
39
|
+
size: "$5"
|
|
40
|
+
});
|
|
41
|
+
export {
|
|
42
|
+
H1,
|
|
43
|
+
H2,
|
|
44
|
+
H3,
|
|
45
|
+
H4,
|
|
46
|
+
H5,
|
|
47
|
+
H6,
|
|
48
|
+
Heading
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=Headings.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Headings.tsx"],
|
|
4
|
+
"sourcesContent": ["import { styled } from '@tamagui/core'\n\nimport { Paragraph } from './Paragraph'\n\nexport const Heading = styled(Paragraph, {\n tag: 'span',\n name: 'Heading',\n accessibilityRole: 'header',\n fontFamily: '$heading',\n size: '$8',\n margin: 0,\n})\n\nexport const H1 = styled(Heading, {\n name: 'H1',\n tag: 'h1',\n size: '$10',\n})\n\nexport const H2 = styled(Heading, {\n name: 'H2',\n tag: 'h2',\n size: '$9',\n})\n\nexport const H3 = styled(Heading, {\n name: 'H3',\n tag: 'h3',\n size: '$8',\n})\n\nexport const H4 = styled(Heading, {\n name: 'H4',\n tag: 'h4',\n size: '$7',\n})\n\nexport const H5 = styled(Heading, {\n name: 'H5',\n tag: 'h5',\n size: '$6',\n})\n\nexport const H6 = styled(Heading, {\n name: 'H6',\n tag: 'h6',\n size: '$5',\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc;AAEvB,SAAS,iBAAiB;AAEnB,MAAM,UAAU,OAAO,WAAW;AAAA,EACvC,KAAK;AAAA,EACL,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,QAAQ;AACV,CAAC;AAEM,MAAM,KAAK,OAAO,SAAS;AAAA,EAChC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACR,CAAC;AAEM,MAAM,KAAK,OAAO,SAAS;AAAA,EAChC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACR,CAAC;AAEM,MAAM,KAAK,OAAO,SAAS;AAAA,EAChC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACR,CAAC;AAEM,MAAM,KAAK,OAAO,SAAS;AAAA,EAChC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACR,CAAC;AAEM,MAAM,KAAK,OAAO,SAAS;AAAA,EAChC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACR,CAAC;AAEM,MAAM,KAAK,OAAO,SAAS;AAAA,EAChC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACR,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/jsx/Paragraph.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Paragraph.tsx"],
|
|
4
|
+
"sourcesContent": ["import { PropTypes, styled } from '@tamagui/core'\n\nimport { SizableText } from './SizableText'\n\nexport const Paragraph = styled(SizableText, {\n name: 'Paragraph',\n tag: 'p',\n selectable: true,\n cursor: 'text',\n})\n\nexport type ParagraphProps = PropTypes<typeof Paragraph>\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,cAAc;AAElC,SAAS,mBAAmB;AAErB,MAAM,YAAY,OAAO,aAAa;AAAA,EAC3C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,QAAQ;AACV,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/jsx/SizableText.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Text,
|
|
1
|
+
import { Text, styled } from "@tamagui/core";
|
|
2
|
+
import { getFontSized } from "@tamagui/get-font-sized";
|
|
2
3
|
const SizableText = styled(Text, {
|
|
3
4
|
name: "SizableText",
|
|
4
5
|
fontFamily: "$body",
|
|
5
6
|
variants: {
|
|
6
|
-
size:
|
|
7
|
+
size: getFontSized
|
|
7
8
|
},
|
|
8
9
|
defaultVariants: {
|
|
9
10
|
size: "$4"
|
|
@@ -12,3 +13,4 @@ const SizableText = styled(Text, {
|
|
|
12
13
|
export {
|
|
13
14
|
SizableText
|
|
14
15
|
};
|
|
16
|
+
//# sourceMappingURL=SizableText.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/SizableText.tsx"],
|
|
4
|
+
"sourcesContent": ["import { GetProps, Text, styled } from '@tamagui/core'\nimport { getFontSized } from '@tamagui/get-font-sized'\n\nexport const SizableText = styled(Text, {\n name: 'SizableText',\n fontFamily: '$body',\n\n variants: {\n size: getFontSized,\n } as const,\n\n defaultVariants: {\n size: '$4',\n },\n})\n\nexport type SizableTextProps = GetProps<typeof SizableText>\n"],
|
|
5
|
+
"mappings": "AAAA,SAAmB,MAAM,cAAc;AACvC,SAAS,oBAAoB;AAEtB,MAAM,cAAc,OAAO,MAAM;AAAA,EACtC,MAAM;AAAA,EACN,YAAY;AAAA,EAEZ,UAAU;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EAEA,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/jsx/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.tsx"],
|
|
4
|
+
"sourcesContent": ["export * from './SizableText'\nexport * from './Paragraph'\nexport * from './Headings'\nexport * from './wrapChildrenInText'\nexport * from './types'\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
function wrapChildrenInText(TextComponent, propsIn) {
|
|
3
|
+
const {
|
|
4
|
+
children,
|
|
5
|
+
textProps,
|
|
6
|
+
size,
|
|
7
|
+
noTextWrap,
|
|
8
|
+
color,
|
|
9
|
+
fontFamily,
|
|
10
|
+
fontSize,
|
|
11
|
+
fontWeight,
|
|
12
|
+
letterSpacing,
|
|
13
|
+
textAlign
|
|
14
|
+
} = propsIn;
|
|
15
|
+
if (noTextWrap || !children) {
|
|
16
|
+
return children;
|
|
17
|
+
}
|
|
18
|
+
const allChildren = React.Children.toArray(children);
|
|
19
|
+
const nextChildren = [];
|
|
20
|
+
let lastIsString = false;
|
|
21
|
+
const props = {};
|
|
22
|
+
if (color)
|
|
23
|
+
props.color = color;
|
|
24
|
+
if (fontFamily)
|
|
25
|
+
props.fontFamily = fontFamily;
|
|
26
|
+
if (fontSize)
|
|
27
|
+
props.fontSize = fontSize;
|
|
28
|
+
if (fontWeight)
|
|
29
|
+
props.fontWeight = fontWeight;
|
|
30
|
+
if (letterSpacing)
|
|
31
|
+
props.letterSpacing = letterSpacing;
|
|
32
|
+
if (textAlign)
|
|
33
|
+
props.textAlign = textAlign;
|
|
34
|
+
if (size)
|
|
35
|
+
props.size = size;
|
|
36
|
+
function concatStringChildren() {
|
|
37
|
+
if (!lastIsString)
|
|
38
|
+
return;
|
|
39
|
+
const index = nextChildren.length - 1;
|
|
40
|
+
const childrenStrings = nextChildren[index];
|
|
41
|
+
nextChildren[index] = <TextComponent key={index} {...props} {...textProps}>{childrenStrings}</TextComponent>;
|
|
42
|
+
}
|
|
43
|
+
for (const child of allChildren) {
|
|
44
|
+
const last = nextChildren[nextChildren.length - 1];
|
|
45
|
+
const isString = typeof child === "string";
|
|
46
|
+
if (isString) {
|
|
47
|
+
if (lastIsString) {
|
|
48
|
+
last.push(child);
|
|
49
|
+
} else {
|
|
50
|
+
nextChildren.push([child]);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
concatStringChildren();
|
|
54
|
+
nextChildren.push(child);
|
|
55
|
+
}
|
|
56
|
+
lastIsString = isString;
|
|
57
|
+
}
|
|
58
|
+
concatStringChildren();
|
|
59
|
+
return nextChildren;
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
wrapChildrenInText
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=wrapChildrenInText.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/wrapChildrenInText.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { SizeTokens } from '@tamagui/core'\nimport React from 'react'\n\nimport { TextParentStyles } from './types'\n\ntype Props = TextParentStyles & {\n children?: React.ReactNode\n size?: SizeTokens\n}\n\nexport function wrapChildrenInText(TextComponent: any, propsIn: Props) {\n const {\n children,\n textProps,\n size,\n noTextWrap,\n color,\n fontFamily,\n fontSize,\n fontWeight,\n letterSpacing,\n textAlign,\n } = propsIn\n\n if (noTextWrap || !children) {\n return children\n }\n\n // in the case of using variables, like so:\n // <ListItem>Hello, {name}</ListItem>\n // it gives us props.children as ['Hello, ', 'name']\n // but we don't want to wrap multiple SizableText around each part\n // so we group them\n const allChildren = React.Children.toArray(children)\n const nextChildren: any[] = []\n let lastIsString = false\n const props: any = {}\n // to avoid setting undefined\n if (color) props.color = color\n if (fontFamily) props.fontFamily = fontFamily\n if (fontSize) props.fontSize = fontSize\n if (fontWeight) props.fontWeight = fontWeight\n if (letterSpacing) props.letterSpacing = letterSpacing\n if (textAlign) props.textAlign = textAlign\n if (size) props.size = size\n\n function concatStringChildren() {\n if (!lastIsString) return\n const index = nextChildren.length - 1\n const childrenStrings = nextChildren[index]\n nextChildren[index] = (\n <TextComponent key={index} {...props} {...textProps}>\n {childrenStrings}\n </TextComponent>\n )\n }\n\n for (const child of allChildren) {\n const last = nextChildren[nextChildren.length - 1]\n const isString = typeof child === 'string'\n if (isString) {\n if (lastIsString) {\n last.push(child)\n } else {\n nextChildren.push([child])\n }\n } else {\n concatStringChildren()\n nextChildren.push(child)\n }\n lastIsString = isString\n }\n concatStringChildren()\n\n return nextChildren\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,WAAW;AASX,SAAS,mBAAmB,eAAoB,SAAgB;AACrE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,cAAc,CAAC,UAAU;AAC3B,WAAO;AAAA,EACT;AAOA,QAAM,cAAc,MAAM,SAAS,QAAQ,QAAQ;AACnD,QAAM,eAAsB,CAAC;AAC7B,MAAI,eAAe;AACnB,QAAM,QAAa,CAAC;AAEpB,MAAI;AAAO,UAAM,QAAQ;AACzB,MAAI;AAAY,UAAM,aAAa;AACnC,MAAI;AAAU,UAAM,WAAW;AAC/B,MAAI;AAAY,UAAM,aAAa;AACnC,MAAI;AAAe,UAAM,gBAAgB;AACzC,MAAI;AAAW,UAAM,YAAY;AACjC,MAAI;AAAM,UAAM,OAAO;AAEvB,WAAS,uBAAuB;AAC9B,QAAI,CAAC;AAAc;AACnB,UAAM,QAAQ,aAAa,SAAS;AACpC,UAAM,kBAAkB,aAAa;AACrC,iBAAa,SACX,CAAC,cAAc,KAAK,WAAW,WAAW,YACvC,gBACH,EAFC;AAAA,EAIL;AAEA,aAAW,SAAS,aAAa;AAC/B,UAAM,OAAO,aAAa,aAAa,SAAS;AAChD,UAAM,WAAW,OAAO,UAAU;AAClC,QAAI,UAAU;AACZ,UAAI,cAAc;AAChB,aAAK,KAAK,KAAK;AAAA,MACjB,OAAO;AACL,qBAAa,KAAK,CAAC,KAAK,CAAC;AAAA,MAC3B;AAAA,IACF,OAAO;AACL,2BAAqB;AACrB,mBAAa,KAAK,KAAK;AAAA,IACzB;AACA,mBAAe;AAAA,EACjB;AACA,uBAAqB;AAErB,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { wrapChildrenInText } from "./wrapChildrenInText";
|
|
3
|
+
const Comp = () => {
|
|
4
|
+
};
|
|
5
|
+
const re = <div data-id={Math.random()} />;
|
|
6
|
+
const reID = re.props["data-id"];
|
|
7
|
+
test("should wrap all string children, not wrap others", () => {
|
|
8
|
+
const out = wrapChildrenInText(Comp, {
|
|
9
|
+
children: [re, "a", "b", re, "c", re, "d"]
|
|
10
|
+
});
|
|
11
|
+
expect(out[0].props["data-id"]).toBe(reID);
|
|
12
|
+
expect(out[1].type).toBe(Comp);
|
|
13
|
+
expect(out[1].props.children).toStrictEqual(["a", "b"]);
|
|
14
|
+
expect(out[2].props["data-id"]).toBe(reID);
|
|
15
|
+
expect(out[3].type).toBe(Comp);
|
|
16
|
+
expect(out[3].props.children).toStrictEqual(["c"]);
|
|
17
|
+
expect(out[4].props["data-id"]).toBe(reID);
|
|
18
|
+
expect(out[5].type).toBe(Comp);
|
|
19
|
+
expect(out[5].props.children).toStrictEqual(["d"]);
|
|
20
|
+
});
|
|
21
|
+
test("should first child string", () => {
|
|
22
|
+
const out = wrapChildrenInText(Comp, {
|
|
23
|
+
children: ["a", re]
|
|
24
|
+
});
|
|
25
|
+
expect(out[0].type).toBe(Comp);
|
|
26
|
+
expect(out[0].props.children).toStrictEqual(["a"]);
|
|
27
|
+
expect(out[1].props["data-id"]).toBe(reID);
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=wrapChildrenInText.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/wrapChildrenInText.test.tsx"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { expect, test } from 'vitest'\n\nimport { wrapChildrenInText } from './wrapChildrenInText'\n\nconst Comp = () => {}\nconst re = <div data-id={Math.random()} />\nconst reID = re.props['data-id']\n\ntest('should wrap all string children, not wrap others', () => {\n const out = wrapChildrenInText(Comp, {\n children: [re, 'a', 'b', re, 'c', re, 'd'],\n }) as any\n\n expect(out[0].props['data-id']).toBe(reID)\n\n expect(out[1].type).toBe(Comp)\n expect(out[1].props.children).toStrictEqual(['a', 'b'])\n\n expect(out[2].props['data-id']).toBe(reID)\n\n expect(out[3].type).toBe(Comp)\n expect(out[3].props.children).toStrictEqual(['c'])\n\n expect(out[4].props['data-id']).toBe(reID)\n\n expect(out[5].type).toBe(Comp)\n expect(out[5].props.children).toStrictEqual(['d'])\n})\n\ntest('should first child string', () => {\n const out = wrapChildrenInText(Comp, {\n children: ['a', re],\n }) as any\n\n expect(out[0].type).toBe(Comp)\n expect(out[0].props.children).toStrictEqual(['a'])\n\n expect(out[1].props['data-id']).toBe(reID)\n})\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,QAAQ,YAAY;AAE7B,SAAS,0BAA0B;AAEnC,MAAM,OAAO,MAAM;AAAC;AACpB,MAAM,KAAK,CAAC,IAAI,SAAS,KAAK,OAAO,GAAG;AACxC,MAAM,OAAO,GAAG,MAAM;AAEtB,KAAK,oDAAoD,MAAM;AAC7D,QAAM,MAAM,mBAAmB,MAAM;AAAA,IACnC,UAAU,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,GAAG;AAAA,EAC3C,CAAC;AAED,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,KAAK,GAAG,CAAC;AAEtD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AACnD,CAAC;AAED,KAAK,6BAA6B,MAAM;AACtC,QAAM,MAAM,mBAAmB,MAAM;AAAA,IACnC,UAAU,CAAC,KAAK,EAAE;AAAA,EACpB,CAAC;AAED,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAC3C,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,31 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/text",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
4
|
-
"sideEffects":
|
|
3
|
+
"version": "1.0.1-beta.211",
|
|
4
|
+
"sideEffects": [
|
|
5
|
+
"*.css"
|
|
6
|
+
],
|
|
5
7
|
"source": "src/index.ts",
|
|
6
|
-
"
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
7
9
|
"main": "dist/cjs",
|
|
8
10
|
"module": "dist/esm",
|
|
9
11
|
"module:jsx": "dist/jsx",
|
|
10
12
|
"files": [
|
|
13
|
+
"src",
|
|
11
14
|
"types",
|
|
12
15
|
"dist"
|
|
13
16
|
],
|
|
14
17
|
"scripts": {
|
|
15
18
|
"build": "tamagui-build",
|
|
16
|
-
"watch": "tamagui-build --watch"
|
|
19
|
+
"watch": "tamagui-build --watch",
|
|
20
|
+
"lint": "eslint",
|
|
21
|
+
"lint:fix": "yarn lint --fix",
|
|
22
|
+
"clean": "tamagui-build clean",
|
|
23
|
+
"clean:build": "tamagui-build clean:build",
|
|
24
|
+
"test": "vitest --config ../vite-plugin-internal/src/vite.config.ts --run"
|
|
17
25
|
},
|
|
18
26
|
"dependencies": {
|
|
19
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
27
|
+
"@tamagui/core": "^1.0.1-beta.211",
|
|
28
|
+
"@tamagui/get-font-sized": "^1.0.1-beta.211",
|
|
29
|
+
"@tamagui/helpers-tamagui": "^1.0.1-beta.211"
|
|
20
30
|
},
|
|
21
31
|
"peerDependencies": {
|
|
22
32
|
"react": "*",
|
|
23
33
|
"react-dom": "*"
|
|
24
34
|
},
|
|
25
35
|
"devDependencies": {
|
|
26
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
36
|
+
"@tamagui/build": "^1.0.1-beta.211",
|
|
27
37
|
"react": "*",
|
|
28
|
-
"react-dom": "*"
|
|
38
|
+
"react-dom": "*",
|
|
39
|
+
"vitest": "^0.24.3"
|
|
29
40
|
},
|
|
30
41
|
"publishConfig": {
|
|
31
42
|
"access": "public"
|
package/src/Headings.tsx
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { styled } from '@tamagui/core'
|
|
2
|
+
|
|
3
|
+
import { Paragraph } from './Paragraph'
|
|
4
|
+
|
|
5
|
+
export const Heading = styled(Paragraph, {
|
|
6
|
+
tag: 'span',
|
|
7
|
+
name: 'Heading',
|
|
8
|
+
accessibilityRole: 'header',
|
|
9
|
+
fontFamily: '$heading',
|
|
10
|
+
size: '$8',
|
|
11
|
+
margin: 0,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export const H1 = styled(Heading, {
|
|
15
|
+
name: 'H1',
|
|
16
|
+
tag: 'h1',
|
|
17
|
+
size: '$10',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const H2 = styled(Heading, {
|
|
21
|
+
name: 'H2',
|
|
22
|
+
tag: 'h2',
|
|
23
|
+
size: '$9',
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export const H3 = styled(Heading, {
|
|
27
|
+
name: 'H3',
|
|
28
|
+
tag: 'h3',
|
|
29
|
+
size: '$8',
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export const H4 = styled(Heading, {
|
|
33
|
+
name: 'H4',
|
|
34
|
+
tag: 'h4',
|
|
35
|
+
size: '$7',
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export const H5 = styled(Heading, {
|
|
39
|
+
name: 'H5',
|
|
40
|
+
tag: 'h5',
|
|
41
|
+
size: '$6',
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
export const H6 = styled(Heading, {
|
|
45
|
+
name: 'H6',
|
|
46
|
+
tag: 'h6',
|
|
47
|
+
size: '$5',
|
|
48
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PropTypes, styled } from '@tamagui/core'
|
|
2
|
+
|
|
3
|
+
import { SizableText } from './SizableText'
|
|
4
|
+
|
|
5
|
+
export const Paragraph = styled(SizableText, {
|
|
6
|
+
name: 'Paragraph',
|
|
7
|
+
tag: 'p',
|
|
8
|
+
selectable: true,
|
|
9
|
+
cursor: 'text',
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export type ParagraphProps = PropTypes<typeof Paragraph>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GetProps, Text, styled } from '@tamagui/core'
|
|
2
|
+
import { getFontSized } from '@tamagui/get-font-sized'
|
|
3
|
+
|
|
4
|
+
export const SizableText = styled(Text, {
|
|
5
|
+
name: 'SizableText',
|
|
6
|
+
fontFamily: '$body',
|
|
7
|
+
|
|
8
|
+
variants: {
|
|
9
|
+
size: getFontSized,
|
|
10
|
+
} as const,
|
|
11
|
+
|
|
12
|
+
defaultVariants: {
|
|
13
|
+
size: '$4',
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export type SizableTextProps = GetProps<typeof SizableText>
|
package/src/index.tsx
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SizableTextProps } from './SizableText'
|
|
2
|
+
|
|
3
|
+
export type TextParentStyles = {
|
|
4
|
+
color?: SizableTextProps['color']
|
|
5
|
+
fontWeight?: SizableTextProps['fontWeight']
|
|
6
|
+
fontSize?: SizableTextProps['fontSize']
|
|
7
|
+
fontFamily?: SizableTextProps['fontFamily']
|
|
8
|
+
letterSpacing?: SizableTextProps['letterSpacing']
|
|
9
|
+
textAlign?: SizableTextProps['textAlign']
|
|
10
|
+
// all the other text controls
|
|
11
|
+
textProps?: Partial<SizableTextProps>
|
|
12
|
+
noTextWrap?: boolean
|
|
13
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { expect, test } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { wrapChildrenInText } from './wrapChildrenInText'
|
|
5
|
+
|
|
6
|
+
const Comp = () => {}
|
|
7
|
+
const re = <div data-id={Math.random()} />
|
|
8
|
+
const reID = re.props['data-id']
|
|
9
|
+
|
|
10
|
+
test('should wrap all string children, not wrap others', () => {
|
|
11
|
+
const out = wrapChildrenInText(Comp, {
|
|
12
|
+
children: [re, 'a', 'b', re, 'c', re, 'd'],
|
|
13
|
+
}) as any
|
|
14
|
+
|
|
15
|
+
expect(out[0].props['data-id']).toBe(reID)
|
|
16
|
+
|
|
17
|
+
expect(out[1].type).toBe(Comp)
|
|
18
|
+
expect(out[1].props.children).toStrictEqual(['a', 'b'])
|
|
19
|
+
|
|
20
|
+
expect(out[2].props['data-id']).toBe(reID)
|
|
21
|
+
|
|
22
|
+
expect(out[3].type).toBe(Comp)
|
|
23
|
+
expect(out[3].props.children).toStrictEqual(['c'])
|
|
24
|
+
|
|
25
|
+
expect(out[4].props['data-id']).toBe(reID)
|
|
26
|
+
|
|
27
|
+
expect(out[5].type).toBe(Comp)
|
|
28
|
+
expect(out[5].props.children).toStrictEqual(['d'])
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('should first child string', () => {
|
|
32
|
+
const out = wrapChildrenInText(Comp, {
|
|
33
|
+
children: ['a', re],
|
|
34
|
+
}) as any
|
|
35
|
+
|
|
36
|
+
expect(out[0].type).toBe(Comp)
|
|
37
|
+
expect(out[0].props.children).toStrictEqual(['a'])
|
|
38
|
+
|
|
39
|
+
expect(out[1].props['data-id']).toBe(reID)
|
|
40
|
+
})
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { SizeTokens } from '@tamagui/core'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { TextParentStyles } from './types'
|
|
5
|
+
|
|
6
|
+
type Props = TextParentStyles & {
|
|
7
|
+
children?: React.ReactNode
|
|
8
|
+
size?: SizeTokens
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function wrapChildrenInText(TextComponent: any, propsIn: Props) {
|
|
12
|
+
const {
|
|
13
|
+
children,
|
|
14
|
+
textProps,
|
|
15
|
+
size,
|
|
16
|
+
noTextWrap,
|
|
17
|
+
color,
|
|
18
|
+
fontFamily,
|
|
19
|
+
fontSize,
|
|
20
|
+
fontWeight,
|
|
21
|
+
letterSpacing,
|
|
22
|
+
textAlign,
|
|
23
|
+
} = propsIn
|
|
24
|
+
|
|
25
|
+
if (noTextWrap || !children) {
|
|
26
|
+
return children
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// in the case of using variables, like so:
|
|
30
|
+
// <ListItem>Hello, {name}</ListItem>
|
|
31
|
+
// it gives us props.children as ['Hello, ', 'name']
|
|
32
|
+
// but we don't want to wrap multiple SizableText around each part
|
|
33
|
+
// so we group them
|
|
34
|
+
const allChildren = React.Children.toArray(children)
|
|
35
|
+
const nextChildren: any[] = []
|
|
36
|
+
let lastIsString = false
|
|
37
|
+
const props: any = {}
|
|
38
|
+
// to avoid setting undefined
|
|
39
|
+
if (color) props.color = color
|
|
40
|
+
if (fontFamily) props.fontFamily = fontFamily
|
|
41
|
+
if (fontSize) props.fontSize = fontSize
|
|
42
|
+
if (fontWeight) props.fontWeight = fontWeight
|
|
43
|
+
if (letterSpacing) props.letterSpacing = letterSpacing
|
|
44
|
+
if (textAlign) props.textAlign = textAlign
|
|
45
|
+
if (size) props.size = size
|
|
46
|
+
|
|
47
|
+
function concatStringChildren() {
|
|
48
|
+
if (!lastIsString) return
|
|
49
|
+
const index = nextChildren.length - 1
|
|
50
|
+
const childrenStrings = nextChildren[index]
|
|
51
|
+
nextChildren[index] = (
|
|
52
|
+
<TextComponent key={index} {...props} {...textProps}>
|
|
53
|
+
{childrenStrings}
|
|
54
|
+
</TextComponent>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const child of allChildren) {
|
|
59
|
+
const last = nextChildren[nextChildren.length - 1]
|
|
60
|
+
const isString = typeof child === 'string'
|
|
61
|
+
if (isString) {
|
|
62
|
+
if (lastIsString) {
|
|
63
|
+
last.push(child)
|
|
64
|
+
} else {
|
|
65
|
+
nextChildren.push([child])
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
concatStringChildren()
|
|
69
|
+
nextChildren.push(child)
|
|
70
|
+
}
|
|
71
|
+
lastIsString = isString
|
|
72
|
+
}
|
|
73
|
+
concatStringChildren()
|
|
74
|
+
|
|
75
|
+
return nextChildren
|
|
76
|
+
}
|