react-ui-basics 0.0.230 → 0.0.231

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-ui-basics",
3
- "version": "0.0.230",
3
+ "version": "0.0.231",
4
4
  "description": "",
5
5
  "module": "index.js",
6
6
  "_main": "index.cjs.js",
package/router/NavLink.js CHANGED
@@ -6,6 +6,9 @@ import { classNames } from '../Tools.js';
6
6
 
7
7
  const NavLink = (props) => {
8
8
  const { href, highlightPath, className, activeClassName } = props;
9
+ const other = __extends({}, props);
10
+ delete other.activeClassName;
11
+ delete other.highlightPath;
9
12
  return jsxRuntime_2(Route, { path: highlightPath || href, controller: matches => jsxRuntime_2(Link, __extends({}, props, { [ReactConstants[5]]: classNames(className, matches && activeClassName) })) });
10
13
  };
11
14
  var NavLink$1 = NavLink;
@@ -1 +1 @@
1
- {"version":3,"file":"NavLink.js","sources":["../src/router/NavLink.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;;AAYA,MAAM,OAAO,GAA2B,CAAC,KAAK,KAAI;IAC9C,MAAM,EAAC,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAC,GAAG,KAAK,CAAC;AAChE,IAAA,OAAOA,YAAC,CAAA,KAAK,EACT,EAAA,IAAI,EAAE,aAAa,IAAI,IAAI,EAC3B,UAAU,EAAE,OAAO,IAAIA,YAAA,CAAC,IAAI,EAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAK,KAAK,EAAA,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,OAAO,IAAI,eAAe,CAAC,EAAA,CAAA,CAAG,GACzG,CAAC;AACP,CAAC,CAAC;AAEF,gBAAe,OAAO;;;;"}
1
+ {"version":3,"file":"NavLink.js","sources":["../src/router/NavLink.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;;AAYA,MAAM,OAAO,GAA2B,CAAC,KAAK,KAAI;IAC9C,MAAM,EAAC,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAC,GAAG,KAAK,CAAC;AAChE,IAAA,MAAM,KAAK,GAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAO,KAAK,CAAC,CAAA;IACxB,OAAO,KAAK,CAAC,eAAe,CAAA;IAC5B,OAAO,KAAK,CAAC,aAAa,CAAA;AAE1B,IAAA,OAAOA,YAAC,CAAA,KAAK,EACT,EAAA,IAAI,EAAE,aAAa,IAAI,IAAI,EAC3B,UAAU,EAAE,OAAO,IAAIA,YAAA,CAAC,IAAI,EAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAK,KAAK,EAAA,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,OAAO,IAAI,eAAe,CAAC,EAAA,CAAA,CAAG,GACzG,CAAC;AACP,CAAC,CAAC;AAEF,gBAAe,OAAO;;;;"}
@@ -163,6 +163,7 @@ class AutocompleteSelect extends PureComponent {
163
163
  childComponent: DummyChild,
164
164
  withArrow: true,
165
165
  withFilter: true,
166
+ selectCustomOnClickOutside: true,
166
167
  withReset: false,
167
168
  scrollToValue: false,
168
169
  mode: MODE_DEFAULT,
@@ -223,7 +224,7 @@ class AutocompleteSelect extends PureComponent {
223
224
  const hasSelected = __length(selectedIds) !== 0;
224
225
  const setActive = (e) => {
225
226
  stopPropagation(e);
226
- this.setState({isActive: true}, () => (scrollToValue && __length(selectedIds) > 0) && this.list.scrollTo(selectedIds[0]));
227
+ this.setState({isActive: true}, () => (scrollToValue && __length(selectedIds) > 0) && this.list.selected(selectedIds[0]));
227
228
  };
228
229
  const toggle = (e) => {
229
230
  if (!__state(this).isActive) {
@@ -236,9 +237,9 @@ class AutocompleteSelect extends PureComponent {
236
237
 
237
238
  const isInline = mode === MODE_INLINE || mode === MODE_INLINE_MULTIPLE || mode === MODE_MULTIPLE_MINI_INLINE;
238
239
  const filterValueTrimmed = filterValue.trim();
239
- const dataFiltered = allowCustom ? [filterValueTrimmed, ...data.filter(suggestion => suggestion !== filterValueTrimmed)] : data;
240
+ const dataFiltered = allowCustom && !scrollToValue ? [filterValueTrimmed, ...data.filter(suggestion => suggestion !== filterValueTrimmed)] : data;
240
241
 
241
- const filterFunction = this.createFilter(prefilter, filterValue, filterValueTrimmed.toLowerCase(), filter)
242
+ const filterFunction = !scrollToValue ? this.createFilter(prefilter, filterValue, filterValueTrimmed.toLowerCase(), filter) : UNDEFINED
242
243
  let filteredList = <FilteredList className={classNames(isActive && 'visible', listPortal && 'portal')}
243
244
  style={listStyles}
244
245
  ref={ref('list', this)}
@@ -371,7 +372,7 @@ class AutocompleteSelect extends PureComponent {
371
372
  } else if (keyCode === 27/*esc*/) {
372
373
  this.setState({
373
374
  isActive: false,
374
- filterValue: isMultipleSelect(mode) ? '' : (allowCustom ? filterValue : ''),
375
+ filterValue: isMultipleSelect(mode) ? '' : Object.values(selected)[0] || '',
375
376
  });
376
377
  this.input.getInput().blur()
377
378
  this.onCancel();
@@ -389,14 +390,15 @@ class AutocompleteSelect extends PureComponent {
389
390
  }
390
391
 
391
392
  onClickOutside = () => {
392
- const {allowCustom, required, onFilterInputChange} = __props(this);
393
- const {filterValue} = __state(this);
394
- if (allowCustom && (!!filterValue || !required)) {
395
- this.onSelect()
393
+ const {allowCustom, required, onFilterInputChange, mode, selectCustomOnClickOutside} = __props(this);
394
+ let {filterValue, selected} = __state(this);
395
+ if (allowCustom && selectCustomOnClickOutside && (!!filterValue || !required)) {
396
+ selected = this.onSelect()
396
397
  }
397
398
 
398
- this.setState({isActive: false, filterValue: ''});
399
- onFilterInputChange && onFilterInputChange('');
399
+ filterValue = (!isMultipleSelect(mode) && Object.values(selected)[0]) || ''
400
+ this.setState({isActive: false, filterValue});
401
+ onFilterInputChange && onFilterInputChange(filterValue);
400
402
 
401
403
  this.onCancel();
402
404
  };
@@ -466,6 +468,7 @@ class AutocompleteSelect extends PureComponent {
466
468
 
467
469
  orNoop(onSelect)(selectedId);
468
470
  orNoop(onChange)(Object.values(selected));
471
+ return selected
469
472
  };
470
473
 
471
474
  clean = (e) => {
@@ -498,6 +501,11 @@ class AutocompleteSelect extends PureComponent {
498
501
  onChange = (event) => {
499
502
  const value = __target(event).value;
500
503
  this.setState({filterValue: value});
504
+ const data = __state(this).data || __props(this).data || []
505
+ if (data.indexOf(value) !== -1) {
506
+ this.list.selected(value)
507
+ }
508
+
501
509
  __props(this).onFilterInputChange?.(value);
502
510
  }
503
511
  }
@@ -37,7 +37,6 @@
37
37
  padding-right: 15px;
38
38
  cursor: pointer;
39
39
  overflow: hidden;
40
- transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
41
40
  border-left: 5px solid #4AC263;
42
41
  padding-left: 15px;
43
42
  margin-left: -5px;
@@ -44,7 +44,6 @@
44
44
  padding-right: 15px;
45
45
  cursor: pointer;
46
46
  overflow: hidden;
47
- transition: 0.2s cubic-bezier(.4, 0, .2, 1);
48
47
 
49
48
  border-left: 5px solid #4AC263;
50
49
  padding-left: 15px;
@@ -2,7 +2,7 @@ import React, {CSSProperties, MouseEventHandler} from 'react';
2
2
  import ReactCreateElement from './ReactCreateElement';
3
3
  import './FilteredList.css'
4
4
  import Scrollable from "./Scrollable";
5
- import {classNames, orNoop, ref, stopPropagation, isFunction, isObject} from "./Tools";
5
+ import {classNames, orNoop, ref, stopPropagation, isFunction, isObject, UNDEFINED} from "./Tools";
6
6
  import {PureComponent} from "./ReactConstants";
7
7
 
8
8
  type Labels<T> = ((item: T) => string) | { [key: string]: string } | { [key: number]: string };
@@ -44,9 +44,9 @@ class FilteredList<T extends string|number> extends PureComponent<FilteredListPr
44
44
  filter: () => true,
45
45
  };
46
46
 
47
- hidden:Map<T, boolean> = new Map();
48
- elements :Map<T, HTMLDivElement> = new Map();
49
- list:T[] = [];
47
+ hidden: Map<T, boolean> = new Map();
48
+ elements: Map<T, HTMLDivElement> = new Map();
49
+ list: T[] = [];
50
50
  el: Scrollable
51
51
 
52
52
  constructor(props) {
@@ -114,7 +114,12 @@ class FilteredList<T extends string|number> extends PureComponent<FilteredListPr
114
114
  this.props.onSelect(id);
115
115
  };
116
116
 
117
- selected = (): T => {
117
+ selected = (id?: T): T => {
118
+ if (id !== UNDEFINED) {
119
+ this.setState({selected: id});
120
+ this.scrollTo(id)
121
+ return id;
122
+ }
118
123
  const {selected: value} = this.state;
119
124
  const {selectSingle} = this.props;
120
125
 
@@ -144,7 +149,7 @@ class FilteredList<T extends string|number> extends PureComponent<FilteredListPr
144
149
  if (position < list.length) {
145
150
  let id = list[position];
146
151
  this.setState({selected: id});
147
- this.updateScroll(id)
152
+ this.scrollTo(id)
148
153
  }
149
154
  };
150
155
 
@@ -162,27 +167,7 @@ class FilteredList<T extends string|number> extends PureComponent<FilteredListPr
162
167
  if (position >= 0) {
163
168
  let id = list[position];
164
169
  this.setState({selected: id});
165
- this.updateScroll(id)
166
- }
167
- };
168
-
169
- updateScroll = (id) => {
170
- const child = this.elements[id];
171
- if (!child)
172
- return
173
-
174
- const container = this.el;
175
- const scrollTop = container.getScroll();
176
- const height = container.getHeight();
177
- let isVisible = scrollTop <= child.offsetTop && scrollTop + height >= child.offsetTop + child.clientHeight;
178
- if (!isVisible) {
179
- let scrollToBottom = child.offsetTop + child.clientHeight - height;
180
- let scrollToTop = child.offsetTop;
181
- if (Math.abs(scrollTop - scrollToTop) < Math.abs(scrollTop - scrollToBottom)) {
182
- container.setScroll(scrollToTop)
183
- } else {
184
- container.setScroll(scrollToBottom)
185
- }
170
+ this.scrollTo(id)
186
171
  }
187
172
  };
188
173
 
@@ -191,7 +176,10 @@ class FilteredList<T extends string|number> extends PureComponent<FilteredListPr
191
176
  this.el.setScroll(0)
192
177
  };
193
178
 
194
- scrollTo = (id) => this.el.setScroll(this.elements[id] && this.elements[id].offsetTop);
179
+ scrollTo = (id: T) => {
180
+ const child = this.elements.get(id);
181
+ child && this.el.setScroll(child.offsetTop - (this.el.getHeight() - child.clientHeight) / 2);
182
+ };
195
183
  }
196
184
 
197
185
  export default FilteredList;
@@ -12,6 +12,10 @@ export interface NavLinkProps extends LinkProps {
12
12
 
13
13
  const NavLink: React.FC<NavLinkProps> = (props) => {
14
14
  const {href, highlightPath, className, activeClassName} = props;
15
+ const other = {...props}
16
+ delete other.activeClassName
17
+ delete other.highlightPath
18
+
15
19
  return <Route
16
20
  path={highlightPath || href}
17
21
  controller={matches => <Link {...props} className={classNames(className, matches && activeClassName)}/>}