@stack-spot/portal-layout 0.0.65 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Layout.d.ts +58 -6
- package/dist/Layout.d.ts.map +1 -1
- package/dist/Layout.js +14 -7
- package/dist/Layout.js.map +1 -1
- package/dist/LayoutOverlayManager.d.ts +173 -6
- package/dist/LayoutOverlayManager.d.ts.map +1 -1
- package/dist/LayoutOverlayManager.js +118 -9
- package/dist/LayoutOverlayManager.js.map +1 -1
- package/dist/components/Dialog.d.ts +48 -5
- package/dist/components/Dialog.d.ts.map +1 -1
- package/dist/components/Dialog.js +7 -2
- package/dist/components/Dialog.js.map +1 -1
- package/dist/components/Header.d.ts +29 -1
- package/dist/components/Header.d.ts.map +1 -1
- package/dist/components/Header.js +6 -2
- package/dist/components/Header.js.map +1 -1
- package/dist/components/OverlayContent.d.ts +22 -0
- package/dist/components/OverlayContent.d.ts.map +1 -1
- package/dist/components/OverlayContent.js +4 -0
- package/dist/components/OverlayContent.js.map +1 -1
- package/dist/components/PortalSwitcher.d.ts +14 -0
- package/dist/components/PortalSwitcher.d.ts.map +1 -1
- package/dist/components/PortalSwitcher.js +9 -6
- package/dist/components/PortalSwitcher.js.map +1 -1
- package/dist/components/Toaster.d.ts +4 -0
- package/dist/components/Toaster.d.ts.map +1 -1
- package/dist/components/Toaster.js +5 -1
- package/dist/components/Toaster.js.map +1 -1
- package/dist/components/UserMenu.d.ts +14 -1
- package/dist/components/UserMenu.d.ts.map +1 -1
- package/dist/components/UserMenu.js +5 -1
- package/dist/components/UserMenu.js.map +1 -1
- package/dist/components/error/ErrorBoundary.d.ts +10 -1
- package/dist/components/error/ErrorBoundary.d.ts.map +1 -1
- package/dist/components/error/ErrorBoundary.js +10 -1
- package/dist/components/error/ErrorBoundary.js.map +1 -1
- package/dist/components/error/ErrorManager.d.ts +22 -6
- package/dist/components/error/ErrorManager.d.ts.map +1 -1
- package/dist/components/error/ErrorManager.js +21 -1
- package/dist/components/error/ErrorManager.js.map +1 -1
- package/dist/components/error/SilentErrorBoundary.d.ts +11 -2
- package/dist/components/error/SilentErrorBoundary.d.ts.map +1 -1
- package/dist/components/error/SilentErrorBoundary.js +10 -0
- package/dist/components/error/SilentErrorBoundary.js.map +1 -1
- package/dist/components/menu/MenuContent.d.ts +19 -2
- package/dist/components/menu/MenuContent.d.ts.map +1 -1
- package/dist/components/menu/MenuContent.js +33 -35
- package/dist/components/menu/MenuContent.js.map +1 -1
- package/dist/components/menu/MenuSections.d.ts +10 -0
- package/dist/components/menu/MenuSections.d.ts.map +1 -1
- package/dist/components/menu/MenuSections.js +70 -16
- package/dist/components/menu/MenuSections.js.map +1 -1
- package/dist/components/menu/PageSelector.d.ts +5 -0
- package/dist/components/menu/PageSelector.d.ts.map +1 -1
- package/dist/components/menu/PageSelector.js +8 -3
- package/dist/components/menu/PageSelector.js.map +1 -1
- package/dist/components/menu/types.d.ts +100 -7
- package/dist/components/menu/types.d.ts.map +1 -1
- package/dist/components/tour/PortalSwitcherStep.d.ts +6 -1
- package/dist/components/tour/PortalSwitcherStep.d.ts.map +1 -1
- package/dist/components/tour/PortalSwitcherStep.js +6 -1
- package/dist/components/tour/PortalSwitcherStep.js.map +1 -1
- package/dist/components/types.d.ts +0 -13
- package/dist/components/types.d.ts.map +1 -1
- package/dist/dictionary.d.ts +3 -0
- package/dist/dictionary.d.ts.map +1 -1
- package/dist/dictionary.js +3 -0
- package/dist/dictionary.js.map +1 -1
- package/dist/elements.d.ts +6 -0
- package/dist/elements.d.ts.map +1 -1
- package/dist/elements.js +6 -0
- package/dist/elements.js.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/layout.css +1 -5
- package/dist/toaster.d.ts +74 -9
- package/dist/toaster.d.ts.map +1 -1
- package/dist/toaster.js +32 -6
- package/dist/toaster.js.map +1 -1
- package/dist/utils.d.ts +6 -69
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -130
- package/dist/utils.js.map +1 -1
- package/package.json +16 -15
- package/readme.md +146 -0
- package/src/Layout.tsx +79 -30
- package/src/LayoutOverlayManager.tsx +184 -9
- package/src/components/Dialog.tsx +49 -6
- package/src/components/Header.tsx +31 -3
- package/src/components/OverlayContent.tsx +22 -0
- package/src/components/PortalSwitcher.tsx +22 -8
- package/src/components/Toaster.tsx +10 -2
- package/src/components/UserMenu.tsx +14 -1
- package/src/components/error/ErrorBoundary.tsx +11 -2
- package/src/components/error/ErrorManager.ts +22 -6
- package/src/components/error/SilentErrorBoundary.tsx +12 -2
- package/src/components/menu/MenuContent.tsx +33 -52
- package/src/components/menu/MenuSections.tsx +99 -49
- package/src/components/menu/PageSelector.tsx +8 -3
- package/src/components/menu/types.ts +100 -8
- package/src/components/tour/PortalSwitcherStep.tsx +7 -4
- package/src/components/types.ts +0 -14
- package/src/dictionary.ts +3 -0
- package/src/elements.ts +6 -0
- package/src/index.ts +0 -3
- package/src/layout.css +1 -5
- package/src/toaster.tsx +125 -14
- package/src/utils.ts +9 -142
- package/dist/components/BottomNotification.d.ts +0 -1
- package/dist/components/BottomNotification.d.ts.map +0 -1
- package/dist/components/BottomNotification.js +0 -2
- package/dist/components/BottomNotification.js.map +0 -1
- package/dist/components/BottomPanel.d.ts +0 -1
- package/dist/components/BottomPanel.d.ts.map +0 -1
- package/dist/components/BottomPanel.js +0 -2
- package/dist/components/BottomPanel.js.map +0 -1
- package/dist/components/SelectionList.d.ts +0 -36
- package/dist/components/SelectionList.d.ts.map +0 -1
- package/dist/components/SelectionList.js +0 -140
- package/dist/components/SelectionList.js.map +0 -1
- package/dist/components/error/ErrorFeedback.d.ts +0 -3
- package/dist/components/error/ErrorFeedback.d.ts.map +0 -1
- package/dist/components/error/ErrorFeedback.js +0 -66
- package/dist/components/error/ErrorFeedback.js.map +0 -1
- package/dist/components/menu/use-check-text-overflow.d.ts +0 -6
- package/dist/components/menu/use-check-text-overflow.d.ts.map +0 -1
- package/dist/components/menu/use-check-text-overflow.js +0 -20
- package/dist/components/menu/use-check-text-overflow.js.map +0 -1
- package/dist/components/menu/use-keyboard-controls.d.ts +0 -23
- package/dist/components/menu/use-keyboard-controls.d.ts.map +0 -1
- package/dist/components/menu/use-keyboard-controls.js +0 -49
- package/dist/components/menu/use-keyboard-controls.js.map +0 -1
- package/dist/layout-context.d.ts +0 -10
- package/dist/layout-context.d.ts.map +0 -1
- package/dist/layout-context.js +0 -11
- package/dist/layout-context.js.map +0 -1
- package/dist/svg/AI.d.ts +0 -6
- package/dist/svg/AI.d.ts.map +0 -1
- package/dist/svg/AI.js +0 -9
- package/dist/svg/AI.js.map +0 -1
- package/dist/svg/EDP.d.ts +0 -6
- package/dist/svg/EDP.d.ts.map +0 -1
- package/dist/svg/EDP.js +0 -5
- package/dist/svg/EDP.js.map +0 -1
- package/dist/svg/Forbidden.d.ts +0 -6
- package/dist/svg/Forbidden.d.ts.map +0 -1
- package/dist/svg/Forbidden.js +0 -4
- package/dist/svg/Forbidden.js.map +0 -1
- package/dist/svg/HUB.d.ts +0 -6
- package/dist/svg/HUB.d.ts.map +0 -1
- package/dist/svg/HUB.js +0 -5
- package/dist/svg/HUB.js.map +0 -1
- package/dist/svg/Logo.d.ts +0 -2
- package/dist/svg/Logo.d.ts.map +0 -1
- package/dist/svg/Logo.js +0 -4
- package/dist/svg/Logo.js.map +0 -1
- package/dist/svg/NotFound.d.ts +0 -6
- package/dist/svg/NotFound.d.ts.map +0 -1
- package/dist/svg/NotFound.js +0 -4
- package/dist/svg/NotFound.js.map +0 -1
- package/dist/svg/ServerError.d.ts +0 -6
- package/dist/svg/ServerError.d.ts.map +0 -1
- package/dist/svg/ServerError.js +0 -4
- package/dist/svg/ServerError.js.map +0 -1
- package/dist/svg/Unauthenticated.d.ts +0 -6
- package/dist/svg/Unauthenticated.d.ts.map +0 -1
- package/dist/svg/Unauthenticated.js +0 -4
- package/dist/svg/Unauthenticated.js.map +0 -1
- package/src/components/BottomNotification.tsx +0 -0
- package/src/components/BottomPanel.tsx +0 -0
- package/src/components/SelectionList.tsx +0 -272
- package/src/components/error/ErrorFeedback.tsx +0 -114
- package/src/components/menu/use-check-text-overflow.tsx +0 -26
- package/src/components/menu/use-keyboard-controls.tsx +0 -70
- package/src/layout-context.tsx +0 -22
- package/src/svg/AI.tsx +0 -37
- package/src/svg/EDP.tsx +0 -35
- package/src/svg/Forbidden.tsx +0 -22
- package/src/svg/HUB.tsx +0 -35
- package/src/svg/Logo.tsx +0 -35
- package/src/svg/NotFound.tsx +0 -16
- package/src/svg/ServerError.tsx +0 -33
- package/src/svg/Unauthenticated.tsx +0 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Action } from '@stack-spot/portal-components/SelectionList'
|
|
1
2
|
import { ReactElement, ReactNode } from 'react'
|
|
2
|
-
import { Action } from '../types'
|
|
3
3
|
|
|
4
4
|
interface BaseMenuItem {
|
|
5
5
|
hidden?: boolean,
|
|
@@ -19,47 +19,106 @@ interface BaseMenuItem {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface ItemGroup extends BaseMenuItem {
|
|
22
|
+
/**
|
|
23
|
+
* The label for this group.
|
|
24
|
+
*/
|
|
22
25
|
label: string,
|
|
26
|
+
/**
|
|
27
|
+
* The items in this group.
|
|
28
|
+
*/
|
|
23
29
|
children: MenuItem[],
|
|
30
|
+
/**
|
|
31
|
+
* Whether it should start opened or not.
|
|
32
|
+
*/
|
|
24
33
|
open?: boolean,
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
export interface MenuAction extends Action, BaseMenuItem {
|
|
37
|
+
/**
|
|
38
|
+
* Whether this menu item is currently active or not.
|
|
39
|
+
*/
|
|
28
40
|
active?: boolean,
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
export type MenuItem = ItemGroup | MenuAction
|
|
32
44
|
|
|
33
|
-
export interface MenuButton extends Action {
|
|
34
|
-
icon?: ReactElement,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
45
|
export interface SelectorItem extends Action {
|
|
46
|
+
/**
|
|
47
|
+
* A unique id for this item.
|
|
48
|
+
*/
|
|
38
49
|
key: string,
|
|
50
|
+
/**
|
|
51
|
+
* An icon to place at the left side of the item.
|
|
52
|
+
*/
|
|
39
53
|
icon?: ReactElement,
|
|
40
54
|
}
|
|
41
55
|
|
|
42
56
|
export interface Selector {
|
|
57
|
+
/**
|
|
58
|
+
* The current value. Must correspond to a `key` in `options`.
|
|
59
|
+
*/
|
|
43
60
|
value?: string,
|
|
61
|
+
/**
|
|
62
|
+
* A series of options to show in the selector.
|
|
63
|
+
*/
|
|
44
64
|
options: SelectorItem[],
|
|
65
|
+
/**
|
|
66
|
+
* An extra button to show after the list of options.
|
|
67
|
+
*/
|
|
45
68
|
button?: Action,
|
|
69
|
+
/**
|
|
70
|
+
* A title of this selector.
|
|
71
|
+
*/
|
|
46
72
|
title?: string,
|
|
73
|
+
/**
|
|
74
|
+
* A subtitle for this selector.
|
|
75
|
+
*/
|
|
47
76
|
subtitle?: string,
|
|
77
|
+
/**
|
|
78
|
+
* Whether or not the options for this selector are loading.
|
|
79
|
+
*/
|
|
48
80
|
loading?: boolean,
|
|
49
81
|
}
|
|
50
82
|
|
|
51
83
|
export interface MenuSectionContent {
|
|
84
|
+
/**
|
|
85
|
+
* A link to go back.
|
|
86
|
+
*/
|
|
52
87
|
goBack?: Action,
|
|
88
|
+
/**
|
|
89
|
+
* A title for this menu.
|
|
90
|
+
*/
|
|
53
91
|
title?: string,
|
|
92
|
+
/**
|
|
93
|
+
* A subtitle for this menu.
|
|
94
|
+
*/
|
|
54
95
|
subtitle?: string,
|
|
96
|
+
/**
|
|
97
|
+
* A custom React Node to add right after the menu title.
|
|
98
|
+
*/
|
|
55
99
|
afterTitle?: React.ReactNode,
|
|
100
|
+
/**
|
|
101
|
+
* A page selector.
|
|
102
|
+
*/
|
|
56
103
|
pageSelector?: Selector,
|
|
104
|
+
/**
|
|
105
|
+
* The menu options, may contain subgroups.
|
|
106
|
+
*/
|
|
57
107
|
options?: MenuItem[],
|
|
108
|
+
/**
|
|
109
|
+
* Whether or not the options for this menu are loading.
|
|
110
|
+
*/
|
|
58
111
|
loading?: boolean,
|
|
112
|
+
/**
|
|
113
|
+
* An error to show instead of the menu.
|
|
114
|
+
*/
|
|
59
115
|
error?: string,
|
|
60
116
|
}
|
|
61
117
|
|
|
62
118
|
export interface MenuSection extends Action {
|
|
119
|
+
/**
|
|
120
|
+
* The icon for this section.
|
|
121
|
+
*/
|
|
63
122
|
icon: ReactElement,
|
|
64
123
|
/**
|
|
65
124
|
* The content or a function that creates the content.
|
|
@@ -74,32 +133,65 @@ export interface MenuSection extends Action {
|
|
|
74
133
|
* This should be used when the content you want to render is not the default content
|
|
75
134
|
*/
|
|
76
135
|
customContent?: ReactNode,
|
|
136
|
+
/**
|
|
137
|
+
* Whether or not this section is currently active.
|
|
138
|
+
*/
|
|
77
139
|
active?: boolean,
|
|
78
|
-
|
|
140
|
+
/**
|
|
141
|
+
* A css class to pass to the <li> tag.
|
|
142
|
+
*/
|
|
79
143
|
className?: string,
|
|
80
144
|
hidden?: boolean,
|
|
81
145
|
}
|
|
82
146
|
|
|
83
147
|
interface BaseMenuProps {
|
|
148
|
+
/**
|
|
149
|
+
* The sections of the menu.
|
|
150
|
+
*/
|
|
84
151
|
sections?: MenuSection[],
|
|
152
|
+
/**
|
|
153
|
+
* The content of the menu as a React Element. Use this to create anything you want as the menu content, but prefer using `content`
|
|
154
|
+
* instead, which is a predefined menu.
|
|
155
|
+
*/
|
|
85
156
|
customContent?: ReactNode,
|
|
157
|
+
/**
|
|
158
|
+
* Options for the settings button.
|
|
159
|
+
*/
|
|
86
160
|
settings?: {
|
|
161
|
+
/**
|
|
162
|
+
* Whether or not to show the settings button.
|
|
163
|
+
*/
|
|
87
164
|
show?: boolean,
|
|
165
|
+
/**
|
|
166
|
+
* A function to call when the button is clicked.
|
|
167
|
+
*/
|
|
88
168
|
onClick?: () => void,
|
|
169
|
+
/**
|
|
170
|
+
* A url to go to when the button is clicked.
|
|
171
|
+
*/
|
|
89
172
|
href?: string,
|
|
173
|
+
/**
|
|
174
|
+
* Whether or not this button represents the page currently active.
|
|
175
|
+
*/
|
|
90
176
|
active?: boolean,
|
|
177
|
+
/**
|
|
178
|
+
* A css class to pass to the button.
|
|
179
|
+
*/
|
|
91
180
|
className?: string,
|
|
92
181
|
},
|
|
93
182
|
}
|
|
94
183
|
|
|
95
184
|
export interface MenuPropsWithStaticContent extends BaseMenuProps {
|
|
185
|
+
/**
|
|
186
|
+
* The config for creating the menu content.
|
|
187
|
+
*/
|
|
96
188
|
content?: MenuSectionContent,
|
|
97
189
|
}
|
|
98
190
|
|
|
99
191
|
export interface MenuPropsWithDynamicContent extends BaseMenuProps {
|
|
100
192
|
/**
|
|
101
|
-
* The function that creates
|
|
102
|
-
* be rendered.
|
|
193
|
+
* The function that creates a config to render a menu content. It will be called only when the content is rendered, i.e. only when the
|
|
194
|
+
* content really needs to be rendered.
|
|
103
195
|
*
|
|
104
196
|
* Tip: this function can be a React Hook.
|
|
105
197
|
*/
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Box, Image, Text } from '@citric/core'
|
|
2
|
-
import { TourStep, tourStepBuilder } from '@stack-spot/portal-components'
|
|
2
|
+
import { TourStep, tourStepBuilder } from '@stack-spot/portal-components/Tour'
|
|
3
3
|
import { useTranslate } from '@stack-spot/portal-translate'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tutorial: a React hook for retrieving the React Tour step that explains how the portal switcher works. The portal switcher is a component
|
|
7
|
+
* at the top left corner of the layout (header) that allows the user to switch between the different Stackspot portals.
|
|
8
|
+
* @returns the React Tour step for the PortalSwitcher.
|
|
9
|
+
*/
|
|
4
10
|
export const usePortalSwitcherStep = (): TourStep => {
|
|
5
11
|
const t = useTranslate(translations)
|
|
6
12
|
return tourStepBuilder({
|
|
@@ -19,9 +25,6 @@ export const usePortalSwitcherStep = (): TourStep => {
|
|
|
19
25
|
})
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
28
|
const translations = {
|
|
26
29
|
en: {
|
|
27
30
|
title: 'Expand Your Horizons with Stackspot',
|
package/src/components/types.ts
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react'
|
|
2
|
-
|
|
3
|
-
interface CustomLabel {
|
|
4
|
-
id: string,
|
|
5
|
-
element: ReactNode,
|
|
6
|
-
}
|
|
7
|
-
export interface Action {
|
|
8
|
-
label: string | CustomLabel,
|
|
9
|
-
onClick?: () => void,
|
|
10
|
-
href?: string,
|
|
11
|
-
target?: React.AnchorHTMLAttributes<HTMLAnchorElement>['target'],
|
|
12
|
-
iconActive?: React.ReactElement,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
1
|
export type PortalAcronym = 'EDP' | 'AI' | 'HUB'
|
package/src/dictionary.ts
CHANGED
package/src/elements.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ids of the layout elements.
|
|
3
|
+
*/
|
|
1
4
|
export const elementIds = {
|
|
2
5
|
layout: 'layout',
|
|
3
6
|
backdrop: 'backdrop',
|
|
@@ -16,6 +19,9 @@ export const elementIds = {
|
|
|
16
19
|
export type LayoutElement = keyof typeof elementIds
|
|
17
20
|
export type LayoutElements = Record<LayoutElement, HTMLElement | null>
|
|
18
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @returns an object with the html elements of the layout.
|
|
24
|
+
*/
|
|
19
25
|
export function getLayoutElements() {
|
|
20
26
|
return (Object.keys(elementIds) as LayoutElement[]).reduce<LayoutElements>(
|
|
21
27
|
(result, id) => ({ ...result, [id]: document.getElementById(id) }),
|
package/src/index.ts
CHANGED
|
@@ -4,14 +4,11 @@ export { Dialog } from './components/Dialog'
|
|
|
4
4
|
export { Header, HeaderProps } from './components/Header'
|
|
5
5
|
export { OverlayContent } from './components/OverlayContent'
|
|
6
6
|
export { PortalSwitcher } from './components/PortalSwitcher'
|
|
7
|
-
export { ListAction, SelectionList, SelectionListProps } from './components/SelectionList'
|
|
8
|
-
export { Toaster } from './components/Toaster'
|
|
9
7
|
export { ActionItem, MenuContent, MenuGroup, Title } from './components/menu/MenuContent'
|
|
10
8
|
export { MenuSections } from './components/menu/MenuSections'
|
|
11
9
|
export * from './components/menu/types'
|
|
12
10
|
export * from './components/types'
|
|
13
11
|
export * from './elements'
|
|
14
12
|
export * from './errors'
|
|
15
|
-
export { Logo as StackspotLogo } from './svg/Logo'
|
|
16
13
|
export * from './utils'
|
|
17
14
|
|
package/src/layout.css
CHANGED
|
@@ -245,6 +245,7 @@ body {
|
|
|
245
245
|
pointer-events: none;
|
|
246
246
|
z-index: 1;
|
|
247
247
|
transition: opacity 0.3s;
|
|
248
|
+
overflow-y: auto;
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
#menuContentOverlay.visible {
|
|
@@ -252,11 +253,6 @@ body {
|
|
|
252
253
|
pointer-events: auto;
|
|
253
254
|
}
|
|
254
255
|
|
|
255
|
-
#menuContentOverlay > div {
|
|
256
|
-
flex: 1;
|
|
257
|
-
overflow: auto;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
256
|
#menuContent {
|
|
261
257
|
width: var(--menu-content-width);
|
|
262
258
|
transition: left ease-out var(--menu-animation-duration);
|
package/src/toaster.tsx
CHANGED
|
@@ -1,30 +1,94 @@
|
|
|
1
|
-
import { IconBox, OneOfColorSchemesWithVariants } from '@citric/core'
|
|
1
|
+
import { Flex, IconBox, OneOfColorSchemesWithVariants, Text } from '@citric/core'
|
|
2
2
|
import { CheckCircleFill, ExclamationCircleFill, ExclamationTriangleFill, InfoCircleFill } from '@citric/icons'
|
|
3
|
+
import React from 'react'
|
|
3
4
|
import { toast } from 'react-toastify'
|
|
4
5
|
import 'react-toastify/dist/ReactToastify.css'
|
|
5
6
|
|
|
6
7
|
type ToastType = 'error' | 'success' | 'warning' | 'info'
|
|
7
8
|
|
|
8
|
-
interface
|
|
9
|
+
interface BaseOptions {
|
|
10
|
+
/**
|
|
11
|
+
* An identifier for the toaster, if not provided, `Math.random()` will be used.
|
|
12
|
+
*
|
|
13
|
+
* The id can be used to programmatically control the toaster.
|
|
14
|
+
*/
|
|
15
|
+
id?: number | string,
|
|
16
|
+
/**
|
|
17
|
+
* The message to show.
|
|
18
|
+
* Can be either a string or a React element.
|
|
19
|
+
*/
|
|
20
|
+
message: React.ReactNode,
|
|
21
|
+
/**
|
|
22
|
+
* Level/severity of this message.
|
|
23
|
+
* @default 'info'
|
|
24
|
+
*/
|
|
9
25
|
type?: ToastType,
|
|
10
26
|
/**
|
|
11
27
|
* Seconds until auto-close or false to not auto-close.
|
|
12
|
-
* @default
|
|
28
|
+
* @default 3s for success toast and 10s for the others
|
|
13
29
|
*/
|
|
14
30
|
autoClose?: number | false,
|
|
31
|
+
/**
|
|
32
|
+
* If true, `message` must be a React Element and none of the default toaster UI is rendered (title, icon and close button).
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
custom?: boolean,
|
|
36
|
+
/**
|
|
37
|
+
* Whether or not to close the toaster when the user clicks it.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
closeOnClick?: boolean,
|
|
15
41
|
}
|
|
16
42
|
|
|
17
|
-
interface
|
|
18
|
-
|
|
43
|
+
interface ToasterAction {
|
|
44
|
+
/**
|
|
45
|
+
* The button's label.
|
|
46
|
+
*/
|
|
47
|
+
label: string,
|
|
48
|
+
/**
|
|
49
|
+
* A function to run once the button is clicked.
|
|
50
|
+
*/
|
|
51
|
+
onClick?: (event: React.MouseEvent) => void,
|
|
52
|
+
/**
|
|
53
|
+
* If this is set, instead of a button, an anchor is rendered with this href.
|
|
54
|
+
*/
|
|
55
|
+
href?: string,
|
|
56
|
+
/**
|
|
57
|
+
* Whether or not to close the toaster once the button is clicked.
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
closeOnClick?: boolean,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface DefaultToasterOptions extends BaseOptions {
|
|
64
|
+
/**
|
|
65
|
+
* The title of the toaster.
|
|
66
|
+
*/
|
|
19
67
|
title?: string,
|
|
68
|
+
/**
|
|
69
|
+
* A function to call when the user clicks the toaster. By default, it closes the toaster.
|
|
70
|
+
*/
|
|
20
71
|
onClick?: () => void,
|
|
72
|
+
/**
|
|
73
|
+
* A set of buttons (or links/anchors) to show after the message.
|
|
74
|
+
*/
|
|
75
|
+
actions?: ToasterAction[],
|
|
76
|
+
custom?: false,
|
|
21
77
|
}
|
|
22
78
|
|
|
23
|
-
interface
|
|
24
|
-
|
|
79
|
+
export interface CustomToasterOptions extends BaseOptions {
|
|
80
|
+
/**
|
|
81
|
+
* The whole content to render inside the toaster.
|
|
82
|
+
*/
|
|
83
|
+
message: React.ReactElement,
|
|
84
|
+
custom: true,
|
|
85
|
+
/**
|
|
86
|
+
* A close button to render on the top right corner of the toaster. If not provided, a close button won't be rendered.
|
|
87
|
+
*/
|
|
88
|
+
closeButton?: React.ReactElement,
|
|
25
89
|
}
|
|
26
90
|
|
|
27
|
-
type
|
|
91
|
+
export type ToasterOptions = DefaultToasterOptions | CustomToasterOptions | React.ReactNode
|
|
28
92
|
|
|
29
93
|
const toasterConfig: Record<ToastType, { element: React.ReactElement, color: string, duration: number }> = {
|
|
30
94
|
error: {
|
|
@@ -49,28 +113,75 @@ const toasterConfig: Record<ToastType, { element: React.ReactElement, color: str
|
|
|
49
113
|
},
|
|
50
114
|
}
|
|
51
115
|
|
|
52
|
-
export function showToaster(
|
|
116
|
+
export function showToaster(defaultToasterConfig: DefaultToasterOptions): number | string
|
|
117
|
+
export function showToaster(customToasterConfig: CustomToasterOptions): number | string
|
|
118
|
+
export function showToaster(message: React.ReactNode): number | string
|
|
119
|
+
export function showToaster(options: ToasterOptions): number | string {
|
|
120
|
+
const isToasterConfig = options && typeof options === 'object' && 'message' in options
|
|
121
|
+
const { type = 'info', autoClose, ...opts }: DefaultToasterOptions | CustomToasterOptions = isToasterConfig
|
|
122
|
+
? options
|
|
123
|
+
: { message: options }
|
|
53
124
|
const config = toasterConfig[type]
|
|
125
|
+
const id = opts.id ?? Math.random()
|
|
54
126
|
const closeTime = autoClose ? autoClose : config.duration
|
|
55
127
|
const bg = `var(--${config.color}-500)`
|
|
56
128
|
const bgDark = `var(--${config.color}-600)`
|
|
57
129
|
const fg = `var(--${config.color}-contrastText)`
|
|
130
|
+
const actionStyle: React.CSSProperties = {
|
|
131
|
+
background: 'transparent',
|
|
132
|
+
border: 'none',
|
|
133
|
+
padding: 0,
|
|
134
|
+
color: 'inherit',
|
|
135
|
+
font: 'inherit',
|
|
136
|
+
fontWeight: 500,
|
|
137
|
+
cursor: 'pointer',
|
|
138
|
+
}
|
|
139
|
+
const buttons = opts.custom ? null : opts.actions?.map(
|
|
140
|
+
({ label, href, onClick, closeOnClick = true }) => (
|
|
141
|
+
<Text
|
|
142
|
+
key={label}
|
|
143
|
+
as={href ? 'a' : 'button'}
|
|
144
|
+
href={href}
|
|
145
|
+
style={actionStyle}
|
|
146
|
+
onClick={(event: React.MouseEvent) => {
|
|
147
|
+
onClick?.(event)
|
|
148
|
+
if (closeOnClick) closeReactToaster(id)
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
{label}
|
|
152
|
+
</Text>
|
|
153
|
+
),
|
|
154
|
+
)
|
|
58
155
|
toast(
|
|
59
|
-
|
|
60
|
-
?
|
|
61
|
-
:
|
|
156
|
+
opts.custom
|
|
157
|
+
? opts.message
|
|
158
|
+
: (
|
|
159
|
+
<div onClick={opts.onClick}>
|
|
160
|
+
<h1 style={{ textTransform: 'capitalize' }}>{opts.title ?? type}</h1>
|
|
161
|
+
{typeof opts.message === 'string' ? <p>{opts.message}</p> : opts.message}
|
|
162
|
+
{buttons?.length ? <Flex style={{ gap: '12px', marginTop: '12px' }}>{buttons}</Flex> : null}
|
|
163
|
+
</div>
|
|
164
|
+
),
|
|
62
165
|
{
|
|
166
|
+
toastId: id,
|
|
63
167
|
type,
|
|
64
168
|
autoClose: autoClose === false ? false : closeTime * 1000,
|
|
65
169
|
className: 'main-toaster',
|
|
66
170
|
style: { backgroundColor: bg, color: fg },
|
|
67
171
|
progressStyle: { background: bgDark },
|
|
68
172
|
bodyClassName: 'toast-body',
|
|
69
|
-
icon:
|
|
173
|
+
icon: opts.custom ? false : () => (
|
|
70
174
|
<IconBox colorIcon={`${config.color}.contrastText` as OneOfColorSchemesWithVariants} size="xs">
|
|
71
175
|
{config.element}
|
|
72
176
|
</IconBox>
|
|
73
|
-
)
|
|
177
|
+
),
|
|
178
|
+
closeOnClick: opts.closeOnClick ?? false,
|
|
179
|
+
closeButton: opts.custom ? (opts.closeButton ?? false) : undefined,
|
|
74
180
|
},
|
|
75
181
|
)
|
|
182
|
+
return id
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function closeReactToaster(id: number | string) {
|
|
186
|
+
toast.dismiss(id)
|
|
76
187
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,152 +1,19 @@
|
|
|
1
1
|
import { valueOf } from '@stack-spot/portal-theme'
|
|
2
2
|
import { getLayoutElements } from './elements'
|
|
3
3
|
|
|
4
|
-
export function valueOfLayoutVar(varname: string): string {
|
|
5
|
-
const layout = document.getElementById('layout')
|
|
6
|
-
if (!layout) return ''
|
|
7
|
-
return valueOf(varname, layout)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
4
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Makes it so we focus the next focusable element in the DOM hierarchy, disregarding the element passed as parameter and its children.
|
|
5
|
+
* Gets the value for a css variable of the layout.
|
|
14
6
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @param current the reference element to focus the next. If not provided, will be the currently active element.
|
|
19
|
-
*/
|
|
20
|
-
export function focusNextIgnoringChildren(current?: HTMLElement | null) {
|
|
21
|
-
current = current ?? document.activeElement as HTMLElement
|
|
22
|
-
while (current && !current.nextElementSibling) {
|
|
23
|
-
current = current?.parentElement
|
|
24
|
-
}
|
|
25
|
-
current = current?.nextElementSibling as HTMLElement
|
|
26
|
-
while (current && current.tabIndex < 0) {
|
|
27
|
-
current = (current.children.length ? current.firstChild : current.nextElementSibling) as HTMLElement
|
|
28
|
-
}
|
|
29
|
-
if (current) current?.focus?.()
|
|
30
|
-
else focusFirstChild(document)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type TagPriority = 'a' | 'button' | 'input' | 'textarea' | 'select' | 'other'
|
|
34
|
-
type TagPriorityElement = TagPriority | TagPriority[]
|
|
35
|
-
|
|
36
|
-
interface FocusOptions {
|
|
37
|
-
/**
|
|
38
|
-
* Instead of focusing the first element overall, focus the first according to this list of priorities.
|
|
39
|
-
*/
|
|
40
|
-
priority?: TagPriorityElement[],
|
|
41
|
-
/**
|
|
42
|
-
* Ignores any element that matches this query selector.
|
|
43
|
-
*/
|
|
44
|
-
ignore?: string,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const selectors: Record<TagPriority, string> = {
|
|
48
|
-
a: 'a[href]:not(:disabled)',
|
|
49
|
-
button: 'button:not(:disabled)',
|
|
50
|
-
input: 'input:not(:disabled):not([type="hidden"])',
|
|
51
|
-
select: 'textarea:not(:disabled)',
|
|
52
|
-
textarea: 'select:not(:disabled)',
|
|
53
|
-
other: '[tabindex]:not([tabindex="-1"])',
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Checks if an element can receive focus.
|
|
7
|
+
* Supposing the actual name of the variable is name-of-variable, the value passed to the first parameter (varname) may be: name-of-variable
|
|
8
|
+
* or --name-of-variable or var(--name-of-variable). All these formats work.
|
|
58
9
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* - they're visible;
|
|
62
|
-
* - they're not disabled;
|
|
63
|
-
* - they are a focusable tag name or have a positive tab index;
|
|
64
|
-
* - they don't have a negative tab index.
|
|
65
|
-
* @param element the element to check.
|
|
66
|
-
* @returns true if the element is focusable, false otherwise.
|
|
10
|
+
* @param varname the name of css variable.
|
|
11
|
+
* @returns the value of `varname`.
|
|
67
12
|
*/
|
|
68
|
-
export function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// is invisible: return false
|
|
73
|
-
if (!element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true })) return false
|
|
74
|
-
// has tab index: return false if negative, true otherwise
|
|
75
|
-
const tabIndexStr = element.getAttribute('tabindex')
|
|
76
|
-
const tabIndex = tabIndexStr ? parseInt(tabIndexStr) : undefined
|
|
77
|
-
if (tabIndex !== undefined) return tabIndex >= 0
|
|
78
|
-
// check the tag name
|
|
79
|
-
return ['a', 'button', 'input', 'iframe', 'select', 'textarea'].includes(element.tagName.toLowerCase() ?? '')
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Focus the element passed as parameter if it can receive focus. Otherwise, decides on another element to focus based on the HTML tree
|
|
84
|
-
* and accessibility attributes.
|
|
85
|
-
*
|
|
86
|
-
* Decision making:
|
|
87
|
-
* - If the element is focusable, focus it.
|
|
88
|
-
* - If the element is not focusable, check if it has an id and if another element controls it (aria-controls).
|
|
89
|
-
* - If the element is controlled by another, try to focus the controller, based in this same algorithm.
|
|
90
|
-
* - Otherwise, try to focus its parent.
|
|
91
|
-
*
|
|
92
|
-
* If no focusable element is found. Nothing happens.
|
|
93
|
-
* @param element the element to focus.
|
|
94
|
-
*/
|
|
95
|
-
export function focusAccessibleElement(element?: Element | null) {
|
|
96
|
-
let elementToFocus = element as HTMLElement | null | undefined
|
|
97
|
-
while (elementToFocus && !isFocusable(elementToFocus)) {
|
|
98
|
-
const controlledBy = elementToFocus.id ? document.querySelector(`[aria-controls=${elementToFocus.id}]`) : undefined
|
|
99
|
-
elementToFocus = (controlledBy ?? elementToFocus.parentElement) as HTMLElement | null | undefined
|
|
100
|
-
}
|
|
101
|
-
elementToFocus?.focus?.()
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Focus the first focusable child of the element provided. If the element has no focusable child, nothing happens.
|
|
106
|
-
*
|
|
107
|
-
* A priority list can be passed in the second parameter, as an option. If it's provided, it will focus the first element according to the
|
|
108
|
-
* list.
|
|
109
|
-
*
|
|
110
|
-
* An ignore query selector can also be passed in the options parameter. If the first focusable element matches the query selector, the
|
|
111
|
-
* next element is focused instead.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* Suppose the children of element are: h1, button, p, input, select.
|
|
115
|
-
* 1. We don't pass a priority list. The focused element will be the button.
|
|
116
|
-
* 2. Our priority list is ['button']. The focused element will be the button.
|
|
117
|
-
* 3. Our priority list is ['input', 'button']. The focused element will be the input.
|
|
118
|
-
* 4. Our priority list is ['select', 'input']. The focused element will be the select.
|
|
119
|
-
* 5. Our priority list is [['select', 'input'], 'button']. The focused element will be the input.
|
|
120
|
-
*
|
|
121
|
-
* @param element the element to search a child to focus.
|
|
122
|
-
* @param options optional.
|
|
123
|
-
*/
|
|
124
|
-
export function focusFirstChild(element: HTMLElement | Document | null | undefined, { priority = [], ignore }: FocusOptions = {}) {
|
|
125
|
-
let focusable: NodeListOf<HTMLElement> | null | undefined
|
|
126
|
-
let missing: TagPriority[] = ['a', 'button', 'input', 'other', 'select', 'textarea']
|
|
127
|
-
for (const p of priority) {
|
|
128
|
-
const tags = Array.isArray(p) ? p : [p]
|
|
129
|
-
const querySelectors = tags.map(t => {
|
|
130
|
-
missing = missing.filter(tag => tag != t)
|
|
131
|
-
return selectors[t]
|
|
132
|
-
})
|
|
133
|
-
focusable = element?.querySelectorAll(querySelectors.join(', '))
|
|
134
|
-
if (focusable) break
|
|
135
|
-
}
|
|
136
|
-
if (!focusable) {
|
|
137
|
-
element?.querySelectorAll(missing.map(t => selectors[t]).join(', '))
|
|
138
|
-
}
|
|
139
|
-
let elementToFocus: HTMLElement | undefined
|
|
140
|
-
for (const f of focusable ?? []) {
|
|
141
|
-
if (!ignore || !f.matches(ignore)) {
|
|
142
|
-
const styles = window.getComputedStyle(f)
|
|
143
|
-
if (styles.display != 'none' && styles.visibility != 'hidden') {
|
|
144
|
-
elementToFocus = f
|
|
145
|
-
break
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
elementToFocus?.focus?.()
|
|
13
|
+
export function valueOfLayoutVar(varname: string): string {
|
|
14
|
+
const layout = document.getElementById('layout')
|
|
15
|
+
if (!layout) return ''
|
|
16
|
+
return valueOf(varname, layout)
|
|
150
17
|
}
|
|
151
18
|
|
|
152
19
|
/**
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=BottomNotification.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BottomNotification.d.ts","sourceRoot":"","sources":["../../src/components/BottomNotification.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BottomNotification.js","sourceRoot":"","sources":["../../src/components/BottomNotification.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=BottomPanel.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BottomPanel.d.ts","sourceRoot":"","sources":["../../src/components/BottomPanel.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BottomPanel.js","sourceRoot":"","sources":["../../src/components/BottomPanel.tsx"],"names":[],"mappings":""}
|