Skip to content

Commit

Permalink
[Emotion] Convert EuiTreeView (#7513)
Browse files Browse the repository at this point in the history
Co-authored-by: Trevor Pierce <1Copenut@users.noreply.github.com>
  • Loading branch information
cee-chen and 1Copenut authored Feb 7, 2024
1 parent b2687f2 commit 4584d91
Show file tree
Hide file tree
Showing 14 changed files with 592 additions and 421 deletions.
9 changes: 9 additions & 0 deletions changelogs/upcoming/7513.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**Bug fixes**

- Fixed an `EuiTreeView` bug where `aria-expanded` was being applied to items without expandable children

**CSS-in-JS conversions**

- Converted `EuiTreeView` to Emotion. Updates as part of the conversion:
- Removed `.euiTreeView__wrapper` div node
- Enforced consistent `icon` size based on `display` size
9 changes: 6 additions & 3 deletions src-docs/src/views/tree_view/playground.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { EuiTreeView, EuiIcon } from '../../../../src/components';
import { EuiTreeViewClass } from '../../../../src/components/tree_view/tree_view';
import {
propUtilityForPlayground,
generateCustomProps,
} from '../../services/playground';

export const TreeViewConfig = () => {
const docgenInfo = Array.isArray(EuiTreeView.__docgenInfo)
? EuiTreeView.__docgenInfo[0]
: EuiTreeView.__docgenInfo;
const docgenInfo = Array.isArray(EuiTreeViewClass.__docgenInfo)
? EuiTreeViewClass.__docgenInfo[0]
: EuiTreeViewClass.__docgenInfo;
const propsToUse = propUtilityForPlayground(docgenInfo.props);

delete propsToUse.theme;

propsToUse.display = {
...propsToUse.display,
defaultValue: 'default',
Expand Down
1 change: 0 additions & 1 deletion src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@import 'datagrid/index';
@import 'form/index';
@import 'markdown_editor/index';
@import 'tree_view/index';
@import 'side_nav/index';
@import 'selectable/index';
@import 'table/index';
175 changes: 80 additions & 95 deletions src/components/tree_view/__snapshots__/tree_view.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiTreeView is rendered 1`] = `
<div
class="euiText euiTreeView__wrapper emotion-euiText-m"
>
<div>
<p
class="emotion-euiScreenReaderOnly"
id="euiTreeView_generated-id--instruction"
Expand All @@ -13,147 +11,134 @@ exports[`EuiTreeView is rendered 1`] = `
<ul
aria-describedby="euiTreeView_generated-id--instruction"
aria-label="aria-label"
class="euiTreeView testClass1 testClass2 emotion-euiTestCss"
class="euiTreeView testClass1 testClass2 emotion-euiTreeView-default-euiTestCss"
data-test-subj="test subject string"
id="euiTreeView_generated-id"
role="list"
>
<li
class="euiTreeView__node euiTreeView__node--expanded"
class="euiTreeView__node euiTreeView__node--expanded emotion-euiTreeView__node-default-expanded"
>
<button
aria-controls="euiTreeView_generated-id_item_one"
aria-expanded="true"
class="euiTreeView__nodeInner"
class="euiTreeView__nodeInner emotion-euiTreeView__nodeInner-default"
data-test-subj="euiTreeViewButton-euiTreeView_generated-id"
id="item_one"
>
<span
class="euiTreeView__iconWrapper"
class="euiTreeView__iconWrapper emotion-euiTreeView__iconWrapper-default"
>
<span
data-euiicon-type="folderOpen"
/>
</span>
<span
class="euiTreeView__nodeLabel"
class="euiTreeView__nodeLabel eui-textTruncate"
>
Item One
</span>
</button>
<div
id="euiTreeView_generated-id_item_one"
>
<div
class="euiText euiTreeView__wrapper emotion-euiText-m"
<ul
class="euiTreeView emotion-euiTreeView-default"
role="list"
>
<ul
aria-label="Item One child of aria-label"
class="euiTreeView"
<li
class="euiTreeView__node emotion-euiTreeView__node-default"
>
<li
class="euiTreeView__node"
<button
class="euiTreeView__nodeInner emotion-euiTreeView__nodeInner-default"
data-test-subj="euiTreeViewButton-euiTreeView_generated-id"
id="item_a"
>
<button
aria-controls="euiTreeView_generated-id_item_a"
aria-expanded="false"
class="euiTreeView__nodeInner"
data-test-subj="euiTreeViewButton-euiTreeView_generated-id"
id="item_a"
<span
class="euiTreeView__iconWrapper emotion-euiTreeView__iconWrapper-default"
>
<span
class="euiTreeView__iconWrapper"
>
<span
data-euiicon-type="document"
/>
</span>
<span
class="euiTreeView__nodeLabel"
>
Item A
</span>
</button>
<div
id="euiTreeView_generated-id_item_a"
/>
</li>
<li
class="euiTreeView__node"
data-euiicon-type="document"
/>
</span>
<span
class="euiTreeView__nodeLabel eui-textTruncate"
>
Item A
</span>
</button>
</li>
<li
class="euiTreeView__node emotion-euiTreeView__node-default"
>
<button
aria-controls="euiTreeView_generated-id_item_b"
aria-expanded="false"
class="euiTreeView__nodeInner emotion-euiTreeView__nodeInner-default"
data-test-subj="euiTreeViewButton-euiTreeView_generated-id"
id="item_b"
>
<button
aria-controls="euiTreeView_generated-id_item_b"
aria-expanded="false"
class="euiTreeView__nodeInner"
data-test-subj="euiTreeViewButton-euiTreeView_generated-id"
id="item_b"
<span
class="euiTreeView__iconWrapper emotion-euiTreeView__iconWrapper-default"
>
<span
class="euiTreeView__iconWrapper"
>
<span
data-euiicon-type="arrowRight"
/>
</span>
<span
class="euiTreeView__nodeLabel"
>
Item B
</span>
</button>
<div
id="euiTreeView_generated-id_item_b"
/>
</li>
<li
class="euiTreeView__node"
data-euiicon-type="arrowRight"
/>
</span>
<span
class="euiTreeView__nodeLabel eui-textTruncate"
>
Item B
</span>
</button>
<div
id="euiTreeView_generated-id_item_b"
/>
</li>
<li
class="euiTreeView__node emotion-euiTreeView__node-default"
>
<button
aria-controls="euiTreeView_generated-id_item_c"
aria-expanded="false"
class="euiTreeView__nodeInner emotion-euiTreeView__nodeInner-default"
data-test-subj="euiTreeViewButton-euiTreeView_generated-id"
id="item_c"
>
<button
aria-controls="euiTreeView_generated-id_item_c"
aria-expanded="false"
class="euiTreeView__nodeInner"
data-test-subj="euiTreeViewButton-euiTreeView_generated-id"
id="item_c"
<span
class="euiTreeView__iconWrapper emotion-euiTreeView__iconWrapper-default"
>
<span
class="euiTreeView__iconWrapper"
>
<span
data-euiicon-type="arrowRight"
/>
</span>
<span
class="euiTreeView__nodeLabel"
>
Item C
</span>
</button>
<div
id="euiTreeView_generated-id_item_c"
/>
</li>
</ul>
</div>
data-euiicon-type="arrowRight"
/>
</span>
<span
class="euiTreeView__nodeLabel eui-textTruncate"
>
Item C
</span>
</button>
<div
id="euiTreeView_generated-id_item_c"
/>
</li>
</ul>
</div>
</li>
<li
class="euiTreeView__node"
class="euiTreeView__node emotion-euiTreeView__node-default"
>
<button
aria-controls="euiTreeView_generated-id_item_two"
aria-expanded="false"
class="euiTreeView__nodeInner"
class="euiTreeView__nodeInner emotion-euiTreeView__nodeInner-default"
data-test-subj="euiTreeViewButton-euiTreeView_generated-id"
id="item_two"
>
<span
class="euiTreeView__nodeLabel"
class="euiTreeView__nodeLabel eui-textTruncate"
>
Item Two
</span>
</button>
<div
id="euiTreeView_generated-id_item_two"
/>
</li>
</ul>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/tree_view/_index.scss

This file was deleted.

102 changes: 102 additions & 0 deletions src/components/tree_view/_tree_view_item.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* 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, transparentize } from '../../services';
import { euiFocusRing, logicalCSS, mathWithUnits } from '../../global_styling';

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

const defaultSize = euiTheme.size.xl;
const compressedSize = euiTheme.size.l;

return {
li: {
euiTreeView__node: css``,
default: css`
${logicalCSS('max-height', defaultSize)}
line-height: ${defaultSize};
`,
compressed: css`
${logicalCSS('max-height', compressedSize)}
line-height: ${compressedSize};
`,
expanded: css`
${logicalCSS('max-height', '100vh')}
`,
},

button: {
euiTreeView__nodeInner: css`
${logicalCSS('width', '100%')}
${logicalCSS('padding-left', euiTheme.size.s)}
${logicalCSS('padding-right', euiTheme.size.xxs)}
display: flex;
align-items: center;
&:focus {
${euiFocusRing(euiThemeContext, 'inset')}
}
&:hover,
&:active,
&:focus {
background-color: ${transparentize(
euiTheme.colors.text,
euiTheme.focus.transparency
)};
}
`,
default: css`
${logicalCSS('height', defaultSize)}
gap: ${euiTheme.size.s};
border-radius: ${euiTheme.border.radius.medium};
`,
compressed: css`
${logicalCSS('height', compressedSize)}
gap: ${euiTheme.size.xs};
border-radius: ${euiTheme.border.radius.small};
`,
},

icon: {
euiTreeView__iconWrapper: css`
flex-shrink: 0;
line-height: 0; /* Vertically centers the icon */
/* Handle smaller icons in compressed mode */
& > * {
${logicalCSS('max-width', '100%')}
}
& > .euiToken {
${logicalCSS('max-height', '100%')}
${logicalCSS('height', 'auto')}
svg {
${logicalCSS('width', '100%')}
}
}
`,
default: css`
${logicalCSS(
'width',
mathWithUnits(defaultSize, (x) => x / 2)
)}
`,
compressed: css`
${logicalCSS(
'width',
mathWithUnits(compressedSize, (x) => x / 2)
)}
`,
},
};
};
Loading

0 comments on commit 4584d91

Please sign in to comment.