@multiplatform.one/components 0.2.17 → 0.7.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 (233) hide show
  1. package/LICENSE +201 -0
  2. package/dist/cjs/forms/FormCheckBox/FormCheckBox.stories.js +30 -1
  3. package/dist/cjs/forms/FormCheckBox/FormCheckBox.stories.js.map +1 -1
  4. package/dist/cjs/forms/{RadioSimple/RadioSimple.stories.js → FormProgress/FormProgress.stories.js} +18 -13
  5. package/dist/cjs/forms/FormProgress/FormProgress.stories.js.map +6 -0
  6. package/dist/cjs/forms/FormProgress/index.js +104 -0
  7. package/dist/cjs/forms/FormProgress/index.js.map +6 -0
  8. package/dist/cjs/forms/FormRadioGroup/FormRadioGroup.stories.js +3 -1
  9. package/dist/cjs/forms/FormRadioGroup/FormRadioGroup.stories.js.map +1 -1
  10. package/dist/cjs/forms/FormSlider/FormSlider.stories.js +2 -1
  11. package/dist/cjs/forms/FormSlider/FormSlider.stories.js.map +1 -1
  12. package/dist/cjs/forms/FormSwitch/FormSwitch.stories.js +11 -1
  13. package/dist/cjs/forms/FormSwitch/FormSwitch.stories.js.map +1 -1
  14. package/dist/cjs/forms/FormTextArea/FormTextArea.stories.js +11 -1
  15. package/dist/cjs/forms/FormTextArea/FormTextArea.stories.js.map +1 -1
  16. package/dist/cjs/forms/SimpleForm/SimpleForm.stories.js +16 -1
  17. package/dist/cjs/forms/SimpleForm/SimpleForm.stories.js.map +1 -1
  18. package/dist/cjs/hooks/useAssets/index.js +6 -13
  19. package/dist/cjs/hooks/useAssets/index.js.map +1 -1
  20. package/dist/cjs/hooks/useAssets/index.native.js +4 -10
  21. package/dist/cjs/hooks/useAssets/index.native.js.map +1 -1
  22. package/dist/cjs/images/SimpleImage/index.js +104 -123
  23. package/dist/cjs/images/SimpleImage/index.js.map +2 -2
  24. package/dist/cjs/images/SimpleImage/index.stories.js +26 -2
  25. package/dist/cjs/images/SimpleImage/index.stories.js.map +1 -1
  26. package/dist/cjs/images/index.js +2 -2
  27. package/dist/cjs/images/index.js.map +1 -1
  28. package/dist/cjs/organize/SimpleTabs/SimpleTabs.stories.js +54 -0
  29. package/dist/cjs/organize/SimpleTabs/SimpleTabs.stories.js.map +6 -0
  30. package/dist/cjs/organize/SimpleTabs/index.js +132 -0
  31. package/dist/cjs/organize/SimpleTabs/index.js.map +6 -0
  32. package/dist/cjs/{forms/RadioSimple/index.js → panels/SimpleToast/SimpleToast.stories.js} +23 -20
  33. package/dist/cjs/panels/SimpleToast/SimpleToast.stories.js.map +6 -0
  34. package/dist/cjs/panels/SimpleToast/index.js +59 -0
  35. package/dist/cjs/panels/SimpleToast/index.js.map +6 -0
  36. package/dist/esm/forms/FormCheckBox/FormCheckBox.stories.js +31 -2
  37. package/dist/esm/forms/FormCheckBox/FormCheckBox.stories.js.map +1 -1
  38. package/dist/esm/forms/FormProgress/FormProgress.stories.js +19 -0
  39. package/dist/esm/forms/FormProgress/FormProgress.stories.js.map +6 -0
  40. package/dist/esm/forms/FormProgress/index.js +71 -0
  41. package/dist/esm/forms/FormProgress/index.js.map +6 -0
  42. package/dist/esm/forms/FormRadioGroup/FormRadioGroup.stories.js +3 -1
  43. package/dist/esm/forms/FormRadioGroup/FormRadioGroup.stories.js.map +1 -1
  44. package/dist/esm/forms/FormSlider/FormSlider.stories.js +2 -1
  45. package/dist/esm/forms/FormSlider/FormSlider.stories.js.map +1 -1
  46. package/dist/esm/forms/FormSwitch/FormSwitch.stories.js +11 -1
  47. package/dist/esm/forms/FormSwitch/FormSwitch.stories.js.map +1 -1
  48. package/dist/esm/forms/FormTextArea/FormTextArea.stories.js +11 -1
  49. package/dist/esm/forms/FormTextArea/FormTextArea.stories.js.map +1 -1
  50. package/dist/esm/forms/SimpleForm/SimpleForm.stories.js +16 -1
  51. package/dist/esm/forms/SimpleForm/SimpleForm.stories.js.map +1 -1
  52. package/dist/esm/hooks/useAssets/index.js +6 -13
  53. package/dist/esm/hooks/useAssets/index.js.map +1 -1
  54. package/dist/esm/hooks/useAssets/index.native.js +4 -10
  55. package/dist/esm/hooks/useAssets/index.native.js.map +1 -1
  56. package/dist/esm/images/SimpleImage/index.js +106 -125
  57. package/dist/esm/images/SimpleImage/index.js.map +2 -2
  58. package/dist/esm/images/SimpleImage/index.stories.js +23 -1
  59. package/dist/esm/images/SimpleImage/index.stories.js.map +1 -1
  60. package/dist/esm/images/index.js +1 -1
  61. package/dist/esm/organize/SimpleTabs/SimpleTabs.stories.js +20 -0
  62. package/dist/esm/organize/SimpleTabs/SimpleTabs.stories.js.map +6 -0
  63. package/dist/esm/organize/SimpleTabs/index.js +96 -0
  64. package/dist/esm/organize/SimpleTabs/index.js.map +6 -0
  65. package/dist/esm/panels/SimpleToast/SimpleToast.stories.js +23 -0
  66. package/dist/esm/panels/SimpleToast/SimpleToast.stories.js.map +6 -0
  67. package/dist/esm/panels/SimpleToast/index.js +26 -0
  68. package/dist/esm/panels/SimpleToast/index.js.map +6 -0
  69. package/dist/jsx/forms/FormCheckBox/FormCheckBox.stories.js +24 -2
  70. package/dist/jsx/forms/FormCheckBox/FormCheckBox.stories.js.map +1 -1
  71. package/dist/jsx/forms/FormCheckBox/FormCheckBox.stories.mjs +24 -2
  72. package/dist/jsx/forms/FormCheckBox/FormCheckBox.stories.mjs.map +1 -1
  73. package/dist/jsx/forms/FormProgress/FormProgress.stories.js +18 -0
  74. package/dist/jsx/forms/FormProgress/FormProgress.stories.js.map +6 -0
  75. package/dist/jsx/forms/FormProgress/FormProgress.stories.mjs +18 -0
  76. package/dist/jsx/forms/FormProgress/FormProgress.stories.mjs.map +6 -0
  77. package/dist/jsx/forms/FormProgress/index.js +57 -0
  78. package/dist/jsx/forms/FormProgress/index.js.map +6 -0
  79. package/dist/jsx/forms/FormProgress/index.mjs +57 -0
  80. package/dist/jsx/forms/FormProgress/index.mjs.map +6 -0
  81. package/dist/jsx/forms/FormRadioGroup/FormRadioGroup.stories.js +2 -0
  82. package/dist/jsx/forms/FormRadioGroup/FormRadioGroup.stories.js.map +1 -1
  83. package/dist/jsx/forms/FormRadioGroup/FormRadioGroup.stories.mjs +2 -0
  84. package/dist/jsx/forms/FormRadioGroup/FormRadioGroup.stories.mjs.map +1 -1
  85. package/dist/jsx/forms/FormSlider/FormSlider.stories.js +2 -1
  86. package/dist/jsx/forms/FormSlider/FormSlider.stories.js.map +1 -1
  87. package/dist/jsx/forms/FormSlider/FormSlider.stories.mjs +2 -1
  88. package/dist/jsx/forms/FormSlider/FormSlider.stories.mjs.map +1 -1
  89. package/dist/jsx/forms/FormSwitch/FormSwitch.stories.js +8 -1
  90. package/dist/jsx/forms/FormSwitch/FormSwitch.stories.js.map +1 -1
  91. package/dist/jsx/forms/FormSwitch/FormSwitch.stories.mjs +8 -1
  92. package/dist/jsx/forms/FormSwitch/FormSwitch.stories.mjs.map +1 -1
  93. package/dist/jsx/forms/FormTextArea/FormTextArea.stories.js +8 -1
  94. package/dist/jsx/forms/FormTextArea/FormTextArea.stories.js.map +1 -1
  95. package/dist/jsx/forms/FormTextArea/FormTextArea.stories.mjs +8 -1
  96. package/dist/jsx/forms/FormTextArea/FormTextArea.stories.mjs.map +1 -1
  97. package/dist/jsx/forms/SimpleForm/SimpleForm.stories.js +15 -0
  98. package/dist/jsx/forms/SimpleForm/SimpleForm.stories.js.map +1 -1
  99. package/dist/jsx/forms/SimpleForm/SimpleForm.stories.mjs +15 -0
  100. package/dist/jsx/forms/SimpleForm/SimpleForm.stories.mjs.map +1 -1
  101. package/dist/jsx/hooks/useAssets/index.js +6 -13
  102. package/dist/jsx/hooks/useAssets/index.js.map +1 -1
  103. package/dist/jsx/hooks/useAssets/index.mjs +6 -13
  104. package/dist/jsx/hooks/useAssets/index.mjs.map +1 -1
  105. package/dist/jsx/hooks/useAssets/index.native.js +4 -10
  106. package/dist/jsx/hooks/useAssets/index.native.js.map +1 -1
  107. package/dist/jsx/hooks/useAssets/index.native.mjs +4 -10
  108. package/dist/jsx/hooks/useAssets/index.native.mjs.map +1 -1
  109. package/dist/jsx/images/SimpleImage/index.js +105 -119
  110. package/dist/jsx/images/SimpleImage/index.js.map +2 -2
  111. package/dist/jsx/images/SimpleImage/index.mjs +105 -119
  112. package/dist/jsx/images/SimpleImage/index.mjs.map +2 -2
  113. package/dist/jsx/images/SimpleImage/index.stories.js +21 -1
  114. package/dist/jsx/images/SimpleImage/index.stories.js.map +1 -1
  115. package/dist/jsx/images/SimpleImage/index.stories.mjs +21 -1
  116. package/dist/jsx/images/SimpleImage/index.stories.mjs.map +1 -1
  117. package/dist/jsx/images/index.js +1 -1
  118. package/dist/jsx/images/index.mjs +1 -1
  119. package/dist/jsx/organize/SimpleTabs/SimpleTabs.stories.js +41 -0
  120. package/dist/jsx/organize/SimpleTabs/SimpleTabs.stories.js.map +6 -0
  121. package/dist/jsx/organize/SimpleTabs/SimpleTabs.stories.mjs +41 -0
  122. package/dist/jsx/organize/SimpleTabs/SimpleTabs.stories.mjs.map +6 -0
  123. package/dist/jsx/organize/SimpleTabs/index.js +80 -0
  124. package/dist/jsx/organize/SimpleTabs/index.js.map +6 -0
  125. package/dist/jsx/organize/SimpleTabs/index.mjs +80 -0
  126. package/dist/jsx/organize/SimpleTabs/index.mjs.map +6 -0
  127. package/dist/jsx/panels/SimpleToast/SimpleToast.stories.js +25 -0
  128. package/dist/jsx/panels/SimpleToast/SimpleToast.stories.js.map +6 -0
  129. package/dist/jsx/panels/SimpleToast/SimpleToast.stories.mjs +25 -0
  130. package/dist/jsx/panels/SimpleToast/SimpleToast.stories.mjs.map +6 -0
  131. package/dist/jsx/panels/SimpleToast/index.js +24 -0
  132. package/dist/jsx/panels/SimpleToast/index.js.map +6 -0
  133. package/dist/jsx/panels/SimpleToast/index.mjs +24 -0
  134. package/dist/jsx/panels/SimpleToast/index.mjs.map +6 -0
  135. package/package.json +15 -13
  136. package/src/forms/FormCheckBox/FormCheckBox.stories.tsx +24 -4
  137. package/src/forms/FormProgress/FormProgress.stories.tsx +16 -0
  138. package/src/forms/FormProgress/index.tsx +74 -0
  139. package/src/forms/FormRadioGroup/FormRadioGroup.stories.tsx +2 -0
  140. package/src/forms/FormSlider/FormSlider.stories.tsx +2 -1
  141. package/src/forms/FormSwitch/FormSwitch.stories.tsx +8 -1
  142. package/src/forms/FormTextArea/FormTextArea.stories.tsx +8 -1
  143. package/src/forms/SimpleForm/SimpleForm.stories.tsx +15 -0
  144. package/src/hooks/useAssets/index.native.ts +8 -14
  145. package/src/hooks/useAssets/index.ts +8 -28
  146. package/src/images/SimpleImage/index.stories.tsx +26 -0
  147. package/src/images/SimpleImage/index.tsx +137 -162
  148. package/src/images/index.ts +1 -1
  149. package/src/organize/SimpleTabs/SimpleTabs.stories.tsx +63 -0
  150. package/src/organize/SimpleTabs/index.tsx +118 -0
  151. package/src/panels/SimpleToast/SimpleToast.stories.tsx +27 -0
  152. package/src/panels/SimpleToast/index.tsx +27 -0
  153. package/types/code/Code/index.d.ts +49 -15
  154. package/types/code/Code/index.d.ts.map +1 -1
  155. package/types/code/Pre/index.d.ts +16 -7
  156. package/types/code/Pre/index.d.ts.map +1 -1
  157. package/types/forms/FormCheckBox/FormCheckBox.stories.d.ts.map +1 -1
  158. package/types/forms/FormProgress/FormProgress.stories.d.ts +15 -0
  159. package/types/forms/FormProgress/FormProgress.stories.d.ts.map +1 -0
  160. package/types/forms/FormProgress/index.d.ts +11 -0
  161. package/types/forms/FormProgress/index.d.ts.map +1 -0
  162. package/types/forms/FormRadioGroup/FormRadioGroup.stories.d.ts.map +1 -1
  163. package/types/forms/FormSlider/FormSlider.stories.d.ts.map +1 -1
  164. package/types/forms/FormSwitch/FormSwitch.stories.d.ts.map +1 -1
  165. package/types/forms/FormTextArea/FormTextArea.stories.d.ts.map +1 -1
  166. package/types/forms/SimpleForm/SimpleForm.stories.d.ts.map +1 -1
  167. package/types/hooks/useAssets/index.d.ts +2 -3
  168. package/types/hooks/useAssets/index.d.ts.map +1 -1
  169. package/types/hooks/useAssets/index.native.d.ts +2 -2
  170. package/types/hooks/useAssets/index.native.d.ts.map +1 -1
  171. package/types/images/SimpleImage/index.d.ts +15 -22
  172. package/types/images/SimpleImage/index.d.ts.map +1 -1
  173. package/types/images/SimpleImage/index.stories.d.ts +8 -2
  174. package/types/images/SimpleImage/index.stories.d.ts.map +1 -1
  175. package/types/images/SvgUri/index.native.d.ts +5 -5
  176. package/types/images/index.d.ts +1 -1
  177. package/types/images/index.d.ts.map +1 -1
  178. package/types/mdx/LI/LI.stories.d.ts +29 -12
  179. package/types/mdx/LI/LI.stories.d.ts.map +1 -1
  180. package/types/mdx/LI/index.d.ts +29 -12
  181. package/types/mdx/LI/index.d.ts.map +1 -1
  182. package/types/mdx/UL/UL.stories.d.ts +16 -7
  183. package/types/mdx/UL/UL.stories.d.ts.map +1 -1
  184. package/types/mdx/UL/index.d.ts +16 -7
  185. package/types/mdx/UL/index.d.ts.map +1 -1
  186. package/types/mdx/components.d.ts +16 -7
  187. package/types/mdx/components.d.ts.map +1 -1
  188. package/types/organize/SimpleTabs/SimpleTabs.stories.d.ts +15 -0
  189. package/types/organize/SimpleTabs/SimpleTabs.stories.d.ts.map +1 -0
  190. package/types/organize/SimpleTabs/index.d.ts +21 -0
  191. package/types/organize/SimpleTabs/index.d.ts.map +1 -0
  192. package/types/{forms/RadioSimple/RadioSimple.stories.d.ts → panels/SimpleToast/SimpleToast.stories.d.ts} +4 -4
  193. package/types/panels/SimpleToast/SimpleToast.stories.d.ts.map +1 -0
  194. package/types/panels/SimpleToast/index.d.ts +3 -0
  195. package/types/panels/SimpleToast/index.d.ts.map +1 -0
  196. package/types/table/Table/Table.stories.d.ts +51 -10
  197. package/types/table/Table/Table.stories.d.ts.map +1 -1
  198. package/types/table/Table/index.d.ts +51 -10
  199. package/types/table/Table/index.d.ts.map +1 -1
  200. package/types/table/TableCell/index.d.ts +20 -3
  201. package/types/table/TableCell/index.d.ts.map +1 -1
  202. package/types/table/TableCol/index.d.ts +31 -7
  203. package/types/table/TableCol/index.d.ts.map +1 -1
  204. package/dist/cjs/forms/RadioSimple/RadioSimple.stories.js.map +0 -6
  205. package/dist/cjs/forms/RadioSimple/index.js.map +0 -6
  206. package/dist/cjs/hooks/useAssets/types.js +0 -16
  207. package/dist/cjs/hooks/useAssets/types.js.map +0 -6
  208. package/dist/esm/forms/RadioSimple/RadioSimple.stories.js +0 -15
  209. package/dist/esm/forms/RadioSimple/RadioSimple.stories.js.map +0 -6
  210. package/dist/esm/forms/RadioSimple/index.js +0 -20
  211. package/dist/esm/forms/RadioSimple/index.js.map +0 -6
  212. package/dist/esm/hooks/useAssets/types.js +0 -1
  213. package/dist/esm/hooks/useAssets/types.js.map +0 -6
  214. package/dist/jsx/forms/RadioSimple/RadioSimple.stories.js +0 -14
  215. package/dist/jsx/forms/RadioSimple/RadioSimple.stories.js.map +0 -6
  216. package/dist/jsx/forms/RadioSimple/RadioSimple.stories.mjs +0 -14
  217. package/dist/jsx/forms/RadioSimple/RadioSimple.stories.mjs.map +0 -6
  218. package/dist/jsx/forms/RadioSimple/index.js +0 -26
  219. package/dist/jsx/forms/RadioSimple/index.js.map +0 -6
  220. package/dist/jsx/forms/RadioSimple/index.mjs +0 -26
  221. package/dist/jsx/forms/RadioSimple/index.mjs.map +0 -6
  222. package/dist/jsx/hooks/useAssets/types.js +0 -1
  223. package/dist/jsx/hooks/useAssets/types.js.map +0 -6
  224. package/dist/jsx/hooks/useAssets/types.mjs +0 -1
  225. package/dist/jsx/hooks/useAssets/types.mjs.map +0 -6
  226. package/src/forms/RadioSimple/RadioSimple.stories.tsx +0 -12
  227. package/src/forms/RadioSimple/index.tsx +0 -42
  228. package/src/hooks/useAssets/types.ts +0 -3
  229. package/types/forms/RadioSimple/RadioSimple.stories.d.ts.map +0 -1
  230. package/types/forms/RadioSimple/index.d.ts +0 -8
  231. package/types/forms/RadioSimple/index.d.ts.map +0 -1
  232. package/types/hooks/useAssets/types.d.ts +0 -3
  233. package/types/hooks/useAssets/types.d.ts.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { FormSwitch } from './index';
3
+ import { action } from '@storybook/addon-actions';
3
4
 
4
5
  export default {
5
6
  title: 'forms/FormSwitch',
@@ -10,5 +11,11 @@ export default {
10
11
  };
11
12
 
12
13
  export const main = () => (
13
- <FormSwitch label="Example Switch" name="exampleSwitch" helperText="This is an example switch" defaultValue={false} />
14
+ <FormSwitch
15
+ label="Example Switch"
16
+ name="exampleSwitch"
17
+ helperText="This is an example switch"
18
+ defaultValue={false}
19
+ onCheckedChange={action('onCheckedChange')}
20
+ />
14
21
  );
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { FormTextArea } from './index';
3
+ import { action } from '@storybook/addon-actions';
3
4
 
4
5
  export default {
5
6
  title: 'forms/FormTextArea',
@@ -10,5 +11,11 @@ export default {
10
11
  };
11
12
 
12
13
  export const main = () => (
13
- <FormTextArea label="Description" name="description" defaultValue="" rules={{ required: true }} />
14
+ <FormTextArea
15
+ label="Description"
16
+ name="description"
17
+ defaultValue=""
18
+ rules={{ required: true }}
19
+ onChangeText={action('onChangeText')}
20
+ />
14
21
  );
@@ -3,6 +3,9 @@ import { SimpleForm } from './index';
3
3
  import { FormInput } from '../FormInput';
4
4
  import { FormSelectSimple } from '../FormSelectSimple';
5
5
  import { FormSubmitButton } from '../FormSubmitButton';
6
+ import { FormTextArea } from '../FormTextArea';
7
+ import { FormSwitch } from '../FormSwitch';
8
+ import { FormRadioGroup } from '../FormRadioGroup';
6
9
  import { Select } from 'tamagui';
7
10
  import { action } from '@storybook/addon-actions';
8
11
 
@@ -41,6 +44,18 @@ export const main = () => (
41
44
  <Select.ItemText>Violet</Select.ItemText>
42
45
  </Select.Item>
43
46
  </FormSelectSimple>
47
+ <FormTextArea name="bio" label="Bio" />
48
+ <FormSwitch name="isAwesome" label="Is Awesome" />
49
+ <FormRadioGroup
50
+ radioElements={[
51
+ { label: 'male', value: 'male' },
52
+ { label: 'female', value: 'female' },
53
+ ]}
54
+ name="Gender"
55
+ label="Gender"
56
+ horizontal
57
+ spacingProps={{ space: true }}
58
+ />
44
59
  <FormSubmitButton onSubmit={action('onSubmit')}>Submit</FormSubmitButton>
45
60
  </SimpleForm>
46
61
  );
@@ -1,26 +1,20 @@
1
- import type { Asset as ExpoAsset } from 'expo-asset';
2
- import type { Asset } from './types';
1
+ import type { Asset } from 'expo-asset';
2
+ import type { StaticImageData } from 'next/dist/client/image';
3
3
  import { useAssets as expoUseAssets } from 'expo-asset';
4
4
 
5
5
  const logger = console;
6
6
 
7
- export function useAssets(modules: any | any[]): (Asset | undefined)[] {
7
+ export function useAssets(modules: any | any[]): (StaticImageData | undefined)[] {
8
8
  const modulesArr = (Array.isArray(modules) ? modules : [modules]).map((module: any) => {
9
- if (typeof module.default !== 'undefined' && module.__esModule === true) return module.default;
9
+ if (typeof module.default !== 'undefined') return module.default;
10
10
  return module;
11
11
  });
12
12
  const [assets, err] = expoUseAssets(modulesArr);
13
13
  if (err) logger.error(err);
14
14
  if (!assets) return new Array(modulesArr.length);
15
- return assets.map((asset: ExpoAsset) => ({
16
- type: asset.type,
17
- uri: asset.uri,
18
- width: asset.width || undefined,
19
- height: asset.height || undefined,
20
- name: asset.name,
21
- hash: asset.hash,
22
- localUri: asset.localUri,
23
- downloading: asset.downloading,
24
- downloaded: asset.downloaded,
15
+ return assets.map((asset: Asset) => ({
16
+ height: asset.height!,
17
+ src: asset.uri,
18
+ width: asset.width!,
25
19
  }));
26
20
  }
@@ -1,31 +1,11 @@
1
- import type { Asset } from './types';
1
+ import type { StaticImageData } from 'next/dist/client/image';
2
2
 
3
- export function useAssets(modules: any | any[]): (Asset | undefined)[] {
4
- const modulesArr = (Array.isArray(modules) ? modules : [modules]).map((module: any) => {
5
- if (typeof module.default !== 'undefined' && module.__esModule === true) return module.default;
6
- return module;
7
- });
8
- return modulesArr.map((module: WebModule) =>
9
- typeof module === 'string'
10
- ? {
11
- uri: module,
12
- }
13
- : {
14
- uri: module.src,
15
- height: module.height,
16
- blurDataURL: module.blurDataURL,
17
- width: module.width,
18
- },
3
+ export function useAssets(modules: any | any[]): (StaticImageData | undefined)[] {
4
+ const modulesArr: (StaticImageData | undefined)[] = (Array.isArray(modules) ? modules : [modules]).map(
5
+ (module: any) => {
6
+ if (typeof module.default !== 'undefined') return module.default;
7
+ return module;
8
+ },
19
9
  );
10
+ return modulesArr;
20
11
  }
21
-
22
- type WebModule =
23
- | string
24
- | {
25
- blurDataURL?: string;
26
- height?: 850;
27
- src: string;
28
- width?: 1024;
29
- };
30
-
31
- export type { Asset };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { Platform } from 'react-native';
3
3
  import { useAssets } from '../../hooks';
4
4
  import { SimpleImage } from './index';
5
+ import { YStack } from 'tamagui';
5
6
 
6
7
  export default {
7
8
  title: 'images/SimpleImage',
@@ -53,3 +54,28 @@ function WithRequire() {
53
54
  );
54
55
  }
55
56
  export const withRequire = () => <WithRequire />;
57
+
58
+ export const withYStack = () => (
59
+ <YStack>
60
+ <YStack width="50%" height={200} bg="red" />
61
+ <YStack width="50%" height={200} bg="blue" />
62
+ <SimpleImage
63
+ bg="green"
64
+ height={200}
65
+ resizeMode="stretch"
66
+ src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a8/Inukshuk_Park_05.jpg/500px-Inukshuk_Park_05.jpg"
67
+ width="50%"
68
+ />
69
+ </YStack>
70
+ );
71
+
72
+ export const withTamagui = () => (
73
+ <YStack>
74
+ <SimpleImage
75
+ bg="$green9"
76
+ h="$19"
77
+ src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a8/Inukshuk_Park_05.jpg/500px-Inukshuk_Park_05.jpg"
78
+ w="100%"
79
+ />
80
+ </YStack>
81
+ );
@@ -1,174 +1,149 @@
1
- import React, { useEffect, useState } from 'react';
2
- import type { ImageProps, YStackProps } from 'tamagui';
3
- import type { ImageURISource, ImageResizeMode } from 'react-native';
4
- import type { SvgUriProps } from '../SvgUri';
5
- import { MultiPlatform } from 'multiplatform.one';
6
- import { Platform, Image as RNImage } from 'react-native';
7
- import { SvgUri } from '../SvgUri';
8
- import { XMLParser } from 'fast-xml-parser';
9
- import { YStack, Image } from 'tamagui';
10
- import { getTokens } from 'tamagui';
1
+ import React, { useMemo, forwardRef, useRef } from 'react';
2
+ import type { ComponentProps, Ref } from 'react';
3
+ import type { Image } from 'expo-image';
4
+ import type { SolitoImageProps } from 'solito/build/image/image.types';
5
+ import type { StackProps } from 'tamagui';
6
+ import type { StaticImageData } from 'next/dist/client/image';
7
+ import { SolitoImage } from 'solito/image';
8
+ import { Stack, createComponent } from 'tamagui';
9
+ import { StyleSheet } from 'react-native';
11
10
  import { useAssets } from '../../hooks/useAssets';
12
- import { useMemo } from 'react';
13
11
 
14
- export type SimpleImageProps = Omit<ImageProps, 'src' | 'source'> & {
15
- src?: ImageURISource | string;
16
- svg?: boolean;
17
- };
12
+ type Props = Omit<SolitoImageProps, 'height' | 'width' | 'src' | 'fill' | 'style' | 'alt'> &
13
+ Omit<StackProps, 'height' | 'width'> & {
14
+ alt?: string;
15
+ height?: number | string;
16
+ src?: StaticImport | string | number;
17
+ width?: number | string;
18
+ };
18
19
 
19
- export function SimpleImage({
20
- aspectRatio,
21
- h,
22
- height,
23
- resizeMode,
24
- src,
25
- svg,
26
- w,
27
- width,
28
- ...imageProps
29
- }: SimpleImageProps) {
30
- const tokens = getTokens();
31
- height = tokens.size[(height || h) as string]?.val || height || h;
32
- width = tokens.size[(width || w) as string]?.val || width || w;
33
- const preserveAspectRatio = useMemo(() => getPreserveAspectRatio(resizeMode), [resizeMode]);
34
- let source: string | number | ImageURISource | undefined = src;
35
- if ((typeof src === 'object' && typeof (src as ImageURISource).uri === 'undefined') || typeof src === 'number') {
36
- [source] = useAssets(src);
37
- }
38
- const [imageAspectRatio, setImageAspectRatio] = useState(
39
- typeof source === 'object' && source.width && source.height ? source.width / source.height : undefined,
40
- );
41
- if (!Number.isFinite(aspectRatio)) aspectRatio = imageAspectRatio;
42
- const uri = typeof source === 'object' ? source.uri : source;
43
- const origin = uri?.replace(/\?.+/g, '');
44
- // fixes bug on web where width is calculated differently than on native
45
- if (
46
- Platform.OS === 'web' &&
47
- typeof aspectRatio === 'number' &&
48
- typeof height === 'number' &&
49
- Number.isFinite(height) &&
50
- (!Number.isFinite(width) || width === 'auto')
51
- ) {
52
- width = height * aspectRatio;
53
- }
54
- if (Number.isFinite(height) && Number.isFinite(width)) aspectRatio = undefined;
55
- const isSvg =
56
- svg ||
57
- (((src as any)?.type === 'svg' || origin?.substring(origin.length - 4) === '.svg') && typeof svg === 'undefined');
20
+ const SimpleImageComponent = forwardRef<Image, Props>(
21
+ (
22
+ {
23
+ alt,
24
+ blurDataURL,
25
+ contentFit,
26
+ contentPosition,
27
+ crossOrigin,
28
+ height,
29
+ loader,
30
+ loading,
31
+ onLayout,
32
+ onLoadingComplete,
33
+ placeholder,
34
+ priority,
35
+ quality,
36
+ aspectRatio,
37
+ referrerPolicy,
38
+ resizeMode,
39
+ sizes,
40
+ src,
41
+ unoptimized,
42
+ width,
43
+ ...props
44
+ }: Props,
45
+ ref: Ref<Image>,
46
+ ) => {
47
+ const parentRef = useRef();
48
+ const style = StyleSheet.flatten(props.style || {});
49
+ let asset: StaticImageData | undefined;
50
+ if (typeof src === 'number') [asset] = useAssets([src]);
51
+ const staticImageData = useMemo(() => {
52
+ if (typeof src === 'string') return;
53
+ if (typeof src === 'number') return asset;
54
+ return (src as { default?: StaticImageData })?.default || (src as StaticImageData);
55
+ }, [asset, src]);
58
56
 
59
- useEffect(() => {
60
- if (Platform.OS !== 'web' && isSvg) {
61
- (async () => {
62
- const meta = await getSvgMeta(uri);
63
- const height = Number.isFinite(meta.height) ? meta.height : meta.viewBox?.[3];
64
- const width = Number.isFinite(meta.width) ? meta.width : meta.viewBox?.[2];
65
- if (
66
- typeof height === 'number' &&
67
- Number.isFinite(height) &&
68
- typeof width === 'number' &&
69
- Number.isFinite(width)
70
- ) {
71
- setImageAspectRatio(width / height);
72
- }
73
- })();
74
- } else if (typeof uri !== 'number' && uri /* && calculateHeight */) {
75
- RNImage.getSize(uri, (width: number, height: number) => {
76
- const ratio = width / height;
77
- if (Number.isFinite(ratio)) setImageAspectRatio(ratio);
78
- });
79
- }
80
- }, [uri]);
57
+ const mAspectRatio = useMemo(() => {
58
+ const sAspectRatio = aspectRatio || style.aspectRatio;
59
+ if (typeof sAspectRatio === 'string') {
60
+ const [width, height] = sAspectRatio.split(':');
61
+ return parseInt(width, 10) / parseInt(height, 10);
62
+ }
63
+ return sAspectRatio;
64
+ }, [aspectRatio, style.aspectRatio]);
81
65
 
82
- if (!uri) {
83
- return <YStack {...(imageProps as YStackProps)} width={width} height={height} aspectRatio={aspectRatio} />;
84
- }
85
- if (!MultiPlatform.isWeb && isSvg) {
86
- return (
87
- <SvgUri
88
- {...(imageProps as Partial<SvgUriProps>)}
89
- width={Number.isFinite(width) ? (width as number) : Number.isFinite(height) ? undefined : '100%'}
90
- height={height as number}
91
- preserveAspectRatio={preserveAspectRatio}
92
- aspectRatio={aspectRatio}
93
- uri={uri}
94
- />
95
- );
96
- }
97
- return (
98
- <Image
99
- zIndex={undefined}
100
- {...imageProps}
101
- // @ts-ignore
102
- width={width}
103
- // @ts-ignore
104
- height={height}
105
- aspectRatio={aspectRatio}
106
- resizeMode={resizeMode}
107
- source={{ uri }}
108
- />
109
- );
110
- }
66
+ const solitoHeight = useMemo(() => {
67
+ if (typeof height === 'string') return;
68
+ if (typeof height === 'number') return height;
69
+ const w =
70
+ typeof width === 'number'
71
+ ? width
72
+ : typeof style.width !== 'undefined'
73
+ ? typeof style.width === 'number'
74
+ ? style.width
75
+ : undefined
76
+ : staticImageData?.width;
77
+ if (typeof w === 'number' && typeof mAspectRatio === 'number') return w / mAspectRatio;
78
+ return staticImageData?.height;
79
+ }, [mAspectRatio, staticImageData?.width, staticImageData?.height, style.width, style.height, width, height]);
111
80
 
112
- SimpleImage.defaultProps = {
113
- resizeMode: 'cover',
114
- };
81
+ const solitoWidth = useMemo(() => {
82
+ if (typeof width === 'string') return;
83
+ if (typeof width === 'number') return width;
84
+ const h =
85
+ typeof height === 'number'
86
+ ? height
87
+ : typeof style.height !== 'undefined'
88
+ ? typeof style.height === 'number'
89
+ ? style.height
90
+ : undefined
91
+ : staticImageData?.height;
92
+ if (typeof h === 'number' && typeof mAspectRatio === 'number') return h * mAspectRatio;
93
+ return staticImageData?.width;
94
+ }, [mAspectRatio, staticImageData?.width, staticImageData?.height, style.width, style.height, width, height]);
115
95
 
116
- function getPreserveAspectRatio(resizeMode?: ImageResizeMode): string {
117
- switch (resizeMode) {
118
- case 'stretch': {
119
- return 'none';
120
- }
121
- case 'contain': {
122
- return 'xMidYMid meet';
123
- }
124
- }
125
- return 'xMidYMid slice';
126
- }
96
+ const fill = useMemo(() => {
97
+ if (typeof solitoWidth === 'undefined' || typeof solitoHeight === 'undefined') {
98
+ return true;
99
+ }
100
+ return false;
101
+ }, [solitoWidth, solitoHeight]);
127
102
 
128
- const logger = console;
129
- const parser = new XMLParser({
130
- ignoreAttributes: false,
131
- attributeNamePrefix: '@_',
132
- allowBooleanAttributes: true,
133
- });
103
+ return (
104
+ <Stack {...props} aspectRatio={aspectRatio} width={width} height={height} ref={parentRef as any}>
105
+ {src && (
106
+ <SolitoImage
107
+ alt={alt || ''}
108
+ blurDataURL={blurDataURL}
109
+ contentFit={contentFit}
110
+ contentPosition={contentPosition}
111
+ crossOrigin={crossOrigin}
112
+ fill={fill}
113
+ height={fill ? undefined : solitoHeight}
114
+ loader={loader}
115
+ loading={loading}
116
+ onLayout={onLayout}
117
+ onLoadingComplete={onLoadingComplete}
118
+ placeholder={placeholder}
119
+ priority={priority}
120
+ quality={quality}
121
+ ref={ref}
122
+ referrerPolicy={referrerPolicy}
123
+ resizeMode={resizeMode}
124
+ sizes={sizes}
125
+ src={src as any}
126
+ unoptimized={unoptimized}
127
+ width={fill ? undefined : solitoWidth}
128
+ />
129
+ )}
130
+ </Stack>
131
+ );
132
+ },
133
+ );
134
134
 
135
- async function getSvgMeta(uri?: string | number) {
136
- const meta: SvgMeta = {};
137
- if (Platform.OS === 'web' || typeof uri === 'number' || !uri) return meta;
138
- const res = await fetch(uri);
139
- try {
140
- const xml = parser.parse(await res.text());
141
- const width = parseInt(xml?.svg?.['@_width'], 10);
142
- const height = parseInt(xml?.svg?.['@_height'], 10);
143
- const viewBox = xml?.svg?.['@_viewBox']
144
- ?.toString()
145
- .split(' ')
146
- .reduce(
147
- (viewBox: SvgViewBox | undefined, itemStr: string, i: number) => {
148
- if (!viewBox) return {};
149
- const itemNum = parseInt(itemStr, 10);
150
- if (!Number.isFinite(itemNum)) return {};
151
- viewBox[i] = itemNum;
152
- return viewBox;
153
- },
154
- [0, 0, 0, 0],
155
- ) as SvgViewBox;
156
- if (typeof width === 'number' && Number.isFinite(width)) meta.width = width;
157
- if (typeof height === 'number' && Number.isFinite(height)) meta.height = height;
158
- if (viewBox) meta.viewBox = viewBox;
159
- return meta;
160
- } catch (err) {
161
- logger.error(err);
162
- }
163
- return meta;
135
+ export const SimpleImage = createComponent<ComponentProps<typeof SimpleImageComponent>>(
136
+ {
137
+ Component: SimpleImageComponent as any,
138
+ acceptsClassName: true,
139
+ },
140
+ SimpleImageComponent,
141
+ );
142
+
143
+ export interface StaticRequire {
144
+ default: StaticImageData;
164
145
  }
165
146
 
166
- type Width = number;
167
- type Height = number;
168
- export type SvgViewBox = [number, number, Width, Height];
147
+ export type StaticImport = StaticRequire | StaticImageData;
169
148
 
170
- export interface SvgMeta {
171
- height?: number;
172
- viewBox?: SvgViewBox;
173
- width?: number;
174
- }
149
+ export type SimpleImageProps = ComponentProps<typeof SimpleImage>;
@@ -1,2 +1,2 @@
1
- export * from './SimpleImage';
1
+ export * from './SimpleImage/index';
2
2
  export * from './Svg';
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ import { SimpleTabs, TabContent, TabsList, Tab } from './index';
3
+ import { H5, SizableText } from 'tamagui';
4
+
5
+ export default {
6
+ title: 'organize/SimpleTabs',
7
+ component: SimpleTabs,
8
+ parameters: {
9
+ status: {
10
+ type: 'beta',
11
+ },
12
+ },
13
+ };
14
+
15
+ export const horizontalTabs = () => (
16
+ <SimpleTabs defaultRoute="contact" fullScreen>
17
+ <TabsList>
18
+ <Tab path="home">Home</Tab>
19
+ <Tab path="about">About</Tab>
20
+ <Tab path="contact">Contact</Tab>
21
+ <Tab path="description">
22
+ <SizableText textAlign="center">Description</SizableText>
23
+ </Tab>
24
+ </TabsList>
25
+ <TabContent route="home">
26
+ <H5>Home</H5>
27
+ </TabContent>
28
+ <TabContent route="about">
29
+ <H5>About</H5>
30
+ </TabContent>
31
+ <TabContent route="contact">
32
+ <H5>Contact</H5>
33
+ </TabContent>
34
+ <TabContent route="description" jc="center" ai="center">
35
+ <H5>Default</H5>
36
+ </TabContent>
37
+ </SimpleTabs>
38
+ );
39
+
40
+ export const verticalTabs = () => (
41
+ <SimpleTabs defaultRoute="about" orientation="vertical" width="100%" height="100%">
42
+ <TabsList fullHeight={false}>
43
+ <Tab path="home">Home</Tab>
44
+ <Tab path="about">About</Tab>
45
+ <Tab path="contact">Contact</Tab>
46
+ <Tab path="description">
47
+ <SizableText textAlign="center">Description</SizableText>
48
+ </Tab>
49
+ </TabsList>
50
+ <TabContent route="home">
51
+ <H5>Home</H5>
52
+ </TabContent>
53
+ <TabContent route="about">
54
+ <H5>About</H5>
55
+ </TabContent>
56
+ <TabContent route="contact">
57
+ <H5>Contact</H5>
58
+ </TabContent>
59
+ <TabContent route="description" jc="center" ai="center">
60
+ <H5>Default</H5>
61
+ </TabContent>
62
+ </SimpleTabs>
63
+ );