@cypress-design/react-modal 0.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.
- package/.turbo/turbo-build.log +6 -0
- package/CHANGELOG.md +10 -0
- package/Modal.tsx +106 -0
- package/ModalReact.cy.tsx +39 -0
- package/ReadMe.md +30 -0
- package/dist/Modal.d.ts +11 -0
- package/dist/Modal.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.mjs +31071 -0
- package/dist/index.es.mjs.map +1 -0
- package/dist/index.umd.js +31091 -0
- package/dist/index.umd.js.map +1 -0
- package/index.ts +1 -0
- package/package.json +30 -0
- package/rollup.config.mjs +3 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
$ yarn build:module && yarn build:types
|
|
2
|
+
$ rollup -c ./rollup.config.mjs
|
|
3
|
+
[36m
|
|
4
|
+
[1m./index.ts[22m → [1m./dist/index.umd.js, ./dist/index.es.mjs[22m...[39m
|
|
5
|
+
[32mcreated [1m./dist/index.umd.js, ./dist/index.es.mjs[22m in [1m17s[22m[39m
|
|
6
|
+
$ tsc --project ./tsconfig.build.json
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @cypress-design/react-modal
|
|
2
|
+
|
|
3
|
+
## 0.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#228](https://github.com/cypress-io/cypress-design/pull/228) [`3c5e87e`](https://github.com/cypress-io/cypress-design/commit/3c5e87e56937be486c10c928170ee7b64eb622c6) Thanks [@elevatebart](https://github.com/elevatebart)! - creation of modal component
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`3c5e87e`](https://github.com/cypress-io/cypress-design/commit/3c5e87e56937be486c10c928170ee7b64eb622c6)]:
|
|
10
|
+
- @cypress-design/constants-modal@0.0.2
|
package/Modal.tsx
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { createPortal } from 'react-dom'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
import {
|
|
5
|
+
IconActionQuestionMarkCircle,
|
|
6
|
+
IconActionDelete,
|
|
7
|
+
} from '@cypress-design/react-icon'
|
|
8
|
+
import {
|
|
9
|
+
ClassBackDrop,
|
|
10
|
+
ClassCloseButton,
|
|
11
|
+
ClassContent,
|
|
12
|
+
ClassHelpLink,
|
|
13
|
+
ClassHelpLinkDash,
|
|
14
|
+
ClassModal,
|
|
15
|
+
ClassModalContainer,
|
|
16
|
+
ClassTitle,
|
|
17
|
+
ClassTitleBox,
|
|
18
|
+
disableBodyScroll,
|
|
19
|
+
freeBodyScroll,
|
|
20
|
+
} from '@cypress-design/constants-modal'
|
|
21
|
+
|
|
22
|
+
export interface ModalProps {
|
|
23
|
+
title?: string
|
|
24
|
+
helpLink?: string
|
|
25
|
+
children?: React.ReactNode
|
|
26
|
+
show?: boolean
|
|
27
|
+
onClose?: () => void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const Modal: React.FC<ModalProps> = ({
|
|
31
|
+
show = false,
|
|
32
|
+
title,
|
|
33
|
+
helpLink,
|
|
34
|
+
onClose,
|
|
35
|
+
children,
|
|
36
|
+
}) => {
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (show) {
|
|
39
|
+
disableBodyScroll()
|
|
40
|
+
} else {
|
|
41
|
+
freeBodyScroll()
|
|
42
|
+
}
|
|
43
|
+
}, [show])
|
|
44
|
+
|
|
45
|
+
React.useEffect(
|
|
46
|
+
() => () => {
|
|
47
|
+
freeBodyScroll()
|
|
48
|
+
},
|
|
49
|
+
[]
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<>
|
|
54
|
+
{createPortal(
|
|
55
|
+
<div>
|
|
56
|
+
{show ? (
|
|
57
|
+
<div className={ClassBackDrop} onClick={() => onClose?.()}></div>
|
|
58
|
+
) : null}
|
|
59
|
+
{show ? (
|
|
60
|
+
<div
|
|
61
|
+
className={ClassModalContainer}
|
|
62
|
+
tabIndex={-1}
|
|
63
|
+
aria-modal="true"
|
|
64
|
+
role="modal"
|
|
65
|
+
>
|
|
66
|
+
<div className={ClassModal}>
|
|
67
|
+
<div className={ClassTitleBox}>
|
|
68
|
+
<div className={ClassTitle}>{title}</div>
|
|
69
|
+
{helpLink ? <div className={ClassHelpLinkDash} /> : null}
|
|
70
|
+
{helpLink ? (
|
|
71
|
+
<a href={helpLink} className={ClassHelpLink}>
|
|
72
|
+
Need help
|
|
73
|
+
<IconActionQuestionMarkCircle
|
|
74
|
+
className="ml-[4px]"
|
|
75
|
+
stroke-color="indigo-500"
|
|
76
|
+
fill-color="indigo-100"
|
|
77
|
+
/>
|
|
78
|
+
</a>
|
|
79
|
+
) : null}
|
|
80
|
+
|
|
81
|
+
<div className="grow" />
|
|
82
|
+
<button
|
|
83
|
+
aria-label="Close"
|
|
84
|
+
className={ClassCloseButton}
|
|
85
|
+
onClick={() => onClose?.()}
|
|
86
|
+
>
|
|
87
|
+
<IconActionDelete
|
|
88
|
+
className="children:transition-all"
|
|
89
|
+
stroke-color="gray-400"
|
|
90
|
+
hover-stroke-color="gray-700"
|
|
91
|
+
interactiveColorsOnGroup
|
|
92
|
+
/>
|
|
93
|
+
</button>
|
|
94
|
+
</div>
|
|
95
|
+
<div className={ClassContent}>{children}</div>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
) : null}
|
|
99
|
+
</div>,
|
|
100
|
+
document.body
|
|
101
|
+
)}
|
|
102
|
+
</>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default Modal
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { mount } from 'cypress/react18'
|
|
5
|
+
import Modal from './Modal'
|
|
6
|
+
import assertions from '../assertions'
|
|
7
|
+
|
|
8
|
+
const ComponentUsingModal = (options: {
|
|
9
|
+
title?: string
|
|
10
|
+
helpLink?: string
|
|
11
|
+
}) => {
|
|
12
|
+
const [visibleModal, setVisibleModal] = React.useState(false)
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<div className="h-[900px] w-[50px] bg-red-200"></div>
|
|
16
|
+
<button onClick={() => setVisibleModal(true)}>Open Modal</button>
|
|
17
|
+
<div className="h-[900px] w-[50px] bg-red-200"></div>
|
|
18
|
+
<Modal
|
|
19
|
+
{...options}
|
|
20
|
+
show={visibleModal}
|
|
21
|
+
onClose={() => setVisibleModal(false)}
|
|
22
|
+
>
|
|
23
|
+
<p>
|
|
24
|
+
Contents of the modal: Lorem ipsum dolor sit amet consectetur
|
|
25
|
+
adipisicing elit. Id perspiciatis hic ad minima ex recusandae autem
|
|
26
|
+
incidunt, perferendis, illo voluptatum repudiandae iste voluptate
|
|
27
|
+
reiciendis quam officiis voluptas laboriosam eligendi explicabo!
|
|
28
|
+
</p>
|
|
29
|
+
</Modal>
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('Modal', () => {
|
|
35
|
+
function mountStory(options: { title?: string; helpLink?: string }) {
|
|
36
|
+
mount(<ComponentUsingModal {...options} />)
|
|
37
|
+
}
|
|
38
|
+
assertions(mountStory)
|
|
39
|
+
})
|
package/ReadMe.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Modal
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @cypress-design/react-modal
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
or with yarn
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn add @cypress-design/react-modal
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```tsx live
|
|
16
|
+
import React from 'react'
|
|
17
|
+
import Button from '@cypress-design/react-button'
|
|
18
|
+
import Modal from '@cypress-design/react-modal'
|
|
19
|
+
const [visible, setVisible] = React.useState(false)
|
|
20
|
+
|
|
21
|
+
export default () => {
|
|
22
|
+
return (<Modal show={visible} title="modal" onClose={() => setVisible(false)}>
|
|
23
|
+
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id perspiciatis hic
|
|
24
|
+
ad minima ex recusandae autem incidunt, perferendis, illo voluptatum
|
|
25
|
+
repudiandae iste voluptate reiciendis quam officiis voluptas laboriosam
|
|
26
|
+
eligendi explicabo!
|
|
27
|
+
</Modal>
|
|
28
|
+
<Button @click={() => setVisible(true)}>Open Modal</Button>)
|
|
29
|
+
}
|
|
30
|
+
```
|
package/dist/Modal.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface ModalProps {
|
|
3
|
+
title?: string;
|
|
4
|
+
helpLink?: string;
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
show?: boolean;
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const Modal: React.FC<ModalProps>;
|
|
10
|
+
export default Modal;
|
|
11
|
+
//# sourceMappingURL=Modal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"./","sources":["Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAqB9B,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAED,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CA0EtC,CAAA;AAED,eAAe,KAAK,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"./","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA"}
|