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

[Emotion] Convert EuiDroppable & EuiDraggable #7187

Merged
merged 17 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -40,7 +40,7 @@ exports[`[React 18] EuiDraggable renders 1`] = `
>
<div
aria-describedby="rfd-hidden-text-:r0:-hidden-text-:r1:"
class="euiDraggable"
class="euiDraggable emotion-euiDraggable-none"
data-rfd-drag-handle-context-id=":r0:"
data-rfd-drag-handle-draggable-id="testDraggable"
data-rfd-draggable-context-id=":r0:"
Expand Down
6 changes: 0 additions & 6 deletions src/components/drag_and_drop/_draggable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,3 @@
}
}
}

@each $size, $spacing in $euiDragAndDropSpacing {
.euiDraggable--#{$size} {
padding: $spacing;
}
}
5 changes: 0 additions & 5 deletions src/components/drag_and_drop/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
$euiDragAndDropSpacing: (
s: ($euiSizeXS / 2),
m: ($euiSizeS / 2),
l: ($euiSize / 2),
);
32 changes: 32 additions & 0 deletions src/components/drag_and_drop/draggable.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { css } from '@emotion/react';

import { UseEuiTheme } from '../../services';
import { mathWithUnits } from '../../global_styling';

export const euiDraggableStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

return {
euiDraggable: css``,
spacing: {
none: css``,
s: css`
padding: ${euiTheme.size.xxs};
`,
m: css`
padding: ${mathWithUnits(euiTheme.size.m, (x) => x / 2)};
`,
l: css`
padding: ${euiTheme.size.m};
`,
},
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
};
};
21 changes: 12 additions & 9 deletions src/components/drag_and_drop/draggable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ import React, {
} from 'react';
import { Draggable, DraggableProps } from '@hello-pangea/dnd';
import classNames from 'classnames';

import { useEuiTheme } from '../../services';
import { CommonProps } from '../common';
import { EuiDroppableContext } from './droppable';

const spacingToClassNameMap = {
none: null,
s: 'euiDraggable--s',
m: 'euiDraggable--m',
l: 'euiDraggable--l',
};
import { EuiDroppableContext } from './droppable';
import { euiDraggableStyles } from './draggable.styles';

export type EuiDraggableSpacing = keyof typeof spacingToClassNameMap;
const SPACINGS = ['none', 's', 'm', 'l'] as const;
export type EuiDraggableSpacing = (typeof SPACINGS)[number];

export interface EuiDraggableProps
extends CommonProps,
Expand Down Expand Up @@ -71,6 +69,9 @@ export const EuiDraggable: FunctionComponent<EuiDraggableProps> = ({
}) => {
const { cloneItems } = useContext(EuiDroppableContext);

const euiTheme = useEuiTheme();
const styles = euiDraggableStyles(euiTheme);

return (
<Draggable
draggableId={draggableId}
Expand All @@ -79,6 +80,8 @@ export const EuiDraggable: FunctionComponent<EuiDraggableProps> = ({
{...rest}
>
{(provided, snapshot, rubric) => {
const cssStyles = [styles.euiDraggable, styles.spacing[spacing]];

const classes = classNames(
'euiDraggable',
{
Expand All @@ -87,7 +90,6 @@ export const EuiDraggable: FunctionComponent<EuiDraggableProps> = ({
'euiDraggable--isDragging': snapshot.isDragging,
'euiDraggable--withoutDropAnimation': isRemovable,
},
spacingToClassNameMap[spacing],
className
);
const childClasses = classNames('euiDraggable__item', {
Expand All @@ -108,6 +110,7 @@ export const EuiDraggable: FunctionComponent<EuiDraggableProps> = ({
ref={provided.innerRef}
data-test-subj={dataTestSubj}
className={classes}
css={cssStyles}
style={{ ...style, ...provided.draggableProps.style }}
// We use [role="group"] instead of [role="button"] when we expect a nested
// interactive element. Screen readers will cue users that this is a container
Expand Down