@korsolutions/ui 0.0.93 → 0.0.95

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 (70) hide show
  1. package/dist/module/components/combobox/components/combobox-content.js +2 -0
  2. package/dist/module/components/combobox/components/combobox-content.js.map +1 -1
  3. package/dist/module/components/combobox/components/combobox-list.js +8 -15
  4. package/dist/module/components/combobox/components/combobox-list.js.map +1 -1
  5. package/dist/module/components/combobox/components/combobox-option.js +7 -2
  6. package/dist/module/components/combobox/components/combobox-option.js.map +1 -1
  7. package/dist/module/components/combobox/components/combobox-overlay.js +9 -3
  8. package/dist/module/components/combobox/components/combobox-overlay.js.map +1 -1
  9. package/dist/module/components/combobox/components/combobox-root.js +18 -71
  10. package/dist/module/components/combobox/components/combobox-root.js.map +1 -1
  11. package/dist/module/components/combobox/components/combobox-trigger.js +11 -33
  12. package/dist/module/components/combobox/components/combobox-trigger.js.map +1 -1
  13. package/dist/module/components/combobox/context.js.map +1 -1
  14. package/dist/module/components/focus/focus-prevent.js +10 -0
  15. package/dist/module/components/focus/focus-prevent.js.map +1 -0
  16. package/dist/module/components/select/components/select-content.js +2 -3
  17. package/dist/module/components/select/components/select-content.js.map +1 -1
  18. package/dist/module/components/select/components/select-option.js +2 -2
  19. package/dist/module/components/select/components/select-option.js.map +1 -1
  20. package/dist/module/components/select/components/select-overlay.js +2 -3
  21. package/dist/module/components/select/components/select-overlay.js.map +1 -1
  22. package/dist/module/components/select/components/select-root.js +3 -3
  23. package/dist/module/components/select/components/select-root.js.map +1 -1
  24. package/dist/module/components/select/components/select-trigger.js +3 -4
  25. package/dist/module/components/select/components/select-trigger.js.map +1 -1
  26. package/dist/module/components/select/variants/default.js +0 -5
  27. package/dist/module/components/select/variants/default.js.map +1 -1
  28. package/dist/module/utils/calculate-styles.js +6 -0
  29. package/dist/module/utils/calculate-styles.js.map +1 -1
  30. package/dist/typescript/src/components/combobox/components/combobox-content.d.ts.map +1 -1
  31. package/dist/typescript/src/components/combobox/components/combobox-list.d.ts +1 -1
  32. package/dist/typescript/src/components/combobox/components/combobox-list.d.ts.map +1 -1
  33. package/dist/typescript/src/components/combobox/components/combobox-option.d.ts.map +1 -1
  34. package/dist/typescript/src/components/combobox/components/combobox-overlay.d.ts.map +1 -1
  35. package/dist/typescript/src/components/combobox/components/combobox-root.d.ts +8 -25
  36. package/dist/typescript/src/components/combobox/components/combobox-root.d.ts.map +1 -1
  37. package/dist/typescript/src/components/combobox/components/combobox-trigger.d.ts +2 -1
  38. package/dist/typescript/src/components/combobox/components/combobox-trigger.d.ts.map +1 -1
  39. package/dist/typescript/src/components/combobox/context.d.ts +9 -8
  40. package/dist/typescript/src/components/combobox/context.d.ts.map +1 -1
  41. package/dist/typescript/src/components/focus/focus-prevent.d.ts +6 -0
  42. package/dist/typescript/src/components/focus/focus-prevent.d.ts.map +1 -0
  43. package/dist/typescript/src/components/select/components/select-content.d.ts.map +1 -1
  44. package/dist/typescript/src/components/select/components/select-option.d.ts.map +1 -1
  45. package/dist/typescript/src/components/select/components/select-overlay.d.ts.map +1 -1
  46. package/dist/typescript/src/components/select/components/select-root.d.ts.map +1 -1
  47. package/dist/typescript/src/components/select/components/select-trigger.d.ts +2 -2
  48. package/dist/typescript/src/components/select/components/select-trigger.d.ts.map +1 -1
  49. package/dist/typescript/src/components/select/types.d.ts +2 -2
  50. package/dist/typescript/src/components/select/types.d.ts.map +1 -1
  51. package/dist/typescript/src/components/select/variants/default.d.ts.map +1 -1
  52. package/dist/typescript/src/utils/calculate-styles.d.ts +2 -0
  53. package/dist/typescript/src/utils/calculate-styles.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/src/components/combobox/components/combobox-content.tsx +2 -0
  56. package/src/components/combobox/components/combobox-list.tsx +9 -17
  57. package/src/components/combobox/components/combobox-option.tsx +7 -2
  58. package/src/components/combobox/components/combobox-overlay.tsx +10 -3
  59. package/src/components/combobox/components/combobox-root.tsx +33 -117
  60. package/src/components/combobox/components/combobox-trigger.tsx +13 -38
  61. package/src/components/combobox/context.ts +12 -9
  62. package/src/components/focus/focus-prevent.ts +8 -0
  63. package/src/components/select/components/select-content.tsx +6 -7
  64. package/src/components/select/components/select-option.tsx +5 -4
  65. package/src/components/select/components/select-overlay.tsx +6 -7
  66. package/src/components/select/components/select-root.tsx +14 -3
  67. package/src/components/select/components/select-trigger.tsx +12 -12
  68. package/src/components/select/types.ts +2 -2
  69. package/src/components/select/variants/default.tsx +0 -5
  70. package/src/utils/calculate-styles.ts +16 -1
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
1
+ import React, { useMemo, useRef, useState } from "react";
2
2
  import {
3
3
  type LayoutRectangle,
4
4
  type StyleProp,
@@ -8,59 +8,24 @@ import {
8
8
  } from "react-native";
9
9
  import { DEFAULT_LAYOUT, DEFAULT_POSITION, type LayoutPosition } from "../../../hooks";
10
10
  import { useComponentConfig } from "../../../themes/provider";
11
+ import type { TextInputRef } from "../../../types/element.types";
11
12
  import { mergeStyles } from "../../../utils/calculate-styles";
12
13
  import type { Size } from "../../../utils/size-scale";
13
14
  import { ComboboxContext } from "../context";
14
15
  import type { ComboboxState } from "../types";
15
16
  import { ComboboxVariants } from "../variants";
16
17
 
17
- const defaultGetItemValue = (item: unknown): string => {
18
- if (typeof item === "string") return item;
19
- if (typeof item === "object" && item !== null && "value" in item) {
20
- return String((item as Record<string, unknown>).value);
21
- }
22
- return String(item);
23
- };
24
-
25
- const defaultGetItemLabel = (item: unknown): string => {
26
- if (typeof item === "string") return item;
27
- if (typeof item === "object" && item !== null && "label" in item) {
28
- return String((item as Record<string, unknown>).label);
29
- }
30
- return defaultGetItemValue(item);
31
- };
32
-
33
18
  export interface ComboboxRootProps<T> {
34
- /** The full list of selectable items. */
35
- items: readonly T[];
19
+ items: T[];
36
20
 
37
- /** The currently selected item. */
38
- value?: T;
21
+ value: T | null;
22
+ onChange: (item: T) => void;
39
23
 
40
- /** Called when the user selects an item. */
41
- onChange?: (item: T) => void;
24
+ inputValue: string;
25
+ onInputChange: (text: string) => void;
42
26
 
43
- /**
44
- * Extracts a unique string identifier from an item.
45
- * Defaults to reading `item.value` or `String(item)`.
46
- */
47
- getItemValue?: (item: T) => string;
48
-
49
- /**
50
- * Extracts a display label from an item (shown in the trigger when selected).
51
- * Defaults to reading `item.label` or falling back to `getItemValue`.
52
- */
53
- getItemLabel?: (item: T) => string;
54
-
55
- /**
56
- * Custom filter function. Return `true` to include the item.
57
- * Defaults to case-insensitive label includes query.
58
- * Pass `null` to disable built-in filtering (useful for async search).
59
- */
60
- filter?: ((item: T, query: string) => boolean) | null;
61
-
62
- /** Called when the text input value changes. Useful for async search. */
63
- onInputChange?: (text: string) => void;
27
+ getItemValue: (item: T) => string;
28
+ getItemLabel: (item: T) => string;
64
29
 
65
30
  variant?: keyof typeof ComboboxVariants;
66
31
  size?: Size;
@@ -74,20 +39,12 @@ const calculateState = <T,>(props: ComboboxRootProps<T>): ComboboxState => {
74
39
  return "default";
75
40
  };
76
41
 
77
- export function ComboboxRoot<T>(props: ComboboxRootProps<T>) {
78
- const {
79
- items,
80
- value,
81
- onChange,
82
- getItemValue = defaultGetItemValue as (item: T) => string,
83
- getItemLabel = defaultGetItemLabel as (item: T) => string,
84
- filter,
85
- onInputChange,
86
- variant = "default",
87
- size = "md",
88
- isDisabled = false,
89
- } = props;
90
-
42
+ export function ComboboxRoot<T>({
43
+ variant = "default",
44
+ size = "md",
45
+ isDisabled = false,
46
+ ...props
47
+ }: ComboboxRootProps<T>) {
91
48
  const variantStyles = ComboboxVariants[variant](size);
92
49
  const globalStyles = useComponentConfig("combobox");
93
50
  const mergedStyles = mergeStyles(variantStyles, globalStyles?.styles);
@@ -95,42 +52,7 @@ export function ComboboxRoot<T>(props: ComboboxRootProps<T>) {
95
52
  const [isOpen, setIsOpen] = useState(false);
96
53
  const [contentLayout, setContentLayout] = useState<LayoutRectangle>(DEFAULT_LAYOUT);
97
54
  const [triggerPosition, setTriggerPosition] = useState<LayoutPosition>(DEFAULT_POSITION);
98
- const [inputValue, setInputValue] = useState("");
99
-
100
- // Reset input value when closing
101
- const prevOpen = useRef(isOpen);
102
- useEffect(() => {
103
- if (prevOpen.current && !isOpen) {
104
- setInputValue("");
105
- }
106
- prevOpen.current = isOpen;
107
- }, [isOpen]);
108
-
109
- // Notify consumer when input value changes
110
- const onInputChangeRef = useRef(onInputChange);
111
- onInputChangeRef.current = onInputChange;
112
- const isFirstRender = useRef(true);
113
- useEffect(() => {
114
- if (isFirstRender.current) {
115
- isFirstRender.current = false;
116
- return;
117
- }
118
- onInputChangeRef.current?.(inputValue);
119
- }, [inputValue]);
120
-
121
- const filteredItems = useMemo(() => {
122
- if (filter === null) return items;
123
- if (!inputValue) return items;
124
-
125
- const filterFn =
126
- filter ??
127
- ((item: T, query: string) => {
128
- const label = getItemLabel(item);
129
- return label.toLowerCase().includes(query.toLowerCase());
130
- });
131
-
132
- return items.filter((item) => filterFn(item, inputValue));
133
- }, [items, inputValue, filter, getItemLabel]);
55
+ const inputRef = useRef<TextInputRef>(null);
134
56
 
135
57
  const state = calculateState(props);
136
58
  const composedStyles = StyleSheet.flatten([
@@ -139,44 +61,38 @@ export function ComboboxRoot<T>(props: ComboboxRootProps<T>) {
139
61
  props.style,
140
62
  ]);
141
63
 
142
- const handleChange = useCallback(
143
- (item: unknown) => {
144
- onChange?.(item as T);
145
- },
146
- [onChange],
147
- );
148
-
149
- const contextValue: ComboboxContext = useMemo(
64
+ const contextValue = useMemo<ComboboxContext>(
150
65
  () => ({
151
- items,
152
- filteredItems,
153
- getItemValue: getItemValue as (item: unknown) => string,
154
- getItemLabel: getItemLabel as (item: unknown) => string,
155
- value,
156
- onChange: handleChange,
66
+ items: props.items,
67
+ filteredItems: props.items,
68
+ value: props.value,
69
+ onChange: props.onChange,
70
+ inputValue: props.inputValue,
71
+ onInputChange: props.onInputChange,
72
+ inputRef,
73
+ getItemValue: props.getItemValue,
74
+ getItemLabel: props.getItemLabel,
157
75
  isOpen,
158
76
  setIsOpen,
159
77
  triggerPosition,
160
78
  setTriggerPosition,
161
79
  contentLayout,
162
80
  setContentLayout,
163
- inputValue,
164
- setInputValue,
165
81
  state,
166
82
  isDisabled,
167
83
  styles: mergedStyles,
168
84
  }),
169
85
  [
170
- items,
171
- filteredItems,
172
- getItemValue,
173
- getItemLabel,
174
- value,
175
- handleChange,
86
+ props.items,
87
+ props.value,
88
+ props.onChange,
89
+ props.inputValue,
90
+ props.onInputChange,
91
+ props.getItemValue,
92
+ props.getItemLabel,
176
93
  isOpen,
177
94
  triggerPosition,
178
95
  contentLayout,
179
- inputValue,
180
96
  state,
181
97
  isDisabled,
182
98
  mergedStyles,
@@ -1,7 +1,6 @@
1
- import React, { useEffect, useRef } from "react";
1
+ import React from "react";
2
2
  import { StyleSheet, TextInput, type TextInputProps } from "react-native";
3
3
  import type { TextInputRef } from "../../../types/element.types";
4
- import { setInnerInputValue } from "../../../utils/input-utils";
5
4
  import { measureLayoutPosition } from "../../../utils/normalize-layout";
6
5
  import { useCombobox } from "../context";
7
6
  import type { ComboboxTriggerState } from "../types";
@@ -11,7 +10,8 @@ type ExtendableProps = Omit<TextInputProps, "value" | "onChange" | "onChangeText
11
10
  type RenderProps = {
12
11
  inputRef: React.RefObject<TextInputRef | null>;
13
12
  open: () => void;
14
- setInputValue: (value: string) => void;
13
+ value: string;
14
+ onChange: (value: string) => void;
15
15
  };
16
16
 
17
17
  export type ComboboxTriggerProps = ExtendableProps & {
@@ -26,50 +26,24 @@ const calculateState = (isDisabled: boolean, isOpen: boolean): ComboboxTriggerSt
26
26
 
27
27
  export function ComboboxTrigger({ render, ...props }: ComboboxTriggerProps) {
28
28
  const combobox = useCombobox();
29
- const triggerRef = useRef<TextInputRef>(null);
30
29
 
31
30
  const triggerState = calculateState(combobox.isDisabled, combobox.isOpen);
32
- const selectedLabel = combobox.value != null ? combobox.getItemLabel(combobox.value) : "";
33
- const displayValue = combobox.isOpen ? combobox.inputValue : selectedLabel;
34
31
 
35
32
  const open = () => {
36
33
  if (combobox.isDisabled) return;
37
- combobox.setInputValue(selectedLabel);
38
34
  requestAnimationFrame(() => {
39
- measureLayoutPosition(triggerRef.current, (layout) => {
35
+ measureLayoutPosition(combobox.inputRef.current, (layout) => {
40
36
  combobox.setTriggerPosition(layout);
41
37
  combobox.setIsOpen(true);
42
38
  });
43
39
  });
44
40
  };
45
41
 
46
- const onChangeText = (text: string) => {
47
- if (combobox.isDisabled) return;
48
- combobox.setInputValue(text);
49
- if (!combobox.isOpen) open();
50
- };
51
-
52
- const onFocus = () => {
53
- if (!combobox.isOpen) open();
42
+ const onFocus: TextInputProps["onFocus"] = (e) => {
43
+ props.onFocus?.(e);
44
+ open();
54
45
  };
55
46
 
56
- const setInputValue = (value: string) => {
57
- combobox.setInputValue(value);
58
- if (triggerRef.current) {
59
- setInnerInputValue(triggerRef.current, value);
60
- }
61
- };
62
-
63
- useEffect(() => {
64
- setInputValue(displayValue);
65
- }, [displayValue]);
66
-
67
- useEffect(() => {
68
- if (!combobox.isOpen) {
69
- triggerRef.current?.blur();
70
- }
71
- }, [combobox.isOpen]);
72
-
73
47
  const triggerStyles = combobox.styles?.trigger;
74
48
  const composedProps: TextInputProps = {
75
49
  ...triggerStyles?.default,
@@ -89,19 +63,20 @@ export function ComboboxTrigger({ render, ...props }: ComboboxTriggerProps) {
89
63
 
90
64
  if (render) {
91
65
  return render({
92
- inputRef: triggerRef,
66
+ inputRef: combobox.inputRef,
93
67
  open,
94
- setInputValue,
68
+ value: combobox.inputValue,
69
+ onChange: combobox.onInputChange,
95
70
  });
96
71
  }
97
72
 
98
73
  return (
99
74
  <TextInput
100
75
  {...composedProps}
101
- ref={triggerRef}
102
- value={undefined}
76
+ ref={combobox.inputRef}
77
+ value={combobox.inputValue}
103
78
  onChange={undefined}
104
- onChangeText={onChangeText}
79
+ onChangeText={combobox.onInputChange}
105
80
  onFocus={onFocus}
106
81
  style={composedStyle}
107
82
  />
@@ -1,16 +1,22 @@
1
1
  import { createContext, type Dispatch, useContext } from "react";
2
2
  import type { LayoutRectangle } from "react-native";
3
3
  import type { LayoutPosition } from "../../hooks";
4
+ import type { TextInputRef } from "../../types/element.types";
4
5
  import type { ComboboxState, ComboboxStyles } from "./types";
5
6
 
6
7
  export interface ComboboxContext {
7
- items: readonly unknown[];
8
- filteredItems: readonly unknown[];
9
- getItemValue: (item: unknown) => string;
10
- getItemLabel: (item: unknown) => string;
8
+ items: readonly any[];
11
9
 
12
- value: unknown | undefined;
13
- onChange: ((item: unknown) => void) | undefined;
10
+ value: any | undefined;
11
+ onChange: (item: any) => void;
12
+
13
+ inputValue: string;
14
+ onInputChange: (text: string) => void;
15
+
16
+ getItemValue: (item: any) => string;
17
+ getItemLabel: (item: any) => string;
18
+
19
+ inputRef: React.RefObject<TextInputRef | null>;
14
20
 
15
21
  isOpen: boolean;
16
22
  setIsOpen: Dispatch<React.SetStateAction<boolean>>;
@@ -19,9 +25,6 @@ export interface ComboboxContext {
19
25
  contentLayout: LayoutRectangle;
20
26
  setContentLayout: Dispatch<React.SetStateAction<LayoutRectangle>>;
21
27
 
22
- inputValue: string;
23
- setInputValue: Dispatch<React.SetStateAction<string>>;
24
-
25
28
  isDisabled: boolean;
26
29
 
27
30
  state: ComboboxState;
@@ -0,0 +1,8 @@
1
+ import { Platform } from "react-native";
2
+
3
+ export const focusPreventProps = Platform.select({
4
+ web: {
5
+ onMouseDown: (e: React.MouseEvent) => e.preventDefault(),
6
+ },
7
+ default: {},
8
+ });
@@ -1,7 +1,6 @@
1
1
  import React from "react";
2
- import { type StyleProp, View, type ViewStyle } from "react-native";
2
+ import { type StyleProp, StyleSheet, View, type ViewStyle } from "react-native";
3
3
  import { useRelativePosition } from "../../../hooks/use-relative-position";
4
- import { calculateComposedStyles } from "../../../utils/calculate-styles";
5
4
  import { useSelect } from "../context";
6
5
 
7
6
  export interface SelectContentProps {
@@ -14,12 +13,12 @@ export interface SelectContentProps {
14
13
 
15
14
  export function SelectContent(props: SelectContentProps) {
16
15
  const select = useSelect();
17
- const composedStyles = calculateComposedStyles(
18
- select.styles,
19
- select.state,
20
- "content",
16
+
17
+ const composedStyles = StyleSheet.flatten([
18
+ select.styles?.content?.default,
19
+ select.styles?.content?.[select.state],
21
20
  props.style,
22
- );
21
+ ]);
23
22
 
24
23
  const positionStyle = useRelativePosition({
25
24
  align: "start",
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect, useState } from "react";
2
2
  import { Pressable, StyleSheet, type PressableProps } from "react-native";
3
3
  import type { ElementChildren } from "../../../types/element.types";
4
+ import { extractPressableStyles } from "../../../utils/calculate-styles";
4
5
  import { useSelect } from "../context";
5
6
  import type { SelectOptionState, SelectState } from "../types";
6
7
 
@@ -33,7 +34,7 @@ export function SelectOption(props: SelectOptionProps): React.ReactElement {
33
34
  const isSelected = select.value === props.value;
34
35
 
35
36
  const optionState = calculateState(select.state, isHovered, isSelected);
36
- const optionStyles = select.styles?.option;
37
+
37
38
  useEffect(() => {
38
39
  select.setOptions((prev) => {
39
40
  if (prev.find((option) => option.value === props.value)) {
@@ -57,9 +58,9 @@ export function SelectOption(props: SelectOptionProps): React.ReactElement {
57
58
  onPointerLeave={handlePointerLeave}
58
59
  style={(styleProps) =>
59
60
  StyleSheet.flatten([
60
- optionStyles?.default,
61
- optionStyles?.[optionState],
62
- typeof props.style === "function" ? props.style(styleProps) : props.style,
61
+ extractPressableStyles(select.styles?.option?.default, styleProps),
62
+ extractPressableStyles(select.styles?.option?.[optionState], styleProps),
63
+ extractPressableStyles(props.style, styleProps),
63
64
  ])
64
65
  }
65
66
  >
@@ -1,4 +1,3 @@
1
- import { calculateComposedStyles } from "../../../utils/calculate-styles";
2
1
  import React from "react";
3
2
  import { Pressable, type StyleProp, StyleSheet, type ViewStyle } from "react-native";
4
3
  import { useSelect } from "../context";
@@ -16,12 +15,12 @@ export interface SelectOverlayProps {
16
15
  export function SelectOverlay(props: SelectOverlayProps) {
17
16
  const select = useSelect();
18
17
 
19
- const composedStyles = calculateComposedStyles(
20
- select.styles,
21
- select.state,
22
- "overlay",
18
+ const composedStyles = StyleSheet.flatten([
19
+ select.styles?.overlay?.default,
20
+ select.styles?.overlay?.[select.state],
23
21
  props.style,
24
- );
22
+ StyleSheet.absoluteFill,
23
+ ]);
25
24
 
26
25
  const Component = props.render ?? Pressable;
27
26
  return (
@@ -30,7 +29,7 @@ export function SelectOverlay(props: SelectOverlayProps) {
30
29
  select.setIsOpen(false);
31
30
  }}
32
31
  pointerEvents="auto"
33
- style={[StyleSheet.absoluteFill, composedStyles]}
32
+ style={composedStyles}
34
33
  >
35
34
  {props.children}
36
35
  </Component>
@@ -1,8 +1,14 @@
1
1
  import React, { useState } from "react";
2
- import { type LayoutRectangle, type StyleProp, View, type ViewStyle } from "react-native";
2
+ import {
3
+ type LayoutRectangle,
4
+ type StyleProp,
5
+ StyleSheet,
6
+ View,
7
+ type ViewStyle,
8
+ } from "react-native";
3
9
  import { DEFAULT_LAYOUT, DEFAULT_POSITION, type LayoutPosition } from "../../../hooks";
4
10
  import { useComponentConfig } from "../../../themes/provider";
5
- import { calculateComposedStyles, mergeStyles } from "../../../utils/calculate-styles";
11
+ import { mergeStyles } from "../../../utils/calculate-styles";
6
12
  import type { Size } from "../../../utils/size-scale";
7
13
  import { SelectContext } from "../context";
8
14
  import type { SelectOption, SelectState } from "../types";
@@ -48,7 +54,12 @@ export function SelectRoot(props: SelectRootProps) {
48
54
  const [options, setOptions] = useState<Array<SelectOption>>([]);
49
55
 
50
56
  const state = calculateState(props);
51
- const composedStyles = calculateComposedStyles(mergedStyles, state, "root", props.style);
57
+
58
+ const composedStyles = StyleSheet.flatten([
59
+ mergedStyles?.root?.default,
60
+ mergedStyles?.root?.[state],
61
+ props.style,
62
+ ]);
52
63
 
53
64
  const Component = props.render ?? View;
54
65
  return (
@@ -1,32 +1,26 @@
1
1
  import React, { useRef } from "react";
2
2
  import {
3
3
  Pressable,
4
+ StyleSheet,
4
5
  Text,
6
+ type PressableProps,
5
7
  type StyleProp,
6
- type TextStyle,
7
- type ViewStyle,
8
+ type TextStyle
8
9
  } from "react-native";
9
10
  import type { ViewRef } from "../../../types/element.types";
10
- import { calculateComposedStyles } from "../../../utils/calculate-styles";
11
+ import { extractPressableStyles } from "../../../utils/calculate-styles";
11
12
  import { measureLayoutPosition } from "../../../utils/normalize-layout";
12
13
  import { useSelect } from "../context";
13
14
 
14
15
  export interface SelectTriggerProps {
15
16
  placeholder?: string;
16
- style?: StyleProp<ViewStyle>;
17
+ style?: PressableProps["style"];
17
18
  }
18
19
 
19
20
  export function SelectTrigger(props: SelectTriggerProps) {
20
21
  const select = useSelect();
21
22
  const triggerRef = useRef<ViewRef>(null);
22
23
 
23
- const composedStyles = calculateComposedStyles(
24
- select.styles,
25
- select.state,
26
- "trigger",
27
- props.style,
28
- );
29
-
30
24
  const onTriggerPress = () => {
31
25
  if (!select.isOpen) {
32
26
  measureLayoutPosition(triggerRef.current, (layout) => {
@@ -43,7 +37,13 @@ export function SelectTrigger(props: SelectTriggerProps) {
43
37
  ref={triggerRef}
44
38
  onPress={onTriggerPress}
45
39
  disabled={select.isDisabled}
46
- style={composedStyles}
40
+ style={(styleProp) =>
41
+ StyleSheet.flatten([
42
+ extractPressableStyles(select.styles?.trigger?.default, styleProp),
43
+ extractPressableStyles(select.styles?.trigger?.[select.state], styleProp),
44
+ extractPressableStyles(props.style, styleProp),
45
+ ])
46
+ }
47
47
  >
48
48
  <SelectValue placeholder={props.placeholder} />
49
49
  </Pressable>
@@ -1,5 +1,5 @@
1
- import type { TextStyle } from "react-native";
2
1
  import type { SelectContentProps } from "./components/select-content";
2
+ import type { SelectOptionProps } from "./components/select-option";
3
3
  import type { SelectOverlayProps } from "./components/select-overlay";
4
4
  import type { SelectRootProps } from "./components/select-root";
5
5
  import type { SelectTriggerProps, SelectValueProps } from "./components/select-trigger";
@@ -14,7 +14,7 @@ export interface SelectStyles {
14
14
  placeholder?: Partial<Record<SelectState, SelectValueProps["style"]>>;
15
15
  overlay?: Partial<Record<SelectState, SelectOverlayProps["style"]>>;
16
16
  content?: Partial<Record<SelectState, SelectContentProps["style"]>>;
17
- option?: Partial<Record<SelectOptionState, TextStyle>>;
17
+ option?: Partial<Record<SelectOptionState, SelectOptionProps["style"]>>;
18
18
  }
19
19
 
20
20
  export interface SelectOption {
@@ -71,15 +71,10 @@ export function useSelectVariantDefault(size: Size): SelectStyles {
71
71
  default: {
72
72
  paddingVertical: s.paddingVertical,
73
73
  paddingHorizontal: s.paddingHorizontal,
74
- fontFamily,
75
- fontSize: s.fontSize,
76
- lineHeight: s.lineHeight,
77
- color: colors.foreground,
78
74
  borderRadius: radius / 2,
79
75
  cursor: "pointer",
80
76
  },
81
77
  disabled: {
82
- color: colors.mutedForeground,
83
78
  cursor: "not-allowed" as CursorValue,
84
79
  },
85
80
  selected: {
@@ -1,4 +1,9 @@
1
- import { StyleSheet } from "react-native";
1
+ import {
2
+ StyleSheet,
3
+ type PressableProps,
4
+ type PressableStateCallbackType,
5
+ type ViewStyle,
6
+ } from "react-native";
2
7
 
3
8
  export const calculateComposedStyles = <
4
9
  TStyle,
@@ -57,3 +62,13 @@ export const mergeStyles = <TStyle extends Record<string, any>>(
57
62
  }
58
63
  return returnStyles;
59
64
  };
65
+
66
+ export const extractPressableStyles = (
67
+ style: PressableProps["style"],
68
+ props: PressableStateCallbackType,
69
+ ): ViewStyle => {
70
+ if (typeof style === "function") {
71
+ return style(props) as ViewStyle;
72
+ }
73
+ return style as ViewStyle;
74
+ };