@stokr/components-library 2.3.65-beta.7 → 2.3.65-beta.8
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/dist/components/Input/Input.js +33 -33
- package/dist/components/Input/Input.stories.js +83 -8
- package/dist/components/Input/Select.js +51 -28
- package/dist/components/Input/Select.stories.js +345 -6
- package/dist/components/ProfileBox/ProfileBox.js +2 -1
- package/dist/components/Snackbar/Snackbar.js +193 -0
- package/dist/components/Snackbar/Snackbar.stories.js +292 -0
- package/dist/components/Snackbar/Snackbar.styles.js +97 -0
- package/dist/components/Snackbar/SnackbarProvider.js +81 -0
- package/dist/components/Snackbar/index.js +32 -0
- package/dist/components/Snackbar/useSnackbar.js +43 -0
- package/dist/index.js +11 -0
- package/package.json +1 -1
|
@@ -7,65 +7,64 @@ exports.default = exports.Input = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _Input = require("./Input.styles");
|
|
10
|
+
const _excluded = ["type", "id", "name", "label", "placeholder", "value", "error", "touched", "readOnly", "inverted", "dashboard", "disabled", "inputWrapStyle", "wrapperStyle", "autoHeightLabel", "onChange", "onBlur", "onFocus"];
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
12
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
13
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
14
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
15
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
13
16
|
const Input = props => {
|
|
14
17
|
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
type,
|
|
19
|
+
id,
|
|
20
|
+
name,
|
|
21
|
+
label,
|
|
22
|
+
placeholder,
|
|
23
|
+
value,
|
|
24
|
+
error,
|
|
25
|
+
touched,
|
|
26
|
+
readOnly,
|
|
27
|
+
inverted,
|
|
28
|
+
dashboard,
|
|
29
|
+
disabled,
|
|
30
|
+
inputWrapStyle,
|
|
31
|
+
wrapperStyle,
|
|
32
|
+
autoHeightLabel,
|
|
33
|
+
// Destructure these so they don't get spread to the input
|
|
34
|
+
onChange: onChangeProp,
|
|
35
|
+
onBlur: onBlurProp,
|
|
36
|
+
onFocus: onFocusProp
|
|
37
|
+
} = props,
|
|
38
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
31
39
|
const [labelUp, setLabelUp] = (0, _react.useState)(false);
|
|
32
40
|
const [hasFocus, setHasFocus] = (0, _react.useState)(false);
|
|
33
41
|
(0, _react.useEffect)(() => {
|
|
34
42
|
checkLabel(false);
|
|
35
43
|
}, []);
|
|
36
44
|
(0, _react.useEffect)(() => {
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
if (!!value && !labelUp) {
|
|
46
|
+
checkLabel(false);
|
|
47
|
+
}
|
|
48
|
+
}, [labelUp, value]);
|
|
39
49
|
(0, _react.useEffect)(() => {
|
|
40
50
|
if (value && !labelUp) setLabelUp(true);
|
|
41
51
|
}, [value, labelUp]);
|
|
42
52
|
const onBlur = (e, field) => {
|
|
43
|
-
const {
|
|
44
|
-
onBlur
|
|
45
|
-
} = props;
|
|
46
|
-
|
|
47
53
|
// formik handler MUST be called before our logic !
|
|
48
|
-
|
|
54
|
+
onBlurProp && onBlurProp(e, field);
|
|
49
55
|
|
|
50
56
|
// our logic follows
|
|
51
57
|
checkLabel(false);
|
|
52
58
|
};
|
|
53
59
|
const onFocus = (e, field) => {
|
|
54
|
-
const {
|
|
55
|
-
onFocus
|
|
56
|
-
} = props;
|
|
57
|
-
|
|
58
60
|
// formik handler MUST be called before our logic !
|
|
59
|
-
|
|
61
|
+
onFocusProp && onFocusProp(e, field);
|
|
60
62
|
|
|
61
63
|
// our logic follows
|
|
62
64
|
checkLabel(true);
|
|
63
65
|
};
|
|
64
66
|
const onChange = (e, field) => {
|
|
65
|
-
|
|
66
|
-
onChange
|
|
67
|
-
} = props;
|
|
68
|
-
onChange && onChange(e, field); // formik handler
|
|
67
|
+
onChangeProp && onChangeProp(e, field); // formik handler
|
|
69
68
|
};
|
|
70
69
|
const checkLabel = focus => {
|
|
71
70
|
setHasFocus(focus);
|
|
@@ -96,11 +95,12 @@ const Input = props => {
|
|
|
96
95
|
onFocus: onFocus,
|
|
97
96
|
readOnly: readOnly,
|
|
98
97
|
placeholder: placeholder,
|
|
98
|
+
disabled: disabled,
|
|
99
99
|
style: {
|
|
100
100
|
WebkitAppearance: 'none',
|
|
101
101
|
WebkitBorderRadius: 0
|
|
102
102
|
}
|
|
103
|
-
},
|
|
103
|
+
}, restProps))));
|
|
104
104
|
};
|
|
105
105
|
exports.Input = Input;
|
|
106
106
|
Input.propTypes = {
|
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.InputLabeled = exports.InputFilled = exports.InputFillInverted = exports.InputEmpty = void 0;
|
|
6
|
+
exports.default = exports.InputLabeled = exports.InputFilled = exports.InputFillInverted = exports.InputEmpty = exports.AllStates = void 0;
|
|
7
7
|
var _viewport = require("storybook/viewport");
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _Input = require("./Input");
|
|
10
10
|
var _ComponentWrapper = require("../ComponentWrapper/ComponentWrapper.styles");
|
|
11
11
|
var _global = _interopRequireDefault(require("../../styles/global"));
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
13
15
|
var _default = exports.default = {
|
|
14
16
|
title: 'Components Library/Inputs/Input',
|
|
15
17
|
component: _Input.Input,
|
|
18
|
+
decorators: [Story => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_global.default, null), /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(Story, null)))],
|
|
16
19
|
argTypes: {
|
|
17
20
|
type: {
|
|
18
21
|
type: 'string'
|
|
@@ -79,8 +82,19 @@ var _default = exports.default = {
|
|
|
79
82
|
defaultViewport: 'resetviewport'
|
|
80
83
|
}
|
|
81
84
|
}
|
|
85
|
+
}; // Controlled wrapper for interactive stories
|
|
86
|
+
const ControlledInput = props => {
|
|
87
|
+
const [value, setValue] = (0, _react.useState)(props.value || '');
|
|
88
|
+
return /*#__PURE__*/_react.default.createElement(_Input.Input, _extends({}, props, {
|
|
89
|
+
value: value,
|
|
90
|
+
onChange: e => {
|
|
91
|
+
var _props$onChange;
|
|
92
|
+
setValue(e.target.value);
|
|
93
|
+
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, e);
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
82
96
|
};
|
|
83
|
-
const Template = args => /*#__PURE__*/_react.default.createElement(
|
|
97
|
+
const Template = args => /*#__PURE__*/_react.default.createElement(ControlledInput, args);
|
|
84
98
|
|
|
85
99
|
//trying to integrate state:
|
|
86
100
|
// const Template = args => {
|
|
@@ -135,8 +149,69 @@ InputEmpty.parameters = {
|
|
|
135
149
|
}
|
|
136
150
|
};
|
|
137
151
|
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
152
|
+
// All states example
|
|
153
|
+
const AllStates = () => {
|
|
154
|
+
const [value1, setValue1] = (0, _react.useState)('');
|
|
155
|
+
const [value2, setValue2] = (0, _react.useState)('Filled value');
|
|
156
|
+
const [value3, setValue3] = (0, _react.useState)('');
|
|
157
|
+
const [value4, setValue4] = (0, _react.useState)('Error text');
|
|
158
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
159
|
+
style: {
|
|
160
|
+
display: 'flex',
|
|
161
|
+
flexDirection: 'column',
|
|
162
|
+
gap: '32px'
|
|
163
|
+
}
|
|
164
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
|
|
165
|
+
style: {
|
|
166
|
+
marginBottom: '8px',
|
|
167
|
+
fontSize: '12px',
|
|
168
|
+
color: '#666'
|
|
169
|
+
}
|
|
170
|
+
}, "Empty - Click to see blue label on focus"), /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
171
|
+
id: "empty",
|
|
172
|
+
name: "empty",
|
|
173
|
+
label: "Empty Input",
|
|
174
|
+
value: value1,
|
|
175
|
+
onChange: e => setValue1(e.target.value)
|
|
176
|
+
})), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
|
|
177
|
+
style: {
|
|
178
|
+
marginBottom: '8px',
|
|
179
|
+
fontSize: '12px',
|
|
180
|
+
color: '#666'
|
|
181
|
+
}
|
|
182
|
+
}, "With value"), /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
183
|
+
id: "filled",
|
|
184
|
+
name: "filled",
|
|
185
|
+
label: "Filled Input",
|
|
186
|
+
value: value2,
|
|
187
|
+
onChange: e => setValue2(e.target.value)
|
|
188
|
+
})), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
|
|
189
|
+
style: {
|
|
190
|
+
marginBottom: '8px',
|
|
191
|
+
fontSize: '12px',
|
|
192
|
+
color: '#666'
|
|
193
|
+
}
|
|
194
|
+
}, "Disabled"), /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
195
|
+
id: "disabled",
|
|
196
|
+
name: "disabled",
|
|
197
|
+
label: "Disabled Input",
|
|
198
|
+
value: "Cannot edit",
|
|
199
|
+
disabled: true,
|
|
200
|
+
onChange: () => {}
|
|
201
|
+
})), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
|
|
202
|
+
style: {
|
|
203
|
+
marginBottom: '8px',
|
|
204
|
+
fontSize: '12px',
|
|
205
|
+
color: '#666'
|
|
206
|
+
}
|
|
207
|
+
}, "Error state"), /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
208
|
+
id: "error",
|
|
209
|
+
name: "error",
|
|
210
|
+
label: "Error Input",
|
|
211
|
+
value: value4,
|
|
212
|
+
onChange: e => setValue4(e.target.value),
|
|
213
|
+
error: true,
|
|
214
|
+
touched: true
|
|
215
|
+
})));
|
|
216
|
+
};
|
|
217
|
+
exports.AllStates = AllStates;
|
|
@@ -7,9 +7,10 @@ exports.default = exports.Select = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _reactSelect = _interopRequireWildcard(require("react-select"));
|
|
10
|
+
var _creatable = _interopRequireDefault(require("react-select/creatable"));
|
|
10
11
|
var _Input = require("./Input.styles");
|
|
11
12
|
var _Select = require("./Select.styles");
|
|
12
|
-
const _excluded = ["id", "name", "label", "options", "search", "error", "touched", "value", "disabled", "menuHeight"];
|
|
13
|
+
const _excluded = ["id", "name", "label", "options", "search", "error", "touched", "value", "disabled", "menuHeight", "creatable", "formatCreateLabel"];
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
16
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
@@ -59,7 +60,9 @@ const Select = props => {
|
|
|
59
60
|
touched,
|
|
60
61
|
value,
|
|
61
62
|
disabled,
|
|
62
|
-
menuHeight
|
|
63
|
+
menuHeight,
|
|
64
|
+
creatable,
|
|
65
|
+
formatCreateLabel
|
|
63
66
|
} = props,
|
|
64
67
|
otherProps = _objectWithoutProperties(props, _excluded);
|
|
65
68
|
const [labelUp, setLabelUp] = (0, _react.useState)(!!value);
|
|
@@ -72,7 +75,7 @@ const Select = props => {
|
|
|
72
75
|
name,
|
|
73
76
|
value
|
|
74
77
|
});
|
|
75
|
-
if (search) {
|
|
78
|
+
if (search || creatable) {
|
|
76
79
|
setHasFocus(true);
|
|
77
80
|
}
|
|
78
81
|
};
|
|
@@ -94,12 +97,46 @@ const Select = props => {
|
|
|
94
97
|
setHasFocus(true);
|
|
95
98
|
}, 1);
|
|
96
99
|
};
|
|
100
|
+
|
|
101
|
+
// Choose component based on creatable prop
|
|
102
|
+
const SelectComponent = creatable ? _creatable.default : _reactSelect.default;
|
|
103
|
+
|
|
104
|
+
// Common styles for both components
|
|
105
|
+
const selectStyles = {
|
|
106
|
+
control: () => _Select.SelectControl,
|
|
107
|
+
menu: baseStyle => _objectSpread(_objectSpread({}, baseStyle), {}, {
|
|
108
|
+
marginTop: 0,
|
|
109
|
+
zIndex: 1000,
|
|
110
|
+
SelectMenu: _Select.SelectMenu
|
|
111
|
+
}),
|
|
112
|
+
option: (baseStyle, state) => _objectSpread({
|
|
113
|
+
fontWeight: state.isSelected || state.isFocused ? 'bold' : 'normal',
|
|
114
|
+
cursor: 'pointer'
|
|
115
|
+
}, _Select.SelectOption),
|
|
116
|
+
selectContainer: () => _Select.SelectContainer,
|
|
117
|
+
valueContainer: baseStyle => _objectSpread(_objectSpread({}, baseStyle), {}, {
|
|
118
|
+
padding: 0
|
|
119
|
+
})
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Common components for both
|
|
123
|
+
const selectComponents = {
|
|
124
|
+
DropdownIndicator,
|
|
125
|
+
IndicatorSeparator: null,
|
|
126
|
+
MenuList: SelectMenuListWithScroll
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// Get current value - for creatable, also check if value exists even if not in options
|
|
130
|
+
const currentValue = creatable ? (options === null || options === void 0 ? void 0 : options.find(option => option.value === value)) || (value ? {
|
|
131
|
+
value,
|
|
132
|
+
label: value
|
|
133
|
+
} : null) : options === null || options === void 0 ? void 0 : options.find(option => option.value === value);
|
|
97
134
|
return /*#__PURE__*/_react.default.createElement(_Input.Wrapper, null, label && /*#__PURE__*/_react.default.createElement(_Input.Label, {
|
|
98
135
|
isUp: labelUp,
|
|
99
136
|
active: hasFocus,
|
|
100
137
|
error: error && touched,
|
|
101
138
|
htmlFor: id
|
|
102
|
-
}, label), /*#__PURE__*/_react.default.createElement(
|
|
139
|
+
}, label), /*#__PURE__*/_react.default.createElement(SelectComponent, _extends({}, otherProps, {
|
|
103
140
|
id: id,
|
|
104
141
|
name: name,
|
|
105
142
|
options: options,
|
|
@@ -107,32 +144,14 @@ const Select = props => {
|
|
|
107
144
|
onChange: onChange,
|
|
108
145
|
onBlur: onBlur,
|
|
109
146
|
onFocus: onFocus,
|
|
110
|
-
value:
|
|
147
|
+
value: currentValue,
|
|
111
148
|
placeholder: "",
|
|
112
|
-
isSearchable: search,
|
|
149
|
+
isSearchable: creatable || search,
|
|
113
150
|
maxMenuHeight: menuHeight,
|
|
114
|
-
styles:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
zIndex: 1000,
|
|
119
|
-
SelectMenu: _Select.SelectMenu
|
|
120
|
-
}),
|
|
121
|
-
option: (baseStyle, state) => _objectSpread({
|
|
122
|
-
fontWeight: state.isSelected || state.isFocused ? 'bold' : 'normal',
|
|
123
|
-
cursor: 'pointer'
|
|
124
|
-
}, _Select.SelectOption),
|
|
125
|
-
selectContainer: () => _Select.SelectContainer,
|
|
126
|
-
valueContainer: baseStyle => _objectSpread(_objectSpread({}, baseStyle), {}, {
|
|
127
|
-
padding: 0
|
|
128
|
-
//marginLeft: '-2px',
|
|
129
|
-
})
|
|
130
|
-
},
|
|
131
|
-
components: {
|
|
132
|
-
DropdownIndicator,
|
|
133
|
-
IndicatorSeparator: null,
|
|
134
|
-
MenuList: SelectMenuListWithScroll
|
|
135
|
-
}
|
|
151
|
+
styles: selectStyles,
|
|
152
|
+
components: selectComponents
|
|
153
|
+
}, creatable && {
|
|
154
|
+
formatCreateLabel: formatCreateLabel || (inputValue => "Create \"".concat(inputValue, "\""))
|
|
136
155
|
})));
|
|
137
156
|
};
|
|
138
157
|
exports.Select = Select;
|
|
@@ -149,6 +168,8 @@ Select.propTypes = {
|
|
|
149
168
|
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]).isRequired
|
|
150
169
|
})).isRequired,
|
|
151
170
|
search: _propTypes.default.bool,
|
|
171
|
+
creatable: _propTypes.default.bool,
|
|
172
|
+
formatCreateLabel: _propTypes.default.func,
|
|
152
173
|
onChange: _propTypes.default.func,
|
|
153
174
|
onBlur: _propTypes.default.func,
|
|
154
175
|
onFocus: _propTypes.default.func
|
|
@@ -157,6 +178,8 @@ Select.defaultProps = {
|
|
|
157
178
|
label: '',
|
|
158
179
|
value: '',
|
|
159
180
|
search: false,
|
|
181
|
+
creatable: false,
|
|
182
|
+
formatCreateLabel: null,
|
|
160
183
|
error: false,
|
|
161
184
|
touched: false,
|
|
162
185
|
onChange: () => {},
|