grommet 2.36.0 → 2.37.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/Data/stories/OnSelect.js +264 -0
- package/components/Data/stories/SpaceX.js +3 -6
- package/components/DataSearch/DataSearch.js +5 -0
- package/components/DataTable/DataTable.js +9 -16
- package/components/DataTable/Header.js +22 -15
- package/components/DataTable/index.d.ts +5 -1
- package/components/DataTableColumns/DataTableColumns.js +16 -2
- package/components/DataTableColumns/index.d.ts +9 -1
- package/components/DataTableColumns/propTypes.js +1 -0
- package/components/DataTableColumns/stories/Pinned.js +46 -0
- package/components/FormField/FormField.js +1 -1
- package/components/List/List.js +43 -19
- package/components/List/index.d.ts +20 -6
- package/components/List/propTypes.js +6 -1
- package/components/Pagination/Pagination.js +4 -1
- package/components/Pagination/PaginationStep.js +1 -1
- package/components/Skeleton/StyledSkeleton.js +5 -2
- package/components/TextInput/CopyButton.js +6 -5
- package/components/ToggleGroup/README.md +2 -0
- package/components/ToggleGroup/StyledToggleGroup.js +36 -0
- package/components/ToggleGroup/ToggleGroup.js +165 -0
- package/components/ToggleGroup/index.d.ts +26 -0
- package/components/ToggleGroup/index.js +6 -0
- package/components/ToggleGroup/propTypes.js +21 -0
- package/components/ToggleGroup/stories/Controlled.js +31 -0
- package/components/ToggleGroup/stories/multiple.tsx +28 -0
- package/components/ToggleGroup/stories/simple.js +37 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +6 -0
- package/es6/components/Data/stories/OnSelect.js +258 -0
- package/es6/components/Data/stories/SpaceX.js +5 -8
- package/es6/components/DataSearch/DataSearch.js +5 -0
- package/es6/components/DataTable/DataTable.js +9 -16
- package/es6/components/DataTable/Header.js +22 -15
- package/es6/components/DataTable/index.d.ts +5 -1
- package/es6/components/DataTableColumns/DataTableColumns.js +16 -2
- package/es6/components/DataTableColumns/index.d.ts +9 -1
- package/es6/components/DataTableColumns/propTypes.js +1 -0
- package/es6/components/DataTableColumns/stories/Pinned.js +42 -0
- package/es6/components/FormField/FormField.js +1 -1
- package/es6/components/List/List.js +44 -20
- package/es6/components/List/index.d.ts +20 -6
- package/es6/components/List/propTypes.js +7 -2
- package/es6/components/Pagination/Pagination.js +4 -1
- package/es6/components/Pagination/PaginationStep.js +1 -1
- package/es6/components/Skeleton/StyledSkeleton.js +5 -2
- package/es6/components/TextInput/CopyButton.js +6 -5
- package/es6/components/ToggleGroup/README.md +2 -0
- package/es6/components/ToggleGroup/StyledToggleGroup.js +31 -0
- package/es6/components/ToggleGroup/ToggleGroup.js +160 -0
- package/es6/components/ToggleGroup/index.d.ts +26 -0
- package/es6/components/ToggleGroup/index.js +1 -0
- package/es6/components/ToggleGroup/propTypes.js +16 -0
- package/es6/components/ToggleGroup/stories/Controlled.js +25 -0
- package/es6/components/ToggleGroup/stories/multiple.tsx +28 -0
- package/es6/components/ToggleGroup/stories/simple.js +34 -0
- package/es6/components/index.d.ts +1 -0
- package/es6/components/index.js +1 -0
- package/es6/index.d.ts +1 -0
- package/es6/themes/base.d.ts +20 -1
- package/es6/themes/base.js +19 -0
- package/es6/utils/DOM.js +3 -1
- package/es6/utils/styles.js +1 -1
- package/es6/utils/useControlled.js +25 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +1 -0
- package/package.json +18 -18
- package/themes/base.d.ts +20 -1
- package/themes/base.js +19 -0
- package/utils/DOM.js +3 -1
- package/utils/styles.js +1 -1
- package/utils/useControlled.js +28 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var _excluded = ["a11yTitle", "aria-label", "action", "as", "background", "border", "children", "data", "defaultItemProps", "disabled", "focus", "itemKey", "itemProps", "onActive", "onClickItem", "onKeyDown", "onMore", "onOrder", "pad", "paginate", "pinned", "primaryKey", "secondaryKey", "show", "step"];
|
|
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
|
-
import React, { Fragment, useContext, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import React, { Fragment, cloneElement, useContext, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import styled, { ThemeContext } from 'styled-components';
|
|
6
6
|
import { DataContext } from '../../contexts/DataContext';
|
|
7
7
|
import { Box } from '../Box';
|
|
@@ -174,8 +174,10 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
174
174
|
indexes: pinnedIndexes
|
|
175
175
|
}];
|
|
176
176
|
currentData.forEach(function (item, index) {
|
|
177
|
+
var _pinned$items;
|
|
177
178
|
var key = getValue(item, index, itemKey);
|
|
178
|
-
|
|
179
|
+
var isPinned = Array.isArray(pinned) ? pinned.includes(key) : typeof pinned === 'object' && (pinned == null || (_pinned$items = pinned.items) == null ? void 0 : _pinned$items.includes(key));
|
|
180
|
+
if (isPinned) {
|
|
179
181
|
pinnedData.push(item);
|
|
180
182
|
pinnedIndexes.push(index);
|
|
181
183
|
} else {
|
|
@@ -301,8 +303,21 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
301
303
|
}, marker);
|
|
302
304
|
}
|
|
303
305
|
}, function (item, index) {
|
|
306
|
+
var _pinned$items2;
|
|
304
307
|
var content;
|
|
305
308
|
var boxProps = {};
|
|
309
|
+
var key = getValue(item, index, itemKey) || index;
|
|
310
|
+
var isPinned;
|
|
311
|
+
if (Array.isArray(pinned) && pinned.length > 0 || Array.isArray(pinned == null ? void 0 : pinned.items) && (pinned == null || (_pinned$items2 = pinned.items) == null ? void 0 : _pinned$items2.length) > 0) {
|
|
312
|
+
if (typeof item === 'object' && !itemKey) {
|
|
313
|
+
console.error( // eslint-disable-next-line max-len
|
|
314
|
+
"Warning: Missing prop itemKey. Prop pin requires itemKey to be specified when data is of type 'object'.");
|
|
315
|
+
}
|
|
316
|
+
isPinned = Array.isArray(pinned) ? pinned == null ? void 0 : pinned.includes(key) : pinned.items.some(function (pinnedItem) {
|
|
317
|
+
return pinnedItem === key;
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
var pinnedColor = isPinned ? pinned.color : undefined;
|
|
306
321
|
if (children) {
|
|
307
322
|
content = children(item, index, onClickItem ? {
|
|
308
323
|
active: active === index
|
|
@@ -310,11 +325,13 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
310
325
|
} else if (primaryKey) {
|
|
311
326
|
var primary = getValue(item, index, primaryKey);
|
|
312
327
|
content = typeof primary === 'string' || typeof primary === 'number' ? /*#__PURE__*/React.createElement(Text, _extends({
|
|
328
|
+
color: pinnedColor,
|
|
313
329
|
key: "p"
|
|
314
330
|
}, theme.list.primaryKey), primary) : primary;
|
|
315
331
|
if (secondaryKey) {
|
|
316
332
|
var secondary = getValue(item, index, secondaryKey);
|
|
317
333
|
content = [content, typeof secondary === 'string' || typeof secondary === 'number' ? /*#__PURE__*/React.createElement(Text, {
|
|
334
|
+
color: pinnedColor,
|
|
318
335
|
key: "s"
|
|
319
336
|
}, getValue(item, index, secondaryKey)) : secondary];
|
|
320
337
|
boxProps = {
|
|
@@ -325,11 +342,20 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
325
342
|
};
|
|
326
343
|
}
|
|
327
344
|
} else if (typeof item === 'object') {
|
|
328
|
-
|
|
345
|
+
var value = item[Object.keys(item)[0]];
|
|
346
|
+
content =
|
|
347
|
+
// for backwards compatibility, only wrap in Text if
|
|
348
|
+
// pinned.color is defined
|
|
349
|
+
pinnedColor && typeof value === 'string' ? /*#__PURE__*/React.createElement(Text, {
|
|
350
|
+
color: pinnedColor
|
|
351
|
+
}, value) : value;
|
|
329
352
|
} else {
|
|
330
|
-
|
|
353
|
+
// for backwards compatibility, only wrap in Text if
|
|
354
|
+
// pinned.color is defined
|
|
355
|
+
content = pinnedColor ? /*#__PURE__*/React.createElement(Text, {
|
|
356
|
+
color: pinnedColor
|
|
357
|
+
}, item) : item;
|
|
331
358
|
}
|
|
332
|
-
var key = getValue(item, index, itemKey) || index;
|
|
333
359
|
var orderableIndex = orderableData.findIndex(function (ordItem, ordIndex) {
|
|
334
360
|
return getValue(ordItem, ordIndex, itemKey) === key;
|
|
335
361
|
});
|
|
@@ -341,14 +367,6 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
341
367
|
}
|
|
342
368
|
isDisabled = disabledItems == null ? void 0 : disabledItems.includes(key);
|
|
343
369
|
}
|
|
344
|
-
var isPinned;
|
|
345
|
-
if (pinned.length > 0) {
|
|
346
|
-
if (typeof item === 'object' && !itemKey) {
|
|
347
|
-
console.error( // eslint-disable-next-line max-len
|
|
348
|
-
"Warning: Missing prop itemKey. Prop pin requires itemKey to be specified when data is of type 'object'.");
|
|
349
|
-
}
|
|
350
|
-
isPinned = pinned == null ? void 0 : pinned.includes(key);
|
|
351
|
-
}
|
|
352
370
|
if (action) {
|
|
353
371
|
content = [/*#__PURE__*/React.createElement(Box, {
|
|
354
372
|
align: "start",
|
|
@@ -367,7 +385,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
367
385
|
} else if (Array.isArray(adjustedBackground)) {
|
|
368
386
|
adjustedBackground = adjustedBackground[index % adjustedBackground.length];
|
|
369
387
|
} else if (isPinned) {
|
|
370
|
-
adjustedBackground = theme.list.item.pinned.background;
|
|
388
|
+
adjustedBackground = (pinned == null ? void 0 : pinned.background) || theme.list.item.pinned.background;
|
|
371
389
|
}
|
|
372
390
|
var adjustedBorder = border !== undefined ? border : theme.list.item.border;
|
|
373
391
|
if (adjustedBorder === 'horizontal' && index) {
|
|
@@ -541,10 +559,16 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
541
559
|
}
|
|
542
560
|
var displayPinned;
|
|
543
561
|
if (isPinned) {
|
|
544
|
-
|
|
545
|
-
var Pin = theme.list.icons.pin;
|
|
562
|
+
var _pinIcon$props;
|
|
546
563
|
var pinSize = theme.list.item.pinned.icon.size;
|
|
547
564
|
var pinPad = theme.list.item.pinned.icon.pad;
|
|
565
|
+
var Icon = (pinned == null ? void 0 : pinned.icon) || theme.list.icons.pin;
|
|
566
|
+
var pinIcon = /*#__PURE__*/React.isValidElement(Icon) ? Icon : /*#__PURE__*/React.createElement(Icon, null);
|
|
567
|
+
pinIcon = /*#__PURE__*/cloneElement(pinIcon, _extends({}, !((_pinIcon$props = pinIcon.props) != null && _pinIcon$props.color) && pinnedColor ? {
|
|
568
|
+
color: pinnedColor
|
|
569
|
+
} : {}, {
|
|
570
|
+
size: pinSize
|
|
571
|
+
}));
|
|
548
572
|
boxProps = {
|
|
549
573
|
direction: 'row',
|
|
550
574
|
align: defaultItemProps && defaultItemProps.align || 'center',
|
|
@@ -555,9 +579,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
555
579
|
align: "center",
|
|
556
580
|
justify: "end",
|
|
557
581
|
pad: pinPad
|
|
558
|
-
},
|
|
559
|
-
size: pinSize
|
|
560
|
-
}));
|
|
582
|
+
}, pinIcon);
|
|
561
583
|
content = /*#__PURE__*/React.createElement(Box, {
|
|
562
584
|
flex: true
|
|
563
585
|
}, content);
|
|
@@ -573,7 +595,9 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
573
595
|
isDisabled: isDisabled,
|
|
574
596
|
flex: false,
|
|
575
597
|
pad: pad || theme.list.item.pad
|
|
576
|
-
}, defaultItemProps, boxProps, clickProps, orderProps, itemAriaProps), onOrder && /*#__PURE__*/React.createElement(Text,
|
|
598
|
+
}, defaultItemProps, boxProps, clickProps, orderProps, itemAriaProps), onOrder && /*#__PURE__*/React.createElement(Text, {
|
|
599
|
+
color: pinnedColor
|
|
600
|
+
}, index + 1), content, displayPinned, orderControls);
|
|
577
601
|
}))), paginate && data.length > step && items && items.length ? /*#__PURE__*/React.createElement(Pagination, _extends({
|
|
578
602
|
alignSelf: "end"
|
|
579
603
|
}, paginationProps)) : null);
|
|
@@ -2,6 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
A11yTitleType,
|
|
4
4
|
AlignSelfType,
|
|
5
|
+
BackgroundType,
|
|
6
|
+
ColorType,
|
|
5
7
|
GridAreaType,
|
|
6
8
|
MarginType,
|
|
7
9
|
PadType,
|
|
@@ -43,7 +45,11 @@ export interface ListProps<ListItemType> {
|
|
|
43
45
|
| string[]
|
|
44
46
|
| { light: string | string[]; dark: string | string[] };
|
|
45
47
|
border?: BorderType;
|
|
46
|
-
children?: (
|
|
48
|
+
children?: (
|
|
49
|
+
item: ListItemType,
|
|
50
|
+
index: number,
|
|
51
|
+
state?: { active: boolean },
|
|
52
|
+
) => any;
|
|
47
53
|
data?: ListItemType[];
|
|
48
54
|
disabled?: string[];
|
|
49
55
|
gridArea?: GridAreaType;
|
|
@@ -54,14 +60,22 @@ export interface ListProps<ListItemType> {
|
|
|
54
60
|
};
|
|
55
61
|
margin?: MarginType;
|
|
56
62
|
onActive?: (index: number) => void;
|
|
57
|
-
onClickItem?:
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
onClickItem?: (
|
|
64
|
+
event: React.MouseEvent & { item: ListItemType; index: number },
|
|
65
|
+
) => void;
|
|
60
66
|
onMore?: () => void;
|
|
61
67
|
onOrder?: (orderedData: ListItemType[]) => void;
|
|
62
68
|
pad?: PadType;
|
|
63
69
|
paginate?: boolean | PaginationType;
|
|
64
|
-
pinned?:
|
|
70
|
+
pinned?:
|
|
71
|
+
| boolean
|
|
72
|
+
| (string | number)[]
|
|
73
|
+
| {
|
|
74
|
+
items?: (string | number)[];
|
|
75
|
+
background?: BackgroundType;
|
|
76
|
+
color?: ColorType;
|
|
77
|
+
icon?: JSX.Element;
|
|
78
|
+
};
|
|
65
79
|
primaryKey?: string | ((item: ListItemType) => React.ReactElement);
|
|
66
80
|
secondaryKey?: string | ((item: ListItemType) => React.ReactElement);
|
|
67
81
|
show?: number | { page?: number };
|
|
@@ -76,7 +90,7 @@ export interface ListExtendedProps<ListItemType>
|
|
|
76
90
|
ulProps {}
|
|
77
91
|
|
|
78
92
|
declare const List: <ListItemType = string | {}>(
|
|
79
|
-
p:
|
|
93
|
+
p: ListExtendedProps<ListItemType>,
|
|
80
94
|
) => React.ReactElement<ListExtendedProps<ListItemType>>;
|
|
81
95
|
|
|
82
96
|
export { List };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { genericProps, padPropType } from '../../utils/general-prop-types';
|
|
3
|
+
import { backgroundDoc, genericProps, padPropType } from '../../utils/general-prop-types';
|
|
4
4
|
import { BoxPropTypes } from '../Box/propTypes';
|
|
5
5
|
var sizes = ['none', 'xxsmall', 'xsmall', 'small', 'medium', 'large', 'xlarge'];
|
|
6
6
|
var sides = ['horizontal', 'vertical', 'top', 'bottom', 'left', 'right', 'start', 'end'];
|
|
@@ -35,7 +35,12 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
35
35
|
onOrder: PropTypes.func,
|
|
36
36
|
pad: PropTypes.oneOfType([padPropType]),
|
|
37
37
|
paginate: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
38
|
-
pinned: PropTypes.arrayOf(PropTypes.string),
|
|
38
|
+
pinned: PropTypes.oneOfType([PropTypes.bool, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), PropTypes.shape({
|
|
39
|
+
items: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
|
40
|
+
background: backgroundDoc,
|
|
41
|
+
color: PropTypes.string,
|
|
42
|
+
icon: PropTypes.element
|
|
43
|
+
})]),
|
|
39
44
|
primaryKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
40
45
|
secondaryKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
41
46
|
show: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
|
@@ -57,6 +57,9 @@ var Pagination = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
57
57
|
var _useState2 = useState(Math.min(page, totalPages) || 1),
|
|
58
58
|
activePage = _useState2[0],
|
|
59
59
|
setActivePage = _useState2[1];
|
|
60
|
+
useEffect(function () {
|
|
61
|
+
if (stepProp) setStep(stepProp);
|
|
62
|
+
}, [stepProp]);
|
|
60
63
|
useEffect(function () {
|
|
61
64
|
setActivePage(page);
|
|
62
65
|
var pageEvent = new Event('pagechange');
|
|
@@ -208,7 +211,7 @@ var Pagination = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
208
211
|
flex: "grow"
|
|
209
212
|
}, summary && /*#__PURE__*/React.createElement(PaginationSummary, {
|
|
210
213
|
messages: messages,
|
|
211
|
-
page:
|
|
214
|
+
page: activePage,
|
|
212
215
|
step: step,
|
|
213
216
|
numberItems: total
|
|
214
217
|
})), /*#__PURE__*/React.createElement(Box, {
|
|
@@ -21,7 +21,7 @@ export var PaginationStep = function PaginationStep(_ref) {
|
|
|
21
21
|
direction: "row",
|
|
22
22
|
align: "center",
|
|
23
23
|
gap: "xsmall"
|
|
24
|
-
}, rest), /*#__PURE__*/React.createElement(Text, null,
|
|
24
|
+
}, rest), /*#__PURE__*/React.createElement(Text, null, formatMessage({
|
|
25
25
|
id: 'pagination.stepLabel',
|
|
26
26
|
messages: messages
|
|
27
27
|
})), /*#__PURE__*/React.createElement(Select, {
|
|
@@ -7,7 +7,7 @@ import { backgroundStyle, edgeStyle, genericStyles, heightStyle, roundStyle, wid
|
|
|
7
7
|
export var StyledSkeleton = styled.div.withConfig({
|
|
8
8
|
displayName: "StyledSkeleton",
|
|
9
9
|
componentId: "sc-1omqm6u-0"
|
|
10
|
-
})(["display:flex;box-sizing:border-box;", " ", " ", " ", " ", " ", ""], genericStyles, function (props) {
|
|
10
|
+
})(["display:flex;box-sizing:border-box;", " ", " ", " ", " ", " ", " ", ""], genericStyles, function (props) {
|
|
11
11
|
return props.background && backgroundStyle(props.background, props.theme);
|
|
12
12
|
}, function (props) {
|
|
13
13
|
var _props$theme$text;
|
|
@@ -17,5 +17,8 @@ export var StyledSkeleton = styled.div.withConfig({
|
|
|
17
17
|
}, function (props) {
|
|
18
18
|
return props.pad && edgeStyle('padding', props.pad, props.responsive, props.theme.box.responsiveBreakpoint, props.theme);
|
|
19
19
|
}, function (props) {
|
|
20
|
-
return props.round && roundStyle(props.round,
|
|
20
|
+
return props.round && roundStyle(props.round, true, props.theme);
|
|
21
|
+
}, function (props) {
|
|
22
|
+
var _props$theme;
|
|
23
|
+
return (_props$theme = props.theme) == null || (_props$theme = _props$theme.skeleton) == null ? void 0 : _props$theme.extend;
|
|
21
24
|
});
|
|
@@ -32,14 +32,15 @@ export var CopyButton = function CopyButton(_ref) {
|
|
|
32
32
|
content: tip
|
|
33
33
|
}, /*#__PURE__*/React.createElement(StyledButton, {
|
|
34
34
|
onClick: onClickCopy,
|
|
35
|
-
icon: /*#__PURE__*/React.createElement(Copy, null)
|
|
36
|
-
// only apply horizontal padding since button will
|
|
37
|
-
// fill height of input
|
|
38
|
-
,
|
|
35
|
+
icon: /*#__PURE__*/React.createElement(Copy, null),
|
|
39
36
|
pad: {
|
|
40
37
|
horizontal: (_theme$global$input$p = theme.global.input.padding) == null ? void 0 : _theme$global$input$p.horizontal,
|
|
41
38
|
left: (_theme$global$input$p2 = theme.global.input.padding) == null ? void 0 : _theme$global$input$p2.left,
|
|
42
|
-
right: (_theme$global$input$p3 = theme.global.input.padding) == null ? void 0 : _theme$global$input$p3.right
|
|
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'
|
|
43
44
|
},
|
|
44
45
|
onBlur: onBlurCopy,
|
|
45
46
|
onMouseOut: onBlurCopy,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { Button } from '../Button';
|
|
3
|
+
import { roundStyle, edgeStyle, parseMetricToNum } from '../../utils';
|
|
4
|
+
var adjustPad = function adjustPad(value, theme) {
|
|
5
|
+
// resolve t-shirt size if it exists
|
|
6
|
+
var vertical = typeof value === 'string' ? value : value == null ? void 0 : value.vertical;
|
|
7
|
+
vertical = theme.global.edgeSize[vertical] || vertical;
|
|
8
|
+
var horizontal = typeof value === 'string' ? value : value == null ? void 0 : value.horizontal;
|
|
9
|
+
horizontal = theme.global.edgeSize[horizontal] || horizontal;
|
|
10
|
+
var borderWidth = parseMetricToNum(theme.global.borderSize.xsmall);
|
|
11
|
+
vertical = Math.max(parseMetricToNum(vertical) - borderWidth, 0) + "px";
|
|
12
|
+
horizontal = Math.max(parseMetricToNum(horizontal) - borderWidth, 0) + "px";
|
|
13
|
+
return {
|
|
14
|
+
vertical: vertical,
|
|
15
|
+
horizontal: horizontal
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export var StyledButton = styled(Button).withConfig({
|
|
19
|
+
displayName: "StyledToggleGroup__StyledButton",
|
|
20
|
+
componentId: "sc-13k5sx8-0"
|
|
21
|
+
})(["border-radius:0;border:none;", ";", " &:hover{border:none;box-shadow:none;}"], function (props) {
|
|
22
|
+
return roundStyle(props.round, false, props.theme);
|
|
23
|
+
}, function (props) {
|
|
24
|
+
var _props$theme, _props$theme2, _props$theme3, _props$theme4;
|
|
25
|
+
var themePad = props.icon && !props.label && (_props$theme = props.theme) != null && (_props$theme = _props$theme.toggleGroup) != null && (_props$theme = _props$theme.button) != null && (_props$theme = _props$theme.iconOnly) != null && _props$theme.pad ? (_props$theme2 = props.theme) == null || (_props$theme2 = _props$theme2.toggleGroup) == null || (_props$theme2 = _props$theme2.button) == null || (_props$theme2 = _props$theme2.iconOnly) == null ? void 0 : _props$theme2.pad : (_props$theme3 = props.theme) == null || (_props$theme3 = _props$theme3.toggleGroup.button) == null ? void 0 : _props$theme3.pad;
|
|
26
|
+
|
|
27
|
+
// adjust pad for "kind" themes to align with how "kind" themes
|
|
28
|
+
// manages this calculation
|
|
29
|
+
var pad = (_props$theme4 = props.theme) != null && (_props$theme4 = _props$theme4.button) != null && _props$theme4["default"] ? adjustPad(themePad, props.theme) : themePad;
|
|
30
|
+
return edgeStyle('padding', pad, false, undefined, props.theme);
|
|
31
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
var _excluded = ["defaultValue", "multiple", "options", "onToggle", "value"];
|
|
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, { useCallback, useContext, useState, useRef } from 'react';
|
|
5
|
+
import { ThemeContext } from 'styled-components';
|
|
6
|
+
import { Box } from '../Box';
|
|
7
|
+
import { Keyboard } from '../Keyboard';
|
|
8
|
+
import { ToggleGroupPropTypes } from './propTypes';
|
|
9
|
+
import { StyledButton } from './StyledToggleGroup';
|
|
10
|
+
var useControlled = function useControlled(_ref) {
|
|
11
|
+
var prop = _ref.prop,
|
|
12
|
+
defaultProp = _ref.defaultProp,
|
|
13
|
+
_ref$onChange = _ref.onChange,
|
|
14
|
+
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
15
|
+
var _useState = useState(defaultProp),
|
|
16
|
+
uncontrolledProp = _useState[0],
|
|
17
|
+
setUncontrolledProp = _useState[1];
|
|
18
|
+
var controlled = prop !== undefined;
|
|
19
|
+
var value = controlled ? prop : uncontrolledProp;
|
|
20
|
+
var handleChange = useCallback(onChange, [onChange]);
|
|
21
|
+
var setValue = useCallback(function (event) {
|
|
22
|
+
// only update internal value in uncontrolled cases
|
|
23
|
+
if (!controlled) {
|
|
24
|
+
setUncontrolledProp(event.value);
|
|
25
|
+
}
|
|
26
|
+
handleChange(event);
|
|
27
|
+
}, [controlled, setUncontrolledProp, handleChange]);
|
|
28
|
+
return [value, setValue];
|
|
29
|
+
};
|
|
30
|
+
var ToggleGroup = function ToggleGroup(_ref2) {
|
|
31
|
+
var defaultValue = _ref2.defaultValue,
|
|
32
|
+
multiple = _ref2.multiple,
|
|
33
|
+
options = _ref2.options,
|
|
34
|
+
onToggle = _ref2.onToggle,
|
|
35
|
+
valueProp = _ref2.value,
|
|
36
|
+
rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
37
|
+
var _useControlled = useControlled({
|
|
38
|
+
prop: valueProp,
|
|
39
|
+
defaultProp: defaultValue,
|
|
40
|
+
onChange: onToggle
|
|
41
|
+
}),
|
|
42
|
+
_useControlled$ = _useControlled[0],
|
|
43
|
+
value = _useControlled$ === void 0 ? multiple ? [] : '' : _useControlled$,
|
|
44
|
+
setValue = _useControlled[1];
|
|
45
|
+
var theme = useContext(ThemeContext);
|
|
46
|
+
var ref = useRef();
|
|
47
|
+
var buttonRefs = useRef([]);
|
|
48
|
+
var values = options == null ? void 0 : options.map(function (option) {
|
|
49
|
+
return typeof option === 'object' ? option.value : option;
|
|
50
|
+
});
|
|
51
|
+
var getFocusableIndex = useCallback(function () {
|
|
52
|
+
var defaultIndex = 0;
|
|
53
|
+
if (value.length) {
|
|
54
|
+
// set earliest button that's part of value to active
|
|
55
|
+
// assume that value might not be ordered the same as options
|
|
56
|
+
defaultIndex = values.indexOf(values.find(function (option) {
|
|
57
|
+
return value.includes(option);
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
return defaultIndex;
|
|
61
|
+
}, [value, values]);
|
|
62
|
+
var _useState2 = useState(function () {
|
|
63
|
+
return getFocusableIndex();
|
|
64
|
+
}),
|
|
65
|
+
focusableIndex = _useState2[0],
|
|
66
|
+
setFocusableIndex = _useState2[1];
|
|
67
|
+
var onNext = function onNext(e) {
|
|
68
|
+
// prevent page scroll
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
var nextIndex = focusableIndex + 1 <= options.length - 1 ? focusableIndex + 1 : 0;
|
|
71
|
+
setFocusableIndex(nextIndex);
|
|
72
|
+
buttonRefs.current[nextIndex].focus();
|
|
73
|
+
};
|
|
74
|
+
var onPrevious = function onPrevious(e) {
|
|
75
|
+
// prevent page scroll
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
var nextIndex = focusableIndex - 1 >= 0 ? focusableIndex - 1 : options.length - 1;
|
|
78
|
+
setFocusableIndex(nextIndex);
|
|
79
|
+
buttonRefs.current[nextIndex].focus();
|
|
80
|
+
};
|
|
81
|
+
var handleToggle = function handleToggle(event, option) {
|
|
82
|
+
var adjustedEvent = event;
|
|
83
|
+
var nextValue;
|
|
84
|
+
if (!multiple) {
|
|
85
|
+
nextValue = option;
|
|
86
|
+
} else {
|
|
87
|
+
nextValue = value.includes(option) ? value.filter(function (item) {
|
|
88
|
+
return item !== option;
|
|
89
|
+
}) : [].concat(value, [option]);
|
|
90
|
+
}
|
|
91
|
+
adjustedEvent.value = nextValue;
|
|
92
|
+
setValue(adjustedEvent);
|
|
93
|
+
};
|
|
94
|
+
return /*#__PURE__*/React.createElement(Keyboard, {
|
|
95
|
+
onUp: onPrevious,
|
|
96
|
+
onDown: onNext,
|
|
97
|
+
onLeft: onPrevious,
|
|
98
|
+
onRight: onNext
|
|
99
|
+
}, /*#__PURE__*/React.createElement(Box, _extends({
|
|
100
|
+
ref: ref,
|
|
101
|
+
alignSelf: "start",
|
|
102
|
+
direction: "row",
|
|
103
|
+
flex: false,
|
|
104
|
+
onBlur: function onBlur(e) {
|
|
105
|
+
if (!(ref != null && ref.current.contains(e.relatedTarget))) {
|
|
106
|
+
setFocusableIndex(getFocusableIndex());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}, theme.toggleGroup.container, {
|
|
110
|
+
// match button rounding
|
|
111
|
+
responsive: false,
|
|
112
|
+
role: multiple ? 'group' : 'radiogroup'
|
|
113
|
+
}, rest), options == null ? void 0 : options.map(function (option, index) {
|
|
114
|
+
var label;
|
|
115
|
+
var icon;
|
|
116
|
+
var optionValue;
|
|
117
|
+
if (typeof option === 'object') {
|
|
118
|
+
icon = option.icon;
|
|
119
|
+
label = option.label;
|
|
120
|
+
optionValue = option.value;
|
|
121
|
+
} else {
|
|
122
|
+
label = option;
|
|
123
|
+
optionValue = option;
|
|
124
|
+
}
|
|
125
|
+
var active = Array.isArray(value) ? !!value.includes(optionValue) : value === optionValue;
|
|
126
|
+
var round = 0;
|
|
127
|
+
// round corners of first and last buttons to match container
|
|
128
|
+
if (typeof theme.toggleGroup.container.round === 'string' && (index === 0 || index === options.length - 1)) {
|
|
129
|
+
round = {
|
|
130
|
+
corner: index === 0 ? 'left' : 'right',
|
|
131
|
+
size: theme.toggleGroup.container.round
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
135
|
+
border: index < options.length - 1 ? {
|
|
136
|
+
side: 'right',
|
|
137
|
+
color: theme.toggleGroup.divider.color
|
|
138
|
+
} : undefined,
|
|
139
|
+
key: optionValue || index
|
|
140
|
+
}, /*#__PURE__*/React.createElement(StyledButton, {
|
|
141
|
+
active: active,
|
|
142
|
+
"aria-pressed": multiple && active,
|
|
143
|
+
"aria-checked": !multiple && active,
|
|
144
|
+
icon: icon,
|
|
145
|
+
label: label,
|
|
146
|
+
onClick: function onClick(event) {
|
|
147
|
+
return handleToggle(event, optionValue);
|
|
148
|
+
},
|
|
149
|
+
ref: function ref(r) {
|
|
150
|
+
buttonRefs.current[index] = r;
|
|
151
|
+
},
|
|
152
|
+
role: !multiple ? 'radio' : undefined,
|
|
153
|
+
round: round,
|
|
154
|
+
tabIndex: index === focusableIndex ? '0' : '-1'
|
|
155
|
+
}));
|
|
156
|
+
})));
|
|
157
|
+
};
|
|
158
|
+
ToggleGroup.displayName = 'ToggleGroup';
|
|
159
|
+
ToggleGroup.propTypes = ToggleGroupPropTypes;
|
|
160
|
+
export { ToggleGroup };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { BoxProps } from '../Box/index';
|
|
3
|
+
|
|
4
|
+
export interface ToggleGroupProps {
|
|
5
|
+
multiple?: boolean;
|
|
6
|
+
defaultValue?: string | string[];
|
|
7
|
+
onToggle?: (event: React.MouseEvent & { value?: string | string[] }) => void;
|
|
8
|
+
options?: (
|
|
9
|
+
| string
|
|
10
|
+
| {
|
|
11
|
+
icon?: React.ReactNode | JSX.Element;
|
|
12
|
+
label?: string | React.ReactNode;
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
)[];
|
|
16
|
+
value?: string | string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ToggleGroupExtendedProps
|
|
20
|
+
extends ToggleGroupProps,
|
|
21
|
+
BoxProps,
|
|
22
|
+
Omit<JSX.IntrinsicElements['div'], keyof ToggleGroupProps> {}
|
|
23
|
+
|
|
24
|
+
declare const ToggleGroup: React.FC<ToggleGroupExtendedProps>;
|
|
25
|
+
|
|
26
|
+
export { ToggleGroup };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ToggleGroup } from './ToggleGroup';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
var PropType = {};
|
|
3
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
4
|
+
PropType = {
|
|
5
|
+
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
6
|
+
multiple: PropTypes.bool,
|
|
7
|
+
onToggle: PropTypes.func,
|
|
8
|
+
options: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.arrayOf(PropTypes.shape({
|
|
9
|
+
icon: PropTypes.oneOfType([PropTypes.element, PropTypes.node]),
|
|
10
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
11
|
+
value: PropTypes.string
|
|
12
|
+
}))]),
|
|
13
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)])
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export var ToggleGroupPropTypes = PropType;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Box, ToggleGroup, Text } from 'grommet';
|
|
3
|
+
export var Controlled = function Controlled() {
|
|
4
|
+
var _useState = useState(['Option 2']),
|
|
5
|
+
value = _useState[0],
|
|
6
|
+
setValue = _useState[1];
|
|
7
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
8
|
+
direction: "row",
|
|
9
|
+
gap: "xlarge",
|
|
10
|
+
overflow: "auto"
|
|
11
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
12
|
+
gap: "large",
|
|
13
|
+
pad: "large"
|
|
14
|
+
}, /*#__PURE__*/React.createElement(Text, null, "In multiple selection mode, enforce at least one selection."), /*#__PURE__*/React.createElement(ToggleGroup, {
|
|
15
|
+
options: ['Option 1', 'Option 2', 'Option 3'],
|
|
16
|
+
value: value,
|
|
17
|
+
onToggle: function onToggle(e) {
|
|
18
|
+
if (e.value.length) setValue(e.value);
|
|
19
|
+
},
|
|
20
|
+
multiple: true
|
|
21
|
+
})));
|
|
22
|
+
};
|
|
23
|
+
export default {
|
|
24
|
+
title: 'Controls/ToggleGroup/Controlled'
|
|
25
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, ToggleGroup } from 'grommet';
|
|
3
|
+
import { Bold, Italic, Underline } from 'grommet-icons';
|
|
4
|
+
|
|
5
|
+
const options = [
|
|
6
|
+
{
|
|
7
|
+
icon: <Bold a11yTitle="Bold" />,
|
|
8
|
+
value: 'bold',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
icon: <Italic a11yTitle="Italic" />,
|
|
12
|
+
value: 'italic',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
icon: <Underline a11yTitle="Underline" />,
|
|
16
|
+
value: 'underline',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const Multiple = () => (
|
|
21
|
+
<Box pad="large">
|
|
22
|
+
<ToggleGroup a11yTitle="Format text" options={options} multiple />
|
|
23
|
+
</Box>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
title: 'Controls/ToggleGroup/Multiple',
|
|
28
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, ToggleGroup } from 'grommet';
|
|
3
|
+
import { List } from "grommet-icons/es6/icons/List";
|
|
4
|
+
import { Table } from "grommet-icons/es6/icons/Table";
|
|
5
|
+
import { MapLocation } from "grommet-icons/es6/icons/MapLocation";
|
|
6
|
+
var options = [{
|
|
7
|
+
icon: /*#__PURE__*/React.createElement(List, {
|
|
8
|
+
a11yTitle: "List view"
|
|
9
|
+
}),
|
|
10
|
+
value: 'list'
|
|
11
|
+
}, {
|
|
12
|
+
icon: /*#__PURE__*/React.createElement(Table, {
|
|
13
|
+
a11yTitle: "Map view"
|
|
14
|
+
}),
|
|
15
|
+
value: 'table'
|
|
16
|
+
}, {
|
|
17
|
+
icon: /*#__PURE__*/React.createElement(MapLocation, {
|
|
18
|
+
a11yTitle: "Map view"
|
|
19
|
+
}),
|
|
20
|
+
value: 'map'
|
|
21
|
+
}];
|
|
22
|
+
export var Simple = function Simple() {
|
|
23
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
24
|
+
gap: "large",
|
|
25
|
+
pad: "large"
|
|
26
|
+
}, /*#__PURE__*/React.createElement(ToggleGroup, {
|
|
27
|
+
a11yTitle: "Choose view",
|
|
28
|
+
options: options,
|
|
29
|
+
defaultValue: "list"
|
|
30
|
+
}));
|
|
31
|
+
};
|
|
32
|
+
export default {
|
|
33
|
+
title: 'Controls/ToggleGroup/Simple'
|
|
34
|
+
};
|
package/es6/components/index.js
CHANGED
package/es6/index.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export * from './components/TextArea';
|
|
|
89
89
|
export * from './components/TextInput';
|
|
90
90
|
export * from './components/ThumbsRating';
|
|
91
91
|
export * from './components/Tip';
|
|
92
|
+
export * from './components/ToggleGroup';
|
|
92
93
|
export * from './components/Toolbar';
|
|
93
94
|
export * from './components/Video';
|
|
94
95
|
export * from './components/WorldMap';
|