@sprinklrjs/spaceweb 14.14.1 → 14.14.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/color-picker/CustomColorSelector.js +25 -15
- package/color-picker/constants.d.ts +3 -0
- package/color-picker/constants.js +3 -1
- package/date-picker/StatelessDatePicker.js +10 -8
- package/esm/color-picker/CustomColorSelector.js +26 -16
- package/esm/color-picker/constants.d.ts +3 -0
- package/esm/color-picker/constants.js +2 -0
- package/esm/date-picker/StatelessDatePicker.js +10 -8
- package/esm/helpers/colors.d.ts +1 -0
- package/esm/helpers/colors.js +14 -2
- package/helpers/colors.d.ts +1 -0
- package/helpers/colors.js +16 -3
- package/package.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -10,6 +10,7 @@ var stack_1 = require("../stack");
|
|
|
10
10
|
var box_1 = require("../box");
|
|
11
11
|
var colors_1 = require("../helpers/colors");
|
|
12
12
|
var transparentBackground_1 = tslib_1.__importDefault(require("../icon/components/transparentBackground"));
|
|
13
|
+
var constants_1 = require("./constants");
|
|
13
14
|
var CustomPointer = function () { return ((0, jsx_runtime_1.jsx)(box_1.Box, { style: function (_a) {
|
|
14
15
|
var rtlCompatible = _a.rtlCompatible;
|
|
15
16
|
return rtlCompatible({ transform: 'translate(-50%, -2px)' });
|
|
@@ -64,6 +65,11 @@ var CustomEditableInput = function (_a) {
|
|
|
64
65
|
// @ts-ignore -- @types/react-color doesn't properly include types for input
|
|
65
66
|
var input = editableInput.input;
|
|
66
67
|
var fireChange = function () {
|
|
68
|
+
var inputValue = input.value;
|
|
69
|
+
if (inputValue === String(value))
|
|
70
|
+
return;
|
|
71
|
+
if (label === 'Hex' && (0, colors_1.normalizeHex)(inputValue) === (0, colors_1.normalizeHex)(String(value)))
|
|
72
|
+
return;
|
|
67
73
|
onChange(typedValue.current);
|
|
68
74
|
};
|
|
69
75
|
var keydownHandler = function (event) {
|
|
@@ -76,16 +82,15 @@ var CustomEditableInput = function (_a) {
|
|
|
76
82
|
input.removeEventListener('blur', fireChange);
|
|
77
83
|
input.removeEventListener('keydown', keydownHandler);
|
|
78
84
|
};
|
|
79
|
-
}, [editableInput, label, onChange]);
|
|
85
|
+
}, [editableInput, label, onChange, value]);
|
|
80
86
|
return ((0, jsx_runtime_1.jsx)(common_1.EditableInput, { style: EDITABLE_INPUT_STYLES, label: label, value: value, onChange: handleChange, ref: setInput }));
|
|
81
87
|
};
|
|
82
88
|
function getNumberWithFallback(input, fallback) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return parseInt(input);
|
|
89
|
+
if (fallback === void 0) { fallback = 0; }
|
|
90
|
+
var trimmedInput = input === null || input === void 0 ? void 0 : input.trim();
|
|
91
|
+
if (!trimmedInput || Number.isNaN(+trimmedInput))
|
|
92
|
+
return fallback;
|
|
93
|
+
return parseInt(trimmedInput);
|
|
89
94
|
}
|
|
90
95
|
var ColorPickerComponent = function (_props) {
|
|
91
96
|
// react-color intercepts the onChange function, wraps the data, and forwards it accordingly
|
|
@@ -99,8 +104,9 @@ var ColorPickerComponent = function (_props) {
|
|
|
99
104
|
// color which cause a flickering issue
|
|
100
105
|
//https://github.com/casesandberg/react-color/blob/bc9a0e1dc5d11b06c511a8e02a95bd85c7129f4b/src/components/sketch/SketchFields.js#L51
|
|
101
106
|
var _a = rgb !== null && rgb !== void 0 ? rgb : {}, r = _a.r, g = _a.g, b = _a.b, a = _a.a;
|
|
107
|
+
var hexInput = (_hex === null || _hex === void 0 ? void 0 : _hex.toLowerCase()) === 'transparent' ? '#000000' : _hex;
|
|
102
108
|
// react-color doesn't support alpha hexes, so we need to insert it ourselves
|
|
103
|
-
var hex = (0, colors_1.normalizeHexWithAlpha)(
|
|
109
|
+
var hex = (0, colors_1.normalizeHexWithAlpha)(hexInput, a);
|
|
104
110
|
var handleHueChange = (0, react_1.useCallback)(function (data) {
|
|
105
111
|
// If alpha was zero and the saturation/lightness is changed, reset alpha to full
|
|
106
112
|
if ('a' in data && data.a === 0) {
|
|
@@ -113,15 +119,19 @@ var ColorPickerComponent = function (_props) {
|
|
|
113
119
|
// react-color emitted data is very dynamic and uses properties from labels
|
|
114
120
|
if ('Hex' in data) {
|
|
115
121
|
var newHex = data.Hex;
|
|
116
|
-
|
|
122
|
+
if (newHex.toLowerCase() === 'transparent' && hex !== constants_1.TRANSPARENT_HEX) {
|
|
123
|
+
onChange(constants_1.TRANSPARENT_RGBA);
|
|
124
|
+
onChangeComplete({ rgb: constants_1.TRANSPARENT_RGBA });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (!(0, colors_1.isValidHex)(newHex))
|
|
128
|
+
return;
|
|
129
|
+
var parsedRgba = (0, colors_1.hexToRgb)(newHex);
|
|
117
130
|
var newRgba = enableAlphaSelector ? parsedRgba : tslib_1.__assign(tslib_1.__assign({}, parsedRgba), { a: 1 }); // No alpha values when enableAlphaSelector is disabled
|
|
118
131
|
onChange(newRgba);
|
|
119
|
-
|
|
120
|
-
// CustomPicker HOC takes care that onChange is invoked with correct values in case of invalid value of rgba.
|
|
121
|
-
if ((0, colors_1.isValidHex)(newHex))
|
|
122
|
-
onChangeComplete({ rgb: newRgba });
|
|
132
|
+
onChangeComplete({ rgb: newRgba });
|
|
123
133
|
}
|
|
124
|
-
else if (
|
|
134
|
+
else if ('R' in data || 'G' in data || 'B' in data || 'A' in data) {
|
|
125
135
|
var _a = tslib_1.__read(Object.keys(data), 1), changedKey = _a[0];
|
|
126
136
|
// Reset alpha IF:
|
|
127
137
|
// Changed value is R/G/B AND current alpha is 0 AND new value is different from old value
|
|
@@ -135,7 +145,7 @@ var ColorPickerComponent = function (_props) {
|
|
|
135
145
|
onChange(newRgba);
|
|
136
146
|
onChangeComplete({ rgb: newRgba });
|
|
137
147
|
}
|
|
138
|
-
}, [onChange, onChangeComplete, enableAlphaSelector, r, g, b, a]);
|
|
148
|
+
}, [onChange, onChangeComplete, enableAlphaSelector, r, g, b, a, hex]);
|
|
139
149
|
return ((0, jsx_runtime_1.jsxs)(stack_1.Stack, tslib_1.__assign({ direction: "vertical", gap: 4 }, { children: [renderColorSuggestionPanel ? renderColorSuggestionPanel(hex) : null, (0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ className: "relative w-full h-32 rounded-16 overflow-hidden", style: { height: '150px' } }, { children: (0, jsx_runtime_1.jsx)(common_1.Saturation, tslib_1.__assign({}, props, { onChange: handleHueChange })) })), (0, jsx_runtime_1.jsxs)(stack_1.Stack, tslib_1.__assign({ direction: "vertical", gap: 2 }, { children: [(0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ className: "flex gap-2 justify-between ml-2" }, { children: (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "flex flex-col items-start gap-2" }, { children: [(0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "flex items-center gap-2" }, { children: [(0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ className: "relative h-3", style: { width: enableAlphaSelector ? '261px' : '228px' } }, { children: (0, jsx_runtime_1.jsx)(common_1.Hue, tslib_1.__assign({ pointer: CustomPointer, radius: "24px" }, props, { onChange: handleHueChange })) })), (0, jsx_runtime_1.jsx)(exports.ColorPreview, { color: rgb })] })), enableAlphaSelector ? ((0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ className: "relative h-3", style: { width: '261px' } }, { children: (0, jsx_runtime_1.jsx)(common_1.Alpha, tslib_1.__assign({ pointer: CustomPointer, radius: "24px", style: { container: { margin: 0 } } }, props)) }))) : null] })) })), (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "grid w-full gap-2",
|
|
140
150
|
// 5 columns with alpha, 4 columns without
|
|
141
151
|
style: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RGBColor } from 'react-color';
|
|
1
2
|
export declare const GRADIENT_TYPE: {
|
|
2
3
|
LINEAR: string;
|
|
3
4
|
RADIAL: string;
|
|
@@ -12,3 +13,5 @@ export declare const COLOR_TYPE: {
|
|
|
12
13
|
readonly GRADIENT: "gradient";
|
|
13
14
|
};
|
|
14
15
|
export declare const SWATCHES_PER_ROW = 10;
|
|
16
|
+
export declare const TRANSPARENT_HEX = "#00000000";
|
|
17
|
+
export declare const TRANSPARENT_RGBA: RGBColor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SWATCHES_PER_ROW = exports.COLOR_TYPE = exports.TAB_IDS = exports.GRADIENT_TYPE = void 0;
|
|
3
|
+
exports.TRANSPARENT_RGBA = exports.TRANSPARENT_HEX = exports.SWATCHES_PER_ROW = exports.COLOR_TYPE = exports.TAB_IDS = exports.GRADIENT_TYPE = void 0;
|
|
4
4
|
exports.GRADIENT_TYPE = {
|
|
5
5
|
LINEAR: 'linear',
|
|
6
6
|
RADIAL: 'radial',
|
|
@@ -11,3 +11,5 @@ exports.COLOR_TYPE = {
|
|
|
11
11
|
GRADIENT: 'gradient',
|
|
12
12
|
};
|
|
13
13
|
exports.SWATCHES_PER_ROW = 10;
|
|
14
|
+
exports.TRANSPARENT_HEX = '#00000000';
|
|
15
|
+
exports.TRANSPARENT_RGBA = { r: 0, g: 0, b: 0, a: 0 };
|
|
@@ -27,9 +27,9 @@ var themeHelpers_1 = require("../helpers/themeHelpers");
|
|
|
27
27
|
var style_1 = require("../style");
|
|
28
28
|
// eslint-disable-next-line max-statements -- required for function component
|
|
29
29
|
var StatelessDatePicker = function (_props) {
|
|
30
|
-
var _a, _b, _c;
|
|
30
|
+
var _a, _b, _c, _d;
|
|
31
31
|
var theme = (0, style_1.useStyle)().theme;
|
|
32
|
-
var
|
|
32
|
+
var _e = (0, context_1.useContextualFormProps)(_props), onChange = _e.onChange, onBlur = _e.onBlur, _f = _e.adapter, adapter = _f === void 0 ? date_fns_adapter_1.default : _f, _g = _e.size, size = _g === void 0 ? (0, themeHelpers_1.getDefaultSize)(theme) : _g, _h = _e.formatString, formatString = _h === void 0 ? constants_1.DEFAULT_FORMAT_STRING : _h, _j = _e.isOpen, isOpen = _j === void 0 ? false : _j, onFocus = _e.onFocus, clearable = _e.clearable, _displayValueAtRangeIndex = _e.displayValueAtRangeIndex, _k = _e.variant, variant = _k === void 0 ? 'default' : _k, overrides = _e.overrides, intent = _e.intent, _value = _e.value, formatDisplayValue = _e.formatDisplayValue, _l = _e.autoSizeInput, autoSizeInput = _l === void 0 ? false : _l, weekStartsOn = _e.weekStartsOn, _m = _e.timezone, timezone = _m === void 0 ? (0, getSystemTzName_1.getSystemTzName)() : _m, _o = _e.showTimezone, showTimezone = _o === void 0 ? false : _o, timezoneOptions = _e.timezoneOptions, props = tslib_1.__rest(_e, ["onChange", "onBlur", "adapter", "size", "formatString", "isOpen", "onFocus", "clearable", "displayValueAtRangeIndex", "variant", "overrides", "intent", "value", "formatDisplayValue", "autoSizeInput", "weekStartsOn", "timezone", "showTimezone", "timezoneOptions"]);
|
|
33
33
|
var locale = (0, locale_1.useLocale)();
|
|
34
34
|
var dateHelpers = React.useMemo(function () { return new date_helpers_1.default(adapter); }, [adapter]);
|
|
35
35
|
var dateFnsLocale = React.useMemo(function () { return (0, utils_1.prepareLocale)(props.locale, { weekStartsOn: weekStartsOn }); }, [weekStartsOn, props.locale]);
|
|
@@ -44,8 +44,8 @@ var StatelessDatePicker = function (_props) {
|
|
|
44
44
|
}, [_value, timezone, timezoneOptions]);
|
|
45
45
|
// this state is required for a11y of calendar, this will be set to true when user first press down arrow key on opened calendar
|
|
46
46
|
// and we will set this to false when calendar will be closed.
|
|
47
|
-
var
|
|
48
|
-
var
|
|
47
|
+
var _p = tslib_1.__read(React.useState(false), 2), autoFocusCalendar = _p[0], setAutoFocusCalendar = _p[1];
|
|
48
|
+
var _q = tslib_1.__read(React.useState(false), 2), error = _q[0], setError = _q[1];
|
|
49
49
|
React.useEffect(function () {
|
|
50
50
|
var _a = (0, utils_2.getMinMaxDateInTimezone)({
|
|
51
51
|
maxDate: props.maxDate,
|
|
@@ -61,7 +61,9 @@ var StatelessDatePicker = function (_props) {
|
|
|
61
61
|
}
|
|
62
62
|
}, [value, props.minDate, props.maxDate, dateHelpers, timezone, timezoneOptions]);
|
|
63
63
|
var screenReaderMsgId = (0, useUniqueId_1.default)();
|
|
64
|
-
var
|
|
64
|
+
var screenReaderMsgDescribedById = "datepicker--screenreader--message--input-".concat(screenReaderMsgId);
|
|
65
|
+
var baseAriaDescribedBy = (_a = props['aria-describedby']) !== null && _a !== void 0 ? _a : '';
|
|
66
|
+
var ariaDescribedBy = "".concat(screenReaderMsgDescribedById, " ").concat(baseAriaDescribedBy).trim();
|
|
65
67
|
var defaultFormatDisplayValue = React.useCallback(function (date) {
|
|
66
68
|
var normalizedFormatString = (0, utils_1.normalizeDashes)(formatString);
|
|
67
69
|
if (formatDisplayValue) {
|
|
@@ -140,11 +142,11 @@ var StatelessDatePicker = function (_props) {
|
|
|
140
142
|
var _r = tslib_1.__read((0, overrides_1.useOverrides)(mergedOverrides === null || mergedOverrides === void 0 ? void 0 : mergedOverrides.Input, DatePickerInput_1.default), 2), InputComponent = _r[0], inputProps = _r[1];
|
|
141
143
|
var _s = tslib_1.__read((0, overrides_1.useOverrides)(mergedOverrides === null || mergedOverrides === void 0 ? void 0 : mergedOverrides.Popover, popover_2.Popover), 2), PopoverComponent = _s[0], popoverProps = _s[1];
|
|
142
144
|
var _t = tslib_1.__read((0, overrides_1.useOverrides)(mergedOverrides === null || mergedOverrides === void 0 ? void 0 : mergedOverrides.InputWrapper, styled_components_1.StyledInputWrapper), 2), InputWrapper = _t[0], inputWrapperProps = _t[1];
|
|
143
|
-
var placeholder = (
|
|
145
|
+
var placeholder = (_b = props.placeholder) !== null && _b !== void 0 ? _b : formatString.toLowerCase();
|
|
144
146
|
// if calendar is close, open it on click otherwise close the calendar
|
|
145
147
|
var popoverHandleClick = isOpen ? onBlur : onFocus;
|
|
146
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PopoverComponent, tslib_1.__assign({ accessibilityType: "none", focusLock: true, returnFocus: true, mountNode: props.mountNode, placement: popover_1.PLACEMENT.auto, isOpen: isOpen, onClickOutside: onClose, onEsc: onClose, showArrow: false, triggerType: "click", onClick: props.disabled ? noop_1.default : popoverHandleClick, content: (0, jsx_runtime_1.jsx)(DatePickerContent_1.DatePickerContent, tslib_1.__assign({}, props, { value: value, onChange: handleDateChange, overrides: mergedOverrides, autoFocusCalendar: autoFocusCalendar, onClose: onClose, formatString: formatString, adapter: adapter, locale: dateFnsLocale, showTimezone: showTimezone, timezone: timezone, timezoneOptions: timezoneOptions, formatDisplayValue: defaultFormatDisplayValue })) }, popoverProps, { children: (0, jsx_runtime_1.jsx)(InputWrapper, tslib_1.__assign({}, inputWrapperProps, { children: (0, jsx_runtime_1.jsx)(InputComponent, tslib_1.__assign({ id: props.id, "aria-disabled": props.disabled, "aria-label": (
|
|
148
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PopoverComponent, tslib_1.__assign({ accessibilityType: "none", focusLock: true, returnFocus: true, mountNode: props.mountNode, placement: popover_1.PLACEMENT.auto, isOpen: isOpen, onClickOutside: onClose, onEsc: onClose, showArrow: false, triggerType: "click", onClick: props.disabled ? noop_1.default : popoverHandleClick, content: (0, jsx_runtime_1.jsx)(DatePickerContent_1.DatePickerContent, tslib_1.__assign({}, props, { value: value, onChange: handleDateChange, overrides: mergedOverrides, autoFocusCalendar: autoFocusCalendar, onClose: onClose, formatString: formatString, adapter: adapter, locale: dateFnsLocale, showTimezone: showTimezone, timezone: timezone, timezoneOptions: timezoneOptions, formatDisplayValue: defaultFormatDisplayValue })) }, popoverProps, { children: (0, jsx_runtime_1.jsx)(InputWrapper, tslib_1.__assign({}, inputWrapperProps, { children: (0, jsx_runtime_1.jsx)(InputComponent, tslib_1.__assign({ id: props.id, "aria-disabled": props.disabled, "aria-label": (_c = props['aria-label']) !== null && _c !== void 0 ? _c : locale.timeRangePicker.ariaLabel, "aria-describedby": ariaDescribedBy, "aria-labelledby": props['aria-labelledby'], "aria-invalid": props['aria-invalid'], "aria-errormessage": props['aria-errormessage'], "aria-required": (_d = props.required) !== null && _d !== void 0 ? _d : props['aria-required'], disabled: props.disabled, size: size, variant: variant, intent: error ? 'error' : intent, value: displayValue,
|
|
147
149
|
// onFocus={onFocus}
|
|
148
|
-
onKeyDown: handleKeyDown, onChange: handleInputChange, placeholder: placeholder, required: props.required, clearable: clearable, isOpen: isOpen, autoSizeInput: autoSizeInput }, inputProps)) })) })), (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "relative" }, { children: [(0, jsx_runtime_1.jsx)(typography_1.Typography, tslib_1.__assign({ id:
|
|
150
|
+
onKeyDown: handleKeyDown, onChange: handleInputChange, placeholder: placeholder, required: props.required, clearable: clearable, isOpen: isOpen, autoSizeInput: autoSizeInput }, inputProps)) })) })), (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "relative" }, { children: [(0, jsx_runtime_1.jsx)(typography_1.Typography, tslib_1.__assign({ id: screenReaderMsgDescribedById, className: "sr-only" }, { children: locale.timeRangePicker.screenReaderMessageInput })), (0, jsx_runtime_1.jsx)(typography_1.Typography, tslib_1.__assign({ "aria-live": "assertive", className: "sr-only" }, { children: dateAriaLabel }))] }))] }));
|
|
149
151
|
};
|
|
150
152
|
exports.StatelessDatePicker = StatelessDatePicker;
|
|
@@ -5,8 +5,9 @@ import { CustomPicker } from 'react-color';
|
|
|
5
5
|
import { Alpha, EditableInput, Hue, Saturation } from 'react-color/lib/components/common';
|
|
6
6
|
import { Stack } from '../stack';
|
|
7
7
|
import { Box } from '../box';
|
|
8
|
-
import { hexToRgb, isValidHex, normalizeHexWithAlpha } from '../helpers/colors';
|
|
8
|
+
import { hexToRgb, isValidHex, normalizeHexWithAlpha, normalizeHex } from '../helpers/colors';
|
|
9
9
|
import TransparentBackground from '../icon/components/transparentBackground';
|
|
10
|
+
import { TRANSPARENT_HEX, TRANSPARENT_RGBA } from './constants';
|
|
10
11
|
var CustomPointer = function () { return (_jsx(Box, { style: function (_a) {
|
|
11
12
|
var rtlCompatible = _a.rtlCompatible;
|
|
12
13
|
return rtlCompatible({ transform: 'translate(-50%, -2px)' });
|
|
@@ -60,6 +61,11 @@ var CustomEditableInput = function (_a) {
|
|
|
60
61
|
// @ts-ignore -- @types/react-color doesn't properly include types for input
|
|
61
62
|
var input = editableInput.input;
|
|
62
63
|
var fireChange = function () {
|
|
64
|
+
var inputValue = input.value;
|
|
65
|
+
if (inputValue === String(value))
|
|
66
|
+
return;
|
|
67
|
+
if (label === 'Hex' && normalizeHex(inputValue) === normalizeHex(String(value)))
|
|
68
|
+
return;
|
|
63
69
|
onChange(typedValue.current);
|
|
64
70
|
};
|
|
65
71
|
var keydownHandler = function (event) {
|
|
@@ -72,16 +78,15 @@ var CustomEditableInput = function (_a) {
|
|
|
72
78
|
input.removeEventListener('blur', fireChange);
|
|
73
79
|
input.removeEventListener('keydown', keydownHandler);
|
|
74
80
|
};
|
|
75
|
-
}, [editableInput, label, onChange]);
|
|
81
|
+
}, [editableInput, label, onChange, value]);
|
|
76
82
|
return (_jsx(EditableInput, { style: EDITABLE_INPUT_STYLES, label: label, value: value, onChange: handleChange, ref: setInput }));
|
|
77
83
|
};
|
|
78
84
|
function getNumberWithFallback(input, fallback) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return parseInt(input);
|
|
85
|
+
if (fallback === void 0) { fallback = 0; }
|
|
86
|
+
var trimmedInput = input === null || input === void 0 ? void 0 : input.trim();
|
|
87
|
+
if (!trimmedInput || Number.isNaN(+trimmedInput))
|
|
88
|
+
return fallback;
|
|
89
|
+
return parseInt(trimmedInput);
|
|
85
90
|
}
|
|
86
91
|
var ColorPickerComponent = function (_props) {
|
|
87
92
|
// react-color intercepts the onChange function, wraps the data, and forwards it accordingly
|
|
@@ -95,8 +100,9 @@ var ColorPickerComponent = function (_props) {
|
|
|
95
100
|
// color which cause a flickering issue
|
|
96
101
|
//https://github.com/casesandberg/react-color/blob/bc9a0e1dc5d11b06c511a8e02a95bd85c7129f4b/src/components/sketch/SketchFields.js#L51
|
|
97
102
|
var _a = rgb !== null && rgb !== void 0 ? rgb : {}, r = _a.r, g = _a.g, b = _a.b, a = _a.a;
|
|
103
|
+
var hexInput = (_hex === null || _hex === void 0 ? void 0 : _hex.toLowerCase()) === 'transparent' ? '#000000' : _hex;
|
|
98
104
|
// react-color doesn't support alpha hexes, so we need to insert it ourselves
|
|
99
|
-
var hex = normalizeHexWithAlpha(
|
|
105
|
+
var hex = normalizeHexWithAlpha(hexInput, a);
|
|
100
106
|
var handleHueChange = useCallback(function (data) {
|
|
101
107
|
// If alpha was zero and the saturation/lightness is changed, reset alpha to full
|
|
102
108
|
if ('a' in data && data.a === 0) {
|
|
@@ -109,15 +115,19 @@ var ColorPickerComponent = function (_props) {
|
|
|
109
115
|
// react-color emitted data is very dynamic and uses properties from labels
|
|
110
116
|
if ('Hex' in data) {
|
|
111
117
|
var newHex = data.Hex;
|
|
112
|
-
|
|
118
|
+
if (newHex.toLowerCase() === 'transparent' && hex !== TRANSPARENT_HEX) {
|
|
119
|
+
onChange(TRANSPARENT_RGBA);
|
|
120
|
+
onChangeComplete({ rgb: TRANSPARENT_RGBA });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!isValidHex(newHex))
|
|
124
|
+
return;
|
|
125
|
+
var parsedRgba = hexToRgb(newHex);
|
|
113
126
|
var newRgba = enableAlphaSelector ? parsedRgba : __assign(__assign({}, parsedRgba), { a: 1 }); // No alpha values when enableAlphaSelector is disabled
|
|
114
127
|
onChange(newRgba);
|
|
115
|
-
|
|
116
|
-
// CustomPicker HOC takes care that onChange is invoked with correct values in case of invalid value of rgba.
|
|
117
|
-
if (isValidHex(newHex))
|
|
118
|
-
onChangeComplete({ rgb: newRgba });
|
|
128
|
+
onChangeComplete({ rgb: newRgba });
|
|
119
129
|
}
|
|
120
|
-
else if (
|
|
130
|
+
else if ('R' in data || 'G' in data || 'B' in data || 'A' in data) {
|
|
121
131
|
var _a = __read(Object.keys(data), 1), changedKey = _a[0];
|
|
122
132
|
// Reset alpha IF:
|
|
123
133
|
// Changed value is R/G/B AND current alpha is 0 AND new value is different from old value
|
|
@@ -131,7 +141,7 @@ var ColorPickerComponent = function (_props) {
|
|
|
131
141
|
onChange(newRgba);
|
|
132
142
|
onChangeComplete({ rgb: newRgba });
|
|
133
143
|
}
|
|
134
|
-
}, [onChange, onChangeComplete, enableAlphaSelector, r, g, b, a]);
|
|
144
|
+
}, [onChange, onChangeComplete, enableAlphaSelector, r, g, b, a, hex]);
|
|
135
145
|
return (_jsxs(Stack, __assign({ direction: "vertical", gap: 4 }, { children: [renderColorSuggestionPanel ? renderColorSuggestionPanel(hex) : null, _jsx(Box, __assign({ className: "relative w-full h-32 rounded-16 overflow-hidden", style: { height: '150px' } }, { children: _jsx(Saturation, __assign({}, props, { onChange: handleHueChange })) })), _jsxs(Stack, __assign({ direction: "vertical", gap: 2 }, { children: [_jsx(Box, __assign({ className: "flex gap-2 justify-between ml-2" }, { children: _jsxs(Box, __assign({ className: "flex flex-col items-start gap-2" }, { children: [_jsxs(Box, __assign({ className: "flex items-center gap-2" }, { children: [_jsx(Box, __assign({ className: "relative h-3", style: { width: enableAlphaSelector ? '261px' : '228px' } }, { children: _jsx(Hue, __assign({ pointer: CustomPointer, radius: "24px" }, props, { onChange: handleHueChange })) })), _jsx(ColorPreview, { color: rgb })] })), enableAlphaSelector ? (_jsx(Box, __assign({ className: "relative h-3", style: { width: '261px' } }, { children: _jsx(Alpha, __assign({ pointer: CustomPointer, radius: "24px", style: { container: { margin: 0 } } }, props)) }))) : null] })) })), _jsxs(Box, __assign({ className: "grid w-full gap-2",
|
|
136
146
|
// 5 columns with alpha, 4 columns without
|
|
137
147
|
style: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RGBColor } from 'react-color';
|
|
1
2
|
export declare const GRADIENT_TYPE: {
|
|
2
3
|
LINEAR: string;
|
|
3
4
|
RADIAL: string;
|
|
@@ -12,3 +13,5 @@ export declare const COLOR_TYPE: {
|
|
|
12
13
|
readonly GRADIENT: "gradient";
|
|
13
14
|
};
|
|
14
15
|
export declare const SWATCHES_PER_ROW = 10;
|
|
16
|
+
export declare const TRANSPARENT_HEX = "#00000000";
|
|
17
|
+
export declare const TRANSPARENT_RGBA: RGBColor;
|
|
@@ -24,9 +24,9 @@ import { getDefaultSize } from '../helpers/themeHelpers';
|
|
|
24
24
|
import { useStyle } from '../style';
|
|
25
25
|
// eslint-disable-next-line max-statements -- required for function component
|
|
26
26
|
export var StatelessDatePicker = function (_props) {
|
|
27
|
-
var _a, _b, _c;
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
28
|
var theme = useStyle().theme;
|
|
29
|
-
var
|
|
29
|
+
var _e = useContextualFormProps(_props), onChange = _e.onChange, onBlur = _e.onBlur, _f = _e.adapter, adapter = _f === void 0 ? dateFnsAdapter : _f, _g = _e.size, size = _g === void 0 ? getDefaultSize(theme) : _g, _h = _e.formatString, formatString = _h === void 0 ? DEFAULT_FORMAT_STRING : _h, _j = _e.isOpen, isOpen = _j === void 0 ? false : _j, onFocus = _e.onFocus, clearable = _e.clearable, _displayValueAtRangeIndex = _e.displayValueAtRangeIndex, _k = _e.variant, variant = _k === void 0 ? 'default' : _k, overrides = _e.overrides, intent = _e.intent, _value = _e.value, formatDisplayValue = _e.formatDisplayValue, _l = _e.autoSizeInput, autoSizeInput = _l === void 0 ? false : _l, weekStartsOn = _e.weekStartsOn, _m = _e.timezone, timezone = _m === void 0 ? getSystemTzName() : _m, _o = _e.showTimezone, showTimezone = _o === void 0 ? false : _o, timezoneOptions = _e.timezoneOptions, props = __rest(_e, ["onChange", "onBlur", "adapter", "size", "formatString", "isOpen", "onFocus", "clearable", "displayValueAtRangeIndex", "variant", "overrides", "intent", "value", "formatDisplayValue", "autoSizeInput", "weekStartsOn", "timezone", "showTimezone", "timezoneOptions"]);
|
|
30
30
|
var locale = useLocale();
|
|
31
31
|
var dateHelpers = React.useMemo(function () { return new DateHelpers(adapter); }, [adapter]);
|
|
32
32
|
var dateFnsLocale = React.useMemo(function () { return prepareLocale(props.locale, { weekStartsOn: weekStartsOn }); }, [weekStartsOn, props.locale]);
|
|
@@ -41,8 +41,8 @@ export var StatelessDatePicker = function (_props) {
|
|
|
41
41
|
}, [_value, timezone, timezoneOptions]);
|
|
42
42
|
// this state is required for a11y of calendar, this will be set to true when user first press down arrow key on opened calendar
|
|
43
43
|
// and we will set this to false when calendar will be closed.
|
|
44
|
-
var
|
|
45
|
-
var
|
|
44
|
+
var _p = __read(React.useState(false), 2), autoFocusCalendar = _p[0], setAutoFocusCalendar = _p[1];
|
|
45
|
+
var _q = __read(React.useState(false), 2), error = _q[0], setError = _q[1];
|
|
46
46
|
React.useEffect(function () {
|
|
47
47
|
var _a = getMinMaxDateInTimezone({
|
|
48
48
|
maxDate: props.maxDate,
|
|
@@ -58,7 +58,9 @@ export var StatelessDatePicker = function (_props) {
|
|
|
58
58
|
}
|
|
59
59
|
}, [value, props.minDate, props.maxDate, dateHelpers, timezone, timezoneOptions]);
|
|
60
60
|
var screenReaderMsgId = useUniqueId();
|
|
61
|
-
var
|
|
61
|
+
var screenReaderMsgDescribedById = "datepicker--screenreader--message--input-".concat(screenReaderMsgId);
|
|
62
|
+
var baseAriaDescribedBy = (_a = props['aria-describedby']) !== null && _a !== void 0 ? _a : '';
|
|
63
|
+
var ariaDescribedBy = "".concat(screenReaderMsgDescribedById, " ").concat(baseAriaDescribedBy).trim();
|
|
62
64
|
var defaultFormatDisplayValue = React.useCallback(function (date) {
|
|
63
65
|
var normalizedFormatString = normalizeDashes(formatString);
|
|
64
66
|
if (formatDisplayValue) {
|
|
@@ -137,10 +139,10 @@ export var StatelessDatePicker = function (_props) {
|
|
|
137
139
|
var _r = __read(useOverrides(mergedOverrides === null || mergedOverrides === void 0 ? void 0 : mergedOverrides.Input, DatePickerInput), 2), InputComponent = _r[0], inputProps = _r[1];
|
|
138
140
|
var _s = __read(useOverrides(mergedOverrides === null || mergedOverrides === void 0 ? void 0 : mergedOverrides.Popover, Popover), 2), PopoverComponent = _s[0], popoverProps = _s[1];
|
|
139
141
|
var _t = __read(useOverrides(mergedOverrides === null || mergedOverrides === void 0 ? void 0 : mergedOverrides.InputWrapper, StyledInputWrapper), 2), InputWrapper = _t[0], inputWrapperProps = _t[1];
|
|
140
|
-
var placeholder = (
|
|
142
|
+
var placeholder = (_b = props.placeholder) !== null && _b !== void 0 ? _b : formatString.toLowerCase();
|
|
141
143
|
// if calendar is close, open it on click otherwise close the calendar
|
|
142
144
|
var popoverHandleClick = isOpen ? onBlur : onFocus;
|
|
143
|
-
return (_jsxs(_Fragment, { children: [_jsx(PopoverComponent, __assign({ accessibilityType: "none", focusLock: true, returnFocus: true, mountNode: props.mountNode, placement: PLACEMENT.auto, isOpen: isOpen, onClickOutside: onClose, onEsc: onClose, showArrow: false, triggerType: "click", onClick: props.disabled ? _noop : popoverHandleClick, content: _jsx(DatePickerContent, __assign({}, props, { value: value, onChange: handleDateChange, overrides: mergedOverrides, autoFocusCalendar: autoFocusCalendar, onClose: onClose, formatString: formatString, adapter: adapter, locale: dateFnsLocale, showTimezone: showTimezone, timezone: timezone, timezoneOptions: timezoneOptions, formatDisplayValue: defaultFormatDisplayValue })) }, popoverProps, { children: _jsx(InputWrapper, __assign({}, inputWrapperProps, { children: _jsx(InputComponent, __assign({ id: props.id, "aria-disabled": props.disabled, "aria-label": (
|
|
145
|
+
return (_jsxs(_Fragment, { children: [_jsx(PopoverComponent, __assign({ accessibilityType: "none", focusLock: true, returnFocus: true, mountNode: props.mountNode, placement: PLACEMENT.auto, isOpen: isOpen, onClickOutside: onClose, onEsc: onClose, showArrow: false, triggerType: "click", onClick: props.disabled ? _noop : popoverHandleClick, content: _jsx(DatePickerContent, __assign({}, props, { value: value, onChange: handleDateChange, overrides: mergedOverrides, autoFocusCalendar: autoFocusCalendar, onClose: onClose, formatString: formatString, adapter: adapter, locale: dateFnsLocale, showTimezone: showTimezone, timezone: timezone, timezoneOptions: timezoneOptions, formatDisplayValue: defaultFormatDisplayValue })) }, popoverProps, { children: _jsx(InputWrapper, __assign({}, inputWrapperProps, { children: _jsx(InputComponent, __assign({ id: props.id, "aria-disabled": props.disabled, "aria-label": (_c = props['aria-label']) !== null && _c !== void 0 ? _c : locale.timeRangePicker.ariaLabel, "aria-describedby": ariaDescribedBy, "aria-labelledby": props['aria-labelledby'], "aria-invalid": props['aria-invalid'], "aria-errormessage": props['aria-errormessage'], "aria-required": (_d = props.required) !== null && _d !== void 0 ? _d : props['aria-required'], disabled: props.disabled, size: size, variant: variant, intent: error ? 'error' : intent, value: displayValue,
|
|
144
146
|
// onFocus={onFocus}
|
|
145
|
-
onKeyDown: handleKeyDown, onChange: handleInputChange, placeholder: placeholder, required: props.required, clearable: clearable, isOpen: isOpen, autoSizeInput: autoSizeInput }, inputProps)) })) })), _jsxs(Box, __assign({ className: "relative" }, { children: [_jsx(Typography, __assign({ id:
|
|
147
|
+
onKeyDown: handleKeyDown, onChange: handleInputChange, placeholder: placeholder, required: props.required, clearable: clearable, isOpen: isOpen, autoSizeInput: autoSizeInput }, inputProps)) })) })), _jsxs(Box, __assign({ className: "relative" }, { children: [_jsx(Typography, __assign({ id: screenReaderMsgDescribedById, className: "sr-only" }, { children: locale.timeRangePicker.screenReaderMessageInput })), _jsx(Typography, __assign({ "aria-live": "assertive", className: "sr-only" }, { children: dateAriaLabel }))] }))] }));
|
|
146
148
|
};
|
package/esm/helpers/colors.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const isValidHex: (hex: unknown) => string | undefined;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function hexToRgb(_hex: string): RGBColor;
|
|
9
9
|
export declare function RgbToHex({ r, g, b, a }: RGBColor): string;
|
|
10
|
+
export declare function normalizeHex(hex: string): string | undefined;
|
|
10
11
|
/**
|
|
11
12
|
* https://medium.muz.li/the-science-of-color-contrast-an-expert-designers-guide-33e84c41d156
|
|
12
13
|
* https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum#dfn-contrast-ratio
|
package/esm/helpers/colors.js
CHANGED
|
@@ -7,7 +7,7 @@ export var isValidHex = function (hex) {
|
|
|
7
7
|
if (![3, 4, 6, 8].includes(hexVal.length))
|
|
8
8
|
return undefined;
|
|
9
9
|
if (/^[0-9a-f]+$/i.test(hexVal))
|
|
10
|
-
return hexVal;
|
|
10
|
+
return hexVal.toUpperCase();
|
|
11
11
|
return undefined;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
@@ -30,6 +30,18 @@ export function RgbToHex(_a) {
|
|
|
30
30
|
return "#".concat(__spreadArray([r, g, b], __read((a < 1 ? [Math.round(a * 255)] : [])), false).map(function (n) { return (Number.isNaN(n) ? 10 : Math.round(Math.min(Math.max(n, 0), 255))).toString(16).padStart(2, '0'); })
|
|
31
31
|
.join(''));
|
|
32
32
|
}
|
|
33
|
+
export function normalizeHex(hex) {
|
|
34
|
+
if (!isValidHex(hex))
|
|
35
|
+
return undefined;
|
|
36
|
+
var _a = hexToRgb(hex), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
|
|
37
|
+
return "#".concat([r, g, b, Math.round((a !== null && a !== void 0 ? a : 1) * 255)]
|
|
38
|
+
.map(function (n) {
|
|
39
|
+
return Math.round(Math.min(Math.max(n, 0), 255))
|
|
40
|
+
.toString(16)
|
|
41
|
+
.padStart(2, '0');
|
|
42
|
+
})
|
|
43
|
+
.join(''));
|
|
44
|
+
}
|
|
33
45
|
/**
|
|
34
46
|
* https://medium.muz.li/the-science-of-color-contrast-an-expert-designers-guide-33e84c41d156
|
|
35
47
|
* https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum#dfn-contrast-ratio
|
|
@@ -86,7 +98,7 @@ export function noAlphaHex(inputHex) {
|
|
|
86
98
|
return inputHex;
|
|
87
99
|
}
|
|
88
100
|
export function normalizeHexWithAlpha(hex, alpha) {
|
|
89
|
-
if (typeof alpha !== 'number' || alpha === 1 || !hex)
|
|
101
|
+
if (typeof alpha !== 'number' || alpha === 1 || !hex || !isValidHex(hex))
|
|
90
102
|
return hex;
|
|
91
103
|
return (hex +
|
|
92
104
|
Math.floor(alpha * 255)
|
package/helpers/colors.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const isValidHex: (hex: unknown) => string | undefined;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function hexToRgb(_hex: string): RGBColor;
|
|
9
9
|
export declare function RgbToHex({ r, g, b, a }: RGBColor): string;
|
|
10
|
+
export declare function normalizeHex(hex: string): string | undefined;
|
|
10
11
|
/**
|
|
11
12
|
* https://medium.muz.li/the-science-of-color-contrast-an-expert-designers-guide-33e84c41d156
|
|
12
13
|
* https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum#dfn-contrast-ratio
|
package/helpers/colors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeHexWithAlpha = exports.noAlphaHex = exports.HslToRgb = exports.RgbToHsl = exports.getContrastRatio = exports.getRelativeLuminance = exports.RgbToHex = exports.hexToRgb = exports.isValidHex = void 0;
|
|
3
|
+
exports.normalizeHexWithAlpha = exports.noAlphaHex = exports.HslToRgb = exports.RgbToHsl = exports.getContrastRatio = exports.getRelativeLuminance = exports.normalizeHex = exports.RgbToHex = exports.hexToRgb = exports.isValidHex = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var memoize_1 = tslib_1.__importDefault(require("lodash/memoize"));
|
|
6
6
|
var isValidHex = function (hex) {
|
|
@@ -10,7 +10,7 @@ var isValidHex = function (hex) {
|
|
|
10
10
|
if (![3, 4, 6, 8].includes(hexVal.length))
|
|
11
11
|
return undefined;
|
|
12
12
|
if (/^[0-9a-f]+$/i.test(hexVal))
|
|
13
|
-
return hexVal;
|
|
13
|
+
return hexVal.toUpperCase();
|
|
14
14
|
return undefined;
|
|
15
15
|
};
|
|
16
16
|
exports.isValidHex = isValidHex;
|
|
@@ -36,6 +36,19 @@ function RgbToHex(_a) {
|
|
|
36
36
|
.join(''));
|
|
37
37
|
}
|
|
38
38
|
exports.RgbToHex = RgbToHex;
|
|
39
|
+
function normalizeHex(hex) {
|
|
40
|
+
if (!(0, exports.isValidHex)(hex))
|
|
41
|
+
return undefined;
|
|
42
|
+
var _a = hexToRgb(hex), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
|
|
43
|
+
return "#".concat([r, g, b, Math.round((a !== null && a !== void 0 ? a : 1) * 255)]
|
|
44
|
+
.map(function (n) {
|
|
45
|
+
return Math.round(Math.min(Math.max(n, 0), 255))
|
|
46
|
+
.toString(16)
|
|
47
|
+
.padStart(2, '0');
|
|
48
|
+
})
|
|
49
|
+
.join(''));
|
|
50
|
+
}
|
|
51
|
+
exports.normalizeHex = normalizeHex;
|
|
39
52
|
/**
|
|
40
53
|
* https://medium.muz.li/the-science-of-color-contrast-an-expert-designers-guide-33e84c41d156
|
|
41
54
|
* https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum#dfn-contrast-ratio
|
|
@@ -96,7 +109,7 @@ function noAlphaHex(inputHex) {
|
|
|
96
109
|
}
|
|
97
110
|
exports.noAlphaHex = noAlphaHex;
|
|
98
111
|
function normalizeHexWithAlpha(hex, alpha) {
|
|
99
|
-
if (typeof alpha !== 'number' || alpha === 1 || !hex)
|
|
112
|
+
if (typeof alpha !== 'number' || alpha === 1 || !hex || !(0, exports.isValidHex)(hex))
|
|
100
113
|
return hex;
|
|
101
114
|
return (hex +
|
|
102
115
|
Math.floor(alpha * 255)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprinklrjs/spaceweb",
|
|
3
|
-
"version": "14.14.
|
|
3
|
+
"version": "14.14.2",
|
|
4
4
|
"description": "Components for SpaceWeb",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"ts-node": "^10.4.0"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@sprinklrjs/spaceweb-themes": "14.14.
|
|
104
|
+
"@sprinklrjs/spaceweb-themes": "14.14.2",
|
|
105
105
|
"react": ">=17.0.2 <19.0.0",
|
|
106
106
|
"react-dom": ">=17.0.2 <19.0.0"
|
|
107
107
|
}
|