@sprinklrjs/spaceweb 14.15.2 → 14.16.1
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/baseui/timepicker/timepicker.js +5 -5
- package/baseui/timepicker/types.d.ts +5 -0
- package/color-picker/ColorPalette.js +20 -3
- package/color-picker/GradientColorPicker.js +4 -1
- package/color-picker/Swatch.d.ts +3 -1
- package/color-picker/Swatch.js +8 -5
- package/color-picker/handleSwatchGroupKeyDown.d.ts +7 -0
- package/color-picker/handleSwatchGroupKeyDown.js +43 -0
- package/date-picker/DateInput.d.ts +4 -1
- package/date-picker/DateInput.js +7 -5
- package/date-picker/TimeInput.d.ts +6 -1
- package/date-picker/TimeInput.js +2 -2
- package/esm/baseui/timepicker/timepicker.js +5 -5
- package/esm/baseui/timepicker/types.d.ts +5 -0
- package/esm/color-picker/ColorPalette.js +20 -3
- package/esm/color-picker/GradientColorPicker.js +4 -1
- package/esm/color-picker/Swatch.d.ts +3 -1
- package/esm/color-picker/Swatch.js +8 -5
- package/esm/color-picker/handleSwatchGroupKeyDown.d.ts +7 -0
- package/esm/color-picker/handleSwatchGroupKeyDown.js +39 -0
- package/esm/date-picker/DateInput.d.ts +4 -1
- package/esm/date-picker/DateInput.js +7 -5
- package/esm/date-picker/TimeInput.d.ts +6 -1
- package/esm/date-picker/TimeInput.js +2 -2
- package/esm/list/divider.js +1 -1
- package/esm/list/list-item.js +14 -9
- package/esm/locale/en_US.js +3 -0
- package/esm/locale/types.d.ts +3 -0
- package/esm/menu/useKeyboardNavigation.js +10 -3
- package/esm/menu/useStatefulMenu.js +14 -8
- package/esm/modal/modal.js +2 -2
- package/esm/select/overlaySelect/hooks/useOverlaySelectOverrides.js +3 -0
- package/esm/select/selectMenuAdapter/CollapsibleSelectMenu.js +15 -7
- package/esm/select/selectMenuAdapter/NestedSelectMenuAdapter.js +1 -1
- package/esm/select/selectMenuAdapter/SelectMenuAdapter.js +8 -6
- package/esm/select/styled-component.js +4 -6
- package/esm/slider/slider.d.ts +1 -1
- package/esm/slider/slider.js +12 -2
- package/esm/slider/types.d.ts +3 -0
- package/esm/time-range-picker/RangeSelector.js +2 -2
- package/esm/time-range-picker/RangeSelectorContainer.js +1 -1
- package/esm/time-range-picker/types.d.ts +1 -0
- package/esm/time-zone-picker/types.d.ts +1 -0
- package/esm/tooltip/actionable-tooltip.js +2 -1
- package/list/divider.js +1 -1
- package/list/list-item.js +14 -9
- package/locale/en_US.js +3 -0
- package/locale/types.d.ts +3 -0
- package/menu/useKeyboardNavigation.js +10 -3
- package/menu/useStatefulMenu.js +14 -8
- package/modal/modal.js +2 -2
- package/package.json +2 -4
- package/select/overlaySelect/hooks/useOverlaySelectOverrides.js +3 -0
- package/select/selectMenuAdapter/CollapsibleSelectMenu.js +14 -6
- package/select/selectMenuAdapter/NestedSelectMenuAdapter.js +1 -1
- package/select/selectMenuAdapter/SelectMenuAdapter.js +8 -6
- package/select/styled-component.js +4 -6
- package/slider/slider.d.ts +1 -1
- package/slider/slider.js +12 -2
- package/slider/types.d.ts +3 -0
- package/time-range-picker/RangeSelector.js +2 -2
- package/time-range-picker/RangeSelectorContainer.js +1 -1
- package/time-range-picker/types.d.ts +1 -0
- package/time-zone-picker/types.d.ts +1 -0
- package/tooltip/actionable-tooltip.js +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -49,7 +49,7 @@ var TimePicker = /** @class */ (function (_super) {
|
|
|
49
49
|
tslib_1.__extends(TimePicker, _super);
|
|
50
50
|
function TimePicker(props) {
|
|
51
51
|
var _this = _super.call(this, props) || this;
|
|
52
|
-
// @ts-ignore
|
|
52
|
+
// @ts-ignore -- legacy baseui code
|
|
53
53
|
_this.state = { steps: [], value: null };
|
|
54
54
|
_this.onChange = function (params) {
|
|
55
55
|
_this.setState({ value: params.value[0] });
|
|
@@ -170,9 +170,9 @@ var TimePicker = /** @class */ (function (_super) {
|
|
|
170
170
|
var maxDate = _this.props.adapter.toJsDate(max);
|
|
171
171
|
var midnightDate = _this.props.adapter.toJsDate(dayStart);
|
|
172
172
|
return {
|
|
173
|
-
// @ts-expect-error todo(flow->ts)
|
|
173
|
+
// @ts-expect-error todo(flow->ts) -- legacy code from base ui
|
|
174
174
|
start: (minDate - midnightDate) / 1000,
|
|
175
|
-
// @ts-expect-error todo(flow->ts)
|
|
175
|
+
// @ts-expect-error todo(flow->ts) -- legacy code from base ui
|
|
176
176
|
end: (maxDate - midnightDate) / 1000,
|
|
177
177
|
};
|
|
178
178
|
};
|
|
@@ -299,12 +299,12 @@ var TimePicker = /** @class */ (function (_super) {
|
|
|
299
299
|
? _this.buildSelectedOption(_this.props.value, _this.props.format, langCode)
|
|
300
300
|
: _this.state.value;
|
|
301
301
|
var ariaLabel = format === '12' ? timeRangePicker.timePickerAriaLabel12Hour : timeRangePicker.timePickerAriaLabel24Hour;
|
|
302
|
-
return ((0, jsx_runtime_1.jsx)(OverriddenSelect, tslib_1.__assign({
|
|
302
|
+
return ((0, jsx_runtime_1.jsx)(OverriddenSelect, tslib_1.__assign({ disabled: _this.props.disabled, error: _this.props.error, positive: _this.props.positive, size: _this.props.size, placeholder: _this.props.placeholder || defaultPlaceholder, options: _this.state.steps.map(function (n) { return ({
|
|
303
303
|
id: n,
|
|
304
304
|
label: _this.secondsToLabel(n, _this.props.format, langCode),
|
|
305
305
|
}); }), filterOptions: _this.props.creatable ? _this.creatableFilterOptions : undefined, onChange: _this.onChange,
|
|
306
306
|
// if value is defined, it should be an array type
|
|
307
|
-
value: value ? [value] : value, clearable: false, backspaceRemoves: false, valueKey: "label" }, selectProps)));
|
|
307
|
+
value: value ? [value] : value, clearable: false, backspaceRemoves: false, valueKey: "label" }, selectProps, { "aria-label": _this.props['aria-labelledby'] ? undefined : ariaLabel, "aria-labelledby": _this.props['aria-labelledby'], "aria-describedby": _this.props['aria-describedby'], "aria-errormessage": _this.props['aria-errormessage'], required: _this.props.required, id: _this.props.id })));
|
|
308
308
|
} }));
|
|
309
309
|
};
|
|
310
310
|
TimePicker.defaultProps = {
|
|
@@ -40,6 +40,11 @@ export type TimePickerProps<T = Date> = {
|
|
|
40
40
|
* By default the component will clamp the time window and setting this flag will ignore dates.
|
|
41
41
|
*/
|
|
42
42
|
ignoreMinMaxDateComponent?: boolean;
|
|
43
|
+
id?: string;
|
|
44
|
+
'aria-labelledby'?: string;
|
|
45
|
+
'aria-describedby'?: string;
|
|
46
|
+
'aria-errormessage'?: string;
|
|
47
|
+
required?: boolean;
|
|
43
48
|
};
|
|
44
49
|
export type TimePickerState = {
|
|
45
50
|
/** List of times (in seconds) displayed in the dropdown menu. */
|
|
@@ -9,13 +9,19 @@ var grid_1 = require("../grid");
|
|
|
9
9
|
var Swatch_1 = require("./Swatch");
|
|
10
10
|
var locale_1 = require("../locale");
|
|
11
11
|
var overrides_1 = require("../overrides");
|
|
12
|
+
var theme_1 = require("../theme");
|
|
12
13
|
var colors_1 = require("./colors");
|
|
14
|
+
var handleSwatchGroupKeyDown_1 = require("./handleSwatchGroupKeyDown");
|
|
13
15
|
var constants_1 = require("./constants");
|
|
14
16
|
var typography_1 = require("../typography");
|
|
15
17
|
var defaultColorPalette = colors_1.COLOR_PALETTE.flat();
|
|
18
|
+
var getSwatchTabIndex = function (isSelected, index, hasGroupSelection) {
|
|
19
|
+
return isSelected || (!hasGroupSelection && index === 0) ? 0 : -1;
|
|
20
|
+
};
|
|
16
21
|
exports.ColorPalette = (0, react_1.memo)(function (_a) {
|
|
17
22
|
var selectedColor = _a.color, overrides = _a.overrides, onChange = _a.onChange, _colorPalette = _a.colorPalette, _presets = _a.presets, noReset = _a.noReset;
|
|
18
23
|
var locale = (0, locale_1.useLocale)();
|
|
24
|
+
var direction = (0, theme_1.useTheme)().direction;
|
|
19
25
|
var presets = (0, react_1.useMemo)(function () {
|
|
20
26
|
var defaultPreset = {
|
|
21
27
|
label: locale.colorPicker.sprinklrPresets,
|
|
@@ -24,10 +30,21 @@ exports.ColorPalette = (0, react_1.memo)(function (_a) {
|
|
|
24
30
|
return typeof _presets === 'function' ? _presets(defaultPreset) : _presets !== null && _presets !== void 0 ? _presets : [defaultPreset];
|
|
25
31
|
}, [_presets, noReset, locale.colorPicker]);
|
|
26
32
|
var colorPalette = _colorPalette !== null && _colorPalette !== void 0 ? _colorPalette : defaultColorPalette;
|
|
33
|
+
var hasPaletteSelection = colorPalette.some(function (paletteColor) { return selectedColor === paletteColor; });
|
|
27
34
|
var _b = tslib_1.__read((0, overrides_1.useOverrides)(overrides === null || overrides === void 0 ? void 0 : overrides.Swatches, grid_1.Grid), 2), Swatches = _b[0], swatchesProps = _b[1];
|
|
28
35
|
var _c = tslib_1.__read((0, overrides_1.useOverrides)(overrides === null || overrides === void 0 ? void 0 : overrides.Swatch, Swatch_1.Swatch), 2), Swatch = _c[0], swatchProps = _c[1];
|
|
29
|
-
return ((0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "min-h-40" }, { children: [presets.map(function (preset
|
|
36
|
+
return ((0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "min-h-40" }, { children: [presets.map(function (preset) {
|
|
30
37
|
var _a;
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
if (!((_a = preset.colors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
var hasPresetSelection = preset.colors.some(function (presetColor) { return selectedColor === presetColor || (!selectedColor && presetColor === colors_1.RESET_COLOR); });
|
|
42
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(typography_1.Typography, tslib_1.__assign({ className: "spr-text-primary", variant: "body-md", weight: "semibold" }, { children: preset.label })), (0, jsx_runtime_1.jsx)(Swatches, tslib_1.__assign({ className: "mb-4 mt-2", cols: constants_1.SWATCHES_PER_ROW, colGap: 1, rowGap: 1, role: "radiogroup", "aria-label": preset.label, onKeyDown: function (event) { return (0, handleSwatchGroupKeyDown_1.handleSwatchGroupKeyDown)(event, direction); } }, swatchesProps, { children: preset.colors.map(function (color, index) {
|
|
43
|
+
var isSelected = selectedColor === color || (!selectedColor && color === colors_1.RESET_COLOR);
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(Swatch, tslib_1.__assign({ color: color, onChange: onChange, isSelected: isSelected, tabIndex: getSwatchTabIndex(isSelected, index, hasPresetSelection), className: ['w-6 h-6', swatchProps === null || swatchProps === void 0 ? void 0 : swatchProps.className] }, swatchProps), color));
|
|
45
|
+
}) }))] }, preset.label));
|
|
46
|
+
}), (colorPalette === null || colorPalette === void 0 ? void 0 : colorPalette.length) ? ((0, jsx_runtime_1.jsx)(Swatches, tslib_1.__assign({ cols: constants_1.SWATCHES_PER_ROW, colGap: 1, rowGap: 1, role: "radiogroup", "aria-label": locale.colorPicker.colorLibraryLabel, onKeyDown: function (event) { return (0, handleSwatchGroupKeyDown_1.handleSwatchGroupKeyDown)(event, direction); } }, swatchesProps, { children: colorPalette.map(function (color, index) {
|
|
47
|
+
var isSelected = selectedColor === color;
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(Swatch, tslib_1.__assign({ color: color, overrides: overrides, onChange: onChange, isSelected: isSelected, tabIndex: getSwatchTabIndex(isSelected, index, hasPaletteSelection), className: ['w-6 h-6', swatchProps === null || swatchProps === void 0 ? void 0 : swatchProps.className] }, swatchProps), color));
|
|
49
|
+
}) }))) : null] })));
|
|
33
50
|
});
|
|
@@ -12,12 +12,15 @@ var CustomColorSelector_1 = require("./CustomColorSelector");
|
|
|
12
12
|
var Swatch_1 = require("./Swatch");
|
|
13
13
|
var constants_1 = require("./constants");
|
|
14
14
|
var locale_1 = require("../locale");
|
|
15
|
+
var theme_1 = require("../theme");
|
|
15
16
|
var utils_1 = require("./utils");
|
|
17
|
+
var handleSwatchGroupKeyDown_1 = require("./handleSwatchGroupKeyDown");
|
|
16
18
|
var colors_1 = require("../helpers/colors");
|
|
17
19
|
var LabelOverrides = { Label: { className: 'spr-text-primary font-600 text-16 leading-150' } };
|
|
18
20
|
var GradientColorPicker = (0, react_1.memo)(function (_a) {
|
|
19
21
|
var color = _a.color, _b = _a.onChange, onChange = _b === void 0 ? noop_1.default : _b, _c = _a.onChangeComplete, onChangeComplete = _c === void 0 ? noop_1.default : _c, _d = _a.enableAlphaSelector, enableAlphaSelector = _d === void 0 ? false : _d;
|
|
20
22
|
var locale = (0, locale_1.useLocale)();
|
|
23
|
+
var direction = (0, theme_1.useTheme)().direction;
|
|
21
24
|
var _e = tslib_1.__read((0, react_1.useState)(function () {
|
|
22
25
|
var gradientColorData = (0, utils_1.extractColorsFromGradient)(color);
|
|
23
26
|
return (gradientColorData !== null && gradientColorData !== void 0 ? gradientColorData : {
|
|
@@ -72,7 +75,7 @@ var GradientColorPicker = (0, react_1.memo)(function (_a) {
|
|
|
72
75
|
var newRgb = _a.rgb;
|
|
73
76
|
return updateGradient(tslib_1.__assign(tslib_1.__assign({}, gradientColorObj), (_b = {}, _b[currentColorSelected === utils_1.SELECTED_COLOR.FIRST_COLOR ? 'firstColor' : 'secondColor'] = (0, colors_1.RgbToHex)(newRgb), _b)), onChangeComplete);
|
|
74
77
|
};
|
|
75
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(form_control_1.FormControl, tslib_1.__assign({ className: "mb-2", overrides: LabelOverrides, label: locale.colorPicker.gradientDirection, layout: "vertical" }, { children: (0, jsx_runtime_1.jsxs)(radio_1.RadioGroup, tslib_1.__assign({ value: gradientType, onChange: handleGradientTypeChange, size: "medium" }, { children: [(0, jsx_runtime_1.jsx)(radio_1.Radio, tslib_1.__assign({ value: constants_1.GRADIENT_TYPE.LINEAR }, { children: constants_1.GRADIENT_TYPE.LINEAR })), (0, jsx_runtime_1.jsx)(radio_1.Radio, tslib_1.__assign({ value: constants_1.GRADIENT_TYPE.RADIAL }, { children: constants_1.GRADIENT_TYPE.RADIAL }))] })) })), (0, jsx_runtime_1.jsx)(form_control_1.FormControl, tslib_1.__assign({ className: "mb-4", overrides: LabelOverrides, label: locale.colorPicker.gradientDegree, layout: "vertical" }, { children: (0, jsx_runtime_1.jsx)(slider_1.Slider, { className: "py-1.5 px-2", disabled: gradientType === constants_1.GRADIENT_TYPE.RADIAL, value: degree, max: 360, onChange: handleDegreeChange, onFinalChange: handleDegreeChangeComplete }) })), (0, jsx_runtime_1.jsx)(form_control_1.FormControl, tslib_1.__assign({ className: "mb-4", overrides: LabelOverrides, label: locale.colorPicker.gradientEndPoints, layout: "vertical" }, { children: (0, jsx_runtime_1.jsx)(slider_1.Slider, { className: "py-1.5 px-2", value: endPoints, max: 100, onChange: handleEndPointsChange, onFinalChange: handleEndPointsChangeComplete }) })), (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "flex justify-between items-center mb-3" }, { children: [(0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ className: "flex justify-center items-center" }, { children: (0, jsx_runtime_1.jsx)(Swatch_1.Swatch, { color: firstColor, className: "w-8 h-8", isSelected: currentColorSelected === utils_1.SELECTED_COLOR.FIRST_COLOR, onChange: function () { return setCurrentSelectedColor(utils_1.SELECTED_COLOR.FIRST_COLOR); }, "aria-label": locale.colorPicker.selectFirstColorAriaLabel }) })), (0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ className: "flex justify-center items-center" }, { children: (0, jsx_runtime_1.jsx)(Swatch_1.Swatch, { color: secondColor, className: "w-8 h-8", isSelected: currentColorSelected === utils_1.SELECTED_COLOR.SECOND_COLOR, onChange: function () { return setCurrentSelectedColor(utils_1.SELECTED_COLOR.SECOND_COLOR); }, "aria-label": locale.colorPicker.selectSecondColorAriaLabel }) }))] })), (0, jsx_runtime_1.jsx)(box_1.Box, { style: { background: (0, utils_1.getGradientColorString)(gradientColorObj) }, className: "mb-4 w-full h-6 rounded-48" }), (0, jsx_runtime_1.jsx)(CustomColorSelector_1.CustomColorSelector, { color: currentColorAsRgb, onChange: handleCustomColorChange, onChangeComplete: handleCustomColorChangeComplete, enableAlphaSelector: enableAlphaSelector })] }));
|
|
78
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(form_control_1.FormControl, tslib_1.__assign({ className: "mb-2", overrides: LabelOverrides, label: locale.colorPicker.gradientDirection, layout: "vertical" }, { children: (0, jsx_runtime_1.jsxs)(radio_1.RadioGroup, tslib_1.__assign({ value: gradientType, onChange: handleGradientTypeChange, size: "medium" }, { children: [(0, jsx_runtime_1.jsx)(radio_1.Radio, tslib_1.__assign({ value: constants_1.GRADIENT_TYPE.LINEAR }, { children: constants_1.GRADIENT_TYPE.LINEAR })), (0, jsx_runtime_1.jsx)(radio_1.Radio, tslib_1.__assign({ value: constants_1.GRADIENT_TYPE.RADIAL }, { children: constants_1.GRADIENT_TYPE.RADIAL }))] })) })), (0, jsx_runtime_1.jsx)(form_control_1.FormControl, tslib_1.__assign({ className: "mb-4", overrides: LabelOverrides, label: locale.colorPicker.gradientDegree, layout: "vertical" }, { children: (0, jsx_runtime_1.jsx)(slider_1.Slider, { className: "py-1.5 px-2", disabled: gradientType === constants_1.GRADIENT_TYPE.RADIAL, value: degree, max: 360, onChange: handleDegreeChange, onFinalChange: handleDegreeChangeComplete }) })), (0, jsx_runtime_1.jsx)(form_control_1.FormControl, tslib_1.__assign({ className: "mb-4", overrides: LabelOverrides, label: locale.colorPicker.gradientEndPoints, layout: "vertical" }, { children: (0, jsx_runtime_1.jsx)(slider_1.Slider, { className: "py-1.5 px-2", value: endPoints, max: 100, onChange: handleEndPointsChange, onFinalChange: handleEndPointsChangeComplete }) })), (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "flex justify-between items-center mb-3", role: "radiogroup", "aria-label": locale.colorPicker.selectColorLabel, onKeyDown: function (event) { return (0, handleSwatchGroupKeyDown_1.handleSwatchGroupKeyDown)(event, direction); } }, { children: [(0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ className: "flex justify-center items-center" }, { children: (0, jsx_runtime_1.jsx)(Swatch_1.Swatch, { color: firstColor, className: "w-8 h-8", isSelected: currentColorSelected === utils_1.SELECTED_COLOR.FIRST_COLOR, onChange: function () { return setCurrentSelectedColor(utils_1.SELECTED_COLOR.FIRST_COLOR); }, "aria-label": locale.colorPicker.selectFirstColorAriaLabel }) })), (0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ className: "flex justify-center items-center" }, { children: (0, jsx_runtime_1.jsx)(Swatch_1.Swatch, { color: secondColor, className: "w-8 h-8", isSelected: currentColorSelected === utils_1.SELECTED_COLOR.SECOND_COLOR, onChange: function () { return setCurrentSelectedColor(utils_1.SELECTED_COLOR.SECOND_COLOR); }, "aria-label": locale.colorPicker.selectSecondColorAriaLabel }) }))] })), (0, jsx_runtime_1.jsx)(box_1.Box, { style: { background: (0, utils_1.getGradientColorString)(gradientColorObj) }, className: "mb-4 w-full h-6 rounded-48" }), (0, jsx_runtime_1.jsx)(CustomColorSelector_1.CustomColorSelector, { color: currentColorAsRgb, onChange: handleCustomColorChange, onChangeComplete: handleCustomColorChangeComplete, enableAlphaSelector: enableAlphaSelector })] }));
|
|
76
79
|
});
|
|
77
80
|
GradientColorPicker.displayName = 'GradientColorPicker';
|
|
78
81
|
exports.default = GradientColorPicker;
|
package/color-picker/Swatch.d.ts
CHANGED
|
@@ -7,5 +7,7 @@ export type SwatchProps = {
|
|
|
7
7
|
onChange: (color?: string) => void | (() => void);
|
|
8
8
|
className?: ClassName;
|
|
9
9
|
style?: Styles;
|
|
10
|
+
tabIndex?: number;
|
|
11
|
+
'aria-label'?: string;
|
|
10
12
|
};
|
|
11
|
-
export declare const Swatch: import("react").MemoExoticComponent<({ color, isSelected, onChange, className, ...props }: SwatchProps) => ReactElement>;
|
|
13
|
+
export declare const Swatch: import("react").MemoExoticComponent<({ color, isSelected, onChange, className, tabIndex, "aria-label": ariaLabelProp, ...props }: SwatchProps) => ReactElement>;
|
package/color-picker/Swatch.js
CHANGED
|
@@ -8,18 +8,21 @@ var react_1 = require("react");
|
|
|
8
8
|
var box_1 = require("../box");
|
|
9
9
|
var transparentBackground_1 = tslib_1.__importDefault(require("../icon/components/transparentBackground"));
|
|
10
10
|
var colors_1 = require("./colors");
|
|
11
|
+
var locale_1 = require("../locale");
|
|
11
12
|
exports.Swatch = (0, react_1.memo)(function (_a) {
|
|
12
|
-
var color = _a.color, isSelected = _a.isSelected, onChange = _a.onChange, className = _a.className, props = tslib_1.__rest(_a, ["color", "isSelected", "onChange", "className"]);
|
|
13
|
+
var color = _a.color, isSelected = _a.isSelected, onChange = _a.onChange, className = _a.className, tabIndex = _a.tabIndex, ariaLabelProp = _a["aria-label"], props = tslib_1.__rest(_a, ["color", "isSelected", "onChange", "className", "tabIndex", 'aria-label']);
|
|
14
|
+
var locale = (0, locale_1.useLocale)();
|
|
13
15
|
var handleChange = (0, react_1.useCallback)(function () { return onChange(color); }, [color, onChange]);
|
|
16
|
+
var isReset = !color || color === colors_1.RESET_COLOR;
|
|
17
|
+
var ariaLabel = ariaLabelProp !== null && ariaLabelProp !== void 0 ? ariaLabelProp : (isReset ? locale.colorPicker.resetButtonLabel : color);
|
|
14
18
|
var swatchInnerEl = (0, jsx_runtime_1.jsx)(box_1.Box, { className: "h-full w-full rounded-full", style: { backgroundColor: color } });
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
swatchInnerEl = (0, jsx_runtime_1.jsx)(transparentBackground_1.default, { size: 20 });
|
|
19
|
+
if (isReset) {
|
|
20
|
+
swatchInnerEl = (0, jsx_runtime_1.jsx)(transparentBackground_1.default, { size: 20, "aria-hidden": true });
|
|
18
21
|
}
|
|
19
22
|
return ((0, jsx_runtime_1.jsx)(base_button_1.BaseButton, tslib_1.__assign({ onClick: handleChange, "data-testid": "swatch-".concat(color), className: [
|
|
20
23
|
'z-0 cursor-pointer h-5 w-5 rounded-full flex justify-center items-center p-px border-1 border-solid spr-border-primary hover:spr-border-quaternary',
|
|
21
24
|
'focus-visible:outline-1 focus-visible:-outline-offset-1',
|
|
22
25
|
isSelected ? 'spr-border-quinary' : '',
|
|
23
26
|
className,
|
|
24
|
-
], "aria-checked": isSelected, tabIndex: 0 }, props, { children: swatchInnerEl })));
|
|
27
|
+
], role: "radio", "aria-checked": isSelected, "aria-label": ariaLabel, tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : (isSelected ? 0 : -1) }, props, { children: swatchInnerEl })));
|
|
25
28
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KeyboardEvent } from 'react';
|
|
2
|
+
import type { Direction } from '@sprinklrjs/spaceweb-themes/types';
|
|
3
|
+
/**
|
|
4
|
+
* APG radio pattern: one tab stop, arrows move focus and selection within the group.
|
|
5
|
+
* https://www.w3.org/WAI/ARIA/apg/patterns/radio/
|
|
6
|
+
*/
|
|
7
|
+
export declare const handleSwatchGroupKeyDown: (event: KeyboardEvent<HTMLElement>, direction?: Direction) => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleSwatchGroupKeyDown = void 0;
|
|
4
|
+
/** +1 for “next” in DOM order, −1 for “previous”; horizontal arrows flip in RTL (see tabs keyboard nav). */
|
|
5
|
+
var getArrowDelta = function (key, direction) {
|
|
6
|
+
var horizontalStep = direction === 'rtl' ? -1 : 1;
|
|
7
|
+
switch (key) {
|
|
8
|
+
case 'ArrowUp':
|
|
9
|
+
return -1;
|
|
10
|
+
case 'ArrowDown':
|
|
11
|
+
return 1;
|
|
12
|
+
case 'ArrowLeft':
|
|
13
|
+
return -horizontalStep;
|
|
14
|
+
case 'ArrowRight':
|
|
15
|
+
return horizontalStep;
|
|
16
|
+
default:
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* APG radio pattern: one tab stop, arrows move focus and selection within the group.
|
|
22
|
+
* https://www.w3.org/WAI/ARIA/apg/patterns/radio/
|
|
23
|
+
*/
|
|
24
|
+
var handleSwatchGroupKeyDown = function (event, direction) {
|
|
25
|
+
if (direction === void 0) { direction = 'ltr'; }
|
|
26
|
+
var delta = getArrowDelta(event.key, direction);
|
|
27
|
+
if (delta === null) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
var radios = Array.from(event.currentTarget.querySelectorAll('[role="radio"]'));
|
|
31
|
+
if (radios.length === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
var currentIndex = radios.findIndex(function (radio) { return radio === event.target || radio.contains(event.target); });
|
|
35
|
+
if (currentIndex === -1) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
var nextRadio = radios[(currentIndex + delta + radios.length) % radios.length];
|
|
40
|
+
nextRadio.focus();
|
|
41
|
+
nextRadio.click();
|
|
42
|
+
};
|
|
43
|
+
exports.handleSwatchGroupKeyDown = handleSwatchGroupKeyDown;
|
|
@@ -13,9 +13,12 @@ type DateInputProps = {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
size?: InputSize;
|
|
15
15
|
formatString?: string;
|
|
16
|
+
id?: string;
|
|
17
|
+
'aria-labelledby'?: string;
|
|
18
|
+
'aria-describedby'?: string;
|
|
16
19
|
};
|
|
17
20
|
/**
|
|
18
21
|
* This component renders the Date dropdown inside the DatePicker Popover.
|
|
19
22
|
*/
|
|
20
|
-
export declare const DateInput: React.MemoExoticComponent<({ dateHelpers, date, onChange, maxDate, minDate, disabled, size, formatString, }: DateInputProps) => JSX.Element>;
|
|
23
|
+
export declare const DateInput: React.MemoExoticComponent<({ dateHelpers, date, onChange, maxDate, minDate, disabled, size, formatString, id, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, }: DateInputProps) => JSX.Element>;
|
|
21
24
|
export {};
|
package/date-picker/DateInput.js
CHANGED
|
@@ -18,6 +18,7 @@ var InputFieldIcon_1 = require("./InputFieldIcon");
|
|
|
18
18
|
var calendar_solid_1 = tslib_1.__importDefault(require("../icon/components/calendar-solid"));
|
|
19
19
|
var utils_2 = require("../date-input/utils");
|
|
20
20
|
var constants_1 = require("./constants");
|
|
21
|
+
var locale_1 = require("../locale");
|
|
21
22
|
var COMMON_STYLE = [
|
|
22
23
|
'px-0 py-0 rounded-2 text-center tabular-nums',
|
|
23
24
|
function (_a) {
|
|
@@ -79,8 +80,9 @@ exports.DateInput = React.memo(
|
|
|
79
80
|
// eslint-disable-next-line max-statements -- works for functional component
|
|
80
81
|
function (_a) {
|
|
81
82
|
var _b, _c, _d, _e;
|
|
82
|
-
var dateHelpers = _a.dateHelpers, date = _a.date, onChange = _a.onChange, maxDate = _a.maxDate, minDate = _a.minDate, disabled = _a.disabled, size = _a.size, _f = _a.formatString, formatString = _f === void 0 ? constants_1.DEFAULT_FORMAT_STRING : _f;
|
|
83
|
+
var dateHelpers = _a.dateHelpers, date = _a.date, onChange = _a.onChange, maxDate = _a.maxDate, minDate = _a.minDate, disabled = _a.disabled, size = _a.size, _f = _a.formatString, formatString = _f === void 0 ? constants_1.DEFAULT_FORMAT_STRING : _f, id = _a.id, ariaLabelledBy = _a["aria-labelledby"], ariaDescribedBy = _a["aria-describedby"];
|
|
83
84
|
var theme = (0, theme_1.useTheme)().theme;
|
|
85
|
+
var spacewebLocale = (0, locale_1.useLocale)();
|
|
84
86
|
var _g = tslib_1.__read(React.useState(function () { return (date ? dateHelpers.formatDate(date, 'dd') : ''); }), 2), day = _g[0], setDay = _g[1];
|
|
85
87
|
var _h = tslib_1.__read(React.useState(function () { return (date ? dateHelpers.formatDate(date, 'MM') : ''); }), 2), month = _h[0], setMonth = _h[1];
|
|
86
88
|
var _j = tslib_1.__read(React.useState(function () { return (date ? dateHelpers.getYear(date) : ''); }), 2), year = _j[0], setYear = _j[1];
|
|
@@ -261,7 +263,7 @@ function (_a) {
|
|
|
261
263
|
var inputSizeTheme = (0, themeHelpers_1.getComponentSizeTheme)(theme, 'input', size, defaultSize);
|
|
262
264
|
var inputClasses = cvaConfigs_1.input$Size[size !== null && size !== void 0 ? size : defaultSize];
|
|
263
265
|
var inputStyles = (0, styled_components_1.inputStyleVariables)({ theme: theme }, { $size: size });
|
|
264
|
-
return ((0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ "data-testid": "date-input", className: [
|
|
266
|
+
return ((0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ "data-testid": "date-input", role: "group", id: id, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, className: [
|
|
265
267
|
'px-3 flex items-center border-1 border-solid border-box rounded-8',
|
|
266
268
|
error ? 'spr-support-error-border' : 'spr-border-03',
|
|
267
269
|
disabled ? 'spr-ui-02' : 'spr-ui-01',
|
|
@@ -281,10 +283,10 @@ function (_a) {
|
|
|
281
283
|
}
|
|
282
284
|
: {})),
|
|
283
285
|
], style: inputStyles }, { children: [(0, jsx_runtime_1.jsx)(InputFieldIcon_1.FieldIcon, { icon: calendar_solid_1.default, disabled: disabled }), (function (isDayFirst) {
|
|
284
|
-
var DayInputMask = ((0, jsx_runtime_1.jsx)(react_input_mask_1.default, tslib_1.__assign({ onBlur: dateBlur, onKeyDown: dateKeyDown, mask: "99", value: day, onChange: dayChange, maskChar: "_", disabled: disabled }, { children: function (props) { return ((0, jsx_runtime_1.jsx)(input_1.Input, tslib_1.__assign({}, props, { className: DATE_CLASSNAME, overrides: DATE_OVERRIDES, placeholder: "dd", size: "small", disabled: disabled }))); } })));
|
|
285
|
-
var MonthInputMask = ((0, jsx_runtime_1.jsx)(react_input_mask_1.default, tslib_1.__assign({ onBlur: monthBlur, onKeyDown: monthKeyDown, mask: "99", value: month, onChange: monthChange, maskChar: "_", disabled: disabled }, { children: function (props) { return ((0, jsx_runtime_1.jsx)(input_1.Input, tslib_1.__assign({}, props, { className: MONTH_CLASSNAME, style: MONTH_STYLE, overrides: MONTH_OVERRIDES, placeholder: "mm", size: "small", disabled: disabled }))); } })));
|
|
286
|
+
var DayInputMask = ((0, jsx_runtime_1.jsx)(react_input_mask_1.default, tslib_1.__assign({ onBlur: dateBlur, onKeyDown: dateKeyDown, mask: "99", value: day, onChange: dayChange, maskChar: "_", disabled: disabled }, { children: function (props) { return ((0, jsx_runtime_1.jsx)(input_1.Input, tslib_1.__assign({}, props, { className: DATE_CLASSNAME, overrides: DATE_OVERRIDES, placeholder: "dd", size: "small", disabled: disabled, "aria-label": spacewebLocale.calendar.dateInputDayAriaLabel }))); } })));
|
|
287
|
+
var MonthInputMask = ((0, jsx_runtime_1.jsx)(react_input_mask_1.default, tslib_1.__assign({ onBlur: monthBlur, onKeyDown: monthKeyDown, mask: "99", value: month, onChange: monthChange, maskChar: "_", disabled: disabled }, { children: function (props) { return ((0, jsx_runtime_1.jsx)(input_1.Input, tslib_1.__assign({}, props, { className: MONTH_CLASSNAME, style: MONTH_STYLE, overrides: MONTH_OVERRIDES, placeholder: "mm", size: "small", disabled: disabled, "aria-label": spacewebLocale.calendar.dateInputMonthAriaLabel }))); } })));
|
|
286
288
|
if (isDayFirst)
|
|
287
289
|
return [DayInputMask, '/', MonthInputMask];
|
|
288
290
|
return [MonthInputMask, '/', DayInputMask];
|
|
289
|
-
})((0, utils_2.isDDMM)(formatString)), "/", (0, jsx_runtime_1.jsx)(react_input_mask_1.default, tslib_1.__assign({ onBlur: yearBlur, onKeyDown: yearKeyDown, mask: "9999", value: year, onChange: yearChange, maskChar: "_", disabled: disabled }, { children: function (props) { return ((0, jsx_runtime_1.jsx)(input_1.Input, tslib_1.__assign({}, props, { className: YEAR_CLASSNAME, overrides: YEAR_OVERRIDES, placeholder: "yyyy", size: "small", disabled: disabled }))); } }))] })));
|
|
291
|
+
})((0, utils_2.isDDMM)(formatString)), "/", (0, jsx_runtime_1.jsx)(react_input_mask_1.default, tslib_1.__assign({ onBlur: yearBlur, onKeyDown: yearKeyDown, mask: "9999", value: year, onChange: yearChange, maskChar: "_", disabled: disabled }, { children: function (props) { return ((0, jsx_runtime_1.jsx)(input_1.Input, tslib_1.__assign({}, props, { className: YEAR_CLASSNAME, overrides: YEAR_OVERRIDES, placeholder: "yyyy", size: "small", disabled: disabled, "aria-label": spacewebLocale.calendar.dateInputYearAriaLabel }))); } }))] })));
|
|
290
292
|
});
|
|
@@ -14,6 +14,11 @@ type TimeInputProps = {
|
|
|
14
14
|
adapter: DateIOAdapter<Date>;
|
|
15
15
|
getTimeRangesForDate?: GetTimeRangesForDate;
|
|
16
16
|
size?: InputSize;
|
|
17
|
+
id?: string;
|
|
18
|
+
'aria-labelledby'?: string;
|
|
19
|
+
'aria-describedby'?: string;
|
|
20
|
+
'aria-errormessage'?: string;
|
|
21
|
+
required?: boolean;
|
|
17
22
|
};
|
|
18
|
-
export declare const TimeInput: ({ overrides, time, onChange, dateHelpers, minTime, maxTime, disabled, adapter, getTimeRangesForDate, size, }: TimeInputProps) => JSX.Element;
|
|
23
|
+
export declare const TimeInput: ({ overrides, time, onChange, dateHelpers, minTime, maxTime, disabled, adapter, getTimeRangesForDate, size, id, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, required, }: TimeInputProps) => JSX.Element;
|
|
19
24
|
export {};
|
package/date-picker/TimeInput.js
CHANGED
|
@@ -12,7 +12,7 @@ var InputFieldIcon_1 = require("./InputFieldIcon");
|
|
|
12
12
|
var MS_IN_5_MINUTES = 60 * 1000 * 5;
|
|
13
13
|
var roundUpTime = function (minTime) { return new Date(Math.ceil(minTime.getTime() / MS_IN_5_MINUTES) * MS_IN_5_MINUTES); };
|
|
14
14
|
var TimeInput = function (_a) {
|
|
15
|
-
var overrides = _a.overrides, time = _a.time, onChange = _a.onChange, dateHelpers = _a.dateHelpers, minTime = _a.minTime, maxTime = _a.maxTime, disabled = _a.disabled, adapter = _a.adapter, getTimeRangesForDate = _a.getTimeRangesForDate, size = _a.size;
|
|
15
|
+
var overrides = _a.overrides, time = _a.time, onChange = _a.onChange, dateHelpers = _a.dateHelpers, minTime = _a.minTime, maxTime = _a.maxTime, disabled = _a.disabled, adapter = _a.adapter, getTimeRangesForDate = _a.getTimeRangesForDate, size = _a.size, id = _a.id, ariaLabelledBy = _a["aria-labelledby"], ariaDescribedBy = _a["aria-describedby"], ariaErrorMessage = _a["aria-errormessage"], required = _a.required;
|
|
16
16
|
var _b = tslib_1.__read((0, react_1.useState)(time), 2), value = _b[0], setValue = _b[1];
|
|
17
17
|
var _c = tslib_1.__read((0, react_1.useState)(false), 2), error = _c[0], setError = _c[1];
|
|
18
18
|
(0, react_1.useEffect)(function () {
|
|
@@ -75,6 +75,6 @@ var TimeInput = function (_a) {
|
|
|
75
75
|
}, [error, value, overrides, time, minTime, maxTime, dateHelpers]);
|
|
76
76
|
var _d = tslib_1.__read((0, overrides_1.useOverrides)(mergedOverrides === null || mergedOverrides === void 0 ? void 0 : mergedOverrides.TimePicker, time_picker_1.TimePicker), 2), TimePicker = _d[0], timeSelectProps = _d[1];
|
|
77
77
|
var timeRanges = (0, react_1.useMemo)(function () { return (time ? getTimeRangesForDate === null || getTimeRangesForDate === void 0 ? void 0 : getTimeRangesForDate(time) : undefined); }, [time, getTimeRangesForDate]);
|
|
78
|
-
return ((0, jsx_runtime_1.jsx)(TimePicker, tslib_1.__assign({ adapter: adapter, value: value, onChange: handleChange, creatable: true, clearable: true, disabled: disabled, minTime: minTime && dateHelpers.isSameDay(value, minTime) ? roundUpTime(minTime) : undefined, maxTime: dateHelpers.isSameDay(value, maxTime) ? maxTime : undefined, timeRanges: timeRanges, size: size }, timeSelectProps)));
|
|
78
|
+
return ((0, jsx_runtime_1.jsx)(TimePicker, tslib_1.__assign({ adapter: adapter, value: value, onChange: handleChange, creatable: true, clearable: true, disabled: disabled, minTime: minTime && dateHelpers.isSameDay(value, minTime) ? roundUpTime(minTime) : undefined, maxTime: dateHelpers.isSameDay(value, maxTime) ? maxTime : undefined, timeRanges: timeRanges, size: size, id: id, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, required: required }, timeSelectProps)));
|
|
79
79
|
};
|
|
80
80
|
exports.TimeInput = TimeInput;
|
|
@@ -45,7 +45,7 @@ var TimePicker = /** @class */ (function (_super) {
|
|
|
45
45
|
__extends(TimePicker, _super);
|
|
46
46
|
function TimePicker(props) {
|
|
47
47
|
var _this = _super.call(this, props) || this;
|
|
48
|
-
// @ts-ignore
|
|
48
|
+
// @ts-ignore -- legacy baseui code
|
|
49
49
|
_this.state = { steps: [], value: null };
|
|
50
50
|
_this.onChange = function (params) {
|
|
51
51
|
_this.setState({ value: params.value[0] });
|
|
@@ -166,9 +166,9 @@ var TimePicker = /** @class */ (function (_super) {
|
|
|
166
166
|
var maxDate = _this.props.adapter.toJsDate(max);
|
|
167
167
|
var midnightDate = _this.props.adapter.toJsDate(dayStart);
|
|
168
168
|
return {
|
|
169
|
-
// @ts-expect-error todo(flow->ts)
|
|
169
|
+
// @ts-expect-error todo(flow->ts) -- legacy code from base ui
|
|
170
170
|
start: (minDate - midnightDate) / 1000,
|
|
171
|
-
// @ts-expect-error todo(flow->ts)
|
|
171
|
+
// @ts-expect-error todo(flow->ts) -- legacy code from base ui
|
|
172
172
|
end: (maxDate - midnightDate) / 1000,
|
|
173
173
|
};
|
|
174
174
|
};
|
|
@@ -295,12 +295,12 @@ var TimePicker = /** @class */ (function (_super) {
|
|
|
295
295
|
? _this.buildSelectedOption(_this.props.value, _this.props.format, langCode)
|
|
296
296
|
: _this.state.value;
|
|
297
297
|
var ariaLabel = format === '12' ? timeRangePicker.timePickerAriaLabel12Hour : timeRangePicker.timePickerAriaLabel24Hour;
|
|
298
|
-
return (_jsx(OverriddenSelect, __assign({
|
|
298
|
+
return (_jsx(OverriddenSelect, __assign({ disabled: _this.props.disabled, error: _this.props.error, positive: _this.props.positive, size: _this.props.size, placeholder: _this.props.placeholder || defaultPlaceholder, options: _this.state.steps.map(function (n) { return ({
|
|
299
299
|
id: n,
|
|
300
300
|
label: _this.secondsToLabel(n, _this.props.format, langCode),
|
|
301
301
|
}); }), filterOptions: _this.props.creatable ? _this.creatableFilterOptions : undefined, onChange: _this.onChange,
|
|
302
302
|
// if value is defined, it should be an array type
|
|
303
|
-
value: value ? [value] : value, clearable: false, backspaceRemoves: false, valueKey: "label" }, selectProps)));
|
|
303
|
+
value: value ? [value] : value, clearable: false, backspaceRemoves: false, valueKey: "label" }, selectProps, { "aria-label": _this.props['aria-labelledby'] ? undefined : ariaLabel, "aria-labelledby": _this.props['aria-labelledby'], "aria-describedby": _this.props['aria-describedby'], "aria-errormessage": _this.props['aria-errormessage'], required: _this.props.required, id: _this.props.id })));
|
|
304
304
|
} }));
|
|
305
305
|
};
|
|
306
306
|
TimePicker.defaultProps = {
|
|
@@ -40,6 +40,11 @@ export type TimePickerProps<T = Date> = {
|
|
|
40
40
|
* By default the component will clamp the time window and setting this flag will ignore dates.
|
|
41
41
|
*/
|
|
42
42
|
ignoreMinMaxDateComponent?: boolean;
|
|
43
|
+
id?: string;
|
|
44
|
+
'aria-labelledby'?: string;
|
|
45
|
+
'aria-describedby'?: string;
|
|
46
|
+
'aria-errormessage'?: string;
|
|
47
|
+
required?: boolean;
|
|
43
48
|
};
|
|
44
49
|
export type TimePickerState = {
|
|
45
50
|
/** List of times (in seconds) displayed in the dropdown menu. */
|
|
@@ -6,13 +6,19 @@ import { Grid } from '../grid';
|
|
|
6
6
|
import { Swatch as DefaultSwatch } from './Swatch';
|
|
7
7
|
import { useLocale } from '../locale';
|
|
8
8
|
import { useOverrides } from '../overrides';
|
|
9
|
+
import { useTheme } from '../theme';
|
|
9
10
|
import { COLOR_PALETTE, SPRINKLR_PRESET_COLORS, RESET_COLOR } from './colors';
|
|
11
|
+
import { handleSwatchGroupKeyDown } from './handleSwatchGroupKeyDown';
|
|
10
12
|
import { SWATCHES_PER_ROW } from './constants';
|
|
11
13
|
import { Typography } from '../typography';
|
|
12
14
|
var defaultColorPalette = COLOR_PALETTE.flat();
|
|
15
|
+
var getSwatchTabIndex = function (isSelected, index, hasGroupSelection) {
|
|
16
|
+
return isSelected || (!hasGroupSelection && index === 0) ? 0 : -1;
|
|
17
|
+
};
|
|
13
18
|
export var ColorPalette = memo(function (_a) {
|
|
14
19
|
var selectedColor = _a.color, overrides = _a.overrides, onChange = _a.onChange, _colorPalette = _a.colorPalette, _presets = _a.presets, noReset = _a.noReset;
|
|
15
20
|
var locale = useLocale();
|
|
21
|
+
var direction = useTheme().direction;
|
|
16
22
|
var presets = useMemo(function () {
|
|
17
23
|
var defaultPreset = {
|
|
18
24
|
label: locale.colorPicker.sprinklrPresets,
|
|
@@ -21,10 +27,21 @@ export var ColorPalette = memo(function (_a) {
|
|
|
21
27
|
return typeof _presets === 'function' ? _presets(defaultPreset) : _presets !== null && _presets !== void 0 ? _presets : [defaultPreset];
|
|
22
28
|
}, [_presets, noReset, locale.colorPicker]);
|
|
23
29
|
var colorPalette = _colorPalette !== null && _colorPalette !== void 0 ? _colorPalette : defaultColorPalette;
|
|
30
|
+
var hasPaletteSelection = colorPalette.some(function (paletteColor) { return selectedColor === paletteColor; });
|
|
24
31
|
var _b = __read(useOverrides(overrides === null || overrides === void 0 ? void 0 : overrides.Swatches, Grid), 2), Swatches = _b[0], swatchesProps = _b[1];
|
|
25
32
|
var _c = __read(useOverrides(overrides === null || overrides === void 0 ? void 0 : overrides.Swatch, DefaultSwatch), 2), Swatch = _c[0], swatchProps = _c[1];
|
|
26
|
-
return (_jsxs(Box, __assign({ className: "min-h-40" }, { children: [presets.map(function (preset
|
|
33
|
+
return (_jsxs(Box, __assign({ className: "min-h-40" }, { children: [presets.map(function (preset) {
|
|
27
34
|
var _a;
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
if (!((_a = preset.colors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
var hasPresetSelection = preset.colors.some(function (presetColor) { return selectedColor === presetColor || (!selectedColor && presetColor === RESET_COLOR); });
|
|
39
|
+
return (_jsxs(Fragment, { children: [_jsx(Typography, __assign({ className: "spr-text-primary", variant: "body-md", weight: "semibold" }, { children: preset.label })), _jsx(Swatches, __assign({ className: "mb-4 mt-2", cols: SWATCHES_PER_ROW, colGap: 1, rowGap: 1, role: "radiogroup", "aria-label": preset.label, onKeyDown: function (event) { return handleSwatchGroupKeyDown(event, direction); } }, swatchesProps, { children: preset.colors.map(function (color, index) {
|
|
40
|
+
var isSelected = selectedColor === color || (!selectedColor && color === RESET_COLOR);
|
|
41
|
+
return (_jsx(Swatch, __assign({ color: color, onChange: onChange, isSelected: isSelected, tabIndex: getSwatchTabIndex(isSelected, index, hasPresetSelection), className: ['w-6 h-6', swatchProps === null || swatchProps === void 0 ? void 0 : swatchProps.className] }, swatchProps), color));
|
|
42
|
+
}) }))] }, preset.label));
|
|
43
|
+
}), (colorPalette === null || colorPalette === void 0 ? void 0 : colorPalette.length) ? (_jsx(Swatches, __assign({ cols: SWATCHES_PER_ROW, colGap: 1, rowGap: 1, role: "radiogroup", "aria-label": locale.colorPicker.colorLibraryLabel, onKeyDown: function (event) { return handleSwatchGroupKeyDown(event, direction); } }, swatchesProps, { children: colorPalette.map(function (color, index) {
|
|
44
|
+
var isSelected = selectedColor === color;
|
|
45
|
+
return (_jsx(Swatch, __assign({ color: color, overrides: overrides, onChange: onChange, isSelected: isSelected, tabIndex: getSwatchTabIndex(isSelected, index, hasPaletteSelection), className: ['w-6 h-6', swatchProps === null || swatchProps === void 0 ? void 0 : swatchProps.className] }, swatchProps), color));
|
|
46
|
+
}) }))) : null] })));
|
|
30
47
|
});
|
|
@@ -10,12 +10,15 @@ import { CustomColorSelector } from './CustomColorSelector';
|
|
|
10
10
|
import { Swatch } from './Swatch';
|
|
11
11
|
import { GRADIENT_TYPE } from './constants';
|
|
12
12
|
import { useLocale } from '../locale';
|
|
13
|
+
import { useTheme } from '../theme';
|
|
13
14
|
import { extractColorsFromGradient, getGradientColorString, SELECTED_COLOR } from './utils';
|
|
15
|
+
import { handleSwatchGroupKeyDown } from './handleSwatchGroupKeyDown';
|
|
14
16
|
import { hexToRgb, RgbToHex } from '../helpers/colors';
|
|
15
17
|
var LabelOverrides = { Label: { className: 'spr-text-primary font-600 text-16 leading-150' } };
|
|
16
18
|
var GradientColorPicker = memo(function (_a) {
|
|
17
19
|
var color = _a.color, _b = _a.onChange, onChange = _b === void 0 ? _noop : _b, _c = _a.onChangeComplete, onChangeComplete = _c === void 0 ? _noop : _c, _d = _a.enableAlphaSelector, enableAlphaSelector = _d === void 0 ? false : _d;
|
|
18
20
|
var locale = useLocale();
|
|
21
|
+
var direction = useTheme().direction;
|
|
19
22
|
var _e = __read(useState(function () {
|
|
20
23
|
var gradientColorData = extractColorsFromGradient(color);
|
|
21
24
|
return (gradientColorData !== null && gradientColorData !== void 0 ? gradientColorData : {
|
|
@@ -70,7 +73,7 @@ var GradientColorPicker = memo(function (_a) {
|
|
|
70
73
|
var newRgb = _a.rgb;
|
|
71
74
|
return updateGradient(__assign(__assign({}, gradientColorObj), (_b = {}, _b[currentColorSelected === SELECTED_COLOR.FIRST_COLOR ? 'firstColor' : 'secondColor'] = RgbToHex(newRgb), _b)), onChangeComplete);
|
|
72
75
|
};
|
|
73
|
-
return (_jsxs(_Fragment, { children: [_jsx(FormControl, __assign({ className: "mb-2", overrides: LabelOverrides, label: locale.colorPicker.gradientDirection, layout: "vertical" }, { children: _jsxs(RadioGroup, __assign({ value: gradientType, onChange: handleGradientTypeChange, size: "medium" }, { children: [_jsx(Radio, __assign({ value: GRADIENT_TYPE.LINEAR }, { children: GRADIENT_TYPE.LINEAR })), _jsx(Radio, __assign({ value: GRADIENT_TYPE.RADIAL }, { children: GRADIENT_TYPE.RADIAL }))] })) })), _jsx(FormControl, __assign({ className: "mb-4", overrides: LabelOverrides, label: locale.colorPicker.gradientDegree, layout: "vertical" }, { children: _jsx(Slider, { className: "py-1.5 px-2", disabled: gradientType === GRADIENT_TYPE.RADIAL, value: degree, max: 360, onChange: handleDegreeChange, onFinalChange: handleDegreeChangeComplete }) })), _jsx(FormControl, __assign({ className: "mb-4", overrides: LabelOverrides, label: locale.colorPicker.gradientEndPoints, layout: "vertical" }, { children: _jsx(Slider, { className: "py-1.5 px-2", value: endPoints, max: 100, onChange: handleEndPointsChange, onFinalChange: handleEndPointsChangeComplete }) })), _jsxs(Box, __assign({ className: "flex justify-between items-center mb-3" }, { children: [_jsx(Box, __assign({ className: "flex justify-center items-center" }, { children: _jsx(Swatch, { color: firstColor, className: "w-8 h-8", isSelected: currentColorSelected === SELECTED_COLOR.FIRST_COLOR, onChange: function () { return setCurrentSelectedColor(SELECTED_COLOR.FIRST_COLOR); }, "aria-label": locale.colorPicker.selectFirstColorAriaLabel }) })), _jsx(Box, __assign({ className: "flex justify-center items-center" }, { children: _jsx(Swatch, { color: secondColor, className: "w-8 h-8", isSelected: currentColorSelected === SELECTED_COLOR.SECOND_COLOR, onChange: function () { return setCurrentSelectedColor(SELECTED_COLOR.SECOND_COLOR); }, "aria-label": locale.colorPicker.selectSecondColorAriaLabel }) }))] })), _jsx(Box, { style: { background: getGradientColorString(gradientColorObj) }, className: "mb-4 w-full h-6 rounded-48" }), _jsx(CustomColorSelector, { color: currentColorAsRgb, onChange: handleCustomColorChange, onChangeComplete: handleCustomColorChangeComplete, enableAlphaSelector: enableAlphaSelector })] }));
|
|
76
|
+
return (_jsxs(_Fragment, { children: [_jsx(FormControl, __assign({ className: "mb-2", overrides: LabelOverrides, label: locale.colorPicker.gradientDirection, layout: "vertical" }, { children: _jsxs(RadioGroup, __assign({ value: gradientType, onChange: handleGradientTypeChange, size: "medium" }, { children: [_jsx(Radio, __assign({ value: GRADIENT_TYPE.LINEAR }, { children: GRADIENT_TYPE.LINEAR })), _jsx(Radio, __assign({ value: GRADIENT_TYPE.RADIAL }, { children: GRADIENT_TYPE.RADIAL }))] })) })), _jsx(FormControl, __assign({ className: "mb-4", overrides: LabelOverrides, label: locale.colorPicker.gradientDegree, layout: "vertical" }, { children: _jsx(Slider, { className: "py-1.5 px-2", disabled: gradientType === GRADIENT_TYPE.RADIAL, value: degree, max: 360, onChange: handleDegreeChange, onFinalChange: handleDegreeChangeComplete }) })), _jsx(FormControl, __assign({ className: "mb-4", overrides: LabelOverrides, label: locale.colorPicker.gradientEndPoints, layout: "vertical" }, { children: _jsx(Slider, { className: "py-1.5 px-2", value: endPoints, max: 100, onChange: handleEndPointsChange, onFinalChange: handleEndPointsChangeComplete }) })), _jsxs(Box, __assign({ className: "flex justify-between items-center mb-3", role: "radiogroup", "aria-label": locale.colorPicker.selectColorLabel, onKeyDown: function (event) { return handleSwatchGroupKeyDown(event, direction); } }, { children: [_jsx(Box, __assign({ className: "flex justify-center items-center" }, { children: _jsx(Swatch, { color: firstColor, className: "w-8 h-8", isSelected: currentColorSelected === SELECTED_COLOR.FIRST_COLOR, onChange: function () { return setCurrentSelectedColor(SELECTED_COLOR.FIRST_COLOR); }, "aria-label": locale.colorPicker.selectFirstColorAriaLabel }) })), _jsx(Box, __assign({ className: "flex justify-center items-center" }, { children: _jsx(Swatch, { color: secondColor, className: "w-8 h-8", isSelected: currentColorSelected === SELECTED_COLOR.SECOND_COLOR, onChange: function () { return setCurrentSelectedColor(SELECTED_COLOR.SECOND_COLOR); }, "aria-label": locale.colorPicker.selectSecondColorAriaLabel }) }))] })), _jsx(Box, { style: { background: getGradientColorString(gradientColorObj) }, className: "mb-4 w-full h-6 rounded-48" }), _jsx(CustomColorSelector, { color: currentColorAsRgb, onChange: handleCustomColorChange, onChangeComplete: handleCustomColorChangeComplete, enableAlphaSelector: enableAlphaSelector })] }));
|
|
74
77
|
});
|
|
75
78
|
GradientColorPicker.displayName = 'GradientColorPicker';
|
|
76
79
|
export default GradientColorPicker;
|
|
@@ -7,5 +7,7 @@ export type SwatchProps = {
|
|
|
7
7
|
onChange: (color?: string) => void | (() => void);
|
|
8
8
|
className?: ClassName;
|
|
9
9
|
style?: Styles;
|
|
10
|
+
tabIndex?: number;
|
|
11
|
+
'aria-label'?: string;
|
|
10
12
|
};
|
|
11
|
-
export declare const Swatch: import("react").MemoExoticComponent<({ color, isSelected, onChange, className, ...props }: SwatchProps) => ReactElement>;
|
|
13
|
+
export declare const Swatch: import("react").MemoExoticComponent<({ color, isSelected, onChange, className, tabIndex, "aria-label": ariaLabelProp, ...props }: SwatchProps) => ReactElement>;
|
|
@@ -5,18 +5,21 @@ import { memo, useCallback } from 'react';
|
|
|
5
5
|
import { Box } from '../box';
|
|
6
6
|
import TransparentBackgroundIcon from '../icon/components/transparentBackground';
|
|
7
7
|
import { RESET_COLOR } from './colors';
|
|
8
|
+
import { useLocale } from '../locale';
|
|
8
9
|
export var Swatch = memo(function (_a) {
|
|
9
|
-
var color = _a.color, isSelected = _a.isSelected, onChange = _a.onChange, className = _a.className, props = __rest(_a, ["color", "isSelected", "onChange", "className"]);
|
|
10
|
+
var color = _a.color, isSelected = _a.isSelected, onChange = _a.onChange, className = _a.className, tabIndex = _a.tabIndex, ariaLabelProp = _a["aria-label"], props = __rest(_a, ["color", "isSelected", "onChange", "className", "tabIndex", 'aria-label']);
|
|
11
|
+
var locale = useLocale();
|
|
10
12
|
var handleChange = useCallback(function () { return onChange(color); }, [color, onChange]);
|
|
13
|
+
var isReset = !color || color === RESET_COLOR;
|
|
14
|
+
var ariaLabel = ariaLabelProp !== null && ariaLabelProp !== void 0 ? ariaLabelProp : (isReset ? locale.colorPicker.resetButtonLabel : color);
|
|
11
15
|
var swatchInnerEl = _jsx(Box, { className: "h-full w-full rounded-full", style: { backgroundColor: color } });
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
swatchInnerEl = _jsx(TransparentBackgroundIcon, { size: 20 });
|
|
16
|
+
if (isReset) {
|
|
17
|
+
swatchInnerEl = _jsx(TransparentBackgroundIcon, { size: 20, "aria-hidden": true });
|
|
15
18
|
}
|
|
16
19
|
return (_jsx(BaseButton, __assign({ onClick: handleChange, "data-testid": "swatch-".concat(color), className: [
|
|
17
20
|
'z-0 cursor-pointer h-5 w-5 rounded-full flex justify-center items-center p-px border-1 border-solid spr-border-primary hover:spr-border-quaternary',
|
|
18
21
|
'focus-visible:outline-1 focus-visible:-outline-offset-1',
|
|
19
22
|
isSelected ? 'spr-border-quinary' : '',
|
|
20
23
|
className,
|
|
21
|
-
], "aria-checked": isSelected, tabIndex: 0 }, props, { children: swatchInnerEl })));
|
|
24
|
+
], role: "radio", "aria-checked": isSelected, "aria-label": ariaLabel, tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : (isSelected ? 0 : -1) }, props, { children: swatchInnerEl })));
|
|
22
25
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KeyboardEvent } from 'react';
|
|
2
|
+
import type { Direction } from '@sprinklrjs/spaceweb-themes/types';
|
|
3
|
+
/**
|
|
4
|
+
* APG radio pattern: one tab stop, arrows move focus and selection within the group.
|
|
5
|
+
* https://www.w3.org/WAI/ARIA/apg/patterns/radio/
|
|
6
|
+
*/
|
|
7
|
+
export declare const handleSwatchGroupKeyDown: (event: KeyboardEvent<HTMLElement>, direction?: Direction) => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** +1 for “next” in DOM order, −1 for “previous”; horizontal arrows flip in RTL (see tabs keyboard nav). */
|
|
2
|
+
var getArrowDelta = function (key, direction) {
|
|
3
|
+
var horizontalStep = direction === 'rtl' ? -1 : 1;
|
|
4
|
+
switch (key) {
|
|
5
|
+
case 'ArrowUp':
|
|
6
|
+
return -1;
|
|
7
|
+
case 'ArrowDown':
|
|
8
|
+
return 1;
|
|
9
|
+
case 'ArrowLeft':
|
|
10
|
+
return -horizontalStep;
|
|
11
|
+
case 'ArrowRight':
|
|
12
|
+
return horizontalStep;
|
|
13
|
+
default:
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* APG radio pattern: one tab stop, arrows move focus and selection within the group.
|
|
19
|
+
* https://www.w3.org/WAI/ARIA/apg/patterns/radio/
|
|
20
|
+
*/
|
|
21
|
+
export var handleSwatchGroupKeyDown = function (event, direction) {
|
|
22
|
+
if (direction === void 0) { direction = 'ltr'; }
|
|
23
|
+
var delta = getArrowDelta(event.key, direction);
|
|
24
|
+
if (delta === null) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
var radios = Array.from(event.currentTarget.querySelectorAll('[role="radio"]'));
|
|
28
|
+
if (radios.length === 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
var currentIndex = radios.findIndex(function (radio) { return radio === event.target || radio.contains(event.target); });
|
|
32
|
+
if (currentIndex === -1) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
var nextRadio = radios[(currentIndex + delta + radios.length) % radios.length];
|
|
37
|
+
nextRadio.focus();
|
|
38
|
+
nextRadio.click();
|
|
39
|
+
};
|
|
@@ -13,9 +13,12 @@ type DateInputProps = {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
size?: InputSize;
|
|
15
15
|
formatString?: string;
|
|
16
|
+
id?: string;
|
|
17
|
+
'aria-labelledby'?: string;
|
|
18
|
+
'aria-describedby'?: string;
|
|
16
19
|
};
|
|
17
20
|
/**
|
|
18
21
|
* This component renders the Date dropdown inside the DatePicker Popover.
|
|
19
22
|
*/
|
|
20
|
-
export declare const DateInput: React.MemoExoticComponent<({ dateHelpers, date, onChange, maxDate, minDate, disabled, size, formatString, }: DateInputProps) => JSX.Element>;
|
|
23
|
+
export declare const DateInput: React.MemoExoticComponent<({ dateHelpers, date, onChange, maxDate, minDate, disabled, size, formatString, id, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, }: DateInputProps) => JSX.Element>;
|
|
21
24
|
export {};
|