@tamagui/adapt 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/Adapt.js CHANGED
@@ -71,7 +71,7 @@ const Adapt = (0, import_core.withStaticProperties)(
71
71
  (0, import_core.useIsomorphicLayoutEffect)(() => {
72
72
  if (!enabled)
73
73
  return;
74
- context == null ? void 0 : context.setWhen(when);
74
+ context == null ? void 0 : context.setWhen(when || enabled);
75
75
  }, [when, context, enabled]);
76
76
  if (!enabled) {
77
77
  return null;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Adapt.tsx"],
4
- "sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\nexport type AdaptProps = {\n when?: MediaQueryKey\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => any\n}\n\nexport const AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\n// forward props\nexport const AdaptContents = (props: any) => {\n const context = useContext(AdaptParentContext)\n if (!context?.Contents) {\n throw new Error('Adapt not supported by this component')\n }\n return createElement(context.Contents, props)\n}\n\nAdaptContents['shouldForwardSpace'] = true\n\nexport const useAdaptParent = ({\n Contents,\n}: {\n Contents: AdaptParentContextI['Contents']\n}) => {\n const [when, setWhen] = useState<MediaQueryKey | null>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n function AdaptProviderView(props: { children?: any }) {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\n\n return AdaptProviderView\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen(when as MediaQueryKey)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDQ;AAjDR,kBAMO;AACP,mBAA4E;AAcrE,MAAM,yBAAqB,4BAA0C,IAAI;AAGzE,MAAM,gBAAgB,CAAC,UAAe;AAC3C,QAAM,cAAU,yBAAW,kBAAkB;AAC7C,MAAI,EAAC,mCAAS,WAAU;AACtB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACA,aAAO,4BAAc,QAAQ,UAAU,KAAK;AAC9C;AAEA,cAAc,wBAAwB;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,QAAI,uBAA+B,IAAI;AAE3D,QAAM,oBAAgB,sBAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,aAAS,kBAAkB,OAA2B;AACpD,aACE,4CAAC,mBAAmB,UAAnB;AAAA,QAA4B,OAAO;AAAA,QACjC,gBAAM;AAAA,OACT;AAAA,IAEJ;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,YAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,cAAU,yBAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,+CAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
4
+ "sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\ntype MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never\n\nexport type AdaptProps = {\n when?: MediaQueryKeyString\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype When = MediaQueryKeyString | boolean | null\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: When) => any\n}\n\nexport const AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\n// forward props\nexport const AdaptContents = (props: any) => {\n const context = useContext(AdaptParentContext)\n if (!context?.Contents) {\n throw new Error('Adapt not supported by this component')\n }\n return createElement(context.Contents, props)\n}\n\nAdaptContents['shouldForwardSpace'] = true\n\nexport const useAdaptParent = ({\n Contents,\n}: {\n Contents: AdaptParentContextI['Contents']\n}) => {\n const [when, setWhen] = useState<When>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n function AdaptProviderView(props: { children?: any }) {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\n\n return AdaptProviderView\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen((when || enabled) as When)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqDQ;AArDR,kBAMO;AACP,mBAA4E;AAkBrE,MAAM,yBAAqB,4BAA0C,IAAI;AAGzE,MAAM,gBAAgB,CAAC,UAAe;AAC3C,QAAM,cAAU,yBAAW,kBAAkB;AAC7C,MAAI,EAAC,mCAAS,WAAU;AACtB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACA,aAAO,4BAAc,QAAQ,UAAU,KAAK;AAC9C;AAEA,cAAc,wBAAwB;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAe,IAAI;AAE3C,QAAM,oBAAgB,sBAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,aAAS,kBAAkB,OAA2B;AACpD,aACE,4CAAC,mBAAmB,UAAnB;AAAA,QAA4B,OAAO;AAAA,QACjC,gBAAM;AAAA,OACT;AAAA,IAEJ;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,YAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,cAAU,yBAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,+CAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAS,QAAQ;AAAA,IAC5B,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
6
6
  "names": ["Adapt"]
7
7
  }
package/dist/esm/Adapt.js CHANGED
@@ -50,7 +50,7 @@ const Adapt = withStaticProperties(
50
50
  useIsomorphicLayoutEffect(() => {
51
51
  if (!enabled)
52
52
  return;
53
- context == null ? void 0 : context.setWhen(when);
53
+ context == null ? void 0 : context.setWhen(when || enabled);
54
54
  }, [when, context, enabled]);
55
55
  if (!enabled) {
56
56
  return null;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Adapt.tsx"],
4
- "sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\nexport type AdaptProps = {\n when?: MediaQueryKey\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: MediaQueryKey) => any\n}\n\nexport const AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\n// forward props\nexport const AdaptContents = (props: any) => {\n const context = useContext(AdaptParentContext)\n if (!context?.Contents) {\n throw new Error('Adapt not supported by this component')\n }\n return createElement(context.Contents, props)\n}\n\nAdaptContents['shouldForwardSpace'] = true\n\nexport const useAdaptParent = ({\n Contents,\n}: {\n Contents: AdaptParentContextI['Contents']\n}) => {\n const [when, setWhen] = useState<MediaQueryKey | null>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n function AdaptProviderView(props: { children?: any }) {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\n\n return AdaptProviderView\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen(when as MediaQueryKey)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
- "mappings": "AAiDQ;AAjDR;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,eAAe,YAAY,SAAS,gBAAgB;AAcrE,MAAM,qBAAqB,cAA0C,IAAI;AAGzE,MAAM,gBAAgB,CAAC,UAAe;AAC3C,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,EAAC,mCAAS,WAAU;AACtB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACA,SAAO,cAAc,QAAQ,UAAU,KAAK;AAC9C;AAEA,cAAc,wBAAwB;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,IAAI,SAA+B,IAAI;AAE3D,QAAM,gBAAgB,QAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,aAAS,kBAAkB,OAA2B;AACpD,aACE,oBAAC,mBAAmB,UAAnB;AAAA,QAA4B,OAAO;AAAA,QACjC,gBAAM;AAAA,OACT;AAAA,IAEJ;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,QAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,UAAU,WAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,8BAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
4
+ "sourcesContent": ["import {\n MediaQueryKey,\n isTouchable,\n isWeb,\n useIsomorphicLayoutEffect,\n withStaticProperties,\n} from '@tamagui/core'\nimport { createContext, createElement, useContext, useMemo, useState } from 'react'\n\ntype MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never\n\nexport type AdaptProps = {\n when?: MediaQueryKeyString\n platform?: 'native' | 'web' | 'touch'\n children?: any\n}\n\ntype When = MediaQueryKeyString | boolean | null\n\ntype Component = (props: any) => any\ntype AdaptParentContextI = {\n Contents: Component\n setWhen: (when: When) => any\n}\n\nexport const AdaptParentContext = createContext<AdaptParentContextI | null>(null)\n\n// forward props\nexport const AdaptContents = (props: any) => {\n const context = useContext(AdaptParentContext)\n if (!context?.Contents) {\n throw new Error('Adapt not supported by this component')\n }\n return createElement(context.Contents, props)\n}\n\nAdaptContents['shouldForwardSpace'] = true\n\nexport const useAdaptParent = ({\n Contents,\n}: {\n Contents: AdaptParentContextI['Contents']\n}) => {\n const [when, setWhen] = useState<When>(null)\n\n const AdaptProvider = useMemo(() => {\n const context: AdaptParentContextI = {\n Contents,\n setWhen,\n }\n\n function AdaptProviderView(props: { children?: any }) {\n return (\n <AdaptParentContext.Provider value={context}>\n {props.children}\n </AdaptParentContext.Provider>\n )\n }\n\n return AdaptProviderView\n }, [Contents])\n\n return {\n AdaptProvider,\n when,\n }\n}\n\nexport const Adapt = withStaticProperties(\n function Adapt({ platform, when, children }: AdaptProps) {\n const context = useContext(AdaptParentContext)\n\n let enabled = !platform\n if (platform === 'touch') enabled = isTouchable\n if (platform === 'native') enabled = !isWeb\n if (platform === 'web') enabled = isWeb\n\n useIsomorphicLayoutEffect(() => {\n if (!enabled) return\n context?.setWhen((when || enabled) as When)\n }, [when, context, enabled])\n\n if (!enabled) {\n return null\n }\n\n return children\n },\n {\n Contents: AdaptContents,\n }\n)\n"],
5
+ "mappings": "AAqDQ;AArDR;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,eAAe,YAAY,SAAS,gBAAgB;AAkBrE,MAAM,qBAAqB,cAA0C,IAAI;AAGzE,MAAM,gBAAgB,CAAC,UAAe;AAC3C,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,EAAC,mCAAS,WAAU;AACtB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACA,SAAO,cAAc,QAAQ,UAAU,KAAK;AAC9C;AAEA,cAAc,wBAAwB;AAE/B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AACF,MAEM;AACJ,QAAM,CAAC,MAAM,OAAO,IAAI,SAAe,IAAI;AAE3C,QAAM,gBAAgB,QAAQ,MAAM;AAClC,UAAM,UAA+B;AAAA,MACnC;AAAA,MACA;AAAA,IACF;AAEA,aAAS,kBAAkB,OAA2B;AACpD,aACE,oBAAC,mBAAmB,UAAnB;AAAA,QAA4B,OAAO;AAAA,QACjC,gBAAM;AAAA,OACT;AAAA,IAEJ;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,QAAQ;AAAA,EACnB,SAASA,OAAM,EAAE,UAAU,MAAM,SAAS,GAAe;AACvD,UAAM,UAAU,WAAW,kBAAkB;AAE7C,QAAI,UAAU,CAAC;AACf,QAAI,aAAa;AAAS,gBAAU;AACpC,QAAI,aAAa;AAAU,gBAAU,CAAC;AACtC,QAAI,aAAa;AAAO,gBAAU;AAElC,8BAA0B,MAAM;AAC9B,UAAI,CAAC;AAAS;AACd,yCAAS,QAAS,QAAQ;AAAA,IAC5B,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC;AAE3B,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,UAAU;AAAA,EACZ;AACF;",
6
6
  "names": ["Adapt"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/adapt",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -18,10 +18,10 @@
18
18
  "clean:build": "tamagui-build clean:build"
19
19
  },
20
20
  "dependencies": {
21
- "@tamagui/core": "^1.1.0"
21
+ "@tamagui/core": "^1.1.2"
22
22
  },
23
23
  "devDependencies": {
24
- "@tamagui/build": "^1.1.0"
24
+ "@tamagui/build": "^1.1.2"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"
package/src/Adapt.tsx CHANGED
@@ -7,16 +7,20 @@ import {
7
7
  } from '@tamagui/core'
8
8
  import { createContext, createElement, useContext, useMemo, useState } from 'react'
9
9
 
10
+ type MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never
11
+
10
12
  export type AdaptProps = {
11
- when?: MediaQueryKey
13
+ when?: MediaQueryKeyString
12
14
  platform?: 'native' | 'web' | 'touch'
13
15
  children?: any
14
16
  }
15
17
 
18
+ type When = MediaQueryKeyString | boolean | null
19
+
16
20
  type Component = (props: any) => any
17
21
  type AdaptParentContextI = {
18
22
  Contents: Component
19
- setWhen: (when: MediaQueryKey) => any
23
+ setWhen: (when: When) => any
20
24
  }
21
25
 
22
26
  export const AdaptParentContext = createContext<AdaptParentContextI | null>(null)
@@ -37,7 +41,7 @@ export const useAdaptParent = ({
37
41
  }: {
38
42
  Contents: AdaptParentContextI['Contents']
39
43
  }) => {
40
- const [when, setWhen] = useState<MediaQueryKey | null>(null)
44
+ const [when, setWhen] = useState<When>(null)
41
45
 
42
46
  const AdaptProvider = useMemo(() => {
43
47
  const context: AdaptParentContextI = {
@@ -73,7 +77,7 @@ export const Adapt = withStaticProperties(
73
77
 
74
78
  useIsomorphicLayoutEffect(() => {
75
79
  if (!enabled) return
76
- context?.setWhen(when as MediaQueryKey)
80
+ context?.setWhen((when || enabled) as When)
77
81
  }, [when, context, enabled])
78
82
 
79
83
  if (!enabled) {
package/types/Adapt.d.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  /// <reference types="react" />
2
2
  import { MediaQueryKey } from '@tamagui/core';
3
+ type MediaQueryKeyString = MediaQueryKey extends string ? MediaQueryKey : never;
3
4
  export type AdaptProps = {
4
- when?: MediaQueryKey;
5
+ when?: MediaQueryKeyString;
5
6
  platform?: 'native' | 'web' | 'touch';
6
7
  children?: any;
7
8
  };
9
+ type When = MediaQueryKeyString | boolean | null;
8
10
  type Component = (props: any) => any;
9
11
  type AdaptParentContextI = {
10
12
  Contents: Component;
11
- setWhen: (when: MediaQueryKey) => any;
13
+ setWhen: (when: When) => any;
12
14
  };
13
15
  export declare const AdaptParentContext: import("react").Context<AdaptParentContextI | null>;
14
16
  export declare const AdaptContents: {
@@ -21,7 +23,7 @@ export declare const useAdaptParent: ({ Contents, }: {
21
23
  AdaptProvider: (props: {
22
24
  children?: any;
23
25
  }) => JSX.Element;
24
- when: string | number | null;
26
+ when: When;
25
27
  };
26
28
  export declare const Adapt: (({ platform, when, children }: AdaptProps) => any) & {
27
29
  Contents: {