Skip to content

Commit

Permalink
[EuiCheckbox][EuiRadio] Remove compressed props (#7818)
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored Jun 10, 2024
1 parent 1cabbd2 commit 7fac1ce
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 54 deletions.
8 changes: 8 additions & 0 deletions packages/eui/changelogs/upcoming/7818.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**Breaking changes**

- Removed the unused `compressed` prop from `EuiCheckbox` and `EuiRadio`. This prop was not doing anything on individual components.

**CSS-in-JS conversions**

- Converted `EuiCheckboxGroup` to Emotion
- Converted `EuiRadioGroup` to Emotion
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export default () => {

<EuiCheckbox
id={compressedCheckboxId}
label="I am a compressed checkbox"
label="I am a readonly checkbox"
checked={checked}
onChange={(e) => onChange(e)}
compressed
readOnly
/>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiCheckboxGroup (mocked checkbox) disabled is rendered 1`] = `
<div>
<div
class="euiCheckboxGroup emotion-euiCheckboxGroup"
>
<div
data-eui-checkbox=""
/>
Expand All @@ -12,7 +14,9 @@ exports[`EuiCheckboxGroup (mocked checkbox) disabled is rendered 1`] = `
`;

exports[`EuiCheckboxGroup (mocked checkbox) idToSelectedMap is rendered 1`] = `
<div>
<div
class="euiCheckboxGroup emotion-euiCheckboxGroup"
>
<div
data-eui-checkbox=""
/>
Expand All @@ -23,7 +27,9 @@ exports[`EuiCheckboxGroup (mocked checkbox) idToSelectedMap is rendered 1`] = `
`;

exports[`EuiCheckboxGroup (mocked checkbox) individual disabled is rendered 1`] = `
<div>
<div
class="euiCheckboxGroup emotion-euiCheckboxGroup"
>
<div
data-eui-checkbox=""
/>
Expand All @@ -36,13 +42,15 @@ exports[`EuiCheckboxGroup (mocked checkbox) individual disabled is rendered 1`]
exports[`EuiCheckboxGroup (mocked checkbox) is rendered 1`] = `
<div
aria-label="aria-label"
class="testClass1 testClass2 emotion-euiTestCss"
class="euiCheckboxGroup testClass1 testClass2 emotion-euiCheckboxGroup-euiTestCss"
data-test-subj="test subject string"
/>
`;

exports[`EuiCheckboxGroup (mocked checkbox) legend is rendered 1`] = `
<fieldset>
<fieldset
class="euiCheckboxGroup emotion-euiCheckboxGroup"
>
<legend
class="euiFormLegend"
>
Expand All @@ -52,7 +60,9 @@ exports[`EuiCheckboxGroup (mocked checkbox) legend is rendered 1`] = `
`;

exports[`EuiCheckboxGroup (mocked checkbox) options are rendered 1`] = `
<div>
<div
class="euiCheckboxGroup emotion-euiCheckboxGroup"
>
<div
data-eui-checkbox=""
/>
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/eui/src/components/form/checkbox/_index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
@import 'checkbox';
@import 'checkbox_group';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const meta: Meta<EuiCheckboxProps> = {
component: EuiCheckbox,
args: {
checked: false,
compressed: false,
disabled: false,
indeterminate: false,
// set up for easier testing/QA
Expand Down
6 changes: 0 additions & 6 deletions packages/eui/src/components/form/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export interface EuiCheckboxProps
inputRef?: (element: HTMLInputElement) => void;
label?: ReactNode;
disabled?: boolean;
/**
* when `true` creates a shorter height checkbox row
*/
compressed?: boolean;
indeterminate?: boolean;
/**
* Object of props passed to the <label/>
Expand All @@ -50,7 +46,6 @@ export const EuiCheckbox: FunctionComponent<EuiCheckboxProps> = ({
onChange,
type,
disabled = false,
compressed = false,
indeterminate = false,
inputRef,
labelProps,
Expand All @@ -60,7 +55,6 @@ export const EuiCheckbox: FunctionComponent<EuiCheckboxProps> = ({
'euiCheckbox',
{
'euiCheckbox--noLabel': !label,
'euiCheckbox--compressed': compressed,
},
className
);
Expand Down
25 changes: 25 additions & 0 deletions packages/eui/src/components/form/checkbox/checkbox_group.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { css } from '@emotion/react';

import { UseEuiTheme } from '../../../services';

export const euiCheckboxGroupStyles = ({ euiTheme }: UseEuiTheme) => ({
euiCheckboxGroup: css`
display: flex;
flex-direction: column;
`,
// Skip css`` to avoid generating a className
uncompressed: `
gap: ${euiTheme.size.xs}
`,
compressed: css`
gap: 0;
`,
});
26 changes: 21 additions & 5 deletions packages/eui/src/components/form/checkbox/checkbox_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../../services';
import { CommonProps, ExclusiveUnion } from '../../common';

import {
Expand All @@ -17,6 +18,7 @@ import {
EuiFormFieldset,
} from '../form_fieldset';
import { EuiCheckbox, EuiCheckboxProps } from './checkbox';
import { euiCheckboxGroupStyles } from './checkbox_group.styles';

export interface EuiCheckboxGroupOption
extends Omit<EuiCheckboxProps, 'checked' | 'onChange'> {
Expand All @@ -43,10 +45,12 @@ export type EuiCheckboxGroupProps = CommonProps & {
idToSelectedMap: EuiCheckboxGroupIdToSelectedMap;
onChange: (optionId: string) => void;
/**
* Tightens up the spacing between checkbox rows and sends down the
* compressed prop to the checkbox itself
* Tightens up the spacing between checkbox rows
*/
compressed?: boolean;
/**
* Passed down to all child `EuiCheckbox`es
*/
disabled?: boolean;
} & ExclusiveUnion<AsDivProps, WithLegendProps>;

Expand All @@ -60,6 +64,14 @@ export const EuiCheckboxGroup: FunctionComponent<EuiCheckboxGroupProps> = ({
legend,
...rest
}) => {
const classes = classNames('euiCheckboxGroup', className);

const styles = useEuiMemoizedStyles(euiCheckboxGroupStyles);
const cssStyles = [
styles.euiCheckboxGroup,
compressed ? styles.compressed : styles.uncompressed,
];

const checkboxes = options.map((option, index) => {
const {
disabled: isOptionDisabled,
Expand All @@ -73,7 +85,6 @@ export const EuiCheckboxGroup: FunctionComponent<EuiCheckboxGroupProps> = ({
checked={idToSelectedMap[option.id]}
disabled={disabled || isOptionDisabled}
onChange={onChange.bind(null, option.id)}
compressed={compressed}
{...optionRest}
/>
);
Expand All @@ -85,7 +96,8 @@ export const EuiCheckboxGroup: FunctionComponent<EuiCheckboxGroupProps> = ({

return (
<EuiFormFieldset
className={className}
css={cssStyles}
className={classes}
legend={legend}
{...(rest as EuiFormFieldsetProps)}
>
Expand All @@ -95,7 +107,11 @@ export const EuiCheckboxGroup: FunctionComponent<EuiCheckboxGroupProps> = ({
}

return (
<div className={className} {...(rest as HTMLAttributes<HTMLDivElement>)}>
<div
css={cssStyles}
className={classes}
{...(rest as HTMLAttributes<HTMLDivElement>)}
>
{checkboxes}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
exports[`EuiRadioGroup is rendered 1`] = `
<div
aria-label="aria-label"
class="testClass1 testClass2 emotion-euiTestCss"
class="euiRadioGroup testClass1 testClass2 emotion-euiRadioGroup-euiTestCss"
data-test-subj="test subject string"
/>
`;

exports[`EuiRadioGroup props idSelected is rendered 1`] = `
<div>
<div
class="euiRadioGroup emotion-euiRadioGroup"
>
<div
class="euiRadio euiRadioGroup__item"
>
Expand Down Expand Up @@ -53,7 +55,9 @@ exports[`EuiRadioGroup props idSelected is rendered 1`] = `
`;

exports[`EuiRadioGroup props legend is rendered 1`] = `
<fieldset>
<fieldset
class="euiRadioGroup emotion-euiRadioGroup"
>
<legend
class="euiFormLegend"
>
Expand Down Expand Up @@ -101,7 +105,9 @@ exports[`EuiRadioGroup props legend is rendered 1`] = `
`;

exports[`EuiRadioGroup props name is propagated to radios 1`] = `
<div>
<div
class="euiRadioGroup emotion-euiRadioGroup"
>
<div
class="euiRadio euiRadioGroup__item"
>
Expand Down Expand Up @@ -146,7 +152,9 @@ exports[`EuiRadioGroup props name is propagated to radios 1`] = `
`;

exports[`EuiRadioGroup props options are rendered 1`] = `
<div>
<div
class="euiRadioGroup emotion-euiRadioGroup"
>
<div
class="euiRadio euiRadioGroup__item"
>
Expand Down Expand Up @@ -190,7 +198,9 @@ exports[`EuiRadioGroup props options are rendered 1`] = `
`;

exports[`EuiRadioGroup props value is propagated to radios 1`] = `
<div>
<div
class="euiRadioGroup emotion-euiRadioGroup"
>
<div
class="euiRadio euiRadioGroup__item"
>
Expand Down
1 change: 0 additions & 1 deletion packages/eui/src/components/form/radio/_index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
@import 'radio';
@import 'radio_group';
7 changes: 0 additions & 7 deletions packages/eui/src/components/form/radio/_radio_group.scss

This file was deleted.

1 change: 0 additions & 1 deletion packages/eui/src/components/form/radio/radio.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const meta: Meta<EuiRadioProps> = {
},
args: {
checked: false,
compressed: false,
disabled: false,
// set up for easier testing/QA
id: '',
Expand Down
6 changes: 0 additions & 6 deletions packages/eui/src/components/form/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import { CommonProps, ExclusiveUnion } from '../../common';

export interface RadioProps {
autoFocus?: boolean;
/**
* When `true` creates a shorter height radio row
*/
compressed?: boolean;
name?: string;
value?: string;
checked?: boolean;
Expand Down Expand Up @@ -55,7 +51,6 @@ export const EuiRadio: FunctionComponent<EuiRadioProps> = ({
value,
onChange,
disabled,
compressed,
autoFocus,
labelProps,
...rest
Expand All @@ -64,7 +59,6 @@ export const EuiRadio: FunctionComponent<EuiRadioProps> = ({
'euiRadio',
{
'euiRadio--noLabel': !label,
'euiRadio--compressed': compressed,
},
className
);
Expand Down
25 changes: 25 additions & 0 deletions packages/eui/src/components/form/radio/radio_group.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { css } from '@emotion/react';

import { UseEuiTheme } from '../../../services';

export const euiRadioGroupStyles = ({ euiTheme }: UseEuiTheme) => ({
euiRadioGroup: css`
display: flex;
flex-direction: column;
`,
// Skip css`` to avoid generating a className
uncompressed: `
gap: ${euiTheme.size.xs}
`,
compressed: css`
gap: 0;
`,
});
Loading

0 comments on commit 7fac1ce

Please sign in to comment.