@stack-spot/portal-layout 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/Layout.d.ts +2 -2
  2. package/dist/Layout.js +1 -1
  3. package/dist/LayoutOverlayManager.js +6 -6
  4. package/dist/LayoutOverlayManager.js.map +1 -1
  5. package/dist/components/Dialog.d.ts +1 -1
  6. package/dist/components/Dialog.js +1 -1
  7. package/dist/components/Header.d.ts +1 -1
  8. package/dist/components/Header.js +1 -1
  9. package/dist/components/OverlayContent.d.ts +1 -1
  10. package/dist/components/OverlayContent.js +20 -20
  11. package/dist/components/PortalSwitcher.d.ts +1 -1
  12. package/dist/components/PortalSwitcher.js +54 -54
  13. package/dist/components/Toaster.d.ts +33 -1
  14. package/dist/components/Toaster.d.ts.map +1 -1
  15. package/dist/components/Toaster.js +26 -2
  16. package/dist/components/Toaster.js.map +1 -1
  17. package/dist/components/UserMenu.d.ts +1 -1
  18. package/dist/components/UserMenu.js +41 -41
  19. package/dist/components/error/ErrorBoundary.d.ts +1 -1
  20. package/dist/components/error/ErrorBoundary.js +1 -1
  21. package/dist/components/error/SilentErrorBoundary.d.ts +1 -1
  22. package/dist/components/error/SilentErrorBoundary.js +1 -1
  23. package/dist/components/menu/MenuContent.d.ts +2 -2
  24. package/dist/components/menu/MenuContent.d.ts.map +1 -1
  25. package/dist/components/menu/MenuContent.js +125 -132
  26. package/dist/components/menu/MenuContent.js.map +1 -1
  27. package/dist/components/menu/MenuSections.d.ts +1 -1
  28. package/dist/components/menu/MenuSections.js +1 -1
  29. package/dist/components/menu/MenuSections.js.map +1 -1
  30. package/dist/components/menu/PageSelector.d.ts +1 -1
  31. package/dist/components/menu/PageSelector.js +69 -69
  32. package/dist/components/menu/PageSelector.js.map +1 -1
  33. package/dist/components/tour/PortalSwitcherStep.js +1 -1
  34. package/dist/layout.css +477 -468
  35. package/dist/toaster.d.ts +2 -20
  36. package/dist/toaster.d.ts.map +1 -1
  37. package/dist/toaster.js +19 -17
  38. package/dist/toaster.js.map +1 -1
  39. package/package.json +3 -2
  40. package/readme.md +146 -146
  41. package/src/Layout.tsx +171 -171
  42. package/src/LayoutOverlayManager.tsx +464 -464
  43. package/src/components/Dialog.tsx +140 -140
  44. package/src/components/Header.tsx +62 -62
  45. package/src/components/OverlayContent.tsx +80 -80
  46. package/src/components/PortalSwitcher.tsx +161 -161
  47. package/src/components/Toaster.tsx +95 -24
  48. package/src/components/UserMenu.tsx +124 -124
  49. package/src/components/error/ErrorBoundary.tsx +47 -47
  50. package/src/components/error/ErrorManager.ts +47 -47
  51. package/src/components/error/SilentErrorBoundary.tsx +64 -64
  52. package/src/components/menu/MenuContent.tsx +270 -277
  53. package/src/components/menu/MenuSections.tsx +320 -320
  54. package/src/components/menu/PageSelector.tsx +164 -164
  55. package/src/components/menu/constants.ts +2 -2
  56. package/src/components/menu/types.ts +205 -205
  57. package/src/components/tour/PortalSwitcherStep.tsx +39 -39
  58. package/src/components/types.ts +1 -1
  59. package/src/dictionary.ts +28 -28
  60. package/src/elements.ts +30 -30
  61. package/src/errors.ts +11 -11
  62. package/src/index.ts +14 -14
  63. package/src/layout.css +477 -468
  64. package/src/toaster.tsx +153 -187
  65. package/src/utils.ts +29 -29
  66. package/tsconfig.json +8 -8
@@ -1,124 +1,124 @@
1
- import { Flex, IconBox, LinkBox, Text } from '@citric/core'
2
- import { ChevronDown } from '@citric/icons'
3
- import { Avatar } from '@citric/ui'
4
- import { SelectionList, SelectionListProps } from '@stack-spot/portal-components/SelectionList'
5
- import { theme } from '@stack-spot/portal-theme'
6
- import { Dictionary, interpolate, useTranslate } from '@stack-spot/portal-translate'
7
- import { useState } from 'react'
8
- import { styled } from 'styled-components'
9
-
10
- interface Props {
11
- /**
12
- * The user name.
13
- */
14
- userName: string,
15
- /**
16
- * The user email.
17
- */
18
- email?: string,
19
- /**
20
- * The menu options.
21
- */
22
- options?: SelectionListProps['items'],
23
- }
24
-
25
- const USER_MENU_ID = 'userMenu'
26
-
27
- const UserMenuBox = styled.div`
28
- .user-menu-header {
29
- display: flex;
30
- flex-direction: column;
31
- justify-content: center;
32
- align-items: center;
33
- padding: 12px;
34
- border-bottom: 2px solid ${theme.color.light['600']};
35
- }
36
-
37
- .selection-list {
38
- position: absolute;
39
- top: var(--header-height);
40
- right: 20px;
41
- width: 266px;
42
-
43
- .selection-list-content {
44
- border: none;
45
- padding: 16px 16px 8px;
46
- background-color: ${theme.color.light['400']};
47
- }
48
-
49
- li {
50
- margin: 8px 0;
51
- & > a {
52
- border-radius: 6px;
53
- &:hover, &:focus {
54
- background: ${theme.color.light['500']};
55
- }
56
- }
57
- }
58
- }
59
-
60
- .username {
61
- margin: 5px 0 2px 0;
62
- }
63
-
64
- .chevron {
65
- transition: transform ease-out 0.3s;
66
- }
67
- `
68
-
69
- const UserMenuHeader = ({ userName, email }: Omit<Props, 'options'>) => (
70
- <div className="user-menu-header">
71
- <Avatar size="xs">{userName}</Avatar>
72
- <Text appearance="body1" className="username">{userName}</Text>
73
- {email && <Text appearance="microtext1" className="email" colorScheme="light.700">{email}</Text>}
74
- </div>
75
- )
76
-
77
- /**
78
- * Renders the user menu.
79
- * @param props the component's props {@link Props}.
80
- */
81
- export const UserMenu = ({ userName, email, options }: Props) => {
82
- const t = useTranslate(dictionary)
83
- const [visible, setVisible] = useState(false)
84
-
85
- return (
86
- <UserMenuBox>
87
- <LinkBox
88
- as="button"
89
- onClick={() => setVisible(v => !v)}
90
- aria-controls={USER_MENU_ID}
91
- aria-expanded={visible}
92
- aria-label={interpolate(t.accountMenu, [userName])}
93
- >
94
- <Flex alignItems="center">
95
- <Avatar size="xs" aria-label={interpolate(t.accountMenu, [userName])}>{userName}</Avatar>
96
- <IconBox colorIcon="inverse.500" className="chevron" style={visible ? { transform: 'rotate(180deg)' } : undefined}>
97
- <ChevronDown />
98
- </IconBox>
99
- </Flex>
100
- </LinkBox>
101
-
102
- {options?.length
103
- ? <SelectionList
104
- id={USER_MENU_ID}
105
- visible={visible}
106
- before={<UserMenuHeader userName={userName} email={email} />}
107
- items={options!}
108
- onHide={() => setVisible(false)}
109
- maxHeight="600px"
110
- />
111
- : null
112
- }
113
- </UserMenuBox>
114
- )
115
- }
116
-
117
- const dictionary = {
118
- en: {
119
- accountMenu: 'Profile menu of $0',
120
- },
121
- pt: {
122
- accountMenu: 'Menu do perfil $0',
123
- },
124
- } satisfies Dictionary
1
+ import { Flex, IconBox, LinkBox, Text } from '@citric/core'
2
+ import { ChevronDown } from '@citric/icons'
3
+ import { Avatar } from '@citric/ui'
4
+ import { SelectionList, SelectionListProps } from '@stack-spot/portal-components/SelectionList'
5
+ import { theme } from '@stack-spot/portal-theme'
6
+ import { Dictionary, interpolate, useTranslate } from '@stack-spot/portal-translate'
7
+ import { useState } from 'react'
8
+ import { styled } from 'styled-components'
9
+
10
+ interface Props {
11
+ /**
12
+ * The user name.
13
+ */
14
+ userName: string,
15
+ /**
16
+ * The user email.
17
+ */
18
+ email?: string,
19
+ /**
20
+ * The menu options.
21
+ */
22
+ options?: SelectionListProps['items'],
23
+ }
24
+
25
+ const USER_MENU_ID = 'userMenu'
26
+
27
+ const UserMenuBox = styled.div`
28
+ .user-menu-header {
29
+ display: flex;
30
+ flex-direction: column;
31
+ justify-content: center;
32
+ align-items: center;
33
+ padding: 12px;
34
+ border-bottom: 2px solid ${theme.color.light['600']};
35
+ }
36
+
37
+ .selection-list {
38
+ position: absolute;
39
+ top: var(--header-height);
40
+ right: 20px;
41
+ width: 266px;
42
+
43
+ .selection-list-content {
44
+ border: none;
45
+ padding: 16px 16px 8px;
46
+ background-color: ${theme.color.light['400']};
47
+ }
48
+
49
+ li {
50
+ margin: 8px 0;
51
+ & > a {
52
+ border-radius: 6px;
53
+ &:hover, &:focus {
54
+ background: ${theme.color.light['500']};
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ .username {
61
+ margin: 5px 0 2px 0;
62
+ }
63
+
64
+ .chevron {
65
+ transition: transform ease-out 0.3s;
66
+ }
67
+ `
68
+
69
+ const UserMenuHeader = ({ userName, email }: Omit<Props, 'options'>) => (
70
+ <div className="user-menu-header">
71
+ <Avatar size="xs">{userName}</Avatar>
72
+ <Text appearance="body1" className="username">{userName}</Text>
73
+ {email && <Text appearance="microtext1" className="email" colorScheme="light.700">{email}</Text>}
74
+ </div>
75
+ )
76
+
77
+ /**
78
+ * Renders the user menu.
79
+ * @param props the component's props {@link Props}.
80
+ */
81
+ export const UserMenu = ({ userName, email, options }: Props) => {
82
+ const t = useTranslate(dictionary)
83
+ const [visible, setVisible] = useState(false)
84
+
85
+ return (
86
+ <UserMenuBox>
87
+ <LinkBox
88
+ as="button"
89
+ onClick={() => setVisible(v => !v)}
90
+ aria-controls={USER_MENU_ID}
91
+ aria-expanded={visible}
92
+ aria-label={interpolate(t.accountMenu, [userName])}
93
+ >
94
+ <Flex alignItems="center">
95
+ <Avatar size="xs" aria-label={interpolate(t.accountMenu, [userName])}>{userName}</Avatar>
96
+ <IconBox colorIcon="inverse.500" className="chevron" style={visible ? { transform: 'rotate(180deg)' } : undefined}>
97
+ <ChevronDown />
98
+ </IconBox>
99
+ </Flex>
100
+ </LinkBox>
101
+
102
+ {options?.length
103
+ ? <SelectionList
104
+ id={USER_MENU_ID}
105
+ visible={visible}
106
+ before={<UserMenuHeader userName={userName} email={email} />}
107
+ items={options!}
108
+ onHide={() => setVisible(false)}
109
+ maxHeight="600px"
110
+ />
111
+ : null
112
+ }
113
+ </UserMenuBox>
114
+ )
115
+ }
116
+
117
+ const dictionary = {
118
+ en: {
119
+ accountMenu: 'Profile menu of $0',
120
+ },
121
+ pt: {
122
+ accountMenu: 'Menu do perfil $0',
123
+ },
124
+ } satisfies Dictionary
@@ -1,47 +1,47 @@
1
- import { ErrorDescription, ErrorFeedback } from '@stack-spot/portal-components/ErrorFeedback'
2
- import { Component } from 'react'
3
- import { ErrorManager } from './ErrorManager'
4
-
5
- interface State extends ErrorDescription {
6
- hasError: boolean,
7
- }
8
-
9
- interface Props {
10
- children: React.ReactNode,
11
- }
12
-
13
- /**
14
- * An Error Boundary that renders an ErrorFeedback instead of its content if any of its children throws.
15
- *
16
- * To customize what properties are passed to the ErrorFeedback component, setup an error descriptor for the ErrorManager class. If you're
17
- * using the component `Layout` or `RawLayout`, you can use the property `errorDescriptor`.
18
- *
19
- * To run an error handler every time an error is catch by this boundary, setup an error handler for the ErrorManager class. If you're
20
- * using the component `Layout` or `RawLayout`, you can use the property `onError`.
21
- */
22
- export class ErrorBoundary extends Component<Props, State> {
23
- constructor(props: Props) {
24
- super(props)
25
- this.state = { hasError: false }
26
- }
27
-
28
- static getDerivedStateFromError(error: any) {
29
- return { hasError: true, ...ErrorManager.describe(error) }
30
- }
31
-
32
- componentDidCatch(error: any, errorInfo: any) {
33
- // eslint-disable-next-line no-console
34
- console.error(error, errorInfo)
35
- ErrorManager.runErrorHandler(error)
36
- }
37
-
38
- componentDidUpdate(prevProps: Readonly<Props>) {
39
- if (this.props.children !== prevProps.children) this.setState({ hasError: false })
40
- }
41
-
42
- render() {
43
- return this.state.hasError
44
- ? <ErrorFeedback code={this.state.code} message={this.state.message} debug={this.state.debug} />
45
- : this.props.children
46
- }
47
- }
1
+ import { ErrorDescription, ErrorFeedback } from '@stack-spot/portal-components/ErrorFeedback'
2
+ import { Component } from 'react'
3
+ import { ErrorManager } from './ErrorManager'
4
+
5
+ interface State extends ErrorDescription {
6
+ hasError: boolean,
7
+ }
8
+
9
+ interface Props {
10
+ children: React.ReactNode,
11
+ }
12
+
13
+ /**
14
+ * An Error Boundary that renders an ErrorFeedback instead of its content if any of its children throws.
15
+ *
16
+ * To customize what properties are passed to the ErrorFeedback component, setup an error descriptor for the ErrorManager class. If you're
17
+ * using the component `Layout` or `RawLayout`, you can use the property `errorDescriptor`.
18
+ *
19
+ * To run an error handler every time an error is catch by this boundary, setup an error handler for the ErrorManager class. If you're
20
+ * using the component `Layout` or `RawLayout`, you can use the property `onError`.
21
+ */
22
+ export class ErrorBoundary extends Component<Props, State> {
23
+ constructor(props: Props) {
24
+ super(props)
25
+ this.state = { hasError: false }
26
+ }
27
+
28
+ static getDerivedStateFromError(error: any) {
29
+ return { hasError: true, ...ErrorManager.describe(error) }
30
+ }
31
+
32
+ componentDidCatch(error: any, errorInfo: any) {
33
+ // eslint-disable-next-line no-console
34
+ console.error(error, errorInfo)
35
+ ErrorManager.runErrorHandler(error)
36
+ }
37
+
38
+ componentDidUpdate(prevProps: Readonly<Props>) {
39
+ if (this.props.children !== prevProps.children) this.setState({ hasError: false })
40
+ }
41
+
42
+ render() {
43
+ return this.state.hasError
44
+ ? <ErrorFeedback code={this.state.code} message={this.state.message} debug={this.state.debug} />
45
+ : this.props.children
46
+ }
47
+ }
@@ -1,47 +1,47 @@
1
- import { ErrorDescription } from '@stack-spot/portal-components/ErrorFeedback'
2
-
3
- export type DescriptionFn = (error: any) => ErrorDescription
4
- export type ErrorHandler = (error: any) => void
5
-
6
- /**
7
- * Setup how the Error Boundaries deal with errors.
8
- */
9
- export class ErrorManager {
10
- private static descriptionFunction: DescriptionFn = error => ({
11
- message: error.message || `${error}`,
12
- })
13
- private static errorHandler: ErrorHandler | undefined
14
-
15
- /**
16
- * Sets a custom logic for generating error messages and codes. Also setups the environment (debug or not).
17
- * @param fn a function that, given an error, generates its description.
18
- */
19
- static setDescriptionFunction(fn: DescriptionFn) {
20
- this.descriptionFunction = fn
21
- }
22
-
23
- /**
24
- * Sets a custom error handler, i.e. a function to run every time an error is catch by an ErrorBoundary.
25
- * @param fn a function that receives the error.
26
- */
27
- static setErrorHandler(handler: ErrorHandler) {
28
- this.errorHandler = handler
29
- }
30
-
31
- /**
32
- * Uses the error descriptor to describe an error.
33
- * @param error the error
34
- * @returns the error description
35
- */
36
- static describe(error: any) {
37
- return this.descriptionFunction(error)
38
- }
39
-
40
- /**
41
- * Runs the error handler, if any has been setup.
42
- * @param error the error
43
- */
44
- static runErrorHandler(error: any) {
45
- this.errorHandler?.(error)
46
- }
47
- }
1
+ import { ErrorDescription } from '@stack-spot/portal-components/ErrorFeedback'
2
+
3
+ export type DescriptionFn = (error: any) => ErrorDescription
4
+ export type ErrorHandler = (error: any) => void
5
+
6
+ /**
7
+ * Setup how the Error Boundaries deal with errors.
8
+ */
9
+ export class ErrorManager {
10
+ private static descriptionFunction: DescriptionFn = error => ({
11
+ message: error.message || `${error}`,
12
+ })
13
+ private static errorHandler: ErrorHandler | undefined
14
+
15
+ /**
16
+ * Sets a custom logic for generating error messages and codes. Also setups the environment (debug or not).
17
+ * @param fn a function that, given an error, generates its description.
18
+ */
19
+ static setDescriptionFunction(fn: DescriptionFn) {
20
+ this.descriptionFunction = fn
21
+ }
22
+
23
+ /**
24
+ * Sets a custom error handler, i.e. a function to run every time an error is catch by an ErrorBoundary.
25
+ * @param fn a function that receives the error.
26
+ */
27
+ static setErrorHandler(handler: ErrorHandler) {
28
+ this.errorHandler = handler
29
+ }
30
+
31
+ /**
32
+ * Uses the error descriptor to describe an error.
33
+ * @param error the error
34
+ * @returns the error description
35
+ */
36
+ static describe(error: any) {
37
+ return this.descriptionFunction(error)
38
+ }
39
+
40
+ /**
41
+ * Runs the error handler, if any has been setup.
42
+ * @param error the error
43
+ */
44
+ static runErrorHandler(error: any) {
45
+ this.errorHandler?.(error)
46
+ }
47
+ }
@@ -1,64 +1,64 @@
1
- import { ErrorDescription } from '@stack-spot/portal-components/ErrorFeedback'
2
- import { theme } from '@stack-spot/portal-theme'
3
- import { Component } from 'react'
4
- import { ErrorManager } from './ErrorManager'
5
-
6
- interface State extends ErrorDescription {
7
- hasError: boolean,
8
- }
9
-
10
- interface Props {
11
- children: React.ReactNode,
12
- }
13
-
14
- /**
15
- * An Error Boundary that doesn't render anything if any of its children throws. If the environment is not production, a small error icon
16
- * is rendered instead of nothing.
17
- *
18
- * To customize how the error is logged, setup an error descriptor for the ErrorManager class. If you're using the component `Layout` or
19
- * `RawLayout`, you can use the property `errorDescriptor`.
20
- *
21
- * To run an error handler every time an error is catch by this boundary, setup an error handler for the ErrorManager class. If you're
22
- * using the component `Layout` or `RawLayout`, you can use the property `onError`.
23
- */
24
- export class SilentErrorBoundary extends Component<Props, State> {
25
- constructor(props: Props) {
26
- super(props)
27
- this.state = { hasError: false }
28
- }
29
-
30
- static getDerivedStateFromError(error: any) {
31
- return { hasError: true, ...ErrorManager.describe(error) }
32
- }
33
-
34
- componentDidCatch(error: any, errorInfo: any) {
35
- // eslint-disable-next-line no-console
36
- console.error(error, errorInfo)
37
- ErrorManager.runErrorHandler(error)
38
- }
39
-
40
- componentDidUpdate(prevProps: Readonly<Props>) {
41
- if (this.props.children !== prevProps.children) this.setState({ hasError: false })
42
- }
43
-
44
- render() {
45
- return this.state.hasError
46
- ? <div
47
- title={this.state.message ? `Error: ${this.state.message}` : undefined}
48
- style={{
49
- width: '16px',
50
- height: '16px',
51
- margin: '16px',
52
- background: theme.color.danger[500],
53
- color: theme.color.danger.contrastText,
54
- display: this.state.debug ? 'flex' : 'none',
55
- justifyContent: 'center',
56
- alignItems: 'center',
57
- fontWeight: 'bold',
58
- fontSize: '10px',
59
- borderRadius: '50%',
60
- }}
61
- >!</div>
62
- : this.props.children
63
- }
64
- }
1
+ import { ErrorDescription } from '@stack-spot/portal-components/ErrorFeedback'
2
+ import { theme } from '@stack-spot/portal-theme'
3
+ import { Component } from 'react'
4
+ import { ErrorManager } from './ErrorManager'
5
+
6
+ interface State extends ErrorDescription {
7
+ hasError: boolean,
8
+ }
9
+
10
+ interface Props {
11
+ children: React.ReactNode,
12
+ }
13
+
14
+ /**
15
+ * An Error Boundary that doesn't render anything if any of its children throws. If the environment is not production, a small error icon
16
+ * is rendered instead of nothing.
17
+ *
18
+ * To customize how the error is logged, setup an error descriptor for the ErrorManager class. If you're using the component `Layout` or
19
+ * `RawLayout`, you can use the property `errorDescriptor`.
20
+ *
21
+ * To run an error handler every time an error is catch by this boundary, setup an error handler for the ErrorManager class. If you're
22
+ * using the component `Layout` or `RawLayout`, you can use the property `onError`.
23
+ */
24
+ export class SilentErrorBoundary extends Component<Props, State> {
25
+ constructor(props: Props) {
26
+ super(props)
27
+ this.state = { hasError: false }
28
+ }
29
+
30
+ static getDerivedStateFromError(error: any) {
31
+ return { hasError: true, ...ErrorManager.describe(error) }
32
+ }
33
+
34
+ componentDidCatch(error: any, errorInfo: any) {
35
+ // eslint-disable-next-line no-console
36
+ console.error(error, errorInfo)
37
+ ErrorManager.runErrorHandler(error)
38
+ }
39
+
40
+ componentDidUpdate(prevProps: Readonly<Props>) {
41
+ if (this.props.children !== prevProps.children) this.setState({ hasError: false })
42
+ }
43
+
44
+ render() {
45
+ return this.state.hasError
46
+ ? <div
47
+ title={this.state.message ? `Error: ${this.state.message}` : undefined}
48
+ style={{
49
+ width: '16px',
50
+ height: '16px',
51
+ margin: '16px',
52
+ background: theme.color.danger[500],
53
+ color: theme.color.danger.contrastText,
54
+ display: this.state.debug ? 'flex' : 'none',
55
+ justifyContent: 'center',
56
+ alignItems: 'center',
57
+ fontWeight: 'bold',
58
+ fontSize: '10px',
59
+ borderRadius: '50%',
60
+ }}
61
+ >!</div>
62
+ : this.props.children
63
+ }
64
+ }