diff --git a/cypress/drafts/Menu/position.feature b/cypress/drafts/Menu/position.feature deleted file mode 100644 index d8318f564f..0000000000 --- a/cypress/drafts/Menu/position.feature +++ /dev/null @@ -1,51 +0,0 @@ -Feature: Position of a menu component - - # default max width: 380px; default max height: 380px - Background: - Given the menu component has a height and width of its default maximum - - Scenario: Default rendering - Given there is enough space between the anchor's bottom and the body's bottom to fit the default maximum - When the menu is opened - Then the menu is below the anchor - And the left of the menu is aligned with the left of the anchor - - Scenario: Flipped vertically - Given there is not enough space between the anchor's bottom and the body's bottom to fit the default maximum - And there is not enough space between the anchor's top and the body's top to fit the default maximum - When the menu is opened - Then the menu is above the anchor - And the left of the menu is aligned with the left of the anchor - - Scenario: Less than 368px and more than 50px available space below and above anchor - Given there is not enough space between the anchor's bottom and the body's bottom to fit the default maximum - And there is not enough space between the anchor's top and the body's top to fit the default maximum - But there is more than 50px of available space between the anchor's bottom and the body's bottom - When the menu is opened - Then the menu is below the anchor - And the height of the menu is reduced to fit - - # ¯\_(ツ)_/¯ - # This will cause the menu always to be off screen, but that's the apps fault - Scenario: Less than 50px available space below and above anchor - Given there is not enough space between the anchor's top and the body's top to fit the default maximum - And there is not enough space between the anchor's bottom and the body's bottom to fit the default maximum - When the menu is opened - Then the menu is below the anchor - And the heght of the menu is not reduced below 50px - - Scenario: Flipped horizontally - Given the space between the anchor's right and the body's right is less than the horizontal minimum space - And the space between the anchor's left and the body's left is at least the horizontal minimum space - When the menu is opened - Then the right of the menu is aligned with the right of the anchor - And the menu is below the anchor - - # ¯\_(ツ)_/¯ - # This will cause the menu always to be off screen, but that's the apps fault - Scenario: Forced body overflow - Given the space between the anchor's right and the body's right is less than the horizontal minimum space - And the space between the anchor's left and the body's left is less than the horizontal minimum space - When the menu is opened - Then the left of the menu is aligned with the left of the anchor - And the menu is rendered below the anchor diff --git a/cypress/drafts/Popover/position.feature b/cypress/drafts/Popover/position.feature deleted file mode 100644 index 70b8df5165..0000000000 --- a/cypress/drafts/Popover/position.feature +++ /dev/null @@ -1,31 +0,0 @@ -Feature: Popover positioning - - Background: - Given the popover has a width of 360px and height of 200px - - Scenario: Spacing between anchor and popover - When the anchor is clicked - Then there is some space between the anchor and the popover - - Scenario: Default positioning - Given there is enough space between the anchor's top and the body's top to fit the Popover - When the anchor is clicked - Then the popover is rendered above the the anchor - And the horizontal center of the popover is aligned with the horizontal center of the anchor - - Scenario: Flipped vertical - Given there is not enough space between the anchor's top and the body's top to fit the Popover - And there is enough space between the anchor's bottom and the body's bottom to fit the Popover - When the anchor is clicked - Then the popover is rendered below the anchor - And the horizontal center of the popover is aligned with the horizontal center of the anchor - - Scenario: Adjusted width - Given there is not enough space between the anchor's top and the body's top to fit the Popover - And there is not enough space between the anchor's bottom and the body's bottom to fit the Popover - When the anchor is clicked - Then the popover is rendered above the anchor - And the horizontal center of the popover is aligned with the horizontal center of the anchor - And the popover width is reduced to fit in the available space - - #!!Note: this is a exact copy of tooltip positioning diff --git a/cypress/drafts/Select/position.feature b/cypress/drafts/Select/position.feature deleted file mode 100644 index b0a487a0e1..0000000000 --- a/cypress/drafts/Select/position.feature +++ /dev/null @@ -1,25 +0,0 @@ -Feature: Position of select menu dropdown - - Background: - Given the select menu dropdown has a height of 368px - And the select menu dropdown has a width of 280px - - Scenario: Default rendering - Given there is enough space between the anchor's bottom and the body's bottom to fit the Select's menu - When the menu is opened - Then it is rendered below the select - And the left of the select is aligned with the left of the anchor - - Scenario: Flipped rendering when insufficient space below - Given there is not enough space between the anchor's bottom and the body's bottom to fit the Select's menu - And there is enough space between the anchor's top and the body's top to fit the Select's menu - When the menu is opened - Then it is rendered above the select - And the left of the select is aligned with the left of the anchor - - Scenario: A select with less than 368px available space below and above - Given there is not enough space between the anchor's bottom and the body's bottom to fit the Select's menu - And there is not enough space between the anchor's top and the body's top to fit the Select's menu - When the menu is opened - Then it is rendered below the select - And the height of the select dropdown menu is reduced to fit within the
element diff --git a/cypress/drafts/Tooltip/position.feature b/cypress/drafts/Tooltip/position.feature deleted file mode 100644 index 0c60451986..0000000000 --- a/cypress/drafts/Tooltip/position.feature +++ /dev/null @@ -1,38 +0,0 @@ -Feature: Tooltip positioning - - Background: - Given the tooltip has a width of 300px and height of 28px - - Scenario: Spacing between anchor and tooltip - When the anchor is clicked - Then there is some space between the anchor and the tooltip - - Scenario: Default positioning - Given there is enough space between the anchor's top and the body's top to fit the Tooltip - When the anchor is clicked - Then the tooltip is rendered above the the anchor - And the horizontal center of the tooltip is aligned with the horizontal center of the anchor - - Scenario: Flipped vertical - Given there is not enough space between the anchor's top and the body's top to fit the Tooltip - And there is enough space between the anchor's bottom and the body's bottom to fit the Tooltip - When the anchor is clicked - Then the tooltip is rendered below the anchor - And the horizontal center of the tooltip is aligned with the horizontal center of the anchor - - Scenario: Adjusted horiztonal position - Given there is enough space between the anchor's top and the body's top to fit the Tooltip - And there is enough space between the body's left and the body's right to fit the Tooltip - And the Tooltip doesn't use more than 50% of the space between the body's sides and the anchor's sides - When the anchor is clicked - Then the tooltip is rendered above the anchor - And the horizontal center of the tooltip is aligned with the horizontal center of the anchor - - Scenario: Adjusted width - Given there is enough space between the anchor's top and the body's top to fit the Tooltip - And there is enough space between the body's left and the body's right to fit the Tooltip - And the Tooltip does use more than 50% of the space between the body's sides and the anchor's sides - When the anchor is clicked - Then the tooltip is rendered above the anchor - And the horizontal center of the tooltip is aligned with the horizontal center of the anchor - But the tooltip's width is reducesd to only take 50% of the space available next to the anchor diff --git a/cypress/integration/Backdrop/accepts_children.feature b/cypress/integration/Backdrop/accepts_children.feature deleted file mode 100644 index 246f9e1a09..0000000000 --- a/cypress/integration/Backdrop/accepts_children.feature +++ /dev/null @@ -1,5 +0,0 @@ -Feature: The Backdrop renders children - - Scenario: A Backdrop with children - Given a Backdrop with children is rendered - Then the children are visible diff --git a/cypress/integration/Backdrop/accepts_children/index.js b/cypress/integration/Backdrop/accepts_children/index.js deleted file mode 100644 index 93fee4d32e..0000000000 --- a/cypress/integration/Backdrop/accepts_children/index.js +++ /dev/null @@ -1,10 +0,0 @@ -import { Given, Then } from 'cypress-cucumber-preprocessor/steps' - -Given('a Backdrop with children is rendered', () => { - cy.visitStory('Backdrop', 'With children') - cy.get('[data-test="dhis2-uicore-backdrop"]').should('be.visible') -}) - -Then('the children are visible', () => { - cy.contains('I am a child').should('be.visible') -}) diff --git a/cypress/integration/Backdrop/is_clickable.feature b/cypress/integration/Backdrop/is_clickable.feature deleted file mode 100644 index 19cac5a086..0000000000 --- a/cypress/integration/Backdrop/is_clickable.feature +++ /dev/null @@ -1,6 +0,0 @@ -Feature: The Backdrop has an onClick api - - Scenario: The user clicks on the Backdrop - Given a Backdrop with onClick handler is rendered - When the user clicks on the Backdrop - Then the onClick handler will be called diff --git a/cypress/integration/Backdrop/is_clickable/index.js b/cypress/integration/Backdrop/is_clickable/index.js deleted file mode 100644 index 3b7c90406c..0000000000 --- a/cypress/integration/Backdrop/is_clickable/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' - -Given('a Backdrop with onClick handler is rendered', () => { - cy.visitStory('Backdrop', 'With onClick') -}) - -When('the user clicks on the Backdrop', () => { - cy.get('[data-test="dhis2-uicore-backdrop"]').click() -}) - -Then('the onClick handler will be called', () => { - cy.window().then(win => { - expect(win.onClick).to.be.calledWith({}) - }) -}) diff --git a/cypress/integration/ComponentCover/accepts_children/index.js b/cypress/integration/ComponentCover/accepts_children/index.js index 49754b4375..64712cb8c5 100644 --- a/cypress/integration/ComponentCover/accepts_children/index.js +++ b/cypress/integration/ComponentCover/accepts_children/index.js @@ -1,7 +1,7 @@ import { Given, Then } from 'cypress-cucumber-preprocessor/steps' Given('a ComponentCover with children is rendered', () => { - cy.visitStory('ComponentCover', 'With children') + cy.visitStory('ComponentCover', 'With Children') cy.get('[data-test="dhis2-uicore-componentcover"]').should('be.visible') }) diff --git a/cypress/integration/ComponentCover/click_behavior.feature b/cypress/integration/ComponentCover/click_behavior.feature new file mode 100644 index 0000000000..90d61e59ac --- /dev/null +++ b/cypress/integration/ComponentCover/click_behavior.feature @@ -0,0 +1,22 @@ +Feature: The ComponentCover has configurable click behaviour + + Scenario: A non-blocking ComponentCover + Given a ComponentCover with pointerEvents none and a button below it is rendered + When the user clicks the button + Then the onClick handler of the button is called + + Scenario: A blocking ComponentCover + Given a ComponentCover with a button below it is rendered + When the user clicks on the button coordinates + Then the onClick handler of the button is not called + + Scenario: A blocking ComponentCover with an onClick handler + Given a ComponentCover with a button in it is rendered + When the user clicks on the ComponentCover + Then the onClick handler of the ComponentCover is called + + Scenario: Clicks orginating from children are ignored + Given a ComponentCover with a button in it is rendered + When the user clicks the button + Then the onClick handler of the button is called + But the onClick handler of the ComponentCover is not called diff --git a/cypress/integration/ComponentCover/click_behavior/index.js b/cypress/integration/ComponentCover/click_behavior/index.js new file mode 100644 index 0000000000..21f5dce3b6 --- /dev/null +++ b/cypress/integration/ComponentCover/click_behavior/index.js @@ -0,0 +1,59 @@ +import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' + +Given( + 'a ComponentCover with pointerEvents none and a button below it is rendered', + () => { + cy.visitStory('ComponentCover', 'Non Blocking') + } +) + +Given('a ComponentCover with a button below it is rendered', () => { + cy.visitStory('ComponentCover', 'Blocking') +}) + +Given('a ComponentCover with a button in it is rendered', () => { + cy.visitStory('ComponentCover', 'With Click Handler') +}) + +When('the user clicks the button', () => { + cy.get('button').click() +}) + +When('the user clicks on the ComponentCover', () => { + cy.get('[data-test="dhis2-uicore-componentcover"]').click() +}) + +When('the user clicks on the button coordinates', () => { + cy.getPositionsBySelectors('button').then(([rect]) => { + // Get button center coordinates + const buttonCenterX = rect.left + rect.width / 2 + const buttonCenterY = rect.top + rect.height / 2 + + // click body on the button center + cy.get('body').click(buttonCenterX, buttonCenterY) + }) +}) + +Then('the onClick handler of the button is called', () => { + cy.window().then(win => { + expect(win.onButtonClick).to.be.calledOnce + }) +}) + +Then('the onClick handler of the ComponentCover is called', () => { + cy.window().then(win => { + expect(win.onComponentCoverClick).to.be.calledOnce + }) +}) + +Then('the onClick handler of the button is not called', () => { + cy.window().then(win => { + expect(win.onButtonClick).to.have.callCount(0) + }) +}) + +Then('the onClick handler of the ComponentCover is not called', () => { + cy.window().then(win => { + expect(win.onComponentCoverClick).to.have.callCount(0) + }) +}) diff --git a/cypress/integration/DropdownButton/opens_a_dropdown.feature b/cypress/integration/DropdownButton/opens_a_dropdown.feature index 6d1224ec5b..017874532e 100644 --- a/cypress/integration/DropdownButton/opens_a_dropdown.feature +++ b/cypress/integration/DropdownButton/opens_a_dropdown.feature @@ -7,5 +7,5 @@ Feature: The DropdownButton renders a dropdown Scenario: The user closes the dropdown Given a DropdownButton with opened dropdown is rendered - When the Backdrop is clicked + When the user clicks the backdrop Layer Then the dropdown is not rendered diff --git a/cypress/integration/DropdownButton/opens_a_dropdown/index.js b/cypress/integration/DropdownButton/opens_a_dropdown/index.js index afe2881c6c..39a2c47253 100644 --- a/cypress/integration/DropdownButton/opens_a_dropdown/index.js +++ b/cypress/integration/DropdownButton/opens_a_dropdown/index.js @@ -12,8 +12,8 @@ Given('a DropdownButton with opened dropdown is rendered', () => { cy.get('[data-test="dhis2-uicore-dropdownbutton-popper"]').should('exist') }) -When('the Backdrop is clicked', () => { - cy.get('[data-test="dhis2-uicore-backdrop"]').click() +When('the user clicks the backdrop Layer', () => { + cy.get('[data-test="dhis2-uicore-layer"]').click() }) Then('the dropdown is not rendered', () => { diff --git a/cypress/integration/Layer/accepts_children.feature b/cypress/integration/Layer/accepts_children.feature new file mode 100644 index 0000000000..5ffe48e8a3 --- /dev/null +++ b/cypress/integration/Layer/accepts_children.feature @@ -0,0 +1,5 @@ +Feature: The Layer renders children + + Scenario: A Layer with children + Given a Layer with children is rendered + Then the children are visible diff --git a/cypress/integration/Layer/accepts_children/index.js b/cypress/integration/Layer/accepts_children/index.js new file mode 100644 index 0000000000..b687dc83d8 --- /dev/null +++ b/cypress/integration/Layer/accepts_children/index.js @@ -0,0 +1,8 @@ +import { Given, Then } from 'cypress-cucumber-preprocessor/steps' + +Given('a Layer with children is rendered', () => { + cy.visitStory('Layer', 'Default') +}) +Then('the children are visible', () => { + cy.contains('I am a child').should('be.visible') +}) diff --git a/cypress/integration/Layer/click_behavior.feature b/cypress/integration/Layer/click_behavior.feature new file mode 100644 index 0000000000..cef3686777 --- /dev/null +++ b/cypress/integration/Layer/click_behavior.feature @@ -0,0 +1,22 @@ +Feature: The Layer has configurable click behaviour + + Scenario: A non-blocking layer + Given a Layer with pointerEvents none and a button below it is rendered + When the user clicks the button + Then the onClick handler of the button is called + + Scenario: A blocking layer + Given a Layer with a button below it is rendered + When the user clicks on the button coordinates + Then the onClick handler of the button is not called + + Scenario: A blocking layer with an onClick handler + Given a Layer with a button in it is rendered + When the user clicks on the layer + Then the onClick handler of the layer is called + + Scenario: Clicks orginating from children are ignored + Given a Layer with a button in it is rendered + When the user clicks the button + Then the onClick handler of the button is called + But the onClick handler of the layer is not called diff --git a/cypress/integration/Layer/click_behavior/index.js b/cypress/integration/Layer/click_behavior/index.js new file mode 100644 index 0000000000..72e8e19dd1 --- /dev/null +++ b/cypress/integration/Layer/click_behavior/index.js @@ -0,0 +1,59 @@ +import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' + +Given( + 'a Layer with pointerEvents none and a button below it is rendered', + () => { + cy.visitStory('Layer', 'Non Blocking') + } +) + +Given('a Layer with a button below it is rendered', () => { + cy.visitStory('Layer', 'Blocking') +}) + +Given('a Layer with a button in it is rendered', () => { + cy.visitStory('Layer', 'With Click Handler') +}) + +When('the user clicks the button', () => { + cy.get('button').click() +}) + +When('the user clicks on the layer', () => { + cy.get('[data-test="dhis2-uicore-layer"]').click() +}) + +When('the user clicks on the button coordinates', () => { + cy.getPositionsBySelectors('button').then(([rect]) => { + // Get button center coordinates + const buttonCenterX = rect.left + rect.width / 2 + const buttonCenterY = rect.top + rect.height / 2 + + // click body on the button center + cy.get('body').click(buttonCenterX, buttonCenterY) + }) +}) + +Then('the onClick handler of the button is called', () => { + cy.window().then(win => { + expect(win.onButtonClick).to.be.calledOnce + }) +}) + +Then('the onClick handler of the layer is called', () => { + cy.window().then(win => { + expect(win.onLayerClick).to.be.calledOnce + }) +}) + +Then('the onClick handler of the button is not called', () => { + cy.window().then(win => { + expect(win.onButtonClick).to.have.callCount(0) + }) +}) + +Then('the onClick handler of the layer is not called', () => { + cy.window().then(win => { + expect(win.onLayerClick).to.have.callCount(0) + }) +}) diff --git a/cypress/integration/Layer/stacking.feature b/cypress/integration/Layer/stacking.feature new file mode 100644 index 0000000000..64a25d01c1 --- /dev/null +++ b/cypress/integration/Layer/stacking.feature @@ -0,0 +1,34 @@ +Feature: Layers are stacked on top of each other + + Scenario: Equal sibling layers + Given two equal sibling Layers are rendered + Then the second layer is on top of the first layer + + Scenario: Inequal sibling layers + Given an alert, blocking, and applicatioTop Layer are rendered as siblings + Then the alert layer is on top + + # use zIndex stacking context + Scenario: Nesting Layer elements with lower levels + Given a blocking layer is rendered as the child of an alert layer + Then the blocking layer is on top + And the blocking layer is a child of the alert layer + + # avoid stacking context upper bound issue + Scenario: Appending nested Layers with higher levels to the body + Given an alert layer is rendered as the child of a blocking layer + Then the alert layer is on top + And the alert layer is a sibling of the blocking layer + + # verify that bug from previous implementation is not there + # that bug was as follows: + # nested layers top element zIndex = 1000 + 1 + 1 = 1002 + # sibling layer element zIndex = 1001 + # so layer level 1001 would be below the nested layer with level 1000 + Scenario: Levels are respected when nesting layers + Given a layer with level 1001 is a sibling of 3 nested layers with level 1000 + Then the layer with level 1001 is on top + + Scenario: Nested higher levels still end up on top + Given an applicatioTop layer with a nested alert layer with a blocking sibling + Then the alert layer is on top diff --git a/cypress/integration/Layer/stacking/index.js b/cypress/integration/Layer/stacking/index.js new file mode 100644 index 0000000000..24465c53c0 --- /dev/null +++ b/cypress/integration/Layer/stacking/index.js @@ -0,0 +1,70 @@ +import { Given, Then } from 'cypress-cucumber-preprocessor/steps' + +Given('two equal sibling Layers are rendered', () => { + cy.visitStory('Layer', 'Equal Siblings') +}) + +Given( + 'an alert, blocking, and applicatioTop Layer are rendered as siblings', + () => { + cy.visitStory('Layer', 'Inequal Siblings') + } +) + +Given('a blocking layer is rendered as the child of an alert layer', () => { + cy.visitStory('Layer', 'Nested Lower Levels') +}) + +Given('an alert layer is rendered as the child of a blocking layer', () => { + cy.visitStory('Layer', 'Nested Higher Levels') +}) + +Given( + 'a layer with level 1001 is a sibling of 3 nested layers with level 1000', + () => { + cy.visitStory('Layer', 'Levels Are Respected When Nesting') + } +) + +Given( + 'an applicatioTop layer with a nested alert layer with a blocking sibling', + () => { + cy.visitStory('Layer', 'Nested Higher Level Ends On Top') + } +) + +Then('the second layer is on top of the first layer', () => { + assertLayerIsOnTop('second') +}) + +Then('the alert layer is on top', () => { + assertLayerIsOnTop('alert') +}) + +Then('the layer with level 1001 is on top', () => { + assertLayerIsOnTop('1001') +}) + +Then('the blocking layer is on top', () => { + assertLayerIsOnTop('blocking') +}) + +Then('the blocking layer is a child of the alert layer', () => { + cy.get('[data-test="blocking"]') + .parent() + .should('have.data', 'test', 'alert') +}) + +Then('the alert layer is a sibling of the blocking layer', () => { + cy.get('[data-test="blocking"]') + .next() + .should('have.data', 'test', 'alert') +}) + +function assertLayerIsOnTop(layerName) { + cy.get('body').click() + cy.window().then(win => { + expect(win.onLayerClick).to.be.calledOnce + expect(win.onLayerClick).to.be.calledWith(layerName) + }) +} diff --git a/cypress/integration/LayerContext/layers.feature.future b/cypress/integration/LayerContext/layers.feature.future deleted file mode 100644 index e4074032f4..0000000000 --- a/cypress/integration/LayerContext/layers.feature.future +++ /dev/null @@ -1,35 +0,0 @@ -Feature: Layers - - Scenario: Base layer z-index calculation - Given a Layer component wraps a component - And the prop zIndexBase is "0" - Then the Layer renders with a z-index of "0" - - Scenario: Application top layer z-index calculation - Given a Layer component wraps a component - And the prop zIndexBase is "2000" - Then the Layer renders with a z-index of "2000" - - Scenario: Blocking layer z-index calculation - Given a Layer component wraps a component - And the prop zIndexBase is "3000" - Then the Layer renders with a z-index of "3000" - - Scenario: Alert layer z-index calculation - Given a Layer component wraps a component - And the prop zIndexBase is "9999" - Then the Layer renders with a z-index of "9999" - - Scenario: Nested layer z-index calculation - Given a Layer component is nested inside of another Layer component - And the outer Layer component has a higher "I am a child
+Lorem ipsum
+ > +) + +export const Translucent = () => ( + <> +Lorem ipsum
+ > +) + +export const WithClickHandler = () => ( + <> +Lorem ipsum
+ > +) + +export const NonBlocking = () => ( + <> ++ You can still select this text because the cover has pointer-event: + none. +
+ > +) + +export const WithCenteredContentCircularLoader = () => ( + <> +Lorem ipsum
-Lorem ipsum
-Lorem ipsum
+ > +) diff --git a/packages/widgets/src/DropdownButton/DropdownButton.js b/packages/widgets/src/DropdownButton/DropdownButton.js index 5652926295..fd00b41d98 100644 --- a/packages/widgets/src/DropdownButton/DropdownButton.js +++ b/packages/widgets/src/DropdownButton/DropdownButton.js @@ -1,13 +1,12 @@ import propTypes from '@dhis2/prop-types' import React, { Component } from 'react' -import { createPortal } from 'react-dom' import { resolve } from 'styled-jsx/css' import { spacers } from '@dhis2/ui-constants' import { ArrowDown, ArrowUp } from '@dhis2/ui-icons' import { Button } from '../Button/Button.js' -import { Backdrop } from '../Backdrop/Backdrop.js' +import { Layer } from '../Layer/Layer.js' import { Popper } from '../Popper/Popper.js' import { sharedPropTypes } from '@dhis2/ui-constants' @@ -88,19 +87,17 @@ class DropdownButton extends Component {I am a child
+Lorem ipsum
+ > ) -DivInLayer.propTypes = { - stackLevel: propTypes.number.isRequired, - children: propTypes.node, - className: propTypes.string, -} +export const Translucent = () => ( + <> +Lorem ipsum
+ > ) -storiesOf('Component/Widget/Layer', module).add('Inverse nesting', () => ( +export const WithClickHandler = () => ( <> -Lorem ipsum
> -)) +) + +export const NonBlocking = () => ( + <> ++ You can still select this text because the layer has pointer-event: + none. +
+ > +) + +export const WithCenteredContentCircularLoader = () => ( + <> +Lorem ipsum
+ > +) diff --git a/packages/widgets/src/LayerContext/LayerContext.js b/packages/widgets/src/LayerContext/LayerContext.js deleted file mode 100644 index dd8a49f377..0000000000 --- a/packages/widgets/src/LayerContext/LayerContext.js +++ /dev/null @@ -1,62 +0,0 @@ -import React, { useContext } from 'react' - -import propTypes from '@dhis2/prop-types' -import { layers } from '@dhis2/ui-constants' - -const LayerContext = React.createContext(0) - -const getStackedLayer = (zIndex, context) => { - // Keep alert layer constant - if (zIndex === layers.alert) { - return layers.alert - } - - // Differentiate between a stacked blocking and applicationTop layer - const layerIncrement = zIndex === layers.blocking ? 2 : 1 - const layer = context + layerIncrement - - // stay within stack layer boundaries defined by the design system - // https://github.com/dhis2/design-system/blob/master/principles/spacing-alignment.md#stacking - if (layer >= layers.alert) { - return layers.alert - 1 - } - - return layer -} - -const useLayer = zIndex => { - const context = useContext(LayerContext) - - if (context) return getStackedLayer(zIndex, context) - - return zIndex -} - -/** - * @module - * @private - * @param {Layer.PropTypes} props - * @returns {React.Component} - */ -const Layer = ({ children, zIndex }) => { - const newLayer = useLayer(zIndex) - - return ( -