@stokr/components-library 2.3.65-beta.7 → 2.3.65-beta.9

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.WrapperWithSubTable = exports.WithoutPagination = exports.WithSubTable = exports.WithStatusBasedHover = exports.WithRowSpecificHover = exports.WithRowHover = exports.WithHoverStylesAndContent = exports.WithHoverContent = exports.WithFixedColumnWidths = exports.WithCustomStyling = exports.DefaultWrapper = exports.Default = exports.CustomStyledTable = exports.BoxStyleTable = exports.BlueWrapper = exports.BlueTable = void 0;
6
+ exports.default = exports.WrapperWithSubTable = exports.WithoutPagination = exports.WithSubTable = exports.WithStatusBasedHover = exports.WithRowSpecificHover = exports.WithRowHover = exports.WithRowClick = exports.WithHoverStylesAndContent = exports.WithHoverContent = exports.WithFixedColumnWidths = exports.WithCustomStyling = exports.SortableHeaders = exports.RowClickWithExpandedContent = exports.RowClickWithButtons = exports.PerColumnHeaderClick = exports.HeaderClick = exports.FilterableHeaders = exports.ExpandedWithRichContent = exports.DefaultWrapper = exports.Default = exports.CustomStyledTable = exports.CustomExpandedContent = exports.BoxStyleTable = exports.BlueWrapper = exports.BlueTable = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _ReactTable = require("./ReactTable");
9
9
  var _ReactTableWrapper = require("./ReactTableWrapper");
@@ -403,4 +403,511 @@ CustomStyledTable.args = _objectSpread(_objectSpread({}, Default.args), {}, {
403
403
  textTransform: 'uppercase',
404
404
  letterSpacing: '0.5px'
405
405
  })
406
- });
406
+ });
407
+
408
+ // ============================================
409
+ // NEW FEATURE STORIES: onRowClick & renderExpandedContent
410
+ // ============================================
411
+
412
+ // Row Click Handler - Basic
413
+ const WithRowClick = exports.WithRowClick = Template.bind({});
414
+ WithRowClick.args = _objectSpread(_objectSpread({}, Default.args), {}, {
415
+ onRowClick: (rowData, rowIndex, event) => {
416
+ alert("Clicked row ".concat(rowIndex + 1, ": ").concat(rowData.name, " (").concat(rowData.status, ")"));
417
+ }
418
+ });
419
+ WithRowClick.parameters = {
420
+ docs: {
421
+ description: {
422
+ story: 'Click anywhere on a row to trigger an action. Buttons and links inside cells will NOT trigger the row click.'
423
+ }
424
+ }
425
+ };
426
+
427
+ // Row Click with Buttons Inside - Demonstrates click isolation
428
+ const columnsWithActions = [...columns.slice(0, 3), {
429
+ Header: 'Actions',
430
+ accessor: 'actions',
431
+ width: '40%',
432
+ Cell: _ref => {
433
+ let {
434
+ row
435
+ } = _ref;
436
+ return /*#__PURE__*/_react.default.createElement("div", {
437
+ style: {
438
+ display: 'flex',
439
+ gap: '8px'
440
+ }
441
+ }, /*#__PURE__*/_react.default.createElement("button", {
442
+ style: {
443
+ padding: '6px 12px',
444
+ backgroundColor: '#0050ca',
445
+ color: 'white',
446
+ border: 'none',
447
+ borderRadius: '4px',
448
+ cursor: 'pointer'
449
+ },
450
+ onClick: () => alert("Edit button clicked for ".concat(row.original.name))
451
+ }, "Edit"), /*#__PURE__*/_react.default.createElement("button", {
452
+ style: {
453
+ padding: '6px 12px',
454
+ backgroundColor: '#dc3545',
455
+ color: 'white',
456
+ border: 'none',
457
+ borderRadius: '4px',
458
+ cursor: 'pointer'
459
+ },
460
+ onClick: () => alert("Delete button clicked for ".concat(row.original.name))
461
+ }, "Delete"));
462
+ }
463
+ }];
464
+ const RowClickWithButtons = exports.RowClickWithButtons = Template.bind({});
465
+ RowClickWithButtons.args = {
466
+ columns: columnsWithActions,
467
+ data: data,
468
+ noPagination: false,
469
+ onRowClick: (rowData, rowIndex) => {
470
+ alert("Row clicked: ".concat(rowData.name));
471
+ }
472
+ };
473
+ RowClickWithButtons.parameters = {
474
+ docs: {
475
+ description: {
476
+ story: 'Demonstrates that clicking buttons inside cells does NOT trigger onRowClick. Only clicking on non-interactive areas triggers the row click.'
477
+ }
478
+ }
479
+ };
480
+
481
+ // Custom Expanded Content - Simple
482
+ const CustomExpandedContent = exports.CustomExpandedContent = Template.bind({});
483
+ CustomExpandedContent.args = _objectSpread(_objectSpread({}, Default.args), {}, {
484
+ renderExpandedContent: (row, toggleExpanded) => {
485
+ var _row$original$subData;
486
+ return /*#__PURE__*/_react.default.createElement("div", {
487
+ style: {
488
+ padding: '20px',
489
+ backgroundColor: '#f8f9fa',
490
+ borderRadius: '8px'
491
+ }
492
+ }, /*#__PURE__*/_react.default.createElement("h4", {
493
+ style: {
494
+ margin: '0 0 12px 0'
495
+ }
496
+ }, "Details for ", row.original.name), /*#__PURE__*/_react.default.createElement("p", {
497
+ style: {
498
+ margin: '0 0 8px 0'
499
+ }
500
+ }, /*#__PURE__*/_react.default.createElement("strong", null, "ID:"), " ", row.original.id), /*#__PURE__*/_react.default.createElement("p", {
501
+ style: {
502
+ margin: '0 0 8px 0'
503
+ }
504
+ }, /*#__PURE__*/_react.default.createElement("strong", null, "Status:"), " ", row.original.status), /*#__PURE__*/_react.default.createElement("p", {
505
+ style: {
506
+ margin: '0 0 16px 0'
507
+ }
508
+ }, /*#__PURE__*/_react.default.createElement("strong", null, "Sub-items:"), " ", ((_row$original$subData = row.original.subData) === null || _row$original$subData === void 0 ? void 0 : _row$original$subData.length) || 0), /*#__PURE__*/_react.default.createElement("button", {
509
+ style: {
510
+ padding: '8px 16px',
511
+ backgroundColor: '#6c757d',
512
+ color: 'white',
513
+ border: 'none',
514
+ borderRadius: '4px',
515
+ cursor: 'pointer'
516
+ },
517
+ onClick: () => toggleExpanded()
518
+ }, "Collapse"));
519
+ }
520
+ });
521
+ CustomExpandedContent.parameters = {
522
+ docs: {
523
+ description: {
524
+ story: 'Click on a row to expand and show custom content instead of a sub-table. The toggleExpanded function allows you to collapse the row programmatically.'
525
+ }
526
+ }
527
+ };
528
+
529
+ // Custom Expanded Content - Rich Component
530
+ const ExpandedWithRichContent = exports.ExpandedWithRichContent = Template.bind({});
531
+ ExpandedWithRichContent.args = _objectSpread(_objectSpread({}, Default.args), {}, {
532
+ renderExpandedContent: row => {
533
+ var _row$original$subData2;
534
+ return /*#__PURE__*/_react.default.createElement("div", {
535
+ style: {
536
+ padding: '24px'
537
+ }
538
+ }, /*#__PURE__*/_react.default.createElement("div", {
539
+ style: {
540
+ display: 'grid',
541
+ gridTemplateColumns: '1fr 1fr',
542
+ gap: '24px'
543
+ }
544
+ }, /*#__PURE__*/_react.default.createElement("div", {
545
+ style: {
546
+ padding: '16px',
547
+ backgroundColor: '#fff',
548
+ border: '1px solid #e1e1e1',
549
+ borderRadius: '8px'
550
+ }
551
+ }, /*#__PURE__*/_react.default.createElement("h4", {
552
+ style: {
553
+ margin: '0 0 16px 0',
554
+ color: '#0050ca'
555
+ }
556
+ }, "User Information"), /*#__PURE__*/_react.default.createElement("div", {
557
+ style: {
558
+ display: 'flex',
559
+ flexDirection: 'column',
560
+ gap: '8px'
561
+ }
562
+ }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("strong", null, "Name:"), " ", row.original.name), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("strong", null, "ID:"), " #", row.original.id), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("strong", null, "Status:"), ' ', /*#__PURE__*/_react.default.createElement("span", {
563
+ style: {
564
+ padding: '2px 8px',
565
+ borderRadius: '12px',
566
+ backgroundColor: row.original.status === 'Active' ? '#d4edda' : row.original.status === 'Inactive' ? '#f8d7da' : '#fff3cd',
567
+ color: row.original.status === 'Active' ? '#155724' : row.original.status === 'Inactive' ? '#721c24' : '#856404',
568
+ fontSize: '12px'
569
+ }
570
+ }, row.original.status)))), /*#__PURE__*/_react.default.createElement("div", {
571
+ style: {
572
+ padding: '16px',
573
+ backgroundColor: '#fff',
574
+ border: '1px solid #e1e1e1',
575
+ borderRadius: '8px'
576
+ }
577
+ }, /*#__PURE__*/_react.default.createElement("h4", {
578
+ style: {
579
+ margin: '0 0 16px 0',
580
+ color: '#0050ca'
581
+ }
582
+ }, "Sub Items"), ((_row$original$subData2 = row.original.subData) === null || _row$original$subData2 === void 0 ? void 0 : _row$original$subData2.length) > 0 ? /*#__PURE__*/_react.default.createElement("ul", {
583
+ style: {
584
+ margin: 0,
585
+ paddingLeft: '20px'
586
+ }
587
+ }, row.original.subData.map(item => /*#__PURE__*/_react.default.createElement("li", {
588
+ key: item.detailId,
589
+ style: {
590
+ marginBottom: '8px'
591
+ }
592
+ }, item.detailName, " (ID: ", item.detailId, ")"))) : /*#__PURE__*/_react.default.createElement("p", {
593
+ style: {
594
+ margin: 0,
595
+ color: '#6c757d',
596
+ fontStyle: 'italic'
597
+ }
598
+ }, "No sub-items"))), /*#__PURE__*/_react.default.createElement("div", {
599
+ style: {
600
+ marginTop: '16px',
601
+ display: 'flex',
602
+ gap: '8px',
603
+ justifyContent: 'flex-end'
604
+ }
605
+ }, /*#__PURE__*/_react.default.createElement("button", {
606
+ style: {
607
+ padding: '8px 16px',
608
+ backgroundColor: '#0050ca',
609
+ color: 'white',
610
+ border: 'none',
611
+ borderRadius: '4px',
612
+ cursor: 'pointer'
613
+ },
614
+ onClick: () => alert("Edit ".concat(row.original.name))
615
+ }, "Edit User"), /*#__PURE__*/_react.default.createElement("button", {
616
+ style: {
617
+ padding: '8px 16px',
618
+ backgroundColor: 'transparent',
619
+ color: '#0050ca',
620
+ border: '1px solid #0050ca',
621
+ borderRadius: '4px',
622
+ cursor: 'pointer'
623
+ },
624
+ onClick: () => alert("View full profile for ".concat(row.original.name))
625
+ }, "View Profile")));
626
+ }
627
+ });
628
+ ExpandedWithRichContent.parameters = {
629
+ docs: {
630
+ description: {
631
+ story: 'A more complex example showing a rich expanded content with multiple panels, styled badges, and action buttons.'
632
+ }
633
+ }
634
+ };
635
+
636
+ // Combined: Row Click + Custom Expanded Content
637
+ const RowClickWithExpandedContent = exports.RowClickWithExpandedContent = Template.bind({});
638
+ RowClickWithExpandedContent.args = {
639
+ columns: columnsWithActions,
640
+ data: data,
641
+ noPagination: false,
642
+ onRowClick: (rowData, rowIndex) => {
643
+ console.log('Row clicked (but not triggering anything in this demo)');
644
+ },
645
+ renderExpandedContent: (row, toggleExpanded) => /*#__PURE__*/_react.default.createElement("div", {
646
+ style: {
647
+ padding: '20px',
648
+ backgroundColor: '#e3f2fd',
649
+ borderLeft: '4px solid #0050ca'
650
+ }
651
+ }, /*#__PURE__*/_react.default.createElement("p", {
652
+ style: {
653
+ margin: '0 0 12px 0'
654
+ }
655
+ }, /*#__PURE__*/_react.default.createElement("strong", null, "Expanded details for:"), " ", row.original.name), /*#__PURE__*/_react.default.createElement("p", {
656
+ style: {
657
+ margin: 0,
658
+ color: '#666'
659
+ }
660
+ }, "Click anywhere on the row to expand/collapse. Buttons work independently."))
661
+ };
662
+ RowClickWithExpandedContent.parameters = {
663
+ docs: {
664
+ description: {
665
+ story: 'Combined example: rows are clickable AND expandable. The onRowClick and renderExpandedContent work together. Buttons inside cells remain independent.'
666
+ }
667
+ }
668
+ };
669
+
670
+ // ============================================
671
+ // HEADER CLICK STORIES: onHeaderClick & renderHeaderContent
672
+ // ============================================
673
+
674
+ // Basic Header Click - shows alert
675
+ const HeaderClick = exports.HeaderClick = Template.bind({});
676
+ HeaderClick.args = _objectSpread(_objectSpread({}, Default.args), {}, {
677
+ onHeaderClick: (column, event) => {
678
+ alert("Header clicked: ".concat(column.id || column.Header));
679
+ }
680
+ });
681
+ HeaderClick.parameters = {
682
+ docs: {
683
+ description: {
684
+ story: 'Click on any column header to trigger an action. Useful for implementing custom sorting or filtering.'
685
+ }
686
+ }
687
+ };
688
+
689
+ // Header Click with Sort State (External Control)
690
+ const SortableTableDemo = () => {
691
+ const [sortConfig, setSortConfig] = _react.default.useState({
692
+ key: null,
693
+ direction: 'asc'
694
+ });
695
+ const [tableData, setTableData] = _react.default.useState(data);
696
+ const handleHeaderClick = column => {
697
+ // Skip non-sortable columns (like actions)
698
+ if (column.id === 'dropdown' || column.id === 'actions') return;
699
+ let direction = 'asc';
700
+ if (sortConfig.key === column.id && sortConfig.direction === 'asc') {
701
+ direction = 'desc';
702
+ }
703
+ setSortConfig({
704
+ key: column.id,
705
+ direction
706
+ });
707
+
708
+ // Sort the data
709
+ const sorted = [...data].sort((a, b) => {
710
+ const aVal = a[column.id];
711
+ const bVal = b[column.id];
712
+ if (aVal < bVal) return direction === 'asc' ? -1 : 1;
713
+ if (aVal > bVal) return direction === 'asc' ? 1 : -1;
714
+ return 0;
715
+ });
716
+ setTableData(sorted);
717
+ };
718
+
719
+ // Add sort indicators to headers
720
+ const renderHeaderContent = (column, defaultContent) => {
721
+ // Skip non-sortable columns
722
+ if (column.id === 'dropdown' || column.id === 'actions') {
723
+ return defaultContent;
724
+ }
725
+ const isSorted = sortConfig.key === column.id;
726
+ const arrow = isSorted ? sortConfig.direction === 'asc' ? ' ↑' : ' ↓' : '';
727
+ return /*#__PURE__*/_react.default.createElement("span", {
728
+ style: {
729
+ display: 'flex',
730
+ alignItems: 'center',
731
+ gap: '4px'
732
+ }
733
+ }, defaultContent, /*#__PURE__*/_react.default.createElement("span", {
734
+ style: {
735
+ opacity: isSorted ? 1 : 0.3
736
+ }
737
+ }, isSorted ? arrow : ' ↕'));
738
+ };
739
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_global.default, null), /*#__PURE__*/_react.default.createElement("div", {
740
+ style: {
741
+ marginBottom: '16px'
742
+ }
743
+ }, /*#__PURE__*/_react.default.createElement("strong", null, "Current sort:"), ' ', sortConfig.key ? "".concat(sortConfig.key, " (").concat(sortConfig.direction, ")") : 'None'), /*#__PURE__*/_react.default.createElement(_ReactTable.ReactTable, {
744
+ columns: columns,
745
+ data: tableData,
746
+ noPagination: false,
747
+ onHeaderClick: handleHeaderClick,
748
+ renderHeaderContent: renderHeaderContent
749
+ }));
750
+ };
751
+ const SortableHeaders = exports.SortableHeaders = {
752
+ render: () => /*#__PURE__*/_react.default.createElement(SortableTableDemo, null),
753
+ parameters: {
754
+ docs: {
755
+ description: {
756
+ story: 'External sorting controlled by parent component. Click headers to sort. Uses onHeaderClick for the action and renderHeaderContent for the sort indicators.'
757
+ }
758
+ }
759
+ }
760
+ };
761
+
762
+ // Header with Custom Dropdown Filter
763
+ const FilterableTableDemo = () => {
764
+ const [filters, setFilters] = _react.default.useState({});
765
+ const [activeDropdown, setActiveDropdown] = _react.default.useState(null);
766
+ const [tableData, setTableData] = _react.default.useState(data);
767
+
768
+ // Get unique values for a column
769
+ const getUniqueValues = columnId => {
770
+ return [...new Set(data.map(row => row[columnId]))];
771
+ };
772
+ const handleFilter = (columnId, value) => {
773
+ const newFilters = _objectSpread({}, filters);
774
+ if (value === 'all') {
775
+ delete newFilters[columnId];
776
+ } else {
777
+ newFilters[columnId] = value;
778
+ }
779
+ setFilters(newFilters);
780
+ setActiveDropdown(null);
781
+
782
+ // Apply filters
783
+ let filtered = [...data];
784
+ Object.keys(newFilters).forEach(key => {
785
+ filtered = filtered.filter(row => row[key] === newFilters[key]);
786
+ });
787
+ setTableData(filtered);
788
+ };
789
+
790
+ // Custom header with filter dropdown
791
+ const renderHeaderContent = (column, defaultContent) => {
792
+ // Only add filter to specific columns
793
+ if (!['status'].includes(column.id)) {
794
+ return defaultContent;
795
+ }
796
+ const isActive = activeDropdown === column.id;
797
+ const hasFilter = filters[column.id];
798
+ return /*#__PURE__*/_react.default.createElement("div", {
799
+ style: {
800
+ position: 'relative'
801
+ }
802
+ }, /*#__PURE__*/_react.default.createElement("span", {
803
+ style: {
804
+ display: 'flex',
805
+ alignItems: 'center',
806
+ gap: '8px'
807
+ },
808
+ "data-clickable": "true",
809
+ onClick: e => {
810
+ e.stopPropagation();
811
+ setActiveDropdown(isActive ? null : column.id);
812
+ }
813
+ }, defaultContent, /*#__PURE__*/_react.default.createElement("span", {
814
+ style: {
815
+ fontSize: '10px',
816
+ padding: '2px 6px',
817
+ borderRadius: '4px',
818
+ backgroundColor: hasFilter ? '#0050ca' : '#e1e1e1',
819
+ color: hasFilter ? 'white' : '#666'
820
+ }
821
+ }, hasFilter ? '✓' : '▼')), isActive && /*#__PURE__*/_react.default.createElement("div", {
822
+ style: {
823
+ position: 'absolute',
824
+ top: '100%',
825
+ left: 0,
826
+ marginTop: '4px',
827
+ backgroundColor: 'white',
828
+ border: '1px solid #e1e1e1',
829
+ borderRadius: '4px',
830
+ boxShadow: '0 4px 12px rgba(0,0,0,0.15)',
831
+ zIndex: 100,
832
+ minWidth: '120px'
833
+ }
834
+ }, /*#__PURE__*/_react.default.createElement("div", {
835
+ style: {
836
+ padding: '8px 12px',
837
+ cursor: 'pointer',
838
+ borderBottom: '1px solid #e1e1e1'
839
+ },
840
+ onClick: () => handleFilter(column.id, 'all')
841
+ }, "All"), getUniqueValues(column.id).map(value => /*#__PURE__*/_react.default.createElement("div", {
842
+ key: value,
843
+ style: {
844
+ padding: '8px 12px',
845
+ cursor: 'pointer',
846
+ backgroundColor: filters[column.id] === value ? '#f0f8ff' : 'transparent'
847
+ },
848
+ onClick: () => handleFilter(column.id, value)
849
+ }, value))));
850
+ };
851
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_global.default, null), /*#__PURE__*/_react.default.createElement("div", {
852
+ style: {
853
+ marginBottom: '16px'
854
+ }
855
+ }, /*#__PURE__*/_react.default.createElement("strong", null, "Active filters:"), ' ', Object.keys(filters).length > 0 ? Object.entries(filters).map(_ref2 => {
856
+ let [k, v] = _ref2;
857
+ return "".concat(k, ": ").concat(v);
858
+ }).join(', ') : 'None'), /*#__PURE__*/_react.default.createElement(_ReactTable.ReactTable, {
859
+ columns: columns,
860
+ data: tableData,
861
+ noPagination: false,
862
+ renderHeaderContent: renderHeaderContent
863
+ }));
864
+ };
865
+ const FilterableHeaders = exports.FilterableHeaders = {
866
+ render: () => /*#__PURE__*/_react.default.createElement(FilterableTableDemo, null),
867
+ parameters: {
868
+ docs: {
869
+ description: {
870
+ story: 'Custom filter dropdown in the "Status" header. Click the dropdown icon to filter. Uses renderHeaderContent to add the dropdown UI.'
871
+ }
872
+ }
873
+ }
874
+ };
875
+
876
+ // Per-Column Header Click Handler
877
+ const columnsWithColumnClick = [{
878
+ Header: 'ID (Click me!)',
879
+ accessor: 'id',
880
+ width: '15%',
881
+ onHeaderClick: column => {
882
+ alert('ID column has its own click handler!');
883
+ }
884
+ }, {
885
+ Header: 'Name',
886
+ accessor: 'name',
887
+ width: '30%'
888
+ }, {
889
+ Header: 'Status',
890
+ accessor: 'status',
891
+ width: '20%'
892
+ }, {
893
+ Header: 'Actions (No click)',
894
+ accessor: 'dropdown',
895
+ width: '35%'
896
+ // No onHeaderClick - won't trigger global onHeaderClick either
897
+ }];
898
+ const PerColumnHeaderClick = exports.PerColumnHeaderClick = Template.bind({});
899
+ PerColumnHeaderClick.args = {
900
+ columns: columnsWithColumnClick,
901
+ data: data,
902
+ noPagination: false,
903
+ onHeaderClick: column => {
904
+ alert("Global header click: ".concat(column.id));
905
+ }
906
+ };
907
+ PerColumnHeaderClick.parameters = {
908
+ docs: {
909
+ description: {
910
+ story: 'Columns can have their own onHeaderClick handlers. The "ID" column has a custom handler. Other columns use the global onHeaderClick. The "Actions" column has neither.'
911
+ }
912
+ }
913
+ };
@@ -7,65 +7,64 @@ exports.default = exports.Input = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _Input = require("./Input.styles");
10
+ const _excluded = ["type", "id", "name", "label", "placeholder", "value", "error", "touched", "readOnly", "inverted", "dashboard", "disabled", "inputWrapStyle", "wrapperStyle", "autoHeightLabel", "onChange", "onBlur", "onFocus"];
10
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
12
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
13
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
14
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
15
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
13
16
  const Input = props => {
14
17
  const {
15
- type,
16
- id,
17
- name,
18
- label,
19
- placeholder,
20
- value,
21
- error,
22
- touched,
23
- readOnly,
24
- inverted,
25
- dashboard,
26
- disabled,
27
- inputWrapStyle,
28
- wrapperStyle,
29
- autoHeightLabel
30
- } = props;
18
+ type,
19
+ id,
20
+ name,
21
+ label,
22
+ placeholder,
23
+ value,
24
+ error,
25
+ touched,
26
+ readOnly,
27
+ inverted,
28
+ dashboard,
29
+ disabled,
30
+ inputWrapStyle,
31
+ wrapperStyle,
32
+ autoHeightLabel,
33
+ // Destructure these so they don't get spread to the input
34
+ onChange: onChangeProp,
35
+ onBlur: onBlurProp,
36
+ onFocus: onFocusProp
37
+ } = props,
38
+ restProps = _objectWithoutProperties(props, _excluded);
31
39
  const [labelUp, setLabelUp] = (0, _react.useState)(false);
32
40
  const [hasFocus, setHasFocus] = (0, _react.useState)(false);
33
41
  (0, _react.useEffect)(() => {
34
42
  checkLabel(false);
35
43
  }, []);
36
44
  (0, _react.useEffect)(() => {
37
- checkLabel(false);
38
- }, [hasFocus, value]);
45
+ if (!!value && !labelUp) {
46
+ checkLabel(false);
47
+ }
48
+ }, [labelUp, value]);
39
49
  (0, _react.useEffect)(() => {
40
50
  if (value && !labelUp) setLabelUp(true);
41
51
  }, [value, labelUp]);
42
52
  const onBlur = (e, field) => {
43
- const {
44
- onBlur
45
- } = props;
46
-
47
53
  // formik handler MUST be called before our logic !
48
- onBlur && onBlur(e, field);
54
+ onBlurProp && onBlurProp(e, field);
49
55
 
50
56
  // our logic follows
51
57
  checkLabel(false);
52
58
  };
53
59
  const onFocus = (e, field) => {
54
- const {
55
- onFocus
56
- } = props;
57
-
58
60
  // formik handler MUST be called before our logic !
59
- onFocus && onFocus(e, field);
61
+ onFocusProp && onFocusProp(e, field);
60
62
 
61
63
  // our logic follows
62
64
  checkLabel(true);
63
65
  };
64
66
  const onChange = (e, field) => {
65
- const {
66
- onChange
67
- } = props;
68
- onChange && onChange(e, field); // formik handler
67
+ onChangeProp && onChangeProp(e, field); // formik handler
69
68
  };
70
69
  const checkLabel = focus => {
71
70
  setHasFocus(focus);
@@ -96,11 +95,12 @@ const Input = props => {
96
95
  onFocus: onFocus,
97
96
  readOnly: readOnly,
98
97
  placeholder: placeholder,
98
+ disabled: disabled,
99
99
  style: {
100
100
  WebkitAppearance: 'none',
101
101
  WebkitBorderRadius: 0
102
102
  }
103
- }, props))));
103
+ }, restProps))));
104
104
  };
105
105
  exports.Input = Input;
106
106
  Input.propTypes = {