draft-components 1.11.0 → 1.13.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/cjs/components/slide-over/slide-over-header.cjs +2 -2
- package/cjs/components/slide-over/slide-over.cjs +13 -6
- package/css/draft-components.css +6 -0
- package/esm/components/slide-over/slide-over-context.js +1 -1
- package/esm/components/slide-over/slide-over-header.js +2 -2
- package/esm/components/slide-over/slide-over.js +14 -7
- package/package.json +1 -1
- package/types/components/slide-over/index.d.ts +1 -1
- package/types/components/slide-over/slide-over-header.d.ts +1 -1
- package/types/components/slide-over/slide-over.d.ts +15 -5
- package/types/components/slide-over/types.d.ts +1 -1
|
@@ -6,13 +6,13 @@ require('../button/button.cjs');
|
|
|
6
6
|
const iconButton = require('../button/icon-button.cjs');
|
|
7
7
|
const slideOverContext = require('./slide-over-context.cjs');
|
|
8
8
|
|
|
9
|
-
function SlideOverHeader({ className, htmlTitle, title, description, closeButtonAccessibleName, onClickCloseButton, ...props }) {
|
|
9
|
+
function SlideOverHeader({ className, htmlTitle, title, children, description, closeButtonAccessibleName, onClickCloseButton, ...props }) {
|
|
10
10
|
const { titleId, descriptionId, closePanel } = slideOverContext.useSlideOverContext();
|
|
11
11
|
const onCloseButtonClicked = (ev) => {
|
|
12
12
|
closePanel('close-button');
|
|
13
13
|
onClickCloseButton?.(ev);
|
|
14
14
|
};
|
|
15
|
-
return (jsxRuntime.jsxs("div", { className: reactHelpers.classNames('dc-slide-over-header', className), title: htmlTitle, ...props, children: [jsxRuntime.jsxs("div", { className: "dc-slide-over-header__title", children: [jsxRuntime.jsx("h2", { id: titleId, children: title }), jsxRuntime.jsx(iconButton.IconButton, { icon: jsxRuntime.jsx(XMarkIcon, {}), "aria-label": closeButtonAccessibleName, variant: "tinted", size: "xs", onClick: onCloseButtonClicked })] }), description ? (jsxRuntime.jsx("div", { id: descriptionId, className: "dc-slide-over-header__description", children: description })) : null] }));
|
|
15
|
+
return (jsxRuntime.jsxs("div", { className: reactHelpers.classNames('dc-slide-over-header', className), title: htmlTitle, ...props, children: [jsxRuntime.jsxs("div", { className: "dc-slide-over-header__title", children: [jsxRuntime.jsx("h2", { id: titleId, children: title }), jsxRuntime.jsx(iconButton.IconButton, { icon: jsxRuntime.jsx(XMarkIcon, {}), "aria-label": closeButtonAccessibleName, variant: "tinted", size: "xs", onClick: onCloseButtonClicked })] }), description ? (jsxRuntime.jsx("div", { id: descriptionId, className: "dc-slide-over-header__description", children: description })) : null, children ? (jsxRuntime.jsx("div", { className: "dc-slide-over-header__content", children: children })) : null] }));
|
|
16
16
|
}
|
|
17
17
|
function XMarkIcon(props) {
|
|
18
18
|
return (jsxRuntime.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: 20, height: 20, fill: "none", stroke: "currentColor", strokeWidth: 1.5, ...props, children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) }));
|
|
@@ -19,7 +19,7 @@ const backdropFade = [
|
|
|
19
19
|
{ opacity: 0 },
|
|
20
20
|
{ opacity: 1 },
|
|
21
21
|
];
|
|
22
|
-
function SlideOver({ 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, animationDurationMs = 350, animationDisabled = false, className, children, onClose, ...props }) {
|
|
22
|
+
const SlideOverWithRef = react.forwardRef(function SlideOver({ 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, animationDurationMs = 350, animationDisabled = false, shouldCloseOnEscKeyPress = true, shouldCloseOnBackdropClick = true, className, children, onClose, ...props }, ref) {
|
|
23
23
|
const id = react.useId();
|
|
24
24
|
const titleId = ariaLabelledby || `${id}dialogTitle`;
|
|
25
25
|
const descriptionId = ariaDescribedby || `${id}dialogDescription`;
|
|
@@ -73,6 +73,9 @@ function SlideOver({ 'aria-labelledby': ariaLabelledby, 'aria-describedby': aria
|
|
|
73
73
|
});
|
|
74
74
|
};
|
|
75
75
|
}, [animationDurationMs, onClose, shouldPlayAnimations]);
|
|
76
|
+
react.useImperativeHandle(ref, () => ({
|
|
77
|
+
close: closePanel,
|
|
78
|
+
}));
|
|
76
79
|
react.useEffect(() => {
|
|
77
80
|
isAnimationDisabled.current = animationDisabled;
|
|
78
81
|
}, [animationDisabled]);
|
|
@@ -92,15 +95,19 @@ function SlideOver({ 'aria-labelledby': ariaLabelledby, 'aria-describedby': aria
|
|
|
92
95
|
});
|
|
93
96
|
}
|
|
94
97
|
}, [shouldPlayAnimations, animationDurationMs]);
|
|
95
|
-
useEscKeyDown.useEscKeyDown(() => closePanel('escape'));
|
|
98
|
+
useEscKeyDown.useEscKeyDown(() => closePanel('escape'), { isEnabled: shouldCloseOnEscKeyPress });
|
|
96
99
|
useFocusTrap.useFocusTrap(panelRef);
|
|
97
100
|
useDisableBodyScroll.useDisableBodyScroll();
|
|
98
101
|
const onClickBackdrop = () => {
|
|
99
|
-
|
|
102
|
+
if (shouldCloseOnBackdropClick) {
|
|
103
|
+
closePanel('backdrop');
|
|
104
|
+
}
|
|
100
105
|
};
|
|
101
106
|
return (jsxRuntime.jsx(portal.Portal, { children: jsxRuntime.jsxs("div", { className: "dc-slide-over", children: [jsxRuntime.jsx("div", { "data-testid": "slide-over-backdrop", className: "dc-slide-over__backdrop", ref: backdropRef, onClick: onClickBackdrop }), jsxRuntime.jsx("div", { ...props, className: reactHelpers.classNames('dc-slide-over__panel', className), role: "dialog", ref: panelRef, "aria-modal": true, "aria-labelledby": titleId, "aria-describedby": descriptionId, children: jsxRuntime.jsx(slideOverContext.SlideOverContextProvider, { titleId: titleId, descriptionId: descriptionId, closePanel: closePanel, children: children }) })] }) }));
|
|
102
|
-
}
|
|
103
|
-
SlideOver
|
|
104
|
-
|
|
107
|
+
});
|
|
108
|
+
const SlideOver = Object.assign(SlideOverWithRef, {
|
|
109
|
+
Header: slideOverHeader.SlideOverHeader,
|
|
110
|
+
Body: slideOverBody.SlideOverBody,
|
|
111
|
+
});
|
|
105
112
|
|
|
106
113
|
exports.SlideOver = SlideOver;
|
package/css/draft-components.css
CHANGED
|
@@ -1275,6 +1275,12 @@
|
|
|
1275
1275
|
margin-top: 4px;
|
|
1276
1276
|
}
|
|
1277
1277
|
|
|
1278
|
+
.dc-slide-over-header__content {
|
|
1279
|
+
font: var(--dc-text-md);
|
|
1280
|
+
color: var(--dc-slide-over-text-color);
|
|
1281
|
+
margin-top: 8px;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1278
1284
|
.dc-slide-over-body {
|
|
1279
1285
|
color: var(--dc-slide-over-text-color);
|
|
1280
1286
|
overflow: auto;
|
|
@@ -4,13 +4,13 @@ import '../button/button.js';
|
|
|
4
4
|
import { IconButton } from '../button/icon-button.js';
|
|
5
5
|
import { useSlideOverContext } from './slide-over-context.js';
|
|
6
6
|
|
|
7
|
-
function SlideOverHeader({ className, htmlTitle, title, description, closeButtonAccessibleName, onClickCloseButton, ...props }) {
|
|
7
|
+
function SlideOverHeader({ className, htmlTitle, title, children, description, closeButtonAccessibleName, onClickCloseButton, ...props }) {
|
|
8
8
|
const { titleId, descriptionId, closePanel } = useSlideOverContext();
|
|
9
9
|
const onCloseButtonClicked = (ev) => {
|
|
10
10
|
closePanel('close-button');
|
|
11
11
|
onClickCloseButton?.(ev);
|
|
12
12
|
};
|
|
13
|
-
return (jsxs("div", { className: classNames('dc-slide-over-header', className), title: htmlTitle, ...props, children: [jsxs("div", { className: "dc-slide-over-header__title", children: [jsx("h2", { id: titleId, children: title }), jsx(IconButton, { icon: jsx(XMarkIcon, {}), "aria-label": closeButtonAccessibleName, variant: "tinted", size: "xs", onClick: onCloseButtonClicked })] }), description ? (jsx("div", { id: descriptionId, className: "dc-slide-over-header__description", children: description })) : null] }));
|
|
13
|
+
return (jsxs("div", { className: classNames('dc-slide-over-header', className), title: htmlTitle, ...props, children: [jsxs("div", { className: "dc-slide-over-header__title", children: [jsx("h2", { id: titleId, children: title }), jsx(IconButton, { icon: jsx(XMarkIcon, {}), "aria-label": closeButtonAccessibleName, variant: "tinted", size: "xs", onClick: onCloseButtonClicked })] }), description ? (jsx("div", { id: descriptionId, className: "dc-slide-over-header__description", children: description })) : null, children ? (jsx("div", { className: "dc-slide-over-header__content", children: children })) : null] }));
|
|
14
14
|
}
|
|
15
15
|
function XMarkIcon(props) {
|
|
16
16
|
return (jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: 20, height: 20, fill: "none", stroke: "currentColor", strokeWidth: 1.5, ...props, children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) }));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { useId, useRef, useCallback, useMemo, useEffect } from 'react';
|
|
2
|
+
import { forwardRef, useId, useRef, useCallback, useMemo, useImperativeHandle, useEffect } from 'react';
|
|
3
3
|
import { SlideOverContextProvider } from './slide-over-context.js';
|
|
4
4
|
import { getRefElement, classNames } from '../../lib/react-helpers.js';
|
|
5
5
|
import { useDisableBodyScroll } from '../../hooks/use-disable-body-scroll.js';
|
|
@@ -17,7 +17,7 @@ const backdropFade = [
|
|
|
17
17
|
{ opacity: 0 },
|
|
18
18
|
{ opacity: 1 },
|
|
19
19
|
];
|
|
20
|
-
function SlideOver({ 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, animationDurationMs = 350, animationDisabled = false, className, children, onClose, ...props }) {
|
|
20
|
+
const SlideOverWithRef = forwardRef(function SlideOver({ 'aria-labelledby': ariaLabelledby, 'aria-describedby': ariaDescribedby, animationDurationMs = 350, animationDisabled = false, shouldCloseOnEscKeyPress = true, shouldCloseOnBackdropClick = true, className, children, onClose, ...props }, ref) {
|
|
21
21
|
const id = useId();
|
|
22
22
|
const titleId = ariaLabelledby || `${id}dialogTitle`;
|
|
23
23
|
const descriptionId = ariaDescribedby || `${id}dialogDescription`;
|
|
@@ -71,6 +71,9 @@ function SlideOver({ 'aria-labelledby': ariaLabelledby, 'aria-describedby': aria
|
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
73
|
}, [animationDurationMs, onClose, shouldPlayAnimations]);
|
|
74
|
+
useImperativeHandle(ref, () => ({
|
|
75
|
+
close: closePanel,
|
|
76
|
+
}));
|
|
74
77
|
useEffect(() => {
|
|
75
78
|
isAnimationDisabled.current = animationDisabled;
|
|
76
79
|
}, [animationDisabled]);
|
|
@@ -90,15 +93,19 @@ function SlideOver({ 'aria-labelledby': ariaLabelledby, 'aria-describedby': aria
|
|
|
90
93
|
});
|
|
91
94
|
}
|
|
92
95
|
}, [shouldPlayAnimations, animationDurationMs]);
|
|
93
|
-
useEscKeyDown(() => closePanel('escape'));
|
|
96
|
+
useEscKeyDown(() => closePanel('escape'), { isEnabled: shouldCloseOnEscKeyPress });
|
|
94
97
|
useFocusTrap(panelRef);
|
|
95
98
|
useDisableBodyScroll();
|
|
96
99
|
const onClickBackdrop = () => {
|
|
97
|
-
|
|
100
|
+
if (shouldCloseOnBackdropClick) {
|
|
101
|
+
closePanel('backdrop');
|
|
102
|
+
}
|
|
98
103
|
};
|
|
99
104
|
return (jsx(Portal, { children: jsxs("div", { className: "dc-slide-over", children: [jsx("div", { "data-testid": "slide-over-backdrop", className: "dc-slide-over__backdrop", ref: backdropRef, onClick: onClickBackdrop }), jsx("div", { ...props, className: classNames('dc-slide-over__panel', className), role: "dialog", ref: panelRef, "aria-modal": true, "aria-labelledby": titleId, "aria-describedby": descriptionId, children: jsx(SlideOverContextProvider, { titleId: titleId, descriptionId: descriptionId, closePanel: closePanel, children: children }) })] }) }));
|
|
100
|
-
}
|
|
101
|
-
SlideOver
|
|
102
|
-
|
|
105
|
+
});
|
|
106
|
+
const SlideOver = Object.assign(SlideOverWithRef, {
|
|
107
|
+
Header: SlideOverHeader,
|
|
108
|
+
Body: SlideOverBody,
|
|
109
|
+
});
|
|
103
110
|
|
|
104
111
|
export { SlideOver };
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { type SlideOverCloseCallback } from './types';
|
|
2
|
-
export { SlideOver, type SlideOverProps } from './slide-over';
|
|
2
|
+
export { SlideOver, type SlideOverProps, type SlideOverRef, } from './slide-over';
|
|
3
3
|
export { SlideOverHeader, type SlideOverHeaderProps, } from './slide-over-header';
|
|
4
4
|
export { SlideOverBody, type SlideOverBodyProps, } from './slide-over-body';
|
|
@@ -8,4 +8,4 @@ export type SlideOverHeaderProps = {
|
|
|
8
8
|
closeButtonAccessibleName?: string;
|
|
9
9
|
onClickCloseButton?: MouseEventHandler<HTMLButtonElement>;
|
|
10
10
|
} & SlideOverHeaderBaseProps;
|
|
11
|
-
export declare function SlideOverHeader({ className, htmlTitle, title, description, closeButtonAccessibleName, onClickCloseButton, ...props }: SlideOverHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare function SlideOverHeader({ className, htmlTitle, title, children, description, closeButtonAccessibleName, onClickCloseButton, ...props }: SlideOverHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -6,10 +6,20 @@ export type SlideOverHTMLProps = ComponentPropsWithoutRef<'div'>;
|
|
|
6
6
|
export type SlideOverProps = SlideOverHTMLProps & {
|
|
7
7
|
animationDurationMs?: number;
|
|
8
8
|
animationDisabled?: boolean;
|
|
9
|
+
shouldCloseOnEscKeyPress?: boolean;
|
|
10
|
+
shouldCloseOnBackdropClick?: boolean;
|
|
9
11
|
onClose: SlideOverCloseCallback;
|
|
10
12
|
};
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export type SlideOverRef = {
|
|
14
|
+
close: () => void;
|
|
15
|
+
};
|
|
16
|
+
export declare const SlideOver: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
17
|
+
animationDurationMs?: number | undefined;
|
|
18
|
+
animationDisabled?: boolean | undefined;
|
|
19
|
+
shouldCloseOnEscKeyPress?: boolean | undefined;
|
|
20
|
+
shouldCloseOnBackdropClick?: boolean | undefined;
|
|
21
|
+
onClose: SlideOverCloseCallback;
|
|
22
|
+
} & import("react").RefAttributes<SlideOverRef>> & {
|
|
23
|
+
Header: typeof SlideOverHeader;
|
|
24
|
+
Body: typeof SlideOverBody;
|
|
25
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type SlideOverCloseCallback = (source
|
|
1
|
+
export type SlideOverCloseCallback = (source?: 'close-button' | 'backdrop' | 'escape') => void;
|