@tamagui/text 1.0.1-beta.99 → 1.0.1-rc.0

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.
Files changed (67) hide show
  1. package/dist/cjs/Headings.js +1 -0
  2. package/dist/cjs/Headings.js.map +1 -1
  3. package/dist/cjs/Paragraph.js +1 -0
  4. package/dist/cjs/Paragraph.js.map +1 -1
  5. package/dist/cjs/SizableText.js +3 -3
  6. package/dist/cjs/SizableText.js.map +2 -2
  7. package/dist/cjs/index.js +2 -0
  8. package/dist/cjs/index.js.map +2 -2
  9. package/dist/cjs/types.js +17 -0
  10. package/dist/cjs/types.js.map +7 -0
  11. package/dist/cjs/wrapChildrenInText.js +35 -44
  12. package/dist/cjs/wrapChildrenInText.js.map +3 -3
  13. package/dist/cjs/wrapChildrenInText.test.js +3 -17
  14. package/dist/cjs/wrapChildrenInText.test.js.map +1 -1
  15. package/dist/esm/Headings.js +0 -0
  16. package/dist/esm/Headings.js.map +1 -1
  17. package/dist/esm/Paragraph.js +0 -0
  18. package/dist/esm/Paragraph.js.map +1 -1
  19. package/dist/esm/SizableText.js +3 -4
  20. package/dist/esm/SizableText.js.map +2 -2
  21. package/dist/esm/index.js +1 -0
  22. package/dist/esm/index.js.map +2 -2
  23. package/dist/esm/types.js +1 -0
  24. package/dist/{cjs/Texts.js.map → esm/types.js.map} +0 -0
  25. package/dist/esm/wrapChildrenInText.js +30 -45
  26. package/dist/esm/wrapChildrenInText.js.map +2 -2
  27. package/dist/esm/wrapChildrenInText.test.js +2 -2
  28. package/dist/esm/wrapChildrenInText.test.js.map +1 -1
  29. package/dist/jsx/Headings.js +0 -0
  30. package/dist/jsx/Headings.js.map +1 -1
  31. package/dist/jsx/Paragraph.js +0 -0
  32. package/dist/jsx/Paragraph.js.map +1 -1
  33. package/dist/jsx/SizableText.js +3 -4
  34. package/dist/jsx/SizableText.js.map +2 -2
  35. package/dist/jsx/index.js +1 -0
  36. package/dist/jsx/index.js.map +2 -2
  37. package/dist/jsx/types.js +1 -0
  38. package/dist/{esm/Texts.js.map → jsx/types.js.map} +0 -0
  39. package/dist/jsx/wrapChildrenInText.js +25 -22
  40. package/dist/jsx/wrapChildrenInText.js.map +2 -2
  41. package/dist/jsx/wrapChildrenInText.test.js +0 -0
  42. package/dist/jsx/wrapChildrenInText.test.js.map +1 -1
  43. package/package.json +13 -10
  44. package/src/SizableText.tsx +11 -16
  45. package/src/index.tsx +1 -0
  46. package/src/types.ts +13 -0
  47. package/src/wrapChildrenInText.tsx +16 -28
  48. package/types/Headings.d.ts +689 -447
  49. package/types/Paragraph.d.ts +17 -15
  50. package/types/SizableText.d.ts +8 -8
  51. package/types/index.d.ts +1 -0
  52. package/types/types.d.ts +12 -0
  53. package/types/wrapChildrenInText.d.ts +2 -12
  54. package/types/wrapChildrenInText.test.d.ts +0 -0
  55. package/dist/cjs/Texts.js +0 -1
  56. package/dist/esm/Texts.js +0 -1
  57. package/dist/jsx/Texts.js +0 -1
  58. package/dist/jsx/Texts.js.map +0 -7
  59. package/src/Texts.tsx +0 -0
  60. package/types/Headings.d.ts.map +0 -1
  61. package/types/Paragraph.d.ts.map +0 -1
  62. package/types/SizableText.d.ts.map +0 -1
  63. package/types/Texts.d.ts +0 -1
  64. package/types/Texts.d.ts.map +0 -1
  65. package/types/index.d.ts.map +0 -1
  66. package/types/wrapChildrenInText.d.ts.map +0 -1
  67. package/types/wrapChildrenInText.test.d.ts.map +0 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["export * from './SizableText'\nexport * from './Paragraph'\nexport * from './Headings'\nexport * from './wrapChildrenInText'\n"],
5
- "mappings": "AAAA;AACA;AACA;AACA;",
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
6
  "names": []
7
7
  }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
File without changes
@@ -1,41 +1,44 @@
1
1
  import React from "react";
2
- function wrapChildrenInText(TextComponent, {
3
- children,
4
- textProps,
5
- size,
6
- noTextWrap,
7
- color,
8
- fontFamily,
9
- fontSize,
10
- fontWeight,
11
- letterSpacing,
12
- textAlign
13
- }) {
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;
14
15
  if (noTextWrap || !children) {
15
16
  return children;
16
17
  }
17
- let allChildren = React.Children.toArray(children);
18
- let nextChildren = [];
18
+ const allChildren = React.Children.toArray(children);
19
+ const nextChildren = [];
19
20
  let lastIsString = false;
20
- const directTextProps = {};
21
+ const props = {};
21
22
  if (color)
22
- directTextProps.color = color;
23
+ props.color = color;
23
24
  if (fontFamily)
24
- directTextProps.fontFamily = fontFamily;
25
+ props.fontFamily = fontFamily;
25
26
  if (fontSize)
26
- directTextProps.fontSize = fontSize;
27
+ props.fontSize = fontSize;
27
28
  if (fontWeight)
28
- directTextProps.fontWeight = fontWeight;
29
+ props.fontWeight = fontWeight;
29
30
  if (letterSpacing)
30
- directTextProps.letterSpacing = letterSpacing;
31
+ props.letterSpacing = letterSpacing;
31
32
  if (textAlign)
32
- directTextProps.textAlign = textAlign;
33
+ props.textAlign = textAlign;
34
+ if (size)
35
+ props.size = size;
33
36
  function concatStringChildren() {
34
37
  if (!lastIsString)
35
38
  return;
36
39
  const index = nextChildren.length - 1;
37
40
  const childrenStrings = nextChildren[index];
38
- nextChildren[index] = <TextComponent key={index} {...directTextProps} size={size} {...textProps}>{childrenStrings}</TextComponent>;
41
+ nextChildren[index] = <TextComponent key={index} {...props} {...textProps}>{childrenStrings}</TextComponent>;
39
42
  }
40
43
  for (const child of allChildren) {
41
44
  const last = nextChildren[nextChildren.length - 1];
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapChildrenInText.tsx"],
4
- "sourcesContent": ["import type { SizeTokens } from '@tamagui/core'\nimport React from 'react'\n\nimport { SizableTextProps } from './SizableText'\n\nexport type TextParentStyles = {\n color?: SizableTextProps['color']\n fontWeight?: SizableTextProps['fontWeight']\n fontSize?: SizableTextProps['fontSize']\n fontFamily?: SizableTextProps['fontFamily']\n letterSpacing?: SizableTextProps['letterSpacing']\n textAlign?: SizableTextProps['textAlign']\n // all the other text controls\n textProps?: Partial<SizableTextProps>\n noTextWrap?: boolean\n}\n\ntype Props = TextParentStyles & {\n children?: React.ReactNode\n size?: SizeTokens\n}\n\nexport function wrapChildrenInText(\n TextComponent: any,\n {\n children,\n textProps,\n size,\n noTextWrap,\n color,\n fontFamily,\n fontSize,\n fontWeight,\n letterSpacing,\n textAlign,\n }: Props\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 let allChildren = React.Children.toArray(children)\n let nextChildren: any[] = []\n let lastIsString = false\n const directTextProps: any = {}\n // to avoid setting undefined\n if (color) directTextProps.color = color\n if (fontFamily) directTextProps.fontFamily = fontFamily\n if (fontSize) directTextProps.fontSize = fontSize\n if (fontWeight) directTextProps.fontWeight = fontWeight\n if (letterSpacing) directTextProps.letterSpacing = letterSpacing\n if (textAlign) directTextProps.textAlign = textAlign\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} {...directTextProps} size={size} {...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;AAqBO,4BACL,eACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAEF;AACA,MAAI,cAAc,CAAC,UAAU;AAC3B,WAAO;AAAA,EACT;AAOA,MAAI,cAAc,MAAM,SAAS,QAAQ,QAAQ;AACjD,MAAI,eAAsB,CAAC;AAC3B,MAAI,eAAe;AACnB,QAAM,kBAAuB,CAAC;AAE9B,MAAI;AAAO,oBAAgB,QAAQ;AACnC,MAAI;AAAY,oBAAgB,aAAa;AAC7C,MAAI;AAAU,oBAAgB,WAAW;AACzC,MAAI;AAAY,oBAAgB,aAAa;AAC7C,MAAI;AAAe,oBAAgB,gBAAgB;AACnD,MAAI;AAAW,oBAAgB,YAAY;AAE3C,kCAAgC;AAC9B,QAAI,CAAC;AAAc;AACnB,UAAM,QAAQ,aAAa,SAAS;AACpC,UAAM,kBAAkB,aAAa;AACrC,iBAAa,SACX,CAAC,cAAc,KAAK,WAAW,iBAAiB,MAAM,UAAU,YAC7D,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;",
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
6
  "names": []
7
7
  }
File without changes
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapChildrenInText.test.tsx"],
4
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;AAEA;AAEA,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;",
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
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/text",
3
- "version": "1.0.1-beta.99",
3
+ "version": "1.0.1-rc.0",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -17,23 +17,26 @@
17
17
  "scripts": {
18
18
  "build": "tamagui-build",
19
19
  "watch": "tamagui-build --watch",
20
+ "lint": "eslint src",
21
+ "lint:fix": "yarn lint --fix",
20
22
  "clean": "tamagui-build clean",
21
23
  "clean:build": "tamagui-build clean:build",
22
- "test": "vitest --config ../vite-plugin-internal/vite.config.ts"
24
+ "test": "vitest --config ../vite-plugin-internal/src/vite.config.ts --run"
23
25
  },
24
26
  "dependencies": {
25
- "@tamagui/core": "^1.0.1-beta.99"
27
+ "@tamagui/core": "^1.0.1-rc.0",
28
+ "@tamagui/get-font-sized": "^1.0.1-rc.0",
29
+ "@tamagui/helpers-tamagui": "^1.0.1-rc.0"
26
30
  },
27
31
  "peerDependencies": {
28
- "react": "*",
29
- "react-dom": "*"
32
+ "react": ">=18",
33
+ "react-dom": ">=18"
30
34
  },
31
35
  "devDependencies": {
32
- "@tamagui/build": "^1.0.1-beta.99",
33
- "@tamagui/vite-plugin-internal": "^1.0.1-beta.99",
34
- "react": "*",
35
- "react-dom": "*",
36
- "vitest": "^0.17.1"
36
+ "@tamagui/build": "^1.0.1-rc.0",
37
+ "react": ">=18",
38
+ "react-dom": ">=18",
39
+ "vitest": "^0.25.3"
37
40
  },
38
41
  "publishConfig": {
39
42
  "access": "public"
@@ -1,22 +1,17 @@
1
- import { GetProps, Text, getFont, styled } from '@tamagui/core'
1
+ import { GetProps, Text, styled } from '@tamagui/core'
2
+ import { getFontSized } from '@tamagui/get-font-sized'
2
3
 
3
- export const SizableText = styled(
4
- Text,
5
- {
6
- name: 'SizableText',
7
- fontFamily: '$body',
4
+ export const SizableText = styled(Text, {
5
+ name: 'SizableText',
6
+ fontFamily: '$body',
8
7
 
9
- variants: {
10
- size: getFont,
11
- },
8
+ variants: {
9
+ size: getFontSized,
10
+ } as const,
12
11
 
13
- defaultVariants: {
14
- size: '$4',
15
- },
12
+ defaultVariants: {
13
+ size: '$4',
16
14
  },
17
- {
18
- inlineWhenUnflattened: new Set(['fontFamily']),
19
- }
20
- )
15
+ })
21
16
 
22
17
  export type SizableTextProps = GetProps<typeof SizableText>
package/src/index.tsx CHANGED
@@ -2,3 +2,4 @@ export * from './SizableText'
2
2
  export * from './Paragraph'
3
3
  export * from './Headings'
4
4
  export * from './wrapChildrenInText'
5
+ export * from './types'
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
+ }
@@ -1,28 +1,15 @@
1
1
  import type { SizeTokens } from '@tamagui/core'
2
2
  import React from 'react'
3
3
 
4
- import { SizableTextProps } from './SizableText'
5
-
6
- export type TextParentStyles = {
7
- color?: SizableTextProps['color']
8
- fontWeight?: SizableTextProps['fontWeight']
9
- fontSize?: SizableTextProps['fontSize']
10
- fontFamily?: SizableTextProps['fontFamily']
11
- letterSpacing?: SizableTextProps['letterSpacing']
12
- textAlign?: SizableTextProps['textAlign']
13
- // all the other text controls
14
- textProps?: Partial<SizableTextProps>
15
- noTextWrap?: boolean
16
- }
4
+ import { TextParentStyles } from './types'
17
5
 
18
6
  type Props = TextParentStyles & {
19
7
  children?: React.ReactNode
20
8
  size?: SizeTokens
21
9
  }
22
10
 
23
- export function wrapChildrenInText(
24
- TextComponent: any,
25
- {
11
+ export function wrapChildrenInText(TextComponent: any, propsIn: Props) {
12
+ const {
26
13
  children,
27
14
  textProps,
28
15
  size,
@@ -33,8 +20,8 @@ export function wrapChildrenInText(
33
20
  fontWeight,
34
21
  letterSpacing,
35
22
  textAlign,
36
- }: Props
37
- ) {
23
+ } = propsIn
24
+
38
25
  if (noTextWrap || !children) {
39
26
  return children
40
27
  }
@@ -44,24 +31,25 @@ export function wrapChildrenInText(
44
31
  // it gives us props.children as ['Hello, ', 'name']
45
32
  // but we don't want to wrap multiple SizableText around each part
46
33
  // so we group them
47
- let allChildren = React.Children.toArray(children)
48
- let nextChildren: any[] = []
34
+ const allChildren = React.Children.toArray(children)
35
+ const nextChildren: any[] = []
49
36
  let lastIsString = false
50
- const directTextProps: any = {}
37
+ const props: any = {}
51
38
  // to avoid setting undefined
52
- if (color) directTextProps.color = color
53
- if (fontFamily) directTextProps.fontFamily = fontFamily
54
- if (fontSize) directTextProps.fontSize = fontSize
55
- if (fontWeight) directTextProps.fontWeight = fontWeight
56
- if (letterSpacing) directTextProps.letterSpacing = letterSpacing
57
- if (textAlign) directTextProps.textAlign = textAlign
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
58
46
 
59
47
  function concatStringChildren() {
60
48
  if (!lastIsString) return
61
49
  const index = nextChildren.length - 1
62
50
  const childrenStrings = nextChildren[index]
63
51
  nextChildren[index] = (
64
- <TextComponent key={index} {...directTextProps} size={size} {...textProps}>
52
+ <TextComponent key={index} {...props} {...textProps}>
65
53
  {childrenStrings}
66
54
  </TextComponent>
67
55
  )