@tamagui/linear-gradient 1.0.4

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 (111) hide show
  1. package/dist/cjs/BubbleSelect.js +44 -0
  2. package/dist/cjs/BubbleSelect.js.map +7 -0
  3. package/dist/cjs/LinearGradient.js +74 -0
  4. package/dist/cjs/LinearGradient.js.map +7 -0
  5. package/dist/cjs/Select.js +480 -0
  6. package/dist/cjs/Select.js.map +7 -0
  7. package/dist/cjs/SelectContent.js +76 -0
  8. package/dist/cjs/SelectContent.js.map +7 -0
  9. package/dist/cjs/SelectContent.native.js +31 -0
  10. package/dist/cjs/SelectContent.native.js.map +7 -0
  11. package/dist/cjs/SelectImpl.js +301 -0
  12. package/dist/cjs/SelectImpl.js.map +7 -0
  13. package/dist/cjs/SelectImpl.native.js +37 -0
  14. package/dist/cjs/SelectImpl.native.js.map +7 -0
  15. package/dist/cjs/SelectScrollButton.js +161 -0
  16. package/dist/cjs/SelectScrollButton.js.map +7 -0
  17. package/dist/cjs/SelectScrollButton.native.js +32 -0
  18. package/dist/cjs/SelectScrollButton.native.js.map +7 -0
  19. package/dist/cjs/SelectViewport.js +126 -0
  20. package/dist/cjs/SelectViewport.js.map +7 -0
  21. package/dist/cjs/SelectViewport.native.js +62 -0
  22. package/dist/cjs/SelectViewport.native.js.map +7 -0
  23. package/dist/cjs/constants.js +47 -0
  24. package/dist/cjs/constants.js.map +7 -0
  25. package/dist/cjs/context.js +49 -0
  26. package/dist/cjs/context.js.map +7 -0
  27. package/dist/cjs/index.js +19 -0
  28. package/dist/cjs/index.js.map +7 -0
  29. package/dist/cjs/linear-gradient.js +29 -0
  30. package/dist/cjs/linear-gradient.js.map +7 -0
  31. package/dist/cjs/types.js +17 -0
  32. package/dist/cjs/types.js.map +7 -0
  33. package/dist/cjs/useSelectBreakpointActive.js +39 -0
  34. package/dist/cjs/useSelectBreakpointActive.js.map +7 -0
  35. package/dist/esm/BubbleSelect.js +25 -0
  36. package/dist/esm/BubbleSelect.js.map +7 -0
  37. package/dist/esm/LinearGradient.js +51 -0
  38. package/dist/esm/LinearGradient.js.map +7 -0
  39. package/dist/esm/Select.js +452 -0
  40. package/dist/esm/Select.js.map +7 -0
  41. package/dist/esm/SelectContent.js +52 -0
  42. package/dist/esm/SelectContent.js.map +7 -0
  43. package/dist/esm/SelectContent.native.js +7 -0
  44. package/dist/esm/SelectContent.native.js.map +7 -0
  45. package/dist/esm/SelectImpl.js +286 -0
  46. package/dist/esm/SelectImpl.js.map +7 -0
  47. package/dist/esm/SelectImpl.native.js +13 -0
  48. package/dist/esm/SelectImpl.native.js.map +7 -0
  49. package/dist/esm/SelectScrollButton.js +130 -0
  50. package/dist/esm/SelectScrollButton.js.map +7 -0
  51. package/dist/esm/SelectScrollButton.native.js +7 -0
  52. package/dist/esm/SelectScrollButton.native.js.map +7 -0
  53. package/dist/esm/SelectViewport.js +95 -0
  54. package/dist/esm/SelectViewport.js.map +7 -0
  55. package/dist/esm/SelectViewport.native.js +32 -0
  56. package/dist/esm/SelectViewport.native.js.map +7 -0
  57. package/dist/esm/constants.js +17 -0
  58. package/dist/esm/constants.js.map +7 -0
  59. package/dist/esm/context.js +21 -0
  60. package/dist/esm/context.js.map +7 -0
  61. package/dist/esm/index.js +2 -0
  62. package/dist/esm/index.js.map +7 -0
  63. package/dist/esm/linear-gradient.js +5 -0
  64. package/dist/esm/linear-gradient.js.map +7 -0
  65. package/dist/esm/types.js +1 -0
  66. package/dist/esm/types.js.map +7 -0
  67. package/dist/esm/useSelectBreakpointActive.js +14 -0
  68. package/dist/esm/useSelectBreakpointActive.js.map +7 -0
  69. package/dist/jsx/BubbleSelect.js +25 -0
  70. package/dist/jsx/BubbleSelect.js.map +7 -0
  71. package/dist/jsx/LinearGradient.js +39 -0
  72. package/dist/jsx/LinearGradient.js.map +7 -0
  73. package/dist/jsx/Select.js +326 -0
  74. package/dist/jsx/Select.js.map +7 -0
  75. package/dist/jsx/SelectContent.js +30 -0
  76. package/dist/jsx/SelectContent.js.map +7 -0
  77. package/dist/jsx/SelectContent.native.js +7 -0
  78. package/dist/jsx/SelectContent.native.js.map +7 -0
  79. package/dist/jsx/SelectImpl.js +259 -0
  80. package/dist/jsx/SelectImpl.js.map +7 -0
  81. package/dist/jsx/SelectImpl.native.js +10 -0
  82. package/dist/jsx/SelectImpl.native.js.map +7 -0
  83. package/dist/jsx/SelectScrollButton.js +103 -0
  84. package/dist/jsx/SelectScrollButton.js.map +7 -0
  85. package/dist/jsx/SelectScrollButton.native.js +7 -0
  86. package/dist/jsx/SelectScrollButton.native.js.map +7 -0
  87. package/dist/jsx/SelectViewport.js +73 -0
  88. package/dist/jsx/SelectViewport.js.map +7 -0
  89. package/dist/jsx/SelectViewport.native.js +18 -0
  90. package/dist/jsx/SelectViewport.native.js.map +7 -0
  91. package/dist/jsx/constants.js +17 -0
  92. package/dist/jsx/constants.js.map +7 -0
  93. package/dist/jsx/context.js +15 -0
  94. package/dist/jsx/context.js.map +7 -0
  95. package/dist/jsx/index.js +2 -0
  96. package/dist/jsx/index.js.map +7 -0
  97. package/dist/jsx/linear-gradient.js +5 -0
  98. package/dist/jsx/linear-gradient.js.map +7 -0
  99. package/dist/jsx/types.js +1 -0
  100. package/dist/jsx/types.js.map +7 -0
  101. package/dist/jsx/useSelectBreakpointActive.js +14 -0
  102. package/dist/jsx/useSelectBreakpointActive.js.map +7 -0
  103. package/package.json +43 -0
  104. package/src/LinearGradient.tsx +64 -0
  105. package/src/index.ts +1 -0
  106. package/src/linear-gradient.d.ts +3 -0
  107. package/src/linear-gradient.d.ts.map +1 -0
  108. package/src/linear-gradient.ts +2 -0
  109. package/types/LinearGradient.d.ts +10 -0
  110. package/types/index.d.ts +2 -0
  111. package/types/linear-gradient.d.ts +3 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/types.tsx"],
4
+ "sourcesContent": ["import type {\n ContextData,\n FloatingContext,\n ReferenceType,\n} from '@floating-ui/react-dom-interactions'\nimport type { SizeTokens } from '@tamagui/core'\nimport type { Scope } from '@tamagui/create-context'\nimport type { ThemeableStackProps, YStackProps } from '@tamagui/stacks'\nimport type {\n DispatchWithoutAction,\n HTMLProps,\n MutableRefObject,\n ReactNode,\n} from 'react'\n\nexport type Direction = 'ltr' | 'rtl'\n\nexport type ScopedProps<P> = P & { __scopeSelect?: Scope }\n\nexport type SelectImplProps = ScopedProps<SelectProps> & {\n activeIndexRef: any\n selectedIndexRef: any\n listContentRef: any\n}\n\nexport interface SelectProps {\n id?: string\n children?: ReactNode\n value?: string\n defaultValue?: string\n onValueChange?(value: string): void\n open?: boolean\n defaultOpen?: boolean\n onOpenChange?(open: boolean): void\n dir?: Direction\n name?: string\n autoComplete?: string\n size?: SizeTokens\n}\n\nexport interface SelectContextValue {\n dir?: Direction\n scopeKey: string\n sheetBreakpoint: any\n size?: SizeTokens\n value: any\n selectedItem: ReactNode\n setSelectedItem: (item: ReactNode) => void\n selectedIndex: number\n setSelectedIndex: (index: number) => void\n activeIndex: number | null\n setActiveIndex: (index: number | null) => void\n setValueAtIndex: (index: number, value: string) => void\n open: boolean\n setOpen: (open: boolean) => void\n onChange: (value: string) => void\n valueNode: Element | null\n onValueNodeChange(node: HTMLElement): void\n valueNodeHasChildren: boolean\n onValueNodeHasChildrenChange(hasChildren: boolean): void\n forceUpdate: DispatchWithoutAction\n\n // SheetImpl only:\n isInSheet?: boolean\n\n // InlineImpl only:\n fallback: boolean\n blockSelection: boolean\n allowSelectRef?: MutableRefObject<boolean>\n allowMouseUpRef?: MutableRefObject<boolean>\n upArrowRef?: MutableRefObject<HTMLDivElement | null>\n downArrowRef?: MutableRefObject<HTMLDivElement | null>\n selectTimeoutRef?: MutableRefObject<any>\n setScrollTop?: Function\n setInnerOffset?: Function\n dataRef?: MutableRefObject<ContextData>\n controlledScrolling?: boolean\n listRef?: MutableRefObject<Array<HTMLElement | null>>\n floatingRef?: MutableRefObject<HTMLElement | null>\n canScrollUp?: boolean\n canScrollDown?: boolean\n floatingContext?: FloatingContext<ReferenceType>\n interactions?: {\n getReferenceProps: (userProps?: HTMLProps<Element> | undefined) => any\n getFloatingProps: (userProps?: HTMLProps<HTMLElement> | undefined) => any\n getItemProps: (userProps?: HTMLProps<HTMLElement> | undefined) => any\n }\n}\n\nexport type SelectViewportProps = ThemeableStackProps & {\n size?: SizeTokens\n}\n\nexport type SelectContentProps = ScopedProps<{\n children?: React.ReactNode\n zIndex?: number\n}>\n\nexport interface SelectScrollButtonImplProps extends YStackProps {\n dir: 'up' | 'down'\n componentName: string\n}\n\nexport interface SelectScrollButtonProps\n extends Omit<SelectScrollButtonImplProps, 'dir' | 'componentName'> {}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useSelectBreakpointActive_exports = {};
20
+ __export(useSelectBreakpointActive_exports, {
21
+ useSelectBreakpointActive: () => useSelectBreakpointActive,
22
+ useShowSelectSheet: () => useShowSelectSheet
23
+ });
24
+ module.exports = __toCommonJS(useSelectBreakpointActive_exports);
25
+ var import_core = require("@tamagui/core");
26
+ const useSelectBreakpointActive = (sheetBreakpoint) => {
27
+ const media = (0, import_core.useMedia)();
28
+ return sheetBreakpoint ? media[sheetBreakpoint] : false;
29
+ };
30
+ const useShowSelectSheet = (context) => {
31
+ const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
32
+ return context.open === false ? false : breakpointActive;
33
+ };
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ useSelectBreakpointActive,
37
+ useShowSelectSheet
38
+ });
39
+ //# sourceMappingURL=useSelectBreakpointActive.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/useSelectBreakpointActive.tsx"],
4
+ "sourcesContent": ["import { useMedia } from '@tamagui/core'\n\nimport { SelectContextValue } from './types'\n\nexport const useSelectBreakpointActive = (\n sheetBreakpoint: SelectContextValue['sheetBreakpoint'],\n) => {\n const media = useMedia()\n return sheetBreakpoint ? media[sheetBreakpoint] : false\n}\n\nexport const useShowSelectSheet = (context: SelectContextValue) => {\n const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint)\n return context.open === false ? false : breakpointActive\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AAIlB,MAAM,4BAA4B,CACvC,oBACG;AACH,QAAM,YAAQ,sBAAS;AACvB,SAAO,kBAAkB,MAAM,mBAAmB;AACpD;AAEO,MAAM,qBAAqB,CAAC,YAAgC;AACjE,QAAM,mBAAmB,0BAA0B,QAAQ,eAAe;AAC1E,SAAO,QAAQ,SAAS,QAAQ,QAAQ;AAC1C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,25 @@
1
+ import { usePrevious } from "@radix-ui/react-use-previous";
2
+ import { useComposedRefs } from "@tamagui/compose-refs";
3
+ import * as React from "react";
4
+ const BubbleSelect = React.forwardRef((props, forwardedRef) => {
5
+ const { value, ...selectProps } = props;
6
+ const ref = React.useRef(null);
7
+ const composedRefs = useComposedRefs(forwardedRef, ref);
8
+ const prevValue = usePrevious(value);
9
+ React.useEffect(() => {
10
+ const select = ref.current;
11
+ const selectProto = window.HTMLSelectElement.prototype;
12
+ const descriptor = Object.getOwnPropertyDescriptor(
13
+ selectProto,
14
+ "value"
15
+ );
16
+ const setValue = descriptor.set;
17
+ if (prevValue !== value && setValue) {
18
+ const event = new Event("change", { bubbles: true });
19
+ setValue.call(select, value);
20
+ select.dispatchEvent(event);
21
+ }
22
+ }, [prevValue, value]);
23
+ return null;
24
+ });
25
+ //# sourceMappingURL=BubbleSelect.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/BubbleSelect.tsx"],
4
+ "sourcesContent": ["import { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport * as React from 'react'\n\n/* -----------------------------------------------------------------------------------------------*/\nconst BubbleSelect = React.forwardRef<\n HTMLSelectElement,\n React.ComponentPropsWithoutRef<'select'>\n>((props, forwardedRef) => {\n const { value, ...selectProps } = props\n const ref = React.useRef<HTMLSelectElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const prevValue = usePrevious(value)\n\n // Bubble value change to parents (e.g form change event)\n React.useEffect(() => {\n const select = ref.current!\n const selectProto = window.HTMLSelectElement.prototype\n const descriptor = Object.getOwnPropertyDescriptor(\n selectProto,\n 'value',\n ) as PropertyDescriptor\n const setValue = descriptor.set\n if (prevValue !== value && setValue) {\n const event = new Event('change', { bubbles: true })\n setValue.call(select, value)\n select.dispatchEvent(event)\n }\n }, [prevValue, value])\n\n /**\n * We purposefully use a `select` here to support form autofill as much\n * as possible.\n *\n * We purposefully do not add the `value` attribute here to allow the value\n * to be set programatically and bubble to any parent form `onChange` event.\n * Adding the `value` will cause React to consider the programatic\n * dispatch a duplicate and it will get swallowed.\n *\n * We use `VisuallyHidden` rather than `display: \"none\"` because Safari autofill\n * won't work otherwise.\n */\n // TODO\n return null\n // return (\n // <VisuallyHidden asChild>\n // <select {...selectProps} ref={composedRefs} defaultValue={value} />\n // </VisuallyHidden>\n // )\n})\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAGvB,MAAM,eAAe,MAAM,WAGzB,CAAC,OAAO,iBAAiB;AACzB,QAAM,EAAE,UAAU,YAAY,IAAI;AAClC,QAAM,MAAM,MAAM,OAA0B,IAAI;AAChD,QAAM,eAAe,gBAAgB,cAAc,GAAG;AACtD,QAAM,YAAY,YAAY,KAAK;AAGnC,QAAM,UAAU,MAAM;AACpB,UAAM,SAAS,IAAI;AACnB,UAAM,cAAc,OAAO,kBAAkB;AAC7C,UAAM,aAAa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF;AACA,UAAM,WAAW,WAAW;AAC5B,QAAI,cAAc,SAAS,UAAU;AACnC,YAAM,QAAQ,IAAI,MAAM,UAAU,EAAE,SAAS,KAAK,CAAC;AACnD,eAAS,KAAK,QAAQ,KAAK;AAC3B,aAAO,cAAc,KAAK;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,WAAW,KAAK,CAAC;AAerB,SAAO;AAMT,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,51 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import {
3
+ getVariable,
4
+ styled,
5
+ themeable,
6
+ useTheme
7
+ } from "@tamagui/core";
8
+ import { YStack } from "@tamagui/stacks";
9
+ import * as React from "react";
10
+ import { StyleSheet } from "react-native";
11
+ import {
12
+ LinearGradient as ExpoLinearGradient
13
+ } from "./linear-gradient";
14
+ const LinearGradient = YStack.extractable(
15
+ themeable(
16
+ React.forwardRef((props, ref) => {
17
+ const { start, end, colors: colorsProp, locations, children, ...stackProps } = props;
18
+ const colors = useThemeColors(colorsProp || []);
19
+ return /* @__PURE__ */ jsx(LinearGradientFrame, {
20
+ ref,
21
+ ...stackProps,
22
+ children: /* @__PURE__ */ jsx(ExpoLinearGradient, {
23
+ start,
24
+ end,
25
+ colors,
26
+ locations,
27
+ style: StyleSheet.absoluteFill,
28
+ children
29
+ })
30
+ });
31
+ })
32
+ )
33
+ );
34
+ const LinearGradientFrame = styled(YStack, {
35
+ name: "LinearGradient",
36
+ overflow: "hidden",
37
+ position: "relative"
38
+ });
39
+ const useThemeColors = (colors) => {
40
+ const theme = useTheme();
41
+ return colors.map((color) => {
42
+ if (color[0] === "$") {
43
+ return getVariable(theme[color] || color);
44
+ }
45
+ return color;
46
+ });
47
+ };
48
+ export {
49
+ LinearGradient
50
+ };
51
+ //# sourceMappingURL=LinearGradient.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/LinearGradient.tsx"],
4
+ "sourcesContent": ["import {\n ColorTokens,\n ThemeTokens,\n getVariable,\n styled,\n themeable,\n useTheme,\n} from '@tamagui/core'\nimport { YStack, YStackProps } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { StyleSheet, View } from 'react-native'\n\nimport {\n LinearGradient as ExpoLinearGradient,\n LinearGradientProps as ExpoLinearGradientProps,\n} from './linear-gradient'\n\n//\nexport type LinearGradientProps = Omit<ExpoLinearGradientProps, 'colors'> &\n Omit<YStackProps, 'children' | keyof ExpoLinearGradientProps> & {\n colors?: (ColorTokens | ThemeTokens | (string & {}))[]\n }\n\nexport const LinearGradient: React.ForwardRefExoticComponent<\n LinearGradientProps & React.RefAttributes<HTMLElement | View>\n> = YStack.extractable(\n themeable(\n React.forwardRef((props: LinearGradientProps, ref) => {\n const { start, end, colors: colorsProp, locations, children, ...stackProps } = props\n const colors = useThemeColors(colorsProp || [])\n return (\n // @ts-ignore\n <LinearGradientFrame ref={ref} {...stackProps}>\n <ExpoLinearGradient\n start={start}\n end={end}\n colors={colors}\n locations={locations}\n style={StyleSheet.absoluteFill}\n >\n {children}\n </ExpoLinearGradient>\n </LinearGradientFrame>\n )\n })\n )\n) as any\n\nconst LinearGradientFrame = styled(YStack, {\n name: 'LinearGradient',\n overflow: 'hidden',\n position: 'relative',\n})\n\n// resolve tamagui theme values\nconst useThemeColors = (colors: string[]) => {\n const theme = useTheme()\n return colors.map((color) => {\n if (color[0] === '$') {\n return getVariable(theme[color] || color)\n }\n return color\n })\n}\n"],
5
+ "mappings": "AAiCU;AAjCV;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAA2B;AACpC,YAAY,WAAW;AACvB,SAAS,kBAAwB;AAEjC;AAAA,EACE,kBAAkB;AAAA,OAEb;AAQA,MAAM,iBAET,OAAO;AAAA,EACT;AAAA,IACE,MAAM,WAAW,CAAC,OAA4B,QAAQ;AACpD,YAAM,EAAE,OAAO,KAAK,QAAQ,YAAY,WAAW,aAAa,WAAW,IAAI;AAC/E,YAAM,SAAS,eAAe,cAAc,CAAC,CAAC;AAC9C,aAEE,oBAAC;AAAA,QAAoB;AAAA,QAAW,GAAG;AAAA,QACjC,8BAAC;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,OAAO,WAAW;AAAA,UAEjB;AAAA,SACH;AAAA,OACF;AAAA,IAEJ,CAAC;AAAA,EACH;AACF;AAEA,MAAM,sBAAsB,OAAO,QAAQ;AAAA,EACzC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AACZ,CAAC;AAGD,MAAM,iBAAiB,CAAC,WAAqB;AAC3C,QAAM,QAAQ,SAAS;AACvB,SAAO,OAAO,IAAI,CAAC,UAAU;AAC3B,QAAI,MAAM,OAAO,KAAK;AACpB,aAAO,YAAY,MAAM,UAAU,KAAK;AAAA,IAC1C;AACA,WAAO;AAAA,EACT,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -0,0 +1,452 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { Adapt, useAdaptParent } from "@tamagui/adapt";
3
+ import { useComposedRefs } from "@tamagui/compose-refs";
4
+ import { isWeb } from "@tamagui/core";
5
+ import {
6
+ styled,
7
+ useGet,
8
+ useIsomorphicLayoutEffect,
9
+ withStaticProperties
10
+ } from "@tamagui/core";
11
+ import { useId } from "@tamagui/core";
12
+ import { ListItem } from "@tamagui/list-item";
13
+ import { PortalHost } from "@tamagui/portal";
14
+ import { Separator } from "@tamagui/separator";
15
+ import { ControlledSheet, SheetController } from "@tamagui/sheet";
16
+ import { XStack, YStack } from "@tamagui/stacks";
17
+ import { Paragraph, SizableText } from "@tamagui/text";
18
+ import { useControllableState } from "@tamagui/use-controllable-state";
19
+ import * as React from "react";
20
+ import { SELECT_NAME } from "./constants";
21
+ import { SelectProvider, createSelectContext, useSelectContext } from "./context";
22
+ import { SelectContent } from "./SelectContent";
23
+ import { SelectInlineImpl } from "./SelectImpl";
24
+ import { SelectScrollDownButton, SelectScrollUpButton } from "./SelectScrollButton";
25
+ import { SelectViewport } from "./SelectViewport";
26
+ import {
27
+ useSelectBreakpointActive,
28
+ useShowSelectSheet
29
+ } from "./useSelectBreakpointActive";
30
+ const TRIGGER_NAME = "SelectTrigger";
31
+ const SelectTrigger = React.forwardRef(
32
+ (props, forwardedRef) => {
33
+ const {
34
+ __scopeSelect,
35
+ disabled = false,
36
+ "aria-labelledby": ariaLabelledby,
37
+ ...triggerProps
38
+ } = props;
39
+ const context = useSelectContext(TRIGGER_NAME, __scopeSelect);
40
+ const labelledBy = ariaLabelledby;
41
+ return /* @__PURE__ */ jsx(ListItem, {
42
+ componentName: TRIGGER_NAME,
43
+ backgrounded: true,
44
+ radiused: true,
45
+ hoverTheme: true,
46
+ pressTheme: true,
47
+ focusTheme: true,
48
+ focusable: true,
49
+ borderWidth: 1,
50
+ size: context.size,
51
+ "aria-expanded": context.open,
52
+ "aria-autocomplete": "none",
53
+ "aria-labelledby": labelledBy,
54
+ dir: context.dir,
55
+ disabled,
56
+ "data-disabled": disabled ? "" : void 0,
57
+ ...triggerProps,
58
+ ref: forwardedRef,
59
+ ...process.env.TAMAGUI_TARGET === "web" && context.interactions ? context.interactions.getReferenceProps() : {
60
+ onPress() {
61
+ context.setOpen(!context.open);
62
+ }
63
+ }
64
+ });
65
+ }
66
+ );
67
+ SelectTrigger.displayName = TRIGGER_NAME;
68
+ const VALUE_NAME = "SelectValue";
69
+ const SelectValueFrame = styled(Paragraph, {
70
+ name: VALUE_NAME,
71
+ selectable: false
72
+ });
73
+ const SelectValue = SelectValueFrame.extractable(
74
+ React.forwardRef(
75
+ ({
76
+ __scopeSelect,
77
+ children: childrenProp,
78
+ placeholder
79
+ }, forwardedRef) => {
80
+ const context = useSelectContext(VALUE_NAME, __scopeSelect);
81
+ const { onValueNodeHasChildrenChange } = context;
82
+ const composedRefs = useComposedRefs(forwardedRef, context.onValueNodeChange);
83
+ const children = childrenProp ?? context.selectedItem;
84
+ const hasChildren = !!children;
85
+ const selectValueChildren = context.value === void 0 && placeholder !== void 0 ? placeholder : children;
86
+ useIsomorphicLayoutEffect(() => {
87
+ onValueNodeHasChildrenChange(hasChildren);
88
+ }, [onValueNodeHasChildrenChange, hasChildren]);
89
+ return /* @__PURE__ */ jsx(SelectValueFrame, {
90
+ size: context.size,
91
+ ref: composedRefs,
92
+ pointerEvents: "none",
93
+ children: selectValueChildren
94
+ });
95
+ }
96
+ )
97
+ );
98
+ SelectValue.displayName = VALUE_NAME;
99
+ const SelectIcon = styled(XStack, {
100
+ name: "SelectIcon",
101
+ "aria-hidden": true,
102
+ children: /* @__PURE__ */ jsx(Paragraph, {
103
+ children: "\u25BC"
104
+ })
105
+ });
106
+ const ITEM_NAME = "SelectItem";
107
+ const [SelectItemContextProvider, useSelectItemContext] = createSelectContext(ITEM_NAME);
108
+ const SelectItem = React.forwardRef(
109
+ (props, forwardedRef) => {
110
+ const {
111
+ __scopeSelect,
112
+ value,
113
+ disabled = false,
114
+ textValue: textValueProp,
115
+ index,
116
+ ...itemProps
117
+ } = props;
118
+ const context = useSelectContext(ITEM_NAME, __scopeSelect);
119
+ const isSelected = context.value === value;
120
+ const textId = useId();
121
+ const {
122
+ selectedIndex,
123
+ setSelectedIndex,
124
+ listRef,
125
+ open,
126
+ setOpen,
127
+ onChange,
128
+ setActiveIndex,
129
+ allowMouseUpRef,
130
+ allowSelectRef,
131
+ setValueAtIndex,
132
+ selectTimeoutRef,
133
+ dataRef
134
+ } = context;
135
+ const composedRefs = useComposedRefs(forwardedRef, (node) => {
136
+ if (!isWeb)
137
+ return;
138
+ if (node instanceof HTMLElement) {
139
+ if (listRef) {
140
+ listRef.current[index] = node;
141
+ }
142
+ }
143
+ });
144
+ React.useEffect(() => {
145
+ setValueAtIndex(index, value);
146
+ }, [index, setValueAtIndex, value]);
147
+ function handleSelect() {
148
+ setSelectedIndex(index);
149
+ onChange(value);
150
+ setOpen(false);
151
+ }
152
+ const selectItemProps = context.interactions ? context.interactions.getItemProps({
153
+ onTouchStart() {
154
+ allowSelectRef.current = true;
155
+ allowMouseUpRef.current = false;
156
+ },
157
+ onKeyDown(event) {
158
+ if (event.key === "Enter" || event.key === " " && !(dataRef == null ? void 0 : dataRef.current.typing)) {
159
+ event.preventDefault();
160
+ handleSelect();
161
+ } else {
162
+ allowSelectRef.current = true;
163
+ }
164
+ },
165
+ onClick() {
166
+ if (allowSelectRef.current) {
167
+ setSelectedIndex(index);
168
+ setOpen(false);
169
+ }
170
+ },
171
+ onMouseUp() {
172
+ if (!allowMouseUpRef.current) {
173
+ return;
174
+ }
175
+ if (allowSelectRef.current) {
176
+ handleSelect();
177
+ }
178
+ clearTimeout(selectTimeoutRef.current);
179
+ selectTimeoutRef.current = setTimeout(() => {
180
+ allowSelectRef.current = true;
181
+ });
182
+ }
183
+ }) : {
184
+ onPress: handleSelect
185
+ };
186
+ return /* @__PURE__ */ jsx(SelectItemContextProvider, {
187
+ scope: __scopeSelect,
188
+ value,
189
+ textId: textId || "",
190
+ isSelected,
191
+ children: /* @__PURE__ */ jsx(ListItem, {
192
+ backgrounded: true,
193
+ pressTheme: true,
194
+ cursor: "",
195
+ focusTheme: true,
196
+ outlineWidth: 0,
197
+ componentName: ITEM_NAME,
198
+ ref: composedRefs,
199
+ "aria-labelledby": textId,
200
+ "aria-selected": isSelected,
201
+ "data-state": isSelected ? "active" : "inactive",
202
+ "aria-disabled": disabled || void 0,
203
+ "data-disabled": disabled ? "" : void 0,
204
+ tabIndex: disabled ? void 0 : -1,
205
+ size: context.size,
206
+ ...itemProps,
207
+ ...selectItemProps
208
+ })
209
+ });
210
+ }
211
+ );
212
+ SelectItem.displayName = ITEM_NAME;
213
+ const ITEM_TEXT_NAME = "SelectItemText";
214
+ const SelectItemTextFrame = styled(SizableText, {
215
+ name: ITEM_TEXT_NAME,
216
+ selectable: false
217
+ });
218
+ const SelectItemText = React.forwardRef(
219
+ (props, forwardedRef) => {
220
+ const { __scopeSelect, className, ...itemTextProps } = props;
221
+ const context = useSelectContext(ITEM_TEXT_NAME, __scopeSelect);
222
+ const itemContext = useSelectItemContext(ITEM_TEXT_NAME, __scopeSelect);
223
+ const ref = React.useRef(null);
224
+ const composedRefs = useComposedRefs(forwardedRef, ref);
225
+ const isSelected = Boolean(itemContext.isSelected && context.valueNode);
226
+ const contents = React.useMemo(
227
+ () => /* @__PURE__ */ jsx(SelectItemTextFrame, {
228
+ className,
229
+ size: context.size,
230
+ id: itemContext.textId,
231
+ ...itemTextProps,
232
+ ref: composedRefs
233
+ }),
234
+ [props, context.size, className, itemContext.textId]
235
+ );
236
+ React.useEffect(() => {
237
+ if (isSelected) {
238
+ context.setSelectedItem(contents);
239
+ }
240
+ }, [isSelected, contents]);
241
+ return /* @__PURE__ */ jsx(Fragment, {
242
+ children: contents
243
+ });
244
+ }
245
+ );
246
+ SelectItemText.displayName = ITEM_TEXT_NAME;
247
+ const ITEM_INDICATOR_NAME = "SelectItemIndicator";
248
+ const SelectItemIndicatorFrame = styled(XStack, {
249
+ name: ITEM_TEXT_NAME
250
+ });
251
+ const SelectItemIndicator = React.forwardRef(
252
+ (props, forwardedRef) => {
253
+ const { __scopeSelect, ...itemIndicatorProps } = props;
254
+ const itemContext = useSelectItemContext(ITEM_INDICATOR_NAME, __scopeSelect);
255
+ return itemContext.isSelected ? /* @__PURE__ */ jsx(SelectItemIndicatorFrame, {
256
+ "aria-hidden": true,
257
+ ...itemIndicatorProps,
258
+ ref: forwardedRef
259
+ }) : null;
260
+ }
261
+ );
262
+ SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
263
+ const GROUP_NAME = "SelectGroup";
264
+ const [SelectGroupContextProvider, useSelectGroupContext] = createSelectContext(GROUP_NAME);
265
+ const SelectGroupFrame = styled(YStack, {
266
+ name: GROUP_NAME,
267
+ width: "100%"
268
+ });
269
+ const SelectGroup = React.forwardRef(
270
+ (props, forwardedRef) => {
271
+ const { __scopeSelect, ...groupProps } = props;
272
+ const groupId = useId();
273
+ return /* @__PURE__ */ jsx(SelectGroupContextProvider, {
274
+ scope: __scopeSelect,
275
+ id: groupId || "",
276
+ children: /* @__PURE__ */ jsx(SelectGroupFrame, {
277
+ role: "group",
278
+ "aria-labelledby": groupId,
279
+ ...groupProps,
280
+ ref: forwardedRef
281
+ })
282
+ });
283
+ }
284
+ );
285
+ SelectGroup.displayName = GROUP_NAME;
286
+ const LABEL_NAME = "SelectLabel";
287
+ const SelectLabel = React.forwardRef(
288
+ (props, forwardedRef) => {
289
+ const { __scopeSelect, ...labelProps } = props;
290
+ const context = useSelectContext(LABEL_NAME, __scopeSelect);
291
+ const groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
292
+ return /* @__PURE__ */ jsx(ListItem, {
293
+ componentName: LABEL_NAME,
294
+ fontWeight: "800",
295
+ id: groupContext.id,
296
+ size: context.size,
297
+ ...labelProps,
298
+ ref: forwardedRef
299
+ });
300
+ }
301
+ );
302
+ SelectLabel.displayName = LABEL_NAME;
303
+ const SelectSeparator = styled(Separator, {
304
+ name: "SelectSeparator"
305
+ });
306
+ const SelectSheetController = (props) => {
307
+ const context = useSelectContext("SelectSheetController", props.__scopeSelect);
308
+ const showSheet = useShowSelectSheet(context);
309
+ const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint);
310
+ const getShowSheet = useGet(showSheet);
311
+ return /* @__PURE__ */ jsx(SheetController, {
312
+ onOpenChange: (val) => {
313
+ if (getShowSheet()) {
314
+ props.onOpenChange(val);
315
+ }
316
+ },
317
+ open: context.open,
318
+ hidden: breakpointActive === false,
319
+ children: props.children
320
+ });
321
+ };
322
+ const SelectSheetImpl = (props) => {
323
+ return /* @__PURE__ */ jsx(Fragment, {
324
+ children: props.children
325
+ });
326
+ };
327
+ const Select = withStaticProperties(
328
+ (props) => {
329
+ const {
330
+ __scopeSelect,
331
+ children,
332
+ open: openProp,
333
+ defaultOpen,
334
+ onOpenChange,
335
+ value: valueProp,
336
+ defaultValue,
337
+ onValueChange,
338
+ size: sizeProp = "$4",
339
+ dir
340
+ } = props;
341
+ const id = useId();
342
+ const scopeKey = __scopeSelect ? Object.keys(__scopeSelect)[0] ?? id : id;
343
+ const { when, AdaptProvider } = useAdaptParent({
344
+ Contents: React.useCallback(
345
+ () => /* @__PURE__ */ jsx(PortalHost, {
346
+ name: `${scopeKey}SheetContents`
347
+ }),
348
+ [scopeKey]
349
+ )
350
+ });
351
+ const sheetBreakpoint = when;
352
+ const isSheet = useSelectBreakpointActive(sheetBreakpoint);
353
+ const SelectImpl = isSheet || !isWeb ? SelectSheetImpl : SelectInlineImpl;
354
+ const forceUpdate = React.useReducer(() => ({}), {})[1];
355
+ const [selectedItem, setSelectedItem] = React.useState(null);
356
+ const [open, setOpen] = useControllableState({
357
+ prop: openProp,
358
+ defaultProp: defaultOpen || false,
359
+ onChange: onOpenChange,
360
+ strategy: "most-recent-wins"
361
+ });
362
+ const [value, setValue] = useControllableState({
363
+ prop: valueProp,
364
+ defaultProp: defaultValue || "",
365
+ onChange: onValueChange,
366
+ strategy: "most-recent-wins",
367
+ transition: true
368
+ });
369
+ const [activeIndex, setActiveIndex] = React.useState(null);
370
+ const selectedIndexRef = React.useRef(null);
371
+ const activeIndexRef = React.useRef(null);
372
+ const listContentRef = React.useRef([]);
373
+ const [selectedIndex, setSelectedIndex] = React.useState(
374
+ Math.max(0, listContentRef.current.indexOf(value))
375
+ );
376
+ const [valueNode, setValueNode] = React.useState(null);
377
+ const [valueNodeHasChildren, setValueNodeHasChildren] = React.useState(false);
378
+ useIsomorphicLayoutEffect(() => {
379
+ selectedIndexRef.current = selectedIndex;
380
+ activeIndexRef.current = activeIndex;
381
+ });
382
+ return /* @__PURE__ */ jsx(AdaptProvider, {
383
+ children: /* @__PURE__ */ jsx(SelectProvider, {
384
+ dir,
385
+ blockSelection: false,
386
+ size: sizeProp,
387
+ fallback: false,
388
+ selectedItem,
389
+ setSelectedItem,
390
+ forceUpdate,
391
+ valueNode,
392
+ onValueNodeChange: setValueNode,
393
+ onValueNodeHasChildrenChange: setValueNodeHasChildren,
394
+ valueNodeHasChildren,
395
+ scopeKey,
396
+ sheetBreakpoint,
397
+ scope: __scopeSelect,
398
+ setValueAtIndex: (index, value2) => {
399
+ listContentRef.current[index] = value2;
400
+ },
401
+ activeIndex,
402
+ onChange: setValue,
403
+ selectedIndex,
404
+ setActiveIndex,
405
+ setOpen,
406
+ setSelectedIndex,
407
+ value,
408
+ open,
409
+ children: /* @__PURE__ */ jsx(SelectSheetController, {
410
+ onOpenChange: setOpen,
411
+ __scopeSelect,
412
+ children: /* @__PURE__ */ jsx(SelectImpl, {
413
+ activeIndexRef,
414
+ listContentRef,
415
+ selectedIndexRef,
416
+ ...props,
417
+ open,
418
+ value,
419
+ children
420
+ })
421
+ })
422
+ })
423
+ });
424
+ },
425
+ {
426
+ Adapt,
427
+ Content: SelectContent,
428
+ Group: SelectGroup,
429
+ Icon: SelectIcon,
430
+ Item: SelectItem,
431
+ ItemIndicator: SelectItemIndicator,
432
+ ItemText: SelectItemText,
433
+ Label: SelectLabel,
434
+ ScrollDownButton: SelectScrollDownButton,
435
+ ScrollUpButton: SelectScrollUpButton,
436
+ Trigger: SelectTrigger,
437
+ Value: SelectValue,
438
+ Viewport: SelectViewport,
439
+ Sheet: ControlledSheet
440
+ }
441
+ );
442
+ Select.displayName = SELECT_NAME;
443
+ export {
444
+ Select,
445
+ SelectGroupFrame,
446
+ SelectIcon,
447
+ SelectItem,
448
+ SelectItemTextFrame,
449
+ SelectSeparator,
450
+ SelectTrigger
451
+ };
452
+ //# sourceMappingURL=Select.js.map