rsuite 6.0.0-canary-20241227 → 6.0.0-canary-20250103
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/AutoComplete/styles/index.css +8 -16
- package/Badge/styles/index.css +83 -17
- package/Badge/styles/index.less +68 -9
- package/Button/styles/index.css +5 -10
- package/Button/styles/mixin.less +1 -2
- package/CHANGELOG.md +18 -0
- package/Calendar/styles/index.css +6 -12
- package/Cascader/styles/index.css +8 -16
- package/CheckPicker/styles/index.css +8 -16
- package/CheckTree/styles/index.css +8 -16
- package/CheckTreePicker/styles/index.css +8 -16
- package/DatePicker/styles/index.css +9 -18
- package/DateRangePicker/styles/index.css +9 -18
- package/Dropdown/styles/index.css +5 -10
- package/IconButton/styles/index.css +7 -14
- package/InputGroup/styles/index.css +6 -12
- package/InputNumber/styles/index.css +6 -12
- package/InputPicker/styles/index.css +8 -16
- package/MultiCascadeTree/styles/index.css +8 -16
- package/MultiCascader/styles/index.css +8 -16
- package/Nav/styles/index.css +5 -10
- package/Navbar/styles/index.css +5 -10
- package/Pagination/styles/index.css +11 -22
- package/Rate/styles/index.css +16 -8
- package/Rate/styles/index.less +6 -2
- package/SelectPicker/styles/index.css +8 -16
- package/Stat/styles/index.css +7 -14
- package/Table/styles/index.css +2 -2
- package/Tabs/styles/index.css +5 -10
- package/Tag/styles/index.css +29 -21
- package/Tag/styles/index.less +6 -3
- package/TagInput/styles/index.css +8 -16
- package/TagPicker/styles/index.css +8 -16
- package/TimePicker/styles/index.css +9 -18
- package/TimeRangePicker/styles/index.css +9 -18
- package/Tree/styles/index.css +8 -16
- package/TreePicker/styles/index.css +8 -16
- package/Uploader/styles/index.css +7 -14
- package/cjs/Accordion/Accordion.js +1 -1
- package/cjs/AutoComplete/AutoComplete.d.ts +2 -2
- package/cjs/AutoComplete/Combobox.js +1 -1
- package/cjs/Badge/Badge.d.ts +40 -5
- package/cjs/Badge/Badge.js +30 -19
- package/cjs/Breadcrumb/Breadcrumb.js +1 -1
- package/cjs/Button/Button.d.ts +5 -1
- package/cjs/Button/Button.js +17 -3
- package/cjs/Card/Card.js +1 -1
- package/cjs/CascadeTree/utils.js +1 -1
- package/cjs/CustomProvider/CustomProvider.d.ts +12 -4
- package/cjs/CustomProvider/CustomProvider.js +4 -3
- package/cjs/DateInput/hooks/useDateInputState.js +10 -8
- package/cjs/DateInput/hooks/useKeyboardInputEvent.js +1 -0
- package/cjs/DatePicker/PredefinedRanges.js +1 -1
- package/cjs/DateRangePicker/DateRangePicker.js +1 -1
- package/cjs/Drawer/Drawer.d.ts +2 -2
- package/cjs/Drawer/Drawer.js +1 -1
- package/cjs/Drawer/DrawerBody.js +7 -5
- package/cjs/Drawer/DrawerFooter.js +7 -5
- package/cjs/Drawer/DrawerHeader.js +7 -5
- package/cjs/Drawer/DrawerTitle.js +7 -5
- package/cjs/Dropdown/Dropdown.d.ts +2 -2
- package/cjs/Dropdown/Dropdown.js +1 -1
- package/cjs/Dropdown/DropdownContext.d.ts +1 -1
- package/cjs/Dropdown/DropdownMenu.d.ts +2 -2
- package/cjs/Dropdown/DropdownToggle.d.ts +2 -2
- package/cjs/FlexboxGrid/FlexboxGrid.js +1 -1
- package/cjs/Form/Form.js +1 -1
- package/cjs/FormControl/FormControl.d.ts +2 -2
- package/cjs/FormErrorMessage/FormErrorMessage.d.ts +2 -2
- package/cjs/InlineEdit/EditableControls.js +1 -1
- package/cjs/InputGroup/InputGroup.js +1 -1
- package/cjs/InputNumber/InputNumber.js +1 -1
- package/cjs/InputPicker/InputPicker.js +0 -1
- package/cjs/InputPicker/TagList.js +1 -0
- package/cjs/InputPicker/TextBox.js +1 -0
- package/cjs/InputPicker/hooks/useMaxWidth.js +0 -1
- package/cjs/List/List.js +1 -1
- package/cjs/MaskedInput/MaskedInput.js +1 -0
- package/cjs/MaskedInput/conformToMask.js +0 -1
- package/cjs/Modal/Modal.js +1 -1
- package/cjs/Modal/utils.js +0 -1
- package/cjs/Nav/Nav.js +1 -1
- package/cjs/Nav/NavDropdown.d.ts +2 -2
- package/cjs/Nav/NavDropdown.js +1 -1
- package/cjs/Nav/NavDropdownToggle.d.ts +2 -2
- package/cjs/Navbar/Navbar.js +1 -1
- package/cjs/Navbar/NavbarDropdown.d.ts +2 -2
- package/cjs/Navbar/NavbarDropdown.js +1 -1
- package/cjs/Navbar/NavbarDropdownToggle.d.ts +2 -2
- package/cjs/Navbar/index.js +0 -0
- package/cjs/RangeSlider/RangeSlider.js +4 -4
- package/cjs/Rate/Character.js +6 -6
- package/cjs/Rate/Rate.d.ts +4 -4
- package/cjs/Rate/Rate.js +16 -15
- package/cjs/Sidenav/ExpandedSidenavDropdown.d.ts +2 -2
- package/cjs/Sidenav/Sidenav.js +1 -1
- package/cjs/Sidenav/SidenavDropdown.d.ts +2 -2
- package/cjs/Sidenav/SidenavDropdown.js +1 -1
- package/cjs/Sidenav/SidenavDropdownToggle.d.ts +2 -2
- package/cjs/Stack/HStack.js +1 -1
- package/cjs/Stack/Stack.js +1 -1
- package/cjs/Stack/VStack.js +1 -1
- package/cjs/Stat/Stat.js +1 -1
- package/cjs/Steps/Steps.js +1 -1
- package/cjs/Table/Table.js +2 -2
- package/cjs/Tabs/Tabs.js +8 -9
- package/cjs/Tag/Tag.d.ts +2 -2
- package/cjs/Tag/Tag.js +12 -6
- package/cjs/Timeline/Timeline.js +8 -5
- package/cjs/Tooltip/Tooltip.d.ts +2 -2
- package/cjs/Tree/hooks/useFlattenTree.js +1 -3
- package/cjs/Tree/hooks/useFocusTree.js +0 -1
- package/cjs/Tree/hooks/useTreeSearch.js +0 -1
- package/cjs/Uploader/UploadTrigger.js +13 -28
- package/cjs/Uploader/utils/ajaxUpload.js +1 -1
- package/cjs/internals/Disclosure/Disclosure.js +1 -0
- package/cjs/internals/Menu/useMenu.js +51 -49
- package/cjs/internals/Overlay/Overlay.d.ts +2 -2
- package/cjs/internals/Overlay/OverlayTrigger.d.ts +2 -2
- package/cjs/internals/Overlay/Position.d.ts +2 -2
- package/cjs/internals/Overlay/positionUtils.d.ts +2 -2
- package/cjs/internals/Picker/PickerToggle.d.ts +2 -2
- package/cjs/internals/Picker/PickerToggleTrigger.d.ts +2 -2
- package/cjs/internals/Picker/hooks/useFocusItemValue.js +1 -1
- package/cjs/internals/Picker/hooks/usePickerClassName.d.ts +2 -2
- package/cjs/internals/ScrollView/hooks/useScrollState.d.ts +1 -1
- package/cjs/internals/Tree/TreeView.js +2 -1
- package/cjs/internals/Tree/utils/getPathTowardsItem.js +1 -1
- package/cjs/internals/Windowing/AutoSizer.js +1 -0
- package/cjs/internals/Windowing/List.js +2 -1
- package/cjs/internals/hooks/useClassNames.d.ts +1 -2
- package/cjs/internals/hooks/useClassNames.js +0 -2
- package/cjs/internals/hooks/usePortal.js +1 -1
- package/cjs/internals/hooks/useToggleCaret.d.ts +2 -2
- package/cjs/internals/hooks/useToggleCaret.js +1 -1
- package/cjs/internals/hooks/useUpdateEffect.js +0 -1
- package/cjs/internals/hooks/useWillUnmount.js +0 -2
- package/cjs/internals/symbols.d.ts +1 -0
- package/cjs/internals/symbols.js +3 -2
- package/cjs/internals/types/colours.d.ts +10 -0
- package/cjs/internals/types/colours.js +15 -0
- package/cjs/internals/types/index.d.ts +6 -7
- package/cjs/internals/types/index.js +13 -1
- package/cjs/internals/types/placement.d.ts +5 -0
- package/cjs/internals/types/placement.js +4 -0
- package/cjs/internals/utils/BrowserDetection.d.ts +0 -2
- package/cjs/internals/utils/BrowserDetection.js +2 -12
- package/cjs/internals/utils/ReactChildren.js +0 -2
- package/cjs/internals/utils/colours.d.ts +21 -0
- package/cjs/internals/utils/colours.js +86 -0
- package/cjs/internals/utils/css.d.ts +13 -1
- package/cjs/internals/utils/css.js +42 -3
- package/cjs/internals/utils/getDOMNode.js +2 -2
- package/cjs/internals/utils/getSafeRegExpString.js +2 -1
- package/cjs/internals/utils/index.d.ts +2 -2
- package/cjs/internals/utils/index.js +17 -9
- package/cjs/toaster/ToastContainer.d.ts +8 -8
- package/cjs/toaster/ToastContainer.js +39 -36
- package/cjs/toaster/render.d.ts +2 -0
- package/cjs/toaster/render.js +25 -0
- package/cjs/toaster/toaster.js +29 -19
- package/cjs/useMediaQuery/useMediaQuery.js +1 -3
- package/cjs/useToaster/useToaster.js +10 -5
- package/dist/rsuite-no-reset-rtl.css +143 -74
- package/dist/rsuite-no-reset-rtl.min.css +1 -1
- package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
- package/dist/rsuite-no-reset.css +143 -74
- package/dist/rsuite-no-reset.min.css +1 -1
- package/dist/rsuite-no-reset.min.css.map +1 -1
- package/dist/rsuite-rtl.css +143 -74
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +143 -74
- package/dist/rsuite.js +113 -91
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Accordion/Accordion.js +1 -1
- package/esm/AutoComplete/AutoComplete.d.ts +2 -2
- package/esm/AutoComplete/Combobox.js +1 -1
- package/esm/Badge/Badge.d.ts +40 -5
- package/esm/Badge/Badge.js +28 -19
- package/esm/Breadcrumb/Breadcrumb.js +1 -1
- package/esm/Button/Button.d.ts +5 -1
- package/esm/Button/Button.js +18 -4
- package/esm/Card/Card.js +1 -1
- package/esm/CascadeTree/utils.js +1 -1
- package/esm/CustomProvider/CustomProvider.d.ts +12 -4
- package/esm/CustomProvider/CustomProvider.js +5 -4
- package/esm/DateInput/hooks/useDateInputState.js +10 -8
- package/esm/DateInput/hooks/useKeyboardInputEvent.js +1 -0
- package/esm/DatePicker/PredefinedRanges.js +1 -1
- package/esm/DateRangePicker/DateRangePicker.js +1 -1
- package/esm/Drawer/Drawer.d.ts +2 -2
- package/esm/Drawer/Drawer.js +1 -1
- package/esm/Drawer/DrawerBody.js +7 -5
- package/esm/Drawer/DrawerFooter.js +7 -5
- package/esm/Drawer/DrawerHeader.js +7 -5
- package/esm/Drawer/DrawerTitle.js +7 -5
- package/esm/Dropdown/Dropdown.d.ts +2 -2
- package/esm/Dropdown/Dropdown.js +1 -1
- package/esm/Dropdown/DropdownContext.d.ts +1 -1
- package/esm/Dropdown/DropdownMenu.d.ts +2 -2
- package/esm/Dropdown/DropdownToggle.d.ts +2 -2
- package/esm/FlexboxGrid/FlexboxGrid.js +1 -1
- package/esm/Form/Form.js +1 -1
- package/esm/FormControl/FormControl.d.ts +2 -2
- package/esm/FormErrorMessage/FormErrorMessage.d.ts +2 -2
- package/esm/InlineEdit/EditableControls.js +1 -1
- package/esm/InputGroup/InputGroup.js +1 -1
- package/esm/InputNumber/InputNumber.js +1 -1
- package/esm/InputPicker/InputPicker.js +0 -1
- package/esm/InputPicker/TagList.js +1 -0
- package/esm/InputPicker/TextBox.js +1 -0
- package/esm/InputPicker/hooks/useMaxWidth.js +0 -1
- package/esm/List/List.js +1 -1
- package/esm/MaskedInput/MaskedInput.js +1 -0
- package/esm/MaskedInput/conformToMask.js +0 -1
- package/esm/Modal/Modal.js +1 -1
- package/esm/Modal/utils.js +0 -1
- package/esm/Nav/Nav.js +1 -1
- package/esm/Nav/NavDropdown.d.ts +2 -2
- package/esm/Nav/NavDropdown.js +1 -1
- package/esm/Nav/NavDropdownToggle.d.ts +2 -2
- package/esm/Navbar/Navbar.js +1 -1
- package/esm/Navbar/NavbarDropdown.d.ts +2 -2
- package/esm/Navbar/NavbarDropdown.js +1 -1
- package/esm/Navbar/NavbarDropdownToggle.d.ts +2 -2
- package/esm/Navbar/index.js +0 -0
- package/esm/RangeSlider/RangeSlider.js +4 -4
- package/esm/Rate/Character.js +8 -8
- package/esm/Rate/Rate.d.ts +4 -4
- package/esm/Rate/Rate.js +19 -18
- package/esm/Sidenav/ExpandedSidenavDropdown.d.ts +2 -2
- package/esm/Sidenav/Sidenav.js +1 -1
- package/esm/Sidenav/SidenavDropdown.d.ts +2 -2
- package/esm/Sidenav/SidenavDropdown.js +1 -1
- package/esm/Sidenav/SidenavDropdownToggle.d.ts +2 -2
- package/esm/Stack/HStack.js +1 -1
- package/esm/Stack/Stack.js +1 -1
- package/esm/Stack/VStack.js +1 -1
- package/esm/Stat/Stat.js +1 -1
- package/esm/Steps/Steps.js +1 -1
- package/esm/Table/Table.js +2 -2
- package/esm/Tabs/Tabs.js +8 -9
- package/esm/Tag/Tag.d.ts +2 -2
- package/esm/Tag/Tag.js +10 -6
- package/esm/Timeline/Timeline.js +8 -5
- package/esm/Tooltip/Tooltip.d.ts +2 -2
- package/esm/Tree/hooks/useFlattenTree.js +1 -3
- package/esm/Tree/hooks/useFocusTree.js +0 -1
- package/esm/Tree/hooks/useTreeSearch.js +0 -1
- package/esm/Uploader/UploadTrigger.js +15 -30
- package/esm/Uploader/utils/ajaxUpload.js +1 -1
- package/esm/internals/Disclosure/Disclosure.js +1 -0
- package/esm/internals/Menu/useMenu.js +51 -49
- package/esm/internals/Overlay/Overlay.d.ts +2 -2
- package/esm/internals/Overlay/OverlayTrigger.d.ts +2 -2
- package/esm/internals/Overlay/Position.d.ts +2 -2
- package/esm/internals/Overlay/positionUtils.d.ts +2 -2
- package/esm/internals/Picker/PickerToggle.d.ts +2 -2
- package/esm/internals/Picker/PickerToggleTrigger.d.ts +2 -2
- package/esm/internals/Picker/hooks/useFocusItemValue.js +1 -1
- package/esm/internals/Picker/hooks/usePickerClassName.d.ts +2 -2
- package/esm/internals/ScrollView/hooks/useScrollState.d.ts +1 -1
- package/esm/internals/Tree/TreeView.js +2 -1
- package/esm/internals/Tree/utils/getPathTowardsItem.js +1 -1
- package/esm/internals/Windowing/AutoSizer.js +1 -0
- package/esm/internals/Windowing/List.js +2 -1
- package/esm/internals/hooks/useClassNames.d.ts +1 -2
- package/esm/internals/hooks/useClassNames.js +0 -2
- package/esm/internals/hooks/usePortal.js +1 -1
- package/esm/internals/hooks/useToggleCaret.d.ts +2 -2
- package/esm/internals/hooks/useToggleCaret.js +1 -1
- package/esm/internals/hooks/useUpdateEffect.js +0 -1
- package/esm/internals/hooks/useWillUnmount.js +0 -2
- package/esm/internals/symbols.d.ts +1 -0
- package/esm/internals/symbols.js +2 -1
- package/esm/internals/types/colours.d.ts +10 -0
- package/esm/internals/types/colours.js +11 -0
- package/esm/internals/types/index.d.ts +6 -7
- package/esm/internals/types/index.js +6 -0
- package/esm/internals/types/placement.d.ts +5 -0
- package/esm/internals/types/placement.js +2 -0
- package/esm/internals/utils/BrowserDetection.d.ts +0 -2
- package/esm/internals/utils/BrowserDetection.js +1 -9
- package/esm/internals/utils/ReactChildren.js +0 -2
- package/esm/internals/utils/colours.d.ts +21 -0
- package/esm/internals/utils/colours.js +77 -0
- package/esm/internals/utils/css.d.ts +13 -1
- package/esm/internals/utils/css.js +40 -3
- package/esm/internals/utils/getDOMNode.js +1 -2
- package/esm/internals/utils/getSafeRegExpString.js +2 -1
- package/esm/internals/utils/index.d.ts +2 -2
- package/esm/internals/utils/index.js +3 -3
- package/esm/toaster/ToastContainer.d.ts +8 -8
- package/esm/toaster/ToastContainer.js +39 -37
- package/esm/toaster/render.d.ts +2 -0
- package/esm/toaster/render.js +21 -0
- package/esm/toaster/toaster.js +27 -18
- package/esm/useMediaQuery/useMediaQuery.js +1 -3
- package/esm/useToaster/useToaster.js +10 -5
- package/package.json +1 -1
- package/styles/color-modes/dark.less +1 -0
- package/styles/color-modes/high-contrast.less +1 -0
- package/styles/color-modes/light.less +1 -0
- package/styles/variables.less +1 -1
- package/cjs/internals/utils/render.d.ts +0 -7
- package/cjs/internals/utils/render.js +0 -26
- package/esm/internals/utils/render.d.ts +0 -7
- package/esm/internals/utils/render.js +0 -22
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
export let Colours = /*#__PURE__*/function (Colours) {
|
|
3
|
+
Colours["Red"] = "red";
|
|
4
|
+
Colours["Orange"] = "orange";
|
|
5
|
+
Colours["Yellow"] = "yellow";
|
|
6
|
+
Colours["Green"] = "green";
|
|
7
|
+
Colours["Cyan"] = "cyan";
|
|
8
|
+
Colours["Blue"] = "blue";
|
|
9
|
+
Colours["Violet"] = "violet";
|
|
10
|
+
return Colours;
|
|
11
|
+
}({});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ReactNode, CSSProperties, ElementType, InputHTMLAttributes, SyntheticEvent, FocusEventHandler } from 'react';
|
|
2
2
|
import { ReplaceProps } from './utils';
|
|
3
|
+
import { Placement } from './placement';
|
|
4
|
+
import { Colours } from './colours';
|
|
5
|
+
export * from './placement';
|
|
6
|
+
export * from './colours';
|
|
3
7
|
export interface StandardProps {
|
|
4
8
|
/** The prefix of the component CSS class */
|
|
5
9
|
classPrefix?: string;
|
|
@@ -20,7 +24,6 @@ export interface WithAsPropsWithoutChildren<As extends ElementType | string = El
|
|
|
20
24
|
}
|
|
21
25
|
export interface RsRefForwardingComponent<T extends ElementType, P = unknown, ExcludeChildren extends boolean = false> {
|
|
22
26
|
<As extends ElementType = T>(props: ReplaceProps<As, ExcludeChildren extends true ? WithAsPropsWithoutChildren<As> & P : WithAsProps<As> & P>, context?: any): any;
|
|
23
|
-
propTypes?: any;
|
|
24
27
|
contextTypes?: any;
|
|
25
28
|
displayName?: string;
|
|
26
29
|
}
|
|
@@ -66,7 +69,7 @@ export interface PickerBaseProps<L = any> extends WithAsProps, AnimationEventPro
|
|
|
66
69
|
/** Placeholder text */
|
|
67
70
|
placeholder?: ReactNode;
|
|
68
71
|
/** The placement of picker */
|
|
69
|
-
placement?:
|
|
72
|
+
placement?: Placement;
|
|
70
73
|
/** Prevent floating element overflow */
|
|
71
74
|
preventOverflow?: boolean;
|
|
72
75
|
/** Open the menu and control it */
|
|
@@ -169,12 +172,8 @@ export interface FormControlPickerProps<T = any, L = any, D = Record<string, any
|
|
|
169
172
|
export declare namespace TypeAttributes {
|
|
170
173
|
type Size = 'lg' | 'md' | 'sm' | 'xs';
|
|
171
174
|
type Status = 'success' | 'warning' | 'error' | 'info';
|
|
172
|
-
type Color =
|
|
175
|
+
type Color = `${Colours}`;
|
|
173
176
|
type Appearance = 'default' | 'primary' | 'link' | 'subtle' | 'ghost';
|
|
174
|
-
type Placement4 = 'top' | 'bottom' | 'right' | 'left';
|
|
175
|
-
type Placement8 = 'bottomStart' | 'bottomEnd' | 'topStart' | 'topEnd' | 'leftStart' | 'rightStart' | 'leftEnd' | 'rightEnd';
|
|
176
|
-
type PlacementAuto = 'auto' | 'autoVertical' | 'autoVerticalStart' | 'autoVerticalEnd' | 'autoHorizontal' | 'autoHorizontalStart' | 'autoHorizontalEnd';
|
|
177
|
-
type Placement = Placement4 | Placement8 | PlacementAuto;
|
|
178
177
|
type CheckTrigger = 'change' | 'blur' | 'none' | null;
|
|
179
178
|
type DisplayState = 'show' | 'hide' | 'hiding';
|
|
180
179
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type PlacementCardinal = 'top' | 'bottom' | 'right' | 'left';
|
|
2
|
+
export type PlacementCornersPolyfill = 'leftStart' | 'rightStart' | 'leftEnd' | 'rightEnd';
|
|
3
|
+
export type PlacementCorners = 'topStart' | 'topEnd' | 'bottomStart' | 'bottomEnd' | PlacementCornersPolyfill;
|
|
4
|
+
export type PlacementAuto = 'auto' | 'autoVertical' | 'autoVerticalStart' | 'autoVerticalEnd' | 'autoHorizontal' | 'autoHorizontalStart' | 'autoHorizontalEnd';
|
|
5
|
+
export type Placement = PlacementCardinal | PlacementCorners | PlacementAuto;
|
|
@@ -5,12 +5,4 @@ import canUseDOM from 'dom-lib/canUseDOM';
|
|
|
5
5
|
|
|
6
6
|
// Internet Explorer 6-11
|
|
7
7
|
export const isIE = () => canUseDOM && /MSIE |Trident\/|Edge\//.test(window.navigator.userAgent);
|
|
8
|
-
export const
|
|
9
|
-
export const isAndroid = () => canUseDOM && /Android/i.test(navigator.userAgent);
|
|
10
|
-
export const getChromeVersion = () => {
|
|
11
|
-
if (canUseDOM) {
|
|
12
|
-
const match = window.navigator.userAgent.match(/Chrom(e|ium)\/([\d\.]+)\./);
|
|
13
|
-
return match ? parseFloat(match[2]) : false;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
};
|
|
8
|
+
export const isAndroid = () => canUseDOM && /Android/i.test(navigator.userAgent);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Color } from '../types/colours';
|
|
2
|
+
export declare const isPresetColor: (color?: Color | React.CSSProperties['color']) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Convert short hex color to full hex color
|
|
5
|
+
* e.g. #fff -> #ffffff
|
|
6
|
+
*/
|
|
7
|
+
export declare const expandHexColor: (color: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Calculate relative luminance of a color
|
|
10
|
+
* Using the formula from WCAG 2.0
|
|
11
|
+
*/
|
|
12
|
+
export declare const getLuminance: (color: string) => number;
|
|
13
|
+
/**
|
|
14
|
+
* Get contrasting text color (black or white) based on background color
|
|
15
|
+
*/
|
|
16
|
+
export declare const getContrastText: (bgColor: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Create CSS color variables for custom colors
|
|
19
|
+
* Returns background and optional text color variables
|
|
20
|
+
*/
|
|
21
|
+
export declare const createColorVariables: (color?: Color | React.CSSProperties['color'], bgFieldName?: string, textFieldName?: string) => React.CSSProperties | undefined;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Colours } from "../types/colours.js";
|
|
3
|
+
export const isPresetColor = color => {
|
|
4
|
+
if (!color) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (color === 'default') {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return Object.values(Colours).includes(color);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Convert short hex color to full hex color
|
|
15
|
+
* e.g. #fff -> #ffffff
|
|
16
|
+
*/
|
|
17
|
+
export const expandHexColor = color => {
|
|
18
|
+
const hex = color.toLowerCase().replace('#', '');
|
|
19
|
+
if (hex.length === 3) {
|
|
20
|
+
return `#${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
|
|
21
|
+
}
|
|
22
|
+
return `#${hex}`;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Calculate relative luminance of a color
|
|
27
|
+
* Using the formula from WCAG 2.0
|
|
28
|
+
*/
|
|
29
|
+
export const getLuminance = color => {
|
|
30
|
+
// Convert hex to rgb
|
|
31
|
+
const fullHex = expandHexColor(color);
|
|
32
|
+
const hex = fullHex.replace('#', '');
|
|
33
|
+
const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
34
|
+
const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
35
|
+
const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
36
|
+
|
|
37
|
+
// Convert rgb to relative luminance
|
|
38
|
+
const rs = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);
|
|
39
|
+
const gs = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4);
|
|
40
|
+
const bs = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4);
|
|
41
|
+
return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get contrasting text color (black or white) based on background color
|
|
46
|
+
*/
|
|
47
|
+
export const getContrastText = bgColor => {
|
|
48
|
+
// For non-hex colors, return default dark text
|
|
49
|
+
if (!bgColor.startsWith('#')) {
|
|
50
|
+
return 'var(--rs-text-primary)';
|
|
51
|
+
}
|
|
52
|
+
const luminance = getLuminance(bgColor);
|
|
53
|
+
return luminance > 0.5 ? '#000000' : '#ffffff';
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create CSS color variables for custom colors
|
|
58
|
+
* Returns background and optional text color variables
|
|
59
|
+
*/
|
|
60
|
+
export const createColorVariables = function (color, bgFieldName, textFieldName) {
|
|
61
|
+
if (bgFieldName === void 0) {
|
|
62
|
+
bgFieldName = '--rs-color-bg';
|
|
63
|
+
}
|
|
64
|
+
if (color && !isPresetColor(color)) {
|
|
65
|
+
const colorStr = color.toString();
|
|
66
|
+
// Only convert to hex if it's a hex color
|
|
67
|
+
const bgColor = colorStr.startsWith('#') ? expandHexColor(colorStr) : colorStr;
|
|
68
|
+
const styles = {
|
|
69
|
+
[bgFieldName]: bgColor
|
|
70
|
+
};
|
|
71
|
+
if (textFieldName) {
|
|
72
|
+
styles[textFieldName] = getContrastText(bgColor);
|
|
73
|
+
}
|
|
74
|
+
return styles;
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
};
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
/**
|
|
2
3
|
* Processes and returns a value suitable for CSS (with a unit).
|
|
3
4
|
*/
|
|
4
|
-
export declare function getCssValue(value?: number | string, unit?: string): string
|
|
5
|
+
export declare function getCssValue(value?: number | string | null, unit?: string): string;
|
|
6
|
+
type CSSVariables = Partial<Record<`--${string}`, string>>;
|
|
7
|
+
type StyleProperties = React.CSSProperties & CSSVariables;
|
|
8
|
+
/**
|
|
9
|
+
* Merge multiple style objects, filtering out undefined values
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergeStyles(...styles: (React.CSSProperties | undefined | null)[]): StyleProperties;
|
|
12
|
+
/**
|
|
13
|
+
* Create CSS variables for offset positioning
|
|
14
|
+
*/
|
|
15
|
+
export declare function createOffsetStyles(offset?: [number | string, number | string], prefix?: string): React.CSSProperties | undefined;
|
|
16
|
+
export {};
|
|
@@ -6,13 +6,50 @@ export function getCssValue(value, unit) {
|
|
|
6
6
|
if (unit === void 0) {
|
|
7
7
|
unit = 'px';
|
|
8
8
|
}
|
|
9
|
+
if (value === undefined || value === null || value === '') {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// If the value is 0, return it as a string without unit
|
|
14
|
+
if (value === 0) {
|
|
15
|
+
return '0';
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
// If the value is a number, append the default unit (defaults to 'px')
|
|
10
19
|
if (typeof value === 'number') {
|
|
11
20
|
return `${value}${unit}`;
|
|
12
21
|
}
|
|
13
22
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
// Return string values as is
|
|
24
|
+
return value.toString();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Merge multiple style objects, filtering out undefined values
|
|
28
|
+
*/
|
|
29
|
+
export function mergeStyles() {
|
|
30
|
+
for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
31
|
+
styles[_key] = arguments[_key];
|
|
32
|
+
}
|
|
33
|
+
return styles.filter(Boolean).reduce((acc, style) => {
|
|
34
|
+
if (!style) return acc;
|
|
35
|
+
return {
|
|
36
|
+
...acc,
|
|
37
|
+
...style
|
|
38
|
+
};
|
|
39
|
+
}, {});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create CSS variables for offset positioning
|
|
44
|
+
*/
|
|
45
|
+
export function createOffsetStyles(offset, prefix) {
|
|
46
|
+
if (prefix === void 0) {
|
|
47
|
+
prefix = '--rs-offset';
|
|
17
48
|
}
|
|
49
|
+
if (!offset) return undefined;
|
|
50
|
+
const [x, y] = offset;
|
|
51
|
+
return {
|
|
52
|
+
[`${prefix}-x`]: getCssValue(x),
|
|
53
|
+
[`${prefix}-y`]: getCssValue(y)
|
|
54
|
+
};
|
|
18
55
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
/* eslint-disable react/no-find-dom-node */
|
|
2
3
|
import ReactDOM from 'react-dom';
|
|
3
4
|
function safeFindDOMNode(componentOrElement) {
|
|
4
5
|
if (componentOrElement && 'setState' in componentOrElement) {
|
|
5
6
|
var _ReactDOM$findDOMNode;
|
|
6
|
-
// eslint-disable-next-line react/no-find-dom-node
|
|
7
7
|
return (_ReactDOM$findDOMNode = ReactDOM.findDOMNode) === null || _ReactDOM$findDOMNode === void 0 ? void 0 : _ReactDOM$findDOMNode.call(ReactDOM, componentOrElement);
|
|
8
8
|
}
|
|
9
9
|
return componentOrElement !== null && componentOrElement !== void 0 ? componentOrElement : null;
|
|
@@ -21,7 +21,6 @@ export function getDOMNode(elementOrRef) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// If you can't get the native HTML element, you can only get it through findDOMNode.
|
|
24
|
-
// eslint-disable-next-line react/no-find-dom-node
|
|
25
24
|
return safeFindDOMNode(element);
|
|
26
25
|
}
|
|
27
26
|
export default getDOMNode;
|
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
* @description escape Regular_Expressions special_characters '^$.|*+?{\\[()'
|
|
4
4
|
*/
|
|
5
5
|
export function getSafeRegExpString(str) {
|
|
6
|
-
|
|
6
|
+
const specialChars = '\\^$.|?*+()[]{}';
|
|
7
|
+
return str.replace(new RegExp(`([${specialChars}])`, 'g'), '\\$1');
|
|
7
8
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './BrowserDetection';
|
|
2
2
|
export * from './htmlPropsUtils';
|
|
3
|
+
export * from './css';
|
|
4
|
+
export * from './colours';
|
|
3
5
|
export { stringifyReactNode, reactToString } from './stringifyReactNode';
|
|
4
6
|
export { getSafeRegExpString } from './getSafeRegExpString';
|
|
5
7
|
export { getDOMNode } from './getDOMNode';
|
|
@@ -13,7 +15,6 @@ export { placementPolyfill } from './placementPolyfill';
|
|
|
13
15
|
export { mergeRefs } from './mergeRefs';
|
|
14
16
|
export { shallowEqual, shallowEqualArray } from './shallowEqual';
|
|
15
17
|
export { composeFunctions } from './composeFunctions';
|
|
16
|
-
export { render } from './render';
|
|
17
18
|
export { safeSetSelection } from './safeSetSelection';
|
|
18
19
|
export { getStringLength } from './getStringLength';
|
|
19
20
|
export { getDataGroupBy } from './getDataGroupBy';
|
|
@@ -24,4 +25,3 @@ export type { ComponentProps } from './createComponent';
|
|
|
24
25
|
export { attachParent } from './attachParent';
|
|
25
26
|
export { isFocusEntering, isFocusLeaving } from './events';
|
|
26
27
|
export { isFocusableElement } from './dom';
|
|
27
|
-
export { getCssValue } from './css';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
export * from "./BrowserDetection.js";
|
|
3
3
|
export * from "./htmlPropsUtils.js";
|
|
4
|
+
export * from "./css.js";
|
|
5
|
+
export * from "./colours.js";
|
|
4
6
|
export { stringifyReactNode, reactToString } from "./stringifyReactNode.js";
|
|
5
7
|
export { getSafeRegExpString } from "./getSafeRegExpString.js";
|
|
6
8
|
export { getDOMNode } from "./getDOMNode.js";
|
|
@@ -14,7 +16,6 @@ export { placementPolyfill } from "./placementPolyfill.js";
|
|
|
14
16
|
export { mergeRefs } from "./mergeRefs.js";
|
|
15
17
|
export { shallowEqual, shallowEqualArray } from "./shallowEqual.js";
|
|
16
18
|
export { composeFunctions } from "./composeFunctions.js";
|
|
17
|
-
export { render } from "./render.js";
|
|
18
19
|
export { safeSetSelection } from "./safeSetSelection.js";
|
|
19
20
|
export { getStringLength } from "./getStringLength.js";
|
|
20
21
|
export { getDataGroupBy } from "./getDataGroupBy.js";
|
|
@@ -23,5 +24,4 @@ export { warnOnce } from "./warnOnce.js";
|
|
|
23
24
|
export { createComponent } from "./createComponent.js";
|
|
24
25
|
export { attachParent } from "./attachParent.js";
|
|
25
26
|
export { isFocusEntering, isFocusLeaving } from "./events.js";
|
|
26
|
-
export { isFocusableElement } from "./dom.js";
|
|
27
|
-
export { getCssValue } from "./css.js";
|
|
27
|
+
export { isFocusableElement } from "./dom.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { WithAsProps, RsRefForwardingComponent } from '../internals/types';
|
|
3
|
+
export declare const defaultToasterContainer: () => HTMLElement | null;
|
|
3
4
|
export type PlacementType = 'topCenter' | 'bottomCenter' | 'topStart' | 'topEnd' | 'bottomStart' | 'bottomEnd';
|
|
4
5
|
export declare const toastPlacements: PlacementType[];
|
|
5
6
|
export interface ToastContainerProps extends WithAsProps {
|
|
@@ -12,7 +13,7 @@ export interface ToastContainerProps extends WithAsProps {
|
|
|
12
13
|
/**
|
|
13
14
|
* Set the message to appear in the specified container
|
|
14
15
|
*/
|
|
15
|
-
container?: HTMLElement | (() => HTMLElement);
|
|
16
|
+
container?: HTMLElement | (() => HTMLElement) | null;
|
|
16
17
|
/**
|
|
17
18
|
* The number of milliseconds to wait before automatically closing a message.
|
|
18
19
|
*/
|
|
@@ -21,18 +22,13 @@ export interface ToastContainerProps extends WithAsProps {
|
|
|
21
22
|
* Reset the hide timer if the mouse moves over the message.
|
|
22
23
|
*/
|
|
23
24
|
mouseReset?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Callback fired when the component mounts
|
|
26
|
-
*/
|
|
27
|
-
callback?: (ref: React.RefObject<ToastContainerInstance>) => void;
|
|
28
25
|
}
|
|
29
26
|
interface PushOptions {
|
|
30
27
|
duration?: number;
|
|
31
28
|
mouseReset?: boolean;
|
|
32
|
-
container?: HTMLElement | (() => HTMLElement);
|
|
29
|
+
container?: HTMLElement | (() => HTMLElement) | null;
|
|
33
30
|
}
|
|
34
31
|
export interface ToastContainerInstance {
|
|
35
|
-
root: HTMLElement;
|
|
36
32
|
push: (message: React.ReactNode, options?: PushOptions) => string;
|
|
37
33
|
remove: (key: string) => void;
|
|
38
34
|
clear: () => void;
|
|
@@ -41,8 +37,12 @@ export interface ToastContainerInstance {
|
|
|
41
37
|
export interface NodeProps extends WithAsProps {
|
|
42
38
|
onClose?: (event?: React.MouseEvent<HTMLDivElement>) => void;
|
|
43
39
|
}
|
|
40
|
+
export type GetInstancePropsType = Omit<ToastContainerProps, 'container' | 'placement'> & {
|
|
41
|
+
container: HTMLElement | null;
|
|
42
|
+
placement: PlacementType;
|
|
43
|
+
};
|
|
44
44
|
interface ToastContainerComponent extends RsRefForwardingComponent<'div', ToastContainerProps> {
|
|
45
|
-
getInstance: (props:
|
|
45
|
+
getInstance: (props: GetInstancePropsType) => Promise<[React.RefObject<ToastContainerInstance>, string]>;
|
|
46
46
|
}
|
|
47
47
|
declare const ToastContainer: ToastContainerComponent;
|
|
48
48
|
export default ToastContainer;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
import React, { useState, useImperativeHandle,
|
|
4
|
-
import { createPortal } from 'react-dom';
|
|
3
|
+
import React, { useState, useImperativeHandle, useCallback } from 'react';
|
|
5
4
|
import kebabCase from 'lodash/kebabCase';
|
|
6
5
|
import Transition from "../Animation/Transition.js";
|
|
7
|
-
import { useClassNames } from "../internals/hooks/index.js";
|
|
8
|
-
import { guid, createChainedFunction, render } from "../internals/utils/index.js";
|
|
9
6
|
import ToastContext from "./ToastContext.js";
|
|
7
|
+
import canUseDOM from 'dom-lib/canUseDOM';
|
|
8
|
+
import { useClassNames } from "../internals/hooks/index.js";
|
|
9
|
+
import { guid, createChainedFunction } from "../internals/utils/index.js";
|
|
10
|
+
import { render } from "./render.js";
|
|
11
|
+
export const defaultToasterContainer = () => {
|
|
12
|
+
return canUseDOM ? document.body : null;
|
|
13
|
+
};
|
|
10
14
|
export const toastPlacements = ['topCenter', 'bottomCenter', 'topStart', 'topEnd', 'bottomStart', 'bottomEnd'];
|
|
11
15
|
const useMessages = () => {
|
|
12
16
|
const [messages, setMessages] = useState([]);
|
|
@@ -68,13 +72,11 @@ const useMessages = () => {
|
|
|
68
72
|
};
|
|
69
73
|
};
|
|
70
74
|
const ToastContainer = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
71
|
-
const rootRef = useRef();
|
|
72
75
|
const {
|
|
73
76
|
as: Component = 'div',
|
|
74
77
|
className,
|
|
75
78
|
classPrefix = 'toast-container',
|
|
76
79
|
placement = 'topCenter',
|
|
77
|
-
callback,
|
|
78
80
|
...rest
|
|
79
81
|
} = props;
|
|
80
82
|
const {
|
|
@@ -90,7 +92,6 @@ const ToastContainer = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
90
92
|
messages
|
|
91
93
|
} = useMessages();
|
|
92
94
|
useImperativeHandle(ref, () => ({
|
|
93
|
-
root: rootRef.current,
|
|
94
95
|
push,
|
|
95
96
|
clear,
|
|
96
97
|
remove
|
|
@@ -99,10 +100,16 @@ const ToastContainer = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
99
100
|
const {
|
|
100
101
|
mouseReset,
|
|
101
102
|
duration,
|
|
102
|
-
node
|
|
103
|
-
container
|
|
103
|
+
node
|
|
104
104
|
} = item;
|
|
105
|
-
|
|
105
|
+
return /*#__PURE__*/React.createElement(ToastContext.Provider, {
|
|
106
|
+
value: {
|
|
107
|
+
usedToaster: true,
|
|
108
|
+
mouseReset,
|
|
109
|
+
duration
|
|
110
|
+
},
|
|
111
|
+
key: item.key
|
|
112
|
+
}, /*#__PURE__*/React.createElement(Transition, {
|
|
106
113
|
in: item.visible,
|
|
107
114
|
exitedClassName: rootPrefix('toast-fade-exited'),
|
|
108
115
|
exitingClassName: rootPrefix('toast-fade-exiting'),
|
|
@@ -122,42 +129,37 @@ const ToastContainer = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
122
129
|
onClose: createChainedFunction((_node$props = node.props) === null || _node$props === void 0 ? void 0 : _node$props.onClose, () => remove(item.key)),
|
|
123
130
|
className: merge(rootPrefix('toast'), (_node$props2 = node.props) === null || _node$props2 === void 0 ? void 0 : _node$props2.className, transitionClassName)
|
|
124
131
|
});
|
|
125
|
-
});
|
|
126
|
-
return /*#__PURE__*/React.createElement(ToastContext.Provider, {
|
|
127
|
-
value: {
|
|
128
|
-
usedToaster: true,
|
|
129
|
-
mouseReset,
|
|
130
|
-
duration
|
|
131
|
-
},
|
|
132
|
-
key: item.key
|
|
133
|
-
}, container ? /*#__PURE__*/createPortal(toastWithTransition, typeof container === 'function' ? container() : container) : toastWithTransition);
|
|
132
|
+
}));
|
|
134
133
|
});
|
|
135
134
|
return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
|
|
136
|
-
ref: selfRef => {
|
|
137
|
-
rootRef.current = selfRef;
|
|
138
|
-
callback === null || callback === void 0 || callback(selfRef);
|
|
139
|
-
},
|
|
140
135
|
className: classes
|
|
141
136
|
}), elements);
|
|
142
137
|
});
|
|
143
|
-
ToastContainer.getInstance = props => {
|
|
138
|
+
ToastContainer.getInstance = async props => {
|
|
144
139
|
const {
|
|
145
140
|
container,
|
|
146
|
-
...
|
|
141
|
+
...toastProps
|
|
147
142
|
} = props;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
154
|
-
const {
|
|
155
|
-
unmount
|
|
156
|
-
} = render(/*#__PURE__*/React.createElement(ToastContainer, _extends({}, rest, {
|
|
157
|
-
ref: containerRef,
|
|
158
|
-
callback: renderCallback
|
|
159
|
-
})), containerElement);
|
|
143
|
+
|
|
144
|
+
// Promise to wait for containerRef to be assigned
|
|
145
|
+
let resolveContainerRef = null;
|
|
146
|
+
const containerRefReady = new Promise(resolve => {
|
|
147
|
+
resolveContainerRef = resolve;
|
|
160
148
|
});
|
|
149
|
+
|
|
150
|
+
// Create a React ref for the ToastContainer instance
|
|
151
|
+
const toastContainerRef = /*#__PURE__*/React.createRef();
|
|
152
|
+
|
|
153
|
+
// Render the ToastContainer component into the specified container
|
|
154
|
+
const containerId = render(/*#__PURE__*/React.createElement(ToastContainer, _extends({}, toastProps, {
|
|
155
|
+
ref: ref => {
|
|
156
|
+
var _resolveContainerRef;
|
|
157
|
+
toastContainerRef.current = ref;
|
|
158
|
+
(_resolveContainerRef = resolveContainerRef) === null || _resolveContainerRef === void 0 || _resolveContainerRef();
|
|
159
|
+
}
|
|
160
|
+
})), container);
|
|
161
|
+
await containerRefReady;
|
|
162
|
+
return [toastContainerRef, containerId];
|
|
161
163
|
};
|
|
162
164
|
ToastContainer.displayName = 'ToastContainer';
|
|
163
165
|
export default ToastContainer;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { guid } from "../internals/utils/index.js";
|
|
4
|
+
import { RSUITE_TOASTER_ID } from "../internals/symbols.js";
|
|
5
|
+
export function render(element, container) {
|
|
6
|
+
const mountElement = document.createElement('div');
|
|
7
|
+
mountElement.className = 'rs-toaster-mount-element';
|
|
8
|
+
const containerElement = container;
|
|
9
|
+
|
|
10
|
+
// Add the detached element to the root
|
|
11
|
+
containerElement.appendChild(mountElement);
|
|
12
|
+
if (!containerElement[RSUITE_TOASTER_ID]) {
|
|
13
|
+
// Attach the containerId to the containerElement
|
|
14
|
+
containerElement[RSUITE_TOASTER_ID] = guid();
|
|
15
|
+
}
|
|
16
|
+
const root = createRoot(mountElement, {
|
|
17
|
+
identifierPrefix: 'rs-root-'
|
|
18
|
+
});
|
|
19
|
+
root.render(element);
|
|
20
|
+
return containerElement[RSUITE_TOASTER_ID];
|
|
21
|
+
}
|
package/esm/toaster/toaster.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import ToastContainer from "./ToastContainer.js";
|
|
3
|
-
|
|
2
|
+
import ToastContainer, { defaultToasterContainer } from "./ToastContainer.js";
|
|
3
|
+
import { RSUITE_TOASTER_ID } from "../internals/symbols.js";
|
|
4
4
|
const containers = new Map();
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Create a container
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
7
|
+
* Create a container instance.
|
|
8
|
+
* @param placement
|
|
9
|
+
* @param props
|
|
10
10
|
*/
|
|
11
|
-
async function createContainer(
|
|
12
|
-
const [container] = await ToastContainer.getInstance(props);
|
|
13
|
-
containers.set(containerId
|
|
11
|
+
async function createContainer(placement, props) {
|
|
12
|
+
const [container, containerId] = await ToastContainer.getInstance(props);
|
|
13
|
+
containers.set(`${containerId}_${placement}`, container);
|
|
14
14
|
return container;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Get the container by ID. Use default ID when ID is not available.
|
|
19
19
|
* @param containerId
|
|
20
|
+
* @param placement
|
|
20
21
|
*/
|
|
21
|
-
function getContainer(containerId) {
|
|
22
|
-
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
return containers.get(containerId || defaultContainerId);
|
|
22
|
+
function getContainer(containerId, placement) {
|
|
23
|
+
return containers.get(`${containerId}_${placement}`);
|
|
26
24
|
}
|
|
27
25
|
const toaster = message => toaster.push(message);
|
|
28
26
|
toaster.push = function (message, options) {
|
|
@@ -30,14 +28,25 @@ toaster.push = function (message, options) {
|
|
|
30
28
|
options = {};
|
|
31
29
|
}
|
|
32
30
|
const {
|
|
33
|
-
placement
|
|
31
|
+
placement = 'topCenter',
|
|
32
|
+
container = defaultToasterContainer,
|
|
34
33
|
...restOptions
|
|
35
34
|
} = options;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const containerElement = typeof container === 'function' ? container() : container;
|
|
36
|
+
const containerElementId = containerElement ? containerElement[RSUITE_TOASTER_ID] : null;
|
|
37
|
+
if (containerElementId) {
|
|
38
|
+
const existedContainer = getContainer(containerElementId, placement);
|
|
39
|
+
if (existedContainer) {
|
|
40
|
+
var _existedContainer$cur;
|
|
41
|
+
return (_existedContainer$cur = existedContainer.current) === null || _existedContainer$cur === void 0 ? void 0 : _existedContainer$cur.push(message, restOptions);
|
|
42
|
+
}
|
|
39
43
|
}
|
|
40
|
-
|
|
44
|
+
const newOptions = {
|
|
45
|
+
...options,
|
|
46
|
+
container: containerElement,
|
|
47
|
+
placement
|
|
48
|
+
};
|
|
49
|
+
return createContainer(placement, newOptions).then(ref => {
|
|
41
50
|
var _ref$current;
|
|
42
51
|
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.push(message, restOptions);
|
|
43
52
|
});
|
|
@@ -32,9 +32,7 @@ const matchMedia = query => {
|
|
|
32
32
|
*/
|
|
33
33
|
export function useMediaQuery(query) {
|
|
34
34
|
const queries = Array.isArray(query) ? query : [query];
|
|
35
|
-
const mediaQueries = useMemo(() => queries.map(query => mediaQuerySizeMap[query] || query),
|
|
36
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
-
[...queries]);
|
|
35
|
+
const mediaQueries = useMemo(() => queries.map(query => mediaQuerySizeMap[query] || query), [...queries]);
|
|
38
36
|
const mediaQueryArray = useRef(mediaQueries.map(query => matchMedia(query).matches));
|
|
39
37
|
const subscribe = useCallback(callback => {
|
|
40
38
|
const list = mediaQueries.map(query => matchMedia(query));
|