grommet 2.35.0 → 2.36.1
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 +1 -4
- package/components/Anchor/StyledAnchor.js +1 -1
- package/components/Box/Box.js +2 -2
- package/components/Box/StyledBox.js +18 -1
- package/components/Box/index.d.ts +1 -1
- package/components/Box/propTypes.js +4 -1
- package/components/Cards/stories/Simple.js +1 -4
- package/components/Data/stories/Cards.js +9 -19
- package/components/Data/stories/Complex.js +1 -4
- package/components/Data/stories/ComposedToolbar.js +74 -0
- package/components/Data/stories/Infinite.js +29 -64
- package/components/Data/stories/Inline.js +1 -9
- package/components/Data/stories/List.js +3 -9
- package/components/Data/stories/Properties.js +17 -22
- package/components/Data/stories/Simple.js +4 -10
- package/components/Data/stories/SpaceX.js +9 -11
- package/components/Data/stories/StarWars.js +6 -12
- package/components/Data/stories/Views.js +4 -11
- package/components/DataFilter/DataFilter.js +1 -0
- package/components/DataFilter/stories/Simple.js +2 -6
- package/components/DataFilters/stories/Drop.js +2 -6
- package/components/DataFilters/stories/Layer.js +2 -6
- package/components/DataFilters/stories/Simple.js +2 -6
- package/components/DataSearch/stories/Drop.js +6 -11
- package/components/DataSearch/stories/Responsive.js +6 -12
- package/components/DataSearch/stories/Simple.js +5 -10
- package/components/DataSearch/stories/UpdateOnSubmit.js +5 -7
- package/components/DataSort/stories/Drop.js +2 -6
- package/components/DataSort/stories/Simple.js +2 -6
- package/components/DataSummary/stories/Simple.js +2 -6
- package/components/DataTableColumns/stories/Simple.js +2 -6
- package/components/DataTableGroupBy/stories/Simple.js +5 -7
- package/components/DataView/stories/Simple.js +4 -6
- package/components/DateInput/DateInput.js +61 -17
- package/components/DateInput/index.d.ts +1 -0
- package/components/DateInput/propTypes.js +1 -0
- package/components/DateInput/stories/ReadOnly.js +36 -0
- package/components/DateInput/utils.js +2 -2
- package/components/Form/Form.js +34 -1
- package/components/FormField/FormField.js +20 -1
- package/components/FormField/README.md +1 -644
- package/components/FormField/index.d.ts +5 -1
- package/components/FormField/propTypes.js +4 -1
- package/components/FormField/stories/ThresholdValidation.js +51 -0
- package/components/Grommet/Grommet.js +1 -1
- package/components/Grommet/index.d.ts +12 -0
- package/components/Grommet/propTypes.js +12 -0
- package/components/Layer/LayerContainer.js +1 -1
- package/components/List/List.js +33 -30
- package/components/Pagination/Pagination.js +52 -9
- package/components/Pagination/PaginationStep.js +41 -0
- package/components/Pagination/PaginationSummary.js +33 -0
- package/components/Pagination/index.d.ts +2 -0
- package/components/Pagination/propTypes.js +3 -1
- package/components/Pagination/stories/Steps.js +40 -0
- package/components/RangeInput/RangeInput.js +19 -12
- package/components/TextInput/CopyButton.js +54 -0
- package/components/TextInput/StyledTextInput.js +13 -2
- package/components/TextInput/TextInput.js +46 -12
- package/components/TextInput/index.d.ts +1 -0
- package/components/TextInput/propTypes.js +1 -0
- package/components/TextInput/stories/ReadOnly.js +43 -0
- package/components/Toolbar/stories/Simple.js +1 -4
- package/es6/components/Anchor/Anchor.js +1 -4
- package/es6/components/Anchor/StyledAnchor.js +1 -1
- package/es6/components/Box/Box.js +2 -2
- package/es6/components/Box/StyledBox.js +18 -1
- package/es6/components/Box/index.d.ts +1 -1
- package/es6/components/Box/propTypes.js +4 -1
- package/es6/components/Cards/stories/Simple.js +2 -5
- package/es6/components/Data/stories/Cards.js +10 -20
- package/es6/components/Data/stories/Complex.js +2 -5
- package/es6/components/Data/stories/ComposedToolbar.js +69 -0
- package/es6/components/Data/stories/Infinite.js +32 -66
- package/es6/components/Data/stories/Inline.js +2 -10
- package/es6/components/Data/stories/List.js +4 -10
- package/es6/components/Data/stories/Properties.js +18 -23
- package/es6/components/Data/stories/Simple.js +5 -11
- package/es6/components/Data/stories/SpaceX.js +11 -13
- package/es6/components/Data/stories/StarWars.js +7 -13
- package/es6/components/Data/stories/Views.js +5 -12
- package/es6/components/DataFilter/DataFilter.js +1 -0
- package/es6/components/DataFilter/stories/Simple.js +2 -6
- package/es6/components/DataFilters/stories/Drop.js +2 -6
- package/es6/components/DataFilters/stories/Layer.js +2 -6
- package/es6/components/DataFilters/stories/Simple.js +2 -6
- package/es6/components/DataSearch/stories/Drop.js +7 -12
- package/es6/components/DataSearch/stories/Responsive.js +7 -13
- package/es6/components/DataSearch/stories/Simple.js +6 -11
- package/es6/components/DataSearch/stories/UpdateOnSubmit.js +6 -8
- package/es6/components/DataSort/stories/Drop.js +2 -6
- package/es6/components/DataSort/stories/Simple.js +2 -6
- package/es6/components/DataSummary/stories/Simple.js +2 -6
- package/es6/components/DataTableColumns/stories/Simple.js +2 -6
- package/es6/components/DataTableGroupBy/stories/Simple.js +5 -7
- package/es6/components/DataView/stories/Simple.js +6 -8
- package/es6/components/DateInput/DateInput.js +61 -17
- package/es6/components/DateInput/index.d.ts +1 -0
- package/es6/components/DateInput/propTypes.js +1 -0
- package/es6/components/DateInput/stories/ReadOnly.js +31 -0
- package/es6/components/DateInput/utils.js +2 -2
- package/es6/components/Form/Form.js +34 -1
- package/es6/components/FormField/FormField.js +21 -2
- package/es6/components/FormField/README.md +1 -644
- package/es6/components/FormField/index.d.ts +5 -1
- package/es6/components/FormField/propTypes.js +4 -1
- package/es6/components/FormField/stories/ThresholdValidation.js +46 -0
- package/es6/components/Grommet/Grommet.js +1 -1
- package/es6/components/Grommet/index.d.ts +12 -0
- package/es6/components/Grommet/propTypes.js +12 -0
- package/es6/components/Layer/LayerContainer.js +1 -1
- package/es6/components/List/List.js +33 -30
- package/es6/components/Pagination/Pagination.js +52 -9
- package/es6/components/Pagination/PaginationStep.js +35 -0
- package/es6/components/Pagination/PaginationSummary.js +27 -0
- package/es6/components/Pagination/index.d.ts +2 -0
- package/es6/components/Pagination/propTypes.js +3 -1
- package/es6/components/Pagination/stories/Steps.js +35 -0
- package/es6/components/RangeInput/RangeInput.js +19 -12
- package/es6/components/TextInput/CopyButton.js +49 -0
- package/es6/components/TextInput/StyledTextInput.js +14 -3
- package/es6/components/TextInput/TextInput.js +46 -12
- package/es6/components/TextInput/index.d.ts +1 -0
- package/es6/components/TextInput/propTypes.js +1 -0
- package/es6/components/TextInput/stories/ReadOnly.js +38 -0
- package/es6/components/Toolbar/stories/Simple.js +2 -5
- package/es6/languages/default.json +23 -0
- package/es6/themes/base.d.ts +8 -0
- package/es6/themes/base.js +12 -1
- package/es6/utils/index.js +1 -0
- package/es6/utils/readOnly.js +10 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/languages/default.json +23 -0
- package/package.json +31 -32
- package/themes/base.d.ts +8 -0
- package/themes/base.js +12 -1
- package/utils/index.js +6 -0
- package/utils/readOnly.js +14 -0
- package/components/Data/stories/Controlled.js +0 -92
- package/components/Data/stories/DataTable.js +0 -49
- package/components/DataFilters/stories/Inline.js +0 -53
- package/es6/components/Data/stories/Controlled.js +0 -86
- package/es6/components/Data/stories/DataTable.js +0 -44
- package/es6/components/DataFilters/stories/Inline.js +0 -48
|
@@ -104,6 +104,18 @@ export interface GrommetProps {
|
|
|
104
104
|
invalid?: string;
|
|
105
105
|
required?: string;
|
|
106
106
|
};
|
|
107
|
+
formField?: {
|
|
108
|
+
maxCharacters?: {
|
|
109
|
+
remaining?: {
|
|
110
|
+
singular?: string;
|
|
111
|
+
plural?: string;
|
|
112
|
+
};
|
|
113
|
+
overLimit?: {
|
|
114
|
+
singular?: string;
|
|
115
|
+
plural: string;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
};
|
|
107
119
|
menu?: {
|
|
108
120
|
openMenu?: string;
|
|
109
121
|
closeMenu?: string;
|
|
@@ -106,6 +106,18 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
106
106
|
invalid: PropTypes.string,
|
|
107
107
|
required: PropTypes.string
|
|
108
108
|
}),
|
|
109
|
+
formField: PropTypes.shape({
|
|
110
|
+
maxCharacters: PropTypes.shape({
|
|
111
|
+
remaining: PropTypes.shape({
|
|
112
|
+
singular: PropTypes.string,
|
|
113
|
+
plural: PropTypes.string
|
|
114
|
+
}),
|
|
115
|
+
overLimit: PropTypes.shape({
|
|
116
|
+
singular: PropTypes.string,
|
|
117
|
+
plural: PropTypes.string
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
}),
|
|
109
121
|
menu: PropTypes.shape({
|
|
110
122
|
openMenu: PropTypes.string,
|
|
111
123
|
closeMenu: PropTypes.string
|
|
@@ -15,7 +15,7 @@ import { StyledLayer, StyledContainer, StyledOverlay } from './StyledLayer';
|
|
|
15
15
|
var HiddenAnchor = styled.a.withConfig({
|
|
16
16
|
displayName: "LayerContainer__HiddenAnchor",
|
|
17
17
|
componentId: "sc-1srj14c-0"
|
|
18
|
-
})(["width:0;height:0;overflow:hidden;position:absolute;"]);
|
|
18
|
+
})(["width:0;height:0;overflow:hidden;position:absolute;&:focus{outline:none;}"]);
|
|
19
19
|
var LayerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
20
20
|
var background = _ref.background,
|
|
21
21
|
children = _ref.children,
|
|
@@ -17,21 +17,16 @@ var emptyData = [];
|
|
|
17
17
|
var StyledList = styled.ul.withConfig({
|
|
18
18
|
displayName: "List__StyledList",
|
|
19
19
|
componentId: "sc-130gdqg-0"
|
|
20
|
-
})(["list-style:none;", " padding:0;", " &:focus{", "}", "}", "}"], function (props) {
|
|
20
|
+
})(["list-style:none;", " padding:0;", " &:focus{", "}", "}&:focus:not(:focus-visible){", "}"], function (props) {
|
|
21
21
|
return !props.margin && 'margin: 0;';
|
|
22
22
|
}, genericStyles, function (props) {
|
|
23
23
|
return props.tabIndex >= 0 && focusStyle({
|
|
24
24
|
forceOutline: true,
|
|
25
25
|
skipSvgChildren: true
|
|
26
26
|
});
|
|
27
|
-
}, function (props) {
|
|
28
|
-
return props.itemFocus && focusStyle({
|
|
29
|
-
forceOutline: true,
|
|
30
|
-
skipSvgChildren: true
|
|
31
|
-
});
|
|
32
27
|
}, function (props) {
|
|
33
28
|
return props.theme.list && props.theme.list.extend;
|
|
34
|
-
});
|
|
29
|
+
}, unfocusStyle());
|
|
35
30
|
var StyledItem = styled(Box).withConfig({
|
|
36
31
|
displayName: "List__StyledItem",
|
|
37
32
|
componentId: "sc-130gdqg-1"
|
|
@@ -224,21 +219,17 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
224
219
|
}
|
|
225
220
|
ariaProps['aria-activedescendant'] = activeId;
|
|
226
221
|
}
|
|
227
|
-
|
|
228
|
-
|
|
222
|
+
var onSelectOption = function onSelectOption(event) {
|
|
223
|
+
if ((onClickItem || onOrder) && active >= 0) {
|
|
229
224
|
if (onOrder) {
|
|
230
225
|
var index = Math.trunc(active / 2);
|
|
231
226
|
// Call onOrder with the re-ordered data.
|
|
232
227
|
// Update the active control index so that the
|
|
233
228
|
// active control will stay on the same item
|
|
234
229
|
// even though it moved up or down.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
} else {
|
|
239
|
-
onOrder(reorder(orderableData, pinnedInfo, index, index - 1));
|
|
240
|
-
updateActive(Math.max(active - 2, 1));
|
|
241
|
-
}
|
|
230
|
+
var newIndex = active % 2 ? index + 1 : index - 1;
|
|
231
|
+
onOrder(reorder(orderableData, pinnedInfo, index, newIndex));
|
|
232
|
+
updateActive(active % 2 ? Math.min(active + 2, orderableData.length * 2 - 2) : Math.max(active - 2, 1));
|
|
242
233
|
} else if (disabledItems != null && disabledItems.includes(getValue(data[active], active, itemKey))) {
|
|
243
234
|
event.preventDefault();
|
|
244
235
|
} else if (onClickItem) {
|
|
@@ -255,16 +246,29 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
255
246
|
index: active
|
|
256
247
|
});
|
|
257
248
|
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
return /*#__PURE__*/React.createElement(Container, containterProps, /*#__PURE__*/React.createElement(Keyboard, {
|
|
252
|
+
onEnter: onSelectOption,
|
|
253
|
+
onSpace: function onSpace(event) {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
onSelectOption(event);
|
|
256
|
+
},
|
|
257
|
+
onUp: function onUp(event) {
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
if ((onClickItem || onOrder) && active) {
|
|
260
|
+
var min = onOrder ? 1 : 0;
|
|
261
|
+
updateActive(Math.max(active - 1, min));
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
onDown: function onDown(event) {
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
if ((onClickItem || onOrder) && orderableData && orderableData.length) {
|
|
267
|
+
var min = onOrder ? 1 : 0;
|
|
268
|
+
var max = onOrder ? orderableData.length * 2 - 2 : data.length - 1;
|
|
269
|
+
updateActive(active >= min ? Math.min(active + 1, max) : min);
|
|
270
|
+
}
|
|
271
|
+
},
|
|
268
272
|
onKeyDown: onKeyDown
|
|
269
273
|
}, /*#__PURE__*/React.createElement(StyledList, _extends({
|
|
270
274
|
"aria-label": ariaLabel || a11yTitle,
|
|
@@ -305,10 +309,9 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
305
309
|
} : undefined);
|
|
306
310
|
} else if (primaryKey) {
|
|
307
311
|
var primary = getValue(item, index, primaryKey);
|
|
308
|
-
content = typeof primary === 'string' || typeof primary === 'number' ? /*#__PURE__*/React.createElement(Text, {
|
|
309
|
-
key: "p"
|
|
310
|
-
|
|
311
|
-
}, primary) : primary;
|
|
312
|
+
content = typeof primary === 'string' || typeof primary === 'number' ? /*#__PURE__*/React.createElement(Text, _extends({
|
|
313
|
+
key: "p"
|
|
314
|
+
}, theme.list.primaryKey), primary) : primary;
|
|
312
315
|
if (secondaryKey) {
|
|
313
316
|
var secondary = getValue(item, index, secondaryKey);
|
|
314
317
|
content = [content, typeof secondary === 'string' || typeof secondary === 'number' ? /*#__PURE__*/React.createElement(Text, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["a11yTitle", "aria-label", "numberItems", "numberEdgePages", "numberMiddlePages", "onChange", "page", "size", "step"];
|
|
1
|
+
var _excluded = ["a11yTitle", "aria-label", "numberItems", "numberEdgePages", "numberMiddlePages", "onChange", "messages", "page", "size", "step", "stepOptions", "summary"];
|
|
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, { forwardRef, useContext, useEffect, useState } from 'react';
|
|
@@ -8,6 +8,8 @@ import { DataContext } from '../../contexts/DataContext';
|
|
|
8
8
|
import { Box } from '../Box';
|
|
9
9
|
import { Nav } from '../Nav';
|
|
10
10
|
import { PageControl } from './PageControl';
|
|
11
|
+
import { PaginationStep } from './PaginationStep';
|
|
12
|
+
import { PaginationSummary } from './PaginationSummary';
|
|
11
13
|
import { PaginationPropTypes } from './propTypes';
|
|
12
14
|
var StyledPaginationContainer = styled(Box).withConfig({
|
|
13
15
|
displayName: "Pagination__StyledPaginationContainer",
|
|
@@ -32,24 +34,29 @@ var Pagination = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
32
34
|
_ref$numberMiddlePage = _ref.numberMiddlePages,
|
|
33
35
|
numberMiddlePagesProp = _ref$numberMiddlePage === void 0 ? 3 : _ref$numberMiddlePage,
|
|
34
36
|
onChange = _ref.onChange,
|
|
37
|
+
messages = _ref.messages,
|
|
35
38
|
pageProp = _ref.page,
|
|
36
39
|
size = _ref.size,
|
|
37
40
|
stepProp = _ref.step,
|
|
41
|
+
stepOptions = _ref.stepOptions,
|
|
42
|
+
summary = _ref.summary,
|
|
38
43
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
39
44
|
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
40
45
|
var _useContext = useContext(DataContext),
|
|
41
46
|
onView = _useContext.onView,
|
|
42
47
|
filteredTotal = _useContext.filteredTotal,
|
|
43
48
|
view = _useContext.view;
|
|
44
|
-
var
|
|
49
|
+
var _useState = useState(stepProp || (view == null ? void 0 : view.step) || 10),
|
|
50
|
+
step = _useState[0],
|
|
51
|
+
setStep = _useState[1];
|
|
45
52
|
var total = (_ref2 = numberItems != null ? numberItems : filteredTotal) != null ? _ref2 : 0;
|
|
46
53
|
var page = pageProp || (view == null ? void 0 : view.page) || 1;
|
|
47
54
|
|
|
48
55
|
/* Calculate total number pages */
|
|
49
56
|
var totalPages = Math.ceil(total / step);
|
|
50
|
-
var
|
|
51
|
-
activePage =
|
|
52
|
-
setActivePage =
|
|
57
|
+
var _useState2 = useState(Math.min(page, totalPages) || 1),
|
|
58
|
+
activePage = _useState2[0],
|
|
59
|
+
setActivePage = _useState2[1];
|
|
53
60
|
useEffect(function () {
|
|
54
61
|
setActivePage(page);
|
|
55
62
|
var pageEvent = new Event('pagechange');
|
|
@@ -164,9 +171,7 @@ var Pagination = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
164
171
|
separator: control === 'more-prev' || control === 'more-next'
|
|
165
172
|
}, navProps[control]);
|
|
166
173
|
});
|
|
167
|
-
|
|
168
|
-
flex: false
|
|
169
|
-
}, theme.pagination.container, rest), /*#__PURE__*/React.createElement(Nav, {
|
|
174
|
+
var paginationControls = /*#__PURE__*/React.createElement(Nav, {
|
|
170
175
|
a11yTitle: ariaLabel || a11yTitle || 'Pagination Navigation',
|
|
171
176
|
ref: ref
|
|
172
177
|
}, /*#__PURE__*/React.createElement(Box, _extends({
|
|
@@ -184,7 +189,45 @@ var Pagination = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
184
189
|
size: size
|
|
185
190
|
}, control))
|
|
186
191
|
);
|
|
187
|
-
})))
|
|
192
|
+
})));
|
|
193
|
+
|
|
194
|
+
// for backwards compatibility
|
|
195
|
+
if (!summary && !stepOptions) return /*#__PURE__*/React.createElement(StyledPaginationContainer, _extends({
|
|
196
|
+
flex: false
|
|
197
|
+
}, theme.pagination.container, rest), paginationControls);
|
|
198
|
+
return /*#__PURE__*/React.createElement(StyledPaginationContainer, _extends({
|
|
199
|
+
direction: "row",
|
|
200
|
+
align: "center",
|
|
201
|
+
gap: {
|
|
202
|
+
column: 'xsmall',
|
|
203
|
+
row: 'small'
|
|
204
|
+
},
|
|
205
|
+
wrap: true,
|
|
206
|
+
flex: false
|
|
207
|
+
}, theme.pagination.container, rest), /*#__PURE__*/React.createElement(Box, {
|
|
208
|
+
flex: "grow"
|
|
209
|
+
}, summary && /*#__PURE__*/React.createElement(PaginationSummary, {
|
|
210
|
+
messages: messages,
|
|
211
|
+
page: activePage,
|
|
212
|
+
step: step,
|
|
213
|
+
numberItems: total
|
|
214
|
+
})), /*#__PURE__*/React.createElement(Box, {
|
|
215
|
+
align: "center",
|
|
216
|
+
direction: "row",
|
|
217
|
+
gap: {
|
|
218
|
+
column: 'xsmall',
|
|
219
|
+
row: 'small'
|
|
220
|
+
},
|
|
221
|
+
wrap: true
|
|
222
|
+
}, stepOptions && /*#__PURE__*/React.createElement(PaginationStep, {
|
|
223
|
+
messages: messages,
|
|
224
|
+
options: Array.isArray(stepOptions) ? stepOptions : undefined,
|
|
225
|
+
step: step,
|
|
226
|
+
onChange: function onChange(_ref3) {
|
|
227
|
+
var value = _ref3.value;
|
|
228
|
+
return setStep(value);
|
|
229
|
+
}
|
|
230
|
+
}), paginationControls));
|
|
188
231
|
});
|
|
189
232
|
Pagination.displayName = 'Pagination';
|
|
190
233
|
Pagination.propTypes = PaginationPropTypes;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var _excluded = ["messages", "onChange", "options", "step"];
|
|
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
|
+
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
|
+
import React, { useContext } from 'react';
|
|
5
|
+
import { ThemeContext } from 'styled-components';
|
|
6
|
+
import { Box } from '../Box';
|
|
7
|
+
import { Select } from '../Select';
|
|
8
|
+
import { Text } from '../Text';
|
|
9
|
+
import { MessageContext } from '../../contexts/MessageContext';
|
|
10
|
+
export var PaginationStep = function PaginationStep(_ref) {
|
|
11
|
+
var messages = _ref.messages,
|
|
12
|
+
onChange = _ref.onChange,
|
|
13
|
+
_ref$options = _ref.options,
|
|
14
|
+
options = _ref$options === void 0 ? [10, 25, 50, 100] : _ref$options,
|
|
15
|
+
step = _ref.step,
|
|
16
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
17
|
+
var _useContext = useContext(MessageContext),
|
|
18
|
+
formatMessage = _useContext.format;
|
|
19
|
+
var theme = useContext(ThemeContext);
|
|
20
|
+
return /*#__PURE__*/React.createElement(Box, _extends({
|
|
21
|
+
direction: "row",
|
|
22
|
+
align: "center",
|
|
23
|
+
gap: "xsmall"
|
|
24
|
+
}, rest), /*#__PURE__*/React.createElement(Text, null, formatMessage({
|
|
25
|
+
id: 'pagination.stepLabel',
|
|
26
|
+
messages: messages
|
|
27
|
+
})), /*#__PURE__*/React.createElement(Select, {
|
|
28
|
+
options: options,
|
|
29
|
+
value: step,
|
|
30
|
+
valueLabel: /*#__PURE__*/React.createElement(Box, _extends({}, theme.global.input, {
|
|
31
|
+
pad: theme.global.input.padding
|
|
32
|
+
}), /*#__PURE__*/React.createElement(Text, theme.global.input.font, step)),
|
|
33
|
+
onChange: onChange
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var _excluded = ["messages", "numberItems", "page", "step"];
|
|
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
|
+
import React, { useContext } from 'react';
|
|
4
|
+
import { Box } from '../Box';
|
|
5
|
+
import { Text } from '../Text';
|
|
6
|
+
import { MessageContext } from '../../contexts/MessageContext';
|
|
7
|
+
export var PaginationSummary = function PaginationSummary(_ref) {
|
|
8
|
+
var messages = _ref.messages,
|
|
9
|
+
numberItems = _ref.numberItems,
|
|
10
|
+
page = _ref.page,
|
|
11
|
+
step = _ref.step,
|
|
12
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
13
|
+
var _useContext = useContext(MessageContext),
|
|
14
|
+
formatMessage = _useContext.format;
|
|
15
|
+
return /*#__PURE__*/React.createElement(Box, rest, /*#__PURE__*/React.createElement(Text, null, numberItems > 0 ? formatMessage({
|
|
16
|
+
id: 'pagination.summary',
|
|
17
|
+
messages: messages,
|
|
18
|
+
values: {
|
|
19
|
+
start: "" + ((page - 1) * step + 1),
|
|
20
|
+
end: "" + Math.min(page * step, numberItems),
|
|
21
|
+
total: numberItems
|
|
22
|
+
}
|
|
23
|
+
}) : formatMessage({
|
|
24
|
+
id: 'pagination.summaryNoItems',
|
|
25
|
+
messages: messages
|
|
26
|
+
})));
|
|
27
|
+
};
|
|
@@ -18,6 +18,8 @@ export interface PaginationProps {
|
|
|
18
18
|
page?: number;
|
|
19
19
|
size?: 'small' | 'medium' | 'large';
|
|
20
20
|
step?: number;
|
|
21
|
+
stepOptions?: boolean | (string | boolean | number | JSX.Element | object)[];
|
|
22
|
+
summary?: boolean;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
declare const Pagination: React.FC<PaginationProps>;
|
|
@@ -10,7 +10,9 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
10
10
|
onChange: PropTypes.func,
|
|
11
11
|
page: PropTypes.number,
|
|
12
12
|
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
13
|
-
step: PropTypes.number
|
|
13
|
+
step: PropTypes.number,
|
|
14
|
+
stepOptions: PropTypes.oneOfType([PropTypes.bool, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool, PropTypes.element, PropTypes.object]))]),
|
|
15
|
+
summary: PropTypes.bool
|
|
14
16
|
});
|
|
15
17
|
}
|
|
16
18
|
export var PaginationPropTypes = PropType;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Pagination, Text } from 'grommet';
|
|
3
|
+
export var Steps = function Steps() {
|
|
4
|
+
return (
|
|
5
|
+
/*#__PURE__*/
|
|
6
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
7
|
+
// <Grommet theme={...}>
|
|
8
|
+
React.createElement(Box, {
|
|
9
|
+
align: "start",
|
|
10
|
+
pad: "small",
|
|
11
|
+
gap: "xlarge"
|
|
12
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
13
|
+
fill: "horizontal"
|
|
14
|
+
}, /*#__PURE__*/React.createElement(Text, null, "Pagination with stepOptions"), /*#__PURE__*/React.createElement(Pagination, {
|
|
15
|
+
numberItems: 237,
|
|
16
|
+
stepOptions: true
|
|
17
|
+
})), /*#__PURE__*/React.createElement(Box, {
|
|
18
|
+
fill: "horizontal"
|
|
19
|
+
}, /*#__PURE__*/React.createElement(Text, null, "Pagination with stepOptions and summary"), /*#__PURE__*/React.createElement(Pagination, {
|
|
20
|
+
numberItems: 237,
|
|
21
|
+
stepOptions: true,
|
|
22
|
+
summary: true
|
|
23
|
+
})), /*#__PURE__*/React.createElement(Box, {
|
|
24
|
+
fill: "horizontal"
|
|
25
|
+
}, /*#__PURE__*/React.createElement(Text, null, "Pagination with custom step sizes"), /*#__PURE__*/React.createElement(Pagination, {
|
|
26
|
+
numberItems: 237,
|
|
27
|
+
stepOptions: [10, 20, 30, 1000],
|
|
28
|
+
summary: true
|
|
29
|
+
})))
|
|
30
|
+
// </Grommet>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
export default {
|
|
34
|
+
title: 'Controls/Pagination/Steps'
|
|
35
|
+
};
|
|
@@ -2,11 +2,14 @@ var _excluded = ["a11yTitle", "color", "focus", "focusIndicator", "name", "onCha
|
|
|
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, { forwardRef, useContext, useState, useCallback, useEffect } from 'react';
|
|
5
|
+
import { ThemeContext } from 'styled-components';
|
|
6
|
+
import { defaultProps } from '../../default-props';
|
|
5
7
|
import { FormContext } from '../Form/FormContext';
|
|
6
8
|
import { StyledRangeInput } from './StyledRangeInput';
|
|
7
9
|
import { RangeInputPropTypes } from './propTypes';
|
|
8
10
|
import { useForwardedRef } from '../../utils';
|
|
9
11
|
var RangeInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
12
|
+
var _theme$rangeInput;
|
|
10
13
|
var a11yTitle = _ref.a11yTitle,
|
|
11
14
|
color = _ref.color,
|
|
12
15
|
focusProp = _ref.focus,
|
|
@@ -24,10 +27,12 @@ var RangeInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
24
27
|
_ref$max = _ref.max,
|
|
25
28
|
max = _ref$max === void 0 ? 100 : _ref$max,
|
|
26
29
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
30
|
+
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
27
31
|
var formContext = useContext(FormContext);
|
|
28
32
|
var _useState = useState(focusProp),
|
|
29
33
|
focus = _useState[0],
|
|
30
34
|
setFocus = _useState[1];
|
|
35
|
+
var scrollEnabled = (theme == null || (_theme$rangeInput = theme.rangeInput) == null ? void 0 : _theme$rangeInput.wheel) !== false;
|
|
31
36
|
var _formContext$useFormI = formContext.useFormInput({
|
|
32
37
|
name: name,
|
|
33
38
|
value: valueProp
|
|
@@ -44,17 +49,19 @@ var RangeInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
44
49
|
useEffect(function () {
|
|
45
50
|
var x = scroll.x,
|
|
46
51
|
y = scroll.y;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
var handleScrollTo = function handleScrollTo() {
|
|
53
|
+
return window.scrollTo(x, y);
|
|
54
|
+
};
|
|
55
|
+
if (x !== null && y !== null && scrollEnabled) {
|
|
51
56
|
window.addEventListener('scroll', handleScrollTo);
|
|
52
|
-
return function () {
|
|
53
|
-
return window.removeEventListener('scroll', handleScrollTo);
|
|
54
|
-
};
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
// there is no need to remove this event listener if scroll is disabled
|
|
59
|
+
// but we need to remove it if scroll is enabled and user switches to
|
|
60
|
+
// a theme with scroll disabled
|
|
61
|
+
return function () {
|
|
62
|
+
window.removeEventListener('scroll', handleScrollTo);
|
|
63
|
+
};
|
|
64
|
+
}, [scroll, scrollEnabled]);
|
|
58
65
|
var setRangeInputValue = useCallback(function (nextValue) {
|
|
59
66
|
if (nextValue > max || nextValue < min) return;
|
|
60
67
|
// Calling set value function directly on input because React library
|
|
@@ -114,9 +121,9 @@ var RangeInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
114
121
|
setValue(event.target.value);
|
|
115
122
|
if (_onChange) _onChange(event);
|
|
116
123
|
},
|
|
117
|
-
onMouseOver: handleMouseOver,
|
|
118
|
-
onMouseOut: handleMouseOut,
|
|
119
|
-
onWheel: handleOnWheel,
|
|
124
|
+
onMouseOver: scrollEnabled ? handleMouseOver : undefined,
|
|
125
|
+
onMouseOut: scrollEnabled ? handleMouseOut : undefined,
|
|
126
|
+
onWheel: scrollEnabled ? handleOnWheel : undefined,
|
|
120
127
|
step: step,
|
|
121
128
|
type: "range",
|
|
122
129
|
min: min,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import styled, { ThemeContext } from 'styled-components';
|
|
3
|
+
import { Copy } from 'grommet-icons/icons/Copy';
|
|
4
|
+
import { Button } from '../Button';
|
|
5
|
+
import { Tip } from '../Tip';
|
|
6
|
+
import { edgeStyle } from '../../utils/styles';
|
|
7
|
+
|
|
8
|
+
// to overcome `plain` styling due to (icon && !label) condition
|
|
9
|
+
// in buttons without theme.button.default, apply the padding here
|
|
10
|
+
var StyledButton = styled(Button).withConfig({
|
|
11
|
+
displayName: "CopyButton__StyledButton",
|
|
12
|
+
componentId: "sc-1bp1m18-0"
|
|
13
|
+
})(["border-radius:", ";", ""], function (props) {
|
|
14
|
+
return props.theme.global.control.border.radius;
|
|
15
|
+
}, function (props) {
|
|
16
|
+
return !props.theme.button["default"] ? edgeStyle('padding', props.pad, false, undefined, props.theme) : '';
|
|
17
|
+
});
|
|
18
|
+
export var CopyButton = function CopyButton(_ref) {
|
|
19
|
+
var _theme$global$input$p, _theme$global$input$p2, _theme$global$input$p3;
|
|
20
|
+
var onClickCopy = _ref.onClickCopy,
|
|
21
|
+
onBlurCopy = _ref.onBlurCopy,
|
|
22
|
+
readOnlyCopyPrompt = _ref.readOnlyCopyPrompt,
|
|
23
|
+
tip = _ref.tip,
|
|
24
|
+
value = _ref.value;
|
|
25
|
+
var theme = useContext(ThemeContext);
|
|
26
|
+
return /*#__PURE__*/React.createElement(Tip, {
|
|
27
|
+
dropProps: {
|
|
28
|
+
align: {
|
|
29
|
+
bottom: 'top'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
content: tip
|
|
33
|
+
}, /*#__PURE__*/React.createElement(StyledButton, {
|
|
34
|
+
onClick: onClickCopy,
|
|
35
|
+
icon: /*#__PURE__*/React.createElement(Copy, null),
|
|
36
|
+
pad: {
|
|
37
|
+
horizontal: (_theme$global$input$p = theme.global.input.padding) == null ? void 0 : _theme$global$input$p.horizontal,
|
|
38
|
+
left: (_theme$global$input$p2 = theme.global.input.padding) == null ? void 0 : _theme$global$input$p2.left,
|
|
39
|
+
right: (_theme$global$input$p3 = theme.global.input.padding) == null ? void 0 : _theme$global$input$p3.right,
|
|
40
|
+
// only apply horizontal padding since button will
|
|
41
|
+
// fill height of input
|
|
42
|
+
top: '0',
|
|
43
|
+
bottom: '0'
|
|
44
|
+
},
|
|
45
|
+
onBlur: onBlurCopy,
|
|
46
|
+
onMouseOut: onBlurCopy,
|
|
47
|
+
"aria-label": readOnlyCopyPrompt + " " + value
|
|
48
|
+
}));
|
|
49
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import styled, { css } from 'styled-components';
|
|
2
|
-
import { disabledStyle, getInputPadBySide, inputStyle, parseMetricToNum, plainInputStyle, textAlignStyle, widthStyle } from '../../utils';
|
|
2
|
+
import { controlBorderStyle, disabledStyle, getInputPadBySide, inputStyle, parseMetricToNum, plainInputStyle, textAlignStyle, widthStyle } from '../../utils';
|
|
3
3
|
import { defaultProps } from '../../default-props';
|
|
4
4
|
import { inputPadForIcon } from '../../utils/styles';
|
|
5
|
+
import { readOnlyStyle } from '../../utils/readOnly';
|
|
5
6
|
var getPlainStyle = function getPlainStyle(plain) {
|
|
6
7
|
if (plain === 'full') {
|
|
7
8
|
return css(["", " padding:0;"], plainInputStyle);
|
|
@@ -11,7 +12,11 @@ var getPlainStyle = function getPlainStyle(plain) {
|
|
|
11
12
|
var StyledTextInput = styled.input.withConfig({
|
|
12
13
|
displayName: "StyledTextInput",
|
|
13
14
|
componentId: "sc-1x30a0s-0"
|
|
14
|
-
})(["", " ", " ", " ", " ", " ", " ", ";"], inputStyle, function (props) {
|
|
15
|
+
})(["", " ", " ", " ", " ", " ", " ", " ", " ", ";"], inputStyle, function (props) {
|
|
16
|
+
return props.readOnlyCopy ? "padding-" + (props.reverse ? 'left' : 'right') + ": 0px;" : '';
|
|
17
|
+
}, function (props) {
|
|
18
|
+
return props.readOnly && "border: none;";
|
|
19
|
+
}, function (props) {
|
|
15
20
|
return getPlainStyle(props.plain);
|
|
16
21
|
}, function (props) {
|
|
17
22
|
return props.icon && inputPadForIcon;
|
|
@@ -29,7 +34,13 @@ Object.setPrototypeOf(StyledTextInput.defaultProps, defaultProps);
|
|
|
29
34
|
var StyledTextInputContainer = styled.div.withConfig({
|
|
30
35
|
displayName: "StyledTextInput__StyledTextInputContainer",
|
|
31
36
|
componentId: "sc-1x30a0s-1"
|
|
32
|
-
})(["position:relative;width:100%;", ";"], function (props) {
|
|
37
|
+
})(["position:relative;width:100%;", ";", ";", " ", ";"], function (props) {
|
|
38
|
+
return props.readOnlyProp && !props.plain && controlBorderStyle;
|
|
39
|
+
}, function (props) {
|
|
40
|
+
return props.readOnlyCopy && "\n box-sizing: border-box;\n flex-direction: row;\n display: flex;\n ";
|
|
41
|
+
}, function (props) {
|
|
42
|
+
return props.readOnlyProp && !props.plain && readOnlyStyle(props.theme);
|
|
43
|
+
}, function (props) {
|
|
33
44
|
return props.theme.textInput && props.theme.textInput.container && props.theme.textInput.container.extend;
|
|
34
45
|
});
|
|
35
46
|
StyledTextInputContainer.defaultProps = {};
|