@dhis2-ui/cover 10.16.2 → 10.16.3-alpha.1
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/package.json +4 -3
- package/src/cover.e2e.stories.js +48 -0
- package/src/cover.js +51 -0
- package/src/cover.prod.stories.js +52 -0
- package/src/features/accepts_children/index.js +10 -0
- package/src/features/accepts_children.feature +5 -0
- package/src/features/click_behavior/index.js +52 -0
- package/src/features/click_behavior.feature +17 -0
- package/src/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/cover",
|
|
3
|
-
"version": "10.16.
|
|
3
|
+
"version": "10.16.3-alpha.1",
|
|
4
4
|
"description": "UI Cover",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,13 +33,14 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@dhis2/prop-types": "^3.1.2",
|
|
36
|
-
"@dhis2/ui-constants": "10.16.
|
|
36
|
+
"@dhis2/ui-constants": "10.16.3-alpha.1",
|
|
37
37
|
"classnames": "^2.3.1",
|
|
38
38
|
"prop-types": "^15.7.2"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"build",
|
|
42
|
-
"types"
|
|
42
|
+
"types",
|
|
43
|
+
"src"
|
|
43
44
|
],
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"react": "^18.3.1",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Cover } from './cover.js'
|
|
3
|
+
|
|
4
|
+
window.onButtonClick = window.Cypress && window.Cypress.cy.stub()
|
|
5
|
+
window.onCover = window.Cypress && window.Cypress.cy.stub()
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Cover',
|
|
9
|
+
component: Cover,
|
|
10
|
+
decorators: [
|
|
11
|
+
(story) => (
|
|
12
|
+
<div>
|
|
13
|
+
{story()}
|
|
14
|
+
<style jsx>{`
|
|
15
|
+
div {
|
|
16
|
+
width: 400px;
|
|
17
|
+
height: 400px;
|
|
18
|
+
position: relative;
|
|
19
|
+
border: 1px dotted grey;
|
|
20
|
+
}
|
|
21
|
+
`}</style>
|
|
22
|
+
</div>
|
|
23
|
+
),
|
|
24
|
+
],
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const WithChildren = () => (
|
|
28
|
+
<Cover>
|
|
29
|
+
<p>I am a child</p>
|
|
30
|
+
</Cover>
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
export const Blocking = () => (
|
|
34
|
+
<>
|
|
35
|
+
<button data-test="button" onClick={window.onButtonClick}>
|
|
36
|
+
Test
|
|
37
|
+
</button>
|
|
38
|
+
<Cover />
|
|
39
|
+
</>
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
export const WithClickHandler = () => (
|
|
43
|
+
<Cover onClick={window.onCover}>
|
|
44
|
+
<button data-test="button" onClick={window.onButtonClick}>
|
|
45
|
+
Test
|
|
46
|
+
</button>
|
|
47
|
+
</Cover>
|
|
48
|
+
)
|
package/src/cover.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { layers } from '@dhis2/ui-constants'
|
|
2
|
+
import cx from 'classnames'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
const createClickHandler = (onClick) => (event) => {
|
|
7
|
+
// don't respond to clicks that originated in the children
|
|
8
|
+
if (onClick && event.target === event.currentTarget) {
|
|
9
|
+
onClick({}, event)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const Cover = ({
|
|
14
|
+
children,
|
|
15
|
+
className,
|
|
16
|
+
dataTest = 'dhis2-uicore-componentcover',
|
|
17
|
+
onClick,
|
|
18
|
+
translucent,
|
|
19
|
+
}) => (
|
|
20
|
+
<div
|
|
21
|
+
className={cx(className, { translucent })}
|
|
22
|
+
onClick={createClickHandler(onClick)}
|
|
23
|
+
data-test={dataTest}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
<style jsx>{`
|
|
27
|
+
div {
|
|
28
|
+
position: absolute;
|
|
29
|
+
top: 0;
|
|
30
|
+
right: 0;
|
|
31
|
+
bottom: 0;
|
|
32
|
+
left: 0;
|
|
33
|
+
z-index: ${layers.applicationTop};
|
|
34
|
+
}
|
|
35
|
+
div.translucent {
|
|
36
|
+
background: rgba(33, 43, 54, 0.4);
|
|
37
|
+
}
|
|
38
|
+
`}</style>
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
Cover.propTypes = {
|
|
43
|
+
children: PropTypes.node,
|
|
44
|
+
className: PropTypes.string,
|
|
45
|
+
dataTest: PropTypes.string,
|
|
46
|
+
/** Adds a semi-transparent background to the cover */
|
|
47
|
+
translucent: PropTypes.bool,
|
|
48
|
+
onClick: PropTypes.func,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { Cover }
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Center } from '@dhis2-ui/center'
|
|
2
|
+
import { CircularLoader } from '@dhis2-ui/loader'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { Cover } from './cover.js'
|
|
5
|
+
|
|
6
|
+
const description = `
|
|
7
|
+
Covers sibling components. Useful for covering a component while it is loading.
|
|
8
|
+
|
|
9
|
+
\`\`\`js
|
|
10
|
+
import { Cover } from '@dhis2/ui'
|
|
11
|
+
\`\`\`
|
|
12
|
+
`
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
title: 'Component Cover',
|
|
16
|
+
component: Cover,
|
|
17
|
+
parameters: { docs: { description: { component: description } } },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const Template = (args) => (
|
|
21
|
+
<div
|
|
22
|
+
style={{
|
|
23
|
+
width: '400px',
|
|
24
|
+
height: '200px',
|
|
25
|
+
position: 'relative',
|
|
26
|
+
border: '1px dotted grey',
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<Cover {...args} />
|
|
30
|
+
|
|
31
|
+
<h1>Text behind the cover</h1>
|
|
32
|
+
<p>Lorem ipsum</p>
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
export const Default = Template.bind({})
|
|
37
|
+
|
|
38
|
+
export const Translucent = Template.bind({})
|
|
39
|
+
Translucent.args = { translucent: true }
|
|
40
|
+
|
|
41
|
+
export const WithClickHandler = Template.bind({})
|
|
42
|
+
WithClickHandler.args = { onClick: () => alert('Cover was clicked') }
|
|
43
|
+
|
|
44
|
+
export const WithCenteredContentCircularLoader = Template.bind({})
|
|
45
|
+
WithCenteredContentCircularLoader.args = {
|
|
46
|
+
translucent: true,
|
|
47
|
+
children: (
|
|
48
|
+
<Center>
|
|
49
|
+
<CircularLoader />
|
|
50
|
+
</Center>
|
|
51
|
+
),
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('a Cover with children is rendered', () => {
|
|
4
|
+
cy.visitStory('Cover', 'With Children')
|
|
5
|
+
cy.get('[data-test="dhis2-uicore-componentcover"]').should('be.visible')
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
Then('the children are visible', () => {
|
|
9
|
+
cy.contains('I am a child').should('be.visible')
|
|
10
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'
|
|
2
|
+
|
|
3
|
+
Given('a Cover with a button below it is rendered', () => {
|
|
4
|
+
cy.visitStory('Cover', 'Blocking')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
Given('a Cover with a button in it is rendered', () => {
|
|
8
|
+
cy.visitStory('Cover', 'With Click Handler')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
When('the user clicks the button', () => {
|
|
12
|
+
cy.get('[data-test="button"]').click()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
When('the user clicks on the Cover', () => {
|
|
16
|
+
cy.get('[data-test="dhis2-uicore-componentcover"]').click()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
When('the user clicks on the button coordinates', () => {
|
|
20
|
+
cy.getPositionsBySelectors('button').then(([rect]) => {
|
|
21
|
+
// Get button center coordinates
|
|
22
|
+
const buttonCenterX = rect.left + rect.width / 2
|
|
23
|
+
const buttonCenterY = rect.top + rect.height / 2
|
|
24
|
+
|
|
25
|
+
// click body on the button center
|
|
26
|
+
cy.get('body').click(buttonCenterX, buttonCenterY)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
Then('the onClick handler of the button is called', () => {
|
|
31
|
+
cy.window().should((win) => {
|
|
32
|
+
expect(win.onButtonClick).to.be.calledOnce
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
Then('the onClick handler of the Cover is called', () => {
|
|
37
|
+
cy.window().should((win) => {
|
|
38
|
+
expect(win.onCover).to.be.calledOnce
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
Then('the onClick handler of the button is not called', () => {
|
|
43
|
+
cy.window().should((win) => {
|
|
44
|
+
expect(win.onButtonClick).to.have.callCount(0)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
Then('the onClick handler of the Cover is not called', () => {
|
|
49
|
+
cy.window().should((win) => {
|
|
50
|
+
expect(win.onCover).to.have.callCount(0)
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Feature: The Cover has configurable click behaviour
|
|
2
|
+
|
|
3
|
+
Scenario: A blocking Cover
|
|
4
|
+
Given a Cover with a button below it is rendered
|
|
5
|
+
When the user clicks on the button coordinates
|
|
6
|
+
Then the onClick handler of the button is not called
|
|
7
|
+
|
|
8
|
+
Scenario: A blocking Cover with an onClick handler
|
|
9
|
+
Given a Cover with a button in it is rendered
|
|
10
|
+
When the user clicks on the Cover
|
|
11
|
+
Then the onClick handler of the Cover is called
|
|
12
|
+
|
|
13
|
+
Scenario: Clicks orginating from children are ignored
|
|
14
|
+
Given a Cover with a button in it is rendered
|
|
15
|
+
When the user clicks the button
|
|
16
|
+
Then the onClick handler of the button is called
|
|
17
|
+
But the onClick handler of the Cover is not called
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Cover } from './cover.js'
|