[Enterprise Search] Migrate shared ApiKey component (#82511)

This commit is contained in:
Scotty Bollinger 2020-11-04 08:24:10 -06:00 committed by GitHub
parent 64f50f8ff7
commit 5a9fc25dc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 0 deletions

View file

@ -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;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { shallow } from 'enzyme';
import { EuiCodeBlock, EuiFormLabel } from '@elastic/eui';
import { ApiKey } from './';
const key = '123abc';
const label = 'foo';
describe('ApiKey', () => {
it('renders', () => {
const wrapper = shallow(<ApiKey apiKey={key} />);
expect(wrapper.find(EuiCodeBlock)).toHaveLength(1);
expect(wrapper.find(EuiFormLabel)).toHaveLength(0);
expect(wrapper.find(EuiCodeBlock).prop('children')).toEqual(key);
});
it('renders label', () => {
const wrapper = shallow(<ApiKey apiKey={key} label={label} />);
expect(wrapper.find(EuiFormLabel)).toHaveLength(1);
expect(wrapper.find(EuiFormLabel).prop('children')).toEqual(label);
});
});

View file

@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { EuiCodeBlock, EuiFormLabel, EuiSpacer } from '@elastic/eui';
interface IApiKeyProps {
apiKey: string;
label?: string;
}
export const ApiKey: React.FC<IApiKeyProps> = ({ apiKey, label }) => (
<>
{label && (
<>
<EuiFormLabel>{label}</EuiFormLabel>
<EuiSpacer size="xs" />
</>
)}
<EuiCodeBlock language="bash" fontSize="m" paddingSize="m" color="dark" isCopyable>
{apiKey}
</EuiCodeBlock>
</>
);

View file

@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export { ApiKey } from './api_key';