@stack-spot/portal-layout 0.0.49 → 0.0.51

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 (112) hide show
  1. package/dist/Layout.d.ts +5 -4
  2. package/dist/Layout.d.ts.map +1 -1
  3. package/dist/Layout.js +4 -3
  4. package/dist/Layout.js.map +1 -1
  5. package/dist/LayoutOverlayManager.js +6 -6
  6. package/dist/components/Dialog.d.ts +1 -1
  7. package/dist/components/Dialog.js +1 -1
  8. package/dist/components/Header.d.ts +1 -1
  9. package/dist/components/Header.d.ts.map +1 -1
  10. package/dist/components/Header.js +8 -4
  11. package/dist/components/Header.js.map +1 -1
  12. package/dist/components/OverlayContent.d.ts +1 -1
  13. package/dist/components/OverlayContent.js +20 -20
  14. package/dist/components/PortalSwitcher.d.ts +1 -1
  15. package/dist/components/PortalSwitcher.js +54 -54
  16. package/dist/components/SelectionList.d.ts +1 -1
  17. package/dist/components/SelectionList.d.ts.map +1 -1
  18. package/dist/components/SelectionList.js +61 -58
  19. package/dist/components/SelectionList.js.map +1 -1
  20. package/dist/components/Toaster.d.ts +1 -1
  21. package/dist/components/Toaster.js +1 -1
  22. package/dist/components/UserMenu.d.ts +1 -1
  23. package/dist/components/UserMenu.js +42 -42
  24. package/dist/components/UserMenu.js.map +1 -1
  25. package/dist/components/error/ErrorBoundary.d.ts +1 -1
  26. package/dist/components/error/ErrorBoundary.js +1 -1
  27. package/dist/components/error/ErrorDescriptor.d.ts +12 -0
  28. package/dist/components/error/ErrorDescriptor.d.ts.map +1 -0
  29. package/dist/components/error/ErrorDescriptor.js +17 -0
  30. package/dist/components/error/ErrorDescriptor.js.map +1 -0
  31. package/dist/components/error/ErrorFeedback.d.ts +1 -1
  32. package/dist/components/error/ErrorFeedback.js +1 -1
  33. package/dist/components/error/SilentErrorBoundary.d.ts +1 -1
  34. package/dist/components/error/SilentErrorBoundary.js +1 -1
  35. package/dist/components/menu/MenuContent.d.ts +8 -12
  36. package/dist/components/menu/MenuContent.d.ts.map +1 -1
  37. package/dist/components/menu/MenuContent.js +151 -148
  38. package/dist/components/menu/MenuContent.js.map +1 -1
  39. package/dist/components/menu/MenuSections.d.ts +1 -1
  40. package/dist/components/menu/MenuSections.d.ts.map +1 -1
  41. package/dist/components/menu/MenuSections.js +7 -5
  42. package/dist/components/menu/MenuSections.js.map +1 -1
  43. package/dist/components/menu/PageSelector.d.ts +1 -1
  44. package/dist/components/menu/PageSelector.d.ts.map +1 -1
  45. package/dist/components/menu/PageSelector.js +68 -66
  46. package/dist/components/menu/PageSelector.js.map +1 -1
  47. package/dist/components/menu/useCheckTextOverflow.d.ts +6 -0
  48. package/dist/components/menu/useCheckTextOverflow.d.ts.map +1 -0
  49. package/dist/components/menu/useCheckTextOverflow.js +20 -0
  50. package/dist/components/menu/useCheckTextOverflow.js.map +1 -0
  51. package/dist/layout-context.d.ts +10 -0
  52. package/dist/layout-context.d.ts.map +1 -0
  53. package/dist/layout-context.js +11 -0
  54. package/dist/layout-context.js.map +1 -0
  55. package/dist/layout.css +465 -465
  56. package/dist/svg/AI.d.ts +1 -1
  57. package/dist/svg/AI.js +1 -1
  58. package/dist/svg/EDP.d.ts +1 -1
  59. package/dist/svg/EDP.js +1 -1
  60. package/dist/svg/Forbidden.d.ts +1 -1
  61. package/dist/svg/Forbidden.js +1 -1
  62. package/dist/svg/HUB.d.ts +1 -1
  63. package/dist/svg/HUB.js +1 -1
  64. package/dist/svg/Logo.d.ts +1 -1
  65. package/dist/svg/Logo.js +1 -1
  66. package/dist/svg/NotFound.d.ts +1 -1
  67. package/dist/svg/NotFound.js +1 -1
  68. package/dist/svg/ServerError.d.ts +1 -1
  69. package/dist/svg/ServerError.js +1 -1
  70. package/dist/svg/Unauthenticated.d.ts +1 -1
  71. package/dist/svg/Unauthenticated.js +1 -1
  72. package/dist/toaster.js +2 -2
  73. package/dist/toaster.js.map +1 -1
  74. package/package.json +2 -2
  75. package/src/Layout.tsx +106 -103
  76. package/src/LayoutOverlayManager.tsx +273 -273
  77. package/src/components/Dialog.tsx +93 -93
  78. package/src/components/Header.tsx +34 -29
  79. package/src/components/OverlayContent.tsx +58 -58
  80. package/src/components/PortalSwitcher.tsx +147 -147
  81. package/src/components/SelectionList.tsx +272 -268
  82. package/src/components/Toaster.tsx +16 -16
  83. package/src/components/UserMenu.tsx +111 -111
  84. package/src/components/error/ErrorBoundary.tsx +38 -38
  85. package/src/components/error/ErrorFeedback.tsx +114 -114
  86. package/src/components/error/ErrorManager.ts +31 -31
  87. package/src/components/error/SilentErrorBoundary.tsx +54 -54
  88. package/src/components/menu/MenuContent.tsx +296 -293
  89. package/src/components/menu/MenuSections.tsx +270 -268
  90. package/src/components/menu/PageSelector.tsx +154 -152
  91. package/src/components/menu/constants.ts +2 -2
  92. package/src/components/menu/types.ts +112 -112
  93. package/src/components/menu/use-check-text-overflow.tsx +26 -26
  94. package/src/components/menu/use-keyboard-controls.tsx +70 -70
  95. package/src/components/types.ts +15 -15
  96. package/src/dictionary.ts +25 -25
  97. package/src/elements.ts +24 -24
  98. package/src/errors.ts +11 -11
  99. package/src/index.ts +17 -17
  100. package/src/layout-context.tsx +22 -0
  101. package/src/layout.css +465 -465
  102. package/src/svg/AI.tsx +37 -37
  103. package/src/svg/EDP.tsx +35 -35
  104. package/src/svg/Forbidden.tsx +22 -22
  105. package/src/svg/HUB.tsx +35 -35
  106. package/src/svg/Logo.tsx +35 -35
  107. package/src/svg/NotFound.tsx +16 -16
  108. package/src/svg/ServerError.tsx +33 -33
  109. package/src/svg/Unauthenticated.tsx +16 -16
  110. package/src/toaster.tsx +76 -76
  111. package/src/utils.ts +114 -114
  112. package/tsconfig.json +8 -8
@@ -1,268 +1,272 @@
1
- import { Flex, IconBox, Text } from '@citric/core'
2
- import { ArrowLeft, Check, ChevronRight } from '@citric/icons'
3
- import { IconButton } from '@citric/ui'
4
- import { WithStyle, listToClass, theme } from '@stack-spot/portal-theme'
5
- import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
6
- import { ReactElement, useCallback, useEffect, useMemo, useState } from 'react'
7
- import { styled } from 'styled-components'
8
- import { useKeyboardControls } from './menu/use-keyboard-controls'
9
- import { Action } from './types'
10
-
11
- interface ItemWithIcon {
12
- icon?: React.ReactElement,
13
- iconRight?: React.ReactElement,
14
- }
15
-
16
- export interface ListAction extends ItemWithIcon, Action {
17
- active?: boolean,
18
- }
19
-
20
- interface ListGroup {
21
- type?: 'section' | 'collapsible',
22
- children: ListItem[],
23
- }
24
-
25
- interface ListSection extends ListGroup {
26
- type: 'section',
27
- label?: string,
28
- }
29
-
30
- interface ListCollapsible extends ListGroup, ItemWithIcon {
31
- type?: 'collapsible',
32
- label: string,
33
- }
34
-
35
- type ListItem = ListSection | ListCollapsible | ListAction
36
-
37
- interface CurrentItemList {
38
- items: ListItem[],
39
- label?: string,
40
- parent?: CurrentItemList,
41
- }
42
-
43
- const ANIMATION_DURATION_MS = 300
44
- const MAX_HEIGHT_TRANSITION = `max-height ease-in ${ANIMATION_DURATION_MS / 1000}s`
45
-
46
- export interface SelectionListProps extends WithStyle {
47
- id: string,
48
- visible?: boolean,
49
- items: ListItem[],
50
- onHide?: () => void,
51
- maxHeight?: string,
52
- before?: ReactElement,
53
- after?: ReactElement,
54
- scroll?: boolean,
55
- }
56
-
57
- interface RenderOptions {
58
- setCurrent: (current: CurrentItemList) => void,
59
- controllerId?: string,
60
- onClose?: () => void,
61
- }
62
-
63
- const SelectionBox = styled.div<{ $maxHeight: string, $scroll?: boolean }>`
64
- max-height: 0;
65
- overflow-y: ${({ $scroll }) => $scroll ? 'auto' : 'hidden'};
66
- overflow-x: hidden;
67
- transition: ${MAX_HEIGHT_TRANSITION}, visibility 0s ${ANIMATION_DURATION_MS / 1000}s;
68
- z-index: 1;
69
- box-shadow: 4px 4px 48px #000;
70
- border-radius: 0.5rem;
71
- visibility: hidden;
72
-
73
- .selection-list-content {
74
- display: flex;
75
- flex-direction: column;
76
- background: ${theme.color.light['500']};
77
- border-radius: 0.5rem;
78
- border: 1px solid ${theme.color.light['600']};
79
- background-color: ${theme.color.light['300']};
80
- }
81
-
82
- .section-title, li > a {
83
- height: 40px;
84
- padding: 0 8px;
85
- display: flex;
86
- flex-direction: row;
87
- align-items: center;
88
- }
89
-
90
- li > a {
91
- gap: 4px;
92
- transition: background-color 0.2s;
93
- &:hover, &:focus {
94
- background: ${theme.color.light['400']};
95
- }
96
- .label {
97
- flex: 1;
98
- white-space: nowrap;
99
- overflow: hidden;
100
- text-overflow: ellipsis;
101
- }
102
- }
103
-
104
- li.section {
105
- border-bottom: 2px solid ${theme.color.light['600']};
106
- &:last-child {
107
- border-bottom: none;
108
- }
109
- }
110
-
111
- &.visible {
112
- max-height: ${({ $maxHeight }) => $maxHeight};
113
- visibility: visible;
114
- transition: ${MAX_HEIGHT_TRANSITION};
115
- }
116
- `
117
-
118
- function renderAction({
119
- label, href, onClick, icon, iconRight, active, target, iconActive = <Check />,
120
- }: ListAction, { onClose }: RenderOptions) {
121
- function handleClick() {
122
- onClick?.()
123
- onClose?.()
124
- }
125
-
126
- const isTextLabel = typeof label === 'string'
127
-
128
- return (
129
- <li key={isTextLabel ? label : label.id} className="action">
130
- <a href={href} onClick={handleClick} target={target} tabIndex={0} aria-selected={active}>
131
- {icon && <IconBox>{icon}</IconBox>}
132
- {isTextLabel ? <Text appearance="body2" className="label">{label}</Text> : label.element}
133
- {iconRight && <IconBox>{iconRight}</IconBox>}
134
- {active && <IconBox>{iconActive}</IconBox>}
135
- </a>
136
- </li>
137
- )
138
- }
139
-
140
- function renderCollapsible({ label, icon, iconRight, children }: ListCollapsible, { setCurrent, controllerId }: RenderOptions) {
141
- function handleClick(ev: React.MouseEvent) {
142
- // accessibility: this will tell the screen reader the section was expanded before this link is removed from the DOM.
143
- (ev.target as HTMLElement)?.setAttribute?.('aria-expanded', 'true')
144
- setCurrent({ items: children, label })
145
- }
146
- return (
147
- <li key={label} className="collapsible">
148
- <a onClick={handleClick} tabIndex={0} aria-expanded={false} aria-controls={controllerId}>
149
- {icon && <IconBox>{icon}</IconBox>}
150
- <Text appearance="body2" className="label">{label}</Text>
151
- {iconRight && <IconBox>{iconRight}</IconBox>}
152
- <IconBox><ChevronRight /></IconBox>
153
- </a>
154
- </li>
155
- )
156
- }
157
-
158
- function renderSection({ label, children }: ListSection, options: RenderOptions) {
159
- return (
160
- <li key={label ?? children.map(c => c.label).join('-')} className="section">
161
- {label && <Text appearance="overheader2" colorScheme="primary" className="section-title">{label}</Text>}
162
- <ul>{children.map(i => renderItem(i, options))}</ul>
163
- </li>
164
- )
165
- }
166
-
167
- function renderItem(item: ListItem, options: RenderOptions) {
168
- if ('children' in item) {
169
- return item.type === 'section' ? renderSection(item, options) : renderCollapsible(item, options)
170
- }
171
- return renderAction(item, options)
172
- }
173
-
174
- export const SelectionList = ({
175
- id, items, className, style, visible = true, maxHeight = '300px', onHide, before, after, scroll,
176
- }: SelectionListProps) => {
177
- const t = useTranslate(dictionary)
178
- const [current, setCurrent] = useState<CurrentItemList>({ items })
179
- const { keyboardControlledElement: wrapper, attachKeyboardListeners, detachKeyboardListeners } = useKeyboardControls(
180
- { onPressEscape: onHide, querySelectors: 'li.action a, li.collapsible a, button' },
181
- )
182
-
183
- const listItems = useMemo(
184
- () => current.items.map(i => renderItem(
185
- i,
186
- {
187
- setCurrent: (next: CurrentItemList) => setCurrent({ ...next, parent: current }),
188
- onClose: onHide,
189
- controllerId: id,
190
- },
191
- )),
192
- [current],
193
- )
194
-
195
- const hide = useCallback((event: Event) => {
196
- const target = (event.target as HTMLElement | null)
197
- // if the element is not in the DOM anymore, we'll consider the click was inside the selection list
198
- const isClickInsideSelectionList = !target?.isConnected || wrapper.current?.contains(target)
199
- const isAction = target?.classList?.contains('action') || !!target?.closest('.action')
200
- if (!isClickInsideSelectionList || isAction) onHide?.()
201
- }, [])
202
-
203
- useEffect(() => {
204
- if (visible) {
205
- setCurrent({ items })
206
- attachKeyboardListeners()
207
- if (onHide) setTimeout(() => document.addEventListener('click', hide), 50)
208
- }
209
- else {
210
- detachKeyboardListeners()
211
- document.removeEventListener('click', hide)
212
- }
213
- }, [visible])
214
-
215
- return (
216
- <SelectionBox
217
- id={id}
218
- ref={wrapper}
219
- $maxHeight={maxHeight}
220
- style={style}
221
- className={listToClass(['selection-list', visible ? 'visible' : undefined, className])}
222
- $scroll={scroll}
223
- aria-hidden={!visible}
224
- >
225
- <div className="selection-list-content">
226
- {before}
227
- {current.parent
228
- ? (
229
- <Flex mt={5} mb={1} alignItems="center">
230
- <IconButton
231
- onClick={(ev) => {
232
- // accessibility: this will tell the screen reader the section was collapsed before this button is removed from the DOM.
233
- (ev.target as HTMLElement)?.setAttribute?.('aria-expanded', 'false')
234
- setCurrent(current.parent ?? { items })
235
- }}
236
- sx={{ mr: 3 }}
237
- title={t.back}
238
- aria-controls={id}
239
- aria-expanded={true}
240
- >
241
- <ArrowLeft />
242
- </IconButton>
243
- <Text appearance="microtext1">{current.label}</Text>
244
- </Flex>
245
- )
246
- : undefined
247
- }
248
- <ul>
249
- {listItems}
250
- {after &&
251
- <li className="action">
252
- {after}
253
- </li>
254
- }
255
- </ul>
256
- </div>
257
- </SelectionBox>
258
- )
259
- }
260
-
261
- const dictionary = {
262
- en: {
263
- back: 'Go back',
264
- },
265
- pt: {
266
- back: 'Voltar',
267
- },
268
- } satisfies Dictionary
1
+ import { Flex, IconBox, Text } from '@citric/core'
2
+ import { ArrowLeft, Check, ChevronRight } from '@citric/icons'
3
+ import { IconButton } from '@citric/ui'
4
+ import { WithStyle, listToClass, theme } from '@stack-spot/portal-theme'
5
+ import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
6
+ import { ReactElement, useCallback, useEffect, useMemo, useState } from 'react'
7
+ import { styled } from 'styled-components'
8
+ import { AnchorComponent, useAnchorTag } from '../layout-context'
9
+ import { useKeyboardControls } from './menu/use-keyboard-controls'
10
+ import { Action } from './types'
11
+
12
+ interface ItemWithIcon {
13
+ icon?: React.ReactElement,
14
+ iconRight?: React.ReactElement,
15
+ }
16
+
17
+ export interface ListAction extends ItemWithIcon, Action {
18
+ active?: boolean,
19
+ }
20
+
21
+ interface ListGroup {
22
+ type?: 'section' | 'collapsible',
23
+ children: ListItem[],
24
+ }
25
+
26
+ interface ListSection extends ListGroup {
27
+ type: 'section',
28
+ label?: string,
29
+ }
30
+
31
+ interface ListCollapsible extends ListGroup, ItemWithIcon {
32
+ type?: 'collapsible',
33
+ label: string,
34
+ }
35
+
36
+ type ListItem = ListSection | ListCollapsible | ListAction
37
+
38
+ interface CurrentItemList {
39
+ items: ListItem[],
40
+ label?: string,
41
+ parent?: CurrentItemList,
42
+ }
43
+
44
+ const ANIMATION_DURATION_MS = 300
45
+ const MAX_HEIGHT_TRANSITION = `max-height ease-in ${ANIMATION_DURATION_MS / 1000}s`
46
+
47
+ export interface SelectionListProps extends WithStyle {
48
+ id: string,
49
+ visible?: boolean,
50
+ items: ListItem[],
51
+ onHide?: () => void,
52
+ maxHeight?: string,
53
+ before?: ReactElement,
54
+ after?: ReactElement,
55
+ scroll?: boolean,
56
+ }
57
+
58
+ interface RenderOptions {
59
+ setCurrent: (current: CurrentItemList) => void,
60
+ controllerId?: string,
61
+ onClose?: () => void,
62
+ Link: AnchorComponent,
63
+ }
64
+
65
+ const SelectionBox = styled.div<{ $maxHeight: string, $scroll?: boolean }>`
66
+ max-height: 0;
67
+ overflow-y: ${({ $scroll }) => $scroll ? 'auto' : 'hidden'};
68
+ overflow-x: hidden;
69
+ transition: ${MAX_HEIGHT_TRANSITION}, visibility 0s ${ANIMATION_DURATION_MS / 1000}s;
70
+ z-index: 1;
71
+ box-shadow: 4px 4px 48px #000;
72
+ border-radius: 0.5rem;
73
+ visibility: hidden;
74
+
75
+ .selection-list-content {
76
+ display: flex;
77
+ flex-direction: column;
78
+ background: ${theme.color.light['500']};
79
+ border-radius: 0.5rem;
80
+ border: 1px solid ${theme.color.light['600']};
81
+ background-color: ${theme.color.light['300']};
82
+ }
83
+
84
+ .section-title, li > a {
85
+ height: 40px;
86
+ padding: 0 8px;
87
+ display: flex;
88
+ flex-direction: row;
89
+ align-items: center;
90
+ }
91
+
92
+ li > a {
93
+ gap: 4px;
94
+ transition: background-color 0.2s;
95
+ &:hover, &:focus {
96
+ background: ${theme.color.light['400']};
97
+ }
98
+ .label {
99
+ flex: 1;
100
+ white-space: nowrap;
101
+ overflow: hidden;
102
+ text-overflow: ellipsis;
103
+ }
104
+ }
105
+
106
+ li.section {
107
+ border-bottom: 2px solid ${theme.color.light['600']};
108
+ &:last-child {
109
+ border-bottom: none;
110
+ }
111
+ }
112
+
113
+ &.visible {
114
+ max-height: ${({ $maxHeight }) => $maxHeight};
115
+ visibility: visible;
116
+ transition: ${MAX_HEIGHT_TRANSITION};
117
+ }
118
+ `
119
+
120
+ function renderAction({
121
+ label, href, onClick, icon, iconRight, active, target, iconActive = <Check />,
122
+ }: ListAction, { onClose, Link }: RenderOptions) {
123
+ function handleClick() {
124
+ onClick?.()
125
+ onClose?.()
126
+ }
127
+
128
+ const isTextLabel = typeof label === 'string'
129
+
130
+ return (
131
+ <li key={isTextLabel ? label : label.id} className="action">
132
+ <Link href={href} onClick={handleClick} target={target} tabIndex={0} aria-selected={active}>
133
+ {icon && <IconBox>{icon}</IconBox>}
134
+ {isTextLabel ? <Text appearance="body2" className="label">{label}</Text> : label.element}
135
+ {iconRight && <IconBox>{iconRight}</IconBox>}
136
+ {active && <IconBox>{iconActive}</IconBox>}
137
+ </Link>
138
+ </li>
139
+ )
140
+ }
141
+
142
+ function renderCollapsible({ label, icon, iconRight, children }: ListCollapsible, { setCurrent, controllerId, Link }: RenderOptions) {
143
+ function handleClick(ev: React.MouseEvent) {
144
+ // accessibility: this will tell the screen reader the section was expanded before this link is removed from the DOM.
145
+ (ev.target as HTMLElement)?.setAttribute?.('aria-expanded', 'true')
146
+ setCurrent({ items: children, label })
147
+ }
148
+ return (
149
+ <li key={label} className="collapsible">
150
+ <Link onClick={handleClick} tabIndex={0} aria-expanded={false} aria-controls={controllerId}>
151
+ {icon && <IconBox>{icon}</IconBox>}
152
+ <Text appearance="body2" className="label">{label}</Text>
153
+ {iconRight && <IconBox>{iconRight}</IconBox>}
154
+ <IconBox><ChevronRight /></IconBox>
155
+ </Link>
156
+ </li>
157
+ )
158
+ }
159
+
160
+ function renderSection({ label, children }: ListSection, options: RenderOptions) {
161
+ return (
162
+ <li key={label ?? children.map(c => c.label).join('-')} className="section">
163
+ {label && <Text appearance="overheader2" colorScheme="primary" className="section-title">{label}</Text>}
164
+ <ul>{children.map(i => renderItem(i, options))}</ul>
165
+ </li>
166
+ )
167
+ }
168
+
169
+ function renderItem(item: ListItem, options: RenderOptions) {
170
+ if ('children' in item) {
171
+ return item.type === 'section' ? renderSection(item, options) : renderCollapsible(item, options)
172
+ }
173
+ return renderAction(item, options)
174
+ }
175
+
176
+ export const SelectionList = ({
177
+ id, items, className, style, visible = true, maxHeight = '300px', onHide, before, after, scroll,
178
+ }: SelectionListProps) => {
179
+ const Link = useAnchorTag()
180
+ const t = useTranslate(dictionary)
181
+ const [current, setCurrent] = useState<CurrentItemList>({ items })
182
+ const { keyboardControlledElement: wrapper, attachKeyboardListeners, detachKeyboardListeners } = useKeyboardControls(
183
+ { onPressEscape: onHide, querySelectors: 'li.action a, li.collapsible a, button' },
184
+ )
185
+
186
+ const listItems = useMemo(
187
+ () => current.items.map(i => renderItem(
188
+ i,
189
+ {
190
+ setCurrent: (next: CurrentItemList) => setCurrent({ ...next, parent: current }),
191
+ onClose: onHide,
192
+ controllerId: id,
193
+ Link,
194
+ },
195
+ )),
196
+ [current],
197
+ )
198
+
199
+ const hide = useCallback((event: Event) => {
200
+ const target = (event.target as HTMLElement | null)
201
+ // if the element is not in the DOM anymore, we'll consider the click was inside the selection list
202
+ const isClickInsideSelectionList = !target?.isConnected || wrapper.current?.contains(target)
203
+ const isAction = target?.classList?.contains('action') || !!target?.closest('.action')
204
+ if (!isClickInsideSelectionList || isAction) onHide?.()
205
+ }, [])
206
+
207
+ useEffect(() => {
208
+ if (visible) {
209
+ setCurrent({ items })
210
+ attachKeyboardListeners()
211
+ if (onHide) setTimeout(() => document.addEventListener('click', hide), 50)
212
+ }
213
+ else {
214
+ detachKeyboardListeners()
215
+ document.removeEventListener('click', hide)
216
+ }
217
+ }, [visible])
218
+
219
+ return (
220
+ <SelectionBox
221
+ id={id}
222
+ ref={wrapper}
223
+ $maxHeight={maxHeight}
224
+ style={style}
225
+ className={listToClass(['selection-list', visible ? 'visible' : undefined, className])}
226
+ $scroll={scroll}
227
+ aria-hidden={!visible}
228
+ >
229
+ <div className="selection-list-content">
230
+ {before}
231
+ {current.parent
232
+ ? (
233
+ <Flex mt={5} mb={1} alignItems="center">
234
+ <IconButton
235
+ onClick={(ev) => {
236
+ // accessibility: this will tell the screen reader the section was collapsed before this button is removed from the DOM.
237
+ (ev.target as HTMLElement)?.setAttribute?.('aria-expanded', 'false')
238
+ setCurrent(current.parent ?? { items })
239
+ }}
240
+ sx={{ mr: 3 }}
241
+ title={t.back}
242
+ aria-controls={id}
243
+ aria-expanded={true}
244
+ >
245
+ <ArrowLeft />
246
+ </IconButton>
247
+ <Text appearance="microtext1">{current.label}</Text>
248
+ </Flex>
249
+ )
250
+ : undefined
251
+ }
252
+ <ul>
253
+ {listItems}
254
+ {after &&
255
+ <li className="action">
256
+ {after}
257
+ </li>
258
+ }
259
+ </ul>
260
+ </div>
261
+ </SelectionBox>
262
+ )
263
+ }
264
+
265
+ const dictionary = {
266
+ en: {
267
+ back: 'Go back',
268
+ },
269
+ pt: {
270
+ back: 'Voltar',
271
+ },
272
+ } satisfies Dictionary
@@ -1,16 +1,16 @@
1
- import { TimesMini } from '@citric/icons'
2
- import { IconButton } from '@citric/ui'
3
- import { CloseButtonProps, ToastContainer } from 'react-toastify'
4
- import 'react-toastify/dist/ReactToastify.css'
5
- import { useDictionary } from '../dictionary'
6
-
7
- const CloseButton = ({ closeToast }: CloseButtonProps) => {
8
- const t = useDictionary()
9
- return (
10
- <IconButton onClick={() => closeToast(null as any)} title={t.dismiss}>
11
- <TimesMini />
12
- </IconButton>
13
- )
14
- }
15
-
16
- export const Toaster = () => <ToastContainer closeButton={CloseButton} />
1
+ import { TimesMini } from '@citric/icons'
2
+ import { IconButton } from '@citric/ui'
3
+ import { CloseButtonProps, ToastContainer } from 'react-toastify'
4
+ import 'react-toastify/dist/ReactToastify.css'
5
+ import { useDictionary } from '../dictionary'
6
+
7
+ const CloseButton = ({ closeToast }: CloseButtonProps) => {
8
+ const t = useDictionary()
9
+ return (
10
+ <IconButton onClick={() => closeToast(null as any)} title={t.dismiss}>
11
+ <TimesMini />
12
+ </IconButton>
13
+ )
14
+ }
15
+
16
+ export const Toaster = () => <ToastContainer closeButton={CloseButton} />