Skip to content

Commit 856df0b

Browse files
refactor(Popovers): Remove custom logic (#408)
Remove custom open / openBy logic from Dialog, Popover and Responsive Popover and use the plain UI5 Web Component. BREAKING CHANGE: **Dialog**: Remove property `open`. You can now open a dialog by attaching a ref to the dialog and call the method `open()`. BREAKING CHANGE: **Popover**: Removed props `openBy`, `openByStyle`, `open` and `propagateOpenByClickEvent`. For opening a popover after e.g. a button click attach a ref to the popover and use the button click hander for calling `.openBy(event.target)` on the popover ref. BREAKING CHANGE: **ResponsivePopover**: Removed props `openBy`, `openByStyle`, `open` and `propagateOpenByClickEvent`. For opening a responsive popover after e.g. a button click attach a ref to the responsive popover and use the Button click hander for calling `.open(event.target)` on the responsive popover ref.
1 parent e9547df commit 856df0b

File tree

28 files changed

+1188
-1436
lines changed

28 files changed

+1188
-1436
lines changed

netlify.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# Default build command.
1414
command = "npm run build:storybook"
1515

16+
environment = { UI5_WEBCOMPONENTS_FOR_REACT_RELEASE_BUILD = "true" }
17+
1618
# Deploy Preview context: all deploys generated from a pull/merge request will
1719
# inherit these settings.
1820
[context.deploy-preview]

packages/main/src/components/ActionSheet/ActionSheet.jss.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ const styles = {
33
* is being applied to the encapsulating ul element
44
*/
55
actionSheet: {
6-
listStyleType: 'none',
76
margin: 0,
87
padding: '0.1875rem 0.375rem',
9-
'&$tablet,&$phone': {
10-
padding: '0.25rem 0.5rem'
11-
},
128
'& ui5-button': {
139
display: 'block'
1410
}
15-
},
16-
phone: {},
17-
tablet: {}
11+
}
1812
};
1913

2014
export default styles;

packages/main/src/components/ActionSheet/ActionSheet.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('ActionSheet', () => {
4141
wrapper.update();
4242

4343
wrapper
44-
.find('ui5-popover ui5-button')
44+
.find('ui5-responsive-popover ui5-button')
4545
.first()
4646
.instance()
4747
// @ts-ignore
@@ -63,14 +63,14 @@ describe('ActionSheet', () => {
6363
<Button>This is my super long text!</Button>
6464
</ActionSheet>
6565
);
66-
expect(legacyRef.tagName).toEqual('UI5-POPOVER');
66+
expect(legacyRef.tagName).toEqual('UI5-RESPONSIVE-POPOVER');
6767
});
6868

6969
test('Ref object', () => {
7070
const ref: RefObject<Ui5PopoverDomRef> = createRef();
7171
const button = <Button />;
7272
mount(<ActionSheet ref={ref} openBy={button} />);
73-
expect((ref.current as any).tagName).toEqual('UI5-POPOVER');
73+
expect((ref.current as any).tagName).toEqual('UI5-RESPONSIVE-POPOVER');
7474
});
7575

7676
test('does not crash with other component', () => {
Lines changed: 41 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,51 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`ActionSheet Render without Crashing 1`] = `
4-
Array [
5-
<div
6-
style="display: inline-block;"
4+
<ui5-responsive-popover
5+
class="ActionSheet-actionSheet-0 myCustomClass"
6+
horizontal-align="Center"
7+
initial-focus=""
8+
placement-type="Right"
9+
vertical-align="Center"
10+
>
11+
<ui5-button
12+
data-is-action-sheet-button=""
13+
design="Transparent"
14+
icon="add"
715
>
8-
<ui5-button
9-
design="Default"
10-
icon=""
11-
/>
12-
</div>,
13-
<ui5-popover
14-
class="ActionSheet-actionSheet-0 myCustomClass"
15-
horizontal-align="Center"
16-
initial-focus=""
17-
placement-type="Bottom"
18-
vertical-align="Center"
16+
Accept
17+
</ui5-button>
18+
<ui5-button
19+
data-is-action-sheet-button=""
20+
design="Transparent"
21+
icon=""
1922
>
20-
<ui5-button
21-
data-is-action-sheet-button=""
22-
design="Transparent"
23-
icon="add"
24-
>
25-
Accept
26-
</ui5-button>
27-
<ui5-button
28-
data-is-action-sheet-button=""
29-
design="Transparent"
30-
icon=""
31-
>
32-
Reject
33-
</ui5-button>
34-
<ui5-button
35-
data-is-action-sheet-button=""
36-
design="Transparent"
37-
icon=""
38-
>
39-
This is my super long text!
40-
</ui5-button>
41-
</ui5-popover>,
42-
]
23+
Reject
24+
</ui5-button>
25+
<ui5-button
26+
data-is-action-sheet-button=""
27+
design="Transparent"
28+
icon=""
29+
>
30+
This is my super long text!
31+
</ui5-button>
32+
</ui5-responsive-popover>
4333
`;
4434

4535
exports[`ActionSheet does not crash with other component 1`] = `
46-
Array [
47-
<div
48-
style="display: inline-block;"
49-
>
50-
<ui5-button
51-
design="Default"
52-
icon=""
53-
/>
54-
</div>,
55-
<ui5-popover
56-
class="ActionSheet-actionSheet-0"
57-
horizontal-align="Center"
58-
initial-focus=""
59-
placement-type="Bottom"
60-
vertical-align="Center"
36+
<ui5-responsive-popover
37+
class="ActionSheet-actionSheet-0"
38+
horizontal-align="Center"
39+
initial-focus=""
40+
placement-type="Right"
41+
vertical-align="Center"
42+
>
43+
<ui5-label
44+
data-is-action-sheet-button=""
45+
design="Transparent"
46+
for=""
6147
>
62-
<ui5-label
63-
data-is-action-sheet-button=""
64-
design="Transparent"
65-
for=""
66-
>
67-
I should not crash
68-
</ui5-label>
69-
</ui5-popover>,
70-
]
48+
I should not crash
49+
</ui5-label>
50+
</ui5-responsive-popover>
7151
`;

packages/main/src/components/ActionSheet/demo.stories.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,31 @@ import { select } from '@storybook/addon-knobs';
22
import { ActionSheet } from '@ui5/webcomponents-react/lib/ActionSheet';
33
import { Button } from '@ui5/webcomponents-react/lib/Button';
44
import { PlacementType } from '@ui5/webcomponents-react/lib/PlacementType';
5-
import React from 'react';
5+
import React, { useCallback, useRef } from 'react';
66

77
export default {
88
title: 'Components / ActionSheet',
99
component: ActionSheet
1010
};
1111

12-
export const defaultStory = () => (
13-
<ActionSheet
14-
openBy={<Button>Open ActionSheet</Button>}
15-
placement={select('placement', [PlacementType.Top, PlacementType.Bottom], PlacementType.Top)}
16-
>
17-
<Button icon="add">Accept</Button>
18-
<Button>Reject</Button>
19-
<Button>This is my super long text!</Button>
20-
</ActionSheet>
21-
);
12+
export const defaultStory = () => {
13+
const actionSheetRef = useRef();
14+
const onButtonClick = useCallback(
15+
(e) => {
16+
actionSheetRef.current.open(e.target);
17+
},
18+
[actionSheetRef]
19+
);
20+
return (
21+
<>
22+
<Button onClick={onButtonClick}>Open ActionSheet</Button>
23+
<ActionSheet ref={actionSheetRef} placementType={select('placementType', PlacementType, PlacementType.Bottom)}>
24+
<Button icon="add">Accept</Button>
25+
<Button>Reject</Button>
26+
<Button>This is my super long text!</Button>
27+
</ActionSheet>
28+
</>
29+
);
30+
};
2231

2332
defaultStory.story = { name: 'Default' };

packages/main/src/components/ActionSheet/index.tsx

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { addCustomCSS } from '@ui5/webcomponents-base/dist/Theming';
2-
import { Device } from '@ui5/webcomponents-react-base/lib/Device';
2+
import { createComponentStyles } from '@ui5/webcomponents-react-base/lib/createComponentStyles';
33
import { StyleClassHelper } from '@ui5/webcomponents-react-base/lib/StyleClassHelper';
44
import { useConsolidatedRef } from '@ui5/webcomponents-react-base/lib/useConsolidatedRef';
55
import { usePassThroughHtmlProps } from '@ui5/webcomponents-react-base/lib/usePassThroughHtmlProps';
66
import { ButtonDesign } from '@ui5/webcomponents-react/lib/ButtonDesign';
77
import { PlacementType } from '@ui5/webcomponents-react/lib/PlacementType';
8-
import { Popover } from '@ui5/webcomponents-react/lib/Popover';
9-
import React, { Children, cloneElement, FC, forwardRef, ReactElement, ReactNode, RefObject } from 'react';
10-
import { createComponentStyles } from '@ui5/webcomponents-react-base/lib/createComponentStyles';
11-
import { CommonProps } from '../../interfaces/CommonProps';
12-
import { Ui5PopoverDomRef } from '../../interfaces/Ui5PopoverDomRef';
8+
import { ResponsivePopover } from '@ui5/webcomponents-react/lib/ResponsivePopover';
9+
import React, { Children, cloneElement, FC, forwardRef, ReactElement, RefObject } from 'react';
10+
import { Ui5ResponsivePopoverDomRef } from '../../interfaces/Ui5ResponsivePopoverDomRef';
1311
import { ButtonPropTypes } from '../../webComponents/Button';
12+
import { ResponsivePopoverPropTypes } from '../../webComponents/ResponsivePopover';
1413
import styles from './ActionSheet.jss';
1514

16-
export interface ActionSheetPropTypes extends CommonProps {
17-
openBy: ReactNode;
15+
export interface ActionSheetPropTypes extends ResponsivePopoverPropTypes {
1816
placement?: PlacementType;
1917
children?: ReactElement<ButtonPropTypes> | ReactElement<ButtonPropTypes>[];
2018
}
@@ -34,22 +32,36 @@ addCustomCSS(
3432
* <code>import { ActionSheet } from '@ui5/webcomponents-react/lib/ActionSheet';</code>
3533
*/
3634
const ActionSheet: FC<ActionSheetPropTypes> = forwardRef(
37-
(props: ActionSheetPropTypes, ref: RefObject<Ui5PopoverDomRef>) => {
38-
const { children, placement, openBy, style, slot, className } = props;
35+
(props: ActionSheetPropTypes, ref: RefObject<Ui5ResponsivePopoverDomRef>) => {
36+
const {
37+
children,
38+
style,
39+
slot,
40+
className,
41+
allowTargetOverlap,
42+
headerText,
43+
horizontalAlign,
44+
initialFocus,
45+
modal,
46+
noArrow,
47+
placementType,
48+
verticalAlign,
49+
footer,
50+
header,
51+
onAfterClose,
52+
onAfterOpen,
53+
onBeforeClose,
54+
onBeforeOpen
55+
} = props;
3956

4057
const classes = useStyles();
4158

4259
const actionSheetClasses = StyleClassHelper.of(classes.actionSheet);
4360
if (className) {
4461
actionSheetClasses.put(className);
4562
}
46-
if (Device.system.tablet) {
47-
actionSheetClasses.put(classes.tablet);
48-
} else if (Device.system.phone) {
49-
actionSheetClasses.put(classes.phone);
50-
}
5163

52-
const popoverRef: RefObject<Ui5PopoverDomRef> = useConsolidatedRef(ref);
64+
const popoverRef: RefObject<Ui5ResponsivePopoverDomRef> = useConsolidatedRef(ref);
5365

5466
const onActionButtonClicked = (handler) => (e) => {
5567
popoverRef.current.close();
@@ -67,20 +79,37 @@ const ActionSheet: FC<ActionSheetPropTypes> = forwardRef(
6779
});
6880
};
6981

70-
const passThroughProps = usePassThroughHtmlProps(props);
82+
const passThroughProps = usePassThroughHtmlProps(props, [
83+
'onAfterClose',
84+
'onAfterOpen',
85+
'onBeforeClose',
86+
'onBeforeOpen'
87+
]);
7188

7289
return (
73-
<Popover
90+
<ResponsivePopover
7491
ref={popoverRef}
75-
openBy={openBy}
76-
placementType={placement}
7792
style={style}
7893
slot={slot}
7994
className={actionSheetClasses.valueOf()}
95+
allowTargetOverlap={allowTargetOverlap}
96+
headerText={headerText}
97+
horizontalAlign={horizontalAlign}
98+
initialFocus={initialFocus}
99+
modal={modal}
100+
noArrow={noArrow}
101+
placementType={placementType}
102+
verticalAlign={verticalAlign}
103+
footer={footer}
104+
header={header}
105+
onAfterClose={onAfterClose}
106+
onAfterOpen={onAfterOpen}
107+
onBeforeClose={onBeforeClose}
108+
onBeforeOpen={onBeforeOpen}
80109
{...passThroughProps}
81110
>
82111
{Children.map(children, renderActionSheetButton)}
83-
</Popover>
112+
</ResponsivePopover>
84113
);
85114
}
86115
);

packages/main/src/components/AnalyticalTable/AnalyticalTable.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ describe('AnalyticalTable', () => {
230230
const wrapper = mount(<AnalyticalTable data={data} title={'Test'} columns={columns} />);
231231

232232
// get first column of the table and simulate dragging of it
233-
let componentDrag = wrapper.find('div[role="columnheader"] div[draggable]').at(0);
233+
let componentDrag = wrapper.find('div[role="columnheader"][draggable]').at(0);
234234
let inst = componentDrag.instance();
235235
// @ts-ignore
236236
let dragColumnId = inst.dataset.columnId;
@@ -248,7 +248,7 @@ describe('AnalyticalTable', () => {
248248
dataTransfer.getData = () => {
249249
return dragColumnId;
250250
};
251-
let componentDrop = wrapper.find('div[role="columnheader"] div[draggable]').at(1);
251+
let componentDrop = wrapper.find('div[role="columnheader"][draggable]').at(1);
252252
// @ts-ignore
253253
componentDrop.simulate('drop', { dataTransfer: dataTransfer });
254254

0 commit comments

Comments
 (0)