@stokr/components-library 2.3.65-beta.2 → 2.3.65-beta.4
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/2FA/main-flow.js +28 -7
- package/dist/components/2FA/main-flow.stories.js +144 -15
- package/dist/components/Input/SearchInput.js +75 -0
- package/dist/components/Input/SearchInput.stories.js +304 -0
- package/dist/components/Input/SearchInput.styles.js +25 -0
- package/dist/components/Modal/SideModal.js +82 -0
- package/dist/components/Modal/SideModal.stories.js +342 -0
- package/dist/components/Modal/SideModal.styles.js +21 -0
- package/dist/components/StatusTag/StatusTag.js +168 -0
- package/dist/components/StatusTag/StatusTag.stories.js +262 -0
- package/dist/components/StatusTag/StatusTag.styles.js +37 -0
- package/dist/index.js +22 -0
- package/dist/static/images/document-icon.svg +3 -0
- package/dist/static/images/search-icon.svg +3 -0
- package/dist/static/images/sent-icon.svg +10 -0
- package/package.json +1 -1
|
@@ -10,7 +10,6 @@ var _AuthContext = require("../../context/AuthContext");
|
|
|
10
10
|
var _ComponentWrapper = _interopRequireDefault(require("../ComponentWrapper/ComponentWrapper.styles"));
|
|
11
11
|
var _Switch = _interopRequireDefault(require("../Switch/Switch"));
|
|
12
12
|
var _Text = _interopRequireDefault(require("../Text/Text.styles"));
|
|
13
|
-
var _Button = _interopRequireDefault(require("../Button/Button.styles"));
|
|
14
13
|
var _loginWithOtpFlow = _interopRequireDefault(require("./login-with-otp-flow"));
|
|
15
14
|
var _enable2faFlow = _interopRequireDefault(require("./enable-2fa-flow"));
|
|
16
15
|
var _disable2faFlow = _interopRequireDefault(require("./disable-2fa-flow"));
|
|
@@ -18,7 +17,7 @@ var _colors = _interopRequireDefault(require("../../styles/colors"));
|
|
|
18
17
|
var _InfoIcon = _interopRequireDefault(require("../InfoIcon/InfoIcon"));
|
|
19
18
|
var _Modal = require("../Modal/Modal");
|
|
20
19
|
var _Sucess2FA = _interopRequireDefault(require("./Sucess2FA"));
|
|
21
|
-
const _excluded = ["onRequiresRecentLoginError", "open2faflow", "onLoginAgainClick", "openDisable2faflow"];
|
|
20
|
+
const _excluded = ["onRequiresRecentLoginError", "open2faflow", "onLoginAgainClick", "openDisable2faflow", "title", "subtitle", "showSwitch", "customComponent"];
|
|
22
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
22
|
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); }
|
|
24
23
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -33,7 +32,11 @@ const Main2FAFlow = _ref => {
|
|
|
33
32
|
onRequiresRecentLoginError,
|
|
34
33
|
open2faflow,
|
|
35
34
|
onLoginAgainClick,
|
|
36
|
-
openDisable2faflow
|
|
35
|
+
openDisable2faflow,
|
|
36
|
+
title = 'SET UP YOUR LOG IN TWO FACTOR AUTHENTICATION',
|
|
37
|
+
subtitle = 'Protect your account with an additional layer of security to log in',
|
|
38
|
+
showSwitch = true,
|
|
39
|
+
customComponent
|
|
37
40
|
} = _ref,
|
|
38
41
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
39
42
|
const {
|
|
@@ -58,6 +61,7 @@ const Main2FAFlow = _ref => {
|
|
|
58
61
|
checkMfaEnrollment();
|
|
59
62
|
generateTotp();
|
|
60
63
|
}
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
65
|
}, [user, userMfaEnrollment]);
|
|
62
66
|
|
|
63
67
|
//remove succes message after 5 seconds
|
|
@@ -70,7 +74,7 @@ const Main2FAFlow = _ref => {
|
|
|
70
74
|
}, [successMessage]);
|
|
71
75
|
const generateTotp = async () => {
|
|
72
76
|
try {
|
|
73
|
-
const response = await generateTotpSecret(
|
|
77
|
+
const response = await generateTotpSecret();
|
|
74
78
|
settotpData(response);
|
|
75
79
|
} catch (error) {
|
|
76
80
|
if (error.code === 'auth/requires-recent-login' || error.code === 'auth/unsupported-first-factor') {
|
|
@@ -79,7 +83,7 @@ const Main2FAFlow = _ref => {
|
|
|
79
83
|
}
|
|
80
84
|
};
|
|
81
85
|
const switchOpenFlow = (prevFlowId, nextFlowId) => {
|
|
82
|
-
setIsFlowOpen(_objectSpread(_objectSpread({},
|
|
86
|
+
setIsFlowOpen(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
83
87
|
[prevFlowId]: false,
|
|
84
88
|
[nextFlowId]: true
|
|
85
89
|
}));
|
|
@@ -102,10 +106,25 @@ const Main2FAFlow = _ref => {
|
|
|
102
106
|
});
|
|
103
107
|
onRequiresRecentLoginError && onRequiresRecentLoginError();
|
|
104
108
|
};
|
|
109
|
+
|
|
110
|
+
// Expose flow control functions for customComponent
|
|
111
|
+
const flowActions = {
|
|
112
|
+
openEnable2FA: () => switchOpenFlow('disable2fa', 'enable2fa'),
|
|
113
|
+
openDisable2FA: () => switchOpenFlow('enable2fa', 'disable2fa'),
|
|
114
|
+
closeFlows: () => {
|
|
115
|
+
setIsFlowOpen({
|
|
116
|
+
enable2fa: false,
|
|
117
|
+
disable2fa: false,
|
|
118
|
+
requiresRecentLogin: false
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
is2FAEnabled,
|
|
122
|
+
isFlowOpen: isFlowopen
|
|
123
|
+
};
|
|
105
124
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ComponentWrapper.default, {
|
|
106
125
|
alignVertically: true,
|
|
107
126
|
noPaddingHorizontal: true
|
|
108
|
-
}, /*#__PURE__*/_react.default.createElement(_Text.default, null, /*#__PURE__*/_react.default.createElement("h5", null,
|
|
127
|
+
}, /*#__PURE__*/_react.default.createElement(_Text.default, null, /*#__PURE__*/_react.default.createElement("h5", null, title))), /*#__PURE__*/_react.default.createElement(_Text.default, null, /*#__PURE__*/_react.default.createElement("p", null, subtitle)), showSwitch && /*#__PURE__*/_react.default.createElement(_ComponentWrapper.default, {
|
|
109
128
|
noPaddingHorizontal: true
|
|
110
129
|
}, /*#__PURE__*/_react.default.createElement(_InfoIcon.default, {
|
|
111
130
|
position: 'top',
|
|
@@ -146,7 +165,9 @@ const Main2FAFlow = _ref => {
|
|
|
146
165
|
bottom: 0,
|
|
147
166
|
left: 0
|
|
148
167
|
}
|
|
149
|
-
}, /*#__PURE__*/_react.default.createElement("p", null, successMessage))),
|
|
168
|
+
}, /*#__PURE__*/_react.default.createElement("p", null, successMessage))), customComponent && (typeof customComponent === 'function' ? customComponent(flowActions) : /*#__PURE__*/_react.default.isValidElement(customComponent) ? /*#__PURE__*/_react.default.cloneElement(customComponent, {
|
|
169
|
+
flowActions
|
|
170
|
+
}) : customComponent), isFlowopen.enable2fa && /*#__PURE__*/_react.default.createElement(_enable2faFlow.default, {
|
|
150
171
|
showFlow: isFlowopen.enable2fa,
|
|
151
172
|
setShowFlow: value => setIsFlowOpen(_objectSpread(_objectSpread({}, isFlowopen), {}, {
|
|
152
173
|
enable2fa: value
|
|
@@ -3,31 +3,160 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.
|
|
7
|
-
var _react =
|
|
6
|
+
exports.default = exports.WithoutSwitch = exports.WithCustomComponentFunction = exports.WithCustomComponent = exports.PreOpenedEnableFlow = exports.PreOpenedDisableFlow = exports.Default = exports.CustomTitles = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactRouterDom = require("react-router-dom");
|
|
9
9
|
var _global = _interopRequireDefault(require("../../styles/global"));
|
|
10
10
|
var _mainFlow = _interopRequireDefault(require("./main-flow"));
|
|
11
11
|
var _AuthContext = require("../../context/AuthContext");
|
|
12
|
+
var _Button = _interopRequireDefault(require("../Button/Button.styles"));
|
|
13
|
+
var _ComponentWrapper = require("../ComponentWrapper/ComponentWrapper.styles");
|
|
12
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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); }
|
|
13
16
|
var _default = exports.default = {
|
|
14
|
-
title: 'Components Library/2FA',
|
|
17
|
+
title: 'Components Library/2FA/Main2FAFlow',
|
|
15
18
|
component: _mainFlow.default,
|
|
16
19
|
argTypes: {
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
title: {
|
|
21
|
+
control: 'text',
|
|
22
|
+
description: 'Title text for the 2FA section'
|
|
23
|
+
},
|
|
24
|
+
subtitle: {
|
|
25
|
+
control: 'text',
|
|
26
|
+
description: 'Subtitle text for the 2FA section'
|
|
27
|
+
},
|
|
28
|
+
showSwitch: {
|
|
29
|
+
control: 'boolean',
|
|
30
|
+
description: 'Show/hide the toggle switch',
|
|
19
31
|
defaultValue: true
|
|
20
32
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
open2faflow: {
|
|
34
|
+
control: 'boolean',
|
|
35
|
+
description: 'Open enable 2FA flow on mount'
|
|
36
|
+
},
|
|
37
|
+
openDisable2faflow: {
|
|
38
|
+
control: 'boolean',
|
|
39
|
+
description: 'Open disable 2FA flow on mount'
|
|
40
|
+
},
|
|
41
|
+
onRequiresRecentLoginError: {
|
|
42
|
+
action: 'requiresRecentLogin',
|
|
43
|
+
description: 'Callback when recent login is required'
|
|
44
|
+
},
|
|
45
|
+
onLoginAgainClick: {
|
|
46
|
+
action: 'loginAgain',
|
|
47
|
+
description: 'Callback when user clicks login again'
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
decorators: [Story => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactRouterDom.BrowserRouter, null, /*#__PURE__*/_react.default.createElement(_AuthContext.AuthProvider, null, /*#__PURE__*/_react.default.createElement(_global.default, null), /*#__PURE__*/_react.default.createElement(Story, null))))]
|
|
51
|
+
};
|
|
52
|
+
const Template = args => /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(_mainFlow.default, args));
|
|
53
|
+
|
|
54
|
+
// Default example
|
|
55
|
+
const Default = exports.Default = Template.bind({});
|
|
56
|
+
Default.args = {};
|
|
57
|
+
|
|
58
|
+
// With custom component as React element
|
|
59
|
+
const WithCustomComponent = () => {
|
|
60
|
+
const CustomButtonGroup = _ref => {
|
|
61
|
+
var _flowActions$isFlowOp, _flowActions$isFlowOp2;
|
|
62
|
+
let {
|
|
63
|
+
flowActions
|
|
64
|
+
} = _ref;
|
|
65
|
+
if (!flowActions) return null;
|
|
66
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, {
|
|
67
|
+
noPaddingHorizontal: true,
|
|
68
|
+
style: {
|
|
69
|
+
marginTop: '16px'
|
|
70
|
+
}
|
|
71
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
72
|
+
style: {
|
|
73
|
+
display: 'flex',
|
|
74
|
+
gap: '12px',
|
|
75
|
+
flexWrap: 'wrap'
|
|
76
|
+
}
|
|
77
|
+
}, /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
78
|
+
onClick: flowActions.openEnable2FA,
|
|
79
|
+
disabled: flowActions.is2FAEnabled
|
|
80
|
+
}, "Enable 2FA"), /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
81
|
+
onClick: flowActions.openDisable2FA,
|
|
82
|
+
disabled: !flowActions.is2FAEnabled,
|
|
83
|
+
secondary: true
|
|
84
|
+
}, "Disable 2FA"), /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
85
|
+
onClick: flowActions.closeFlows,
|
|
86
|
+
outline: true
|
|
87
|
+
}, "Close All Flows")), /*#__PURE__*/_react.default.createElement("div", {
|
|
88
|
+
style: {
|
|
89
|
+
marginTop: '12px',
|
|
90
|
+
fontSize: '12px',
|
|
91
|
+
color: '#666'
|
|
92
|
+
}
|
|
93
|
+
}, /*#__PURE__*/_react.default.createElement("p", null, "Status: ", flowActions.is2FAEnabled ? 'Enabled' : 'Disabled', /*#__PURE__*/_react.default.createElement("br", null), "Enable Flow Open: ", (_flowActions$isFlowOp = flowActions.isFlowOpen) !== null && _flowActions$isFlowOp !== void 0 && _flowActions$isFlowOp.enable2fa ? 'Yes' : 'No', /*#__PURE__*/_react.default.createElement("br", null), "Disable Flow Open:", ' ', (_flowActions$isFlowOp2 = flowActions.isFlowOpen) !== null && _flowActions$isFlowOp2 !== void 0 && _flowActions$isFlowOp2.disable2fa ? 'Yes' : 'No')));
|
|
94
|
+
};
|
|
95
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(_mainFlow.default, {
|
|
96
|
+
customComponent: /*#__PURE__*/_react.default.createElement(CustomButtonGroup, null)
|
|
97
|
+
}));
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// With custom component as render function
|
|
101
|
+
exports.WithCustomComponent = WithCustomComponent;
|
|
102
|
+
const WithCustomComponentFunction = () => {
|
|
103
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(_mainFlow.default, {
|
|
104
|
+
customComponent: flowActions => {
|
|
105
|
+
if (!flowActions) return null;
|
|
106
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, {
|
|
107
|
+
noPaddingHorizontal: true,
|
|
108
|
+
style: {
|
|
109
|
+
marginTop: '16px'
|
|
110
|
+
}
|
|
111
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
112
|
+
style: {
|
|
113
|
+
display: 'flex',
|
|
114
|
+
gap: '12px',
|
|
115
|
+
flexWrap: 'wrap'
|
|
116
|
+
}
|
|
117
|
+
}, /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
118
|
+
onClick: flowActions.openEnable2FA,
|
|
119
|
+
disabled: flowActions.is2FAEnabled
|
|
120
|
+
}, "Enable 2FA"), /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
121
|
+
onClick: flowActions.openDisable2FA,
|
|
122
|
+
disabled: !flowActions.is2FAEnabled,
|
|
123
|
+
secondary: true
|
|
124
|
+
}, "Disable 2FA"), /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
125
|
+
onClick: flowActions.closeFlows,
|
|
126
|
+
outline: true
|
|
127
|
+
}, "Close All Flows")), /*#__PURE__*/_react.default.createElement("div", {
|
|
128
|
+
style: {
|
|
129
|
+
marginTop: '12px',
|
|
130
|
+
fontSize: '12px',
|
|
131
|
+
color: '#666'
|
|
132
|
+
}
|
|
133
|
+
}, /*#__PURE__*/_react.default.createElement("p", null, "Status: ", flowActions.is2FAEnabled ? 'Enabled' : 'Disabled')));
|
|
26
134
|
}
|
|
27
|
-
}
|
|
135
|
+
}));
|
|
28
136
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
137
|
+
|
|
138
|
+
// Without switch
|
|
139
|
+
exports.WithCustomComponentFunction = WithCustomComponentFunction;
|
|
140
|
+
const WithoutSwitch = exports.WithoutSwitch = Template.bind({});
|
|
141
|
+
WithoutSwitch.args = {
|
|
142
|
+
showSwitch: false
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Custom titles
|
|
146
|
+
const CustomTitles = exports.CustomTitles = Template.bind({});
|
|
147
|
+
CustomTitles.args = {
|
|
148
|
+
title: 'Two-Factor Authentication',
|
|
149
|
+
subtitle: 'Add an extra layer of security to your account'
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// Pre-opened enable flow
|
|
153
|
+
const PreOpenedEnableFlow = exports.PreOpenedEnableFlow = Template.bind({});
|
|
154
|
+
PreOpenedEnableFlow.args = {
|
|
155
|
+
open2faflow: true
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Pre-opened disable flow
|
|
159
|
+
const PreOpenedDisableFlow = exports.PreOpenedDisableFlow = Template.bind({});
|
|
160
|
+
PreOpenedDisableFlow.args = {
|
|
161
|
+
openDisable2faflow: true
|
|
33
162
|
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.SearchInput = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _SearchInput = require("./SearchInput.styles");
|
|
9
|
+
var _searchIcon = require("../../static/images/search-icon.svg");
|
|
10
|
+
const _excluded = ["value", "onChange", "placeholder", "icon", "showIcon", "disabled", "onFocus", "onBlur", "className", "containerStyle", "inputStyle", "iconStyle", "id", "name", "aria-label", "aria-describedby"];
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
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
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
const SearchInput = _ref => {
|
|
16
|
+
let {
|
|
17
|
+
value = '',
|
|
18
|
+
onChange,
|
|
19
|
+
placeholder = 'Search',
|
|
20
|
+
icon,
|
|
21
|
+
showIcon = true,
|
|
22
|
+
disabled = false,
|
|
23
|
+
onFocus,
|
|
24
|
+
onBlur,
|
|
25
|
+
className,
|
|
26
|
+
containerStyle,
|
|
27
|
+
inputStyle,
|
|
28
|
+
iconStyle,
|
|
29
|
+
id,
|
|
30
|
+
name,
|
|
31
|
+
'aria-label': ariaLabel,
|
|
32
|
+
'aria-describedby': ariaDescribedBy
|
|
33
|
+
} = _ref,
|
|
34
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
+
const handleChange = e => {
|
|
36
|
+
if (onChange) {
|
|
37
|
+
onChange(e.target.value, e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const handleFocus = e => {
|
|
41
|
+
if (onFocus) {
|
|
42
|
+
onFocus(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const handleBlur = e => {
|
|
46
|
+
if (onBlur) {
|
|
47
|
+
onBlur(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const inputId = id || "search-input-".concat(Math.random().toString(36).substr(2, 9));
|
|
51
|
+
const inputName = name || inputId;
|
|
52
|
+
return /*#__PURE__*/_react.default.createElement(_SearchInput.SearchInputContainer, {
|
|
53
|
+
className: className,
|
|
54
|
+
style: containerStyle
|
|
55
|
+
}, /*#__PURE__*/_react.default.createElement(_SearchInput.SearchInputWrapper, {
|
|
56
|
+
disabled: disabled
|
|
57
|
+
}, showIcon && /*#__PURE__*/_react.default.createElement(_SearchInput.SearchIconWrapper, {
|
|
58
|
+
style: iconStyle
|
|
59
|
+
}, icon || /*#__PURE__*/_react.default.createElement(_searchIcon.ReactComponent, null)), /*#__PURE__*/_react.default.createElement(_SearchInput.SearchInputField, _extends({
|
|
60
|
+
id: inputId,
|
|
61
|
+
name: inputName,
|
|
62
|
+
type: "search",
|
|
63
|
+
value: value,
|
|
64
|
+
onChange: handleChange,
|
|
65
|
+
onFocus: handleFocus,
|
|
66
|
+
onBlur: handleBlur,
|
|
67
|
+
placeholder: placeholder,
|
|
68
|
+
disabled: disabled,
|
|
69
|
+
"aria-label": ariaLabel || placeholder,
|
|
70
|
+
"aria-describedby": ariaDescribedBy,
|
|
71
|
+
style: inputStyle
|
|
72
|
+
}, props))));
|
|
73
|
+
};
|
|
74
|
+
exports.SearchInput = SearchInput;
|
|
75
|
+
var _default = exports.default = SearchInput;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.WithoutIcon = exports.WithInitialValue = exports.WithCustomIcon = exports.LongText = exports.Disabled = exports.DifferentWidths = exports.Default = exports.CustomStyling = exports.CustomPlaceholder = exports.AllStates = exports.AccessibilityExample = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _SearchInput = _interopRequireDefault(require("./SearchInput"));
|
|
9
|
+
var _ComponentWrapper = require("../ComponentWrapper/ComponentWrapper.styles");
|
|
10
|
+
var _colors = _interopRequireDefault(require("../../styles/colors"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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); }
|
|
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
|
+
var _default = exports.default = {
|
|
15
|
+
title: 'Components Library/Inputs/SearchInput',
|
|
16
|
+
component: _SearchInput.default,
|
|
17
|
+
argTypes: {
|
|
18
|
+
value: {
|
|
19
|
+
control: 'text',
|
|
20
|
+
description: 'The search input value (controlled)'
|
|
21
|
+
},
|
|
22
|
+
onChange: {
|
|
23
|
+
action: 'changed',
|
|
24
|
+
description: 'Callback fired when the value changes'
|
|
25
|
+
},
|
|
26
|
+
placeholder: {
|
|
27
|
+
control: 'text',
|
|
28
|
+
description: 'Placeholder text',
|
|
29
|
+
defaultValue: 'Search'
|
|
30
|
+
},
|
|
31
|
+
showIcon: {
|
|
32
|
+
control: 'boolean',
|
|
33
|
+
description: 'Show/hide the search icon',
|
|
34
|
+
defaultValue: true
|
|
35
|
+
},
|
|
36
|
+
disabled: {
|
|
37
|
+
control: 'boolean',
|
|
38
|
+
description: 'Disable the input',
|
|
39
|
+
defaultValue: false
|
|
40
|
+
},
|
|
41
|
+
icon: {
|
|
42
|
+
control: false,
|
|
43
|
+
description: 'Custom icon component (React node)'
|
|
44
|
+
},
|
|
45
|
+
onFocus: {
|
|
46
|
+
action: 'focused',
|
|
47
|
+
description: 'Callback fired when input receives focus'
|
|
48
|
+
},
|
|
49
|
+
onBlur: {
|
|
50
|
+
action: 'blurred',
|
|
51
|
+
description: 'Callback fired when input loses focus'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}; // Controlled component wrapper for stories
|
|
55
|
+
const ControlledSearchInput = args => {
|
|
56
|
+
const [value, setValue] = (0, _react.useState)(args.value || '');
|
|
57
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(_SearchInput.default, _extends({}, args, {
|
|
58
|
+
value: value,
|
|
59
|
+
onChange: (newValue, e) => {
|
|
60
|
+
var _args$onChange;
|
|
61
|
+
setValue(newValue);
|
|
62
|
+
(_args$onChange = args.onChange) === null || _args$onChange === void 0 || _args$onChange.call(args, newValue, e);
|
|
63
|
+
}
|
|
64
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
65
|
+
style: {
|
|
66
|
+
marginTop: '12px',
|
|
67
|
+
fontSize: '12px',
|
|
68
|
+
color: _colors.default.grey2
|
|
69
|
+
}
|
|
70
|
+
}, "Current value: ", /*#__PURE__*/_react.default.createElement("strong", null, value || '(empty)')));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Default example
|
|
74
|
+
const Default = exports.Default = ControlledSearchInput.bind({});
|
|
75
|
+
Default.args = {
|
|
76
|
+
placeholder: 'Search'
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Without icon
|
|
80
|
+
const WithoutIcon = exports.WithoutIcon = ControlledSearchInput.bind({});
|
|
81
|
+
WithoutIcon.args = {
|
|
82
|
+
placeholder: 'Search',
|
|
83
|
+
showIcon: false
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// With custom placeholder
|
|
87
|
+
const CustomPlaceholder = exports.CustomPlaceholder = ControlledSearchInput.bind({});
|
|
88
|
+
CustomPlaceholder.args = {
|
|
89
|
+
placeholder: 'Search users, projects, or tags...'
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Disabled state
|
|
93
|
+
const Disabled = exports.Disabled = ControlledSearchInput.bind({});
|
|
94
|
+
Disabled.args = {
|
|
95
|
+
placeholder: 'Search',
|
|
96
|
+
value: 'Sample search text',
|
|
97
|
+
disabled: true
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// With initial value
|
|
101
|
+
const WithInitialValue = exports.WithInitialValue = ControlledSearchInput.bind({});
|
|
102
|
+
WithInitialValue.args = {
|
|
103
|
+
placeholder: 'Search',
|
|
104
|
+
value: 'Initial search term'
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Custom icon example
|
|
108
|
+
const WithCustomIcon = () => {
|
|
109
|
+
const [value, setValue] = (0, _react.useState)('');
|
|
110
|
+
const CustomIcon = () => /*#__PURE__*/_react.default.createElement("svg", {
|
|
111
|
+
width: "20",
|
|
112
|
+
height: "20",
|
|
113
|
+
viewBox: "0 0 20 20",
|
|
114
|
+
fill: "none",
|
|
115
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
116
|
+
}, /*#__PURE__*/_react.default.createElement("circle", {
|
|
117
|
+
cx: "9",
|
|
118
|
+
cy: "9",
|
|
119
|
+
r: "6",
|
|
120
|
+
stroke: "currentColor",
|
|
121
|
+
strokeWidth: "2"
|
|
122
|
+
}), /*#__PURE__*/_react.default.createElement("path", {
|
|
123
|
+
d: "M15 15L12 12",
|
|
124
|
+
stroke: "currentColor",
|
|
125
|
+
strokeWidth: "2"
|
|
126
|
+
}));
|
|
127
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
128
|
+
value: value,
|
|
129
|
+
onChange: setValue,
|
|
130
|
+
placeholder: "Search with custom icon",
|
|
131
|
+
icon: /*#__PURE__*/_react.default.createElement(CustomIcon, null)
|
|
132
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
133
|
+
style: {
|
|
134
|
+
marginTop: '12px',
|
|
135
|
+
fontSize: '12px',
|
|
136
|
+
color: _colors.default.grey2
|
|
137
|
+
}
|
|
138
|
+
}, "Current value: ", /*#__PURE__*/_react.default.createElement("strong", null, value || '(empty)')));
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Different widths
|
|
142
|
+
exports.WithCustomIcon = WithCustomIcon;
|
|
143
|
+
const DifferentWidths = () => {
|
|
144
|
+
const [value1, setValue1] = (0, _react.useState)('');
|
|
145
|
+
const [value2, setValue2] = (0, _react.useState)('');
|
|
146
|
+
const [value3, setValue3] = (0, _react.useState)('');
|
|
147
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
148
|
+
style: {
|
|
149
|
+
marginBottom: '16px'
|
|
150
|
+
}
|
|
151
|
+
}, /*#__PURE__*/_react.default.createElement("h4", {
|
|
152
|
+
style: {
|
|
153
|
+
marginBottom: '8px',
|
|
154
|
+
fontSize: '14px'
|
|
155
|
+
}
|
|
156
|
+
}, "Full width"), /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
157
|
+
value: value1,
|
|
158
|
+
onChange: setValue1,
|
|
159
|
+
placeholder: "Search (full width)"
|
|
160
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
161
|
+
style: {
|
|
162
|
+
marginBottom: '16px',
|
|
163
|
+
maxWidth: '400px'
|
|
164
|
+
}
|
|
165
|
+
}, /*#__PURE__*/_react.default.createElement("h4", {
|
|
166
|
+
style: {
|
|
167
|
+
marginBottom: '8px',
|
|
168
|
+
fontSize: '14px'
|
|
169
|
+
}
|
|
170
|
+
}, "Max width 400px"), /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
171
|
+
value: value2,
|
|
172
|
+
onChange: setValue2,
|
|
173
|
+
placeholder: "Search (400px max)"
|
|
174
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
175
|
+
style: {
|
|
176
|
+
marginBottom: '16px',
|
|
177
|
+
maxWidth: '200px'
|
|
178
|
+
}
|
|
179
|
+
}, /*#__PURE__*/_react.default.createElement("h4", {
|
|
180
|
+
style: {
|
|
181
|
+
marginBottom: '8px',
|
|
182
|
+
fontSize: '14px'
|
|
183
|
+
}
|
|
184
|
+
}, "Max width 200px"), /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
185
|
+
value: value3,
|
|
186
|
+
onChange: setValue3,
|
|
187
|
+
placeholder: "Search (200px max)"
|
|
188
|
+
})));
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// Long text example
|
|
192
|
+
exports.DifferentWidths = DifferentWidths;
|
|
193
|
+
const LongText = exports.LongText = ControlledSearchInput.bind({});
|
|
194
|
+
LongText.args = {
|
|
195
|
+
placeholder: 'Search',
|
|
196
|
+
value: 'This is a very long search query that might overflow the input field'
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// All states
|
|
200
|
+
const AllStates = () => {
|
|
201
|
+
const [value1, setValue1] = (0, _react.useState)('');
|
|
202
|
+
const [value2, setValue2] = (0, _react.useState)('');
|
|
203
|
+
const [value3, setValue3] = (0, _react.useState)('Sample text');
|
|
204
|
+
const [value4, setValue4] = (0, _react.useState)('Disabled with text');
|
|
205
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
206
|
+
style: {
|
|
207
|
+
marginBottom: '24px'
|
|
208
|
+
}
|
|
209
|
+
}, /*#__PURE__*/_react.default.createElement("h4", {
|
|
210
|
+
style: {
|
|
211
|
+
marginBottom: '8px',
|
|
212
|
+
fontSize: '14px'
|
|
213
|
+
}
|
|
214
|
+
}, "Empty (default)"), /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
215
|
+
value: value1,
|
|
216
|
+
onChange: setValue1,
|
|
217
|
+
placeholder: "Search"
|
|
218
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
219
|
+
style: {
|
|
220
|
+
marginBottom: '24px'
|
|
221
|
+
}
|
|
222
|
+
}, /*#__PURE__*/_react.default.createElement("h4", {
|
|
223
|
+
style: {
|
|
224
|
+
marginBottom: '8px',
|
|
225
|
+
fontSize: '14px'
|
|
226
|
+
}
|
|
227
|
+
}, "Without icon"), /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
228
|
+
value: value2,
|
|
229
|
+
onChange: setValue2,
|
|
230
|
+
placeholder: "Search",
|
|
231
|
+
showIcon: false
|
|
232
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
233
|
+
style: {
|
|
234
|
+
marginBottom: '24px'
|
|
235
|
+
}
|
|
236
|
+
}, /*#__PURE__*/_react.default.createElement("h4", {
|
|
237
|
+
style: {
|
|
238
|
+
marginBottom: '8px',
|
|
239
|
+
fontSize: '14px'
|
|
240
|
+
}
|
|
241
|
+
}, "With value"), /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
242
|
+
value: value3,
|
|
243
|
+
onChange: setValue3,
|
|
244
|
+
placeholder: "Search"
|
|
245
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
246
|
+
style: {
|
|
247
|
+
marginBottom: '24px'
|
|
248
|
+
}
|
|
249
|
+
}, /*#__PURE__*/_react.default.createElement("h4", {
|
|
250
|
+
style: {
|
|
251
|
+
marginBottom: '8px',
|
|
252
|
+
fontSize: '14px'
|
|
253
|
+
}
|
|
254
|
+
}, "Disabled"), /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
255
|
+
value: value4,
|
|
256
|
+
onChange: setValue4,
|
|
257
|
+
placeholder: "Search",
|
|
258
|
+
disabled: true
|
|
259
|
+
})));
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// Accessibility example
|
|
263
|
+
exports.AllStates = AllStates;
|
|
264
|
+
const AccessibilityExample = exports.AccessibilityExample = ControlledSearchInput.bind({});
|
|
265
|
+
AccessibilityExample.args = {
|
|
266
|
+
placeholder: 'Search',
|
|
267
|
+
'aria-label': 'Search for products',
|
|
268
|
+
'aria-describedby': 'search-help-text'
|
|
269
|
+
};
|
|
270
|
+
AccessibilityExample.decorators = [Story => /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(Story, null), /*#__PURE__*/_react.default.createElement("div", {
|
|
271
|
+
id: "search-help-text",
|
|
272
|
+
style: {
|
|
273
|
+
marginTop: '8px',
|
|
274
|
+
fontSize: '12px',
|
|
275
|
+
color: _colors.default.grey2
|
|
276
|
+
}
|
|
277
|
+
}, "Use this search to find products by name, category, or description."))];
|
|
278
|
+
|
|
279
|
+
// Custom styling
|
|
280
|
+
const CustomStyling = () => {
|
|
281
|
+
const [value, setValue] = (0, _react.useState)('');
|
|
282
|
+
return /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(_SearchInput.default, {
|
|
283
|
+
value: value,
|
|
284
|
+
onChange: setValue,
|
|
285
|
+
placeholder: "Search with custom styling",
|
|
286
|
+
containerStyle: {
|
|
287
|
+
maxWidth: '500px',
|
|
288
|
+
margin: '0 auto'
|
|
289
|
+
},
|
|
290
|
+
inputStyle: {
|
|
291
|
+
fontSize: '16px'
|
|
292
|
+
},
|
|
293
|
+
iconStyle: {
|
|
294
|
+
color: _colors.default.blue
|
|
295
|
+
}
|
|
296
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
297
|
+
style: {
|
|
298
|
+
marginTop: '12px',
|
|
299
|
+
fontSize: '12px',
|
|
300
|
+
color: _colors.default.grey2
|
|
301
|
+
}
|
|
302
|
+
}, "Current value: ", /*#__PURE__*/_react.default.createElement("strong", null, value || '(empty)')));
|
|
303
|
+
};
|
|
304
|
+
exports.CustomStyling = CustomStyling;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SearchInputWrapper = exports.SearchInputField = exports.SearchInputContainer = exports.SearchIconWrapper = void 0;
|
|
7
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
|
+
var _colors = _interopRequireDefault(require("../../styles/colors"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
const SearchInputContainer = exports.SearchInputContainer = _styledComponents.default.div.withConfig({
|
|
11
|
+
displayName: "SearchInputstyles__SearchInputContainer",
|
|
12
|
+
componentId: "sc-dcxztv-0"
|
|
13
|
+
})(["width:100%;display:flex;"]);
|
|
14
|
+
const SearchInputWrapper = exports.SearchInputWrapper = _styledComponents.default.div.withConfig({
|
|
15
|
+
displayName: "SearchInputstyles__SearchInputWrapper",
|
|
16
|
+
componentId: "sc-dcxztv-1"
|
|
17
|
+
})(["position:relative;display:flex;align-items:center;width:100%;background-color:", ";border-radius:8px;padding:0 16px;min-height:40px;transition:background-color 0.2s ease;", " &:focus-within{background-color:", ";box-shadow:0 0 0 2px ", ";}"], _colors.default.grey3, props => props.disabled && "\n opacity: 0.6;\n cursor: not-allowed;\n ", _colors.default.white, _colors.default.lightGrey);
|
|
18
|
+
const SearchIconWrapper = exports.SearchIconWrapper = _styledComponents.default.div.withConfig({
|
|
19
|
+
displayName: "SearchInputstyles__SearchIconWrapper",
|
|
20
|
+
componentId: "sc-dcxztv-2"
|
|
21
|
+
})(["display:flex;align-items:center;justify-content:center;margin-right:12px;color:", ";flex-shrink:0;width:16px;height:16px;svg{width:100%;height:100%;}", ":focus-within &{color:", ";}"], _colors.default.grey2, SearchInputWrapper, _colors.default.black);
|
|
22
|
+
const SearchInputField = exports.SearchInputField = _styledComponents.default.input.withConfig({
|
|
23
|
+
displayName: "SearchInputstyles__SearchInputField",
|
|
24
|
+
componentId: "sc-dcxztv-3"
|
|
25
|
+
})(["flex:1;border:none;outline:none;background:transparent;font-size:14px;font-weight:400;line-height:18px;color:", ";width:100%;min-width:0;letter-spacing:0.6px;&::placeholder{color:", ";opacity:1;}&:disabled{cursor:not-allowed;opacity:0.6;}&::-webkit-search-decoration,&::-webkit-search-cancel-button,&::-webkit-search-results-button,&::-webkit-search-results-decoration{-webkit-appearance:none;}"], _colors.default.black, _colors.default.grey2);
|