@tamagui/helpers-tamagui 1.0.1-beta.92 → 1.0.1-beta.95

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 (51) hide show
  1. package/dist/cjs/index.js +0 -1
  2. package/dist/cjs/index.js.map +2 -2
  3. package/dist/cjs/types.js +0 -0
  4. package/dist/cjs/types.js.map +0 -0
  5. package/dist/cjs/useCurrentColor.js +0 -0
  6. package/dist/cjs/useCurrentColor.js.map +1 -1
  7. package/dist/cjs/useGetThemedIcon.js +5 -3
  8. package/dist/cjs/useGetThemedIcon.js.map +2 -2
  9. package/dist/cjs/wrapStringChildrenInText.js +0 -0
  10. package/dist/cjs/wrapStringChildrenInText.js.map +1 -1
  11. package/dist/cjs/wrapStringChildrenInText.test.js +31 -0
  12. package/dist/cjs/wrapStringChildrenInText.test.js.map +7 -0
  13. package/dist/esm/index.js +0 -1
  14. package/dist/esm/index.js.map +2 -2
  15. package/dist/esm/types.js +0 -0
  16. package/dist/esm/types.js.map +0 -0
  17. package/dist/esm/useCurrentColor.js +0 -0
  18. package/dist/esm/useCurrentColor.js.map +1 -1
  19. package/dist/esm/useGetThemedIcon.js +5 -3
  20. package/dist/esm/useGetThemedIcon.js.map +2 -2
  21. package/dist/esm/wrapStringChildrenInText.js +0 -0
  22. package/dist/esm/wrapStringChildrenInText.js.map +1 -1
  23. package/dist/esm/wrapStringChildrenInText.test.js +31 -0
  24. package/dist/esm/wrapStringChildrenInText.test.js.map +7 -0
  25. package/dist/jsx/index.js +0 -1
  26. package/dist/jsx/index.js.map +2 -2
  27. package/dist/jsx/types.js +0 -0
  28. package/dist/jsx/types.js.map +0 -0
  29. package/dist/jsx/useCurrentColor.js +0 -0
  30. package/dist/jsx/useCurrentColor.js.map +1 -1
  31. package/dist/jsx/useGetThemedIcon.js +7 -3
  32. package/dist/jsx/useGetThemedIcon.js.map +2 -2
  33. package/dist/jsx/wrapStringChildrenInText.js +0 -0
  34. package/dist/jsx/wrapStringChildrenInText.js.map +1 -1
  35. package/dist/jsx/wrapStringChildrenInText.test.js +29 -0
  36. package/dist/jsx/wrapStringChildrenInText.test.js.map +7 -0
  37. package/package.json +8 -5
  38. package/src/index.ts +0 -1
  39. package/src/useCurrentColor.tsx +1 -1
  40. package/src/useGetThemedIcon.tsx +8 -3
  41. package/types/index.d.ts +0 -1
  42. package/types/index.d.ts.map +1 -1
  43. package/types/types.d.ts.map +0 -0
  44. package/types/useCurrentColor.d.ts +1 -1
  45. package/types/useCurrentColor.d.ts.map +1 -1
  46. package/types/useGetThemedIcon.d.ts.map +1 -1
  47. package/types/wrapStringChildrenInText.d.ts +2 -2
  48. package/types/wrapStringChildrenInText.d.ts.map +1 -1
  49. package/types/wrapStringChildrenInText.test.d.ts +2 -0
  50. package/types/wrapStringChildrenInText.test.d.ts.map +1 -0
  51. package/src/wrapStringChildrenInText.tsx +0 -76
package/dist/cjs/index.js CHANGED
@@ -16,6 +16,5 @@ var src_exports = {};
16
16
  module.exports = __toCommonJS(src_exports);
17
17
  __reExport(src_exports, require("./useCurrentColor"), module.exports);
18
18
  __reExport(src_exports, require("./useGetThemedIcon"), module.exports);
19
- __reExport(src_exports, require("./wrapStringChildrenInText"), module.exports);
20
19
  __reExport(src_exports, require("./types"), module.exports);
21
20
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './useCurrentColor'\nexport * from './useGetThemedIcon'\nexport * from './wrapStringChildrenInText'\nexport * from './types'\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,+BADd;AAEA,wBAAc,uCAFd;AAGA,wBAAc,oBAHd;",
4
+ "sourcesContent": ["export * from './useCurrentColor'\nexport * from './useGetThemedIcon'\nexport * from './types'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,+BADd;AAEA,wBAAc,oBAFd;",
6
6
  "names": []
7
7
  }
package/dist/cjs/types.js CHANGED
File without changes
File without changes
File without changes
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/useCurrentColor.tsx"],
4
- "sourcesContent": ["import { ColorTokens, ThemeValueFallback, useTheme } from '@tamagui/core'\nimport { TextStyle } from 'react-native'\n\nexport const useCurrentColor = (colorProp: ColorProp) => {\n const theme = useTheme()\n // get color from prop or theme\n let color: any\n // @ts-expect-error\n if (theme && colorProp && colorProp in theme) {\n // @ts-expect-error\n color = theme[colorProp]\n } else if (colorProp) {\n color = colorProp\n } else {\n color = theme?.color\n }\n return color?.toString() || ('' as string)\n}\n\nexport type ColorProp = ThemeValueFallback | ColorTokens | TextStyle['color'] | undefined\n"],
4
+ "sourcesContent": ["import { ColorTokens, ThemeValueFallback, useTheme } from '@tamagui/core'\nimport type { TextStyle } from 'react-native'\n\nexport const useCurrentColor = (colorProp: ColorProp) => {\n const theme = useTheme()\n // get color from prop or theme\n let color: any\n // @ts-expect-error\n if (theme && colorProp && colorProp in theme) {\n // @ts-expect-error\n color = theme[colorProp]\n } else if (colorProp) {\n color = colorProp\n } else {\n color = theme?.color\n }\n return color?.toString() || ('' as string)\n}\n\nexport type ColorProp = ThemeValueFallback | ColorTokens | TextStyle['color'] | undefined\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0D;AAGnD,MAAM,kBAAkB,CAAC,cAAyB;AACvD,QAAM,QAAQ,0BAAS;AAEvB,MAAI;AAEJ,MAAI,SAAS,aAAa,aAAa,OAAO;AAE5C,YAAQ,MAAM;AAAA,EAChB,WAAW,WAAW;AACpB,YAAQ;AAAA,EACV,OAAO;AACL,YAAQ,+BAAO;AAAA,EACjB;AACA,SAAO,gCAAO,eAAe;AAC/B;",
6
6
  "names": []
7
7
  }
@@ -45,10 +45,12 @@ var import_useCurrentColor = require("./useCurrentColor");
45
45
  const useGetThemedIcon = (props) => {
46
46
  const color = (0, import_useCurrentColor.useCurrentColor)(props.color);
47
47
  return (el) => {
48
- if ((0, import_react.isValidElement)(el)) {
49
- return el;
50
- }
51
48
  if (el) {
49
+ if ((0, import_react.isValidElement)(el)) {
50
+ return import_react.default.cloneElement(el, __spreadValues(__spreadProps(__spreadValues({}, props), {
51
+ color
52
+ }), el.props));
53
+ }
52
54
  return import_react.default.createElement(el, __spreadProps(__spreadValues({}, props), {
53
55
  color
54
56
  }));
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/useGetThemedIcon.tsx"],
4
- "sourcesContent": ["import React, { isValidElement } from 'react'\n\nimport { ColorProp, useCurrentColor } from './useCurrentColor'\n\nexport const useGetThemedIcon = (props: { color: ColorProp; size: number }) => {\n const color = useCurrentColor(props.color)\n return (el: any) => {\n if (isValidElement(el)) {\n return el\n }\n if (el) {\n return React.createElement(el, {\n ...props,\n color,\n })\n }\n return el\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsC;AAEtC,6BAA2C;AAEpC,MAAM,mBAAmB,CAAC,UAA8C;AAC7E,QAAM,QAAQ,4CAAgB,MAAM,KAAK;AACzC,SAAO,CAAC,OAAY;AAClB,QAAI,iCAAe,EAAE,GAAG;AACtB,aAAO;AAAA,IACT;AACA,QAAI,IAAI;AACN,aAAO,qBAAM,cAAc,IAAI,iCAC1B,QAD0B;AAAA,QAE7B;AAAA,MACF,EAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import React, { isValidElement } from 'react'\n\nimport { ColorProp, useCurrentColor } from './useCurrentColor'\n\nexport const useGetThemedIcon = (props: { color: ColorProp; size: number }) => {\n const color = useCurrentColor(props.color)\n return (el: any) => {\n if (el) {\n if (isValidElement(el)) {\n return React.cloneElement(el as any, {\n ...props,\n color,\n // @ts-ignore\n ...el.props,\n })\n }\n return React.createElement(el, {\n ...props,\n color,\n })\n }\n return el\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsC;AAEtC,6BAA2C;AAEpC,MAAM,mBAAmB,CAAC,UAA8C;AAC7E,QAAM,QAAQ,4CAAgB,MAAM,KAAK;AACzC,SAAO,CAAC,OAAY;AAClB,QAAI,IAAI;AACN,UAAI,iCAAe,EAAE,GAAG;AACtB,eAAO,qBAAM,aAAa,IAAW,gDAChC,QADgC;AAAA,UAEnC;AAAA,YAEG,GAAG,MACP;AAAA,MACH;AACA,aAAO,qBAAM,cAAc,IAAI,iCAC1B,QAD0B;AAAA,QAE7B;AAAA,MACF,EAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
File without changes
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapStringChildrenInText.tsx"],
4
- "sourcesContent": ["import { 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 wrapStringChildrenInText(\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"],
4
+ "sourcesContent": ["import type { SizeTokens } from '@tamagui/core'\nimport React from 'react'\n\nimport type { TextParentStyles } from './types'\n\ntype Props = TextParentStyles & {\n children?: React.ReactNode\n size?: SizeTokens\n}\n\nexport function wrapStringChildrenInText(\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
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AASX,kCACL,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,qBAAM,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,mDAAC;AAAA,MAAc,KAAK;AAAA,OAAW,kBAA9B;AAAA,MAA+C;AAAA,QAAgB,YAC7D,eACH;AAAA,EAEJ;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
  }
@@ -0,0 +1,31 @@
1
+ var import_vitest = require("vitest");
2
+ var import_wrapStringChildrenInText = require("./wrapStringChildrenInText");
3
+ const Comp = () => {
4
+ };
5
+ const re = /* @__PURE__ */ React.createElement("div", {
6
+ "data-id": Math.random()
7
+ });
8
+ const reID = re.props["data-id"];
9
+ (0, import_vitest.test)("should wrap all string children, not wrap others", () => {
10
+ const out = (0, import_wrapStringChildrenInText.wrapStringChildrenInText)(Comp, {
11
+ children: [re, "a", "b", re, "c", re, "d"]
12
+ });
13
+ (0, import_vitest.expect)(out[0].props["data-id"]).toBe(reID);
14
+ (0, import_vitest.expect)(out[1].type).toBe(Comp);
15
+ (0, import_vitest.expect)(out[1].props.children).toStrictEqual(["a", "b"]);
16
+ (0, import_vitest.expect)(out[2].props["data-id"]).toBe(reID);
17
+ (0, import_vitest.expect)(out[3].type).toBe(Comp);
18
+ (0, import_vitest.expect)(out[3].props.children).toStrictEqual(["c"]);
19
+ (0, import_vitest.expect)(out[4].props["data-id"]).toBe(reID);
20
+ (0, import_vitest.expect)(out[5].type).toBe(Comp);
21
+ (0, import_vitest.expect)(out[5].props.children).toStrictEqual(["d"]);
22
+ });
23
+ (0, import_vitest.test)("should first child string", () => {
24
+ const out = (0, import_wrapStringChildrenInText.wrapStringChildrenInText)(Comp, {
25
+ children: ["a", re]
26
+ });
27
+ (0, import_vitest.expect)(out[0].type).toBe(Comp);
28
+ (0, import_vitest.expect)(out[0].props.children).toStrictEqual(["a"]);
29
+ (0, import_vitest.expect)(out[1].props["data-id"]).toBe(reID);
30
+ });
31
+ //# sourceMappingURL=wrapStringChildrenInText.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapStringChildrenInText.test.tsx"],
4
+ "sourcesContent": ["import { expect, test } from 'vitest'\n\nimport { wrapStringChildrenInText } from './wrapStringChildrenInText'\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 = wrapStringChildrenInText(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 = wrapStringChildrenInText(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": "AAAA,oBAA6B;AAE7B,sCAAyC;AAEzC,MAAM,OAAO,MAAM;AAAC;AACpB,MAAM,KAAK,oCAAC;AAAA,EAAI,WAAS,KAAK,OAAO;AAAA,CAAG;AACxC,MAAM,OAAO,GAAG,MAAM;AAEtB,wBAAK,oDAAoD,MAAM;AAC7D,QAAM,MAAM,8DAAyB,MAAM;AAAA,IACzC,UAAU,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,GAAG;AAAA,EAC3C,CAAC;AAED,4BAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,4BAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,4BAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,KAAK,GAAG,CAAC;AAEtD,4BAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,4BAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,4BAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,4BAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,4BAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,4BAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AACnD,CAAC;AAED,wBAAK,6BAA6B,MAAM;AACtC,QAAM,MAAM,8DAAyB,MAAM;AAAA,IACzC,UAAU,CAAC,KAAK,EAAE;AAAA,EACpB,CAAC;AAED,4BAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,4BAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,4BAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAC3C,CAAC;",
6
+ "names": []
7
+ }
package/dist/esm/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./useCurrentColor";
2
2
  export * from "./useGetThemedIcon";
3
- export * from "./wrapStringChildrenInText";
4
3
  export * from "./types";
5
4
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './useCurrentColor'\nexport * from './useGetThemedIcon'\nexport * from './wrapStringChildrenInText'\nexport * from './types'\n"],
5
- "mappings": "AAAA;AACA;AACA;AACA;",
4
+ "sourcesContent": ["export * from './useCurrentColor'\nexport * from './useGetThemedIcon'\nexport * from './types'\n"],
5
+ "mappings": "AAAA;AACA;AACA;",
6
6
  "names": []
7
7
  }
package/dist/esm/types.js CHANGED
File without changes
File without changes
File without changes
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/useCurrentColor.tsx"],
4
- "sourcesContent": ["import { ColorTokens, ThemeValueFallback, useTheme } from '@tamagui/core'\nimport { TextStyle } from 'react-native'\n\nexport const useCurrentColor = (colorProp: ColorProp) => {\n const theme = useTheme()\n // get color from prop or theme\n let color: any\n // @ts-expect-error\n if (theme && colorProp && colorProp in theme) {\n // @ts-expect-error\n color = theme[colorProp]\n } else if (colorProp) {\n color = colorProp\n } else {\n color = theme?.color\n }\n return color?.toString() || ('' as string)\n}\n\nexport type ColorProp = ThemeValueFallback | ColorTokens | TextStyle['color'] | undefined\n"],
4
+ "sourcesContent": ["import { ColorTokens, ThemeValueFallback, useTheme } from '@tamagui/core'\nimport type { TextStyle } from 'react-native'\n\nexport const useCurrentColor = (colorProp: ColorProp) => {\n const theme = useTheme()\n // get color from prop or theme\n let color: any\n // @ts-expect-error\n if (theme && colorProp && colorProp in theme) {\n // @ts-expect-error\n color = theme[colorProp]\n } else if (colorProp) {\n color = colorProp\n } else {\n color = theme?.color\n }\n return color?.toString() || ('' as string)\n}\n\nexport type ColorProp = ThemeValueFallback | ColorTokens | TextStyle['color'] | undefined\n"],
5
5
  "mappings": "AAAA;AAGO,MAAM,kBAAkB,CAAC,cAAyB;AACvD,QAAM,QAAQ,SAAS;AAEvB,MAAI;AAEJ,MAAI,SAAS,aAAa,aAAa,OAAO;AAE5C,YAAQ,MAAM;AAAA,EAChB,WAAW,WAAW;AACpB,YAAQ;AAAA,EACV,OAAO;AACL,YAAQ,+BAAO;AAAA,EACjB;AACA,SAAO,gCAAO,eAAe;AAC/B;",
6
6
  "names": []
7
7
  }
@@ -22,10 +22,12 @@ import { useCurrentColor } from "./useCurrentColor";
22
22
  const useGetThemedIcon = (props) => {
23
23
  const color = useCurrentColor(props.color);
24
24
  return (el) => {
25
- if (isValidElement(el)) {
26
- return el;
27
- }
28
25
  if (el) {
26
+ if (isValidElement(el)) {
27
+ return React.cloneElement(el, __spreadValues(__spreadProps(__spreadValues({}, props), {
28
+ color
29
+ }), el.props));
30
+ }
29
31
  return React.createElement(el, __spreadProps(__spreadValues({}, props), {
30
32
  color
31
33
  }));
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/useGetThemedIcon.tsx"],
4
- "sourcesContent": ["import React, { isValidElement } from 'react'\n\nimport { ColorProp, useCurrentColor } from './useCurrentColor'\n\nexport const useGetThemedIcon = (props: { color: ColorProp; size: number }) => {\n const color = useCurrentColor(props.color)\n return (el: any) => {\n if (isValidElement(el)) {\n return el\n }\n if (el) {\n return React.createElement(el, {\n ...props,\n color,\n })\n }\n return el\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAEA;AAEO,MAAM,mBAAmB,CAAC,UAA8C;AAC7E,QAAM,QAAQ,gBAAgB,MAAM,KAAK;AACzC,SAAO,CAAC,OAAY;AAClB,QAAI,eAAe,EAAE,GAAG;AACtB,aAAO;AAAA,IACT;AACA,QAAI,IAAI;AACN,aAAO,MAAM,cAAc,IAAI,iCAC1B,QAD0B;AAAA,QAE7B;AAAA,MACF,EAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import React, { isValidElement } from 'react'\n\nimport { ColorProp, useCurrentColor } from './useCurrentColor'\n\nexport const useGetThemedIcon = (props: { color: ColorProp; size: number }) => {\n const color = useCurrentColor(props.color)\n return (el: any) => {\n if (el) {\n if (isValidElement(el)) {\n return React.cloneElement(el as any, {\n ...props,\n color,\n // @ts-ignore\n ...el.props,\n })\n }\n return React.createElement(el, {\n ...props,\n color,\n })\n }\n return el\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAEA;AAEO,MAAM,mBAAmB,CAAC,UAA8C;AAC7E,QAAM,QAAQ,gBAAgB,MAAM,KAAK;AACzC,SAAO,CAAC,OAAY;AAClB,QAAI,IAAI;AACN,UAAI,eAAe,EAAE,GAAG;AACtB,eAAO,MAAM,aAAa,IAAW,gDAChC,QADgC;AAAA,UAEnC;AAAA,YAEG,GAAG,MACP;AAAA,MACH;AACA,aAAO,MAAM,cAAc,IAAI,iCAC1B,QAD0B;AAAA,QAE7B;AAAA,MACF,EAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
File without changes
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapStringChildrenInText.tsx"],
4
- "sourcesContent": ["import { 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 wrapStringChildrenInText(\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"],
4
+ "sourcesContent": ["import type { SizeTokens } from '@tamagui/core'\nimport React from 'react'\n\nimport type { TextParentStyles } from './types'\n\ntype Props = TextParentStyles & {\n children?: React.ReactNode\n size?: SizeTokens\n}\n\nexport function wrapStringChildrenInText(\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
5
  "mappings": ";;;;;;;;;;;;;;;;;;;AACA;AASO,kCACL,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,oCAAC;AAAA,MAAc,KAAK;AAAA,OAAW,kBAA9B;AAAA,MAA+C;AAAA,QAAgB,YAC7D,eACH;AAAA,EAEJ;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
  }
@@ -0,0 +1,31 @@
1
+ import { expect, test } from "vitest";
2
+ import { wrapStringChildrenInText } from "./wrapStringChildrenInText";
3
+ const Comp = () => {
4
+ };
5
+ const re = /* @__PURE__ */ React.createElement("div", {
6
+ "data-id": Math.random()
7
+ });
8
+ const reID = re.props["data-id"];
9
+ test("should wrap all string children, not wrap others", () => {
10
+ const out = wrapStringChildrenInText(Comp, {
11
+ children: [re, "a", "b", re, "c", re, "d"]
12
+ });
13
+ expect(out[0].props["data-id"]).toBe(reID);
14
+ expect(out[1].type).toBe(Comp);
15
+ expect(out[1].props.children).toStrictEqual(["a", "b"]);
16
+ expect(out[2].props["data-id"]).toBe(reID);
17
+ expect(out[3].type).toBe(Comp);
18
+ expect(out[3].props.children).toStrictEqual(["c"]);
19
+ expect(out[4].props["data-id"]).toBe(reID);
20
+ expect(out[5].type).toBe(Comp);
21
+ expect(out[5].props.children).toStrictEqual(["d"]);
22
+ });
23
+ test("should first child string", () => {
24
+ const out = wrapStringChildrenInText(Comp, {
25
+ children: ["a", re]
26
+ });
27
+ expect(out[0].type).toBe(Comp);
28
+ expect(out[0].props.children).toStrictEqual(["a"]);
29
+ expect(out[1].props["data-id"]).toBe(reID);
30
+ });
31
+ //# sourceMappingURL=wrapStringChildrenInText.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapStringChildrenInText.test.tsx"],
4
+ "sourcesContent": ["import { expect, test } from 'vitest'\n\nimport { wrapStringChildrenInText } from './wrapStringChildrenInText'\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 = wrapStringChildrenInText(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 = wrapStringChildrenInText(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": "AAAA;AAEA;AAEA,MAAM,OAAO,MAAM;AAAC;AACpB,MAAM,KAAK,oCAAC;AAAA,EAAI,WAAS,KAAK,OAAO;AAAA,CAAG;AACxC,MAAM,OAAO,GAAG,MAAM;AAEtB,KAAK,oDAAoD,MAAM;AAC7D,QAAM,MAAM,yBAAyB,MAAM;AAAA,IACzC,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,yBAAyB,MAAM;AAAA,IACzC,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/dist/jsx/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./useCurrentColor";
2
2
  export * from "./useGetThemedIcon";
3
- export * from "./wrapStringChildrenInText";
4
3
  export * from "./types";
5
4
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './useCurrentColor'\nexport * from './useGetThemedIcon'\nexport * from './wrapStringChildrenInText'\nexport * from './types'\n"],
5
- "mappings": "AAAA;AACA;AACA;AACA;",
4
+ "sourcesContent": ["export * from './useCurrentColor'\nexport * from './useGetThemedIcon'\nexport * from './types'\n"],
5
+ "mappings": "AAAA;AACA;AACA;",
6
6
  "names": []
7
7
  }
package/dist/jsx/types.js CHANGED
File without changes
File without changes
File without changes
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/useCurrentColor.tsx"],
4
- "sourcesContent": ["import { ColorTokens, ThemeValueFallback, useTheme } from '@tamagui/core'\nimport { TextStyle } from 'react-native'\n\nexport const useCurrentColor = (colorProp: ColorProp) => {\n const theme = useTheme()\n // get color from prop or theme\n let color: any\n // @ts-expect-error\n if (theme && colorProp && colorProp in theme) {\n // @ts-expect-error\n color = theme[colorProp]\n } else if (colorProp) {\n color = colorProp\n } else {\n color = theme?.color\n }\n return color?.toString() || ('' as string)\n}\n\nexport type ColorProp = ThemeValueFallback | ColorTokens | TextStyle['color'] | undefined\n"],
4
+ "sourcesContent": ["import { ColorTokens, ThemeValueFallback, useTheme } from '@tamagui/core'\nimport type { TextStyle } from 'react-native'\n\nexport const useCurrentColor = (colorProp: ColorProp) => {\n const theme = useTheme()\n // get color from prop or theme\n let color: any\n // @ts-expect-error\n if (theme && colorProp && colorProp in theme) {\n // @ts-expect-error\n color = theme[colorProp]\n } else if (colorProp) {\n color = colorProp\n } else {\n color = theme?.color\n }\n return color?.toString() || ('' as string)\n}\n\nexport type ColorProp = ThemeValueFallback | ColorTokens | TextStyle['color'] | undefined\n"],
5
5
  "mappings": "AAAA;AAGO,MAAM,kBAAkB,CAAC,cAAyB;AACvD,QAAM,QAAQ,SAAS;AAEvB,MAAI;AAEJ,MAAI,SAAS,aAAa,aAAa,OAAO;AAE5C,YAAQ,MAAM;AAAA,EAChB,WAAW,WAAW;AACpB,YAAQ;AAAA,EACV,OAAO;AACL,YAAQ,+BAAO;AAAA,EACjB;AACA,SAAO,gCAAO,eAAe;AAC/B;",
6
6
  "names": []
7
7
  }
@@ -3,10 +3,14 @@ import { useCurrentColor } from "./useCurrentColor";
3
3
  const useGetThemedIcon = (props) => {
4
4
  const color = useCurrentColor(props.color);
5
5
  return (el) => {
6
- if (isValidElement(el)) {
7
- return el;
8
- }
9
6
  if (el) {
7
+ if (isValidElement(el)) {
8
+ return React.cloneElement(el, {
9
+ ...props,
10
+ color,
11
+ ...el.props
12
+ });
13
+ }
10
14
  return React.createElement(el, {
11
15
  ...props,
12
16
  color
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/useGetThemedIcon.tsx"],
4
- "sourcesContent": ["import React, { isValidElement } from 'react'\n\nimport { ColorProp, useCurrentColor } from './useCurrentColor'\n\nexport const useGetThemedIcon = (props: { color: ColorProp; size: number }) => {\n const color = useCurrentColor(props.color)\n return (el: any) => {\n if (isValidElement(el)) {\n return el\n }\n if (el) {\n return React.createElement(el, {\n ...props,\n color,\n })\n }\n return el\n }\n}\n"],
5
- "mappings": "AAAA;AAEA;AAEO,MAAM,mBAAmB,CAAC,UAA8C;AAC7E,QAAM,QAAQ,gBAAgB,MAAM,KAAK;AACzC,SAAO,CAAC,OAAY;AAClB,QAAI,eAAe,EAAE,GAAG;AACtB,aAAO;AAAA,IACT;AACA,QAAI,IAAI;AACN,aAAO,MAAM,cAAc,IAAI;AAAA,QAC7B,GAAG;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import React, { isValidElement } from 'react'\n\nimport { ColorProp, useCurrentColor } from './useCurrentColor'\n\nexport const useGetThemedIcon = (props: { color: ColorProp; size: number }) => {\n const color = useCurrentColor(props.color)\n return (el: any) => {\n if (el) {\n if (isValidElement(el)) {\n return React.cloneElement(el as any, {\n ...props,\n color,\n // @ts-ignore\n ...el.props,\n })\n }\n return React.createElement(el, {\n ...props,\n color,\n })\n }\n return el\n }\n}\n"],
5
+ "mappings": "AAAA;AAEA;AAEO,MAAM,mBAAmB,CAAC,UAA8C;AAC7E,QAAM,QAAQ,gBAAgB,MAAM,KAAK;AACzC,SAAO,CAAC,OAAY;AAClB,QAAI,IAAI;AACN,UAAI,eAAe,EAAE,GAAG;AACtB,eAAO,MAAM,aAAa,IAAW;AAAA,UACnC,GAAG;AAAA,UACH;AAAA,UAEA,GAAG,GAAG;AAAA,QACR,CAAC;AAAA,MACH;AACA,aAAO,MAAM,cAAc,IAAI;AAAA,QAC7B,GAAG;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
File without changes
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapStringChildrenInText.tsx"],
4
- "sourcesContent": ["import { 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 wrapStringChildrenInText(\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"],
4
+ "sourcesContent": ["import type { SizeTokens } from '@tamagui/core'\nimport React from 'react'\n\nimport type { TextParentStyles } from './types'\n\ntype Props = TextParentStyles & {\n children?: React.ReactNode\n size?: SizeTokens\n}\n\nexport function wrapStringChildrenInText(\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
5
  "mappings": "AACA;AASO,kCACL,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;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,29 @@
1
+ import { expect, test } from "vitest";
2
+ import { wrapStringChildrenInText } from "./wrapStringChildrenInText";
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 = wrapStringChildrenInText(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 = wrapStringChildrenInText(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=wrapStringChildrenInText.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapStringChildrenInText.test.tsx"],
4
+ "sourcesContent": ["import { expect, test } from 'vitest'\n\nimport { wrapStringChildrenInText } from './wrapStringChildrenInText'\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 = wrapStringChildrenInText(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 = wrapStringChildrenInText(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": "AAAA;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,yBAAyB,MAAM;AAAA,IACzC,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,yBAAyB,MAAM;AAAA,IACzC,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,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/helpers-tamagui",
3
- "version": "1.0.1-beta.92",
3
+ "version": "1.0.1-beta.95",
4
4
  "source": "src/index.ts",
5
5
  "types": "./types/index.d.ts",
6
6
  "main": "dist/cjs",
@@ -15,15 +15,18 @@
15
15
  "build": "tamagui-build",
16
16
  "watch": "tamagui-build --watch",
17
17
  "clean": "tamagui-build clean",
18
- "clean:build": "tamagui-build clean:build"
18
+ "clean:build": "tamagui-build clean:build",
19
+ "test": "vitest --config ../vite-plugin-internal/vite.config.ts"
19
20
  },
20
21
  "dependencies": {
21
- "@tamagui/text": "^1.0.1-beta.92"
22
+ "@tamagui/core": "^1.0.1-beta.95"
22
23
  },
23
24
  "devDependencies": {
24
- "@tamagui/build": "^1.0.1-beta.92",
25
+ "@tamagui/build": "^1.0.1-beta.95",
26
+ "@tamagui/vite-plugin-internal": "^1.0.1-beta.95",
25
27
  "react": "*",
26
- "react-native": "*"
28
+ "react-native": "*",
29
+ "vitest": "^0.16.0"
27
30
  },
28
31
  "peerDependencies": {
29
32
  "react": "*",
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './useCurrentColor'
2
2
  export * from './useGetThemedIcon'
3
- export * from './wrapStringChildrenInText'
4
3
  export * from './types'
@@ -1,5 +1,5 @@
1
1
  import { ColorTokens, ThemeValueFallback, useTheme } from '@tamagui/core'
2
- import { TextStyle } from 'react-native'
2
+ import type { TextStyle } from 'react-native'
3
3
 
4
4
  export const useCurrentColor = (colorProp: ColorProp) => {
5
5
  const theme = useTheme()
@@ -5,10 +5,15 @@ import { ColorProp, useCurrentColor } from './useCurrentColor'
5
5
  export const useGetThemedIcon = (props: { color: ColorProp; size: number }) => {
6
6
  const color = useCurrentColor(props.color)
7
7
  return (el: any) => {
8
- if (isValidElement(el)) {
9
- return el
10
- }
11
8
  if (el) {
9
+ if (isValidElement(el)) {
10
+ return React.cloneElement(el as any, {
11
+ ...props,
12
+ color,
13
+ // @ts-ignore
14
+ ...el.props,
15
+ })
16
+ }
12
17
  return React.createElement(el, {
13
18
  ...props,
14
19
  color,
package/types/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './useCurrentColor';
2
2
  export * from './useGetThemedIcon';
3
- export * from './wrapStringChildrenInText';
4
3
  export * from './types';
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,SAAS,CAAA"}
File without changes
@@ -1,5 +1,5 @@
1
1
  import { ColorTokens, ThemeValueFallback } from '@tamagui/core';
2
- import { TextStyle } from 'react-native';
2
+ import type { TextStyle } from 'react-native';
3
3
  export declare const useCurrentColor: (colorProp: ColorProp) => any;
4
4
  export declare type ColorProp = ThemeValueFallback | ColorTokens | TextStyle['color'] | undefined;
5
5
  //# sourceMappingURL=useCurrentColor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCurrentColor.d.ts","sourceRoot":"","sources":["../src/useCurrentColor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAY,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,eAAO,MAAM,eAAe,cAAe,SAAS,QAcnD,CAAA;AAED,oBAAY,SAAS,GAAG,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA"}
1
+ {"version":3,"file":"useCurrentColor.d.ts","sourceRoot":"","sources":["../src/useCurrentColor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAY,MAAM,eAAe,CAAA;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,eAAO,MAAM,eAAe,cAAe,SAAS,QAcnD,CAAA;AAED,oBAAY,SAAS,GAAG,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useGetThemedIcon.d.ts","sourceRoot":"","sources":["../src/useGetThemedIcon.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAmB,MAAM,mBAAmB,CAAA;AAE9D,eAAO,MAAM,gBAAgB,UAAW;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,UAE5D,GAAG,QAYhB,CAAA"}
1
+ {"version":3,"file":"useGetThemedIcon.d.ts","sourceRoot":"","sources":["../src/useGetThemedIcon.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAmB,MAAM,mBAAmB,CAAA;AAE9D,eAAO,MAAM,gBAAgB,UAAW;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,UAE5D,GAAG,QAiBhB,CAAA"}
@@ -1,6 +1,6 @@
1
- import { SizeTokens } from '@tamagui/core';
1
+ import type { SizeTokens } from '@tamagui/core';
2
2
  import React from 'react';
3
- import { TextParentStyles } from './types';
3
+ import type { TextParentStyles } from './types';
4
4
  declare type Props = TextParentStyles & {
5
5
  children?: React.ReactNode;
6
6
  size?: SizeTokens;
@@ -1 +1 @@
1
- {"version":3,"file":"wrapStringChildrenInText.d.ts","sourceRoot":"","sources":["../src/wrapStringChildrenInText.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,aAAK,KAAK,GAAG,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,GAAG,EAClB,EACE,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,UAAU,EACV,KAAK,EACL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,aAAa,EACb,SAAS,GACV,EAAE,KAAK,mJAoDT"}
1
+ {"version":3,"file":"wrapStringChildrenInText.d.ts","sourceRoot":"","sources":["../src/wrapStringChildrenInText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,aAAK,KAAK,GAAG,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,GAAG,EAClB,EACE,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,UAAU,EACV,KAAK,EACL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,aAAa,EACb,SAAS,GACV,EAAE,KAAK,mJAoDT"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=wrapStringChildrenInText.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapStringChildrenInText.test.d.ts","sourceRoot":"","sources":["../src/wrapStringChildrenInText.test.tsx"],"names":[],"mappings":""}
@@ -1,76 +0,0 @@
1
- import { 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 wrapStringChildrenInText(
12
- TextComponent: any,
13
- {
14
- children,
15
- textProps,
16
- size,
17
- noTextWrap,
18
- color,
19
- fontFamily,
20
- fontSize,
21
- fontWeight,
22
- letterSpacing,
23
- textAlign,
24
- }: Props
25
- ) {
26
- if (noTextWrap || !children) {
27
- return children
28
- }
29
-
30
- // in the case of using variables, like so:
31
- // <ListItem>Hello, {name}</ListItem>
32
- // it gives us props.children as ['Hello, ', 'name']
33
- // but we don't want to wrap multiple SizableText around each part
34
- // so we group them
35
- let allChildren = React.Children.toArray(children)
36
- let nextChildren: any[] = []
37
- let lastIsString = false
38
- const directTextProps: any = {}
39
- // to avoid setting undefined
40
- if (color) directTextProps.color = color
41
- if (fontFamily) directTextProps.fontFamily = fontFamily
42
- if (fontSize) directTextProps.fontSize = fontSize
43
- if (fontWeight) directTextProps.fontWeight = fontWeight
44
- if (letterSpacing) directTextProps.letterSpacing = letterSpacing
45
- if (textAlign) directTextProps.textAlign = textAlign
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} {...directTextProps} size={size} {...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
- }