Skip to content

Commit d846ece

Browse files
rshen91maksimkovalev
authored andcommitted
[shared-ux] Migrate solution toolbar quick group buttons as icon button group component (elastic#126297)
1 parent 53bedbe commit d846ece

15 files changed

+503
-31
lines changed

src/plugins/shared_ux/public/components/index.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export const LazyExitFullScreenButton = React.lazy(() =>
1919
}))
2020
);
2121

22-
export const LazySolutionToolbarButton = React.lazy(() =>
23-
import('./toolbar/index').then(({ SolutionToolbarButton }) => ({
24-
default: SolutionToolbarButton,
22+
export const LazyToolbarButton = React.lazy(() =>
23+
import('./toolbar/index').then(({ ToolbarButton }) => ({
24+
default: ToolbarButton,
2525
}))
2626
);
2727

@@ -35,11 +35,11 @@ export const RedirectAppLinks = React.lazy(() => import('./redirect_app_links'))
3535
export const ExitFullScreenButton = withSuspense(LazyExitFullScreenButton);
3636

3737
/**
38-
* A `SolutionToolbarButton` component that is wrapped by the `withSuspense` HOC. This component can
39-
* be used directly by consumers and will load the `LazySolutionToolbarButton` component lazily with
38+
* A `ToolbarButton` component that is wrapped by the `withSuspense` HOC. This component can
39+
* be used directly by consumers and will load the `LazyToolbarButton` component lazily with
4040
* a predefined fallback and error boundary.
4141
*/
42-
export const SolutionToolbarButton = withSuspense(LazySolutionToolbarButton);
42+
export const ToolbarButton = withSuspense(LazyToolbarButton);
4343

4444
/**
4545
* The Lazily-loaded `NoDataViews` component. Consumers should use `React.Suspennse` or the
@@ -57,3 +57,18 @@ export const LazyNoDataViewsPage = React.lazy(() =>
5757
* a predefined fallback and error boundary.
5858
*/
5959
export const NoDataViewsPage = withSuspense(LazyNoDataViewsPage);
60+
61+
/**
62+
* The Lazily-loaded `IconButtonGroup` component. Consumers should use `React.Suspennse` or the
63+
* `withSuspense` HOC to load this component.
64+
*/
65+
export const LazyIconButtonGroup = React.lazy(() =>
66+
import('./toolbar/index').then(({ IconButtonGroup }) => ({
67+
default: IconButtonGroup,
68+
}))
69+
);
70+
71+
/**
72+
* The IconButtonGroup component that is wrapped by the `withSuspence` HOC.
73+
*/
74+
export const IconButtonGroup = withSuspense(LazyIconButtonGroup);

src/plugins/shared_ux/public/components/toolbar/buttons/icon_button_group/__snapshots__/icon_button_group.test.tsx.snap

+216
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
id: sharedUX/Components/Toolbar/Icon_Button_Group
3+
slug: /shared-ux/components/toolbar/icon_button_group
4+
title: Toolbar Icon Button Group
5+
summary: 'An array of icon-only buttons for use in a toolbar'
6+
tags: ['shared-ux', 'component']
7+
date: 2022-02-23
8+
---
9+
10+
> This documentation is in-progress.
11+
12+
This component requires a prop that consists of a series of buttons that can then be displayed based on the number of buttons desired. An example of a button that can be part of an array of icon buttons is included below:
13+
14+
```
15+
{
16+
label: 'Text',
17+
onClick: clickHandler,
18+
iconType: 'visText',
19+
}
20+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { action } from '@storybook/addon-actions';
10+
import { Story } from '@storybook/react';
11+
import React from 'react';
12+
import { IconButtonGroup } from './icon_button_group';
13+
import mdx from './icon_button_group.mdx';
14+
15+
export default {
16+
title: 'Toolbar/Icon Button Group',
17+
description: 'A collection of buttons that is a part of a toolbar.',
18+
parameters: {
19+
docs: {
20+
page: mdx,
21+
},
22+
},
23+
};
24+
25+
const quickButtons = [
26+
{
27+
label: 'Text',
28+
onClick: action('onTextClick'),
29+
iconType: 'visText',
30+
title: 'Text as markdown',
31+
},
32+
{
33+
label: 'Control',
34+
onClick: action('onControlClick'),
35+
iconType: 'controlsHorizontal',
36+
},
37+
{
38+
label: 'Link',
39+
onClick: action('onLinkClick'),
40+
iconType: 'link',
41+
},
42+
{
43+
label: 'Image',
44+
onClick: action('onImageClick'),
45+
iconType: 'image',
46+
},
47+
{
48+
label: 'Markup',
49+
onClick: action('onMarkupClick'),
50+
iconType: 'visVega',
51+
},
52+
];
53+
54+
export const ConnectedComponent: Story<{ buttonCount: number }> = ({ buttonCount }) => {
55+
return (
56+
<IconButtonGroup legend="Example icon group" buttons={quickButtons.slice(0, buttonCount)} />
57+
);
58+
};
59+
60+
ConnectedComponent.argTypes = {
61+
buttonCount: {
62+
defaultValue: 2,
63+
control: {
64+
type: 'number',
65+
min: 1,
66+
max: 5,
67+
step: 1,
68+
},
69+
},
70+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { UseEuiTheme } from '@elastic/eui';
10+
11+
export const IconButtonGroupStyles = ({ euiTheme }: UseEuiTheme) => {
12+
return {
13+
button: {
14+
'&.euiButtonGroupButton': {
15+
backgroundColor: euiTheme.colors.emptyShade,
16+
border: `${euiTheme.border.thin} !important`,
17+
'&:first-of-type': {
18+
borderTopLeftRadius: `${euiTheme.border.radius.medium} !important`,
19+
borderBottomLeftRadius: `${euiTheme.border.radius.medium} !important`,
20+
},
21+
'&:last-of-type': {
22+
borderTopRightRadius: `${euiTheme.border.radius.medium} !important`,
23+
borderBottomRightRadius: `${euiTheme.border.radius.medium} !important`,
24+
},
25+
},
26+
},
27+
};
28+
};

0 commit comments

Comments
 (0)