Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cpr-select

Package Overview
Dependencies
Maintainers
4
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpr-select - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

4

build/cpr-select.js

@@ -6,4 +6,4 @@ /*!

* license: MIT
* version: 1.2.5
* version: 1.3.6
*/
!function(e){function t(n){if(s[n])return s[n].exports;var i=s[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var s={};return t.m=e,t.c=s,t.p="",t(0)}([function(e,t,s){"use strict";function n(e,t){for(var s,n=!0;n;){n=!1;var i=e,o=t;if(!i)return!1;if(s=i.className.indexOf(o)>-1)return s;e=i.parentElement,t=o,n=!0}}var i=function(e){return e&&e.__esModule?e["default"]:e},o=i(s(1)),l=s(2).findIndex,a="",c=void 0,r=o.createClass({displayName:"CanopySelect",componentWillMount:function(){document.body.addEventListener("click",this.state.close)},componentWillUnmount:function(){document.body.removeEventListener("click",this.state.close)},getInitialState:function(){var e=this,t=null;return this.props.selected&&(t=this.getIndex(this.props.selected)),{dialogDisplayed:!1,top:0,focused:!1,close:function(t){n(t.target,"cp-select-outer")||e.setState({dialogDisplayed:!1,focused:!1})}}},displayDialog:function(e){this.setState({dialogDisplayed:!0})},getIndex:function(e){return l(this.props.options,{key:e})},onKeyDown:function(e){var t=e.which,s=this.state.selectedIndex;9!==t&&e.preventDefault(),13===t?this.selectItem(s):38===t?this.setState({dialogDisplayed:!0,selectedIndex:void 0===s?0:s-1}):40===t?s===this.props.options.length-1?this.setState({dialogDisplayed:!0}):this.setState({dialogDisplayed:!0,selectedIndex:s?s+1:0}):27===t?this.setState({dialogDisplayed:!1}):this.highlightByText(e.which)},triggerItemChange:function(){this.props.onChange&&this.props.onChange.call(null,this.props.options[this.state.selectedIndex].key,this.props.options[this.state.selectedIndex],this.state.selectedIndex)},selectItem:function(e,t){var s=this;setTimeout(function(){s.setState({selectedIndex:e,focused:!0,dialogDisplayed:!1}),setTimeout(s.triggerItemChange)})},positionDialogAndGetTop:function(e,t){var s=e.length-t;return t>5&&6>s?e.length<11?-2+(36*t*-1-10)+"px":(this.positionDialog(t),-215-36*(5-s)+"px"):t>5?(this.positionDialog(t),"-203px"):-1+(36*t*-1-10)+"px"},positionDialog:function(e){var t=this;setTimeout(function(){var s=t.el.querySelector(".cp-select__menu");s&&(s.scrollTop=36*e-192)})},focusSelect:function(){this.state.focused||this.setState({focused:!0})},onBlur:function(){this.setState({focused:!1})},highlightByText:function(e){a+=String.fromCharCode(e);var t=this.getIndexFromString(a);t>-1&&this.selectItem(t),clearTimeout(c),c=setTimeout(function(){a=""},1e3)},getIndexFromString:function(e){var t=this;return e=e.toLowerCase(),l(this.props.options,function(s){return null!==t.getViewValue(s)?0===t.getViewValue(s).toLowerCase().indexOf(e):!1})},getViewValue:function(e){return null===e.value?null:e.value||e},getDialog:function(e,t){var s=this;if(e){var n=function(){var e=s.state.selectedIndex,n=t.map(function(t,n){return o.createElement("li",{key:t.key,className:e===n?"+selected":"",onMouseDown:s.selectItem.bind(s,n)},o.createElement("a",{style:null!==t.value?{}:{color:"rgba(0,0,0,0)"}},null!==t.value?t.value:"null"))});return setTimeout(function(){try{s.el.querySelector(".cp-select__hidden-input").focus()}catch(e){if(-1===e.message.indexOf("Invariant Violation"))throw new Error(e.message)}},100),{v:o.createElement("div",null,o.createElement("ul",{className:"cp-select__menu cps-dropdown-menu",style:{top:s.positionDialogAndGetTop(t,e)}},n))}}();if("object"==typeof n)return n.v}},render:function(){var e="cp-select",t=this.props.options[this.getIndex(this.props.selected)],s=this;return this.props.disabled&&(e+=" +disabled"),this.state.focused&&(e+=" +focus"),o.createElement("div",{ref:function(e){e&&(s.el=e)},className:"cp-select-outer",role:"select"},o.createElement("input",{className:"cp-select__hidden-input",onFocus:this.focusSelect,onBlur:this.onBlur,onKeyDown:this.onKeyDown}),o.createElement("div",{className:e,onClick:this.displayDialog},o.createElement("div",{className:"cp-select__selected"},t?t.value:this.props.placeholder),o.createElement("div",{className:"cp-select__icon"})),this.getDialog(this.state.dialogDisplayed,this.props.options))}});window&&!window.CanopySelect&&(window.CanopySelect=r),e.exports=r},function(e,t,s){e.exports=React},function(e,t,s){e.exports=_}]);
!function(e){function t(i){if(n[i])return n[i].exports;var s=n[i]={exports:{},id:i,loaded:!1};return e[i].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e,t){for(var n,i=!0;i;){i=!1;var s=e,o=t;if(!s)return!1;if(n=s===o)return n;e=s.parentElement,t=o,i=!0}}var s=function(e){return e&&e.__esModule?e["default"]:e},o=s(n(1)),l=n(2).findIndex,a="",c=void 0,r=o.createClass({displayName:"CanopySelect",componentWillMount:function(){document.body.addEventListener("click",this.state.close)},componentWillUnmount:function(){document.body.removeEventListener("click",this.state.close)},getInitialState:function(){var e=this,t=null;return this.props.selected&&(t=this.getIndex(this.props.selected)),{dialogDisplayed:!1,top:0,focused:!1,close:function(t){i(t.target,e.el)||e.setState({dialogDisplayed:!1,focused:!1})}}},displayDialog:function(e){this.setState({dialogDisplayed:!0})},getIndex:function(e){return l(this.props.options,{key:e})},onKeyDown:function(e){var t=e.which,n=this.state.selectedIndex;9!==t&&e.preventDefault(),13===t?this.selectItem(n):38===t?this.setState({dialogDisplayed:!0,selectedIndex:void 0===n?0:n-1}):40===t?n===this.props.options.length-1?this.setState({dialogDisplayed:!0}):this.setState({dialogDisplayed:!0,selectedIndex:n?n+1:0}):27===t?this.setState({dialogDisplayed:!1}):this.highlightByText(e.which)},triggerItemChange:function(){this.props.onChange&&this.props.onChange.call(null,this.props.options[this.state.selectedIndex].key,this.props.options[this.state.selectedIndex],this.state.selectedIndex)},selectItem:function(e,t){var n=this;setTimeout(function(){n.setState({selectedIndex:e,focused:!0,dialogDisplayed:!1}),setTimeout(n.triggerItemChange)})},positionDialogAndGetTop:function(e,t){var n=e.length-t;return t>5&&6>n?e.length<11?-2+(36*t*-1-10)+"px":(this.positionDialog(t),-215-36*(5-n)+"px"):t>5?(this.positionDialog(t),"-203px"):-1+(36*t*-1-10)+"px"},positionDialog:function(e){var t=this;setTimeout(function(){var n=t.el.querySelector(".cp-select__menu");n&&(n.scrollTop=36*e-192)})},focusSelect:function(){this.state.focused||this.setState({focused:!0})},onBlur:function(){this.setState({focused:!1})},highlightByText:function(e){a+=String.fromCharCode(e);var t=this.getIndexFromString(a);t>-1&&this.selectItem(t),clearTimeout(c),c=setTimeout(function(){a=""},1e3)},getIndexFromString:function(e){var t=this;return e=e.toLowerCase(),l(this.props.options,function(n){return null!==t.getViewValue(n)?0===t.getViewValue(n).toLowerCase().indexOf(e):!1})},getViewValue:function(e){return null===e.value?null:e.value||e},getDialog:function(e,t){var n=this;if(e){var i=function(){var e=n.state.selectedIndex,i=t.map(function(t,i){return o.createElement("li",{key:t.key,className:e===i?"+selected":"",onMouseDown:n.selectItem.bind(n,i)},o.createElement("a",{style:null!==t.value?{}:{color:"rgba(0,0,0,0)"}},null!==t.value?t.value:"null"))});return setTimeout(function(){try{n.el.querySelector(".cp-select__hidden-input").focus()}catch(e){if(-1===e.message.indexOf("Invariant Violation"))throw new Error(e.message)}},100),{v:o.createElement("div",null,o.createElement("ul",{className:"cp-select__menu cps-dropdown-menu",style:{top:n.positionDialogAndGetTop(t,e)}},i))}}();if("object"==typeof i)return i.v}},render:function(){var e="cp-select",t=this.props.options[this.getIndex(this.props.selected)],n=this;return this.props.disabled&&(e+=" +disabled"),this.state.focused&&(e+=" +focus"),o.createElement("div",{ref:function(e){e&&(n.el=e)},className:"cp-select-outer",role:"select"},o.createElement("input",{className:"cp-select__hidden-input",onFocus:this.focusSelect,onBlur:this.onBlur,onKeyDown:this.onKeyDown}),o.createElement("div",{className:e,onClick:this.displayDialog},o.createElement("div",{className:"cp-select__selected"},t?t.value:this.props.placeholder),o.createElement("div",{className:"cp-select__icon"})),this.getDialog(this.state.dialogDisplayed,this.props.options))}});"undefined"!=typeof window&&window&&!window.CanopySelect&&(window.CanopySelect=r),e.exports=r},function(e,t,n){e.exports=React},function(e,t,n){e.exports=_}]);

@@ -25,3 +25,3 @@ 'use strict';

var element = _x,
className = _x2;
el = _x2;
_again = false;

@@ -31,3 +31,3 @@

if (_left = element.className.indexOf(className) > -1) {
if (_left = element === el) {
return _left;

@@ -37,3 +37,3 @@ }

_x = element.parentElement;
_x2 = className;
_x2 = el;
_again = true;

@@ -69,3 +69,3 @@ continue _function;

close: function close(e) {
if (!nearest(e.target, 'cp-select-outer')) {
if (!nearest(e.target, _this.el)) {
_this.setState({

@@ -310,5 +310,5 @@ dialogDisplayed: false,

if (window && !window.CanopySelect) window.CanopySelect = CanopySelect;
if (typeof window !== "undefined" && window && !window.CanopySelect) window.CanopySelect = CanopySelect;
exports['default'] = CanopySelect;
module.exports = exports['default'];

@@ -5,3 +5,3 @@ {

"history@1.17.0",
"/home/blittle/dev/cpr-select/node_modules/canopy-styleguide"
"/Users/joel/workplace/cpr-select/node_modules/canopy-styleguide"
]

@@ -36,3 +36,3 @@ ],

"_spec": "history@1.17.0",
"_where": "/home/blittle/dev/cpr-select/node_modules/canopy-styleguide",
"_where": "/Users/joel/workplace/cpr-select/node_modules/canopy-styleguide",
"authors": [

@@ -102,4 +102,4 @@ "Michael Jackson"

{
"name": "mjackson",
"email": "mjijackson@gmail.com"
"email": "mjijackson@gmail.com",
"name": "mjackson"
}

@@ -106,0 +106,0 @@ ],

{
"name": "cpr-select",
"version": "1.3.1",
"version": "1.4.0",
"description": "A consistently styled cross-browser and keyboard friendly select component",

@@ -11,3 +11,3 @@ "main": "lib/select.js",

"build": "npm run dist && npm run compile",
"pre-publish": "npm run build"
"prepublish": "npm run compile"
},

@@ -14,0 +14,0 @@ "sofe": {

@@ -17,2 +17,9 @@ cpr-select [![Build Status](https://travis-ci.org/CanopyTax/cpr-select.png?branch=master)](https://travis-ci.org/CanopyTax/cpr-select)

### Props
+ `selected`: the key of the currently selected item
+ `options`: the items to select from
+ `onChange`: called when selected item changes
+ `disabled`: pass true to disable the input
+ `placeholder`: placeholder for input
### Basic

@@ -19,0 +26,0 @@ ```jsx

@@ -7,5 +7,5 @@ import React from 'react';

function nearest(element, className) {
function nearest(element, el) {
if (!element) return false;
return element.className.indexOf(className) > -1 || nearest(element.parentElement, className);
return element === el || nearest(element.parentElement, el);
}

@@ -35,3 +35,3 @@

close: (e) => {
if (!nearest(e.target, 'cp-select-outer')) {
if (!nearest(e.target, this.el)) {
this.setState({

@@ -247,4 +247,4 @@ dialogDisplayed: false,

if (window && !window.CanopySelect) window.CanopySelect = CanopySelect;
if (typeof window !== "undefined" && window && !window.CanopySelect) window.CanopySelect = CanopySelect;
export default CanopySelect;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc