react-ui-basics 0.0.230 → 0.0.232

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.232",
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
  };
@@ -408,8 +410,9 @@ class AutocompleteSelect extends PureComponent {
408
410
  onSelect = (selectedId) => {
409
411
  const {mode, required, allowCustom, onSelect, onChange, default: defaultValue} = __props(this);
410
412
  const {filterValue, selected: currentSelection} = __state(this);
411
- const {labels = {}, onFilterInputChange} = __props(this);
413
+ const {labels = {}, onFilterInputChange, withFilter} = __props(this);
412
414
 
415
+ // debugger
413
416
  if (selectedId == null && (!!filterValue || !required) && allowCustom && (!this.input || !this.input.check()))
414
417
  selectedId = filterValue.trim();
415
418
 
@@ -450,22 +453,23 @@ class AutocompleteSelect extends PureComponent {
450
453
  customValue = label
451
454
  }
452
455
 
453
- let filterValueWithCustom = isMultiSelect ? '' : customValue;
456
+ let nextFilterValue = (!isMultipleSelect(mode) && withFilter && Object.values(selected)[0]) || ''
454
457
  this.setState({
455
458
  isActive: isActive,
456
459
  selected: selected,
457
- filterValue: filterValueWithCustom,
460
+ filterValue: nextFilterValue,
458
461
  errored,
459
462
  });
460
463
 
461
- if (filterValueWithCustom !== filterValue)
462
- orNoop(onFilterInputChange)(filterValueWithCustom)
464
+ if (nextFilterValue !== filterValue)
465
+ orNoop(onFilterInputChange)(nextFilterValue)
463
466
 
464
467
  if (isActive && this.input)
465
468
  this.input.getInput().focus()
466
469
 
467
470
  orNoop(onSelect)(selectedId);
468
471
  orNoop(onChange)(Object.values(selected));
472
+ return selected
469
473
  };
470
474
 
471
475
  clean = (e) => {
@@ -498,6 +502,13 @@ class AutocompleteSelect extends PureComponent {
498
502
  onChange = (event) => {
499
503
  const value = __target(event).value;
500
504
  this.setState({filterValue: value});
505
+ const data = __state(this).data || __props(this).data || []
506
+ if (data.indexOf(value) !== -1) {
507
+ this.list.selected(value)
508
+ } else {
509
+ this.list.reset()
510
+ }
511
+
501
512
  __props(this).onFilterInputChange?.(value);
502
513
  }
503
514
  }
@@ -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;
package/src/TextField.tsx CHANGED
@@ -13,7 +13,7 @@ export interface TextAreaProps {
13
13
  autoComplete?: string,
14
14
  placeholder?: string,
15
15
  label?: string | ReactElement,
16
- check?: (value: string) => boolean,
16
+ check?: (value: string) => boolean | string | ReactElement,
17
17
  onClick?: MouseEventHandler<HTMLInputElement>,
18
18
  onMouseUp?: MouseEventHandler<HTMLInputElement>,
19
19
  onKeyDown?: KeyboardEventHandler<HTMLInputElement>,
@@ -55,6 +55,7 @@ class TextField extends AbstractTextField {
55
55
  const {required, check} = props();
56
56
  const value = inputRef().value;
57
57
  const error = (required && value === '') || (check && check(value));
58
+ debugger
58
59
  errorState() !== error && setTimeout(errorState, 0, error);
59
60
  return error;
60
61
  };
@@ -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)}/>}