Skip to content

chore: Split presentational and logical parts of internal drag handle component #3651

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ exports[`test-utils selectors 1`] = `
"awsui_control_1wepg",
"awsui_description_1p2cx",
"awsui_description_1wepg",
"awsui_direction-button-block-end_8k1rt",
"awsui_direction-button-block-start_8k1rt",
"awsui_direction-button-inline-end_8k1rt",
"awsui_direction-button-inline-start_8k1rt",
"awsui_direction-button-visible_8k1rt",
"awsui_direction-button-block-end_1om0h",
"awsui_direction-button-block-start_1om0h",
"awsui_direction-button-inline-end_1om0h",
"awsui_direction-button-inline-start_1om0h",
"awsui_direction-button-visible_1om0h",
"awsui_disabled_15o6u",
"awsui_dropdown_qwoo0",
"awsui_expand-toggle_1xe88",
Expand Down
4 changes: 2 additions & 2 deletions src/app-layout/utils/use-keyboard-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import React from 'react';

import { Direction } from '../../internal/components/drag-handle-wrapper/interfaces';
import { DragHandleProps } from '../../internal/components/drag-handle/interfaces';
import handleKey from '../../internal/utils/handle-key';
import { SizeControlProps } from './interfaces';

Expand All @@ -25,7 +25,7 @@ const getCurrentSize = (panelRef?: React.RefObject<HTMLDivElement>) => {

export const useKeyboardEvents = ({ position, onResize, panelRef }: SizeControlProps) => {
return {
onDirectionClick: (direction: Direction) => {
onDirectionClick: (direction: DragHandleProps.Direction) => {
let currentSize: number;

const { panelHeight, panelWidth } = getCurrentSize(panelRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ResizableBox, ResizeBoxProps } from '../../../../lib/components/code-ed
import { PointerEventMock } from '../../../../lib/components/internal/utils/pointer-events-mock';

import dragHandleStyles from '../../../../lib/components/internal/components/drag-handle/styles.css.js';
import dragHandleWrapperStyles from '../../../../lib/components/internal/components/drag-handle-wrapper/styles.css.js';
import styles from '../../../../lib/components/code-editor/resizable-box/styles.selectors.js';

const defaultProps: ResizeBoxProps = {
Expand All @@ -27,7 +26,7 @@ function findHandle() {

function findDirectionButton(direction: 'block-start' | 'block-end') {
return document.querySelector(
`.${dragHandleWrapperStyles[`direction-button-wrapper-${direction}`]} .${dragHandleWrapperStyles['direction-button']}`
`.${dragHandleStyles[`direction-button-wrapper-${direction}`]} .${dragHandleStyles['direction-button']}`
)!;
}

Expand Down
17 changes: 0 additions & 17 deletions src/internal/components/drag-handle-wrapper/interfaces.ts

This file was deleted.

110 changes: 0 additions & 110 deletions src/internal/components/drag-handle-wrapper/styles.scss

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';

import DragHandleButton from '../../../../../lib/components/internal/components/drag-handle/button.js';
import DragHandleButton from '../../../../../lib/components/internal/components/drag-handle/components/button.js';

import styles from '../../../../../lib/components/internal/components/drag-handle/styles.css.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import React from 'react';
import { fireEvent, render } from '@testing-library/react';

import DragHandleWrapper from '../../../../../lib/components/internal/components/drag-handle-wrapper';
import {
Direction,
DragHandleWrapperProps,
} from '../../../../../lib/components/internal/components/drag-handle-wrapper/interfaces';
import DragHandleWrapper from '../../../../../lib/components/internal/components/drag-handle/components/wrapper';
import { useDefaultDragBehavior } from '../../../../../lib/components/internal/components/drag-handle/hooks/use-default-drag-behavior';
import { DragHandleProps } from '../../../../../lib/components/internal/components/drag-handle/interfaces';
import { PointerEventMock } from '../../../../../lib/components/internal/utils/pointer-events-mock';

import styles from '../../../../../lib/components/internal/components/drag-handle-wrapper/styles.css.js';
import styles from '../../../../../lib/components/internal/components/drag-handle/styles.css.js';
import tooltipStyles from '../../../../../lib/components/internal/components/tooltip/styles.css.js';

beforeAll(() => {
Expand All @@ -23,7 +21,7 @@ afterEach(() => {
jest.restoreAllMocks();
});

function getDirectionButton(direction: Direction) {
function getDirectionButton(direction: DragHandleProps.Direction) {
return document.querySelector<HTMLButtonElement>(
`.${styles[`direction-button-wrapper-${direction}`]} .${styles['direction-button']}`
);
Expand All @@ -37,36 +35,44 @@ const DIRECTION_BUTTON_HIDDEN_CLASSES = [
styles['direction-button-wrapper-hidden'],
];

function expectDirectionButtonToBeHidden(direction: Direction) {
function expectDirectionButtonToBeHidden(direction: DragHandleProps.Direction) {
expect(
DIRECTION_BUTTON_HIDDEN_CLASSES.some(className =>
getDirectionButton(direction)!.parentElement!.classList.contains(className)
)
).toBe(true);
}

function expectDirectionButtonToBeVisible(direction: Direction) {
function expectDirectionButtonToBeVisible(direction: DragHandleProps.Direction) {
expect(
!DIRECTION_BUTTON_HIDDEN_CLASSES.some(className =>
getDirectionButton(direction)!.parentElement!.classList.contains(className)
)
).toBe(true);
}

function renderDragHandle(props: Partial<Omit<DragHandleWrapperProps, 'children'>>) {
const mergedProps: Omit<DragHandleWrapperProps, 'children'> = {
directions: {},
hideButtonsOnDrag: false,
clickDragThreshold: 3,
function DragHandleWrapperWithLogic(props: Partial<Omit<DragHandleProps, 'children'>>) {
const mergedProps = {
...props,
directions: props.directions ?? {},
hideButtonsOnDrag: props.hideButtonsOnDrag ?? false,
clickDragThreshold: props.clickDragThreshold ?? 3,
triggerMode: props.triggerMode ?? 'focus',
initialShowButtons: props.initialShowButtons ?? false,
};
const { container } = render(
<DragHandleWrapper {...mergedProps}>
const { wrapperProps } = useDefaultDragBehavior(mergedProps);

return (
<DragHandleWrapper tooltipText={props.tooltipText} {...wrapperProps}>
<button type="button" id="drag-button">
Drag
</button>
</DragHandleWrapper>
);
}

function renderDragHandle(props: Partial<Omit<DragHandleProps, 'children'>>) {
const { container } = render(<DragHandleWrapperWithLogic {...props} />);

return {
dragHandle: container.querySelector<HTMLButtonElement>('#drag-button')!,
Expand Down Expand Up @@ -486,7 +492,7 @@ test("doesn't call onDirectionClick when disabled direction button is pressed",
expect(onDirectionClick).not.toHaveBeenCalled();
});

describe('initialinitialShowButtons property', () => {
describe('initialShowButtons property', () => {
test('shows direction buttons initially when initialShowButtons=true', () => {
renderDragHandle({
directions: { 'block-start': 'active', 'block-end': 'active' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import React, { createRef } from 'react';
import { render, waitFor } from '@testing-library/react';

import PortalOverlay from '../../../../../lib/components/internal/components/drag-handle-wrapper/portal-overlay.js';
import PortalOverlay from '../../../../../lib/components/internal/components/drag-handle/components/portal-overlay.js';

import styles from '../../../../../lib/components/internal/components/drag-handle-wrapper/styles.css.js';
import styles from '../../../../../lib/components/internal/components/drag-handle/styles.css.js';

let isRtl = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ import clsx from 'clsx';

import { useMergeRefs } from '@cloudscape-design/component-toolkit/internal';

import { IconProps } from '../../../icon/interfaces';
import InternalIcon from '../../../icon/internal';
import { DragHandleProps } from './interfaces';
import { ResizeIcon } from './resize-icon';
import { IconProps } from '../../../../icon/interfaces';
import InternalIcon from '../../../../icon/internal';
import { DragHandleProps } from '../interfaces';
import { ResizeIcon } from '../resize-icon';

import styles from './styles.css.js';
import testUtilsStyles from './test-classes/styles.css.js';
import styles from '../styles.css.js';
import testUtilsStyles from '../test-classes/styles.css.js';

interface DragHandleButtonProps {
variant?: DragHandleProps.Variant;
size?: DragHandleProps.Size;
disabled?: boolean;
ariaLabel?: string;
ariaLabelledBy?: string;
ariaDescribedby?: string;
ariaValue?: DragHandleProps.AriaValue;
active?: boolean;
className?: string;
onPointerDown?: React.PointerEventHandler;
onKeyDown?: React.KeyboardEventHandler;
}

const DragHandleButton = forwardRef(
(
Expand All @@ -27,7 +41,7 @@ const DragHandleButton = forwardRef(
disabled,
onPointerDown,
onKeyDown,
}: DragHandleProps,
}: DragHandleButtonProps,
ref: React.Ref<Element>
) => {
const dragHandleRefObject = useRef<HTMLDivElement>(null);
Expand Down
Loading
Loading