Skip to content

Commit 7fac1ce

Browse files
authored
[EuiCheckbox][EuiRadio] Remove compressed props (#7818)
1 parent 1cabbd2 commit 7fac1ce

File tree

16 files changed

+135
-54
lines changed

16 files changed

+135
-54
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
**Breaking changes**
2+
3+
- Removed the unused `compressed` prop from `EuiCheckbox` and `EuiRadio`. This prop was not doing anything on individual components.
4+
5+
**CSS-in-JS conversions**
6+
7+
- Converted `EuiCheckboxGroup` to Emotion
8+
- Converted `EuiRadioGroup` to Emotion

packages/eui/src-docs/src/views/selection_controls/checkbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ export default () => {
5757

5858
<EuiCheckbox
5959
id={compressedCheckboxId}
60-
label="I am a compressed checkbox"
60+
label="I am a readonly checkbox"
6161
checked={checked}
6262
onChange={(e) => onChange(e)}
63-
compressed
63+
readOnly
6464
/>
6565
</Fragment>
6666
);

packages/eui/src/components/form/checkbox/__snapshots__/checkbox_group.test.tsx.snap

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`EuiCheckboxGroup (mocked checkbox) disabled is rendered 1`] = `
4-
<div>
4+
<div
5+
class="euiCheckboxGroup emotion-euiCheckboxGroup"
6+
>
57
<div
68
data-eui-checkbox=""
79
/>
@@ -12,7 +14,9 @@ exports[`EuiCheckboxGroup (mocked checkbox) disabled is rendered 1`] = `
1214
`;
1315

1416
exports[`EuiCheckboxGroup (mocked checkbox) idToSelectedMap is rendered 1`] = `
15-
<div>
17+
<div
18+
class="euiCheckboxGroup emotion-euiCheckboxGroup"
19+
>
1620
<div
1721
data-eui-checkbox=""
1822
/>
@@ -23,7 +27,9 @@ exports[`EuiCheckboxGroup (mocked checkbox) idToSelectedMap is rendered 1`] = `
2327
`;
2428

2529
exports[`EuiCheckboxGroup (mocked checkbox) individual disabled is rendered 1`] = `
26-
<div>
30+
<div
31+
class="euiCheckboxGroup emotion-euiCheckboxGroup"
32+
>
2733
<div
2834
data-eui-checkbox=""
2935
/>
@@ -36,13 +42,15 @@ exports[`EuiCheckboxGroup (mocked checkbox) individual disabled is rendered 1`]
3642
exports[`EuiCheckboxGroup (mocked checkbox) is rendered 1`] = `
3743
<div
3844
aria-label="aria-label"
39-
class="testClass1 testClass2 emotion-euiTestCss"
45+
class="euiCheckboxGroup testClass1 testClass2 emotion-euiCheckboxGroup-euiTestCss"
4046
data-test-subj="test subject string"
4147
/>
4248
`;
4349

4450
exports[`EuiCheckboxGroup (mocked checkbox) legend is rendered 1`] = `
45-
<fieldset>
51+
<fieldset
52+
class="euiCheckboxGroup emotion-euiCheckboxGroup"
53+
>
4654
<legend
4755
class="euiFormLegend"
4856
>
@@ -52,7 +60,9 @@ exports[`EuiCheckboxGroup (mocked checkbox) legend is rendered 1`] = `
5260
`;
5361

5462
exports[`EuiCheckboxGroup (mocked checkbox) options are rendered 1`] = `
55-
<div>
63+
<div
64+
class="euiCheckboxGroup emotion-euiCheckboxGroup"
65+
>
5666
<div
5767
data-eui-checkbox=""
5868
/>

packages/eui/src/components/form/checkbox/_checkbox_group.scss

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
@import 'checkbox';
2-
@import 'checkbox_group';

packages/eui/src/components/form/checkbox/checkbox.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const meta: Meta<EuiCheckboxProps> = {
1919
component: EuiCheckbox,
2020
args: {
2121
checked: false,
22-
compressed: false,
2322
disabled: false,
2423
indeterminate: false,
2524
// set up for easier testing/QA

packages/eui/src/components/form/checkbox/checkbox.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ export interface EuiCheckboxProps
3030
inputRef?: (element: HTMLInputElement) => void;
3131
label?: ReactNode;
3232
disabled?: boolean;
33-
/**
34-
* when `true` creates a shorter height checkbox row
35-
*/
36-
compressed?: boolean;
3733
indeterminate?: boolean;
3834
/**
3935
* Object of props passed to the <label/>
@@ -50,7 +46,6 @@ export const EuiCheckbox: FunctionComponent<EuiCheckboxProps> = ({
5046
onChange,
5147
type,
5248
disabled = false,
53-
compressed = false,
5449
indeterminate = false,
5550
inputRef,
5651
labelProps,
@@ -60,7 +55,6 @@ export const EuiCheckbox: FunctionComponent<EuiCheckboxProps> = ({
6055
'euiCheckbox',
6156
{
6257
'euiCheckbox--noLabel': !label,
63-
'euiCheckbox--compressed': compressed,
6458
},
6559
className
6660
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 { css } from '@emotion/react';
10+
11+
import { UseEuiTheme } from '../../../services';
12+
13+
export const euiCheckboxGroupStyles = ({ euiTheme }: UseEuiTheme) => ({
14+
euiCheckboxGroup: css`
15+
display: flex;
16+
flex-direction: column;
17+
`,
18+
// Skip css`` to avoid generating a className
19+
uncompressed: `
20+
gap: ${euiTheme.size.xs}
21+
`,
22+
compressed: css`
23+
gap: 0;
24+
`,
25+
});

packages/eui/src/components/form/checkbox/checkbox_group.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import React, { FunctionComponent, HTMLAttributes } from 'react';
1010
import classNames from 'classnames';
1111

12+
import { useEuiMemoizedStyles } from '../../../services';
1213
import { CommonProps, ExclusiveUnion } from '../../common';
1314

1415
import {
@@ -17,6 +18,7 @@ import {
1718
EuiFormFieldset,
1819
} from '../form_fieldset';
1920
import { EuiCheckbox, EuiCheckboxProps } from './checkbox';
21+
import { euiCheckboxGroupStyles } from './checkbox_group.styles';
2022

2123
export interface EuiCheckboxGroupOption
2224
extends Omit<EuiCheckboxProps, 'checked' | 'onChange'> {
@@ -43,10 +45,12 @@ export type EuiCheckboxGroupProps = CommonProps & {
4345
idToSelectedMap: EuiCheckboxGroupIdToSelectedMap;
4446
onChange: (optionId: string) => void;
4547
/**
46-
* Tightens up the spacing between checkbox rows and sends down the
47-
* compressed prop to the checkbox itself
48+
* Tightens up the spacing between checkbox rows
4849
*/
4950
compressed?: boolean;
51+
/**
52+
* Passed down to all child `EuiCheckbox`es
53+
*/
5054
disabled?: boolean;
5155
} & ExclusiveUnion<AsDivProps, WithLegendProps>;
5256

@@ -60,6 +64,14 @@ export const EuiCheckboxGroup: FunctionComponent<EuiCheckboxGroupProps> = ({
6064
legend,
6165
...rest
6266
}) => {
67+
const classes = classNames('euiCheckboxGroup', className);
68+
69+
const styles = useEuiMemoizedStyles(euiCheckboxGroupStyles);
70+
const cssStyles = [
71+
styles.euiCheckboxGroup,
72+
compressed ? styles.compressed : styles.uncompressed,
73+
];
74+
6375
const checkboxes = options.map((option, index) => {
6476
const {
6577
disabled: isOptionDisabled,
@@ -73,7 +85,6 @@ export const EuiCheckboxGroup: FunctionComponent<EuiCheckboxGroupProps> = ({
7385
checked={idToSelectedMap[option.id]}
7486
disabled={disabled || isOptionDisabled}
7587
onChange={onChange.bind(null, option.id)}
76-
compressed={compressed}
7788
{...optionRest}
7889
/>
7990
);
@@ -85,7 +96,8 @@ export const EuiCheckboxGroup: FunctionComponent<EuiCheckboxGroupProps> = ({
8596

8697
return (
8798
<EuiFormFieldset
88-
className={className}
99+
css={cssStyles}
100+
className={classes}
89101
legend={legend}
90102
{...(rest as EuiFormFieldsetProps)}
91103
>
@@ -95,7 +107,11 @@ export const EuiCheckboxGroup: FunctionComponent<EuiCheckboxGroupProps> = ({
95107
}
96108

97109
return (
98-
<div className={className} {...(rest as HTMLAttributes<HTMLDivElement>)}>
110+
<div
111+
css={cssStyles}
112+
className={classes}
113+
{...(rest as HTMLAttributes<HTMLDivElement>)}
114+
>
99115
{checkboxes}
100116
</div>
101117
);

packages/eui/src/components/form/radio/__snapshots__/radio_group.test.tsx.snap

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
exports[`EuiRadioGroup is rendered 1`] = `
44
<div
55
aria-label="aria-label"
6-
class="testClass1 testClass2 emotion-euiTestCss"
6+
class="euiRadioGroup testClass1 testClass2 emotion-euiRadioGroup-euiTestCss"
77
data-test-subj="test subject string"
88
/>
99
`;
1010

1111
exports[`EuiRadioGroup props idSelected is rendered 1`] = `
12-
<div>
12+
<div
13+
class="euiRadioGroup emotion-euiRadioGroup"
14+
>
1315
<div
1416
class="euiRadio euiRadioGroup__item"
1517
>
@@ -53,7 +55,9 @@ exports[`EuiRadioGroup props idSelected is rendered 1`] = `
5355
`;
5456

5557
exports[`EuiRadioGroup props legend is rendered 1`] = `
56-
<fieldset>
58+
<fieldset
59+
class="euiRadioGroup emotion-euiRadioGroup"
60+
>
5761
<legend
5862
class="euiFormLegend"
5963
>
@@ -101,7 +105,9 @@ exports[`EuiRadioGroup props legend is rendered 1`] = `
101105
`;
102106

103107
exports[`EuiRadioGroup props name is propagated to radios 1`] = `
104-
<div>
108+
<div
109+
class="euiRadioGroup emotion-euiRadioGroup"
110+
>
105111
<div
106112
class="euiRadio euiRadioGroup__item"
107113
>
@@ -146,7 +152,9 @@ exports[`EuiRadioGroup props name is propagated to radios 1`] = `
146152
`;
147153

148154
exports[`EuiRadioGroup props options are rendered 1`] = `
149-
<div>
155+
<div
156+
class="euiRadioGroup emotion-euiRadioGroup"
157+
>
150158
<div
151159
class="euiRadio euiRadioGroup__item"
152160
>
@@ -190,7 +198,9 @@ exports[`EuiRadioGroup props options are rendered 1`] = `
190198
`;
191199

192200
exports[`EuiRadioGroup props value is propagated to radios 1`] = `
193-
<div>
201+
<div
202+
class="euiRadioGroup emotion-euiRadioGroup"
203+
>
194204
<div
195205
class="euiRadio euiRadioGroup__item"
196206
>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
@import 'radio';
2-
@import 'radio_group';

packages/eui/src/components/form/radio/_radio_group.scss

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/eui/src/components/form/radio/radio.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const meta: Meta<EuiRadioProps> = {
1919
},
2020
args: {
2121
checked: false,
22-
compressed: false,
2322
disabled: false,
2423
// set up for easier testing/QA
2524
id: '',

packages/eui/src/components/form/radio/radio.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import { CommonProps, ExclusiveUnion } from '../../common';
1818

1919
export interface RadioProps {
2020
autoFocus?: boolean;
21-
/**
22-
* When `true` creates a shorter height radio row
23-
*/
24-
compressed?: boolean;
2521
name?: string;
2622
value?: string;
2723
checked?: boolean;
@@ -55,7 +51,6 @@ export const EuiRadio: FunctionComponent<EuiRadioProps> = ({
5551
value,
5652
onChange,
5753
disabled,
58-
compressed,
5954
autoFocus,
6055
labelProps,
6156
...rest
@@ -64,7 +59,6 @@ export const EuiRadio: FunctionComponent<EuiRadioProps> = ({
6459
'euiRadio',
6560
{
6661
'euiRadio--noLabel': !label,
67-
'euiRadio--compressed': compressed,
6862
},
6963
className
7064
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 { css } from '@emotion/react';
10+
11+
import { UseEuiTheme } from '../../../services';
12+
13+
export const euiRadioGroupStyles = ({ euiTheme }: UseEuiTheme) => ({
14+
euiRadioGroup: css`
15+
display: flex;
16+
flex-direction: column;
17+
`,
18+
// Skip css`` to avoid generating a className
19+
uncompressed: `
20+
gap: ${euiTheme.size.xs}
21+
`,
22+
compressed: css`
23+
gap: 0;
24+
`,
25+
});

0 commit comments

Comments
 (0)