Skip to content

Commit c90e3b0

Browse files
authoredNov 11, 2019
feat: add animationMode configuration (#905)
- Add animationMode to configure the degree of components animations. Available options are: 'full' (by default), 'basic', 'minimal', 'none'. - Switch on/off the ui5-panel toggle animation based on the 'animationMode'
1 parent 638a8a7 commit c90e3b0

File tree

9 files changed

+112
-2
lines changed

9 files changed

+112
-2
lines changed
 

‎docs/Configuration.md

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ theme | sap_fiori_3, sap_belize, sap_belize_hcb | sap_fiori_3 |
1111
language | en, de, es, etc... | en | Language to be used for translatable texts
1212
[RTL](#rtl) | true, false | false | When true, sets global text direction to right-to-left
1313
compactSize | true, false | false | When set, enforces compact density (smaller margins/paddings)
14+
[animationMode](#animationMode) | full, basic, minimal, none | full | Defines different animation scenarios or levels
1415
calendarType | Gregorian, Islamic, Buddhist, Japanese, Persian | Gregorian | Default calendar type for date-related web components
1516
[noConflict](#noConflict) | true, false | Object | false | When set to true, all events will be fired with a "ui5-" prefix only
1617
[formatSettings](#formatSettings)| See the [Format settings](#formatSettings) section below | Empty object | Allows to override locale-specific configuration
@@ -22,6 +23,17 @@ When the `rtl` setting is set to `true`, UI5 Web Components will adjust their st
2223
However, you should also set the HTML attribute `dir` to `rtl` on the `body` or `html` or any other relevant region of your application
2324
so that the rest of your application is also affected.
2425

26+
<a name="animationMode"></a>
27+
###Animation Mode
28+
29+
Animation modes allow to specify different animation scenarios or levels.
30+
- When `full` all animations run unrestricted.
31+
- When `basic` more light-weight set of animations would run.
32+
- When `minimal` animations of fundamental functionality are included.
33+
- When `none` all animations are completely suspended.
34+
35+
*Please note that each component determines which animations would run for a specific mode.*
36+
2537
<a name="noConflict"></a>
2638
### No conflict
2739

@@ -100,6 +112,7 @@ import { getTheme, setTheme } from "@ui5/webcomponents-base/dist/config/Theme.js
100112
import { getNoConflict, setNoConflict } from "@ui5/webcomponents-base/dist/config/NoConflict.js";
101113
import { getCompactSize } from "@ui5/webcomponents-base/dist/config/CompactSize.js";
102114
import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
115+
import { getCompactSize } from "@ui5/webcomponents-base/dist/config/AnimationMode.js";
103116
import { getLanguage } from "@ui5/webcomponents-base/dist/config/Language.js";
104117
import { getCalendarType } from "@ui5/webcomponents-base/dist/config/CalendarType.js";
105118
import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSettings.js";

‎packages/base/src/InitialConfiguration.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let initialized = false;
22

33
const initialConfig = {
4+
animationMode: "full",
45
theme: "sap_fiori_3",
56
rtl: null,
67
language: null,
@@ -11,6 +12,11 @@ const initialConfig = {
1112
};
1213

1314
/* General settings */
15+
const getAnimationMode = () => {
16+
initConfiguration();
17+
return initialConfig.animationMode;
18+
};
19+
1420
const getTheme = () => {
1521
initConfiguration();
1622
return initialConfig.theme;
@@ -109,6 +115,7 @@ const initConfiguration = () => {
109115
};
110116

111117
export {
118+
getAnimationMode,
112119
getTheme,
113120
getRTL,
114121
getLanguage,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getAnimationMode as getConfiguredAnimationMode } from "../InitialConfiguration.js";
2+
3+
const animationMode = getConfiguredAnimationMode();
4+
5+
const getAnimationMode = () => {
6+
return animationMode;
7+
};
8+
9+
export { getAnimationMode }; // eslint-disable-line
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const AnimationMode = {
2+
Full: "full",
3+
Basic: "basic",
4+
Minimal: "minimal",
5+
None: "none",
6+
};
7+
export default AnimationMode;

‎packages/main/bundle.esm.js

+2
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ window.isIE = isIE; // attached to the window object for testing purposes
6363

6464

6565
// Note: keep in sync with rollup.config value for IIFE
66+
import { getAnimationMode } from "@ui5/webcomponents-base/dist/config/AnimationMode.js";
6667
import { getTheme, setTheme } from "@ui5/webcomponents-base/dist/config/Theme.js";
6768
import { setNoConflict } from "@ui5/webcomponents-base/dist/config/NoConflict.js";
6869
import { getCompactSize } from "@ui5/webcomponents-base/dist/config/CompactSize.js";
6970
import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
7071
import { getRegisteredNames as getIconNames } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js"
7172
window["sap-ui-webcomponents-main-bundle"] = {
7273
configuration : {
74+
getAnimationMode,
7375
getTheme,
7476
setTheme,
7577
setNoConflict,

‎packages/main/src/Panel.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
>
2020
<ui5-button
2121
design="Transparent"
22-
class="ui5-panel-header-button"
22+
class="ui5-panel-header-button {{classes.headerBtn}}"
2323
icon="sap-icon://navigation-right-arrow"
2424
?non-focusable="{{nonFocusableButton}}"
2525
@click="{{_toggleButtonClick}}"

‎packages/main/src/Panel.js

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
33
import slideDown from "@ui5/webcomponents-base/dist/animations/slideDown.js";
44
import slideUp from "@ui5/webcomponents-base/dist/animations/slideUp.js";
55
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/events/PseudoEvents.js";
6+
import AnimationMode from "@ui5/webcomponents-base/dist/types/AnimationMode.js";
7+
import { getAnimationMode } from "@ui5/webcomponents-base/dist/config/AnimationMode.js";
68
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
79
import Button from "./Button.js";
810
import "./icons/navigation-right-arrow.js";
@@ -223,6 +225,10 @@ class Panel extends UI5Element {
223225
return true;
224226
}
225227

228+
shouldAnimate() {
229+
return getAnimationMode() !== AnimationMode.None;
230+
}
231+
226232
_headerClick(event) {
227233
if (!this.shouldToggle(event.target)) {
228234
return;
@@ -268,6 +274,12 @@ class Panel extends UI5Element {
268274
}
269275

270276
this.collapsed = !this.collapsed;
277+
278+
if (!this.shouldAnimate()) {
279+
this.fireEvent("toggle");
280+
return;
281+
}
282+
271283
this._animationRunning = true;
272284

273285
const elements = this.getDomRef().querySelectorAll(".ui5-panel-content");
@@ -296,6 +308,14 @@ class Panel extends UI5Element {
296308
return target.classList.contains("sapMPanelWrappingDiv");
297309
}
298310

311+
get classes() {
312+
return {
313+
headerBtn: {
314+
"ui5-panel-header-button-animated": this.shouldAnimate(),
315+
},
316+
};
317+
}
318+
299319
get toggleButtonTitle() {
300320
return this.i18nBundle.getText(PANEL_ICON);
301321
}

‎packages/main/src/themes/Panel.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
border-bottom: 1px solid transparent;
3838
}
3939

40-
.ui5-panel-header-button {
40+
.ui5-panel-header-button-animated {
4141
transition: transform 0.4s ease-out;
4242
}
4343

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
5+
<meta charset="utf-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta charset="utf-8">
8+
<title>Animations off</title>
9+
10+
<script data-ui5-config type="application/json">
11+
{
12+
"animationMode": "none"
13+
}
14+
</script>
15+
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
16+
<script src="../../resources/bundle.esm.js" type="module"></script>
17+
<script nomodule src="../../resources/bundle.es5.js"></script>
18+
19+
<style>.panel {border: 1px dotted #bad0e3;}.header {display: flex;align-items: center;width: 100%;}</style>
20+
21+
<script>
22+
document.addEventListener("DOMContentLoaded", function () {
23+
panel1.addEventListener("ui5-toggle", function (event) {
24+
console.log(event);
25+
event.target.headerText = event.target.collapsed ? "Click to expand!" : "Click to collapse!";
26+
field1.value = parseInt(field1.value) + 1;
27+
});
28+
panel2.addEventListener("ui5-toggle", function (event) {
29+
field2.value = parseInt(field2.value) + 1;
30+
});
31+
});
32+
</script>
33+
</head>
34+
35+
<body>
36+
<ui5-panel id="panel1" collapsed header-text="Click to expand!" class="panel">
37+
<ui5-title>This is a demo how to use the &quot;expand&quot; event.</ui5-title><br>
38+
<ui5-label>Some short text.</ui5-label>
39+
</ui5-panel>
40+
41+
<ui5-panel id="panel2" collapsed accessible-role="Complementary" class="panel">
42+
<div slot="header" class="header">
43+
<ui5-title>Expandable but not expanded</ui5-title>
44+
</div>
45+
<ui5-title>This is a demo how to use the &quot;expand&quot; event.</ui5-title><br>
46+
<ui5-label>Some short text.</ui5-label>
47+
</ui5-panel><br>
48+
49+
<ui5-input id="field1" value="0"></ui5-input>
50+
<ui5-input id="field2" value="0"></ui5-input>
51+
</body>
52+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.