@tamagui/select 1.0.1-beta.113 → 1.0.1-beta.116
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/Select.js +61 -567
- package/dist/cjs/Select.js.map +2 -2
- package/dist/cjs/SelectContent.js +53 -0
- package/dist/cjs/SelectContent.js.map +7 -0
- package/dist/cjs/SelectContent.native.js +31 -0
- package/dist/cjs/SelectContent.native.js.map +7 -0
- package/dist/cjs/SelectImpl.js +393 -0
- package/dist/cjs/SelectImpl.js.map +7 -0
- package/dist/cjs/SelectScrollButton.js +128 -0
- package/dist/cjs/SelectScrollButton.js.map +7 -0
- package/dist/cjs/SelectScrollButton.native.js +32 -0
- package/dist/cjs/SelectScrollButton.native.js.map +7 -0
- package/dist/cjs/SelectViewport.js +96 -0
- package/dist/cjs/SelectViewport.js.map +7 -0
- package/dist/cjs/SelectViewport.native.js +43 -0
- package/dist/cjs/SelectViewport.native.js.map +7 -0
- package/dist/cjs/constants.js +47 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/context.js +38 -0
- package/dist/cjs/context.js.map +7 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/esm/Select.js +44 -574
- package/dist/esm/Select.js.map +2 -2
- package/dist/esm/SelectContent.js +26 -0
- package/dist/esm/SelectContent.js.map +7 -0
- package/dist/esm/SelectContent.native.js +7 -0
- package/dist/esm/SelectContent.native.js.map +7 -0
- package/dist/esm/SelectImpl.js +378 -0
- package/dist/esm/SelectImpl.js.map +7 -0
- package/dist/esm/SelectScrollButton.js +100 -0
- package/dist/esm/SelectScrollButton.js.map +7 -0
- package/dist/esm/SelectScrollButton.native.js +7 -0
- package/dist/esm/SelectScrollButton.native.js.map +7 -0
- package/dist/esm/SelectViewport.js +68 -0
- package/dist/esm/SelectViewport.js.map +7 -0
- package/dist/esm/SelectViewport.native.js +16 -0
- package/dist/esm/SelectViewport.native.js.map +7 -0
- package/dist/esm/constants.js +17 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/context.js +11 -0
- package/dist/esm/context.js.map +7 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/jsx/Select.js +43 -516
- package/dist/jsx/Select.js.map +2 -2
- package/dist/jsx/SelectContent.js +19 -0
- package/dist/jsx/SelectContent.js.map +7 -0
- package/dist/jsx/SelectContent.native.js +7 -0
- package/dist/jsx/SelectContent.native.js.map +7 -0
- package/dist/jsx/SelectImpl.js +366 -0
- package/dist/jsx/SelectImpl.js.map +7 -0
- package/dist/jsx/SelectScrollButton.js +78 -0
- package/dist/jsx/SelectScrollButton.js.map +7 -0
- package/dist/jsx/SelectScrollButton.native.js +7 -0
- package/dist/jsx/SelectScrollButton.native.js.map +7 -0
- package/dist/jsx/SelectViewport.js +57 -0
- package/dist/jsx/SelectViewport.js.map +7 -0
- package/dist/jsx/SelectViewport.native.js +14 -0
- package/dist/jsx/SelectViewport.native.js.map +7 -0
- package/dist/jsx/constants.js +17 -0
- package/dist/jsx/constants.js.map +7 -0
- package/dist/jsx/context.js +11 -0
- package/dist/jsx/context.js.map +7 -0
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/index.js.map +2 -2
- package/dist/jsx/types.js +1 -0
- package/dist/jsx/types.js.map +7 -0
- package/package.json +12 -12
- package/src/Select.tsx +69 -890
- package/src/SelectContent.native.tsx +5 -0
- package/src/SelectContent.tsx +34 -0
- package/src/SelectImpl.tsx +511 -0
- package/src/SelectScrollButton.native.tsx +7 -0
- package/src/SelectScrollButton.tsx +150 -0
- package/src/SelectViewport.native.tsx +17 -0
- package/src/SelectViewport.tsx +86 -0
- package/src/constants.tsx +7 -0
- package/src/context.tsx +9 -0
- package/src/index.tsx +7 -0
- package/src/types.tsx +83 -0
- package/types/Select.d.ts +83 -241
- package/types/Select.d.ts.map +1 -1
- package/types/SelectContent.d.ts +4 -0
- package/types/SelectContent.d.ts.map +1 -0
- package/types/SelectContent.native.d.ts +4 -0
- package/types/SelectContent.native.d.ts.map +1 -0
- package/types/SelectImpl.d.ts +9 -0
- package/types/SelectImpl.d.ts.map +1 -0
- package/types/SelectScrollButton.d.ts +6 -0
- package/types/SelectScrollButton.d.ts.map +1 -0
- package/types/SelectScrollButton.native.d.ts +4 -0
- package/types/SelectScrollButton.native.d.ts.map +1 -0
- package/types/SelectViewport.d.ts +127 -0
- package/types/SelectViewport.d.ts.map +1 -0
- package/types/SelectViewport.native.d.ts +54 -0
- package/types/SelectViewport.native.d.ts.map +1 -0
- package/types/constants.d.ts +8 -0
- package/types/constants.d.ts.map +1 -0
- package/types/context.d.ts +17 -0
- package/types/context.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +74 -0
- package/types/types.d.ts.map +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TamaguiElement } from '@tamagui/core'
|
|
2
|
+
import { PortalItem } from '@tamagui/portal'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
|
|
5
|
+
import { VIEWPORT_NAME } from './constants'
|
|
6
|
+
import { useSelectContext } from './context'
|
|
7
|
+
import { ScopedProps, SelectViewportProps } from './types'
|
|
8
|
+
|
|
9
|
+
export const SelectViewport = React.forwardRef<TamaguiElement, SelectViewportProps>(
|
|
10
|
+
(props: ScopedProps<SelectViewportProps>) => {
|
|
11
|
+
const { __scopeSelect, children } = props
|
|
12
|
+
const context = useSelectContext(VIEWPORT_NAME, __scopeSelect)
|
|
13
|
+
return <PortalItem hostName={`${context.scopeKey}SheetContents`}>{children}</PortalItem>
|
|
14
|
+
}
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
SelectViewport.displayName = VIEWPORT_NAME
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { FloatingFocusManager } from '@floating-ui/react-dom-interactions'
|
|
2
|
+
import { TamaguiElement, isWeb } from '@tamagui/core'
|
|
3
|
+
import { styled } from '@tamagui/core'
|
|
4
|
+
import { PortalItem } from '@tamagui/portal'
|
|
5
|
+
import { ThemeableStack } from '@tamagui/stacks'
|
|
6
|
+
import * as React from 'react'
|
|
7
|
+
|
|
8
|
+
import { VIEWPORT_NAME } from './constants'
|
|
9
|
+
import { useSelectContext } from './context'
|
|
10
|
+
import { useSelectBreakpointActive } from './Select'
|
|
11
|
+
import { ScopedProps, SelectViewportProps } from './types'
|
|
12
|
+
|
|
13
|
+
/* -------------------------------------------------------------------------------------------------
|
|
14
|
+
* SelectViewport
|
|
15
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
16
|
+
|
|
17
|
+
export const SelectViewportFrame = styled(ThemeableStack, {
|
|
18
|
+
name: VIEWPORT_NAME,
|
|
19
|
+
backgroundColor: '$background',
|
|
20
|
+
elevate: true,
|
|
21
|
+
bordered: true,
|
|
22
|
+
overflow: 'scroll',
|
|
23
|
+
userSelect: 'none',
|
|
24
|
+
|
|
25
|
+
variants: {
|
|
26
|
+
size: {
|
|
27
|
+
'...size': (val, { tokens }) => {
|
|
28
|
+
return {
|
|
29
|
+
borderRadius: tokens.radius[val] ?? val,
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
defaultVariants: {
|
|
36
|
+
size: '$2',
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export const SelectViewport = React.forwardRef<TamaguiElement, SelectViewportProps>(
|
|
41
|
+
(props: ScopedProps<SelectViewportProps>, forwardedRef) => {
|
|
42
|
+
const { __scopeSelect, children, ...viewportProps } = props
|
|
43
|
+
const context = useSelectContext(VIEWPORT_NAME, __scopeSelect)
|
|
44
|
+
const { style, ...floatingProps } = context.interactions?.getFloatingProps() ?? {}
|
|
45
|
+
const breakpointActive = useSelectBreakpointActive(context.sheetBreakpoint)
|
|
46
|
+
|
|
47
|
+
if (breakpointActive || !isWeb) {
|
|
48
|
+
return <PortalItem hostName={`${context.scopeKey}SheetContents`}>{children}</PortalItem>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!context.floatingContext) {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// TODO
|
|
56
|
+
delete style['scrollbarWidth']
|
|
57
|
+
delete style['listStyleType']
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
{/* Hide scrollbars cross-browser and enable momentum scroll for touch devices */}
|
|
62
|
+
<style
|
|
63
|
+
dangerouslySetInnerHTML={{
|
|
64
|
+
__html: `[data-tamagui-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-tamagui-select-viewport]::-webkit-scrollbar{display:none}`,
|
|
65
|
+
}}
|
|
66
|
+
/>
|
|
67
|
+
<FloatingFocusManager context={context.floatingContext} preventTabbing>
|
|
68
|
+
<SelectViewportFrame
|
|
69
|
+
size={context.size}
|
|
70
|
+
data-tamagui-select-viewport=""
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
role="presentation"
|
|
73
|
+
{...viewportProps}
|
|
74
|
+
ref={forwardedRef}
|
|
75
|
+
{...floatingProps}
|
|
76
|
+
{...style}
|
|
77
|
+
>
|
|
78
|
+
{children}
|
|
79
|
+
</SelectViewportFrame>
|
|
80
|
+
</FloatingFocusManager>
|
|
81
|
+
</>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
SelectViewport.displayName = VIEWPORT_NAME
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const SELECT_NAME = 'Select'
|
|
2
|
+
export const WINDOW_PADDING = 8
|
|
3
|
+
export const SCROLL_ARROW_VELOCITY = 8
|
|
4
|
+
export const SCROLL_ARROW_THRESHOLD = 8
|
|
5
|
+
export const MIN_HEIGHT = 80
|
|
6
|
+
export const FALLBACK_THRESHOLD = 16
|
|
7
|
+
export const VIEWPORT_NAME = 'SelectViewport'
|
package/src/context.tsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContextScope } from '@tamagui/create-context'
|
|
2
|
+
|
|
3
|
+
import { SELECT_NAME } from './constants'
|
|
4
|
+
import { SelectContextValue } from './types'
|
|
5
|
+
|
|
6
|
+
export const [createSelectContext, createSelectScope] = createContextScope(SELECT_NAME)
|
|
7
|
+
|
|
8
|
+
export const [SelectProvider, useSelectContext] =
|
|
9
|
+
createSelectContext<SelectContextValue>(SELECT_NAME)
|
package/src/index.tsx
CHANGED
package/src/types.tsx
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ContextData,
|
|
3
|
+
FloatingContext,
|
|
4
|
+
ReferenceType,
|
|
5
|
+
} from '@floating-ui/react-dom-interactions'
|
|
6
|
+
import type { MediaPropKeys, SizeTokens } from '@tamagui/core'
|
|
7
|
+
import type { Scope } from '@tamagui/create-context'
|
|
8
|
+
import type { ThemeableStackProps, YStackProps } from '@tamagui/stacks'
|
|
9
|
+
import type { DispatchWithoutAction, HTMLProps, MutableRefObject, ReactNode } from 'react'
|
|
10
|
+
|
|
11
|
+
export type Direction = 'ltr' | 'rtl'
|
|
12
|
+
|
|
13
|
+
export type ScopedProps<P> = P & { __scopeSelect?: Scope }
|
|
14
|
+
|
|
15
|
+
export interface SelectProps {
|
|
16
|
+
id?: string
|
|
17
|
+
children?: ReactNode
|
|
18
|
+
value?: string
|
|
19
|
+
defaultValue?: string
|
|
20
|
+
onValueChange?(value: string): void
|
|
21
|
+
open?: boolean
|
|
22
|
+
defaultOpen?: boolean
|
|
23
|
+
onOpenChange?(open: boolean): void
|
|
24
|
+
dir?: Direction
|
|
25
|
+
name?: string
|
|
26
|
+
autoComplete?: string
|
|
27
|
+
size?: SizeTokens
|
|
28
|
+
sheetBreakpoint?: MediaPropKeys | false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type NonNull<A> = Exclude<A, void | null>
|
|
32
|
+
|
|
33
|
+
export interface SelectContextValue {
|
|
34
|
+
dir?: Direction
|
|
35
|
+
scopeKey: string
|
|
36
|
+
sheetBreakpoint: NonNull<SelectProps['sheetBreakpoint']>
|
|
37
|
+
size?: SizeTokens
|
|
38
|
+
value: any
|
|
39
|
+
selectedItem: ReactNode
|
|
40
|
+
setSelectedItem: (item: ReactNode) => void
|
|
41
|
+
selectedIndex: number
|
|
42
|
+
setSelectedIndex: (index: number) => void
|
|
43
|
+
activeIndex: number | null
|
|
44
|
+
setActiveIndex: (index: number | null) => void
|
|
45
|
+
setValueAtIndex: (index: number, value: string) => void
|
|
46
|
+
open: boolean
|
|
47
|
+
setOpen: (open: boolean) => void
|
|
48
|
+
onChange: (value: string) => void
|
|
49
|
+
valueNode: Element | null
|
|
50
|
+
onValueNodeChange(node: HTMLElement): void
|
|
51
|
+
valueNodeHasChildren: boolean
|
|
52
|
+
onValueNodeHasChildrenChange(hasChildren: boolean): void
|
|
53
|
+
forceUpdate: DispatchWithoutAction
|
|
54
|
+
|
|
55
|
+
// InlineImpl only:
|
|
56
|
+
dataRef?: MutableRefObject<ContextData>
|
|
57
|
+
controlledScrolling?: boolean
|
|
58
|
+
listRef?: MutableRefObject<Array<HTMLElement | null>>
|
|
59
|
+
floatingRef?: MutableRefObject<HTMLElement | null>
|
|
60
|
+
canScrollUp?: boolean
|
|
61
|
+
canScrollDown?: boolean
|
|
62
|
+
floatingContext?: FloatingContext<ReferenceType>
|
|
63
|
+
increaseHeight?: (floating: HTMLElement, amount?: any) => number | undefined
|
|
64
|
+
interactions?: {
|
|
65
|
+
getReferenceProps: (userProps?: HTMLProps<Element> | undefined) => any
|
|
66
|
+
getFloatingProps: (userProps?: HTMLProps<HTMLElement> | undefined) => any
|
|
67
|
+
getItemProps: (userProps?: HTMLProps<HTMLElement> | undefined) => any
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type SelectViewportProps = ThemeableStackProps & {
|
|
72
|
+
size?: SizeTokens
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type SelectContentProps = ScopedProps<{ children?: React.ReactNode }>
|
|
76
|
+
|
|
77
|
+
export interface SelectScrollButtonImplProps extends YStackProps {
|
|
78
|
+
dir: 'up' | 'down'
|
|
79
|
+
componentName: string
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface SelectScrollButtonProps
|
|
83
|
+
extends Omit<SelectScrollButtonImplProps, 'dir' | 'componentName'> {}
|