@pingux/astro 1.12.0 → 1.13.0-alpha.2
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/lib/cjs/components/Avatar/Avatar.js +8 -3
- package/lib/cjs/components/Avatar/Avatar.test.js +10 -0
- package/lib/cjs/components/Button/Button.js +9 -3
- package/lib/cjs/components/CodeView/CodeView.test.js +4 -4
- package/lib/cjs/components/ComboBox/ComboBoxInput.js +2 -1
- package/lib/cjs/components/CopyText/CopyButton.js +1 -1
- package/lib/cjs/components/CopyText/CopyText.js +5 -1
- package/lib/cjs/components/CopyText/CopyText.test.js +11 -20
- package/lib/cjs/components/IconButtonToggle/IconButtonToggle.js +78 -0
- package/lib/cjs/components/IconButtonToggle/IconButtonToggle.stories.js +76 -0
- package/lib/cjs/components/IconButtonToggle/IconButtonToggle.test.js +60 -0
- package/lib/cjs/components/IconButtonToggle/index.js +18 -0
- package/lib/cjs/components/Menu/Menu.js +4 -1
- package/lib/cjs/components/Menu/Menu.test.js +3 -0
- package/lib/cjs/hooks/index.js +18 -0
- package/lib/cjs/hooks/useComponentToggle/index.js +18 -0
- package/lib/cjs/hooks/useComponentToggle/useComponentToggle.js +70 -0
- package/lib/cjs/hooks/useComponentToggle/useComponentToggle.test.js +133 -0
- package/lib/cjs/index.js +72 -49
- package/lib/cjs/recipes/OneWayToBidirectionalArrow.stories.js +160 -0
- package/lib/cjs/styles/variants/boxes.js +1 -0
- package/lib/cjs/styles/variants/buttons.js +8 -1
- package/lib/components/Avatar/Avatar.js +8 -3
- package/lib/components/Avatar/Avatar.test.js +8 -0
- package/lib/components/Button/Button.js +9 -3
- package/lib/components/CodeView/CodeView.test.js +4 -4
- package/lib/components/ComboBox/ComboBoxInput.js +2 -1
- package/lib/components/CopyText/CopyButton.js +1 -1
- package/lib/components/CopyText/CopyText.js +5 -1
- package/lib/components/CopyText/CopyText.test.js +11 -16
- package/lib/components/IconButtonToggle/IconButtonToggle.js +59 -0
- package/lib/components/IconButtonToggle/IconButtonToggle.stories.js +40 -0
- package/lib/components/IconButtonToggle/IconButtonToggle.test.js +46 -0
- package/lib/components/IconButtonToggle/index.js +1 -0
- package/lib/components/Menu/Menu.js +3 -1
- package/lib/components/Menu/Menu.test.js +2 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/useComponentToggle/index.js +1 -0
- package/lib/hooks/useComponentToggle/useComponentToggle.js +55 -0
- package/lib/hooks/useComponentToggle/useComponentToggle.test.js +105 -0
- package/lib/index.js +2 -0
- package/lib/recipes/OneWayToBidirectionalArrow.stories.js +137 -0
- package/lib/styles/variants/boxes.js +1 -0
- package/lib/styles/variants/buttons.js +8 -1
- package/package.json +1 -1
- package/NOTICE.html +0 -4311
@@ -0,0 +1,55 @@
|
|
1
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
2
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
3
|
+
import { useProgressiveState } from '../index';
|
4
|
+
/**
|
5
|
+
* Returns one of two components that are supplied via props.
|
6
|
+
* A boolean value is used to determine which component to render.
|
7
|
+
* State can be handled by either props or within this hook if props are not provided.
|
8
|
+
* Also returns a function that inverts the boolean attribute, and calls a callback function.
|
9
|
+
* @param {Object} [props] Properties provided to the state
|
10
|
+
* @param {Boolean} [props.condition] Boolean that controls which component is returned.
|
11
|
+
* @param {Component} [props.ComponentToRenderIfTrue]
|
12
|
+
* Component that is returned when the condition is true.
|
13
|
+
* @param {Component} [props.ComponentToRenderIfFalse]
|
14
|
+
* Component that is returned when the condition is false.
|
15
|
+
* @param {Function} [props.onConditionChange]
|
16
|
+
* Callback function that is called, when the condition boolean changes, if it is provided .
|
17
|
+
* @returns {Object} `{ isOpen: Boolean, open: Function, close: Function, toggle: Function }`
|
18
|
+
* @returns {Object} `{ handleCondtionChange: Function, renderedComponent: Component, }`
|
19
|
+
*/
|
20
|
+
|
21
|
+
var useComponentToggle = function useComponentToggle() {
|
22
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
23
|
+
var ComponentToRenderIfTrue = props.ComponentToRenderIfTrue,
|
24
|
+
ComponentToRenderIfFalse = props.ComponentToRenderIfFalse,
|
25
|
+
condition = props.condition,
|
26
|
+
onConditionChange = props.onConditionChange;
|
27
|
+
|
28
|
+
var _useProgressiveState = useProgressiveState(condition, function () {}),
|
29
|
+
_useProgressiveState2 = _slicedToArray(_useProgressiveState, 2),
|
30
|
+
isToggled = _useProgressiveState2[0],
|
31
|
+
setIsToggled = _useProgressiveState2[1];
|
32
|
+
|
33
|
+
var RenderedComponent = isToggled ? ComponentToRenderIfTrue : ComponentToRenderIfFalse;
|
34
|
+
|
35
|
+
var handleConditionChange = function handleConditionChange() {
|
36
|
+
setIsToggled(!isToggled);
|
37
|
+
|
38
|
+
if (onConditionChange) {
|
39
|
+
var _context;
|
40
|
+
|
41
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
42
|
+
args[_key] = arguments[_key];
|
43
|
+
}
|
44
|
+
|
45
|
+
onConditionChange.apply(void 0, _concatInstanceProperty(_context = [!isToggled]).call(_context, args));
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
return {
|
50
|
+
handleConditionChange: handleConditionChange,
|
51
|
+
RenderedComponent: RenderedComponent
|
52
|
+
};
|
53
|
+
};
|
54
|
+
|
55
|
+
export default useComponentToggle;
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
2
|
+
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
3
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
4
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
5
|
+
import React, { useState } from 'react';
|
6
|
+
import { renderHook, act } from '@testing-library/react-hooks';
|
7
|
+
import userEvent from '@testing-library/user-event';
|
8
|
+
import { render, screen } from '@testing-library/react';
|
9
|
+
import useComponentToggle from './useComponentToggle';
|
10
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
11
|
+
var callback = jest.fn();
|
12
|
+
var condition = false;
|
13
|
+
var defaultProps = {
|
14
|
+
condition: condition,
|
15
|
+
onConditionChange: callback,
|
16
|
+
ComponentToRenderIfTrue: 'true-string',
|
17
|
+
ComponentToRenderIfFalse: 'false-string'
|
18
|
+
};
|
19
|
+
|
20
|
+
var TestComponent = function TestComponent() {
|
21
|
+
var _useState = useState(false),
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
23
|
+
thisCondition = _useState2[0],
|
24
|
+
setCondition = _useState2[1];
|
25
|
+
|
26
|
+
var conditionalRenderProps = {
|
27
|
+
condition: thisCondition,
|
28
|
+
onConditionChange: setCondition,
|
29
|
+
ComponentToRenderIfTrue: 'true-string',
|
30
|
+
ComponentToRenderIfFalse: 'false-string',
|
31
|
+
onConditionChangeProp: callback
|
32
|
+
};
|
33
|
+
|
34
|
+
var _useComponentToggle = useComponentToggle(conditionalRenderProps),
|
35
|
+
handleConditionChange = _useComponentToggle.handleConditionChange,
|
36
|
+
RenderedComponent = _useComponentToggle.RenderedComponent;
|
37
|
+
|
38
|
+
return ___EmotionJSX("button", {
|
39
|
+
"data-testid": "test-div",
|
40
|
+
onClick: handleConditionChange,
|
41
|
+
onKeyDown: handleConditionChange
|
42
|
+
}, RenderedComponent);
|
43
|
+
};
|
44
|
+
|
45
|
+
var getComponent = function getComponent() {
|
46
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
47
|
+
return render(___EmotionJSX(TestComponent, _extends({}, props, defaultProps)));
|
48
|
+
};
|
49
|
+
|
50
|
+
test('default useField', function () {
|
51
|
+
renderHook(function () {
|
52
|
+
return useComponentToggle();
|
53
|
+
});
|
54
|
+
});
|
55
|
+
test('callback function should call, if provided', function () {
|
56
|
+
var _renderHook = renderHook(function () {
|
57
|
+
return useComponentToggle(defaultProps);
|
58
|
+
}),
|
59
|
+
result = _renderHook.result;
|
60
|
+
|
61
|
+
act(function () {
|
62
|
+
return result.current.handleConditionChange();
|
63
|
+
});
|
64
|
+
expect(callback).toHaveBeenCalled();
|
65
|
+
});
|
66
|
+
test('expect hook to return correct data shape', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
67
|
+
var _renderHook2, result, _result$current, handleConditionChange, RenderedComponent;
|
68
|
+
|
69
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
70
|
+
while (1) {
|
71
|
+
switch (_context.prev = _context.next) {
|
72
|
+
case 0:
|
73
|
+
_renderHook2 = renderHook(function () {
|
74
|
+
return useComponentToggle(defaultProps);
|
75
|
+
}), result = _renderHook2.result;
|
76
|
+
_result$current = result.current, handleConditionChange = _result$current.handleConditionChange, RenderedComponent = _result$current.RenderedComponent;
|
77
|
+
expect(handleConditionChange).toEqual(expect.any(Function));
|
78
|
+
expect(RenderedComponent).toEqual('false-string');
|
79
|
+
|
80
|
+
case 4:
|
81
|
+
case "end":
|
82
|
+
return _context.stop();
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}, _callee);
|
86
|
+
})));
|
87
|
+
test('expect conditional toggling to work', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
88
|
+
var component;
|
89
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
90
|
+
while (1) {
|
91
|
+
switch (_context2.prev = _context2.next) {
|
92
|
+
case 0:
|
93
|
+
getComponent();
|
94
|
+
component = screen.getByTestId('test-div');
|
95
|
+
expect(component).toHaveTextContent('false-string');
|
96
|
+
userEvent.click(component);
|
97
|
+
expect(component).toHaveTextContent('true-string');
|
98
|
+
|
99
|
+
case 5:
|
100
|
+
case "end":
|
101
|
+
return _context2.stop();
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}, _callee2);
|
105
|
+
})));
|
package/lib/index.js
CHANGED
@@ -43,6 +43,8 @@ export { default as Icon } from './components/Icon';
|
|
43
43
|
export * from './components/Icon';
|
44
44
|
export { default as IconButton } from './components/IconButton';
|
45
45
|
export * from './components/IconButton';
|
46
|
+
export { default as IconButtonToggle } from './components/IconButtonToggle';
|
47
|
+
export * from './components/IconButtonToggle';
|
46
48
|
export { default as Image } from './components/Image';
|
47
49
|
export * from './components/Image';
|
48
50
|
export { default as ImageUploadField } from './components/ImageUploadField';
|
@@ -0,0 +1,137 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import DragVerticalIcon from 'mdi-react/DragVerticalIcon';
|
3
|
+
import DeleteIcon from 'mdi-react/DeleteIcon';
|
4
|
+
import CogsIcon from 'mdi-react/CogsIcon';
|
5
|
+
import Box from '../components/Box';
|
6
|
+
import { Icon, ComboBoxField, Item, IconButton, IconButtonToggle } from '../index';
|
7
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
|
+
export default {
|
9
|
+
title: 'Recipes/OneWayToBidirectionalArrow'
|
10
|
+
};
|
11
|
+
var items = [{
|
12
|
+
name: 'Last Name',
|
13
|
+
id: '1'
|
14
|
+
}, {
|
15
|
+
name: 'First Name',
|
16
|
+
id: '2'
|
17
|
+
}, {
|
18
|
+
name: 'Third Option',
|
19
|
+
id: '3'
|
20
|
+
}];
|
21
|
+
export var Default = function Default() {
|
22
|
+
var CustomOnSvg = function CustomOnSvg() {
|
23
|
+
return ___EmotionJSX("svg", {
|
24
|
+
width: "24",
|
25
|
+
height: "24",
|
26
|
+
viewBox: "0 0 24 24",
|
27
|
+
fill: "none",
|
28
|
+
xmlns: "http://www.w3.org/2000/svg"
|
29
|
+
}, ___EmotionJSX("path", {
|
30
|
+
d: "M8 10V13H14V18H8V21L2 15.5L8 10Z",
|
31
|
+
fill: "#CACED3"
|
32
|
+
}), ___EmotionJSX("path", {
|
33
|
+
d: "M9.83325 10.6251V6.37511H15.4999V2.94678L21.0533 8.50011L15.4999 14.0534V10.6251H9.83325Z",
|
34
|
+
fill: "#4462ED"
|
35
|
+
}), ___EmotionJSX("path", {
|
36
|
+
d: "M8 10V13H14V18H8V21L2 15.5L8 10ZM22 8.5L16 3V6H10V11H16V14L22 8.5Z",
|
37
|
+
fill: "#515F6B"
|
38
|
+
}));
|
39
|
+
};
|
40
|
+
|
41
|
+
var CustomOffSvg = function CustomOffSvg() {
|
42
|
+
return ___EmotionJSX("svg", {
|
43
|
+
width: "24",
|
44
|
+
height: "24",
|
45
|
+
viewBox: "0 0 24 24",
|
46
|
+
fill: "none",
|
47
|
+
xmlns: "http://www.w3.org/2000/svg"
|
48
|
+
}, ___EmotionJSX("path", {
|
49
|
+
d: "M8 10V13H14V18H8V21L2 15.5L8 10Z",
|
50
|
+
fill: "#CACED3"
|
51
|
+
}), ___EmotionJSX("path", {
|
52
|
+
d: "M9.83331 10.6251V6.37511H15.5V2.94678L21.0533 8.50011L15.5 14.0534V10.6251H9.83331Z",
|
53
|
+
fill: "#4462ED"
|
54
|
+
}));
|
55
|
+
};
|
56
|
+
|
57
|
+
return ___EmotionJSX(Box, {
|
58
|
+
sx: {
|
59
|
+
alignItems: 'center'
|
60
|
+
},
|
61
|
+
isRow: true
|
62
|
+
}, ___EmotionJSX(Icon, {
|
63
|
+
icon: DragVerticalIcon,
|
64
|
+
size: 25,
|
65
|
+
color: "neutral.50"
|
66
|
+
}), ___EmotionJSX(ComboBoxField, {
|
67
|
+
items: items,
|
68
|
+
defaultSelectedKey: "Last Name",
|
69
|
+
containerProps: {
|
70
|
+
width: '275px'
|
71
|
+
},
|
72
|
+
labelProps: {
|
73
|
+
mb: 0
|
74
|
+
},
|
75
|
+
"aria-label": "Row one value",
|
76
|
+
controlProps: {
|
77
|
+
'aria-label': 'test'
|
78
|
+
}
|
79
|
+
}, function (item) {
|
80
|
+
return ___EmotionJSX(Item, {
|
81
|
+
key: item.name,
|
82
|
+
"data-id": item.name
|
83
|
+
}, item.name);
|
84
|
+
}), ___EmotionJSX(Box, {
|
85
|
+
sx: {
|
86
|
+
ml: '5px',
|
87
|
+
mr: '5px',
|
88
|
+
flexShrink: 0
|
89
|
+
}
|
90
|
+
}, ___EmotionJSX(IconButtonToggle, {
|
91
|
+
toggledIcon: CustomOnSvg,
|
92
|
+
defaultIcon: CustomOffSvg,
|
93
|
+
title: "Bidirectional/ Outbound toggle",
|
94
|
+
iconProps: {
|
95
|
+
size: 20
|
96
|
+
},
|
97
|
+
buttonProps: {
|
98
|
+
variant: 'svgIconButton'
|
99
|
+
}
|
100
|
+
})), ___EmotionJSX(ComboBoxField, {
|
101
|
+
items: items,
|
102
|
+
defaultSelectedKey: "First Name",
|
103
|
+
containerProps: {
|
104
|
+
width: '275px'
|
105
|
+
},
|
106
|
+
labelProps: {
|
107
|
+
mb: 0
|
108
|
+
},
|
109
|
+
controlProps: {
|
110
|
+
'aria-label': 'Row one Pingone value'
|
111
|
+
}
|
112
|
+
}, function (item) {
|
113
|
+
return ___EmotionJSX(Item, {
|
114
|
+
key: item.name,
|
115
|
+
"data-id": item.name
|
116
|
+
}, item.name);
|
117
|
+
}), ___EmotionJSX(Box, {
|
118
|
+
isRow: true,
|
119
|
+
alignItems: "center",
|
120
|
+
sx: {
|
121
|
+
marginLeft: '12px',
|
122
|
+
marginRight: '12px'
|
123
|
+
}
|
124
|
+
}, ___EmotionJSX(IconButton, null, ___EmotionJSX(Icon, {
|
125
|
+
icon: CogsIcon,
|
126
|
+
color: "neutral.30",
|
127
|
+
size: 20,
|
128
|
+
title: "edit icon"
|
129
|
+
})), ___EmotionJSX(IconButton, {
|
130
|
+
ml: "5px"
|
131
|
+
}, ___EmotionJSX(Icon, {
|
132
|
+
icon: DeleteIcon,
|
133
|
+
color: "neutral.30",
|
134
|
+
size: 20,
|
135
|
+
title: "delete icon"
|
136
|
+
}))));
|
137
|
+
};
|
@@ -116,6 +116,12 @@ var iconButton = {
|
|
116
116
|
}
|
117
117
|
};
|
118
118
|
|
119
|
+
var svgIconButton = _objectSpread(_objectSpread({}, iconButton), {}, {
|
120
|
+
path: {
|
121
|
+
fill: 'default'
|
122
|
+
}
|
123
|
+
});
|
124
|
+
|
119
125
|
var square = _objectSpread(_objectSpread({}, iconButton), {}, {
|
120
126
|
borderRadius: '2px'
|
121
127
|
});
|
@@ -701,5 +707,6 @@ export default {
|
|
701
707
|
colorBlock: colorBlock,
|
702
708
|
menuTab: menuTab,
|
703
709
|
collapsiblePanelToggle: collapsiblePanelToggle,
|
704
|
-
neutralText: neutralText
|
710
|
+
neutralText: neutralText,
|
711
|
+
svgIconButton: svgIconButton
|
705
712
|
};
|