grommet 2.29.0 → 2.30.0
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/components/Anchor/Anchor.js +9 -3
- package/components/Anchor/StyledAnchor.js +6 -3
- package/components/Button/Button.js +10 -14
- package/components/Button/StyledButtonKind.js +21 -9
- package/components/Calendar/Calendar.js +80 -71
- package/components/Data/Data.js +48 -26
- package/components/Data/DataForm.js +203 -48
- package/components/Data/filter.js +17 -6
- package/components/Data/index.d.ts +12 -7
- package/components/Data/index.js +6 -2
- package/components/Data/propTypes.js +3 -2
- package/components/Data/stories/Cards.js +1 -1
- package/components/Data/stories/Complex.js +84 -0
- package/components/Data/stories/Controlled.js +1 -1
- package/components/Data/stories/DataTable.js +11 -4
- package/components/Data/stories/Infinite.js +53 -57
- package/components/Data/stories/Inline.js +7 -2
- package/components/Data/stories/List.js +1 -1
- package/components/Data/stories/Simple.js +1 -1
- package/components/Data/stories/SpaceX.js +114 -140
- package/components/Data/stories/StarWars.js +127 -0
- package/components/Data/stories/Views.js +56 -0
- package/components/DataFilter/DataFilter.js +33 -42
- package/components/DataFilter/stories/Simple.js +7 -4
- package/components/DataFilters/DataFilters.js +117 -40
- package/components/DataFilters/index.d.ts +1 -0
- package/components/DataFilters/propTypes.js +2 -1
- package/components/DataFilters/stories/Drop.js +7 -4
- package/components/DataFilters/stories/Inline.js +24 -6
- package/components/DataFilters/stories/Layer.js +46 -0
- package/components/DataFilters/stories/Simple.js +7 -4
- package/components/DataSearch/DataSearch.js +70 -13
- package/components/DataSearch/index.d.ts +10 -1
- package/components/DataSearch/propTypes.js +6 -1
- package/components/DataSearch/stories/Drop.js +42 -0
- package/components/DataSearch/stories/Responsive.js +42 -0
- package/components/DataSearch/stories/Simple.js +5 -2
- package/components/DataSort/DataSort.js +67 -18
- package/components/DataSort/index.d.ts +4 -8
- package/components/DataSort/propTypes.js +9 -2
- package/components/DataSort/stories/Drop.js +41 -0
- package/components/DataSort/stories/Simple.js +9 -5
- package/components/DataSummary/DataSummary.js +4 -4
- package/components/DataSummary/index.d.ts +1 -1
- package/components/DataSummary/propTypes.js +2 -2
- package/components/DataSummary/stories/Simple.js +7 -4
- package/components/DataTable/Cell.js +1 -1
- package/components/DataTable/DataTable.js +23 -9
- package/components/DataTable/GroupedBody.js +1 -0
- package/components/DataTable/Resizer.js +1 -3
- package/components/DataTable/StyledDataTable.js +2 -2
- package/components/DataTable/index.d.ts +23 -6
- package/components/DataTable/stories/SpaceX.js +72 -76
- package/components/DataTable/stories/SpaceXUngrouped.js +33 -35
- package/components/DataTableColumns/DataTableColumns.js +226 -0
- package/components/DataTableColumns/README.md +2 -0
- package/components/DataTableColumns/index.d.ts +10 -0
- package/components/DataTableColumns/index.js +6 -0
- package/components/DataTableColumns/propTypes.js +18 -0
- package/components/DataTableColumns/stories/Simple.js +51 -0
- package/components/DataView/DataView.js +73 -0
- package/components/DataView/README.md +2 -0
- package/components/DataView/index.d.ts +15 -0
- package/components/DataView/index.js +6 -0
- package/components/DataView/propTypes.js +10 -0
- package/components/DataView/stories/Simple.js +51 -0
- package/components/DateInput/utils.js +1 -3
- package/components/Distribution/Distribution.js +1 -1
- package/components/Drop/DropContainer.js +56 -100
- package/components/Drop/stories/Overflow.js +1 -0
- package/components/DropButton/DropButton.js +1 -1
- package/components/Form/stories/Controlled.js +11 -2
- package/components/Form/stories/ControlledInput.js +13 -2
- package/components/Form/stories/ControlledInputLazy.js +13 -2
- package/components/Form/stories/ControlledLazy.js +13 -2
- package/components/Form/stories/FieldWithChildren.js +13 -2
- package/components/Form/stories/FieldWithComponentProp.js +17 -1
- package/components/Form/stories/Uncontrolled.js +15 -2
- package/components/Form/stories/ValidateOnBlur.js +18 -0
- package/components/Form/stories/ValidateOnChange.js +6 -0
- package/components/Form/stories/ValidateOnMount.js +4 -0
- package/components/Form/stories/typescript/TypedForm.tsx +25 -3
- package/components/FormField/FormField.js +15 -4
- package/components/Layer/LayerContainer.js +2 -3
- package/components/Layer/PortalContext.js +1 -1
- package/components/Layer/StyledLayer.js +3 -1
- package/components/Layer/stories/Form.js +54 -28
- package/components/List/List.js +1 -8
- package/components/Pagination/Pagination.js +27 -8
- package/components/Paragraph/Paragraph.js +18 -6
- package/components/Select/utils.js +1 -1
- package/components/Skeleton/stories/GridContainer.js +1 -3
- package/components/Tabs/Tabs.js +2 -1
- package/components/Text/Text.js +9 -1
- package/components/Text/TextContext.js +8 -0
- package/components/TextInput/StyledTextInput.js +3 -1
- package/components/TextInput/TextInput.js +4 -2
- package/components/TextInput/index.d.ts +3 -1
- package/components/TextInput/propTypes.js +3 -1
- package/components/Toolbar/stories/Simple.js +1 -1
- package/components/Video/Video.js +4 -8
- package/components/WorldMap/WorldMap.js +18 -17
- package/components/index.d.ts +2 -0
- package/components/index.js +18 -6
- package/es6/components/Anchor/Anchor.js +9 -3
- package/es6/components/Anchor/StyledAnchor.js +6 -3
- package/es6/components/Button/Button.js +10 -14
- package/es6/components/Button/StyledButtonKind.js +21 -9
- package/es6/components/Calendar/Calendar.js +80 -71
- package/es6/components/Data/Data.js +48 -26
- package/es6/components/Data/DataForm.js +199 -51
- package/es6/components/Data/filter.js +17 -6
- package/es6/components/Data/index.d.ts +12 -7
- package/es6/components/Data/index.js +1 -1
- package/es6/components/Data/propTypes.js +3 -2
- package/es6/components/Data/stories/Cards.js +1 -1
- package/es6/components/Data/stories/Complex.js +78 -0
- package/es6/components/Data/stories/Controlled.js +1 -1
- package/es6/components/Data/stories/DataTable.js +12 -5
- package/es6/components/Data/stories/Infinite.js +53 -57
- package/es6/components/Data/stories/Inline.js +7 -2
- package/es6/components/Data/stories/List.js +1 -1
- package/es6/components/Data/stories/Simple.js +1 -1
- package/es6/components/Data/stories/SpaceX.js +114 -140
- package/es6/components/Data/stories/StarWars.js +121 -0
- package/es6/components/Data/stories/Views.js +50 -0
- package/es6/components/DataFilter/DataFilter.js +33 -42
- package/es6/components/DataFilter/stories/Simple.js +8 -5
- package/es6/components/DataFilters/DataFilters.js +118 -41
- package/es6/components/DataFilters/index.d.ts +1 -0
- package/es6/components/DataFilters/propTypes.js +2 -1
- package/es6/components/DataFilters/stories/Drop.js +8 -5
- package/es6/components/DataFilters/stories/Inline.js +25 -7
- package/es6/components/DataFilters/stories/Layer.js +40 -0
- package/es6/components/DataFilters/stories/Simple.js +8 -5
- package/es6/components/DataSearch/DataSearch.js +71 -14
- package/es6/components/DataSearch/index.d.ts +10 -1
- package/es6/components/DataSearch/propTypes.js +5 -1
- package/es6/components/DataSearch/stories/Drop.js +36 -0
- package/es6/components/DataSearch/stories/Responsive.js +36 -0
- package/es6/components/DataSearch/stories/Simple.js +6 -3
- package/es6/components/DataSort/DataSort.js +67 -18
- package/es6/components/DataSort/index.d.ts +4 -8
- package/es6/components/DataSort/propTypes.js +8 -2
- package/es6/components/DataSort/stories/Drop.js +35 -0
- package/es6/components/DataSort/stories/Simple.js +10 -6
- package/es6/components/DataSummary/DataSummary.js +4 -4
- package/es6/components/DataSummary/index.d.ts +1 -1
- package/es6/components/DataSummary/propTypes.js +2 -2
- package/es6/components/DataSummary/stories/Simple.js +8 -5
- package/es6/components/DataTable/Cell.js +2 -2
- package/es6/components/DataTable/DataTable.js +23 -9
- package/es6/components/DataTable/GroupedBody.js +1 -0
- package/es6/components/DataTable/Resizer.js +1 -3
- package/es6/components/DataTable/StyledDataTable.js +2 -2
- package/es6/components/DataTable/index.d.ts +23 -6
- package/es6/components/DataTable/stories/SpaceX.js +72 -76
- package/es6/components/DataTable/stories/SpaceXUngrouped.js +33 -35
- package/es6/components/DataTableColumns/DataTableColumns.js +219 -0
- package/es6/components/DataTableColumns/README.md +2 -0
- package/es6/components/DataTableColumns/index.d.ts +10 -0
- package/es6/components/DataTableColumns/index.js +1 -0
- package/es6/components/DataTableColumns/propTypes.js +12 -0
- package/es6/components/DataTableColumns/stories/Simple.js +46 -0
- package/es6/components/DataView/DataView.js +66 -0
- package/es6/components/DataView/README.md +2 -0
- package/es6/components/DataView/index.d.ts +15 -0
- package/es6/components/DataView/index.js +1 -0
- package/es6/components/DataView/propTypes.js +5 -0
- package/es6/components/DataView/stories/Simple.js +45 -0
- package/es6/components/DateInput/utils.js +1 -3
- package/es6/components/Distribution/Distribution.js +1 -1
- package/es6/components/Drop/DropContainer.js +58 -102
- package/es6/components/Drop/stories/Overflow.js +1 -0
- package/es6/components/DropButton/DropButton.js +1 -1
- package/es6/components/Form/stories/Controlled.js +11 -2
- package/es6/components/Form/stories/ControlledInput.js +13 -2
- package/es6/components/Form/stories/ControlledInputLazy.js +13 -2
- package/es6/components/Form/stories/ControlledLazy.js +13 -2
- package/es6/components/Form/stories/FieldWithChildren.js +13 -2
- package/es6/components/Form/stories/FieldWithComponentProp.js +17 -1
- package/es6/components/Form/stories/Uncontrolled.js +15 -2
- package/es6/components/Form/stories/ValidateOnBlur.js +19 -1
- package/es6/components/Form/stories/ValidateOnChange.js +6 -0
- package/es6/components/Form/stories/ValidateOnMount.js +4 -0
- package/es6/components/Form/stories/typescript/TypedForm.tsx +25 -3
- package/es6/components/FormField/FormField.js +15 -4
- package/es6/components/Layer/LayerContainer.js +2 -3
- package/es6/components/Layer/PortalContext.js +1 -1
- package/es6/components/Layer/StyledLayer.js +3 -1
- package/es6/components/Layer/stories/Form.js +56 -29
- package/es6/components/List/List.js +1 -8
- package/es6/components/Pagination/Pagination.js +27 -8
- package/es6/components/Paragraph/Paragraph.js +19 -7
- package/es6/components/Select/utils.js +1 -1
- package/es6/components/Skeleton/stories/GridContainer.js +1 -3
- package/es6/components/Tabs/Tabs.js +2 -1
- package/es6/components/Text/Text.js +10 -2
- package/es6/components/Text/TextContext.js +2 -0
- package/es6/components/TextInput/StyledTextInput.js +4 -2
- package/es6/components/TextInput/TextInput.js +4 -2
- package/es6/components/TextInput/index.d.ts +3 -1
- package/es6/components/TextInput/propTypes.js +3 -1
- package/es6/components/Toolbar/stories/Simple.js +1 -1
- package/es6/components/Video/Video.js +4 -8
- package/es6/components/WorldMap/WorldMap.js +18 -17
- package/es6/components/index.d.ts +2 -0
- package/es6/components/index.js +3 -1
- package/es6/languages/default.json +14 -4
- package/es6/themes/base.d.ts +31 -0
- package/es6/themes/base.js +31 -1
- package/es6/utils/DOM.js +17 -0
- package/es6/utils/PortalContext.js +1 -1
- package/es6/utils/background.js +9 -1
- package/es6/utils/colors.js +2 -2
- package/es6/utils/general-prop-types.js +1 -1
- package/es6/utils/index.d.ts +7 -1
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/languages/default.json +14 -4
- package/package.json +42 -40
- package/themes/base.d.ts +31 -0
- package/themes/base.js +31 -1
- package/utils/DOM.js +20 -2
- package/utils/PortalContext.js +1 -1
- package/utils/background.js +8 -0
- package/utils/colors.js +3 -1
- package/utils/general-prop-types.js +1 -1
- package/utils/index.d.ts +7 -1
|
@@ -8,8 +8,10 @@ import { MessageContext } from '../../contexts/MessageContext';
|
|
|
8
8
|
import { defaultProps } from '../../default-props';
|
|
9
9
|
import { Box } from '../Box';
|
|
10
10
|
import { Button } from '../Button';
|
|
11
|
+
import { Header } from '../Header';
|
|
11
12
|
import { Heading } from '../Heading';
|
|
12
13
|
import { Keyboard } from '../Keyboard';
|
|
14
|
+
import { Text } from '../Text';
|
|
13
15
|
import { CalendarPropTypes } from './propTypes';
|
|
14
16
|
import { StyledCalendar, StyledDay, StyledDayContainer, StyledWeek, StyledWeeks, StyledWeeksContainer } from './StyledCalendar';
|
|
15
17
|
import { addDays, addMonths, betweenDates, daysApart, endOfMonth, handleOffset, sameDayOrAfter, sameDayOrBefore, startOfMonth, subtractDays, subtractMonths, withinDates } from './utils';
|
|
@@ -495,26 +497,32 @@ var Calendar = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
|
495
497
|
setActive(selectedDate);
|
|
496
498
|
};
|
|
497
499
|
var renderCalendarHeader = function renderCalendarHeader() {
|
|
500
|
+
var _theme$calendar$size;
|
|
498
501
|
var PreviousIcon = size === 'small' ? theme.calendar.icons.small.previous : theme.calendar.icons.previous;
|
|
499
502
|
var NextIcon = size === 'small' ? theme.calendar.icons.small.next : theme.calendar.icons.next;
|
|
503
|
+
var monthAndYear = reference.toLocaleDateString(locale, {
|
|
504
|
+
month: 'long',
|
|
505
|
+
year: 'numeric'
|
|
506
|
+
});
|
|
500
507
|
return /*#__PURE__*/React.createElement(Box, {
|
|
501
508
|
direction: "row",
|
|
502
509
|
justify: "between",
|
|
503
510
|
align: "center"
|
|
504
|
-
}, /*#__PURE__*/React.createElement(
|
|
511
|
+
}, /*#__PURE__*/React.createElement(Header, {
|
|
505
512
|
flex: true,
|
|
506
513
|
pad: {
|
|
507
514
|
horizontal: headingPadMap[size] || 'small'
|
|
508
515
|
}
|
|
509
|
-
}, /*#__PURE__*/React.createElement(
|
|
516
|
+
}, (_theme$calendar$size = theme.calendar[size]) != null && _theme$calendar$size.title ? /*#__PURE__*/React.createElement(Text, theme.calendar[size].title, monthAndYear) :
|
|
517
|
+
/*#__PURE__*/
|
|
518
|
+
// theme.calendar.heading.level should be removed in v3 of grommet
|
|
519
|
+
// theme.calendar[size].title should be used instead
|
|
520
|
+
React.createElement(Heading, {
|
|
510
521
|
level: size === 'small' ? theme.calendar.heading && theme.calendar.heading.level || 4 : (theme.calendar.heading && theme.calendar.heading.level || 4) - 1,
|
|
511
522
|
size: size,
|
|
512
523
|
margin: "none",
|
|
513
524
|
overflowWrap: "normal"
|
|
514
|
-
},
|
|
515
|
-
month: 'long',
|
|
516
|
-
year: 'numeric'
|
|
517
|
-
}))), /*#__PURE__*/React.createElement(Box, {
|
|
525
|
+
}, monthAndYear)), /*#__PURE__*/React.createElement(Box, {
|
|
518
526
|
flex: false,
|
|
519
527
|
direction: "row",
|
|
520
528
|
align: "center"
|
|
@@ -583,7 +591,7 @@ var Calendar = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
|
583
591
|
var days;
|
|
584
592
|
var firstDayInMonth;
|
|
585
593
|
var blankWeek = false;
|
|
586
|
-
|
|
594
|
+
var _loop = function _loop() {
|
|
587
595
|
if (day.getDay() === firstDayOfWeek) {
|
|
588
596
|
if (days) {
|
|
589
597
|
weeks.push( /*#__PURE__*/React.createElement(StyledWeek, {
|
|
@@ -627,73 +635,74 @@ var Calendar = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
|
627
635
|
fillContainer: fill
|
|
628
636
|
})));
|
|
629
637
|
} else {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
return _onClick(dateObject);
|
|
654
|
-
},
|
|
655
|
-
onMouseOver: function onMouseOver() {
|
|
656
|
-
return setActive(dateObject);
|
|
657
|
-
},
|
|
658
|
-
onMouseOut: function onMouseOut() {
|
|
659
|
-
return setActive(undefined);
|
|
660
|
-
}
|
|
638
|
+
var dateObject = day;
|
|
639
|
+
// this.dayRefs[dateObject] = React.createRef();
|
|
640
|
+
var selected = false;
|
|
641
|
+
var inRange = false;
|
|
642
|
+
var selectedState = withinDates(day, range ? normalizeRange(value, activeDate) : value);
|
|
643
|
+
if (selectedState === 2) {
|
|
644
|
+
selected = true;
|
|
645
|
+
} else if (selectedState === 1) {
|
|
646
|
+
inRange = true;
|
|
647
|
+
}
|
|
648
|
+
var dayDisabled = withinDates(day, normalizeInput(disabled)) || bounds && !betweenDates(day, normalizeInput(bounds));
|
|
649
|
+
if (!firstDayInMonth && !dayDisabled && day.getMonth() === reference.getMonth()) {
|
|
650
|
+
firstDayInMonth = dateObject;
|
|
651
|
+
}
|
|
652
|
+
if (!children) {
|
|
653
|
+
days.push( /*#__PURE__*/React.createElement(CalendarDay, {
|
|
654
|
+
key: day.getTime(),
|
|
655
|
+
buttonProps: {
|
|
656
|
+
a11yTitle: day.toDateString(),
|
|
657
|
+
active: active && active.getTime() === day.getTime(),
|
|
658
|
+
disabled: dayDisabled && !!dayDisabled,
|
|
659
|
+
onClick: function onClick() {
|
|
660
|
+
return _onClick(dateObject);
|
|
661
661
|
},
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
662
|
+
onMouseOver: function onMouseOver() {
|
|
663
|
+
return setActive(dateObject);
|
|
664
|
+
},
|
|
665
|
+
onMouseOut: function onMouseOut() {
|
|
666
|
+
return setActive(undefined);
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
isInRange: inRange,
|
|
670
|
+
isSelected: selected,
|
|
671
|
+
otherMonth: day.getMonth() !== reference.getMonth(),
|
|
672
|
+
size: size,
|
|
673
|
+
fill: fill
|
|
674
|
+
}, day.getDate()));
|
|
675
|
+
} else {
|
|
676
|
+
days.push( /*#__PURE__*/React.createElement(CalendarCustomDay, {
|
|
677
|
+
key: day.getTime(),
|
|
678
|
+
buttonProps: onSelect ? {
|
|
679
|
+
a11yTitle: day.toDateString(),
|
|
680
|
+
active: active && active.getTime() === day.getTime(),
|
|
681
|
+
disabled: dayDisabled && !!dayDisabled,
|
|
682
|
+
onClick: function onClick() {
|
|
683
|
+
return _onClick(dateObject);
|
|
684
|
+
},
|
|
685
|
+
onMouseOver: function onMouseOver() {
|
|
686
|
+
return setActive(dateObject);
|
|
687
|
+
},
|
|
688
|
+
onMouseOut: function onMouseOut() {
|
|
689
|
+
return setActive(undefined);
|
|
690
|
+
}
|
|
691
|
+
} : null,
|
|
692
|
+
size: size,
|
|
693
|
+
fill: fill
|
|
694
|
+
}, children({
|
|
695
|
+
date: day,
|
|
696
|
+
day: day.getDate(),
|
|
697
|
+
isInRange: inRange,
|
|
698
|
+
isSelected: selected
|
|
699
|
+
})));
|
|
700
|
+
}
|
|
695
701
|
}
|
|
696
702
|
day = addDays(day, 1);
|
|
703
|
+
};
|
|
704
|
+
while (day.getTime() < displayBounds[1].getTime()) {
|
|
705
|
+
_loop();
|
|
697
706
|
}
|
|
698
707
|
weeks.push( /*#__PURE__*/React.createElement(StyledWeek
|
|
699
708
|
// if a week contains only blank days, for screen reader accessibility
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["children", "data", "id", "messages", "onView", "properties", "toolbar", "total", "updateOn", "view"];
|
|
1
|
+
var _excluded = ["children", "data", "defaultView", "filteredTotal", "id", "messages", "onView", "properties", "toolbar", "total", "updateOn", "view", "views"];
|
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
4
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
@@ -6,17 +6,25 @@ import { Box } from '../Box';
|
|
|
6
6
|
import { DataFilters } from '../DataFilters';
|
|
7
7
|
import { DataSearch } from '../DataSearch';
|
|
8
8
|
import { DataSummary } from '../DataSummary';
|
|
9
|
+
import { DataView } from '../DataView';
|
|
9
10
|
import { Toolbar } from '../Toolbar';
|
|
10
11
|
import { DataContext } from '../../contexts/DataContext';
|
|
11
12
|
import { DataPropTypes } from './propTypes';
|
|
12
13
|
import { filter } from './filter';
|
|
13
|
-
var
|
|
14
|
-
search: ''
|
|
15
|
-
|
|
14
|
+
var defaultDefaultView = {
|
|
15
|
+
search: ''
|
|
16
|
+
};
|
|
17
|
+
var normalizeView = function normalizeView(viewProp, views) {
|
|
18
|
+
return typeof viewProp === 'string' && (views == null ? void 0 : views.find(function (v) {
|
|
19
|
+
return v.name === viewProp;
|
|
20
|
+
})) || typeof viewProp === 'object' && viewProp;
|
|
16
21
|
};
|
|
17
22
|
export var Data = function Data(_ref) {
|
|
18
23
|
var children = _ref.children,
|
|
19
24
|
dataProp = _ref.data,
|
|
25
|
+
_ref$defaultView = _ref.defaultView,
|
|
26
|
+
defaultView = _ref$defaultView === void 0 ? defaultDefaultView : _ref$defaultView,
|
|
27
|
+
filteredTotal = _ref.filteredTotal,
|
|
20
28
|
_ref$id = _ref.id,
|
|
21
29
|
id = _ref$id === void 0 ? 'data' : _ref$id,
|
|
22
30
|
messages = _ref.messages,
|
|
@@ -27,48 +35,62 @@ export var Data = function Data(_ref) {
|
|
|
27
35
|
_ref$updateOn = _ref.updateOn,
|
|
28
36
|
updateOn = _ref$updateOn === void 0 ? 'submit' : _ref$updateOn,
|
|
29
37
|
viewProp = _ref.view,
|
|
38
|
+
views = _ref.views,
|
|
30
39
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
31
|
-
var _useState = useState(viewProp),
|
|
40
|
+
var _useState = useState(normalizeView(viewProp || defaultView, views)),
|
|
32
41
|
view = _useState[0],
|
|
33
42
|
setView = _useState[1];
|
|
34
43
|
useEffect(function () {
|
|
35
|
-
return setView(viewProp);
|
|
36
|
-
}, [viewProp]);
|
|
37
|
-
var
|
|
38
|
-
|
|
44
|
+
return setView(normalizeView(viewProp || defaultView, views));
|
|
45
|
+
}, [defaultView, viewProp, views]);
|
|
46
|
+
var _useState2 = useState([]),
|
|
47
|
+
toolbarKeys = _useState2[0],
|
|
48
|
+
setToolbarKeys = _useState2[1];
|
|
49
|
+
var result = useMemo(function () {
|
|
50
|
+
var _ref2;
|
|
51
|
+
if (onView)
|
|
52
|
+
// caller is filtering
|
|
53
|
+
return {
|
|
54
|
+
data: dataProp,
|
|
55
|
+
total: total,
|
|
56
|
+
filteredTotal: (_ref2 = filteredTotal != null ? filteredTotal : dataProp == null ? void 0 : dataProp.length) != null ? _ref2 : 0
|
|
57
|
+
};
|
|
39
58
|
return filter(dataProp, view, properties);
|
|
40
|
-
}, [dataProp, onView, properties, view]);
|
|
59
|
+
}, [dataProp, filteredTotal, onView, properties, total, view]);
|
|
41
60
|
|
|
42
61
|
// what we use for DataContext value
|
|
43
62
|
var contextValue = useMemo(function () {
|
|
44
|
-
var
|
|
63
|
+
var value = _extends({
|
|
45
64
|
id: id,
|
|
46
65
|
messages: messages,
|
|
47
66
|
properties: properties,
|
|
48
67
|
updateOn: updateOn,
|
|
49
|
-
view: view
|
|
68
|
+
view: view,
|
|
69
|
+
views: views
|
|
70
|
+
}, result);
|
|
71
|
+
value.clearFilters = function () {
|
|
72
|
+
var nextView = defaultView;
|
|
73
|
+
setView(nextView);
|
|
74
|
+
if (onView) onView(nextView);
|
|
50
75
|
};
|
|
51
|
-
|
|
52
|
-
result.clearFilters = function () {
|
|
53
|
-
var nextView = defaultView;
|
|
54
|
-
setView(nextView);
|
|
55
|
-
if (onView) onView(nextView);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
result.onView = function (nextView) {
|
|
76
|
+
value.onView = function (nextView) {
|
|
59
77
|
setView(nextView);
|
|
60
78
|
if (onView) onView(nextView);
|
|
61
79
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
value.addToolbarKey = function (key) {
|
|
81
|
+
setToolbarKeys(function (prevKeys) {
|
|
82
|
+
if (prevKeys.includes(key)) return prevKeys;
|
|
83
|
+
return [].concat(prevKeys, [key]);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
value.toolbarKeys = toolbarKeys;
|
|
87
|
+
return value;
|
|
88
|
+
}, [defaultView, id, messages, onView, properties, result, toolbarKeys, updateOn, view, views]);
|
|
67
89
|
var toolbarContent;
|
|
68
90
|
if (toolbar) {
|
|
69
91
|
toolbarContent = [/*#__PURE__*/React.createElement(Toolbar, {
|
|
70
92
|
key: "toolbar"
|
|
71
|
-
}, (toolbar === true || toolbar === 'search') && /*#__PURE__*/React.createElement(DataSearch, null), (toolbar === true || toolbar === 'filters') && /*#__PURE__*/React.createElement(DataFilters, {
|
|
93
|
+
}, (toolbar === true || toolbar === 'search') && /*#__PURE__*/React.createElement(DataSearch, null), (toolbar === true || toolbar === 'view') && /*#__PURE__*/React.createElement(DataView, null), (toolbar === true || toolbar === 'filters') && /*#__PURE__*/React.createElement(DataFilters, {
|
|
72
94
|
drop: true
|
|
73
95
|
})), /*#__PURE__*/React.createElement(DataSummary, {
|
|
74
96
|
key: "summary"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var _excluded = ["children", "footer", "
|
|
1
|
+
var _excluded = ["children", "footer", "onDone", "onTouched", "pad", "updateOn"];
|
|
2
2
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
3
3
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
-
import React, { useContext, useEffect, useState } from 'react';
|
|
4
|
+
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
|
5
5
|
import styled from 'styled-components';
|
|
6
6
|
import { Box } from '../Box';
|
|
7
7
|
import { Button } from '../Button';
|
|
@@ -15,6 +15,12 @@ var HideableButton = styled(Button).withConfig({
|
|
|
15
15
|
})(["", ""], function (props) {
|
|
16
16
|
return props.disabled && "\n opacity: 0;";
|
|
17
17
|
});
|
|
18
|
+
var MaxForm = styled(Form).withConfig({
|
|
19
|
+
displayName: "DataForm__MaxForm",
|
|
20
|
+
componentId: "sc-v64e1r-1"
|
|
21
|
+
})(["max-width:100%;", ""], function (props) {
|
|
22
|
+
return props.fill && 'max-height: 100%;';
|
|
23
|
+
});
|
|
18
24
|
var hideButtonProps = {
|
|
19
25
|
'aria-hidden': true,
|
|
20
26
|
disabled: true,
|
|
@@ -24,9 +30,59 @@ var hideButtonProps = {
|
|
|
24
30
|
// We convert the view structure to something more flat to work better
|
|
25
31
|
// with the Form inputs. These keys are how we flatten the Form value object
|
|
26
32
|
// from the view object.
|
|
27
|
-
var formSearchKey = '_search';
|
|
28
|
-
var formSortKey = '_sort';
|
|
29
|
-
var formRangeKey = '_range';
|
|
33
|
+
export var formSearchKey = '_search';
|
|
34
|
+
export var formSortKey = '_sort';
|
|
35
|
+
export var formRangeKey = '_range';
|
|
36
|
+
export var formStepKey = '_step';
|
|
37
|
+
export var formPageKey = '_page';
|
|
38
|
+
export var formColumnsKey = '_columns';
|
|
39
|
+
export var formViewNameKey = '_view';
|
|
40
|
+
var viewFormKeyMap = {
|
|
41
|
+
search: formSearchKey,
|
|
42
|
+
sort: formSortKey,
|
|
43
|
+
step: formStepKey,
|
|
44
|
+
page: formPageKey,
|
|
45
|
+
columns: formColumnsKey,
|
|
46
|
+
view: formViewNameKey
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// flatten nested objects. For example: { a: { b: v } } -> { 'a.b': v }
|
|
50
|
+
var flatten = function flatten(formValue, options) {
|
|
51
|
+
var result = JSON.parse(JSON.stringify(formValue));
|
|
52
|
+
Object.keys(result).forEach(function (k) {
|
|
53
|
+
var name = k;
|
|
54
|
+
// flatten one level at a time, ignore _range situations
|
|
55
|
+
while (typeof result[name] === 'object' && !Array.isArray(result[name]) && (options != null && options.full || !result[name][formRangeKey])) {
|
|
56
|
+
var subPath = Object.keys(result[name])[0];
|
|
57
|
+
var path = name + "." + subPath;
|
|
58
|
+
result[path] = result[name][subPath];
|
|
59
|
+
delete result[name];
|
|
60
|
+
name = path;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return result;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// unflatten nested objects. For example: { 'a.b': v } -> { a: { b: v } }
|
|
67
|
+
var unflatten = function unflatten(formValue) {
|
|
68
|
+
var result = JSON.parse(JSON.stringify(formValue));
|
|
69
|
+
var specialKeys = Object.values(viewFormKeyMap);
|
|
70
|
+
Object.keys(result).filter(function (k) {
|
|
71
|
+
return !specialKeys.includes(k);
|
|
72
|
+
}).forEach(function (k) {
|
|
73
|
+
var parts = k.split('.');
|
|
74
|
+
var val = result[k];
|
|
75
|
+
delete result[k];
|
|
76
|
+
var parent = result;
|
|
77
|
+
while (parts.length > 1) {
|
|
78
|
+
var sub = parts.shift();
|
|
79
|
+
if (!parent[sub]) parent[sub] = {};
|
|
80
|
+
parent = parent[sub];
|
|
81
|
+
}
|
|
82
|
+
parent[parts.shift()] = val;
|
|
83
|
+
});
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
30
86
|
|
|
31
87
|
// converts from the external view format to the internal Form value format
|
|
32
88
|
var viewToFormValue = function viewToFormValue(view) {
|
|
@@ -39,24 +95,38 @@ var viewToFormValue = function viewToFormValue(view) {
|
|
|
39
95
|
result[key] = (_result$key3 = {}, _result$key3[formRangeKey] = [result[key].min, result[key].max], _result$key3);
|
|
40
96
|
}
|
|
41
97
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
98
|
+
|
|
99
|
+
// convert formal view keys to their form '_' prefixed counterparts
|
|
100
|
+
Object.keys(viewFormKeyMap).forEach(function (key) {
|
|
101
|
+
if (view != null && view[key]) result[viewFormKeyMap[key]] = view[key];
|
|
102
|
+
});
|
|
103
|
+
// always have some blank search text
|
|
104
|
+
if (!result[formSearchKey]) result[formSearchKey] = '';
|
|
105
|
+
if (view != null && view.sort) result[formSortKey] = view.sort;
|
|
106
|
+
if (view != null && view.name) result[formViewNameKey] = view.name;
|
|
107
|
+
if (view != null && view.columns) result[formColumnsKey] = view.columns;
|
|
108
|
+
return unflatten(result);
|
|
45
109
|
};
|
|
46
110
|
|
|
47
111
|
// converts from the internal Form value format to the external view format
|
|
48
|
-
var formValueToView = function formValueToView(value) {
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
112
|
+
var formValueToView = function formValueToView(value, views) {
|
|
113
|
+
var result = {};
|
|
114
|
+
|
|
115
|
+
// if the user chose a view, use that
|
|
116
|
+
if (value[formViewNameKey]) result = JSON.parse(JSON.stringify(views.find(function (v) {
|
|
117
|
+
return v.name === value[formViewNameKey];
|
|
118
|
+
})));
|
|
119
|
+
var valueCopy = _extends({}, value);
|
|
120
|
+
Object.keys(viewFormKeyMap).forEach(function (key) {
|
|
121
|
+
if (valueCopy[viewFormKeyMap[key]]) {
|
|
122
|
+
result[key] = valueCopy[viewFormKeyMap[key]];
|
|
123
|
+
}
|
|
124
|
+
delete valueCopy[viewFormKeyMap[key]];
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// flatten any nested objects
|
|
128
|
+
var flatValue = flatten(valueCopy);
|
|
129
|
+
result.properties = _extends({}, result.properties || {}, flatValue);
|
|
60
130
|
|
|
61
131
|
// convert any ranges
|
|
62
132
|
Object.keys(result.properties).forEach(function (key) {
|
|
@@ -72,27 +142,79 @@ var formValueToView = function formValueToView(value) {
|
|
|
72
142
|
|
|
73
143
|
// remove any empty arrays of property values by deleting the key for
|
|
74
144
|
// that property in the view properties
|
|
75
|
-
var clearEmpty = function clearEmpty(
|
|
76
|
-
var
|
|
77
|
-
Object.keys(
|
|
78
|
-
|
|
79
|
-
})
|
|
80
|
-
|
|
145
|
+
var clearEmpty = function clearEmpty(formValue) {
|
|
146
|
+
var value = formValue;
|
|
147
|
+
Object.keys(value).forEach(function (k) {
|
|
148
|
+
if (Array.isArray(value[k]) && value[k].length === 0) delete value[k];
|
|
149
|
+
});
|
|
150
|
+
return value;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// if paging, when anything other than the page changes, reset the page to 1
|
|
154
|
+
var resetPage = function resetPage(nextFormValue, prevFormValue) {
|
|
155
|
+
if (prevFormValue[formPageKey] && prevFormValue[formPageKey] > 1)
|
|
156
|
+
// eslint-disable-next-line no-param-reassign
|
|
157
|
+
nextFormValue[formPageKey] = 1;
|
|
158
|
+
};
|
|
159
|
+
var transformTouched = function transformTouched(touched, value) {
|
|
160
|
+
var result = {};
|
|
161
|
+
Object.keys(touched).forEach(function (key) {
|
|
162
|
+
// special case _range fields
|
|
163
|
+
var parts = key.split('.');
|
|
164
|
+
if (parts[1] === formRangeKey) result[key] = value[parts[0]];else result[key] = flatten(value, {
|
|
165
|
+
full: true
|
|
166
|
+
})[key];
|
|
81
167
|
});
|
|
82
168
|
return result;
|
|
83
169
|
};
|
|
170
|
+
|
|
171
|
+
// function shared by onSubmit and onChange to coordinate view
|
|
172
|
+
// name changes
|
|
173
|
+
var normalizeValue = function normalizeValue(nextValue, prevValue, views) {
|
|
174
|
+
if (nextValue[formViewNameKey] && nextValue[formViewNameKey] !== prevValue[formViewNameKey]) {
|
|
175
|
+
// view name changed, reset view contents from named view
|
|
176
|
+
return viewToFormValue(views.find(function (v) {
|
|
177
|
+
return v.name === nextValue[formViewNameKey];
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
// something else changed
|
|
181
|
+
|
|
182
|
+
// clear empty properties
|
|
183
|
+
var result = clearEmpty(nextValue);
|
|
184
|
+
|
|
185
|
+
// if we have a view and something related to it changed, clear the view
|
|
186
|
+
if (result[formViewNameKey]) {
|
|
187
|
+
var view = views.find(function (v) {
|
|
188
|
+
return v.name === result[formViewNameKey];
|
|
189
|
+
});
|
|
190
|
+
var viewValue = viewToFormValue(view);
|
|
191
|
+
clearEmpty(viewValue);
|
|
192
|
+
if (Object.keys(viewValue).some(function (k) {
|
|
193
|
+
return (
|
|
194
|
+
// allow mismatch between empty and set strings
|
|
195
|
+
viewValue[k] && result[k] && JSON.stringify(result[k]) !== JSON.stringify(viewValue[k])
|
|
196
|
+
);
|
|
197
|
+
})) {
|
|
198
|
+
delete result[formViewNameKey];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
};
|
|
84
203
|
export var DataForm = function DataForm(_ref) {
|
|
85
204
|
var children = _ref.children,
|
|
86
205
|
footer = _ref.footer,
|
|
87
|
-
gap = _ref.gap,
|
|
88
206
|
onDone = _ref.onDone,
|
|
207
|
+
onTouched = _ref.onTouched,
|
|
89
208
|
pad = _ref.pad,
|
|
209
|
+
updateOnProp = _ref.updateOn,
|
|
90
210
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
91
211
|
var _useContext = useContext(DataContext),
|
|
92
212
|
messages = _useContext.messages,
|
|
93
213
|
onView = _useContext.onView,
|
|
94
|
-
|
|
95
|
-
view = _useContext.view
|
|
214
|
+
updateOnData = _useContext.updateOn,
|
|
215
|
+
view = _useContext.view,
|
|
216
|
+
views = _useContext.views;
|
|
217
|
+
var updateOn = updateOnProp != null ? updateOnProp : updateOnData;
|
|
96
218
|
var _useContext2 = useContext(MessageContext),
|
|
97
219
|
format = _useContext2.format;
|
|
98
220
|
var _useState = useState(viewToFormValue(view)),
|
|
@@ -101,30 +223,59 @@ export var DataForm = function DataForm(_ref) {
|
|
|
101
223
|
var _useState2 = useState(),
|
|
102
224
|
changed = _useState2[0],
|
|
103
225
|
setChanged = _useState2[1];
|
|
226
|
+
var onSubmit = useCallback(function (_ref2) {
|
|
227
|
+
var value = _ref2.value,
|
|
228
|
+
touched = _ref2.touched;
|
|
229
|
+
var nextValue = normalizeValue(value, formValue, views);
|
|
230
|
+
resetPage(nextValue, formValue);
|
|
231
|
+
setFormValue(nextValue);
|
|
232
|
+
setChanged(false);
|
|
233
|
+
if (onTouched) onTouched(transformTouched(touched, nextValue));
|
|
234
|
+
onView(formValueToView(nextValue, views));
|
|
235
|
+
if (onDone) onDone();
|
|
236
|
+
}, [formValue, onDone, onTouched, onView, views]);
|
|
237
|
+
var onChange = useCallback(function (value, _ref3) {
|
|
238
|
+
var touched = _ref3.touched;
|
|
239
|
+
var nextValue = normalizeValue(value, formValue, views);
|
|
240
|
+
resetPage(nextValue, formValue);
|
|
241
|
+
setFormValue(nextValue);
|
|
242
|
+
setChanged(true);
|
|
243
|
+
if (updateOn === 'change') {
|
|
244
|
+
if (onTouched) onTouched(transformTouched(touched, nextValue));
|
|
245
|
+
onView(formValueToView(nextValue, views));
|
|
246
|
+
}
|
|
247
|
+
}, [formValue, onTouched, onView, updateOn, views]);
|
|
248
|
+
var onReset = useCallback(function () {
|
|
249
|
+
setFormValue(viewToFormValue(view));
|
|
250
|
+
setChanged(false);
|
|
251
|
+
}, [view]);
|
|
104
252
|
useEffect(function () {
|
|
105
253
|
return setFormValue(viewToFormValue(view));
|
|
106
254
|
}, [view]);
|
|
107
|
-
return /*#__PURE__*/React.createElement(
|
|
255
|
+
return /*#__PURE__*/React.createElement(MaxForm, _extends({}, rest, {
|
|
108
256
|
value: formValue,
|
|
109
|
-
onSubmit: updateOn === 'submit' ?
|
|
110
|
-
|
|
111
|
-
clearEmpty(nextValue);
|
|
112
|
-
setFormValue(nextValue);
|
|
113
|
-
setChanged(false);
|
|
114
|
-
onView(formValueToView(nextValue));
|
|
115
|
-
if (onDone) onDone();
|
|
116
|
-
} : undefined,
|
|
117
|
-
onChange: function onChange(nextValue) {
|
|
118
|
-
clearEmpty(nextValue);
|
|
119
|
-
setFormValue(nextValue);
|
|
120
|
-
setChanged(true);
|
|
121
|
-
if (updateOn === 'change') onView(formValueToView(nextValue));
|
|
122
|
-
}
|
|
257
|
+
onSubmit: updateOn === 'submit' ? onSubmit : undefined,
|
|
258
|
+
onChange: onChange
|
|
123
259
|
}), /*#__PURE__*/React.createElement(Box, {
|
|
260
|
+
fill: "vertical"
|
|
261
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
262
|
+
flex: true,
|
|
263
|
+
overflow: "auto",
|
|
264
|
+
pad: {
|
|
265
|
+
horizontal: pad,
|
|
266
|
+
top: pad
|
|
267
|
+
}
|
|
268
|
+
}, children), footer !== false && updateOn === 'submit' && /*#__PURE__*/React.createElement(Footer, {
|
|
124
269
|
flex: false,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
270
|
+
margin: {
|
|
271
|
+
top: 'small'
|
|
272
|
+
},
|
|
273
|
+
pad: {
|
|
274
|
+
horizontal: pad,
|
|
275
|
+
bottom: pad
|
|
276
|
+
},
|
|
277
|
+
gap: "small"
|
|
278
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
128
279
|
label: format({
|
|
129
280
|
id: 'dataForm.submit',
|
|
130
281
|
messages: messages == null ? void 0 : messages.dataForm
|
|
@@ -137,9 +288,6 @@ export var DataForm = function DataForm(_ref) {
|
|
|
137
288
|
messages: messages == null ? void 0 : messages.dataForm
|
|
138
289
|
}),
|
|
139
290
|
type: "reset",
|
|
140
|
-
onClick:
|
|
141
|
-
setFormValue(viewToFormValue(view));
|
|
142
|
-
setChanged(false);
|
|
143
|
-
}
|
|
291
|
+
onClick: onReset
|
|
144
292
|
}, !changed ? hideButtonProps : {})))));
|
|
145
293
|
};
|