@manuscripts/style-guide 3.5.4 → 3.5.6

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.
@@ -1,21 +1,115 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import ReactModal from 'react-modal';
3
- import styled from 'styled-components';
2
+ import { useEffect, useRef } from 'react';
3
+ import { createPortal } from 'react-dom';
4
+ import styled, { css } from 'styled-components';
4
5
  import { RoundIconButton } from './Button';
5
6
  import { SidebarStyles } from './Sidebar';
6
- const totalTransitionTime = 800;
7
- const transitionDelay = 300;
8
- const delayedTransitionTime = totalTransitionTime - transitionDelay;
9
- const ReactModalAdapter = ({ className, modalClassName, ...props }) => {
10
- props.style = props.style || {};
11
- if (props.pointerEventsOnBackdrop == 'none') {
12
- props.style.content = {
13
- ...props.style.content,
14
- pointerEvents: 'all',
7
+ export const StyledModal = ({ isOpen, onRequestClose, shouldCloseOnOverlayClick = true, hideOverlay = false, pointerEventsOnBackdrop, children, className, style, }) => {
8
+ const dialogRef = useRef(null);
9
+ const closedByCancelRef = useRef(false);
10
+ useEffect(() => {
11
+ const dialog = dialogRef.current;
12
+ if (!dialog) {
13
+ return;
14
+ }
15
+ if (isOpen && !dialog.open) {
16
+ dialog.showModal();
17
+ }
18
+ else if (!isOpen && dialog.open) {
19
+ dialog.close();
20
+ }
21
+ }, [isOpen]);
22
+ useEffect(() => {
23
+ const dialog = dialogRef.current;
24
+ if (!dialog) {
25
+ return;
26
+ }
27
+ const handleNativeClose = (wasOpen) => {
28
+ if (wasOpen && !closedByCancelRef.current) {
29
+ onRequestClose?.();
30
+ }
31
+ closedByCancelRef.current = false;
15
32
  };
16
- }
17
- return (_jsx(ReactModal, { className: modalClassName, portalClassName: className, closeTimeoutMS: totalTransitionTime, preventScroll: true, appElement: document.getElementById('root'), ...props }));
33
+ const listener = () => handleNativeClose(isOpen);
34
+ dialog.addEventListener('close', listener);
35
+ return () => dialog.removeEventListener('close', listener);
36
+ }, [isOpen, onRequestClose]);
37
+ useEffect(() => {
38
+ const dialog = dialogRef.current;
39
+ if (!dialog) {
40
+ return;
41
+ }
42
+ const handleCancel = (e) => {
43
+ closedByCancelRef.current = true;
44
+ onRequestClose?.(e);
45
+ };
46
+ dialog.addEventListener('cancel', handleCancel);
47
+ return () => dialog.removeEventListener('cancel', handleCancel);
48
+ }, [onRequestClose]);
49
+ const handleBackdropClick = (e) => {
50
+ if (shouldCloseOnOverlayClick && e.target === dialogRef.current) {
51
+ onRequestClose?.();
52
+ }
53
+ };
54
+ return createPortal(_jsx(Dialog, { ref: dialogRef, onClick: handleBackdropClick, "$hideOverlay": hideOverlay, "$pointerEventsOnBackdrop": pointerEventsOnBackdrop, className: className, style: style?.content, children: children }), document.body);
18
55
  };
56
+ const Dialog = styled.dialog `
57
+ background: transparent;
58
+ border: none;
59
+ position: relative;
60
+ outline: none;
61
+ padding: 0;
62
+ overflow: visible;
63
+ opacity: 1;
64
+ transition:
65
+ opacity 0.5s ease-in-out,
66
+ display 0.5s ease allow-discrete,
67
+ overlay 0.5s ease allow-discrete;
68
+
69
+ &:not([open]) {
70
+ opacity: 0;
71
+ }
72
+
73
+ @starting-style {
74
+ &[open] {
75
+ opacity: 0;
76
+ }
77
+ }
78
+
79
+ &::backdrop {
80
+ ${(props) => {
81
+ if (props.$hideOverlay) {
82
+ return css `
83
+ background: transparent;
84
+ `;
85
+ }
86
+ if (props.$pointerEventsOnBackdrop === 'none') {
87
+ return css `
88
+ background: rgba(0, 0, 0, 0.1);
89
+ `;
90
+ }
91
+ return css `
92
+ background: ${props.theme.colors.background.dark};
93
+ `;
94
+ }}
95
+ opacity: 1;
96
+ pointer-events: ${(props) => props.$pointerEventsOnBackdrop || 'auto'};
97
+ transition:
98
+ opacity 0.5s ease-in-out,
99
+ display 0.5s ease allow-discrete,
100
+ overlay 0.5s ease allow-discrete;
101
+ }
102
+
103
+ &:not([open])::backdrop {
104
+ opacity: 0;
105
+ }
106
+
107
+ @starting-style {
108
+ &[open]::backdrop {
109
+ opacity: 0;
110
+ }
111
+ }
112
+ `;
19
113
  export const ModalContainer = styled.div `
20
114
  background: ${(props) => props.theme.colors.background.primary};
21
115
  border-radius: ${(props) => props.theme.grid.radius.default};
@@ -113,67 +207,3 @@ export const ModalTitle = styled.h2 `
113
207
  color: ${(props) => props.theme.colors.text.primary};
114
208
  margin: 0 0 20px 0;
115
209
  `;
116
- export const StyledModal = styled(ReactModalAdapter).attrs({
117
- closeTimeoutMS: totalTransitionTime,
118
- overlayClassName: {
119
- base: 'Overlay',
120
- afterOpen: 'Overlay--after-open',
121
- beforeClose: 'Overlay--before-close',
122
- },
123
- modalClassName: {
124
- base: 'Modal',
125
- afterOpen: 'Modal--after-open',
126
- beforeClose: 'Modal--before-close',
127
- },
128
- }) `
129
- .Overlay {
130
- position: fixed;
131
- top: 0;
132
- left: 0;
133
- right: 0;
134
- bottom: 0;
135
- background-color: ${(props) => props.hideOverlay
136
- ? 'transparent'
137
- : props.pointerEventsOnBackdrop === 'none'
138
- ? 'rgba(0,0,0,0.1)'
139
- : props.theme.colors.background.dark};
140
- z-index: 1000;
141
- display: flex;
142
- justify-content: center;
143
- align-items: center;
144
- opacity: 0;
145
- pointer-events: ${(props) => props.pointerEventsOnBackdrop || 'auto'};
146
-
147
- &--after-open {
148
- transition: opacity ${totalTransitionTime}ms ease-in-out;
149
- opacity: 1;
150
- }
151
-
152
- &--before-close {
153
- transition: opacity ${delayedTransitionTime}ms ease-in-out;
154
- transition-delay: ${transitionDelay}ms;
155
- opacity: 0;
156
- }
157
- }
158
-
159
- .Modal {
160
- background: transparent;
161
- border: none;
162
- position: relative;
163
- outline: none;
164
- opacity: 0;
165
- transition:
166
- opacity ${delayedTransitionTime}ms ease-in-out,
167
- top ${delayedTransitionTime}ms ease-in-out;
168
- transition-delay: ${transitionDelay}ms;
169
-
170
- &--after-open {
171
- opacity: 1;
172
- }
173
-
174
- &--before-close {
175
- transition-delay: 0ms;
176
- opacity: 0;
177
- }
178
- }
179
- `;
@@ -0,0 +1,47 @@
1
+ import { useEffect } from 'react';
2
+ export function getFocusableElements(element) {
3
+ const selectors = [
4
+ 'button:not([disabled])',
5
+ 'input:not([disabled])',
6
+ 'textarea:not([disabled])',
7
+ 'select:not([disabled])',
8
+ 'a[href]',
9
+ '[tabindex]:not([tabindex="-1"])',
10
+ ];
11
+ return Array.from(element.querySelectorAll(selectors.join(','))).filter((el) => {
12
+ const style = window.getComputedStyle(el);
13
+ return (el instanceof HTMLElement &&
14
+ el.offsetParent &&
15
+ style.visibility !== 'hidden' &&
16
+ style.display !== 'none');
17
+ });
18
+ }
19
+ export function trapFocus(e, element) {
20
+ if (e.key !== 'Tab' ||
21
+ !element ||
22
+ !element?.contains(document.activeElement)) {
23
+ return;
24
+ }
25
+ const focusableElements = getFocusableElements(element);
26
+ if (focusableElements.length === 0) {
27
+ return;
28
+ }
29
+ const firstElement = focusableElements[0];
30
+ const lastElement = focusableElements[focusableElements.length - 1];
31
+ const activeElement = document.activeElement;
32
+ if (!e.shiftKey && activeElement === lastElement) {
33
+ e.preventDefault();
34
+ firstElement.focus();
35
+ }
36
+ else if (e.shiftKey && activeElement === firstElement) {
37
+ e.preventDefault();
38
+ lastElement.focus();
39
+ }
40
+ }
41
+ export const useFocusCycle = (containerRef) => {
42
+ useEffect(() => {
43
+ const handleKeyDown = (e) => trapFocus(e, containerRef.current);
44
+ document.addEventListener('keydown', handleKeyDown);
45
+ return () => document.removeEventListener('keydown', handleKeyDown);
46
+ }, [containerRef]);
47
+ };
package/dist/es/index.js CHANGED
@@ -44,6 +44,7 @@ export * from './components/Badge';
44
44
  export * from './components/NavDropdown';
45
45
  export * from './components/Dropdown';
46
46
  export * from './components/LoadingOverlay';
47
+ export * from './components/List';
47
48
  export * from './components/Text';
48
49
  export * from './components/RelativeDate';
49
50
  export * from './components/Menus';
@@ -54,5 +55,6 @@ export * from './components/SelectedItemsBox';
54
55
  export * from './hooks/use-dropdown';
55
56
  export * from './hooks/use-menus';
56
57
  export * from './hooks/use-scroll-detection';
58
+ export * from './hooks/use-focus-cycle';
57
59
  export * from './lib/files';
58
60
  export * from './lib/menus';
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ export declare const outlineStyle: import("styled-components").FlattenInterpolation<import("styled-components").ThemeProps<import("styled-components").DefaultTheme>>;
16
17
  export declare const SecondaryButton: import("styled-components").StyledComponent<"button", import("styled-components").DefaultTheme, {
17
18
  type: "button" | "submit" | "reset";
18
19
  } & {
@@ -5,10 +5,26 @@ export interface DrawerProps {
5
5
  width?: string;
6
6
  children: React.ReactNode;
7
7
  }
8
- export declare const DrawerItemsList: import("styled-components").StyledComponent<"ul", import("styled-components").DefaultTheme, {}, never>;
9
- export declare const DrawerListItem: import("styled-components").StyledComponent<"li", import("styled-components").DefaultTheme, {
10
- selected?: boolean;
11
- }, never>;
8
+ export declare const DrawerItemsList: import("styled-components").StyledComponent<React.ForwardRefExoticComponent<Omit<{
9
+ [x: string]: any;
10
+ [x: number]: any;
11
+ [x: symbol]: any;
12
+ } & {
13
+ theme?: import("styled-components").DefaultTheme | undefined;
14
+ } & {
15
+ as?: string | React.ComponentType<any> | undefined;
16
+ forwardedAs?: string | React.ComponentType<any> | undefined;
17
+ }, "ref"> & React.RefAttributes<HTMLElement>>, import("styled-components").DefaultTheme, {}, never>;
18
+ export declare const DrawerListItem: import("styled-components").StyledComponent<React.ForwardRefExoticComponent<Omit<{
19
+ [x: string]: any;
20
+ [x: number]: any;
21
+ [x: symbol]: any;
22
+ } & {
23
+ theme?: import("styled-components").DefaultTheme | undefined;
24
+ } & {
25
+ as?: string | React.ComponentType<any> | undefined;
26
+ forwardedAs?: string | React.ComponentType<any> | undefined;
27
+ }, "ref"> & React.RefAttributes<HTMLElement>>, import("styled-components").DefaultTheme, {}, never>;
12
28
  export declare const DrawerIcon: import("styled-components").StyledComponent<"span", import("styled-components").DefaultTheme, {}, never>;
13
29
  export declare const DrawerLabelContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
14
30
  export declare const DrawerItemLabel: import("styled-components").StyledComponent<"span", import("styled-components").DefaultTheme, {}, never>;
@@ -0,0 +1,4 @@
1
+ import React, { ComponentType } from 'react';
2
+ export declare function withListNavigation<P extends object>(Component: ComponentType<P>): import("styled-components").StyledComponent<React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<HTMLElement>>, import("styled-components").DefaultTheme, {}, never>;
3
+ export declare function withNavigableListItem<P extends object>(Component: ComponentType<P>): import("styled-components").StyledComponent<React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<HTMLElement>>, import("styled-components").DefaultTheme, {}, never>;
4
+ export declare function withFocusTrap<P extends object>(Component: ComponentType<P>): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<HTMLElement>>;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * © 2019 Atypon Systems LLC
2
+ * © 2026 Atypon Systems LLC
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,13 +14,19 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import React from 'react';
17
- import ReactModal from 'react-modal';
18
- import { ThemeProps } from 'styled-components';
19
- interface Props {
20
- modalClassName?: ReactModal.Classes;
21
- pointerEventsOnBackdrop?: 'all' | 'none' | 'auto';
17
+ interface StyledModalProps {
18
+ isOpen: boolean;
19
+ onRequestClose?: (e?: Event) => void;
20
+ shouldCloseOnOverlayClick?: boolean;
22
21
  hideOverlay?: boolean;
22
+ pointerEventsOnBackdrop?: 'all' | 'none' | 'auto';
23
+ children: React.ReactNode;
24
+ className?: string;
25
+ style?: {
26
+ content?: React.CSSProperties;
27
+ };
23
28
  }
29
+ export declare const StyledModal: React.FC<StyledModalProps>;
24
30
  export declare const ModalContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
25
31
  export declare const ModalHeader: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
26
32
  export declare const CloseButton: import("styled-components").StyledComponent<"button", import("styled-components").DefaultTheme, {
@@ -48,17 +54,4 @@ export declare const ModalCardBody: import("styled-components").StyledComponent<
48
54
  width?: number | string;
49
55
  }, never>;
50
56
  export declare const ModalTitle: import("styled-components").StyledComponent<"h2", import("styled-components").DefaultTheme, {}, never>;
51
- export declare const StyledModal: import("styled-components").StyledComponent<React.FC<ReactModal.Props & ThemeProps<ReactModal> & Props>, import("styled-components").DefaultTheme, {
52
- closeTimeoutMS: 800;
53
- overlayClassName: {
54
- base: string;
55
- afterOpen: string;
56
- beforeClose: string;
57
- };
58
- modalClassName: {
59
- base: string;
60
- afterOpen: string;
61
- beforeClose: string;
62
- };
63
- }, "modalClassName" | "overlayClassName" | "closeTimeoutMS">;
64
57
  export {};
@@ -0,0 +1,4 @@
1
+ import { RefObject } from 'react';
2
+ export declare function getFocusableElements(element: HTMLElement): HTMLElement[];
3
+ export declare function trapFocus(e: KeyboardEvent, element: HTMLElement | null): void;
4
+ export declare const useFocusCycle: (containerRef: RefObject<HTMLDivElement | null>) => void;
@@ -45,6 +45,7 @@ export * from './components/Badge';
45
45
  export * from './components/NavDropdown';
46
46
  export * from './components/Dropdown';
47
47
  export * from './components/LoadingOverlay';
48
+ export * from './components/List';
48
49
  export * from './components/Text';
49
50
  export * from './components/RelativeDate';
50
51
  export * from './components/Menus';
@@ -55,5 +56,6 @@ export * from './components/SelectedItemsBox';
55
56
  export * from './hooks/use-dropdown';
56
57
  export * from './hooks/use-menus';
57
58
  export * from './hooks/use-scroll-detection';
59
+ export * from './hooks/use-focus-cycle';
58
60
  export * from './lib/files';
59
61
  export * from './lib/menus';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/style-guide",
3
3
  "description": "Shared components for Manuscripts applications",
4
- "version": "3.5.4",
4
+ "version": "3.5.6",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -47,7 +47,6 @@
47
47
  "react-dnd-html5-backend": "16.0.1",
48
48
  "react-dom": "19.2.0",
49
49
  "react-is": "19.2.0",
50
- "react-modal": "3.16.3",
51
50
  "react-router-dom": "5.3.4",
52
51
  "react-select": "5.10.1",
53
52
  "react-tooltip": "5.28.1",
@@ -75,7 +74,6 @@
75
74
  "@types/react": "19.2.3",
76
75
  "@types/react-datepicker": "^7.0.0",
77
76
  "@types/react-dom": "19.2.3",
78
- "@types/react-modal": "3.16.3",
79
77
  "@types/react-router-dom": "5.3.3",
80
78
  "@types/styled-components": "5.1.34",
81
79
  "@typescript-eslint/eslint-plugin": "8.46.4",