From 401eac875f3ac04488db0b072711fc100b9204b6 Mon Sep 17 00:00:00 2001
From: Constance Chen
Date: Wed, 14 Jun 2023 14:17:03 -0700
Subject: [PATCH 01/11] [Setup] Clean up and DRY out shared button sizes
- Remove `useEuiButtonRadiusCSS` in favor of a more agnostic `euiButtonSizeMap` - using the raw data is less strict and generates fewer classNames
- `EuiButtonIcon` will shortly need the height/radius map and does not need to use all of `EuiButtonDisplay`'s logic (e.g. doesn't need fullWidth, or a content/text wrapper)
- Move `_buttonSize` to internal fn to make it unexportable / clearer that its CSS is specific to `EuiButtonDisplay`
---
.../button/__snapshots__/button.test.tsx.snap | 54 +++---
.../_button_display.test.tsx.snap | 2 +-
.../button_display/_button_display.styles.ts | 27 +--
.../button/button_display/_button_display.tsx | 3 -
.../__snapshots__/button_group.test.tsx.snap | 168 +++++++++---------
.../amsterdam/global_styling/mixins/button.ts | 42 ++---
6 files changed, 150 insertions(+), 146 deletions(-)
diff --git a/src/components/button/__snapshots__/button.test.tsx.snap b/src/components/button/__snapshots__/button.test.tsx.snap
index 89fa202379a..a843fdb478e 100644
--- a/src/components/button/__snapshots__/button.test.tsx.snap
+++ b/src/components/button/__snapshots__/button.test.tsx.snap
@@ -3,7 +3,7 @@
exports[`EuiButton is rendered 1`] = `
@@ -131,7 +131,7 @@ Array [
@@ -185,7 +185,7 @@ Array [
@@ -235,7 +235,7 @@ Array [
@@ -312,7 +312,7 @@ Array [
@@ -394,7 +394,7 @@ Array [
diff --git a/src/components/collapsible_nav/collapsible_nav_group/__snapshots__/collapsible_nav_group.test.tsx.snap b/src/components/collapsible_nav/collapsible_nav_group/__snapshots__/collapsible_nav_group.test.tsx.snap
index e489a2eb575..b4e3496cf35 100644
--- a/src/components/collapsible_nav/collapsible_nav_group/__snapshots__/collapsible_nav_group.test.tsx.snap
+++ b/src/components/collapsible_nav/collapsible_nav_group/__snapshots__/collapsible_nav_group.test.tsx.snap
@@ -237,7 +237,7 @@ exports[`EuiCollapsibleNavGroup when isCollapsible is true accepts accordion pro
aria-controls="id"
aria-expanded="false"
aria-labelledby="generated-id"
- class="euiButtonIcon euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton--right emotion-euiButtonIcon-empty-text-hoverStyles-euiAccordion__iconButton-arrowRight"
+ class="euiButtonIcon euiAccordion__iconButton euiAccordion__iconButton--right emotion-euiButtonIcon-xs-empty-text-euiAccordion__iconButton-arrowRight"
tabindex="-1"
type="button"
>
@@ -302,7 +302,7 @@ exports[`EuiCollapsibleNavGroup when isCollapsible is true will render an accord
aria-controls="id"
aria-expanded="false"
aria-labelledby="generated-id"
- class="euiButtonIcon euiButtonIcon--xSmall euiAccordion__iconButton euiAccordion__iconButton--right emotion-euiButtonIcon-empty-text-hoverStyles-euiAccordion__iconButton-arrowRight"
+ class="euiButtonIcon euiAccordion__iconButton euiAccordion__iconButton--right emotion-euiButtonIcon-xs-empty-text-euiAccordion__iconButton-arrowRight"
tabindex="-1"
type="button"
>
diff --git a/src/components/control_bar/__snapshots__/control_bar.test.tsx.snap b/src/components/control_bar/__snapshots__/control_bar.test.tsx.snap
index 9fc05d0f7eb..36ffd4e89c3 100644
--- a/src/components/control_bar/__snapshots__/control_bar.test.tsx.snap
+++ b/src/components/control_bar/__snapshots__/control_bar.test.tsx.snap
@@ -47,7 +47,7 @@ Array [
@@ -143,7 +143,7 @@ Array [
@@ -239,7 +239,7 @@ Array [
@@ -335,7 +335,7 @@ Array [
@@ -430,7 +430,7 @@ exports[`EuiControlBar props position is rendered 1`] = `
@@ -519,7 +519,7 @@ Array [
@@ -615,7 +615,7 @@ Array [
@@ -716,7 +716,7 @@ Array [
diff --git a/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap b/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
index 0e0ce8c2819..b60ebc84bf3 100644
--- a/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
+++ b/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
@@ -54,7 +54,7 @@ exports[`EuiDataGrid pagination renders 1`] = `
@@ -550,7 +550,7 @@ Array [
>
@@ -569,7 +569,7 @@ Array [
>
@@ -996,7 +996,7 @@ Array [
>
@@ -1022,7 +1022,7 @@ Array [
>
@@ -1041,7 +1041,7 @@ Array [
>
@@ -1785,7 +1785,7 @@ Array [
>
@@ -1811,7 +1811,7 @@ Array [
>
@@ -1830,7 +1830,7 @@ Array [
>
@@ -2256,7 +2256,7 @@ Array [
>
@@ -2282,7 +2282,7 @@ Array [
>
@@ -2301,7 +2301,7 @@ Array [
>
diff --git a/src/components/datagrid/controls/__snapshots__/column_sorting.test.tsx.snap b/src/components/datagrid/controls/__snapshots__/column_sorting.test.tsx.snap
index c3b33ace12d..e4312a0d7c1 100644
--- a/src/components/datagrid/controls/__snapshots__/column_sorting.test.tsx.snap
+++ b/src/components/datagrid/controls/__snapshots__/column_sorting.test.tsx.snap
@@ -91,7 +91,7 @@ exports[`useDataGridColumnSorting columnSorting renders a toolbar button/popover
>
@@ -195,7 +195,7 @@ exports[`EuiPinnableListGroup is rendered 1`] = `
@@ -222,7 +222,7 @@ exports[`EuiPinnableListGroup is rendered 1`] = `
@@ -278,7 +278,7 @@ exports[`EuiPinnableListGroup is rendered 1`] = `
@@ -307,7 +307,7 @@ exports[`EuiPinnableListGroup is rendered 1`] = `
diff --git a/src/components/markdown_editor/__snapshots__/markdown_editor.test.tsx.snap b/src/components/markdown_editor/__snapshots__/markdown_editor.test.tsx.snap
index 286ba8b3cb8..16b2ce3d6df 100644
--- a/src/components/markdown_editor/__snapshots__/markdown_editor.test.tsx.snap
+++ b/src/components/markdown_editor/__snapshots__/markdown_editor.test.tsx.snap
@@ -17,7 +17,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -34,7 +34,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -54,7 +54,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -71,7 +71,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -88,7 +88,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -108,7 +108,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -125,7 +125,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -142,7 +142,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -204,7 +204,7 @@ exports[`EuiMarkdownEditor custom plugins are excluded and popover is rendered 1
>
@@ -247,7 +247,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -264,7 +264,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -284,7 +284,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -301,7 +301,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -318,7 +318,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -338,7 +338,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -355,7 +355,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -372,7 +372,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -392,7 +392,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -453,7 +453,7 @@ exports[`EuiMarkdownEditor is rendered 1`] = `
>
@@ -511,7 +511,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -531,7 +531,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -548,7 +548,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -565,7 +565,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -585,7 +585,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -602,7 +602,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -619,7 +619,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -639,7 +639,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -699,7 +699,7 @@ exports[`EuiMarkdownEditor props autoExpandPreview is rendered with false 1`] =
>
@@ -757,7 +757,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -777,7 +777,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -794,7 +794,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -811,7 +811,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -831,7 +831,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -848,7 +848,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -865,7 +865,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -885,7 +885,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -945,7 +945,7 @@ exports[`EuiMarkdownEditor props height is rendered in full mode 1`] = `
>
@@ -1003,7 +1003,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1023,7 +1023,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1040,7 +1040,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1057,7 +1057,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1077,7 +1077,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1094,7 +1094,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1111,7 +1111,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1131,7 +1131,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1191,7 +1191,7 @@ exports[`EuiMarkdownEditor props height is rendered with a custom size 1`] = `
>
@@ -1249,7 +1249,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
@@ -1269,7 +1269,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
@@ -1286,7 +1286,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
@@ -1303,7 +1303,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
@@ -1323,7 +1323,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
@@ -1340,7 +1340,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
@@ -1357,7 +1357,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
@@ -1377,7 +1377,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
@@ -1437,7 +1437,7 @@ exports[`EuiMarkdownEditor props maxHeight is rendered with a custom size 1`] =
>
diff --git a/src/components/modal/__snapshots__/confirm_modal.test.tsx.snap b/src/components/modal/__snapshots__/confirm_modal.test.tsx.snap
index ab79a4d4291..ccbb045a822 100644
--- a/src/components/modal/__snapshots__/confirm_modal.test.tsx.snap
+++ b/src/components/modal/__snapshots__/confirm_modal.test.tsx.snap
@@ -18,7 +18,7 @@ Array [
>
@@ -116,7 +116,7 @@ Array [
>
diff --git a/src/components/modal/__snapshots__/modal.test.tsx.snap b/src/components/modal/__snapshots__/modal.test.tsx.snap
index c992006b697..60d6975e09c 100644
--- a/src/components/modal/__snapshots__/modal.test.tsx.snap
+++ b/src/components/modal/__snapshots__/modal.test.tsx.snap
@@ -24,7 +24,7 @@ exports[`EuiModal renders 1`] = `
>
@@ -92,7 +92,7 @@ exports[`EuiGlobalToastList props side can be changed to left 1`] = `
@@ -148,7 +148,7 @@ exports[`EuiGlobalToastList props toasts is rendered 1`] = `
@@ -195,7 +195,7 @@ exports[`EuiGlobalToastList props toasts is rendered 1`] = `
From 30a415c522331cef3ec22b4136b3db4afc4bce80 Mon Sep 17 00:00:00 2001
From: Constance Chen
Date: Tue, 20 Jun 2023 20:54:47 -0700
Subject: [PATCH 11/11] Fix Storybook icon loading
- preload all icons into the cache at once in the preview
- this increases Storybook's startup time somewhat significantly, but will probably be necessary until we resolve dynamic icons for SSR/Vite
---
.storybook/preview.tsx | 18 ++++++++++++++++++
.../button/button_icon/button_icon.stories.tsx | 10 +---------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx
index d54403c31ff..23d20226efc 100644
--- a/.storybook/preview.tsx
+++ b/.storybook/preview.tsx
@@ -11,6 +11,24 @@
import React from 'react';
import type { Preview } from '@storybook/react';
+/*
+ * Preload all EuiIcons - Storybook does not support dynamic icon loading
+ * TODO: https://github.com/elastic/eui/issues/5463
+ */
+import { typeToPathMap } from '../src/components/icon/icon_map';
+import { appendIconComponentCache } from '../src/components/icon/icon';
+const iconCache: Record = {};
+
+Object.entries(typeToPathMap).forEach(async ([iconType, iconFileName]) => {
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
+ const iconExport = require(`../src/components/icon/assets/${iconFileName}`);
+ iconCache[iconType] = iconExport.icon;
+});
+appendIconComponentCache(iconCache);
+
+/*
+ * Theming
+ */
import { EuiProvider } from '../src/components/provider';
import { writingModeStyles } from './writing_mode.styles';
diff --git a/src/components/button/button_icon/button_icon.stories.tsx b/src/components/button/button_icon/button_icon.stories.tsx
index 8e60019d6d0..29d2e49cf62 100644
--- a/src/components/button/button_icon/button_icon.stories.tsx
+++ b/src/components/button/button_icon/button_icon.stories.tsx
@@ -8,19 +8,11 @@
import type { Meta, StoryObj } from '@storybook/react';
-import { icon } from '../../icon/assets/face_happy'; // TODO: Remove this once icons can be loaded by strings
import { EuiButtonIcon, EuiButtonIconProps } from './button_icon';
const meta: Meta = {
title: 'EuiButtonIcon',
component: EuiButtonIcon,
- argTypes: {
- iconType: {
- // TODO: Storybook can't load icons dynamically
- // Disable user `iconType` input/controls for now
- control: 'function',
- },
- },
};
export default meta;
@@ -28,7 +20,7 @@ type Story = StoryObj;
export const Playground: Story = {
args: {
- iconType: icon, // TODO: Storybook can't load icons dynamically
+ iconType: 'faceHappy',
color: 'primary',
display: 'empty',
size: 'xs',