@butternutbox/pawprint-native 0.9.0 → 0.10.1

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.
@@ -1,5 +1,5 @@
1
1
  import React from "react"
2
- import { View, ViewProps, ScrollView } from "react-native"
2
+ import { View, ViewProps, ScrollView, StyleSheet } from "react-native"
3
3
  import styled from "@emotion/native"
4
4
  import { useTheme } from "@emotion/react"
5
5
  import * as SelectPrimitive from "@rn-primitives/select"
@@ -11,11 +11,6 @@ type SelectFieldContentProps = {
11
11
 
12
12
  const parseTokenValue = (value: string): number => parseFloat(value)
13
13
 
14
- // TODO: Replace with dynamic positioning when @rn-primitives/select supports it on React Native
15
- // These values position the dropdown below and aligned with the trigger
16
- const DROPDOWN_OFFSET_X = -32 // Align with trigger left edge
17
- const DROPDOWN_OFFSET_Y = -94 // Position below trigger with gap
18
-
19
14
  const StyledContentShadow = styled(View)(({ theme }) => {
20
15
  const { dropdown } = theme.tokens.components.dropdownList
21
16
  const shadow = dropdown.list.dropshadow.default
@@ -29,11 +24,7 @@ const StyledContentShadow = styled(View)(({ theme }) => {
29
24
  },
30
25
  shadowOpacity: 1,
31
26
  shadowRadius: parseTokenValue(shadow.blur),
32
- elevation: 8,
33
- transform: [
34
- { translateX: DROPDOWN_OFFSET_X },
35
- { translateY: DROPDOWN_OFFSET_Y }
36
- ]
27
+ elevation: 8
37
28
  }
38
29
  })
39
30
 
@@ -59,6 +50,7 @@ export const SelectFieldContent = React.forwardRef<
59
50
 
60
51
  return (
61
52
  <SelectPrimitive.Portal>
53
+ <SelectPrimitive.Overlay style={StyleSheet.absoluteFill} />
62
54
  <SelectPrimitive.Content
63
55
  side="bottom"
64
56
  align="start"
@@ -70,7 +62,11 @@ export const SelectFieldContent = React.forwardRef<
70
62
  <StyledContentShadow {...rest}>
71
63
  <StyledContentInner>
72
64
  <SelectPrimitive.Viewport>
73
- <ScrollView showsVerticalScrollIndicator nestedScrollEnabled>
65
+ <ScrollView
66
+ showsVerticalScrollIndicator
67
+ nestedScrollEnabled
68
+ keyboardShouldPersistTaps="handled"
69
+ >
74
70
  {children}
75
71
  </ScrollView>
76
72
  </SelectPrimitive.Viewport>
@@ -17,6 +17,8 @@ type SelectFieldTriggerOwnProps = {
17
17
  leadingIcon?: React.ReactNode
18
18
  children?: React.ReactNode
19
19
  isOpen?: boolean
20
+ isSearching?: boolean
21
+ actionIcon?: React.ReactNode
20
22
  }
21
23
 
22
24
  export type SelectFieldTriggerProps = SelectFieldTriggerOwnProps &
@@ -59,7 +61,15 @@ export const SelectFieldTrigger = React.forwardRef<
59
61
  SelectFieldTriggerProps
60
62
  >(
61
63
  (
62
- { state = "default", leadingIcon, children, isOpen = false, ...rest },
64
+ {
65
+ state = "default",
66
+ leadingIcon,
67
+ children,
68
+ isOpen = false,
69
+ isSearching = false,
70
+ actionIcon,
71
+ ...rest
72
+ },
63
73
  ref
64
74
  ) => {
65
75
  const theme = useTheme()
@@ -134,33 +144,41 @@ export const SelectFieldTrigger = React.forwardRef<
134
144
  <Icon icon={SuccessIcon} size="md" colour="success" />
135
145
  ) : null
136
146
 
147
+ const triggerContent = (
148
+ <StyledTriggerWrapper
149
+ state={state}
150
+ style={[
151
+ {
152
+ borderColor,
153
+ borderWidth: animatedBorderWidth,
154
+ paddingVertical: animatedPaddingVertical,
155
+ paddingHorizontal: animatedPaddingHorizontal
156
+ }
157
+ ]}
158
+ >
159
+ {leadingIcon && <StyledIconWrapper>{leadingIcon}</StyledIconWrapper>}
160
+ {children}
161
+ {stateIcon && <StyledIconWrapper>{stateIcon}</StyledIconWrapper>}
162
+ {actionIcon ? (
163
+ <StyledIconWrapper>{actionIcon}</StyledIconWrapper>
164
+ ) : (
165
+ <StyledArrowIcon
166
+ style={{ transform: [{ rotate: animatedRotation }] }}
167
+ >
168
+ <Icon icon={KeyboardArrowDown} size="md" colour="primary" />
169
+ </StyledArrowIcon>
170
+ )}
171
+ </StyledTriggerWrapper>
172
+ )
173
+
174
+ if (isSearching) {
175
+ return <View ref={ref}>{triggerContent}</View>
176
+ }
177
+
137
178
  return (
138
179
  <SelectPrimitive.Trigger asChild>
139
180
  <Slot ref={ref}>
140
- <Pressable {...rest}>
141
- <StyledTriggerWrapper
142
- state={state}
143
- style={[
144
- {
145
- borderColor,
146
- borderWidth: animatedBorderWidth,
147
- paddingVertical: animatedPaddingVertical,
148
- paddingHorizontal: animatedPaddingHorizontal
149
- }
150
- ]}
151
- >
152
- {leadingIcon && (
153
- <StyledIconWrapper>{leadingIcon}</StyledIconWrapper>
154
- )}
155
- {children}
156
- {stateIcon && <StyledIconWrapper>{stateIcon}</StyledIconWrapper>}
157
- <StyledArrowIcon
158
- style={{ transform: [{ rotate: animatedRotation }] }}
159
- >
160
- <Icon icon={KeyboardArrowDown} size="md" colour="primary" />
161
- </StyledArrowIcon>
162
- </StyledTriggerWrapper>
163
- </Pressable>
181
+ <Pressable {...rest}>{triggerContent}</Pressable>
164
182
  </Slot>
165
183
  </SelectPrimitive.Trigger>
166
184
  )
@@ -1,29 +1,28 @@
1
1
  import React from "react"
2
- import { Text, TextProps } from "react-native"
3
- import styled from "@emotion/native"
2
+ import { View, ViewProps } from "react-native"
3
+ import { useTheme } from "@emotion/react"
4
4
  import * as SelectPrimitive from "@rn-primitives/select"
5
+ import { Typography } from "../../atoms/Typography"
5
6
 
6
7
  type SelectFieldValueProps = {
7
8
  placeholder?: string
8
- } & Omit<TextProps, "children">
9
+ } & Omit<ViewProps, "children">
9
10
 
10
- const StyledValue = styled(Text)(({ theme }) => {
11
- const { colour } = theme.tokens.components.inputs
12
-
13
- return {
14
- flex: 1,
15
- minWidth: 0,
16
- textAlign: "left",
17
- color: colour.field.text.default
18
- }
19
- })
20
-
21
- export const SelectFieldValue = React.forwardRef<Text, SelectFieldValueProps>(
11
+ export const SelectFieldValue = React.forwardRef<View, SelectFieldValueProps>(
22
12
  ({ placeholder, ...rest }, ref) => {
13
+ const theme = useTheme()
14
+ const { colour, field } = theme.tokens.components.inputs
15
+
23
16
  return (
24
- <StyledValue ref={ref} {...rest}>
25
- <SelectPrimitive.Value placeholder={placeholder ?? ""} />
26
- </StyledValue>
17
+ <View ref={ref} style={{ flex: 1, minWidth: 0 }} {...rest}>
18
+ <Typography
19
+ token={field.placeholder.default}
20
+ color={colour.field.text.default}
21
+ align="left"
22
+ >
23
+ <SelectPrimitive.Value placeholder={placeholder ?? ""} />
24
+ </Typography>
25
+ </View>
27
26
  )
28
27
  }
29
28
  )