= ({
+ children,
+ className,
+ checkableType = 'radio',
+ label,
+ checked,
+ disabled,
+ ...rest
+}) => {
+ const { id } = rest;
+ const classes = classNames(
+ 'euiCheckableCard',
+ {
+ 'euiCheckableCard-isChecked': checked,
+ 'euiCheckableCard-isDisabled': disabled,
+ },
+ className
+ );
+
+ let checkableElement;
+ if (checkableType === 'radio') {
+ checkableElement = (
+
+ );
+ } else {
+ checkableElement = (
+
+ );
+ }
+
+ const labelClasses = classNames('euiCheckableCard__label', {
+ 'euiCheckableCard__label-isDisabled': disabled,
+ });
+
+ return (
+
+
+
{checkableElement}
+
+
+ {children && (
+
+ {/* Empty div for left side background color only */}
+
+
+ {children}
+
+
+ )}
+
+ );
+};
diff --git a/src/components/card/checkable_card/index.ts b/src/components/card/checkable_card/index.ts
new file mode 100644
index 00000000000..53fa42d59c3
--- /dev/null
+++ b/src/components/card/checkable_card/index.ts
@@ -0,0 +1 @@
+export { EuiCheckableCard, EuiCheckableCardProps } from './checkable_card';
diff --git a/src/components/card/index.ts b/src/components/card/index.ts
index 679ef81085d..3556951adfb 100644
--- a/src/components/card/index.ts
+++ b/src/components/card/index.ts
@@ -1 +1,2 @@
export { EuiCard } from './card';
+export { EuiCheckableCard } from './checkable_card';
diff --git a/src/components/form/checkbox/__snapshots__/checkbox.test.js.snap b/src/components/form/checkbox/__snapshots__/checkbox.test.tsx.snap
similarity index 100%
rename from src/components/form/checkbox/__snapshots__/checkbox.test.js.snap
rename to src/components/form/checkbox/__snapshots__/checkbox.test.tsx.snap
diff --git a/src/components/form/checkbox/__snapshots__/checkbox_group.test.js.snap b/src/components/form/checkbox/__snapshots__/checkbox_group.test.tsx.snap
similarity index 100%
rename from src/components/form/checkbox/__snapshots__/checkbox_group.test.js.snap
rename to src/components/form/checkbox/__snapshots__/checkbox_group.test.tsx.snap
index 2e37e919b1c..9e898755868 100644
--- a/src/components/form/checkbox/__snapshots__/checkbox_group.test.js.snap
+++ b/src/components/form/checkbox/__snapshots__/checkbox_group.test.tsx.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`EuiCheckboxGroup (mocked checkbox) individual disabled is rendered 1`] = `
+exports[`EuiCheckboxGroup (mocked checkbox) disabled is rendered 1`] = `
`;
-exports[`EuiCheckboxGroup (mocked checkbox) disabled is rendered 1`] = `
+exports[`EuiCheckboxGroup (mocked checkbox) idToSelectedMap is rendered 1`] = `
`;
-exports[`EuiCheckboxGroup (mocked checkbox) idToSelectedMap is rendered 1`] = `
+exports[`EuiCheckboxGroup (mocked checkbox) individual disabled is rendered 1`] = `
diff --git a/src/components/form/checkbox/checkbox.test.js b/src/components/form/checkbox/checkbox.test.tsx
similarity index 85%
rename from src/components/form/checkbox/checkbox.test.js
rename to src/components/form/checkbox/checkbox.test.tsx
index 5f43bc2f8f2..fd802836ed3 100644
--- a/src/components/form/checkbox/checkbox.test.js
+++ b/src/components/form/checkbox/checkbox.test.tsx
@@ -26,16 +26,6 @@ describe('EuiCheckbox', () => {
});
describe('props', () => {
- test('id is required', () => {
- expect(() => (
- {}} />
- )).toThrow();
- });
-
- test('onChange is required', () => {
- expect(() => ).toThrow();
- });
-
test('check is rendered', () => {
const component = render(
diff --git a/src/components/form/checkbox/checkbox.js b/src/components/form/checkbox/checkbox.tsx
similarity index 56%
rename from src/components/form/checkbox/checkbox.js
rename to src/components/form/checkbox/checkbox.tsx
index ac4a67ea3a5..88d5e23515e 100644
--- a/src/components/form/checkbox/checkbox.js
+++ b/src/components/form/checkbox/checkbox.tsx
@@ -1,16 +1,48 @@
-import React, { Component } from 'react';
-import PropTypes from 'prop-types';
+import React, {
+ Component,
+ ChangeEventHandler,
+ ReactNode,
+ InputHTMLAttributes,
+} from 'react';
import classNames from 'classnames';
-import { omit } from '../../../services/objects';
+import { keysOf, CommonProps } from '../../common';
const typeToClassNameMap = {
inList: 'euiCheckbox--inList',
};
-export const TYPES = Object.keys(typeToClassNameMap);
+export const TYPES = keysOf(typeToClassNameMap);
+
+export type EuiCheckboxType = keyof typeof typeToClassNameMap;
+
+export interface EuiCheckboxProps
+ extends CommonProps,
+ InputHTMLAttributes {
+ id: string;
+ checked?: boolean;
+ onChange: ChangeEventHandler; // overriding to make it required
+ inputRef?: (element: HTMLInputElement) => void;
+ label?: ReactNode;
+ type?: EuiCheckboxType;
+ disabled?: boolean;
+ /**
+ * when `true` creates a shorter height checkbox row
+ */
+ compressed?: boolean;
+ indeterminate?: boolean;
+}
+
+export class EuiCheckbox extends Component {
+ static defaultProps = {
+ checked: false,
+ disabled: false,
+ indeterminate: false,
+ compressed: false,
+ };
+
+ inputRef?: HTMLInputElement = undefined;
-export class EuiCheckbox extends Component {
componentDidMount() {
this.invalidateIndeterminate();
}
@@ -32,11 +64,11 @@ export class EuiCheckbox extends Component {
...rest
} = this.props;
- const inputProps = omit(rest, 'indeterminate');
+ const { indeterminate, ...inputProps } = rest; // `indeterminate` is set dynamically later
const classes = classNames(
'euiCheckbox',
- typeToClassNameMap[type],
+ type && typeToClassNameMap[type],
{
'euiCheckbox--noLabel': !label,
'euiCheckbox--compressed': compressed,
@@ -74,7 +106,7 @@ export class EuiCheckbox extends Component {
);
}
- setInputRef = input => {
+ setInputRef = (input: HTMLInputElement) => {
this.inputRef = input;
if (this.props.inputRef) {
@@ -86,29 +118,7 @@ export class EuiCheckbox extends Component {
invalidateIndeterminate() {
if (this.inputRef) {
- this.inputRef.indeterminate = this.props.indeterminate;
+ this.inputRef.indeterminate = this.props.indeterminate!;
}
}
}
-
-EuiCheckbox.propTypes = {
- className: PropTypes.string,
- id: PropTypes.string.isRequired,
- checked: PropTypes.bool,
- label: PropTypes.node,
- onChange: PropTypes.func.isRequired,
- type: PropTypes.oneOf(TYPES),
- disabled: PropTypes.bool,
- indeterminate: PropTypes.bool,
- /**
- * when `true` creates a shorter height checkbox row
- */
- compressed: PropTypes.bool,
-};
-
-EuiCheckbox.defaultProps = {
- checked: false,
- disabled: false,
- indeterminate: false,
- compressed: false,
-};
diff --git a/src/components/form/checkbox/checkbox_group.behavior.test.js b/src/components/form/checkbox/checkbox_group.behavior.test.tsx
similarity index 82%
rename from src/components/form/checkbox/checkbox_group.behavior.test.js
rename to src/components/form/checkbox/checkbox_group.behavior.test.tsx
index 41f254bea8e..01959404094 100644
--- a/src/components/form/checkbox/checkbox_group.behavior.test.js
+++ b/src/components/form/checkbox/checkbox_group.behavior.test.tsx
@@ -1,6 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
-import sinon from 'sinon';
import { EuiCheckboxGroup } from './checkbox_group';
@@ -9,7 +8,7 @@ import { EuiCheckboxGroup } from './checkbox_group';
// an interaction that is handled by the Checkbox component.
describe('EuiCheckboxGroup behavior', () => {
test('id is bound to onChange', () => {
- const onChangeHandler = sinon.stub();
+ const onChangeHandler = jest.fn();
const component = mount(
{
);
component.find('input[type="checkbox"]').simulate('change');
- sinon.assert.calledWith(onChangeHandler, '1');
+ expect(onChangeHandler).toBeCalledTimes(1);
+ expect(onChangeHandler.mock.calls[0][0]).toBe('1');
});
});
diff --git a/src/components/form/checkbox/checkbox_group.test.js b/src/components/form/checkbox/checkbox_group.test.tsx
similarity index 82%
rename from src/components/form/checkbox/checkbox_group.test.js
rename to src/components/form/checkbox/checkbox_group.test.tsx
index 02afa8dc29c..c6ec2ccf051 100644
--- a/src/components/form/checkbox/checkbox_group.test.js
+++ b/src/components/form/checkbox/checkbox_group.test.tsx
@@ -6,10 +6,20 @@ import { EuiCheckboxGroup } from './checkbox_group';
jest.mock('./checkbox', () => ({ EuiCheckbox: 'eui_checkbox' }));
+const checkboxGroupRequiredProps = {
+ options: [],
+ idToSelectedMap: {},
+ onChange: () => {},
+};
+
describe('EuiCheckboxGroup (mocked checkbox)', () => {
test('is rendered', () => {
const component = render(
- {}} {...requiredProps} />
+ {}}
+ {...checkboxGroupRequiredProps}
+ {...requiredProps}
+ />
);
expect(component).toMatchSnapshot();
@@ -18,6 +28,7 @@ describe('EuiCheckboxGroup (mocked checkbox)', () => {
test('options are rendered', () => {
const component = render(
{}}
/>
@@ -29,6 +40,7 @@ describe('EuiCheckboxGroup (mocked checkbox)', () => {
test('idToSelectedMap is rendered', () => {
const component = render(
{
test('disabled is rendered', () => {
const component = render(
{
test('individual disabled is rendered', () => {
const component = render(
void;
+ /**
+ * Tightens up the spacing between checkbox rows and sends down the
+ * compressed prop to the checkbox itself
+ */
+ compressed?: boolean;
+ disabled?: boolean;
+}
+
+export const EuiCheckboxGroup: FunctionComponent = ({
+ options = [],
+ idToSelectedMap = {},
onChange,
className,
disabled,
@@ -29,25 +51,3 @@ export const EuiCheckboxGroup = ({
})}
);
-
-EuiCheckboxGroup.propTypes = {
- options: PropTypes.arrayOf(
- PropTypes.shape({
- id: PropTypes.string.isRequired,
- label: PropTypes.node,
- disabled: PropTypes.bool,
- })
- ).isRequired,
- idToSelectedMap: PropTypes.objectOf(PropTypes.bool).isRequired,
- onChange: PropTypes.func.isRequired,
- /**
- * Tightens up the spacing between checkbox rows and sends down the
- * compressed prop to the checkbox itself
- */
- compressed: PropTypes.bool,
-};
-
-EuiCheckboxGroup.defaultProps = {
- options: [],
- idToSelectedMap: {},
-};
diff --git a/src/components/form/checkbox/index.d.ts b/src/components/form/checkbox/index.d.ts
deleted file mode 100644
index c93499d5ed1..00000000000
--- a/src/components/form/checkbox/index.d.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { CommonProps } from '../../common';
-
-import {
- FunctionComponent,
- ReactNode,
- HTMLAttributes,
- ChangeEventHandler,
- InputHTMLAttributes,
-} from 'react';
-
-declare module '@elastic/eui' {
- /**
- * checkbox type defs
- *
- * @see './checkbox.js'
- */
-
- export type EuiCheckboxType = 'inList';
-
- export interface EuiCheckboxProps {
- id: string;
- checked?: boolean;
- onChange: ChangeEventHandler; // overriding to make it required
- label?: ReactNode;
- type?: EuiCheckboxType;
- disabled?: boolean;
- compressed?: boolean;
- indeterminate?: boolean;
- }
-
- export const EuiCheckbox: FunctionComponent<
- CommonProps & InputHTMLAttributes & EuiCheckboxProps
- >;
-
- /**
- * checkbox group type defs
- *
- * @see './checkbox_group.js'
- */
-
- export interface EuiCheckboxGroupOption {
- id: string;
- label?: ReactNode;
- disabled?: boolean;
- }
-
- export interface EuiCheckboxGroupIdToSelectedMap {
- [id: string]: boolean;
- }
-
- export interface EuiCheckboxGroupProps {
- options: EuiCheckboxGroupOption[];
- idToSelectedMap: EuiCheckboxGroupIdToSelectedMap;
- onChange: ChangeEventHandler;
- compressed?: boolean;
- disabled?: boolean;
- }
-
- export const EuiCheckboxGroup: FunctionComponent<
- CommonProps & HTMLAttributes & EuiCheckboxGroupProps
- >;
-}
diff --git a/src/components/form/checkbox/index.js b/src/components/form/checkbox/index.js
deleted file mode 100644
index dec0b16a0a2..00000000000
--- a/src/components/form/checkbox/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-export { EuiCheckbox } from './checkbox';
-export { EuiCheckboxGroup } from './checkbox_group';
diff --git a/src/components/form/checkbox/index.ts b/src/components/form/checkbox/index.ts
new file mode 100644
index 00000000000..7be49859685
--- /dev/null
+++ b/src/components/form/checkbox/index.ts
@@ -0,0 +1,2 @@
+export { EuiCheckbox, EuiCheckboxProps } from './checkbox';
+export { EuiCheckboxGroup, EuiCheckboxGroupProps } from './checkbox_group';
diff --git a/src/components/form/index.d.ts b/src/components/form/index.d.ts
index a707dbfd399..2d025407909 100644
--- a/src/components/form/index.d.ts
+++ b/src/components/form/index.d.ts
@@ -1,5 +1,4 @@
import { CommonProps } from '../common';
-///
///
///
///
diff --git a/src/components/form/radio/_radio_group.scss b/src/components/form/radio/_radio_group.scss
index 8630999fea0..89a3809bbc8 100644
--- a/src/components/form/radio/_radio_group.scss
+++ b/src/components/form/radio/_radio_group.scss
@@ -1,5 +1,5 @@
.euiRadioGroup__item + .euiRadioGroup__item {
- margin-top: $euiSizeS;
+ margin-top: $euiSizeXS;
&.euiRadio--compressed {
margin-top: 0;
diff --git a/src/components/index.js b/src/components/index.js
index 829ab8a0594..febbba31948 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -22,7 +22,7 @@ export {
export { EuiCallOut } from './call_out';
-export { EuiCard } from './card';
+export { EuiCard, EuiCheckableCard } from './card';
export { EuiCode, EuiCodeBlock, EuiCodeBlockImpl } from './code';