@rn-components-dropdown/dropdown 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/README.md CHANGED
@@ -1,118 +1,146 @@
1
1
  # @rn-components-dropdown/dropdown
2
2
 
3
- A lightweight and customizable dropdown component for React Native. Includes a flexible `Dropdown` component and a simple `AppText` component.
3
+ A lightweight, customizable, and fully typed **Dropdown** and **DropdownController** component for **React Native**.
4
+ Supports **single** & **multiple selection**, custom icons, styling, and easy integration with **React Hook Form**.
4
5
 
5
6
  ---
6
7
 
7
- ## 🚀 Installation
8
+ ## 📦 Installation
8
9
 
9
- Install the package using npm or yarn:
10
+ ### Install Package
10
11
 
11
12
  ```bash
12
13
  npm install @rn-components-dropdown/dropdown
13
14
  ```
14
15
 
15
- or
16
+ ### React Hook Form (optional — required only for DropdownController)
16
17
 
17
18
  ```bash
18
- yarn add @rn-components-dropdown/dropdown
19
+ npm install react-hook-form
19
20
  ```
20
21
 
21
22
  ---
22
23
 
23
- ## 📦 Importing Components
24
+ ## ✨ Components Provided
24
25
 
25
- ```js
26
- import { Dropdown, AppText } from '@rn-components-dropdown/dropdown';
27
- ```
26
+ This package includes two components:
28
27
 
29
- ---
28
+ ### 🔹 Dropdown
29
+ A standalone dropdown with:
30
+ - Single or multi selection
31
+ - Custom icons
32
+ - Full styling customization
33
+ - Works independently
30
34
 
31
- ## 🧩 Usage Example
35
+ ### 🔹 DropdownController
36
+ A wrapper designed for **React Hook Form**, handling form values automatically.
32
37
 
33
- ```jsx
34
- import React, { useState } from 'react';
35
- import { View } from 'react-native';
36
- import { Dropdown, AppText } from '@rn-components-dropdown/dropdown';
38
+ ---
37
39
 
38
- export default function App() {
39
- const [value, setValue] = useState(null);
40
+ # 🔽 Dropdown Usage
40
41
 
41
- const data = [
42
- { label: 'Apple', value: 1 },
43
- { label: 'Banana', value: 2 },
44
- { label: 'Mango', value: 3 },
45
- ];
42
+ ```tsx
43
+ import { Dropdown } from "@rn-components-dropdown/dropdown";
46
44
 
45
+ export default function MyScreen() {
47
46
  return (
48
- <View style={{ padding: 20 }}>
49
- <AppText>Choose a fruit:</AppText>
50
-
51
- <Dropdown
52
- data={data}
53
- labelField="label"
54
- valueField="value"
55
- value={value}
56
- onChange={(item) => setValue(item.value)}
57
- placeholder="Select item"
58
- />
59
- </View>
47
+ <Dropdown
48
+ data={[
49
+ { id: 1, label: "Apple" },
50
+ { id: 2, label: "Banana" },
51
+ ]}
52
+ labelField="label"
53
+ valueField="id"
54
+ placeholder="Select fruit"
55
+ />
60
56
  );
61
57
  }
62
58
  ```
63
59
 
64
60
  ---
65
61
 
66
- ## 🛠️ Dropdown Props
67
-
68
- | Prop | Type | Default | Description |
69
- | --------------- | ---------- | --------------- | ----------------------------------------------------- |
70
- | `data` | `array` | `[]` | The list of options for the dropdown. |
71
- | `labelField` | `string` | `'label'` | The key in each data object for displaying the label. |
72
- | `valueField` | `string` | `'value'` | The key used as the selected value. |
73
- | `value` | `any` | `null` | The selected value. |
74
- | `placeholder` | `string` | `'Select item'` | Placeholder text. |
75
- | `onChange` | `function` | `() => {}` | Callback when a value is selected. |
76
- | `style` | `object` | `{}` | Custom style for the dropdown container. |
77
- | `textStyle` | `object` | `{}` | Custom style for the selected text. |
78
- | `dropdownStyle` | `object` | `{}` | Style for the dropdown list. |
62
+ # 🔧 Dropdown Props
63
+
64
+ | Prop | Type | Description |
65
+ |-------------------|-------------------------|--------------------------------------------------|
66
+ | data | Array<any> | List of dropdown items |
67
+ | labelField | string | Key used for item label |
68
+ | valueField | string | Key used for item value |
69
+ | value | any | Current selected item/value |
70
+ | placeholder | string | Placeholder text |
71
+ | multiple | boolean | Enable multi-select |
72
+ | onChange | (item) => void | Callback when value changes |
73
+ | disable | boolean | Disable the dropdown |
74
+ | renderIcon | () => JSX.Element | Custom icon renderer |
75
+ | style | ViewStyle | Wrapper container style |
76
+ | selectedStyle | ViewStyle | Style for selected value display |
77
+ | dropdownStyle | ViewStyle | Dropdown list container style |
78
+ | placeholderStyle | TextStyle | Style for placeholder text |
79
+ | itemStyle | ViewStyle | Style for each dropdown item |
80
+ | ...others | any | Additional props |
79
81
 
80
82
  ---
81
83
 
82
- ## ✨ Features
84
+ # 🎯 DropdownController (React Hook Form Support)
83
85
 
84
- * Fully customizable dropdown UI
85
- * Simple API
86
- * Works with any React Native project
87
- * Includes reusable `AppText` component
86
+ A form-friendly dropdown that automatically:
87
+ - updates values
88
+ - handles errors
89
+ - applies validation rules
88
90
 
89
91
  ---
90
92
 
91
- ## 📄 AppText Component
93
+ ## 📘 Usage with React Hook Form
92
94
 
93
- A simple wrapper around the standard `Text` component.
95
+ ```tsx
96
+ import { useForm } from "react-hook-form";
97
+ import { DropdownController } from "@rn-components-dropdown/dropdown";
94
98
 
95
- ### Usage
99
+ export default function FormScreen() {
100
+ const { control } = useForm();
96
101
 
97
- ```jsx
98
- <AppText style={{ fontSize: 18 }}>Hello World</AppText>
102
+ return (
103
+ <DropdownController
104
+ control={control}
105
+ name="fruit"
106
+ rules={{ required: "Please select a fruit" }}
107
+ dropProps={{
108
+ data: [
109
+ { id: 1, label: "Apple" },
110
+ { id: 2, label: "Banana" },
111
+ ],
112
+ labelField: "label",
113
+ valueField: "id",
114
+ placeholder: "Pick a fruit",
115
+ }}
116
+ />
117
+ );
118
+ }
99
119
  ```
100
120
 
101
- ### Props
121
+ ---
122
+
123
+ ## 🧩 DropdownController Props
102
124
 
103
- | Prop | Type | Description | |
104
- | ---------- | -------- | -------------- | ---------------------- |
105
- | `children` | `string | ReactNode` | Text content to render |
106
- | `style` | `object` | Custom styling | |
125
+ | Prop | Type | Description |
126
+ |---------------|-------------|-----------------------------------------------|
127
+ | control | Control | React Hook Form control object |
128
+ | name | string | Field name in the form |
129
+ | rules | object | Validation rules (optional) |
130
+ | dropProps | object | All dropdown props |
131
+ | defaultValue | any | Initial/default value |
107
132
 
108
133
  ---
109
134
 
110
- ## 📚 Contributing
135
+ ## 📝 Notes
111
136
 
112
- Pull requests are welcome! If you want to improve the package, create an issue or PR.
137
+ - Works on **iOS** and **Android**
138
+ - Supports **custom icons**, SVG or any JSX via `renderIcon`
139
+ - Fully customizable styles
140
+ - TypeScript supported
113
141
 
114
142
  ---
115
143
 
116
- ## 🪪 License
144
+ ## 📄 License
117
145
 
118
- MIT © 2025 @rn-components-dropdown
146
+ MIT
@@ -75,7 +75,7 @@ const DropdownComponent = (props) => {
75
75
  </AppText_1.default>) : (<react_native_1.View style={styles.showMultiSelectContainer}>
76
76
  <react_native_1.ScrollView showsVerticalScrollIndicator={false}>
77
77
  <react_native_1.View style={styles.wraps}>
78
- {currentValue?.map?.((i) => (<Chip_1.default label={i.name} chipColor={'red'} textColor={'white'} key={i?.[valueField]} onClearPress={() => onClearPress(i)}/>))}
78
+ {currentValue?.map?.((i) => (<Chip_1.default chipColor={'red'} textColor={'white'} key={i?.[valueField]} label={i?.[labelField]} onClearPress={() => onClearPress(i)}/>))}
79
79
  </react_native_1.View>
80
80
  </react_native_1.ScrollView>
81
81
  </react_native_1.View>)}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- export { default as AppText } from './components/text/AppText';
2
1
  export { default as Dropdown } from './components/dropdown/Dropdown';
3
- export { default as TextInput } from './components/textInput/AppTextInput';
4
2
  export { default as DropdownController } from './controller/dropDownController/DropdownController';
5
- export { default as TextInputController } from './controller/textInputController/AppTextInputController';
package/dist/index.js CHANGED
@@ -3,14 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TextInputController = exports.DropdownController = exports.TextInput = exports.Dropdown = exports.AppText = void 0;
7
- var AppText_1 = require("./components/text/AppText");
8
- Object.defineProperty(exports, "AppText", { enumerable: true, get: function () { return __importDefault(AppText_1).default; } });
6
+ exports.DropdownController = exports.Dropdown = void 0;
9
7
  var Dropdown_1 = require("./components/dropdown/Dropdown");
10
8
  Object.defineProperty(exports, "Dropdown", { enumerable: true, get: function () { return __importDefault(Dropdown_1).default; } });
11
- var AppTextInput_1 = require("./components/textInput/AppTextInput");
12
- Object.defineProperty(exports, "TextInput", { enumerable: true, get: function () { return __importDefault(AppTextInput_1).default; } });
13
9
  var DropdownController_1 = require("./controller/dropDownController/DropdownController");
14
10
  Object.defineProperty(exports, "DropdownController", { enumerable: true, get: function () { return __importDefault(DropdownController_1).default; } });
15
- var AppTextInputController_1 = require("./controller/textInputController/AppTextInputController");
16
- Object.defineProperty(exports, "TextInputController", { enumerable: true, get: function () { return __importDefault(AppTextInputController_1).default; } });
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@rn-components-dropdown/dropdown",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/Daynight-Himmat/react-components.git"
9
+ },
6
10
  "scripts": {
7
11
  "build": "tsc",
8
12
  "patch": "npm version patch",
@@ -138,10 +138,10 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
138
138
  <View style={styles.wraps}>
139
139
  {currentValue?.map?.((i: any) => (
140
140
  <Chip
141
- label={i.name}
142
141
  chipColor={'red'}
143
142
  textColor={'white'}
144
143
  key={i?.[valueField]}
144
+ label={i?.[labelField]}
145
145
  onClearPress={() => onClearPress(i)}
146
146
  />
147
147
  ))}
package/src/index.ts CHANGED
@@ -1,5 +1,2 @@
1
- export { default as AppText } from './components/text/AppText';
2
1
  export { default as Dropdown } from './components/dropdown/Dropdown';
3
- export { default as TextInput } from './components/textInput/AppTextInput';
4
- export { default as DropdownController }from './controller/dropDownController/DropdownController';
5
- export { default as TextInputController } from './controller/textInputController/AppTextInputController';
2
+ export { default as DropdownController }from './controller/dropDownController/DropdownController';
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- import { AppTextProps } from '../../components/textInput/AppTextInput';
3
- import { StyleProp, TextStyle, ViewStyle } from 'react-native';
4
- import { Control, FieldValues, Path } from 'react-hook-form';
5
- interface Props<T extends FieldValues> extends AppTextProps {
6
- textStyle?: TextStyle;
7
- controllerName: Path<T>;
8
- containerStyle?: ViewStyle;
9
- control: Control<T> | undefined;
10
- labelStyle?: StyleProp<TextStyle>;
11
- }
12
- declare const AppTextControlInput: <T extends FieldValues>({ control, textStyle, labelStyle, controllerName, containerStyle, ...rest }: Props<T>) => React.JSX.Element;
13
- export default AppTextControlInput;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
7
- const AppTextInput_1 = __importDefault(require("../../components/textInput/AppTextInput"));
8
- const InputControllerStyle_1 = require("./InputControllerStyle");
9
- const react_hook_form_1 = require("react-hook-form");
10
- const AppTextControlInput = ({ control, textStyle, labelStyle, controllerName, containerStyle, ...rest }) => {
11
- const { styles } = (0, InputControllerStyle_1.useInputController)();
12
- return (<react_hook_form_1.Controller control={control} name={controllerName} render={({ fieldState: { error }, field: { onChange, value, onBlur }, }) => (<AppTextInput_1.default value={value} onBlur={onBlur} error={error?.message} onChangeText={onChange} textStyle={[styles.inputText, textStyle]} labelStyle={[styles.labelText, labelStyle]} style={[styles.inputControlContainer, containerStyle]} {...rest}/>)}/>);
13
- };
14
- exports.default = AppTextControlInput;
@@ -1,31 +0,0 @@
1
- export declare const useInputController: () => {
2
- styles: {
3
- labelText: {
4
- color: string;
5
- };
6
- inputControlContainer: {
7
- height: number;
8
- borderWidth: number;
9
- borderRadius: number;
10
- alignItems: "center";
11
- marginVertical: number;
12
- borderColor: string;
13
- };
14
- inputText: {
15
- color: string;
16
- };
17
- };
18
- colors: {
19
- blue: string;
20
- gray: string;
21
- error: string;
22
- green: string;
23
- white: string;
24
- black: string;
25
- primary: string;
26
- lightGray: string;
27
- grayishBlue: string;
28
- red: string;
29
- border: string;
30
- };
31
- };
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useInputController = void 0;
4
- const react_1 = require("react");
5
- const react_native_1 = require("react-native");
6
- const style_1 = require("../../style");
7
- const useInputController = () => {
8
- const { ...colors } = style_1.LIGHT_COLORS;
9
- const styles = (0, react_1.useMemo)(() => {
10
- return react_native_1.StyleSheet.create({
11
- labelText: {
12
- color: colors.gray,
13
- },
14
- inputControlContainer: {
15
- height: 48,
16
- borderWidth: 1,
17
- borderRadius: 6,
18
- alignItems: 'center',
19
- marginVertical: style_1.SPACING.s2,
20
- borderColor: colors.border,
21
- },
22
- inputText: {
23
- color: colors.black,
24
- },
25
- });
26
- }, [colors]);
27
- return { styles, colors };
28
- };
29
- exports.useInputController = useInputController;
@@ -1,50 +0,0 @@
1
- import React from 'react';
2
- import AppTextInput, {
3
- AppTextProps,
4
- } from '../../components/textInput/AppTextInput';
5
- import { useInputController } from './InputControllerStyle';
6
- import { StyleProp, TextStyle, ViewStyle } from 'react-native';
7
- import { Controller, Control, FieldValues, Path } from 'react-hook-form';
8
-
9
- interface Props<T extends FieldValues> extends AppTextProps {
10
- textStyle?: TextStyle;
11
- controllerName: Path<T>;
12
- containerStyle?: ViewStyle;
13
- control: Control<T> | undefined;
14
- labelStyle?: StyleProp<TextStyle>;
15
- }
16
-
17
- const AppTextControlInput = <T extends FieldValues>({
18
- control,
19
- textStyle,
20
- labelStyle,
21
- controllerName,
22
- containerStyle,
23
- ...rest
24
- }: Props<T>) => {
25
- const { styles } = useInputController();
26
-
27
- return (
28
- <Controller
29
- control={control}
30
- name={controllerName}
31
- render={({
32
- fieldState: { error },
33
- field: { onChange, value, onBlur },
34
- }) => (
35
- <AppTextInput
36
- value={value}
37
- onBlur={onBlur}
38
- error={error?.message}
39
- onChangeText={onChange}
40
- textStyle={[styles.inputText, textStyle]}
41
- labelStyle={[styles.labelText, labelStyle]}
42
- style={[styles.inputControlContainer, containerStyle]}
43
- {...rest}
44
- />
45
- )}
46
- />
47
- );
48
- };
49
-
50
- export default AppTextControlInput;
@@ -1,28 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { StyleSheet } from 'react-native';
3
- import { LIGHT_COLORS, SPACING } from '../../style';
4
-
5
- export const useInputController = () => {
6
- const { ...colors } = LIGHT_COLORS;
7
-
8
- const styles = useMemo(() => {
9
- return StyleSheet.create({
10
- labelText: {
11
- color: colors.gray,
12
- },
13
- inputControlContainer: {
14
- height: 48,
15
- borderWidth: 1,
16
- borderRadius: 6,
17
- alignItems: 'center',
18
- marginVertical: SPACING.s2,
19
- borderColor: colors.border,
20
- },
21
- inputText: {
22
- color: colors.black,
23
- },
24
- });
25
- }, [colors]);
26
-
27
- return { styles, colors };
28
- };