Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions packages/module/src/WidgetLayout/GridLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const createSerializableConfig = (config?: WidgetConfiguration) => {

const getResizeHandle = (resizeHandleAxis: string, ref: React.Ref<HTMLElement>) => (
<div ref={ref as React.Ref<HTMLDivElement>} className={`react-resizable-handle react-resizable-handle-${resizeHandleAxis}`}>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path d="M16 1.14286L14.8571 0L0 14.8571V16H1.14286L16 1.14286Z" fill="currentColor" />
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path d="M9.5 16L16 9.5" stroke="currentColor" strokeWidth="1" strokeLinecap="round" vectorEffect="non-scaling-stroke" />
<path d="M4 16L16 4" stroke="currentColor" strokeWidth="1" strokeLinecap="round" vectorEffect="non-scaling-stroke" />
</svg>
</div>
);
Expand Down
18 changes: 18 additions & 0 deletions packages/module/src/WidgetLayout/__tests__/GridLayout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import GridLayout from '../GridLayout';
Expand Down Expand Up @@ -197,6 +199,22 @@ describe('GridLayout', () => {
});
});

describe('resize handles', () => {
it('keeps enabled handles in the layout for touch resizing', () => {
const styles = readFileSync(resolve(__dirname, '../../styles.css'), 'utf8');

expect(styles).toMatch(
/\.react-grid-item:not\(\.static\) \.react-resizable-handle\s*{[^}]*display:\s*grid;[^}]*opacity:\s*0;/s
);
expect(styles).toMatch(
/@media \(pointer: coarse\)\s*{[^}]*\.react-grid-item:not\(\.static\) \.react-resizable-handle\s*{[^}]*opacity:\s*1;/s
);
expect(styles).toMatch(
/\.react-grid-item\.static \.react-resizable-handle\s*{[^}]*display:\s*none;/
);
});
});

describe('callbacks', () => {
it('calls onActiveWidgetsChange on initial render', () => {
const onActiveWidgetsChange = jest.fn();
Expand Down
70 changes: 63 additions & 7 deletions packages/module/src/styles.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.react-grid-item .react-resizable-handle-nw,
.react-grid-item .react-resizable-handle-sw,
.react-grid-item .react-resizable-handle-se {
.react-grid-item:not(.static) .react-resizable-handle {
display: grid;
place-items: center;
opacity: 0;
}

.react-grid-item.static .react-resizable-handle {
display: none;
}

Expand All @@ -15,12 +19,28 @@
}

.react-grid-item:hover:not(.static) .react-resizable-handle-nw,
.react-grid-item:hover:not(.static) .react-resizable-handle-ne,
.react-grid-item:hover:not(.static) .react-resizable-handle-sw,
.react-grid-item:hover:not(.static) .react-resizable-handle-se,
.react-grid-item:hover:not(.static) .react-resizable-handle-n,
.react-grid-item:hover:not(.static) .react-resizable-handle-s,
.react-grid-item:hover:not(.static) .react-resizable-handle-w,
.react-grid-item:hover:not(.static) .react-resizable-handle-e,
.react-grid-item:active:not(.static) .react-resizable-handle-nw,
.react-grid-item:active:not(.static) .react-resizable-handle-ne,
.react-grid-item:active:not(.static) .react-resizable-handle-sw,
.react-grid-item:active:not(.static) .react-resizable-handle-se {
display: inherit;
.react-grid-item:active:not(.static) .react-resizable-handle-se,
.react-grid-item:active:not(.static) .react-resizable-handle-n,
.react-grid-item:active:not(.static) .react-resizable-handle-s,
.react-grid-item:active:not(.static) .react-resizable-handle-w,
.react-grid-item:active:not(.static) .react-resizable-handle-e {
opacity: 1;
}

@media (pointer: coarse) {
.react-grid-item:not(.static) .react-resizable-handle {
opacity: 1;
}
}

/* Doubled class for specificity to override react-grid-layout defaults */
Expand All @@ -33,9 +53,45 @@
display: none;
}

.react-grid-item.react-grid-item .react-resizable-handle {
inline-size: var(--pf-t--global--spacer--lg);
block-size: var(--pf-t--global--spacer--lg);
color: var(--pf-t--global--icon--color--subtle);
}

.react-grid-item.react-grid-item > .react-resizable-handle-w,
.react-grid-item.react-grid-item > .react-resizable-handle-e {
margin-block-start: calc(var(--pf-t--global--spacer--lg) / -2);
}

.react-grid-item.react-grid-item > .react-resizable-handle-n,
.react-grid-item.react-grid-item > .react-resizable-handle-s {
margin-inline-start: calc(var(--pf-t--global--spacer--lg) / -2);
}

.react-grid-item.react-grid-item > .react-resizable-handle-nw {
margin-block-start: calc(var(--pf-t--global--spacer--xs) * 3 / 4);
margin-inline-start: calc(var(--pf-t--global--spacer--xs) * 3 / 4);
}

.react-grid-item.react-grid-item > .react-resizable-handle-ne {
margin-block-start: calc(var(--pf-t--global--spacer--xs) * 3 / 4);
margin-inline-end: calc(var(--pf-t--global--spacer--xs) * 3 / 4);
}

.react-grid-item.react-grid-item > .react-resizable-handle-sw {
margin-block-end: calc(var(--pf-t--global--spacer--xs) * 3 / 4);
margin-inline-start: calc(var(--pf-t--global--spacer--xs) * 3 / 4);
}

.react-grid-item.react-grid-item > .react-resizable-handle-se {
margin-block-end: calc(var(--pf-t--global--spacer--xs) * 3 / 4);
margin-inline-end: calc(var(--pf-t--global--spacer--xs) * 3 / 4);
}

.react-grid-item .react-resizable-handle svg {
width: 100%;
height: 100%;
inline-size: calc(var(--pf-t--global--spacer--md) + var(--pf-t--global--spacer--xs) / 2);
block-size: calc(var(--pf-t--global--spacer--md) + var(--pf-t--global--spacer--xs) / 2);
display: block;
}

Expand Down
Loading