Skip to content

Commit

Permalink
Migrate TableHeader component
Browse files Browse the repository at this point in the history
  • Loading branch information
scottybollinger committed Aug 26, 2020
1 parent 0184ae7 commit d51dec7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 { TableHeader } from './table_header';
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { EuiTableHeader, EuiTableHeaderCell } from '@elastic/eui';

import { TableHeader } from './table_header';

const headerItems = ['foo', 'bar', 'baz'];

describe('TableHeader', () => {
it('renders', () => {
const wrapper = shallow(<TableHeader headerItems={headerItems} />);

expect(wrapper.find(EuiTableHeader)).toHaveLength(1);
expect(wrapper.find(EuiTableHeaderCell)).toHaveLength(3);
});

it('renders extra cell', () => {
const wrapper = shallow(<TableHeader headerItems={headerItems} extraCell />);

expect(wrapper.find(EuiTableHeader)).toHaveLength(1);
expect(wrapper.find(EuiTableHeaderCell)).toHaveLength(4);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { EuiTableHeader, EuiTableHeaderCell } from '@elastic/eui';

interface ITableHeaderProps {
headerItems: string[];
extraCell?: boolean;
}

export const TableHeader: React.FC<ITableHeaderProps> = ({ headerItems, extraCell }) => (
<EuiTableHeader>
{headerItems.map((item, i) => (
<EuiTableHeaderCell key={i}>{item}</EuiTableHeaderCell>
))}
{extraCell && <EuiTableHeaderCell />}
</EuiTableHeader>
);

0 comments on commit d51dec7

Please sign in to comment.