Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui5-flexible-column-layout): add arrow icon functionality #10362

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions packages/fiori/src/FlexibleColumnLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ import {
isRightShift,
isHome,
isEnd,
isEnter,
isSpace,
} from "@ui5/webcomponents-base/dist/Keys.js";
import type { PassiveEventListenerObject, AriaLandmarkRole } from "@ui5/webcomponents-base";
import FCLLayout from "./types/FCLLayout.js";
import type { LayoutConfiguration } from "./fcl-utils/FCLLayout.js";
import {
getPhoneTabletLayouts,
getDesktopLayouts,
getLayoutsByMedia,
} from "./fcl-utils/FCLLayout.js";

Expand Down Expand Up @@ -311,6 +315,7 @@ class FlexibleColumnLayout extends UI5Element {
static i18nBundle: I18nBundle;

_prevLayout: `${FCLLayout}` | null;
_hasBeenInIconVisibleLayout: boolean;
_userDefinedColumnLayouts: UserDefinedColumnLayouts = {
tablet: {},
desktop: {},
Expand All @@ -322,6 +327,7 @@ class FlexibleColumnLayout extends UI5Element {
super();

this._prevLayout = null;
this._hasBeenInIconVisibleLayout = false;
this.initialRendering = true;
this._handleResize = this.handleResize.bind(this);
this._onSeparatorMove = this.onSeparatorMove.bind(this);
Expand Down Expand Up @@ -657,13 +663,34 @@ class FlexibleColumnLayout extends UI5Element {
}

async _onkeydown(e: KeyboardEvent) {
if (isEnter(e) || isSpace(e)) {
e.preventDefault();
const focusedElement = e.target as HTMLElement;
if (focusedElement === this.startArrowDOM) {
this.toggleStartColumnVisibility();
return;
}
return;
}

const stepSize = 2,
bigStepSize = this._width,
isRTL = this.effectiveDir === "rtl";
let step = 0;

if (!this.startColumnVisible && e.target === this.startSeparatorDOM && isLeft(e)) {
return;
}

if (isLeft(e)) {
if (this.startArrowDOM === e.target) {
return;
}
step = -stepSize * 10;
} else if (isRight(e)) {
if (this.startArrowDOM === e.target) {
return;
}
step = stepSize * 10;
} else if (isLeftShift(e)) {
step = -stepSize;
Expand Down Expand Up @@ -770,6 +797,33 @@ class FlexibleColumnLayout extends UI5Element {
return `${(pxWidth / this._availableWidthForColumns) * 100}%`;
}

toggleStartColumnVisibility() {
NakataCode marked this conversation as resolved.
Show resolved Hide resolved
const isPhoneOrTablet = this.media === MEDIA.PHONE || this.media === MEDIA.TABLET,
isDesktop = this.media === MEDIA.DESKTOP,
phoneTabletLayouts = getPhoneTabletLayouts(),
desktopLayouts = getDesktopLayouts();

if (this.layout === FCLLayout.ThreeColumnsBeginHiddenMidExpanded || this.layout === FCLLayout.ThreeColumnsBeginHiddenEndExpanded) {
this._hasBeenInIconVisibleLayout = true;
}

if (isPhoneOrTablet) {
if (this.layout === FCLLayout.ThreeColumnsMidExpanded || phoneTabletLayouts.includes(this.layout)) {
this.layout = FCLLayout.ThreeColumnsBeginHiddenMidExpanded;
} else if (this.layout === FCLLayout.ThreeColumnsBeginHiddenMidExpanded) {
this.layout = FCLLayout.TwoColumnsMidExpanded;
}
}

if (isDesktop) {
if (desktopLayouts.includes(this.layout)) {
this.layout = FCLLayout.ThreeColumnsBeginHiddenMidExpanded;
} else if (this.layout === FCLLayout.ThreeColumnsBeginHiddenMidExpanded) {
this.layout = FCLLayout.ThreeColumnsMidExpanded;
}
}
}

getNextLayoutOnSeparatorMovement(separator: HTMLElement, isStartToEndDirection: boolean, fclLayoutBeforeMove: FCLLayout, columnLayoutAfterMove: FlexibleColumnLayoutColumnLayout) {
const isStartSeparator = separator === this.startSeparatorDOM,
separatorName = isStartSeparator ? "start" : "end",
Expand Down Expand Up @@ -829,6 +883,31 @@ class FlexibleColumnLayout extends UI5Element {
return FCLLayout.ThreeColumnsMidExpanded;
}

if (moved({
separator: "start",
from: FCLLayout.ThreeColumnsBeginHiddenMidExpanded,
forward: true,
}) && newColumnWidths.start >= 25) {
NakataCode marked this conversation as resolved.
Show resolved Hide resolved
this._hasBeenInIconVisibleLayout = true;
return FCLLayout.ThreeColumnsMidExpanded;
}

if (moved({
separator: "end",
from: FCLLayout.ThreeColumnsBeginHiddenMidExpanded,
forward: false,
}) && newColumnWidths.mid < newColumnWidths.end) {
return FCLLayout.ThreeColumnsBeginHiddenEndExpanded;
}

if (moved({
separator: "end",
from: FCLLayout.ThreeColumnsBeginHiddenEndExpanded,
forward: true,
}) && newColumnWidths.mid >= newColumnWidths.end) {
return FCLLayout.ThreeColumnsBeginHiddenMidExpanded;
}

if (moved({
separator: "end",
from: FCLLayout.ThreeColumnsMidExpanded,
Expand Down Expand Up @@ -1012,6 +1091,39 @@ class FlexibleColumnLayout extends UI5Element {
return this.shadowRoot!.querySelector<HTMLElement>(".ui5-fcl-separator-end")!;
}

get startArrowDOM() {
return this.shadowRoot!.querySelector<HTMLElement>(".ui5-fcl-arrow--start")!;
}

get arrowIconName() {
const effectiveLayout = this.separatorMovementSession?.tmpFCLLayout || this.layout;
const isTablet = this.media === MEDIA.TABLET;
const startColumnHidden = !this.startColumnVisible;

const shouldDisplayIcon = effectiveLayout === FCLLayout.ThreeColumnsBeginHiddenMidExpanded
|| effectiveLayout === FCLLayout.ThreeColumnsBeginHiddenEndExpanded
|| this._hasBeenInIconVisibleLayout;

if (!shouldDisplayIcon) {
return "";
}

if (effectiveLayout === FCLLayout.ThreeColumnsBeginHiddenMidExpanded
|| (effectiveLayout === FCLLayout.ThreeColumnsMidExpanded && isTablet && startColumnHidden)) {
return "navigation-right-arrow";
}

if (effectiveLayout === FCLLayout.TwoColumnsMidExpanded
|| effectiveLayout === FCLLayout.ThreeColumnsMidExpanded
|| effectiveLayout === FCLLayout.TwoColumnsStartExpanded
|| effectiveLayout === FCLLayout.ThreeColumnsBeginHiddenEndExpanded
|| effectiveLayout === FCLLayout.ThreeColumnsStartExpandedEndHidden
|| effectiveLayout === FCLLayout.ThreeColumnsMidExpandedEndHidden) {
return "navigation-left-arrow";
}
return "navigation-right-arrow";
}

get startSeparatorTabIndex() {
if (this.showStartSeparatorGrip) {
return 0;
Expand Down
21 changes: 16 additions & 5 deletions packages/fiori/src/FlexibleColumnLayoutTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,22 @@ export default function FlexibleColumnLayoutTemplate(this: FlexibleColumnLayout)

function gripStart(this: FlexibleColumnLayout) {
return (
<Icon
name={verticalGrip}
class="ui5-fcl-grip ui5-fcl-grip--start"
style={{ display: this.showStartSeparatorGrip ? "inline-block" : "none" }}
/>
<div>
{ this.arrowIconName && (
NakataCode marked this conversation as resolved.
Show resolved Hide resolved
<Icon
class="ui5-fcl-arrow ui5-fcl-arrow--start"
name={this.arrowIconName}
style={{ display: this.showStartSeparatorGrip ? "inline-block" : "none" }}
onClick={this.toggleStartColumnVisibility}
tabIndex={0}
/>
)}
<Icon
name={verticalGrip}
class="ui5-fcl-grip ui5-fcl-grip--start"
style={{ display: this.showStartSeparatorGrip ? "inline-block" : "none" }}
/>
</div>
);
}

Expand Down
65 changes: 65 additions & 0 deletions packages/fiori/src/fcl-utils/FCLLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ const getLayoutsByMedia = (): LayoutConfiguration => {
{ visible: true, gripVisible: true },
],
},
"ThreeColumnsBeginHiddenMidExpanded": {
NakataCode marked this conversation as resolved.
Show resolved Hide resolved
layout: ["0px", "67%", "33%"],
separators: [
{ visible: true, gripVisible: true },
NakataCode marked this conversation as resolved.
Show resolved Hide resolved
{ visible: true, gripVisible: true },
],
},
"ThreeColumnsBeginHiddenEndExpanded": {
layout: ["0px", "33%", "67%"],
separators: [
{ visible: true, gripVisible: false },
{ visible: true, gripVisible: true },
],
},
"MidColumnFullScreen": {
layout: ["0px", "100%", "0px"],
separators: [
Expand Down Expand Up @@ -130,6 +144,20 @@ const getLayoutsByMedia = (): LayoutConfiguration => {
{ visible: true, gripVisible: true },
],
},
"ThreeColumnsBeginHiddenMidExpanded": {
layout: ["0px", "67%", "33%"],
separators: [
{ visible: true, gripVisible: true },
{ visible: true, gripVisible: true },
],
},
"ThreeColumnsBeginHiddenEndExpanded": {
layout: ["0px", "33%", "67%"],
separators: [
{ visible: false },
{ visible: true, gripVisible: true },
],
},
"MidColumnFullScreen": {
layout: ["0px", "100%", "0px"],
separators: [
Expand Down Expand Up @@ -195,6 +223,20 @@ const getLayoutsByMedia = (): LayoutConfiguration => {
{ visible: false },
],
},
"ThreeColumnsBeginHiddenMidExpanded": {
layout: ["0px", "100%", "0px"],
separators: [
{ visible: false },
{ visible: false },
],
},
"ThreeColumnsBeginHiddenEndExpanded": {
layout: ["0px", "0px", "100%"],
separators: [
{ visible: false },
{ visible: false },
],
},
"MidColumnFullScreen": {
layout: ["0px", "100%", "0px"],
separators: [
Expand All @@ -213,7 +255,30 @@ const getLayoutsByMedia = (): LayoutConfiguration => {
};
};

const getPhoneTabletLayouts = () => {
return [
"TwoColumnsMidExpanded",
"ThreeColumnsMidExpanded",
"ThreeColumnsBeginHiddenEndExpanded",
"TwoColumnsStartExpanded",
"ThreeColumnsStartExpandedEndHidden",
"ThreeColumnsMidExpandedEndHidden",
];
};

const getDesktopLayouts = () => {
return [
"TwoColumnsMidExpanded",
"ThreeColumnsMidExpanded",
"TwoColumnsStartExpanded",
"ThreeColumnsStartExpandedEndHidden",
"ThreeColumnsMidExpandedEndHidden",
];
};

export {
getPhoneTabletLayouts,
getDesktopLayouts,
getLayoutsByMedia,
};

Expand Down
31 changes: 27 additions & 4 deletions packages/fiori/src/themes/FlexibleColumnLayout.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
display: none;
}

/* arrow */
.ui5-fcl-separator {
display: flex;
align-items: center;
Expand All @@ -50,6 +49,24 @@
border:var(--_ui5_fcl_separator_focus_border);
outline: none;
}

/* arrow icon*/
.ui5-fcl-arrow--start {
color: var(--sapButton_TextColor);
border-radius: 0.25rem;
position: absolute;
top: 1rem;
left: 50%;
transform: translateX(-50%);
cursor: pointer;
z-index: 10;
}

.ui5-fcl-arrow--start:focus {
border: var(--_ui5_fcl_separator_focus_border);
outline: none;
}

.ui5-fcl-grip {
cursor: col-resize;
overflow: visible;
Expand All @@ -59,7 +76,7 @@
padding-bottom: 0.3125rem;
}

/* arrow decoration */
/* grip decoration */
.ui5-fcl-grip:before {
background-image: var(--_ui5_fcl_decoration_top);
bottom: calc(50% + 1rem);
Expand All @@ -83,8 +100,14 @@
background-position-x: calc(50% - 0.03125rem);
}

.ui5-fcl-separator:hover .ui5-fcl-grip:before,
.ui5-fcl-separator:hover .ui5-fcl-grip:after {
/*only if the arrow is present the lines will be shorten*/
.ui5-fcl-separator:has(.ui5-fcl-arrow--start):hover:not(:has(.ui5-fcl-arrow--start:hover)) .ui5-fcl-grip:before,
.ui5-fcl-separator:has(.ui5-fcl-arrow--start):hover:not(:has(.ui5-fcl-arrow--start:hover)) .ui5-fcl-grip:after {
height: calc(40% - 1rem);
}

.ui5-fcl-separator:hover:not(:has(.ui5-fcl-arrow--start:hover)) .ui5-fcl-grip:before,
.ui5-fcl-separator:hover:not(:has(.ui5-fcl-arrow--start:hover)) .ui5-fcl-grip:after {
height: calc(50% - 1rem);
}
NakataCode marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
20 changes: 20 additions & 0 deletions packages/fiori/src/types/FCLLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ enum FCLLayout {
*/
ThreeColumnsMidExpandedEndHidden = "ThreeColumnsMidExpandedEndHidden",

/**
* Desktop: Defaults to 0 - 67 - 33 percent widths of columns. Start is hidden, Mid (expanded) and End columns are displayed.
* Tablet: Defaults to 0 - 67 - 33 percent widths of columns. Start is hidden, Mid (expanded) and End columns are displayed.
* Phone: Fixed -- 100 percent width of the Mid column, only the Mid column is displayed.
*
* Use to display the Mid and End columns while the Start column is hidden.
* @public
*/
ThreeColumnsBeginHiddenMidExpanded = "ThreeColumnsBeginHiddenMidExpanded",

/**
* Desktop: Defaults to 0 - 33 - 67 percent widths of columns. Start is hidden, Mid and End (expanded) columns are displayed.
* Tablet: Defaults to 0 - 33 - 67 percent widths of columns. Start is hidden, Mid and End (expanded) columns are displayed.
* Phone: Fixed -- 100 percent width of the End column, only the End column is displayed.
*
* Use to display the Mid column and expanded End column while the grip of the separator is not visible.
* @public
*/
ThreeColumnsBeginHiddenEndExpanded = "ThreeColumnsBeginHiddenEndExpanded",

/**
* Desktop: Fixed -- 100 -- percent widths of columns, only the Mid column is displayed
* Tablet: Fixed -- 100 -- percent widths of columns, only the Mid column is displayed
Expand Down
Loading
Loading