@rn-components-dropdown/dropdown 1.0.1 → 1.0.3
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 +146 -0
- package/dist/index.d.ts +0 -3
- package/dist/index.js +1 -7
- package/package.json +5 -1
- package/src/index.ts +1 -4
- package/dist/controller/textInputController/AppTextInputController.d.ts +0 -13
- package/dist/controller/textInputController/AppTextInputController.js +0 -14
- package/dist/controller/textInputController/InputControllerStyle.d.ts +0 -31
- package/dist/controller/textInputController/InputControllerStyle.js +0 -29
- package/src/controller/textInputController/AppTextInputController.tsx +0 -50
- package/src/controller/textInputController/InputControllerStyle.ts +0 -28
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @rn-components-dropdown/dropdown
|
|
2
|
+
|
|
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**.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 📦 Installation
|
|
9
|
+
|
|
10
|
+
### Install Package
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @rn-components-dropdown/dropdown
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### React Hook Form (optional — required only for DropdownController)
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install react-hook-form
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## ✨ Components Provided
|
|
25
|
+
|
|
26
|
+
This package includes two components:
|
|
27
|
+
|
|
28
|
+
### 🔹 Dropdown
|
|
29
|
+
A standalone dropdown with:
|
|
30
|
+
- Single or multi selection
|
|
31
|
+
- Custom icons
|
|
32
|
+
- Full styling customization
|
|
33
|
+
- Works independently
|
|
34
|
+
|
|
35
|
+
### 🔹 DropdownController
|
|
36
|
+
A wrapper designed for **React Hook Form**, handling form values automatically.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# 🔽 Dropdown Usage
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { Dropdown } from "@rn-components-dropdown/dropdown";
|
|
44
|
+
|
|
45
|
+
export default function MyScreen() {
|
|
46
|
+
return (
|
|
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
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
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 |
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
# 🎯 DropdownController (React Hook Form Support)
|
|
85
|
+
|
|
86
|
+
A form-friendly dropdown that automatically:
|
|
87
|
+
- updates values
|
|
88
|
+
- handles errors
|
|
89
|
+
- applies validation rules
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 📘 Usage with React Hook Form
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { useForm } from "react-hook-form";
|
|
97
|
+
import { DropdownController } from "@rn-components-dropdown/dropdown";
|
|
98
|
+
|
|
99
|
+
export default function FormScreen() {
|
|
100
|
+
const { control } = useForm();
|
|
101
|
+
|
|
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
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 🧩 DropdownController Props
|
|
124
|
+
|
|
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 |
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 📝 Notes
|
|
136
|
+
|
|
137
|
+
- Works on **iOS** and **Android**
|
|
138
|
+
- Supports **custom icons**, SVG or any JSX via `renderIcon`
|
|
139
|
+
- Fully customizable styles
|
|
140
|
+
- TypeScript supported
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## 📄 License
|
|
145
|
+
|
|
146
|
+
MIT
|
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.
|
|
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.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|
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
|
|
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
|
-
};
|