Skip to content

Commit 9c3c323

Browse files
authored
[shared-ux] Migrate solution toolbar button (#125998)
1 parent f2150eb commit 9c3c323

File tree

7 files changed

+217
-0
lines changed

7 files changed

+217
-0
lines changed

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

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

22+
export const LazySolutionToolbarButton = React.lazy(() =>
23+
import('./toolbar/index').then(({ SolutionToolbarButton }) => ({
24+
default: SolutionToolbarButton,
25+
}))
26+
);
27+
2228
/**
2329
* A `ExitFullScreenButton` component that is wrapped by the `withSuspense` HOC. This component can
2430
* be used directly by consumers and will load the `LazyExitFullScreenButton` component lazily with
2531
* a predefined fallback and error boundary.
2632
*/
2733
export const ExitFullScreenButton = withSuspense(LazyExitFullScreenButton);
2834

35+
/**
36+
* A `SolutionToolbarButton` component that is wrapped by the `withSuspense` HOC. This component can
37+
* be used directly by consumers and will load the `LazySolutionToolbarButton` component lazily with
38+
* a predefined fallback and error boundary.
39+
*/
40+
export const SolutionToolbarButton = withSuspense(LazySolutionToolbarButton);
41+
2942
/**
3043
* The Lazily-loaded `NoDataViews` component. Consumers should use `React.Suspennse` or the
3144
* `withSuspense` HOC to load this component.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
export { SolutionToolbarButton } from './solution_toolbar/button/primary';

src/plugins/shared_ux/public/components/toolbar/solution_toolbar/button/__snapshots__/primary.test.tsx.snap

+78
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,12 @@
1+
---
2+
id: sharedUX/Components/SolutionToolbarButton
3+
slug: /shared-ux/components/toolbar/solution_toolbar/button/primary
4+
title: Solution Toolbar Button
5+
summary: An opinionated implementation of the toolbar extracted to just the button.
6+
tags: ['shared-ux', 'component']
7+
date: 2022-02-17
8+
---
9+
10+
> This documentation is in-progress.
11+
12+
This button is a part of the solution toolbar component. This button has primary styling and requires a label. OnClick handlers and icon types are supported as an extension of EuiButtonProps. Icons are always on the left of any labels within the button.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 { Story } from '@storybook/react';
10+
import React from 'react';
11+
import { SolutionToolbarButton } from './primary';
12+
import mdx from './primary.mdx';
13+
14+
export default {
15+
title: 'Solution Toolbar Button',
16+
description: 'A button that is a part of the solution toolbar.',
17+
parameters: {
18+
docs: {
19+
page: mdx,
20+
},
21+
},
22+
argTypes: {
23+
iconType: {
24+
control: {
25+
type: 'radio',
26+
expanded: true,
27+
options: ['apps', 'logoGithub', 'folderCheck', 'documents'],
28+
},
29+
},
30+
},
31+
};
32+
33+
export const Component: Story<{
34+
iconType: any;
35+
}> = ({ iconType }) => {
36+
return <SolutionToolbarButton label={'Primary Action'} iconType={iconType} />;
37+
};
38+
39+
Component.args = {
40+
iconType: 'apps',
41+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 { mount as enzymeMount, ReactWrapper } from 'enzyme';
10+
import React from 'react';
11+
import { ServicesProvider, SharedUXServices } from '../../../../services';
12+
import { servicesFactory } from '../../../../services/mocks';
13+
14+
import { SolutionToolbarButton } from './primary';
15+
16+
describe('<SolutionToolbarButton />', () => {
17+
let services: SharedUXServices;
18+
let mount: (element: JSX.Element) => ReactWrapper;
19+
20+
beforeEach(() => {
21+
services = servicesFactory();
22+
mount = (element: JSX.Element) =>
23+
enzymeMount(<ServicesProvider {...services}>{element}</ServicesProvider>);
24+
});
25+
26+
afterEach(() => {
27+
jest.resetAllMocks();
28+
});
29+
30+
test('is rendered', () => {
31+
const component = mount(<SolutionToolbarButton label="test" />);
32+
33+
expect(component).toMatchSnapshot();
34+
});
35+
test('it can be passed a functional onClick handler', () => {
36+
const mockHandler = jest.fn();
37+
const component = mount(<SolutionToolbarButton label="withOnClick" onClick={mockHandler} />);
38+
component.simulate('click');
39+
expect(mockHandler).toHaveBeenCalled();
40+
});
41+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 React from 'react';
10+
import { EuiButton } from '@elastic/eui';
11+
import { EuiButtonPropsForButton } from '@elastic/eui/src/components/button/button';
12+
13+
export interface Props extends Pick<EuiButtonPropsForButton, 'onClick' | 'iconType'> {
14+
label: string;
15+
}
16+
17+
export const SolutionToolbarButton = ({ label, ...rest }: Props) => {
18+
return (
19+
<EuiButton size="m" color="primary" fill={true} {...rest}>
20+
{label}
21+
</EuiButton>
22+
);
23+
};

0 commit comments

Comments
 (0)