design-react-kit 5.0.0-6 → 5.0.0-8

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/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Alert as Alert$1, Button as Button$1, Badge as Badge$1, Breadcrumb as Breadcrumb$1, Card as Card$1, CardBody as CardBody$1, CardTitle as CardTitle$1, CardText as CardText$1, Collapse as Collapse$1, NavbarBrand, Navbar, Container, Row, Col, NavbarToggler, Nav as Nav$1, UncontrolledDropdown, DropdownToggle, DropdownMenu, Modal as Modal$1, ModalBody as ModalBody$1, ModalFooter as ModalFooter$1, FormGroup, Label, Input as Input$1, Dropdown } from 'reactstrap';
2
2
  export { BreadcrumbItem, ButtonDropdown, ButtonGroup, ButtonToolbar, CardColumns, CardDeck, CardFooter, CardGroup, CardHeader, CardImg, CardImgOverlay, CardLink, CardSubtitle, Col, Container, Dropdown, DropdownItem, DropdownMenu, DropdownToggle, Fade, Form, FormFeedback, FormGroup, FormText, InputGroup, InputGroupText, Label, ListGroup, ListGroupItem, ListGroupItemHeading, ListGroupItemText, Media, NavItem, NavLink, Navbar, NavbarBrand, NavbarToggler, PaginationItem as PagerItem, PaginationLink as PagerLink, Popover, PopoverBody, PopoverHeader, Row, TabContent, TabPane, Table, Tooltip, UncontrolledAlert, UncontrolledButtonDropdown, UncontrolledCollapse, UncontrolledDropdown, UncontrolledTooltip, Util } from 'reactstrap';
3
3
  export { useNavScroll } from 'react-use-navscroll';
4
- import React__default, { useState, useCallback, useEffect, useLayoutEffect, createContext, useContext, Fragment } from 'react';
4
+ import React__default, { useState, useCallback, useEffect, useLayoutEffect, createContext, useContext, useRef, Fragment } from 'react';
5
5
  import classNames from 'classnames';
6
6
  import { Transition } from 'react-transition-group';
7
7
  import { StickyProvider, Sticky } from 'react-stickup';
@@ -2245,6 +2245,7 @@ const InputContainer = _ref => {
2245
2245
  infoText,
2246
2246
  testId,
2247
2247
  activeClass,
2248
+ extraLabelClass,
2248
2249
  label,
2249
2250
  validationTextClass,
2250
2251
  validationText,
@@ -2254,10 +2255,10 @@ const InputContainer = _ref => {
2254
2255
  return React__default.createElement("div", {
2255
2256
  className: wrapperClass,
2256
2257
  "data-testid": testId
2257
- }, children, React__default.createElement("label", {
2258
+ }, React__default.createElement("label", {
2258
2259
  htmlFor: id,
2259
- className: activeClass
2260
- }, label), infoText && React__default.createElement("small", {
2260
+ className: activeClass + ' ' + extraLabelClass
2261
+ }, label), children, infoText && React__default.createElement("small", {
2261
2262
  id: infoId,
2262
2263
  className: 'form-text'
2263
2264
  }, infoText), React__default.createElement("div", {
@@ -2357,10 +2358,14 @@ function getClasses(className, type, _ref4, cssModule) {
2357
2358
  const activeClass = mapToCssModules(classNames({
2358
2359
  active: isFocused || placeholder || value || ['date', 'time'].includes(type)
2359
2360
  }), cssModule);
2361
+ const extraLabelClass = mapToCssModules(classNames({
2362
+ 'input-number-label': ['number', 'currency', 'adaptive', 'percentage'].includes(type)
2363
+ }));
2360
2364
  return {
2361
2365
  wrapperClass,
2362
2366
  inputClasses,
2363
2367
  activeClass,
2368
+ extraLabelClass,
2364
2369
  validationTextClass
2365
2370
  };
2366
2371
  }
@@ -2396,10 +2401,13 @@ const Input = _ref => {
2396
2401
  state,
2397
2402
  tag,
2398
2403
  addon,
2404
+ addonText,
2399
2405
  static: staticInput,
2400
2406
  plaintext,
2401
2407
  innerRef,
2402
2408
  label,
2409
+ incrementLabel,
2410
+ decrementLabel,
2403
2411
  validationText,
2404
2412
  infoText,
2405
2413
  placeholder,
@@ -2426,6 +2434,18 @@ const Input = _ref => {
2426
2434
  setHidden(!isHidden);
2427
2435
  toggleIcon(!hasIcon);
2428
2436
  }, [hasIcon, isHidden]);
2437
+ const divResizeRef = useRef(null);
2438
+ const inputRef = useRef(null);
2439
+ const [width, setWidth] = useState('100');
2440
+ useEffect(() => {
2441
+ if (divResizeRef.current != null && divResizeRef.current.classList.contains('input-number-adaptive')) {
2442
+ if (!value) {
2443
+ setWidth(`calc(70px)`);
2444
+ } else {
2445
+ setWidth(`calc(70px + ${`${value}`.length}ch)`);
2446
+ }
2447
+ }
2448
+ }, [value]);
2429
2449
  let {
2430
2450
  bsSize,
2431
2451
  valid,
@@ -2438,6 +2458,7 @@ const Input = _ref => {
2438
2458
  staticInput,
2439
2459
  type
2440
2460
  });
2461
+ addon = addonText != null ? true : addon;
2441
2462
  const formControlClass = getFormControlClass({
2442
2463
  plaintext,
2443
2464
  staticInput,
@@ -2477,6 +2498,7 @@ const Input = _ref => {
2477
2498
  // Styling
2478
2499
  const {
2479
2500
  activeClass,
2501
+ extraLabelClass,
2480
2502
  validationTextClass,
2481
2503
  inputClasses,
2482
2504
  wrapperClass
@@ -2509,6 +2531,7 @@ const Input = _ref => {
2509
2531
  infoId,
2510
2532
  infoText,
2511
2533
  activeClass,
2534
+ extraLabelClass,
2512
2535
  label,
2513
2536
  validationTextClass,
2514
2537
  validationText,
@@ -2522,6 +2545,61 @@ const Input = _ref => {
2522
2545
  "data-testid": testId
2523
2546
  }));
2524
2547
  }
2548
+ const clickIncrDecr = mode => {
2549
+ var _inputRef$current, _inputRef$current2, _inputRef$current3, _inputRef$current4, _Object$getOwnPropert, _inputRef$current5;
2550
+ var step = parseFloat((_inputRef$current = inputRef.current) != null && _inputRef$current.step ? inputRef.current.step : '1');
2551
+ const min = parseFloat((_inputRef$current2 = inputRef.current) != null && _inputRef$current2.min ? inputRef.current.min : 'Nan');
2552
+ const max = parseFloat((_inputRef$current3 = inputRef.current) != null && _inputRef$current3.max ? inputRef.current.max : 'Nan');
2553
+ step = isNaN(step) ? 1 : step;
2554
+ const newValue = parseFloat((_inputRef$current4 = inputRef.current) != null && _inputRef$current4.value ? inputRef.current.value : '0') + mode * step;
2555
+ if (!isNaN(max) && newValue > max) {
2556
+ return;
2557
+ }
2558
+ if (!isNaN(min) && newValue < min) {
2559
+ return;
2560
+ }
2561
+ const nativeInputValueSetter = (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')) == null ? void 0 : _Object$getOwnPropert.set;
2562
+ nativeInputValueSetter == null ? void 0 : nativeInputValueSetter.call(inputRef.current, `${newValue}`);
2563
+ var ev2 = new Event('input', {
2564
+ bubbles: true
2565
+ });
2566
+ (_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.dispatchEvent(ev2);
2567
+ };
2568
+ if (['currency', 'percentage', 'adaptive', 'number'].includes(type)) {
2569
+ return React__default.createElement(InputContainer, Object.assign({}, containerProps), React__default.createElement("div", {
2570
+ className: classNames({
2571
+ 'input-group': true,
2572
+ 'input-number': true,
2573
+ disabled: rest.disabled,
2574
+ 'input-number-percentage': type == 'percentage',
2575
+ 'input-number-currency': type == 'currency',
2576
+ 'input-number-adaptive': type == 'adaptive'
2577
+ }),
2578
+ style: {
2579
+ width
2580
+ },
2581
+ ref: divResizeRef
2582
+ }, ['currency', 'percentage'].includes(type) && React__default.createElement("span", {
2583
+ className: 'input-group-text fw-semibold'
2584
+ }, addonText), React__default.createElement(Tag, Object.assign({}, rest, extraAttributes, sharedAttributes, {
2585
+ className: inputClasses,
2586
+ "data-testid": testId,
2587
+ type: 'number',
2588
+ ref: inputRef
2589
+ })), React__default.createElement("span", {
2590
+ className: 'input-group-text align-buttons flex-column'
2591
+ }, React__default.createElement("button", {
2592
+ className: 'input-number-add',
2593
+ onClick: () => clickIncrDecr(1)
2594
+ }, React__default.createElement("span", {
2595
+ className: 'visually-hidden'
2596
+ }, incrementLabel || '')), React__default.createElement("button", {
2597
+ className: 'input-number-sub',
2598
+ onClick: () => clickIncrDecr(-1)
2599
+ }, React__default.createElement("span", {
2600
+ className: 'visually-hidden'
2601
+ }, decrementLabel || '')))));
2602
+ }
2525
2603
  if (placeholder) {
2526
2604
  return React__default.createElement(InputContainer, Object.assign({}, containerProps), React__default.createElement(Tag, Object.assign({}, rest, extraAttributes, sharedAttributes, {
2527
2605
  className: inputClasses,
@@ -2611,6 +2689,7 @@ const TextArea = _ref => {
2611
2689
  // Styling
2612
2690
  const {
2613
2691
  activeClass,
2692
+ extraLabelClass,
2614
2693
  validationTextClass,
2615
2694
  inputClasses,
2616
2695
  wrapperClass
@@ -2640,6 +2719,7 @@ const TextArea = _ref => {
2640
2719
  infoId,
2641
2720
  infoText,
2642
2721
  activeClass,
2722
+ extraLabelClass,
2643
2723
  label,
2644
2724
  validationTextClass,
2645
2725
  validationText,