@squiz/generic-browser-lib 1.40.1-alpha.1 → 1.40.1-alpha.10

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.
@@ -6,5 +6,6 @@ export type ModalProps = {
6
6
  state: OverlayTriggerState;
7
7
  overlayProps: DOMAttributes<FocusableElement>;
8
8
  children: (titleProps: DOMAttributes<FocusableElement>) => React.ReactElement;
9
+ scope: 'squiz-gb-scope' | 'squiz-cb-scope' | 'squiz-rb-scope';
9
10
  };
10
- export declare function Modal({ isDismissable, state, overlayProps, children, ...props }: ModalProps): JSX.Element;
11
+ export declare function Modal({ isDismissable, state, overlayProps, children, scope, ...props }: ModalProps): JSX.Element;
@@ -35,11 +35,11 @@ function ModalContent({ children, ...props }) {
35
35
  const { dialogProps, titleProps } = (0, react_aria_1.useDialog)(props, ref);
36
36
  return (react_1.default.createElement("div", { ...dialogProps, ref: ref, className: "z-50 relative bg-white rounded-lg h-screen lg:h-[calc(100vh-3.5rem)] w-screen max-w-screen-lg outline-0" }, children(titleProps)));
37
37
  }
38
- function Modal({ isDismissable, state, overlayProps, children, ...props }) {
38
+ function Modal({ isDismissable, state, overlayProps, children, scope, ...props }) {
39
39
  const ref = (0, react_1.useRef)(null);
40
40
  const { modalProps, underlayProps } = (0, react_aria_1.useModalOverlay)({ isDismissable, ...props }, state, ref);
41
41
  return (react_1.default.createElement(react_aria_1.Overlay, null,
42
- react_1.default.createElement("div", { className: "squiz-gb-scope" },
42
+ react_1.default.createElement("div", { className: scope },
43
43
  react_1.default.createElement("div", { ...underlayProps, className: "h-full z-[9998] fixed inset-0 before:z-40 before:fixed before:inset-0 before:bg-black before:bg-opacity-25" },
44
44
  react_1.default.createElement("div", { ...modalProps, ref: ref, className: "h-full flex items-center justify-center" },
45
45
  react_1.default.createElement(ModalContent, { ...overlayProps }, (titleProps) => children(titleProps)))))));
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { DOMAttributes, FocusableElement } from '@react-types/shared';
3
- export declare function ModalTrigger({ label, labelClasses, showLabel, containerClasses, icon, isDisabled, children, ...props }: {
3
+ export declare function ModalTrigger({ label, labelClasses, showLabel, containerClasses, icon, isDisabled, children, scope, ...props }: {
4
4
  label: string;
5
5
  labelClasses?: string;
6
6
  containerClasses?: string;
@@ -8,4 +8,5 @@ export declare function ModalTrigger({ label, labelClasses, showLabel, container
8
8
  icon?: React.ReactNode;
9
9
  isDisabled?: boolean;
10
10
  children: (onClose: () => void, titleProps: DOMAttributes<FocusableElement>) => React.ReactElement;
11
+ scope: 'squiz-gb-scope' | 'squiz-cb-scope' | 'squiz-rb-scope';
11
12
  }): JSX.Element;
@@ -10,18 +10,18 @@ const react_stately_1 = require("react-stately");
10
10
  const clsx_1 = __importDefault(require("clsx"));
11
11
  const Modal_1 = require("./Modal");
12
12
  const ModalOpeningButton_1 = require("./ModalOpeningButton");
13
- function ModalTrigger({ label, labelClasses, showLabel, containerClasses, icon, isDisabled, children, ...props }) {
13
+ function ModalTrigger({ label, labelClasses, showLabel, containerClasses, icon, isDisabled, children, scope, ...props }) {
14
14
  const state = (0, react_stately_1.useOverlayTriggerState)(props);
15
15
  const { triggerProps, overlayProps } = (0, react_aria_1.useOverlayTrigger)({ type: 'dialog' }, state);
16
16
  let ariaAttr = {};
17
17
  if (!showLabel) {
18
18
  ariaAttr = { ...ariaAttr, 'aria-label': label };
19
19
  }
20
- return (react_1.default.createElement("div", { className: "squiz-gb-scope" },
20
+ return (react_1.default.createElement("div", { className: scope },
21
21
  react_1.default.createElement(ModalOpeningButton_1.ModalOpeningButton, { type: "button", ...triggerProps, ...ariaAttr, isDisabled: isDisabled, className: (0, clsx_1.default)(`${containerClasses ||
22
22
  'flex p-1 px-1.5 rounded mr-auto text-blue-300 hover:bg-blue-100 focus:bg-blue-100 focus:outline-none'}`, isDisabled && 'hover:bg-transparent cursor-not-allowed text-gray-600') },
23
23
  icon,
24
24
  showLabel && react_1.default.createElement("span", { className: `${labelClasses || 'ml-1 text-sm font-semibold leading-4'}` }, label)),
25
- state.isOpen && (react_1.default.createElement(Modal_1.Modal, { isDismissable: true, state: state, overlayProps: overlayProps }, (titleProps) => children(state.close, titleProps)))));
25
+ state.isOpen && (react_1.default.createElement(Modal_1.Modal, { isDismissable: true, state: state, overlayProps: overlayProps, scope: scope }, (titleProps) => children(state.close, titleProps)))));
26
26
  }
27
27
  exports.ModalTrigger = ModalTrigger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/generic-browser-lib",
3
- "version": "1.40.1-alpha.1",
3
+ "version": "1.40.1-alpha.10",
4
4
  "description": "Package with reusable components used by resource/component browsers",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -72,5 +72,5 @@
72
72
  "volta": {
73
73
  "node": "18.15.0"
74
74
  },
75
- "gitHead": "383f1a667a2460518b4e85481a143ef3ddbc41fa"
75
+ "gitHead": "5987cf82afe866ba79320a3960966063309e5cbe"
76
76
  }
@@ -8,7 +8,7 @@ describe('Modal', () => {
8
8
  it('Modal is closed by default', async () => {
9
9
  render(
10
10
  <div>
11
- <ModalTrigger label={'Open testing modal'} showLabel>
11
+ <ModalTrigger label={'Open testing modal'} showLabel scope="squiz-gb-scope">
12
12
  {(onClose, titleProps) => (
13
13
  <div data-testingid="modal">
14
14
  <div {...titleProps}>Testing</div>
@@ -28,7 +28,7 @@ describe('Modal', () => {
28
28
  it('Modal should render label', async () => {
29
29
  render(
30
30
  <div>
31
- <ModalTrigger label={'Open testing modal'} showLabel={false}>
31
+ <ModalTrigger label={'Open testing modal'} showLabel={false} scope="squiz-gb-scope">
32
32
  {(onClose, titleProps) => (
33
33
  <div data-testingid="modal">
34
34
  <div {...titleProps}>Testing</div>
@@ -47,7 +47,7 @@ describe('Modal', () => {
47
47
  it('Modal opens when triggered', async () => {
48
48
  render(
49
49
  <div>
50
- <ModalTrigger label={'Open testing modal'} showLabel>
50
+ <ModalTrigger label={'Open testing modal'} showLabel scope="squiz-gb-scope">
51
51
  {(onClose, titleProps) => (
52
52
  <div data-testid="modal">
53
53
  <div {...titleProps}>Testing</div>
@@ -72,7 +72,7 @@ describe('Modal', () => {
72
72
  it('Clicking outside the modal closes it', async () => {
73
73
  render(
74
74
  <div data-testid="outside">
75
- <ModalTrigger label={'Open testing modal'} showLabel>
75
+ <ModalTrigger label={'Open testing modal'} showLabel scope="squiz-gb-scope">
76
76
  {(onClose, titleProps) => (
77
77
  <div data-testid="modal">
78
78
  <div {...titleProps}>Testing</div>
@@ -103,7 +103,7 @@ describe('Modal', () => {
103
103
  it('ESC closes modal', async () => {
104
104
  render(
105
105
  <div data-testid="outside">
106
- <ModalTrigger label={'Open testing modal'} showLabel>
106
+ <ModalTrigger label={'Open testing modal'} showLabel scope="squiz-gb-scope">
107
107
  {(onClose, titleProps) => (
108
108
  <div data-testid="modal">
109
109
  <div {...titleProps}>Testing</div>
@@ -134,7 +134,7 @@ describe('Modal', () => {
134
134
  it('Invoking onClose function closes modal', async () => {
135
135
  render(
136
136
  <div>
137
- <ModalTrigger label={'Open testing modal'} showLabel>
137
+ <ModalTrigger label={'Open testing modal'} showLabel scope="squiz-gb-scope">
138
138
  {(onClose, titleProps) => (
139
139
  <div data-testid="modal">
140
140
  <div {...titleProps}>Testing</div>
@@ -165,7 +165,7 @@ describe('Modal', () => {
165
165
  it('Modal does not open if modal trigger button is disabled', async () => {
166
166
  render(
167
167
  <div>
168
- <ModalTrigger label={'Open testing modal'} showLabel isDisabled={true}>
168
+ <ModalTrigger label={'Open testing modal'} showLabel isDisabled={true} scope="squiz-gb-scope">
169
169
  {(onClose, titleProps) => (
170
170
  <div data-testid="modal">
171
171
  <div {...titleProps}>Testing</div>
@@ -191,7 +191,7 @@ describe('Modal', () => {
191
191
  render(
192
192
  <div>
193
193
  <button />
194
- <ModalTrigger label={'Open testing modal'} showLabel>
194
+ <ModalTrigger label={'Open testing modal'} showLabel scope="squiz-gb-scope">
195
195
  {(onClose, titleProps) => (
196
196
  <div data-testid="modal">
197
197
  <div {...titleProps}>Testing</div>
@@ -225,7 +225,7 @@ describe('Modal', () => {
225
225
  render(
226
226
  <div>
227
227
  <button />
228
- <ModalTrigger label={'Open testing modal'} showLabel>
228
+ <ModalTrigger label={'Open testing modal'} showLabel scope="squiz-gb-scope">
229
229
  {(onClose, titleProps) => (
230
230
  <div data-testid="modal">
231
231
  <div data-testid="title" {...titleProps}>
@@ -256,7 +256,7 @@ describe('Modal', () => {
256
256
  render(
257
257
  <div>
258
258
  <button />
259
- <ModalTrigger label={'Open testing modal'} showLabel>
259
+ <ModalTrigger label={'Open testing modal'} showLabel scope="squiz-gb-scope">
260
260
  {(onClose, titleProps) => {
261
261
  titleId = titleProps.id;
262
262
 
@@ -33,14 +33,15 @@ export type ModalProps = {
33
33
  state: OverlayTriggerState;
34
34
  overlayProps: DOMAttributes<FocusableElement>;
35
35
  children: (titleProps: DOMAttributes<FocusableElement>) => React.ReactElement; // Returns the title props from the 'ModalContent'
36
+ scope: 'squiz-gb-scope' | 'squiz-cb-scope' | 'squiz-rb-scope';
36
37
  };
37
- export function Modal({ isDismissable, state, overlayProps, children, ...props }: ModalProps) {
38
+ export function Modal({ isDismissable, state, overlayProps, children, scope, ...props }: ModalProps) {
38
39
  const ref = useRef<HTMLDivElement>(null);
39
40
  const { modalProps, underlayProps } = useModalOverlay({ isDismissable, ...props }, state, ref);
40
41
 
41
42
  return (
42
43
  <Overlay>
43
- <div className="squiz-gb-scope">
44
+ <div className={scope}>
44
45
  <div
45
46
  {...underlayProps}
46
47
  className="h-full z-[9998] fixed inset-0 before:z-40 before:fixed before:inset-0 before:bg-black before:bg-opacity-25"
@@ -15,6 +15,7 @@ export function ModalTrigger({
15
15
  icon,
16
16
  isDisabled,
17
17
  children,
18
+ scope,
18
19
  ...props
19
20
  }: {
20
21
  label: string;
@@ -24,6 +25,7 @@ export function ModalTrigger({
24
25
  icon?: React.ReactNode;
25
26
  isDisabled?: boolean;
26
27
  children: (onClose: () => void, titleProps: DOMAttributes<FocusableElement>) => React.ReactElement; // Child needs to be a functions which generates the 'content' so we can pass the onClose function and title aria props
28
+ scope: 'squiz-gb-scope' | 'squiz-cb-scope' | 'squiz-rb-scope';
27
29
  }) {
28
30
  const state = useOverlayTriggerState(props);
29
31
  const { triggerProps, overlayProps } = useOverlayTrigger({ type: 'dialog' }, state);
@@ -34,7 +36,7 @@ export function ModalTrigger({
34
36
  }
35
37
 
36
38
  return (
37
- <div className="squiz-gb-scope">
39
+ <div className={scope}>
38
40
  <ModalOpeningButton
39
41
  type="button"
40
42
  {...triggerProps}
@@ -52,7 +54,7 @@ export function ModalTrigger({
52
54
  {showLabel && <span className={`${labelClasses || 'ml-1 text-sm font-semibold leading-4'}`}>{label}</span>}
53
55
  </ModalOpeningButton>
54
56
  {state.isOpen && (
55
- <Modal isDismissable state={state} overlayProps={overlayProps}>
57
+ <Modal isDismissable state={state} overlayProps={overlayProps} scope={scope}>
56
58
  {(titleProps) => children(state.close, titleProps)}
57
59
  </Modal>
58
60
  )}