@commercetools-uikit/field-warnings 0.0.0-canary-20240117152032

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 commercetools GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ <!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
2
+ <!-- This file is created by the `yarn generate-readme` script. -->
3
+
4
+ # FieldWarnings
5
+
6
+ ## Description
7
+
8
+ The `FieldWarnings` component allows the user to display field warnings.
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ yarn add @commercetools-uikit/field-warnings
14
+ ```
15
+
16
+ ```
17
+ npm --save install @commercetools-uikit/field-warnings
18
+ ```
19
+
20
+ Additionally install the peer dependencies (if not present)
21
+
22
+ ```
23
+ yarn add react react-intl
24
+ ```
25
+
26
+ ```
27
+ npm --save install react react-intl
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```jsx
33
+ import FieldWarnings from '../src/field-warnings';
34
+
35
+ const Example = () => (
36
+ // This example shows how to handle custom warnings on top of the
37
+ // predefined warnings of FieldWarnings which this component and other
38
+ // Field components use under the hood.
39
+ <FieldWarnings
40
+ warnings={{
41
+ customWarning: true,
42
+ defaultWarning: true,
43
+ }}
44
+ isVisible={true}
45
+ renderWarning={(key) => {
46
+ switch (key) {
47
+ case 'customWarning':
48
+ return 'The current password is weak, You may want to use a stronger password';
49
+ default:
50
+ // When null is returned then the default warning handling from
51
+ // renderDefaultWarning will kick in for that warning.
52
+ return null;
53
+ }
54
+ }}
55
+ renderDefaultWarning={(key) => {
56
+ switch (key) {
57
+ case 'defaultWarning':
58
+ return 'Always use a strong password';
59
+ default:
60
+ // When null is returned then the warning handling defined in
61
+ // FieldWarning itself will kick in
62
+ return null;
63
+ }
64
+ }}
65
+ />
66
+ );
67
+
68
+ export default Example;
69
+ ```
70
+
71
+ ## Properties
72
+
73
+ | Props | Type | Required | Default | Description |
74
+ | ---------------------- | ---------------------------------------------------------------- | :------: | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
75
+ | `id` | `string` | | | ID of the warning field. |
76
+ | `warnings` | `Record` | | | List of warnings. Only entries with truthy values will count as active warnings. |
77
+ | `isVisible` | `boolean` | | | `true` when the warning messages should be rendered. Usually you'd pass in a `touched` state of fields. |
78
+ | `renderWarning` | `Function`<br/>[See signature.](#signature-renderWarning) | | | Function which gets called with each warning key (from the `warnings` prop) and may render a warning message or return `null` to hand the warning handling off to `renderDefaultWarning`. |
79
+ | `renderDefaultWarning` | `Function`<br/>[See signature.](#signature-renderDefaultWarning) | | | Function which gets called with each warning key (from the `warnings` prop) for which `renderWarning` returned `null`.&#xA;It may render a warning message or return `null` to hand the warning handling off to `FieldWarning`s built-in warning handling. |
80
+
81
+ ## Signatures
82
+
83
+ ### Signature `renderWarning`
84
+
85
+ ```ts
86
+ (key: string, warning?: boolean) => ReactNode;
87
+ ```
88
+
89
+ ### Signature `renderDefaultWarning`
90
+
91
+ ```ts
92
+ (key: string, warning?: boolean) => ReactNode;
93
+ ```
@@ -0,0 +1,3 @@
1
+ export * from "./declarations/src/index";
2
+ export { default } from "./declarations/src/index";
3
+ //# sourceMappingURL=commercetools-uikit-field-warnings.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commercetools-uikit-field-warnings.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
6
+ var _pt = require('prop-types');
7
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
8
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
9
+ var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
10
+ require('react');
11
+ var messages = require('@commercetools-uikit/messages');
12
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
13
+
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
15
+
16
+ var _pt__default = /*#__PURE__*/_interopDefault(_pt);
17
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
18
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
19
+ var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
20
+
21
+ const isObject = obj => typeof obj === 'object';
22
+ const FieldWarnings = props => {
23
+ var _context, _context2;
24
+ if (!props.isVisible) return null;
25
+ if (!props.warnings || !isObject(props.warnings)) return null;
26
+ return jsxRuntime.jsx(jsxRuntime.Fragment, {
27
+ children: _mapInstanceProperty__default["default"](_context = _filterInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](props.warnings)
28
+ // Only render warnings which have truthy values, to avoid
29
+ // rendering a warning that has falsy values.
30
+ ).call(_context2, _ref => {
31
+ let _ref2 = _slicedToArray(_ref, 2),
32
+ warning = _ref2[1];
33
+ return warning;
34
+ })).call(_context, _ref3 => {
35
+ let _ref4 = _slicedToArray(_ref3, 2),
36
+ key = _ref4[0],
37
+ warning = _ref4[1];
38
+ // We might not use a custom warning renderer, so we fall back to null
39
+ // to enable the default warnings to kick in
40
+ const warningElement = props.renderWarning ? props.renderWarning(key, warning) : null;
41
+ // Render a custom warning if one was provided.
42
+ // Custom warnings take precedence over the default warnings
43
+ if (warningElement) return jsxRuntime.jsx(messages.WarningMessage, {
44
+ id: props.id,
45
+ children: warningElement
46
+ }, key);
47
+ const defaultWarningElement = props.renderDefaultWarning ? props.renderDefaultWarning(key, warning) : null;
48
+ // Render a default warning if one was provided.
49
+ // Default warnings take precedence over the known warnings
50
+ if (defaultWarningElement) return jsxRuntime.jsx(messages.WarningMessage, {
51
+ id: props.id,
52
+ children: defaultWarningElement
53
+ }, key);
54
+ // Render nothing in case the warning is not known and no custom warning
55
+ // was returned
56
+ return null;
57
+ })
58
+ });
59
+ };
60
+ FieldWarnings.propTypes = process.env.NODE_ENV !== "production" ? {
61
+ id: _pt__default["default"].string,
62
+ warnings: _pt__default["default"].objectOf(_pt__default["default"].bool),
63
+ isVisible: _pt__default["default"].bool,
64
+ renderWarning: _pt__default["default"].func,
65
+ renderDefaultWarning: _pt__default["default"].func
66
+ } : {};
67
+ FieldWarnings.displayName = 'FieldWarnings';
68
+ var FieldWarnings$1 = FieldWarnings;
69
+
70
+ // NOTE: This string will be replaced on build time with the package version.
71
+ var version = "1.0.0";
72
+
73
+ exports["default"] = FieldWarnings$1;
74
+ exports.version = version;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./commercetools-uikit-field-warnings.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-uikit-field-warnings.cjs.dev.js");
7
+ }
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
6
+ require('prop-types');
7
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
8
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
9
+ var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
10
+ require('react');
11
+ var messages = require('@commercetools-uikit/messages');
12
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
13
+
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
15
+
16
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
17
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
18
+ var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
19
+
20
+ const isObject = obj => typeof obj === 'object';
21
+ const FieldWarnings = props => {
22
+ var _context, _context2;
23
+ if (!props.isVisible) return null;
24
+ if (!props.warnings || !isObject(props.warnings)) return null;
25
+ return jsxRuntime.jsx(jsxRuntime.Fragment, {
26
+ children: _mapInstanceProperty__default["default"](_context = _filterInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](props.warnings)
27
+ // Only render warnings which have truthy values, to avoid
28
+ // rendering a warning that has falsy values.
29
+ ).call(_context2, _ref => {
30
+ let _ref2 = _slicedToArray(_ref, 2),
31
+ warning = _ref2[1];
32
+ return warning;
33
+ })).call(_context, _ref3 => {
34
+ let _ref4 = _slicedToArray(_ref3, 2),
35
+ key = _ref4[0],
36
+ warning = _ref4[1];
37
+ // We might not use a custom warning renderer, so we fall back to null
38
+ // to enable the default warnings to kick in
39
+ const warningElement = props.renderWarning ? props.renderWarning(key, warning) : null;
40
+ // Render a custom warning if one was provided.
41
+ // Custom warnings take precedence over the default warnings
42
+ if (warningElement) return jsxRuntime.jsx(messages.WarningMessage, {
43
+ id: props.id,
44
+ children: warningElement
45
+ }, key);
46
+ const defaultWarningElement = props.renderDefaultWarning ? props.renderDefaultWarning(key, warning) : null;
47
+ // Render a default warning if one was provided.
48
+ // Default warnings take precedence over the known warnings
49
+ if (defaultWarningElement) return jsxRuntime.jsx(messages.WarningMessage, {
50
+ id: props.id,
51
+ children: defaultWarningElement
52
+ }, key);
53
+ // Render nothing in case the warning is not known and no custom warning
54
+ // was returned
55
+ return null;
56
+ })
57
+ });
58
+ };
59
+ FieldWarnings.propTypes = {};
60
+ FieldWarnings.displayName = 'FieldWarnings';
61
+ var FieldWarnings$1 = FieldWarnings;
62
+
63
+ // NOTE: This string will be replaced on build time with the package version.
64
+ var version = "1.0.0";
65
+
66
+ exports["default"] = FieldWarnings$1;
67
+ exports.version = version;
@@ -0,0 +1,62 @@
1
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
2
+ import _pt from 'prop-types';
3
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
4
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
5
+ import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
6
+ import 'react';
7
+ import { WarningMessage } from '@commercetools-uikit/messages';
8
+ import { jsx, Fragment } from '@emotion/react/jsx-runtime';
9
+
10
+ const isObject = obj => typeof obj === 'object';
11
+ const FieldWarnings = props => {
12
+ var _context, _context2;
13
+ if (!props.isVisible) return null;
14
+ if (!props.warnings || !isObject(props.warnings)) return null;
15
+ return jsx(Fragment, {
16
+ children: _mapInstanceProperty(_context = _filterInstanceProperty(_context2 = _Object$entries(props.warnings)
17
+ // Only render warnings which have truthy values, to avoid
18
+ // rendering a warning that has falsy values.
19
+ ).call(_context2, _ref => {
20
+ let _ref2 = _slicedToArray(_ref, 2),
21
+ warning = _ref2[1];
22
+ return warning;
23
+ })).call(_context, _ref3 => {
24
+ let _ref4 = _slicedToArray(_ref3, 2),
25
+ key = _ref4[0],
26
+ warning = _ref4[1];
27
+ // We might not use a custom warning renderer, so we fall back to null
28
+ // to enable the default warnings to kick in
29
+ const warningElement = props.renderWarning ? props.renderWarning(key, warning) : null;
30
+ // Render a custom warning if one was provided.
31
+ // Custom warnings take precedence over the default warnings
32
+ if (warningElement) return jsx(WarningMessage, {
33
+ id: props.id,
34
+ children: warningElement
35
+ }, key);
36
+ const defaultWarningElement = props.renderDefaultWarning ? props.renderDefaultWarning(key, warning) : null;
37
+ // Render a default warning if one was provided.
38
+ // Default warnings take precedence over the known warnings
39
+ if (defaultWarningElement) return jsx(WarningMessage, {
40
+ id: props.id,
41
+ children: defaultWarningElement
42
+ }, key);
43
+ // Render nothing in case the warning is not known and no custom warning
44
+ // was returned
45
+ return null;
46
+ })
47
+ });
48
+ };
49
+ FieldWarnings.propTypes = process.env.NODE_ENV !== "production" ? {
50
+ id: _pt.string,
51
+ warnings: _pt.objectOf(_pt.bool),
52
+ isVisible: _pt.bool,
53
+ renderWarning: _pt.func,
54
+ renderDefaultWarning: _pt.func
55
+ } : {};
56
+ FieldWarnings.displayName = 'FieldWarnings';
57
+ var FieldWarnings$1 = FieldWarnings;
58
+
59
+ // NOTE: This string will be replaced on build time with the package version.
60
+ var version = "1.0.0";
61
+
62
+ export { FieldWarnings$1 as default, version };
@@ -0,0 +1 @@
1
+ export type { TFieldWarningsProps, TFieldWarnings } from "./field-warnings.js";
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ type TWarningRenderer = (key: string, warning?: boolean) => ReactNode;
3
+ export type TFieldWarnings = Record<string, boolean>;
4
+ export type TFieldWarningsProps = {
5
+ id?: string;
6
+ warnings?: TFieldWarnings;
7
+ isVisible?: boolean;
8
+ renderWarning?: TWarningRenderer;
9
+ renderDefaultWarning?: TWarningRenderer;
10
+ };
11
+ declare const FieldWarnings: {
12
+ (props: TFieldWarningsProps): import("@emotion/react/jsx-runtime").JSX.Element | null;
13
+ displayName: string;
14
+ };
15
+ export default FieldWarnings;
@@ -0,0 +1,3 @@
1
+ export { default } from "./field-warnings.js";
2
+ export { default as version } from "./version.js";
3
+ export * from "./export-types.js";
@@ -0,0 +1,2 @@
1
+ declare const _default: "__@UI_KIT_PACKAGE/VERSION_OF_RELEASE__";
2
+ export default _default;
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@commercetools-uikit/field-warnings",
3
+ "description": "Renders warnings based on configuration.",
4
+ "version": "0.0.0-canary-20240117152032",
5
+ "bugs": "https://github.com/commercetools/ui-kit/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/commercetools/ui-kit.git",
9
+ "directory": "packages/components/field-warnings"
10
+ },
11
+ "homepage": "https://uikit.commercetools.com",
12
+ "keywords": [
13
+ "javascript",
14
+ "typescript",
15
+ "design-system",
16
+ "react",
17
+ "uikit"
18
+ ],
19
+ "license": "MIT",
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "sideEffects": false,
24
+ "main": "dist/commercetools-uikit-field-warnings.cjs.js",
25
+ "module": "dist/commercetools-uikit-field-warnings.esm.js",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "dependencies": {
30
+ "@babel/runtime": "^7.20.13",
31
+ "@babel/runtime-corejs3": "^7.20.13",
32
+ "@commercetools-uikit/messages": "0.0.0-canary-20240117152032",
33
+ "@emotion/react": "^11.10.5",
34
+ "@emotion/styled": "^11.10.5",
35
+ "prop-types": "15.8.1"
36
+ },
37
+ "devDependencies": {
38
+ "react": "17.0.2",
39
+ "react-intl": "^6.3.2"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "17.x",
43
+ "react-intl": "6.x"
44
+ }
45
+ }