@kaushverse/pickify 1.0.2 → 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.
package/dist/index.d.mts CHANGED
@@ -37,6 +37,7 @@ type Props = {
37
37
  selectTextStyle?: TextStyle;
38
38
  errorStyle?: TextStyle;
39
39
  visible?: boolean;
40
+ setVisible?: (val: boolean) => void;
40
41
  selectedValue: string;
41
42
  options: Option[];
42
43
  groups?: Group[];
@@ -54,7 +55,7 @@ type Props = {
54
55
  onClose: () => void;
55
56
  };
56
57
 
57
- declare function PickerModal({ visible, selectedValue, options, groups, styles, theme, renderTab, renderItem, renderContainer, onSelect, onClose, renderIcon, label, placeholder, error, labelStyle, selectBoxStyle, selectTextStyle, errorStyle }: Props & {
58
+ declare function PickerModal({ visible, selectedValue, options, groups, styles, theme, renderTab, renderItem, renderContainer, onSelect, onClose, renderIcon, label, placeholder, error, labelStyle, selectBoxStyle, selectTextStyle, errorStyle, setVisible }: Props & {
58
59
  label?: string;
59
60
  placeholder?: string;
60
61
  error?: string;
package/dist/index.d.ts CHANGED
@@ -37,6 +37,7 @@ type Props = {
37
37
  selectTextStyle?: TextStyle;
38
38
  errorStyle?: TextStyle;
39
39
  visible?: boolean;
40
+ setVisible?: (val: boolean) => void;
40
41
  selectedValue: string;
41
42
  options: Option[];
42
43
  groups?: Group[];
@@ -54,7 +55,7 @@ type Props = {
54
55
  onClose: () => void;
55
56
  };
56
57
 
57
- declare function PickerModal({ visible, selectedValue, options, groups, styles, theme, renderTab, renderItem, renderContainer, onSelect, onClose, renderIcon, label, placeholder, error, labelStyle, selectBoxStyle, selectTextStyle, errorStyle }: Props & {
58
+ declare function PickerModal({ visible, selectedValue, options, groups, styles, theme, renderTab, renderItem, renderContainer, onSelect, onClose, renderIcon, label, placeholder, error, labelStyle, selectBoxStyle, selectTextStyle, errorStyle, setVisible }: Props & {
58
59
  label?: string;
59
60
  placeholder?: string;
60
61
  error?: string;
package/dist/index.js CHANGED
@@ -49,11 +49,13 @@ function PickerModal({
49
49
  labelStyle,
50
50
  selectBoxStyle,
51
51
  selectTextStyle,
52
- errorStyle
52
+ errorStyle,
53
+ setVisible
53
54
  }) {
54
55
  const [activeTab, setActiveTab] = (0, import_react.useState)(0);
55
56
  const [open, setOpen] = (0, import_react.useState)(false);
56
- const isVisible = visible ?? open;
57
+ const isControlled = visible !== void 0 && setVisible !== void 0;
58
+ const isVisible = isControlled ? visible : open;
57
59
  const hasGroups = groups.length > 0;
58
60
  const currentOptions = hasGroups ? groups[activeTab]?.data || [] : options;
59
61
  (0, import_react.useEffect)(() => {
@@ -70,13 +72,21 @@ function PickerModal({
70
72
  const all = hasGroups ? groups.flatMap((g) => g.data) : options;
71
73
  return all.find((o) => o.value === selectedValue)?.label;
72
74
  };
75
+ const handleOpen = () => {
76
+ if (isControlled) {
77
+ setVisible(true);
78
+ } else {
79
+ setOpen(true);
80
+ }
81
+ };
73
82
  const handleClose = () => {
74
- setOpen(false);
83
+ if (isControlled) {
84
+ setVisible(false);
85
+ } else {
86
+ setOpen(false);
87
+ }
75
88
  onClose?.();
76
89
  };
77
- const handleOpen = () => {
78
- setOpen(true);
79
- };
80
90
  const content = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
81
91
  import_react_native.View,
82
92
  {
package/dist/index.mjs CHANGED
@@ -29,11 +29,13 @@ function PickerModal({
29
29
  labelStyle,
30
30
  selectBoxStyle,
31
31
  selectTextStyle,
32
- errorStyle
32
+ errorStyle,
33
+ setVisible
33
34
  }) {
34
35
  const [activeTab, setActiveTab] = useState(0);
35
36
  const [open, setOpen] = useState(false);
36
- const isVisible = visible ?? open;
37
+ const isControlled = visible !== void 0 && setVisible !== void 0;
38
+ const isVisible = isControlled ? visible : open;
37
39
  const hasGroups = groups.length > 0;
38
40
  const currentOptions = hasGroups ? groups[activeTab]?.data || [] : options;
39
41
  useEffect(() => {
@@ -50,13 +52,21 @@ function PickerModal({
50
52
  const all = hasGroups ? groups.flatMap((g) => g.data) : options;
51
53
  return all.find((o) => o.value === selectedValue)?.label;
52
54
  };
55
+ const handleOpen = () => {
56
+ if (isControlled) {
57
+ setVisible(true);
58
+ } else {
59
+ setOpen(true);
60
+ }
61
+ };
53
62
  const handleClose = () => {
54
- setOpen(false);
63
+ if (isControlled) {
64
+ setVisible(false);
65
+ } else {
66
+ setOpen(false);
67
+ }
55
68
  onClose?.();
56
69
  };
57
- const handleOpen = () => {
58
- setOpen(true);
59
- };
60
70
  const content = /* @__PURE__ */ jsxs(
61
71
  View,
62
72
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaushverse/pickify",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A fully customizable React Native picker with search, multi-select, grouping, and async support.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",