') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - camux/react-native-multiple-select: Simple multi-select component for react-native · GitHub
Skip to content

Latest commit

History

79 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

react-native-multiple-select

npmDownloadsLicence

Simple multi-select component for react-native (Select2 for react-native).

multiplesingle

Installation

$ npm install react-native-multiple-select --save

or use yarn

$ yarn add react-native-multiple-select

Usage

Note: Ensure to add and configure react-native-vector-icons to your project before using this package.

You can clone and try out the sample app.

The snippet below shows how the component can be used

// import componentimportReact,{Component}from'react';import{View}from'react-native';importMultiSelectfrom'react-native-multiple-select';letclassMultiSelectExampleextendsComponent{this.state={
selectedItems =[];};this.items=[{id: '92iijs7yta',name: 'Ondo',},{id: 'a0s0a8ssbsd',name: 'Ogun',},{id: '16hbajsabsd',name: 'Calabar',},{id: 'nahs75a5sg',name: 'Lagos',},{id: '667atsas',name: 'Maiduguri',},{id: 'hsyasajs',name: 'Anambra',},{id: 'djsjudksjd',name: 'Benue',},{id: 'sdhyaysdj',name: 'Kaduna',},{id: 'suudydjsjd',name: 'Abuja',}];onSelectedItemsChange=selectedItems=>{this.setState({ selectedItems });};render(){<Viewstyle={{flex: 1}}><MultiSelectitems={items}uniqueKey="id"onSelectedItemsChange={this.onSelectedItemsChange}selectedItems={this.state.selectedItems}selectText="Pick Items"searchInputPlaceholderText="Search Items..."altFontFamily="ProximaNova-Light"tagRemoveIconColor="#CCC"tagBorderColor="#CCC"tagTextColor="#CCC"selectedItemTextColor="#CCC"selectedItemIconColor="#CCC"itemTextColor="#000"searchInputStyle={{color: '#CCC'}}submitButtonColor="#CCC"submitButtonText="Submit"/></View>}}

The component takes 3 compulsory props - items, uniqueKey and selectedItemsChange. Other props are optional. The table below explains more.

Props

PropRequiredPurpose
itemsYes(Array, control prop) List of items to display in the multi-select component. JavaScript Array of objects. Each object must contain a name and unique identifier (Check sample above)
selectedItemsNo(Array, control prop) List of selected items keys . JavaScript Array of strings, that can be instantiated with the component
uniqueKeyYes(String) Unique identifier that is part of each item's properties. Used internally as means of identifying each item (Check sample below)
textColorNo(String) Color for selected item name displayed as label for multiselect
fontSizeNo(Number) Font size for selected item name displayed as label for multiselect
fixedHeightNo(Boolean) Defaults to false. Specifies if select dropdown take height of content or a fixed height with a scrollBar (There is an issue with this behavior when component is nested in a ScrollView in which scroll event will only be dispatched to parent ScrollView and select component won't be scrollable). See this issue for more info.
singleNo(Boolean) Toggles select component between single option and multi option
onSelectedItemsChangeYes(Function) JavaScript function passed in as an argument. The function is to be defined with an argument (selectedItems). Triggered when Submit button is clicked (for multi select) or item is clicked (for single select). (Check sample above)
selectTextNo(String) Text displayed in main component
searchInputPlaceholderTextNo(String) Placeholder text displayed in multi-select filter input
fontFamilyNo(String) Custom font family to be used in component (affects all text except searchInputPlaceholderText described above)
altFontFamilyNo(String) Font family for searchInputPlaceholderText
tagRemoveIconColorNo(String) Color to be used for the remove icon in selected items list
tagBorderColorNo(String) Border color for each selected item
tagTextColorNo(String) Text color for selected items list
selectedItemFontFamilyNo(String) Font family for each selected item in multi-select drop-down
selectedItemTextColorNo(String) Text color for each selected item in multi-select drop-down
selectedItemIconColorNo(String) Color for selected check icon for each selected item in multi-select drop-down
itemFontFamilyNo(String) Font family for each non-selected item in multi-select drop-down
itemTextColorNo(String) Text color for each non-selected item in multi-select drop-down
searchInputStyleNo(Object) Style object for multi-select input element
hideSubmitButtonNo(Boolean) Defaults to false. Hide submit button from dropdown, and rather use arrow-button in search field"
submitButtonColorNo(String) Background color for submit button
submitButtonTextNo(String) Text displayed on submit button

Note

  • When using the single prop, selectedItems should still be passed in as an array of selected items keys. Also, when an item is selected in the single mode, the selected item is returned as an array of string.

  • The items props must be passed as an array of objects with a compulsory name key present in each object as the name key is used to display the items in the options component.

Removing all selected items

To use, add ref to MultiSelect component in parent component, then call method against reference. i.e.

<MultiSelectref={c=>this._multiSelect=c}.../>
clearSelectedCategories = () =>{this._multiSelect.removeAllItems();};

Contributing

Contributions are welcome and will be fully credited.

Contributions are accepted via Pull Requests on Github.

Pull Requests

  • Document any change in behaviour - Make sure the README.md and any other relevant documentation are kept up-to-date.

  • Consider our release cycle - We try to follow SemVer v2.0.0. Randomly breaking public APIs is not an option.

  • Create feature branches - Don't ask us to pull from your master branch.

  • One pull request per feature - If you want to do more than one thing, send multiple pull requests.

  • Send coherent history - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.

Issues

Check issues for current issues.

Author

Mustapha Babatunde

License

The MIT License (MIT). Please see LICENSE for more information.

About

Simple multi-select component for react-native

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages