@sprinklrjs/spaceweb 14.12.1 → 14.12.3
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/a11y/StatusMessage.d.ts +1 -1
- package/a11y/StatusMessage.js +2 -2
- package/a11y/types.d.ts +5 -0
- package/baseui/layer/tether.js +5 -5
- package/esm/a11y/StatusMessage.d.ts +1 -1
- package/esm/a11y/StatusMessage.js +2 -2
- package/esm/a11y/types.d.ts +5 -0
- package/esm/baseui/layer/tether.js +5 -5
- package/esm/input/base-input.js +1 -1
- package/esm/list/divider.js +3 -1
- package/esm/list/list.js +11 -14
- package/esm/list/utils.d.ts +8 -0
- package/esm/list/utils.js +28 -1
- package/esm/menu/menu-item.js +1 -1
- package/esm/phone-input/constants.d.ts +476 -0
- package/esm/phone-input/constants.js +397 -105
- package/esm/phone-input/country-select.js +7 -4
- package/esm/phone-input/types.d.ts +24 -1
- package/esm/phone-input/useStatefulPhoneInput.d.ts +1 -1
- package/esm/phone-input/utils.d.ts +25 -1
- package/esm/phone-input/utils.js +49 -0
- package/esm/snackbar/Snackbar.d.ts +1 -1
- package/esm/snackbar/Snackbar.js +5 -10
- package/esm/snackbar/snackbarContext.d.ts +1 -1
- package/esm/snackbar/snackbarContext.js +7 -2
- package/esm/snackbar/types.d.ts +6 -0
- package/esm/snackbar/useSnackbar.d.ts +2 -1
- package/esm/snackbar/useSnackbar.js +12 -5
- package/input/base-input.js +1 -1
- package/list/divider.js +3 -1
- package/list/list.js +10 -13
- package/list/utils.d.ts +8 -0
- package/list/utils.js +31 -1
- package/menu/menu-item.js +1 -1
- package/package.json +2 -2
- package/phone-input/constants.d.ts +476 -0
- package/phone-input/constants.js +397 -105
- package/phone-input/country-select.js +5 -2
- package/phone-input/types.d.ts +24 -1
- package/phone-input/useStatefulPhoneInput.d.ts +1 -1
- package/phone-input/utils.d.ts +25 -1
- package/phone-input/utils.js +52 -1
- package/snackbar/Snackbar.d.ts +1 -1
- package/snackbar/Snackbar.js +5 -10
- package/snackbar/snackbarContext.d.ts +1 -1
- package/snackbar/snackbarContext.js +7 -2
- package/snackbar/types.d.ts +6 -0
- package/snackbar/useSnackbar.d.ts +2 -1
- package/snackbar/useSnackbar.js +12 -5
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -8,6 +8,7 @@ var pick_1 = tslib_1.__importDefault(require("lodash/pick"));
|
|
|
8
8
|
var select_1 = require("../select");
|
|
9
9
|
var list_1 = require("../list");
|
|
10
10
|
var typography_1 = require("../typography");
|
|
11
|
+
var box_1 = require("../box");
|
|
11
12
|
var flag_container_1 = tslib_1.__importDefault(require("./flag-container"));
|
|
12
13
|
var locale_1 = require("../locale");
|
|
13
14
|
var overrides_1 = require("../overrides");
|
|
@@ -15,8 +16,10 @@ var utils_1 = require("./utils");
|
|
|
15
16
|
var constants_1 = require("./constants");
|
|
16
17
|
var types_1 = require("../popover/types");
|
|
17
18
|
var SelectListItem = React.forwardRef(function (_a, ref) {
|
|
18
|
-
var mapIsoToLabel = _a.mapIsoToLabel,
|
|
19
|
-
|
|
19
|
+
var mapIsoToLabel = _a.mapIsoToLabel, country = _a.$item, rest = tslib_1.__rest(_a, ["mapIsoToLabel", "$item"]);
|
|
20
|
+
var id = country.id, dialCode = country.dialCode;
|
|
21
|
+
var _b = (0, utils_1.resolveCountryLabelParts)(country, mapIsoToLabel), primaryName = _b.primaryName, nativeName = _b.nativeName, nativeLang = _b.nativeLang;
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(list_1.ListItem, tslib_1.__assign({}, rest, { startEnhancer: (0, utils_1.iso2FlagEmoji)(id), ref: ref }, { children: [dialCode, (0, jsx_runtime_1.jsxs)(typography_1.Typography, tslib_1.__assign({ "data-testid": id, "data-entity-type": "country-label", className: "spr-text-03 ml-1" }, { children: ["(", primaryName, nativeName && nativeLang ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [' (', (0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ "$as": "span", lang: nativeLang }, { children: nativeName })), ")"] })) : null, (0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ "$as": "span" }, { children: ")" }))] }))] })));
|
|
20
23
|
});
|
|
21
24
|
var CountrySelect = function (props) {
|
|
22
25
|
var size = props.size, disabled = props.disabled, inputRef = props.inputRef, onChange = props.onChange, countries = props.countries, value = props.value, mapIsoToLabel = props.mapIsoToLabel, maxDropdownHeight = props.maxDropdownHeight, maxDropdownWidth = props.maxDropdownWidth, overrides = props.overrides;
|
package/phone-input/types.d.ts
CHANGED
|
@@ -7,6 +7,14 @@ export type Country = {
|
|
|
7
7
|
id: keyof typeof COUNTRIES;
|
|
8
8
|
label: string;
|
|
9
9
|
dialCode: string;
|
|
10
|
+
/**
|
|
11
|
+
* The portion of `label` (without the wrapping parentheses) that is rendered in a language
|
|
12
|
+
* other than the component's default (English), e.g. `'भारत'` for India. Used to apply the
|
|
13
|
+
* correct `lang` attribute to that segment for screen reader pronunciation (WCAG 3.1.2).
|
|
14
|
+
*/
|
|
15
|
+
nativeName?: string;
|
|
16
|
+
/** BCP 47 language tag for `nativeName`, e.g. `'hi'` for Hindi. */
|
|
17
|
+
nativeLang?: string;
|
|
10
18
|
};
|
|
11
19
|
export type State = {
|
|
12
20
|
country: Country;
|
|
@@ -22,11 +30,26 @@ export type PhoneInputOverrides = {
|
|
|
22
30
|
FlagContainer?: Override<SharedProps & Record<string, any>>;
|
|
23
31
|
DialCode?: Override<SharedProps & Record<string, any>>;
|
|
24
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Custom country label for `mapIsoToLabel`. Provide both `nativeName` and `nativeLang` when a
|
|
35
|
+
* native-language segment should be marked with `lang` (WCAG 3.1.2); otherwise only `label` is used.
|
|
36
|
+
*/
|
|
37
|
+
export type CustomCountryLabel = {
|
|
38
|
+
label: string;
|
|
39
|
+
nativeName?: string;
|
|
40
|
+
nativeLang?: string;
|
|
41
|
+
};
|
|
25
42
|
export type PhoneInputProps = Omit<InputProps, 'value' | 'onChange'> & {
|
|
26
43
|
onInputChange?: (event: React.SyntheticEvent<HTMLInputElement>) => unknown;
|
|
27
44
|
onChange?: (value: Value) => void;
|
|
28
45
|
value?: Value;
|
|
29
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Maps an ISO country code to the dropdown label. Return a `string` to replace the whole label
|
|
48
|
+
* (legacy behavior), or a `CustomCountryLabel` with both `nativeName` and `nativeLang` to mark
|
|
49
|
+
* a native-language segment with `lang` (WCAG 3.1.2). Object results missing either native field
|
|
50
|
+
* are flattened into a single label string.
|
|
51
|
+
*/
|
|
52
|
+
mapIsoToLabel?: (iso: string) => string | CustomCountryLabel;
|
|
30
53
|
maxDropdownHeight?: string;
|
|
31
54
|
countries?: Array<Country>;
|
|
32
55
|
maxDropdownWidth?: string;
|
|
@@ -9,7 +9,7 @@ declare const useStatefulPhoneInput: ({ clearable, disabled, id, initialState, i
|
|
|
9
9
|
intent: import("..").Intent | undefined;
|
|
10
10
|
maxDropdownHeight: string;
|
|
11
11
|
maxDropdownWidth: string;
|
|
12
|
-
mapIsoToLabel: ((iso: string) => string) | undefined;
|
|
12
|
+
mapIsoToLabel: ((iso: string) => string | import("./types").CustomCountryLabel) | undefined;
|
|
13
13
|
name: string | undefined;
|
|
14
14
|
overrides: import("../input").BaseInputOverrides & {
|
|
15
15
|
Root?: import("../overrides").Override<import("../input").SharedProps & Record<string, any>> | undefined;
|
package/phone-input/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Value as ValueT } from '../select/types';
|
|
2
|
-
import type { Value, Country } from './types';
|
|
2
|
+
import type { Value, Country, CustomCountryLabel } from './types';
|
|
3
3
|
export declare const iso2FlagEmoji: (iso: string) => string | undefined;
|
|
4
4
|
export declare const sanitize: (value?: string) => string;
|
|
5
5
|
export declare const getPhoneNumberWithCountryDialCode: (value: Value) => string | undefined;
|
|
@@ -11,3 +11,27 @@ export declare const getDefaultValue: (countries?: Country[]) => {
|
|
|
11
11
|
country: Country;
|
|
12
12
|
phoneNumber: string;
|
|
13
13
|
};
|
|
14
|
+
export type CountryLabelParts = {
|
|
15
|
+
primaryName: string;
|
|
16
|
+
nativeName?: string;
|
|
17
|
+
nativeLang?: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Splits a country's `label` (e.g. `'India (भारत)'`) into the default-language name and the
|
|
21
|
+
* trailing native-language segment (if any), so the native segment can be given its own `lang`
|
|
22
|
+
* attribute for correct screen reader pronunciation (WCAG 3.1.2 - Language of Parts).
|
|
23
|
+
*
|
|
24
|
+
* Requires both `nativeName` and `nativeLang`. Falls back to the whole `label` as `primaryName`
|
|
25
|
+
* if either is missing or `nativeName` is not actually a trailing `label` suffix, so incomplete
|
|
26
|
+
* data never breaks rendering or ships a native segment without a language tag.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getCountryLabelParts: ({ label, nativeName, nativeLang }: Country) => CountryLabelParts;
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the label parts to render for a country option, honoring an optional `mapIsoToLabel`
|
|
31
|
+
* override (string or `{ label, nativeName?, nativeLang? }`).
|
|
32
|
+
*
|
|
33
|
+
* String overrides replace the whole label (legacy behavior). Object overrides only split out a
|
|
34
|
+
* `lang`-tagged native segment when both `nativeName` and `nativeLang` are provided; otherwise the
|
|
35
|
+
* visible text is flattened into `primaryName` so display stays correct without invalid markup.
|
|
36
|
+
*/
|
|
37
|
+
export declare const resolveCountryLabelParts: (country: Country, mapIsoToLabel?: ((iso: string) => string | CustomCountryLabel) | undefined) => CountryLabelParts;
|
package/phone-input/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultValue = exports.countrySelectFilterOptions = exports.getPhoneNumberWithCountryDialCode = exports.sanitize = exports.iso2FlagEmoji = void 0;
|
|
3
|
+
exports.resolveCountryLabelParts = exports.getCountryLabelParts = exports.getDefaultValue = exports.countrySelectFilterOptions = exports.getPhoneNumberWithCountryDialCode = exports.sanitize = exports.iso2FlagEmoji = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
6
6
|
var default_filter_options_1 = require("../select/utils/default-filter-options");
|
|
@@ -38,3 +38,54 @@ var getDefaultValue = function (countries) {
|
|
|
38
38
|
return countries && !(0, isEmpty_1.default)(countries) ? { country: constants_1.COUNTRIES[countries[0].id], phoneNumber: '' } : default_props_1.defaultValue;
|
|
39
39
|
};
|
|
40
40
|
exports.getDefaultValue = getDefaultValue;
|
|
41
|
+
/**
|
|
42
|
+
* Splits a country's `label` (e.g. `'India (भारत)'`) into the default-language name and the
|
|
43
|
+
* trailing native-language segment (if any), so the native segment can be given its own `lang`
|
|
44
|
+
* attribute for correct screen reader pronunciation (WCAG 3.1.2 - Language of Parts).
|
|
45
|
+
*
|
|
46
|
+
* Requires both `nativeName` and `nativeLang`. Falls back to the whole `label` as `primaryName`
|
|
47
|
+
* if either is missing or `nativeName` is not actually a trailing `label` suffix, so incomplete
|
|
48
|
+
* data never breaks rendering or ships a native segment without a language tag.
|
|
49
|
+
*/
|
|
50
|
+
var getCountryLabelParts = function (_a) {
|
|
51
|
+
var label = _a.label, nativeName = _a.nativeName, nativeLang = _a.nativeLang;
|
|
52
|
+
if (!nativeName || !nativeLang) {
|
|
53
|
+
return { primaryName: label };
|
|
54
|
+
}
|
|
55
|
+
var nativeNameSuffix = "(".concat(nativeName, ")");
|
|
56
|
+
var suffixStartIndex = label.lastIndexOf(nativeNameSuffix);
|
|
57
|
+
var isSuffixAtEnd = suffixStartIndex !== -1 && suffixStartIndex + nativeNameSuffix.length === label.length;
|
|
58
|
+
if (!isSuffixAtEnd) {
|
|
59
|
+
return { primaryName: label };
|
|
60
|
+
}
|
|
61
|
+
return { primaryName: label.slice(0, suffixStartIndex).trimEnd(), nativeName: nativeName, nativeLang: nativeLang };
|
|
62
|
+
};
|
|
63
|
+
exports.getCountryLabelParts = getCountryLabelParts;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves the label parts to render for a country option, honoring an optional `mapIsoToLabel`
|
|
66
|
+
* override (string or `{ label, nativeName?, nativeLang? }`).
|
|
67
|
+
*
|
|
68
|
+
* String overrides replace the whole label (legacy behavior). Object overrides only split out a
|
|
69
|
+
* `lang`-tagged native segment when both `nativeName` and `nativeLang` are provided; otherwise the
|
|
70
|
+
* visible text is flattened into `primaryName` so display stays correct without invalid markup.
|
|
71
|
+
*/
|
|
72
|
+
var resolveCountryLabelParts = function (country, mapIsoToLabel) {
|
|
73
|
+
if (!mapIsoToLabel) {
|
|
74
|
+
return (0, exports.getCountryLabelParts)(country);
|
|
75
|
+
}
|
|
76
|
+
var mapped = mapIsoToLabel(country.id);
|
|
77
|
+
if (typeof mapped === 'string') {
|
|
78
|
+
return { primaryName: mapped };
|
|
79
|
+
}
|
|
80
|
+
if (!mapped.nativeName || !mapped.nativeLang) {
|
|
81
|
+
return {
|
|
82
|
+
primaryName: mapped.nativeName ? "".concat(mapped.label, " (").concat(mapped.nativeName, ")") : mapped.label,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
primaryName: mapped.label,
|
|
87
|
+
nativeName: mapped.nativeName,
|
|
88
|
+
nativeLang: mapped.nativeLang,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
exports.resolveCountryLabelParts = resolveCountryLabelParts;
|
package/snackbar/Snackbar.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactElement } from 'react';
|
|
2
2
|
import type { SnackbarProps } from './types';
|
|
3
3
|
declare const Snackbar: {
|
|
4
|
-
({ intent: _intent, message: _message, disableManualClose, placement, autoHide, autoHideDuration, hideOnClickAway, overrides: _overrides, onClose, }: SnackbarProps): ReactElement | null;
|
|
4
|
+
({ intent: _intent, message: _message, id, disableManualClose, placement, autoHide, autoHideDuration, hideOnClickAway, overrides: _overrides, onClose, }: SnackbarProps): ReactElement | null;
|
|
5
5
|
__standard: string;
|
|
6
6
|
};
|
|
7
7
|
export default Snackbar;
|
package/snackbar/Snackbar.js
CHANGED
|
@@ -21,11 +21,12 @@ var locale_1 = require("../locale");
|
|
|
21
21
|
var style_1 = require("../style");
|
|
22
22
|
var theme_1 = require("../theme");
|
|
23
23
|
var Snackbar = function (_a) {
|
|
24
|
-
var _b = _a.intent, _intent = _b === void 0 ? 'success' : _b, _message = _a.message, _c = _a.disableManualClose, disableManualClose = _c === void 0 ? false : _c, _d = _a.placement, placement = _d === void 0 ? 'bottom' : _d, _e = _a.autoHide, autoHide = _e === void 0 ? true : _e, _f = _a.autoHideDuration, autoHideDuration = _f === void 0 ? constants_1.TYPE_TO_HIDE_DURATION[_intent] : _f, _g = _a.hideOnClickAway, hideOnClickAway = _g === void 0 ? true : _g, _overrides = _a.overrides, _h = _a.onClose, onClose = _h === void 0 ? noop_1.default : _h;
|
|
24
|
+
var _b = _a.intent, _intent = _b === void 0 ? 'success' : _b, _message = _a.message, id = _a.id, _c = _a.disableManualClose, disableManualClose = _c === void 0 ? false : _c, _d = _a.placement, placement = _d === void 0 ? 'bottom' : _d, _e = _a.autoHide, autoHide = _e === void 0 ? true : _e, _f = _a.autoHideDuration, autoHideDuration = _f === void 0 ? constants_1.TYPE_TO_HIDE_DURATION[_intent] : _f, _g = _a.hideOnClickAway, hideOnClickAway = _g === void 0 ? true : _g, _overrides = _a.overrides, _h = _a.onClose, onClose = _h === void 0 ? noop_1.default : _h;
|
|
25
25
|
var outerTheme = (0, style_1.useStyle)().theme;
|
|
26
26
|
var inverseTheme = (0, react_1.useMemo)(function () { return ((0, themeHelpers_1.isDarkTheme)(outerTheme) ? light_1.default : dark_1.default); }, [outerTheme]);
|
|
27
27
|
var _j = (0, useSnackbar_1.default)({
|
|
28
28
|
intent: _intent,
|
|
29
|
+
id: id,
|
|
29
30
|
message: _message,
|
|
30
31
|
overrides: _overrides,
|
|
31
32
|
autoHide: autoHide,
|
|
@@ -54,18 +55,12 @@ var Snackbar = function (_a) {
|
|
|
54
55
|
var _s = tslib_1.__read((0, overrides_1.useOverrides)(overrides === null || overrides === void 0 ? void 0 : overrides.CloseIcon, close_1.default), 2), Close = _s[0], closeProps = _s[1];
|
|
55
56
|
var _t = tslib_1.__read((0, overrides_1.useOverrides)(overrides === null || overrides === void 0 ? void 0 : overrides.CloseIconButton, button_1.IconButton), 2), CloseIconButton = _t[0], closeIconButtonProps = _t[1];
|
|
56
57
|
var locale = (0, locale_1.useLocale)();
|
|
57
|
-
var role = constants_1.INTENT_TO_ROLE[intent];
|
|
58
|
-
// We don't know if the message contains any interactive elements, so we only
|
|
59
|
-
// delegate to the shared screen-reader announcer when the message is a string.
|
|
60
58
|
var isStringMessage = typeof message === 'string';
|
|
61
|
-
// Announce string messages through the shared global live region instead of
|
|
62
|
-
// hand-rolling sr-only regions here. The announcer keeps a single source of
|
|
63
|
-
// truth for status messages (WCAG 4.1.3) and re-announces repeated text.
|
|
64
59
|
(0, react_1.useEffect)(function () {
|
|
65
|
-
if (
|
|
66
|
-
(0, a11y_1.announce)(
|
|
60
|
+
if (typeof _message === 'string' && _message) {
|
|
61
|
+
(0, a11y_1.announce)(_message, { politeness: constants_1.INTENT_TO_ROLE[_intent] === 'alert' ? 'assertive' : 'polite' });
|
|
67
62
|
}
|
|
68
|
-
}, [
|
|
63
|
+
}, [_message, _intent, id]);
|
|
69
64
|
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: shouldRender ? ((0, jsx_runtime_1.jsx)(layer_2.LayersManager, tslib_1.__assign({ zIndex: layer_2.Z_INDEX.SNACKBAR }, { children: (0, jsx_runtime_1.jsx)(Layer, tslib_1.__assign({}, sharedProps, layerProps, { children: (0, jsx_runtime_1.jsx)(PlacementContainer, tslib_1.__assign({ "data-spaceweb": "snackbar", "data-testid": "snackbar" }, sharedProps, placementContainerProps, { children: (0, jsx_runtime_1.jsx)(SnackbarContainer, tslib_1.__assign({}, snackbarContainerProps, { ref: snackbarContainerRef }, sharedProps, snackbarContainerOverrideProps, { style: [styled_component_1.getSnackbarContainerAnimationStyle, snackbarContainerOverrideProps.style] }, { children: (0, jsx_runtime_1.jsx)(theme_1.ThemeProvider, tslib_1.__assign({ theme: inverseTheme }, { children: (0, jsx_runtime_1.jsxs)(ContentContainer, tslib_1.__assign({}, sharedProps, contentContainerProps, { children: [(0, jsx_runtime_1.jsx)(IconsContainer, tslib_1.__assign({}, sharedProps, iconsContainerProps, { children: (0, jsx_runtime_1.jsx)(IntentIcon, tslib_1.__assign({ size: 20, className: styled_component_1.getIconStyles }, sharedProps, intentIconProps)) })), (0, jsx_runtime_1.jsx)(Message
|
|
70
65
|
// The sr-only region handles screen reader announcements
|
|
71
66
|
// to prevent the message from being read twice
|
|
@@ -14,15 +14,20 @@ var SnackbarProvider = function (_a) {
|
|
|
14
14
|
var children = _a.children;
|
|
15
15
|
var _b = tslib_1.__read((0, react_1.useState)(''), 2), message = _b[0], setMessage = _b[1];
|
|
16
16
|
var _c = tslib_1.__read((0, react_1.useState)('success'), 2), intent = _c[0], setIntent = _c[1];
|
|
17
|
+
var _d = tslib_1.__read((0, react_1.useState)(0), 2), id = _d[0], setId = _d[1];
|
|
17
18
|
var notify = (0, react_1.useCallback)(function (_a) {
|
|
18
19
|
var _b = _a.intent, _intent = _b === void 0 ? 'success' : _b, _message = _a.message;
|
|
20
|
+
setId(function (prev) { return prev + 1; });
|
|
19
21
|
setMessage(_message);
|
|
20
22
|
setIntent(_intent);
|
|
21
23
|
}, []);
|
|
22
|
-
var onClose = (0, react_1.useCallback)(function () {
|
|
24
|
+
var onClose = (0, react_1.useCallback)(function (reason) {
|
|
25
|
+
// Keep content when swapping instances; only clear on real dismiss.
|
|
26
|
+
if (reason === 'messageChange')
|
|
27
|
+
return;
|
|
23
28
|
setMessage('');
|
|
24
29
|
setIntent('success');
|
|
25
30
|
}, []);
|
|
26
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SnackbarContext.Provider, tslib_1.__assign({ value: notify }, { children: children })), message && intent ? (0, jsx_runtime_1.jsx)(_1.Snackbar, { message: message, intent: intent, onClose: onClose }) : null] }));
|
|
31
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SnackbarContext.Provider, tslib_1.__assign({ value: notify }, { children: children })), message && intent ? (0, jsx_runtime_1.jsx)(_1.Snackbar, { id: id, message: message, intent: intent, onClose: onClose }) : null] }));
|
|
27
32
|
};
|
|
28
33
|
exports.SnackbarProvider = SnackbarProvider;
|
package/snackbar/types.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ export type SnackbarOverrides = {
|
|
|
26
26
|
};
|
|
27
27
|
export type SnackbarProps = {
|
|
28
28
|
message?: React.ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Opaque instance identity. Bump this (e.g. increment a counter) when re-showing
|
|
31
|
+
* the same `message` so the snackbar re-opens and re-announces for screen readers.
|
|
32
|
+
* `SnackbarProvider` / `useNotification` set this automatically on every `notify()`.
|
|
33
|
+
*/
|
|
34
|
+
id?: string | number;
|
|
29
35
|
intent?: Intent;
|
|
30
36
|
hideOnClickAway?: boolean;
|
|
31
37
|
disableManualClose?: boolean;
|
|
@@ -5,6 +5,7 @@ type UseSnackbarParams = {
|
|
|
5
5
|
autoHideDuration: number;
|
|
6
6
|
hideOnClickAway: boolean;
|
|
7
7
|
intent: Intent;
|
|
8
|
+
id?: string | number;
|
|
8
9
|
message?: React.ReactNode;
|
|
9
10
|
onClose?: (reason: HideReason) => void;
|
|
10
11
|
overrides?: SnackbarOverrides;
|
|
@@ -23,5 +24,5 @@ type UseSnackbarReturnValue = {
|
|
|
23
24
|
intent: Intent;
|
|
24
25
|
overrides?: SnackbarOverrides;
|
|
25
26
|
};
|
|
26
|
-
declare const useSnackbar: ({ autoHide, autoHideDuration, hideOnClickAway, intent: nextIntent, message: nextMessage, onClose, overrides: nextOverrides, }: UseSnackbarParams) => UseSnackbarReturnValue;
|
|
27
|
+
declare const useSnackbar: ({ autoHide, autoHideDuration, hideOnClickAway, intent: nextIntent, id, message: nextMessage, onClose, overrides: nextOverrides, }: UseSnackbarParams) => UseSnackbarReturnValue;
|
|
27
28
|
export default useSnackbar;
|
package/snackbar/useSnackbar.js
CHANGED
|
@@ -35,10 +35,10 @@ var useAutoHide = function (_a) {
|
|
|
35
35
|
}, [open, autoHide, autoHideDuration, autoHideTimeoutRef]);
|
|
36
36
|
};
|
|
37
37
|
var useDomVisibility = function (_a) {
|
|
38
|
-
var message = _a.message, open = _a.open, enter = _a.enter, handleClose = _a.handleClose, intent = _a.intent;
|
|
38
|
+
var message = _a.message, open = _a.open, enter = _a.enter, handleClose = _a.handleClose, intent = _a.intent, id = _a.id;
|
|
39
39
|
var _b = tslib_1.__read((0, react_1.useState)(false), 2), domVisibility = _b[0], setDomVisibility = _b[1];
|
|
40
40
|
var removeFromDomTimeoutRef = (0, react_1.useRef)();
|
|
41
|
-
// handle exit, enter on message change
|
|
41
|
+
// handle exit, enter on message / intent / id change
|
|
42
42
|
(0, react_1.useEffect)(function () {
|
|
43
43
|
if (!message)
|
|
44
44
|
return undefined;
|
|
@@ -53,7 +53,7 @@ var useDomVisibility = function (_a) {
|
|
|
53
53
|
open && handleClose('messageChange');
|
|
54
54
|
return function () { return window.clearTimeout(timeoutId); };
|
|
55
55
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- handleClose not required
|
|
56
|
-
}, [message, intent]);
|
|
56
|
+
}, [message, intent, id]);
|
|
57
57
|
// remove from DOM, once transition is over
|
|
58
58
|
(0, useUpdateEffect_1.default)(function () {
|
|
59
59
|
if (open)
|
|
@@ -66,7 +66,7 @@ var useDomVisibility = function (_a) {
|
|
|
66
66
|
return domVisibility;
|
|
67
67
|
};
|
|
68
68
|
var useSnackbar = function (_a) {
|
|
69
|
-
var autoHide = _a.autoHide, autoHideDuration = _a.autoHideDuration, hideOnClickAway = _a.hideOnClickAway, nextIntent = _a.intent, nextMessage = _a.message, onClose = _a.onClose, nextOverrides = _a.overrides;
|
|
69
|
+
var autoHide = _a.autoHide, autoHideDuration = _a.autoHideDuration, hideOnClickAway = _a.hideOnClickAway, nextIntent = _a.intent, id = _a.id, nextMessage = _a.message, onClose = _a.onClose, nextOverrides = _a.overrides;
|
|
70
70
|
var _b = tslib_1.__read((0, react_1.useState)(false), 2), open = _b[0], setOpen = _b[1];
|
|
71
71
|
var _c = tslib_1.__read((0, react_1.useState)({
|
|
72
72
|
intent: nextIntent,
|
|
@@ -91,7 +91,14 @@ var useSnackbar = function (_a) {
|
|
|
91
91
|
};
|
|
92
92
|
useAutoHide({ open: open, handleClose: handleClose, autoHideTimeoutRef: autoHideTimeoutRef, autoHideDuration: autoHideDuration, autoHide: autoHide });
|
|
93
93
|
var snackbarContainerRef = useHideOnClickAway({ hideOnClickAway: hideOnClickAway, handleClose: handleClose, open: open });
|
|
94
|
-
var shouldRender = useDomVisibility({
|
|
94
|
+
var shouldRender = useDomVisibility({
|
|
95
|
+
handleClose: handleClose,
|
|
96
|
+
open: open,
|
|
97
|
+
intent: nextIntent,
|
|
98
|
+
id: id,
|
|
99
|
+
message: nextMessage,
|
|
100
|
+
enter: enter,
|
|
101
|
+
});
|
|
95
102
|
var handleMouseEnter = function () {
|
|
96
103
|
window.clearTimeout(autoHideTimeoutRef.current);
|
|
97
104
|
};
|