@openedx/paragon 21.11.0 → 21.11.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/dist/ColorPicker/index.js +48 -18
- package/dist/ColorPicker/index.js.map +1 -1
- package/dist/Dropzone/index.js +1 -2
- package/dist/Dropzone/index.js.map +1 -1
- package/package.json +3 -3
- package/src/ColorPicker/ColorPicker.test.jsx +24 -2
- package/src/ColorPicker/index.jsx +56 -16
- package/src/Dropzone/index.jsx +1 -2
- package/src/SelectableBox/tests/SelectableBoxSet.test.jsx +1 -1
|
@@ -3,7 +3,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
3
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
5
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
-
import React
|
|
6
|
+
import React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import classNames from 'classnames';
|
|
9
9
|
import { HexColorPicker } from 'react-colorful';
|
|
@@ -22,23 +22,52 @@ function ColorPicker(_ref) {
|
|
|
22
22
|
} = _ref;
|
|
23
23
|
const [isOpen, open, close] = useToggle(false);
|
|
24
24
|
const [target, setTarget] = React.useState(null);
|
|
25
|
-
const
|
|
26
|
-
const validateHex = useCallback(input => {
|
|
25
|
+
const colorIsValid = colorToValidate => {
|
|
27
26
|
const hexRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
return hexRegex.test(colorToValidate);
|
|
28
|
+
};
|
|
29
|
+
const formatHexColorString = colorString => {
|
|
30
|
+
if (!colorString.startsWith('#')) {
|
|
31
|
+
return `#${colorString}`.slice(0, 7);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
return colorString.slice(0, 7);
|
|
34
|
+
};
|
|
35
|
+
const [hexValid, setHexValid] = React.useState(() => color === '' || colorIsValid(formatHexColorString(color)));
|
|
36
|
+
const [hexColorString, setHexColorString] = React.useState(() => {
|
|
37
|
+
if (color === '') {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
return formatHexColorString(color);
|
|
41
|
+
});
|
|
42
|
+
const [colorToDisplay, setColorToDisplay] = React.useState(() => {
|
|
43
|
+
const formattedColor = formatHexColorString(color);
|
|
44
|
+
if (colorIsValid(formattedColor)) {
|
|
45
|
+
return formattedColor;
|
|
46
|
+
}
|
|
47
|
+
return '#fff';
|
|
48
|
+
});
|
|
49
|
+
const setValidatedColor = newColor => {
|
|
50
|
+
if (newColor === '') {
|
|
51
|
+
setHexValid(true);
|
|
52
|
+
setColor('');
|
|
53
|
+
setHexColorString('');
|
|
54
|
+
setColorToDisplay('#fff');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const formattedColor = formatHexColorString(newColor);
|
|
58
|
+
if (colorIsValid(formattedColor)) {
|
|
34
59
|
setHexValid(true);
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
setColor(formattedColor);
|
|
61
|
+
setHexColorString(formattedColor);
|
|
62
|
+
setColorToDisplay(formattedColor);
|
|
63
|
+
return;
|
|
37
64
|
}
|
|
38
|
-
|
|
65
|
+
setHexValid(false);
|
|
66
|
+
setHexColorString(formattedColor);
|
|
39
67
|
|
|
40
|
-
|
|
41
|
-
|
|
68
|
+
// ensure the picker value stays in sync with the textbox
|
|
69
|
+
setColor(formattedColor);
|
|
70
|
+
};
|
|
42
71
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
|
|
43
72
|
className: "d-flex"
|
|
44
73
|
}, /*#__PURE__*/React.createElement(OverlayTrigger, {
|
|
@@ -66,8 +95,8 @@ function ColorPicker(_ref) {
|
|
|
66
95
|
textAlign: 'start'
|
|
67
96
|
}
|
|
68
97
|
}, /*#__PURE__*/React.createElement(HexColorPicker, {
|
|
69
|
-
color:
|
|
70
|
-
onChange:
|
|
98
|
+
color: colorToDisplay,
|
|
99
|
+
onChange: setValidatedColor
|
|
71
100
|
}), /*#__PURE__*/React.createElement(Form.Group, {
|
|
72
101
|
className: "pgn__hex-form",
|
|
73
102
|
size: "sm"
|
|
@@ -76,9 +105,10 @@ function ColorPicker(_ref) {
|
|
|
76
105
|
}, "Hex"), /*#__PURE__*/React.createElement(Form.Control, {
|
|
77
106
|
className: "pgn__hex-field",
|
|
78
107
|
isInvalid: !hexValid,
|
|
79
|
-
value:
|
|
80
|
-
onChange: e =>
|
|
81
|
-
"data-testid": "hex-input"
|
|
108
|
+
value: hexColorString,
|
|
109
|
+
onChange: e => setValidatedColor(e.target.value),
|
|
110
|
+
"data-testid": "hex-input",
|
|
111
|
+
spellCheck: "false"
|
|
82
112
|
})), !hexValid && /*#__PURE__*/React.createElement(Form.Control.Feedback, {
|
|
83
113
|
className: "pgn__color-error",
|
|
84
114
|
type: "invalid"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","PropTypes","classNames","HexColorPicker","Button","Form","ModalPopup","OverlayTrigger","Tooltip","useToggle","ColorPicker","_ref","color","setColor","className","size","isOpen","open","close","target","setTarget","useState","colorIsValid","colorToValidate","hexRegex","test","formatHexColorString","colorString","startsWith","slice","hexValid","setHexValid","hexColorString","setHexColorString","colorToDisplay","setColorToDisplay","formattedColor","setValidatedColor","newColor","createElement","Fragment","placement","overlay","id","ref","style","_objectSpread","background","onClick","positionRef","onClose","textAlign","onChange","Group","Label","Control","isInvalid","value","e","spellCheck","Feedback","type","defaultProps","undefined","propTypes","string","func","isRequired","oneOf"],"sources":["../../src/ColorPicker/index.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport { HexColorPicker } from 'react-colorful';\n\nimport Button from '../Button';\nimport Form from '../Form';\nimport ModalPopup from '../Modal/ModalPopup';\nimport { OverlayTrigger } from '../Overlay';\nimport Tooltip from '../Tooltip';\nimport useToggle from '../hooks/useToggle';\n\nfunction ColorPicker({\n color, setColor, className, size,\n}) {\n const [isOpen, open, close] = useToggle(false);\n const [target, setTarget] = React.useState(null);\n\n const colorIsValid = (colorToValidate) => {\n const hexRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;\n return hexRegex.test(colorToValidate);\n };\n\n const formatHexColorString = (colorString) => {\n if (!colorString.startsWith('#')) {\n return `#${colorString}`.slice(0, 7);\n }\n\n return colorString.slice(0, 7);\n };\n\n const [hexValid, setHexValid] = React.useState(() => (color === '' || colorIsValid(formatHexColorString(color))));\n\n const [hexColorString, setHexColorString] = React.useState(() => {\n if (color === '') {\n return '';\n }\n\n return formatHexColorString(color);\n });\n const [colorToDisplay, setColorToDisplay] = React.useState(() => {\n const formattedColor = formatHexColorString(color);\n if (colorIsValid(formattedColor)) {\n return formattedColor;\n }\n\n return '#fff';\n });\n\n const setValidatedColor = (newColor) => {\n if (newColor === '') {\n setHexValid(true);\n setColor('');\n setHexColorString('');\n setColorToDisplay('#fff');\n return;\n }\n\n const formattedColor = formatHexColorString(newColor);\n\n if (colorIsValid(formattedColor)) {\n setHexValid(true);\n setColor(formattedColor);\n setHexColorString(formattedColor);\n setColorToDisplay(formattedColor);\n return;\n }\n\n setHexValid(false);\n setHexColorString(formattedColor);\n\n // ensure the picker value stays in sync with the textbox\n setColor(formattedColor);\n };\n\n return (\n <>\n <span className=\"d-flex\">\n <OverlayTrigger\n placement=\"top\"\n overlay={<Tooltip id=\"color-picker-tooltip\">Color picker</Tooltip>}\n >\n <Button\n ref={setTarget}\n className={classNames(\n className,\n 'pgn__color-picker',\n `pgn__color-picker-${size}`,\n )}\n style={{\n ...(color && hexValid ? { background: `${color}` } : {}),\n }}\n onClick={open}\n />\n </OverlayTrigger>\n </span>\n <ModalPopup\n positionRef={target}\n isOpen={isOpen}\n style={{ background: 'black' }}\n onClose={close}\n >\n <div\n className=\"pgn__color-modal rounded shadow\"\n style={{ textAlign: 'start' }}\n >\n <HexColorPicker color={colorToDisplay} onChange={setValidatedColor} />\n <Form.Group className=\"pgn__hex-form\" size=\"sm\">\n <div>\n <Form.Label className=\"pgn__hex-label\">Hex</Form.Label>\n <Form.Control\n className=\"pgn__hex-field\"\n isInvalid={!hexValid}\n value={hexColorString}\n onChange={(e) => setValidatedColor(e.target.value)}\n data-testid=\"hex-input\"\n spellCheck=\"false\"\n />\n </div>\n {!hexValid && (\n <Form.Control.Feedback\n className=\"pgn__color-error\"\n type=\"invalid\"\n >\n Colors must be in hexadecimal format.\n </Form.Control.Feedback>\n )}\n </Form.Group>\n </div>\n </ModalPopup>\n </>\n );\n}\n\nColorPicker.defaultProps = {\n color: '',\n className: undefined,\n size: 'md',\n};\n\nColorPicker.propTypes = {\n /** A default hex code to preset the picker to display. */\n color: PropTypes.string,\n /** Passing setState function allows parent to alter the color. */\n setColor: PropTypes.func.isRequired,\n /** A class name to append to the base element. */\n className: PropTypes.string,\n /** Size of the color picker */\n size: PropTypes.oneOf(['sm', 'md']),\n};\n\nexport default ColorPicker;\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,cAAc,QAAQ,gBAAgB;AAE/C,OAAOC,MAAM,MAAM,WAAW;AAC9B,OAAOC,IAAI,MAAM,SAAS;AAC1B,OAAOC,UAAU,MAAM,qBAAqB;AAC5C,SAASC,cAAc,QAAQ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CACT,CACK,CACZ,CAAC;AAEP;AAEAnD,WAAW,CAACoD,YAAY,GAAG;EACzBlD,KAAK,EAAE,EAAE;EACTE,SAAS,EAAEiD,SAAS;EACpBhD,IAAI,EAAE;AACR,CAAC;AAEDL,WAAW,CAACsD,SAAS,GAAG;EACtB;EACApD,KAAK,EAAEX,SAAS,CAACgE,MAAM;EACvB;EACApD,QAAQ,EAAEZ,SAAS,CAACiE,IAAI,CAACC,UAAU;EACnC;EACArD,SAAS,EAAEb,SAAS,CAACgE,MAAM;EAC3B;EACAlD,IAAI,EAAEd,SAAS,CAACmE,KAAK,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;AACpC,CAAC;AAED,eAAe1D,WAAW"}
|
package/dist/Dropzone/index.js
CHANGED
|
@@ -177,8 +177,7 @@ function Dropzone(_ref) {
|
|
|
177
177
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
178
178
|
"data-testid": "dropzone-container"
|
|
179
179
|
}, getRootProps({
|
|
180
|
-
className: classNames('pgn__dropzone', {
|
|
181
|
-
className,
|
|
180
|
+
className: classNames('pgn__dropzone', className, {
|
|
182
181
|
'pgn__dropzone-validation-error': isMultipleDragged || errors.length > 0 || isDragReject,
|
|
183
182
|
'pgn__dropzone-active': isDragActive && !isDragReject
|
|
184
183
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","useState","PropTypes","classNames","useDropzone","ErrorCode","fromEvent","useIntl","DragError","GenericError","UploadProgress","DefaultContent","messages","getTypesString","isMultipleTypes","formatBytes","Dropzone","_ref","className","accept","minSize","maxSize","validator","errorMessages","progressVariant","inputComponent","onProcessUpload","onUploadProgress","onUploadCancel","props","_objectWithoutProperties","_excluded","isMultipleDragged","setIsMultipleDragged","errors","setErrors","progress","setProgress","fileName","setFileName","undefined","controller","setController","intl","uploadError","uploadErrorMsg","invalidSizeLess","invalidSizeLessMsg","invalidSizeMore","invalidSizeMoreMsg","invalidType","invalidTypeMsg","multipleDragged","multipleDraggedMsg","onDragEnter","e","files","length","onDragLeave","onDropRejected","map","error","code","FileTooLarge","formatMessage","size","FileTooSmall","FileInvalidType","count","typeString","unexpectedValidationError","handleProgressUpload","progressEvent","percentValue","Math","round","loaded","total","handleUploadError","processUpload","fileData","newController","AbortController","requestConfig","signal","handleError","onDropAccepted","file","customValidationError","formData","FormData","append","name","handleUploadCancel","abort","getRootProps","getInputProps","isDragActive","isDragReject","multiple","maxFiles","disabled","renderContent","createElement","message","Fragment","errorMsgs","variant","percent","onCancel","_extends","defaultProps","Infinity","propTypes","string","objectOf","arrayOf","number","func","isRequired","shape","oneOfType","element","oneOf","node"],"sources":["../../src/Dropzone/index.jsx"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport { useDropzone, ErrorCode } from 'react-dropzone';\nimport { fromEvent } from 'file-selector';\nimport { useIntl } from 'react-intl';\n\nimport DragError from './DragError';\nimport GenericError from './GenericError';\nimport UploadProgress from './UploadProgress';\nimport DefaultContent from './DefaultContent';\nimport messages from './messages';\nimport { getTypesString, isMultipleTypes, formatBytes } from './utils';\n\nfunction Dropzone({\n className, accept, minSize, maxSize, validator,\n errorMessages, progressVariant, inputComponent,\n onProcessUpload, onUploadProgress, onUploadCancel,\n ...props\n}) {\n const [isMultipleDragged, setIsMultipleDragged] = useState(false);\n const [errors, setErrors] = useState([]);\n const [progress, setProgress] = useState(0);\n const [fileName, setFileName] = useState(undefined);\n const [controller, setController] = useState(undefined);\n const intl = useIntl();\n\n const {\n uploadError: uploadErrorMsg,\n invalidSizeLess: invalidSizeLessMsg,\n invalidSizeMore: invalidSizeMoreMsg,\n invalidType: invalidTypeMsg,\n multipleDragged: multipleDraggedMsg,\n } = errorMessages;\n\n const onDragEnter = async (e) => {\n if (errors) {\n setErrors([]);\n }\n const files = await fromEvent(e);\n if (files && files.length > 1) {\n setIsMultipleDragged(true);\n }\n };\n\n const onDragLeave = () => {\n if (isMultipleDragged) {\n setIsMultipleDragged(false);\n }\n };\n\n const onDropRejected = (files) => {\n if (!isMultipleDragged) {\n setErrors(files[0].errors.map(error => {\n switch (error.code) {\n case ErrorCode.FileTooLarge:\n return invalidSizeMoreMsg || intl.formatMessage(messages.invalidSizeMore, { size: formatBytes(maxSize) });\n case ErrorCode.FileTooSmall:\n return invalidSizeLessMsg || intl.formatMessage(messages.invalidSizeLess, { size: formatBytes(minSize) });\n case ErrorCode.FileInvalidType:\n return invalidTypeMsg || intl.formatMessage(\n messages.invalidType,\n { count: isMultipleTypes(accept) ? 2 : 1, typeString: getTypesString(accept) },\n );\n default:\n return intl.formatMessage(messages.unexpectedValidationError);\n }\n }));\n } else {\n setIsMultipleDragged(false);\n }\n };\n\n const handleProgressUpload = (progressEvent) => {\n const percentValue = Math.round((progressEvent.loaded * 100) / progressEvent.total);\n setProgress(percentValue);\n onUploadProgress(percentValue, progressEvent);\n };\n\n const handleUploadError = (error) => {\n // check if request has been canceled before treating the exception as an upload error\n if (error.code !== 'ERR_CANCELED') {\n setProgress(0);\n setErrors([uploadErrorMsg || intl.formatMessage(messages.uploadError)]);\n }\n };\n\n const processUpload = (fileData) => {\n const newController = new AbortController();\n setController(newController);\n\n const requestConfig = {\n onUploadProgress: handleProgressUpload,\n signal: newController.signal,\n };\n\n onProcessUpload({\n fileData,\n requestConfig,\n handleError: handleUploadError,\n });\n };\n\n const onDropAccepted = async (files) => {\n const file = files[0];\n if (validator) {\n const customValidationError = await validator(file);\n if (customValidationError) {\n setErrors([customValidationError]);\n return;\n }\n }\n\n if (errors) {\n setErrors([]);\n }\n\n const formData = new FormData();\n formData.append('file', file);\n setFileName(file.name);\n\n processUpload(formData);\n };\n\n const handleUploadCancel = () => {\n controller.abort();\n setProgress(0);\n onUploadCancel();\n };\n\n const {\n getRootProps,\n getInputProps,\n isDragActive,\n isDragReject,\n } = useDropzone({\n multiple: false,\n maxFiles: 1,\n maxSize,\n minSize,\n onDragLeave,\n onDragEnter,\n onDropRejected,\n onDropAccepted,\n accept,\n disabled: progress && progress !== 100,\n });\n\n const renderContent = () => {\n if (isMultipleDragged) {\n return <DragError message={multipleDraggedMsg || intl.formatMessage(messages.multipleDragged)} />;\n }\n\n if (errors.length > 0) {\n return (\n <>\n <GenericError errorMsgs={errors} />\n {inputComponent || <DefaultContent minSize={minSize} maxSize={maxSize} accept={accept} />}\n </>\n );\n }\n\n if (progress && progress !== 100) {\n return (\n <UploadProgress\n variant={progressVariant}\n percent={progress}\n name={fileName}\n onCancel={handleUploadCancel}\n />\n );\n }\n\n return inputComponent || <DefaultContent minSize={minSize} maxSize={maxSize} accept={accept} />;\n };\n\n return (\n <div\n data-testid=\"dropzone-container\"\n {...getRootProps({\n className: classNames('pgn__dropzone', {\n className,\n 'pgn__dropzone-validation-error': isMultipleDragged || errors.length > 0 || isDragReject,\n 'pgn__dropzone-active': isDragActive && !isDragReject,\n }),\n })}\n {...props}\n >\n <input {...getInputProps()} />\n <div className=\"d-flex flex-column justify-content-around align-items-center w-100\">\n {renderContent()}\n </div>\n </div>\n );\n}\n\nDropzone.defaultProps = {\n className: undefined,\n accept: undefined,\n maxSize: Infinity,\n minSize: 0,\n onUploadProgress: () => {},\n onUploadCancel: () => {},\n errorMessages: {\n invalidType: undefined,\n invalidSizeLess: undefined,\n invalidSizeMore: undefined,\n multipleDragged: undefined,\n uploadError: undefined,\n },\n progressVariant: 'spinner',\n validator: undefined,\n inputComponent: undefined,\n};\n\nDropzone.propTypes = {\n /** Specifies class name to append to the base element. */\n className: PropTypes.string,\n /**\n * Set accepted file types.\n * This should be an object with the keys set to the\n * [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)\n * and the values to an array of file extensions.\n */\n accept: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.string)),\n /** Maximum file size (in bytes). */\n maxSize: PropTypes.number,\n /** Minimum file size (in bytes). */\n minSize: PropTypes.number,\n /**\n * A callback fired each time an upload progress event happens,\n * receives (percentageUploaded, progressEvent) as arguments.\n */\n onUploadProgress: PropTypes.func,\n /** A callback fired upon successful upload, receives Response object as a single argument. */\n onUploadCancel: PropTypes.func,\n /**\n * A function responsible for uploading the file.\n * Receives following object as its only argument\n * {\n * @param {object} fileData - Metadata about the uploaded file.\n * @param {object} requestConfig - Config to pass to `axios` call.\n * @param {function} handleError - Function to communicate to `Dropzone` that file upload resulted in failure,\n * expects `Error` object to be passed as its only argument.\n * }\n */\n onProcessUpload: PropTypes.func.isRequired,\n /**\n * An object containing error messages, following are supported:\n * 1) invalidType - A message to display when file of invalid type is dropped into `Dropzone`.\n * Defaults to 'The file type must be {filType} file / one of {fileTypes} files.'.\n * 2) invalidSizeLess - A message to display when file of size less than minSize value is dropped into `Dropzone`.\n * Defaults to 'File must be larger than {minSize}.'.\n * 3) invalidSizeMore - A message to display when file of size greater than maxSize value is dropped into `Dropzone`.\n * Defaults to 'File must be less than {maxSize}.'.\n * 4) multipleDragged - A message to display when multiple files are dragged over `Dropzone`.\n * 5) uploadError - A message to display in case upload results in an error\n */\n errorMessages: PropTypes.shape({\n invalidType: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n invalidSizeLess: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n invalidSizeMore: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n multipleDragged: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n uploadError: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n }),\n /** Specifies how the upload progress should be displayed, component shows either spinner or a progress bar. */\n progressVariant: PropTypes.oneOf(['spinner', 'bar']),\n /**\n * Custom validation function, receives `File` object as its only argument.\n * Note that this function will be invoked as a last validation step before beginning an upload process.\n */\n validator: PropTypes.func,\n /** A component to display initial state of the `Dropzone`. */\n inputComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),\n};\n\nexport default Dropzone;\n"],"mappings":";;;;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM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SAAS,CAACuH,SAAS,CAAC,CAACvH,SAAS,CAACgH,MAAM,EAAEhH,SAAS,CAACwH,OAAO,CAAC,CAAC;IAC3E9E,WAAW,EAAE1C,SAAS,CAACuH,SAAS,CAAC,CAACvH,SAAS,CAACgH,MAAM,EAAEhH,SAAS,CAACwH,OAAO,CAAC;EACxE,CAAC,CAAC;EACF;EACAlG,eAAe,EAAEtB,SAAS,CAACyH,KAAK,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;EACpD;AACF;AACA;AACA;EACErG,SAAS,EAAEpB,SAAS,CAACoH,IAAI;EACzB;EACA7F,cAAc,EAAEvB,SAAS,CAACuH,SAAS,CAAC,CAACvH,SAAS,CAACoH,IAAI,EAAEpH,SAAS,CAAC0H,IAAI,CAAC;AACtE,CAAC;AAED,eAAe5G,QAAQ"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useState","PropTypes","classNames","useDropzone","ErrorCode","fromEvent","useIntl","DragError","GenericError","UploadProgress","DefaultContent","messages","getTypesString","isMultipleTypes","formatBytes","Dropzone","_ref","className","accept","minSize","maxSize","validator","errorMessages","progressVariant","inputComponent","onProcessUpload","onUploadProgress","onUploadCancel","props","_objectWithoutProperties","_excluded","isMultipleDragged","setIsMultipleDragged","errors","setErrors","progress","setProgress","fileName","setFileName","undefined","controller","setController","intl","uploadError","uploadErrorMsg","invalidSizeLess","invalidSizeLessMsg","invalidSizeMore","invalidSizeMoreMsg","invalidType","invalidTypeMsg","multipleDragged","multipleDraggedMsg","onDragEnter","e","files","length","onDragLeave","onDropRejected","map","error","code","FileTooLarge","formatMessage","size","FileTooSmall","FileInvalidType","count","typeString","unexpectedValidationError","handleProgressUpload","progressEvent","percentValue","Math","round","loaded","total","handleUploadError","processUpload","fileData","newController","AbortController","requestConfig","signal","handleError","onDropAccepted","file","customValidationError","formData","FormData","append","name","handleUploadCancel","abort","getRootProps","getInputProps","isDragActive","isDragReject","multiple","maxFiles","disabled","renderContent","createElement","message","Fragment","errorMsgs","variant","percent","onCancel","_extends","defaultProps","Infinity","propTypes","string","objectOf","arrayOf","number","func","isRequired","shape","oneOfType","element","oneOf","node"],"sources":["../../src/Dropzone/index.jsx"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\nimport { useDropzone, ErrorCode } from 'react-dropzone';\nimport { fromEvent } from 'file-selector';\nimport { useIntl } from 'react-intl';\n\nimport DragError from './DragError';\nimport GenericError from './GenericError';\nimport UploadProgress from './UploadProgress';\nimport DefaultContent from './DefaultContent';\nimport messages from './messages';\nimport { getTypesString, isMultipleTypes, formatBytes } from './utils';\n\nfunction Dropzone({\n className, accept, minSize, maxSize, validator,\n errorMessages, progressVariant, inputComponent,\n onProcessUpload, onUploadProgress, onUploadCancel,\n ...props\n}) {\n const [isMultipleDragged, setIsMultipleDragged] = useState(false);\n const [errors, setErrors] = useState([]);\n const [progress, setProgress] = useState(0);\n const [fileName, setFileName] = useState(undefined);\n const [controller, setController] = useState(undefined);\n const intl = useIntl();\n\n const {\n uploadError: uploadErrorMsg,\n invalidSizeLess: invalidSizeLessMsg,\n invalidSizeMore: invalidSizeMoreMsg,\n invalidType: invalidTypeMsg,\n multipleDragged: multipleDraggedMsg,\n } = errorMessages;\n\n const onDragEnter = async (e) => {\n if (errors) {\n setErrors([]);\n }\n const files = await fromEvent(e);\n if (files && files.length > 1) {\n setIsMultipleDragged(true);\n }\n };\n\n const onDragLeave = () => {\n if (isMultipleDragged) {\n setIsMultipleDragged(false);\n }\n };\n\n const onDropRejected = (files) => {\n if (!isMultipleDragged) {\n setErrors(files[0].errors.map(error => {\n switch (error.code) {\n case ErrorCode.FileTooLarge:\n return invalidSizeMoreMsg || intl.formatMessage(messages.invalidSizeMore, { size: formatBytes(maxSize) });\n case ErrorCode.FileTooSmall:\n return invalidSizeLessMsg || intl.formatMessage(messages.invalidSizeLess, { size: formatBytes(minSize) });\n case ErrorCode.FileInvalidType:\n return invalidTypeMsg || intl.formatMessage(\n messages.invalidType,\n { count: isMultipleTypes(accept) ? 2 : 1, typeString: getTypesString(accept) },\n );\n default:\n return intl.formatMessage(messages.unexpectedValidationError);\n }\n }));\n } else {\n setIsMultipleDragged(false);\n }\n };\n\n const handleProgressUpload = (progressEvent) => {\n const percentValue = Math.round((progressEvent.loaded * 100) / progressEvent.total);\n setProgress(percentValue);\n onUploadProgress(percentValue, progressEvent);\n };\n\n const handleUploadError = (error) => {\n // check if request has been canceled before treating the exception as an upload error\n if (error.code !== 'ERR_CANCELED') {\n setProgress(0);\n setErrors([uploadErrorMsg || intl.formatMessage(messages.uploadError)]);\n }\n };\n\n const processUpload = (fileData) => {\n const newController = new AbortController();\n setController(newController);\n\n const requestConfig = {\n onUploadProgress: handleProgressUpload,\n signal: newController.signal,\n };\n\n onProcessUpload({\n fileData,\n requestConfig,\n handleError: handleUploadError,\n });\n };\n\n const onDropAccepted = async (files) => {\n const file = files[0];\n if (validator) {\n const customValidationError = await validator(file);\n if (customValidationError) {\n setErrors([customValidationError]);\n return;\n }\n }\n\n if (errors) {\n setErrors([]);\n }\n\n const formData = new FormData();\n formData.append('file', file);\n setFileName(file.name);\n\n processUpload(formData);\n };\n\n const handleUploadCancel = () => {\n controller.abort();\n setProgress(0);\n onUploadCancel();\n };\n\n const {\n getRootProps,\n getInputProps,\n isDragActive,\n isDragReject,\n } = useDropzone({\n multiple: false,\n maxFiles: 1,\n maxSize,\n minSize,\n onDragLeave,\n onDragEnter,\n onDropRejected,\n onDropAccepted,\n accept,\n disabled: progress && progress !== 100,\n });\n\n const renderContent = () => {\n if (isMultipleDragged) {\n return <DragError message={multipleDraggedMsg || intl.formatMessage(messages.multipleDragged)} />;\n }\n\n if (errors.length > 0) {\n return (\n <>\n <GenericError errorMsgs={errors} />\n {inputComponent || <DefaultContent minSize={minSize} maxSize={maxSize} accept={accept} />}\n </>\n );\n }\n\n if (progress && progress !== 100) {\n return (\n <UploadProgress\n variant={progressVariant}\n percent={progress}\n name={fileName}\n onCancel={handleUploadCancel}\n />\n );\n }\n\n return inputComponent || <DefaultContent minSize={minSize} maxSize={maxSize} accept={accept} />;\n };\n\n return (\n <div\n data-testid=\"dropzone-container\"\n {...getRootProps({\n className: classNames('pgn__dropzone', className, {\n 'pgn__dropzone-validation-error': isMultipleDragged || errors.length > 0 || isDragReject,\n 'pgn__dropzone-active': isDragActive && !isDragReject,\n }),\n })}\n {...props}\n >\n <input {...getInputProps()} />\n <div className=\"d-flex flex-column justify-content-around align-items-center w-100\">\n {renderContent()}\n </div>\n </div>\n );\n}\n\nDropzone.defaultProps = {\n className: undefined,\n accept: undefined,\n maxSize: Infinity,\n minSize: 0,\n onUploadProgress: () => {},\n onUploadCancel: () => {},\n errorMessages: {\n invalidType: undefined,\n invalidSizeLess: undefined,\n invalidSizeMore: undefined,\n multipleDragged: undefined,\n uploadError: undefined,\n },\n progressVariant: 'spinner',\n validator: undefined,\n inputComponent: undefined,\n};\n\nDropzone.propTypes = {\n /** Specifies class name to append to the base element. */\n className: PropTypes.string,\n /**\n * Set accepted file types.\n * This should be an object with the keys set to the\n * [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)\n * and the values to an array of file extensions.\n */\n accept: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.string)),\n /** Maximum file size (in bytes). */\n maxSize: PropTypes.number,\n /** Minimum file size (in bytes). */\n minSize: PropTypes.number,\n /**\n * A callback fired each time an upload progress event happens,\n * receives (percentageUploaded, progressEvent) as arguments.\n */\n onUploadProgress: PropTypes.func,\n /** A callback fired upon successful upload, receives Response object as a single argument. */\n onUploadCancel: PropTypes.func,\n /**\n * A function responsible for uploading the file.\n * Receives following object as its only argument\n * {\n * @param {object} fileData - Metadata about the uploaded file.\n * @param {object} requestConfig - Config to pass to `axios` call.\n * @param {function} handleError - Function to communicate to `Dropzone` that file upload resulted in failure,\n * expects `Error` object to be passed as its only argument.\n * }\n */\n onProcessUpload: PropTypes.func.isRequired,\n /**\n * An object containing error messages, following are supported:\n * 1) invalidType - A message to display when file of invalid type is dropped into `Dropzone`.\n * Defaults to 'The file type must be {filType} file / one of {fileTypes} files.'.\n * 2) invalidSizeLess - A message to display when file of size less than minSize value is dropped into `Dropzone`.\n * Defaults to 'File must be larger than {minSize}.'.\n * 3) invalidSizeMore - A message to display when file of size greater than maxSize value is dropped into `Dropzone`.\n * Defaults to 'File must be less than {maxSize}.'.\n * 4) multipleDragged - A message to display when multiple files are dragged over `Dropzone`.\n * 5) uploadError - A message to display in case upload results in an error\n */\n errorMessages: PropTypes.shape({\n invalidType: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n invalidSizeLess: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n invalidSizeMore: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n multipleDragged: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n uploadError: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n }),\n /** Specifies how the upload progress should be displayed, component shows either spinner or a progress bar. */\n progressVariant: PropTypes.oneOf(['spinner', 'bar']),\n /**\n * Custom validation function, receives `File` object as its only argument.\n * Note that this function will be invoked as a last validation step before beginning an upload process.\n */\n validator: PropTypes.func,\n /** A component to display initial state of the `Dropzone`. */\n inputComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),\n};\n\nexport default Dropzone;\n"],"mappings":";;;;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,WAAW,EAAEC,SAAS,QAAQ,gBAAgB;AACvD,SAASC,SAAS,QAAQ,eAAe;AACzC,SAASC,OAAO,QAAQ,YAAY;AAEpC,OAAOC,SAAS,MAAM,aAAa;AACnC,OAAOC,YAAY,MAAM,gBAAgB;AACzC,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,QAAQ,MAAM,Y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D;AACF;AACA;AACA;EACErG,SAAS,EAAEpB,SAAS,CAACoH,IAAI;EACzB;EACA7F,cAAc,EAAEvB,SAAS,CAACuH,SAAS,CAAC,CAACvH,SAAS,CAACoH,IAAI,EAAEpH,SAAS,CAAC0H,IAAI,CAAC;AACtE,CAAC;AAED,eAAe5G,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openedx/paragon",
|
|
3
|
-
"version": "21.11.
|
|
3
|
+
"version": "21.11.2",
|
|
4
4
|
"description": "Accessible, responsive UI component library based on Bootstrap.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -100,11 +100,11 @@
|
|
|
100
100
|
"@formatjs/cli": "^5.0.2",
|
|
101
101
|
"@semantic-release/changelog": "^6.0.1",
|
|
102
102
|
"@semantic-release/git": "^10.0.1",
|
|
103
|
-
"@testing-library/jest-dom": "^
|
|
103
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
104
104
|
"@testing-library/react": "^12.1.4",
|
|
105
105
|
"@testing-library/react-hooks": "^8.0.1",
|
|
106
106
|
"@testing-library/user-event": "^13.5.0",
|
|
107
|
-
"@types/jest": "^
|
|
107
|
+
"@types/jest": "^29.5.10",
|
|
108
108
|
"@types/react": "17.0.0",
|
|
109
109
|
"@types/react-dom": "17.0.11",
|
|
110
110
|
"@types/react-test-renderer": "^18.0.0",
|
|
@@ -29,13 +29,35 @@ describe('picker works as expected', () => {
|
|
|
29
29
|
const color = 'wassap';
|
|
30
30
|
const setColor = jest.fn();
|
|
31
31
|
it('validates hex color', async () => {
|
|
32
|
-
|
|
32
|
+
render(<ColorPicker color={color} setColor={setColor} />);
|
|
33
|
+
|
|
33
34
|
await act(async () => {
|
|
34
35
|
await userEvent.click(screen.getByRole('button'));
|
|
35
36
|
});
|
|
37
|
+
expect(screen.queryByTestId('hex-input').value).toEqual('#wassap');
|
|
36
38
|
expect(screen.queryByText('Colors must be in hexadecimal format.')).toBeInTheDocument();
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
await act(async () => {
|
|
41
|
+
await userEvent.clear(screen.getByTestId('hex-input'));
|
|
42
|
+
await userEvent.paste(screen.getByTestId('hex-input'), '32116c');
|
|
43
|
+
});
|
|
44
|
+
expect(screen.queryByTestId('hex-input').value).toEqual('#32116c');
|
|
45
|
+
expect(screen.queryByText('Colors must be in hexadecimal format.')).not.toBeInTheDocument();
|
|
46
|
+
|
|
47
|
+
await act(async () => {
|
|
48
|
+
await userEvent.clear(screen.getByTestId('hex-input'));
|
|
49
|
+
await userEvent.paste(screen.getByTestId('hex-input'), 'yuk');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(screen.queryByTestId('hex-input').value).toEqual('#yuk');
|
|
53
|
+
expect(screen.queryByText('Colors must be in hexadecimal format.')).toBeInTheDocument();
|
|
54
|
+
|
|
55
|
+
await act(async () => {
|
|
56
|
+
await userEvent.clear(screen.getByTestId('hex-input'));
|
|
57
|
+
await userEvent.paste(screen.getByTestId('hex-input'), '#fad');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(screen.queryByTestId('hex-input').value).toEqual('#fad');
|
|
39
61
|
expect(screen.queryByText('Colors must be in hexadecimal format.')).not.toBeInTheDocument();
|
|
40
62
|
});
|
|
41
63
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { HexColorPicker } from 'react-colorful';
|
|
@@ -15,24 +15,63 @@ function ColorPicker({
|
|
|
15
15
|
}) {
|
|
16
16
|
const [isOpen, open, close] = useToggle(false);
|
|
17
17
|
const [target, setTarget] = React.useState(null);
|
|
18
|
-
const [hexValid, setHexValid] = React.useState(true);
|
|
19
18
|
|
|
20
|
-
const
|
|
19
|
+
const colorIsValid = (colorToValidate) => {
|
|
21
20
|
const hexRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
return hexRegex.test(colorToValidate);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const formatHexColorString = (colorString) => {
|
|
25
|
+
if (!colorString.startsWith('#')) {
|
|
26
|
+
return `#${colorString}`.slice(0, 7);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return colorString.slice(0, 7);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const [hexValid, setHexValid] = React.useState(() => (color === '' || colorIsValid(formatHexColorString(color))));
|
|
33
|
+
|
|
34
|
+
const [hexColorString, setHexColorString] = React.useState(() => {
|
|
35
|
+
if (color === '') {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return formatHexColorString(color);
|
|
40
|
+
});
|
|
41
|
+
const [colorToDisplay, setColorToDisplay] = React.useState(() => {
|
|
42
|
+
const formattedColor = formatHexColorString(color);
|
|
43
|
+
if (colorIsValid(formattedColor)) {
|
|
44
|
+
return formattedColor;
|
|
26
45
|
}
|
|
27
|
-
|
|
46
|
+
|
|
47
|
+
return '#fff';
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const setValidatedColor = (newColor) => {
|
|
51
|
+
if (newColor === '') {
|
|
28
52
|
setHexValid(true);
|
|
29
|
-
|
|
30
|
-
|
|
53
|
+
setColor('');
|
|
54
|
+
setHexColorString('');
|
|
55
|
+
setColorToDisplay('#fff');
|
|
56
|
+
return;
|
|
31
57
|
}
|
|
32
|
-
}, [setColor]);
|
|
33
58
|
|
|
34
|
-
|
|
35
|
-
|
|
59
|
+
const formattedColor = formatHexColorString(newColor);
|
|
60
|
+
|
|
61
|
+
if (colorIsValid(formattedColor)) {
|
|
62
|
+
setHexValid(true);
|
|
63
|
+
setColor(formattedColor);
|
|
64
|
+
setHexColorString(formattedColor);
|
|
65
|
+
setColorToDisplay(formattedColor);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setHexValid(false);
|
|
70
|
+
setHexColorString(formattedColor);
|
|
71
|
+
|
|
72
|
+
// ensure the picker value stays in sync with the textbox
|
|
73
|
+
setColor(formattedColor);
|
|
74
|
+
};
|
|
36
75
|
|
|
37
76
|
return (
|
|
38
77
|
<>
|
|
@@ -65,16 +104,17 @@ function ColorPicker({
|
|
|
65
104
|
className="pgn__color-modal rounded shadow"
|
|
66
105
|
style={{ textAlign: 'start' }}
|
|
67
106
|
>
|
|
68
|
-
<HexColorPicker color={
|
|
107
|
+
<HexColorPicker color={colorToDisplay} onChange={setValidatedColor} />
|
|
69
108
|
<Form.Group className="pgn__hex-form" size="sm">
|
|
70
109
|
<div>
|
|
71
110
|
<Form.Label className="pgn__hex-label">Hex</Form.Label>
|
|
72
111
|
<Form.Control
|
|
73
112
|
className="pgn__hex-field"
|
|
74
113
|
isInvalid={!hexValid}
|
|
75
|
-
value={
|
|
76
|
-
onChange={(e) =>
|
|
114
|
+
value={hexColorString}
|
|
115
|
+
onChange={(e) => setValidatedColor(e.target.value)}
|
|
77
116
|
data-testid="hex-input"
|
|
117
|
+
spellCheck="false"
|
|
78
118
|
/>
|
|
79
119
|
</div>
|
|
80
120
|
{!hexValid && (
|
package/src/Dropzone/index.jsx
CHANGED
|
@@ -178,8 +178,7 @@ function Dropzone({
|
|
|
178
178
|
<div
|
|
179
179
|
data-testid="dropzone-container"
|
|
180
180
|
{...getRootProps({
|
|
181
|
-
className: classNames('pgn__dropzone', {
|
|
182
|
-
className,
|
|
181
|
+
className: classNames('pgn__dropzone', className, {
|
|
183
182
|
'pgn__dropzone-validation-error': isMultipleDragged || errors.length > 0 || isDragReject,
|
|
184
183
|
'pgn__dropzone-active': isDragActive && !isDragReject,
|
|
185
184
|
}),
|