|
1 | 1 | # Advanced Usage
|
2 | 2 |
|
3 |
| -You can customize, `PaperSelect` as per your requirement. Some of the customization options are: |
4 |
| - |
5 |
| -* `textInputMode` - you have two material options to choose from `flat` and `outlined` . See [`screenshot`](broken-reference). |
6 |
| -* `modalDoneButtonText` - you can change the modal's button text in your language. |
7 |
| -* `theme` - you can change the colour of the placeholder/label using: |
8 |
| - * ``` |
9 |
| - theme={{colors: {placeholder: 'black'}}} |
10 |
| - ``` |
11 |
| -
|
12 |
| -```typescript |
13 |
| - // theme={{colors: {placeholder: 'black'}}} |
14 |
| - // changes the label/placeholder color whereas |
15 |
| - // outlineColor changes the border color |
| 3 | +You can customize, `PaperSelect` as per your requirement. You can view a list of customization options at the [API](api.md) page. |
| 4 | + |
| 5 | +## Translations |
| 6 | +Static texts like the button texts, "Select all", the search placeholder can all be replaced through their respective properties: |
| 7 | +- `label`: The actual label shown on the TextInput |
| 8 | +- `dialogTitle`: The title shown in the dialog, this defaults to the label defined above |
| 9 | +- `selectAllText`: The text shown on the "Select all" checkbox in the dialog, only will have an effect when `multiEnable` is true. |
| 10 | +- `searchText`: The text shown in the searchbar placeholder |
| 11 | +- `dialogCloseButtonText`: The text shown in the close button of the dialog. |
| 12 | +- `dialogDoneButtonText`: The text shown in the done button of the dialog. |
| 13 | +- `errorText`: A piece of text shown below the TextInput when you want to indicate an error has occured with your item selection. |
| 14 | + |
| 15 | +## Overriding the theme |
| 16 | +Like with most react-native-paper components, the theme can be overridden on a per component basis. |
| 17 | +We utilize this method too, however the theme is applied to all sub-components below the container component. |
| 18 | +If you need to set specific styles of certain components, you can find them in any of the `...Style` properties. |
| 19 | + |
| 20 | +The theme can be provided in any possible configuration you can use in regular react-native-paper components, MD2/MD3 - Light/Dark. |
| 21 | +By default it will use the theme as provided by the `PaperProvider`. |
| 22 | + |
| 23 | +```tsx |
| 24 | + // This component will utilize a custom primary colour |
| 25 | + <PaperProvider theme={{ colors: { primary: "blue", secondary: "green" }}}> |
| 26 | + <PaperSelect |
| 27 | + label="Select Gender" |
| 28 | + value={gender.value} |
| 29 | + onSelection={(value: any) => { |
| 30 | + setGender({ |
| 31 | + ...gender, |
| 32 | + value: value.text, |
| 33 | + selectedList: value.selectedList |
| 34 | + }); |
| 35 | + }} |
| 36 | + arrayList={[...gender.list]} |
| 37 | + selectedArrayList={[...gender.selectedList]} |
| 38 | + multiEnable={false} |
| 39 | + theme={{ |
| 40 | + colors: { |
| 41 | + primary: 'black' |
| 42 | + } |
| 43 | + }} |
| 44 | + /> |
| 45 | + </PaperProvider> |
| 46 | +``` |
| 47 | + |
| 48 | +```tsx |
| 49 | + // This component will utilize the default theme as provided by the PaperProvider |
| 50 | + <PaperProvider theme={{ colors: { primary: "blue", secondary: "green" }}}> |
| 51 | + <PaperSelect |
| 52 | + label="Select Gender" |
| 53 | + value={gender.value} |
| 54 | + onSelection={(value: any) => { |
| 55 | + setGender({ |
| 56 | + ...gender, |
| 57 | + value: value.text, |
| 58 | + selectedList: value.selectedList |
| 59 | + }); |
| 60 | + }} |
| 61 | + arrayList={[...gender.list]} |
| 62 | + selectedArrayList={[...gender.selectedList]} |
| 63 | + multiEnable={false} |
| 64 | + /> |
| 65 | + </PaperProvider> |
| 66 | +``` |
| 67 | + |
| 68 | +### Overriding components properties |
| 69 | +Currently we support 2 different properties for overriding additional component properties, these are: |
| 70 | +- `textInputProps`: Passes additional properties to the <TextInput> element where the selected value(s) are shown. |
| 71 | +- `checkboxProps`: Passes additional properties to the <CheckBox> elements used for picking items in the dialog, aswell as the "Select all" option. |
| 72 | +- `searchbarProps`: Passes additional properties to the <Searchbar> element used for searching in the possible items. |
| 73 | + |
| 74 | +```tsx |
16 | 75 | <PaperSelect
|
17 | 76 | label="Select Gender"
|
18 | 77 | value={gender.value}
|
19 | 78 | onSelection={(value: any) => {
|
20 | 79 | setGender({
|
21 | 80 | ...gender,
|
22 | 81 | value: value.text,
|
23 |
| - selectedList: value.selectedList, |
24 |
| - error: '', |
| 82 | + selectedList: value.selectedList |
25 | 83 | });
|
26 | 84 | }}
|
27 | 85 | arrayList={[...gender.list]}
|
28 | 86 | selectedArrayList={[...gender.selectedList]}
|
29 |
| - errorText={gender.error} |
30 | 87 | multiEnable={false}
|
31 |
| - outlineColor="black" |
32 |
| - theme={{ |
33 |
| - colors: { |
34 |
| - placeholder: 'black' |
35 |
| - } |
| 88 | + textInputProps={{ |
| 89 | + underlineColor: "red", |
| 90 | + left: <IconButton icon="delete" onPress={() => setGender(undefined)} /> |
| 91 | + }} |
| 92 | + checkboxProps={{ |
| 93 | + checkboxColor: "purple", |
| 94 | + checkboxUncheckedColor: "gold" |
| 95 | + }} |
| 96 | + searchbarProps={{ |
| 97 | + iconColor: "brown" |
36 | 98 | }}
|
37 | 99 | />
|
38 | 100 | ```
|
39 |
| - |
40 |
| - |
41 |
| - |
42 |
| -For more options, see [`Customizations`](customizations.md) |
43 |
| - |
44 |
| -Check out the [`Example`](../example.md#code) code for advance usage. |
|
0 commit comments