Skip to content

Commit

Permalink
Add prop for rendering a header above the list
Browse files Browse the repository at this point in the history
  • Loading branch information
asdolo authored and mikaello committed Sep 10, 2021
1 parent 16b14dd commit 852b575
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Prop | Type | Optional | Default | Description
`enableShortPress` | bool | Yes | true | enables short press. This is regular touch behavior.
`enableLongPress` | bool | Yes | false | enables long press. When true, `onModalOpen` returns `{longPress: true}`
`optionsTestIDPrefix` | string | Yes | `'default'` | This prefixes each selectable option's testID prop if no testID keys are provided in `props.data` array objects. Default for each option's testID: 'default-\<optionLabel\>'
`header` | node | Yes | undefined | Render a header above the list

### Methods

Expand Down
23 changes: 23 additions & 0 deletions SampleApp/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ export const SampleApp = () => {
}}
componentExtractor={(option) => <ListItem data={option} />}
/>

{/* With a fixed header at the top of the list */}
<ModalSelector
data={countryList}
keyExtractor={(x) => x.name}
labelExtractor={(x) => x.name}
initValue="listType without FlatList"
initValueTextStyle={{ color: "black" }}
selectStyle={{ borderColor: "black" }}
selectTextStyle={{ color: "blue" }}
onChange={(option) => {
setTextInputValue(option.name);
}}
componentExtractor={(option) => <ListItem data={option} />}
header={
<View style={{ padding: 16, alignItems: 'center' }}>
<Text style={{ fontSize: 16, color: 'black' }}>What country would you pick?</Text>
<Text style={{ fontSize: 13, color: '#bbbbbb' }}>
Please, select an option
</Text>
</View>
}
/>
</View>
);
};
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ interface IModalSelectorProps<TOption> {
* Default for each option's testID: 'default-<optionLabel>'
*/
optionsTestIDPrefix?: string;

/**
* Render a header above the list
*/
header?: React.ReactNode;

}

Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const propTypes = {
enableShortPress: PropTypes.bool,
enableLongPress: PropTypes.bool,
optionsTestIDPrefix: PropTypes.string,
header: PropTypes.node,
};

const defaultProps = {
Expand Down Expand Up @@ -130,6 +131,7 @@ const defaultProps = {
enableShortPress: true,
enableLongPress: false,
optionsTestIDPrefix: 'default',
header: undefined,
};

export default class ModalSelector extends React.Component {
Expand Down Expand Up @@ -278,6 +280,7 @@ export default class ModalSelector extends React.Component {
cancelStyle,
cancelTextStyle,
cancelText,
header,
} = this.props;

let options = data.map((item, index) => {
Expand Down Expand Up @@ -310,6 +313,7 @@ export default class ModalSelector extends React.Component {
<Overlay {...overlayProps}>
<View style={[styles.overlayStyle, overlayStyle]}>
<View style={[styles.optionContainer, optionContainerStyle]}>
{header}
{listType === 'FLATLIST'?
<FlatList
data={data}
Expand Down

0 comments on commit 852b575

Please sign in to comment.