Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiFlexGrid] Add alignItems prop #6281

Merged
merged 5 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions src/components/flex/__snapshots__/flex_grid.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EuiFlexGrid is rendered 1`] = `
<div
aria-label="aria-label"
class="euiFlexGrid testClass1 testClass2 emotion-euiFlexGrid-l-row-3-responsive"
class="euiFlexGrid testClass1 testClass2 emotion-euiFlexGrid-l-row-stretch-3-responsive"
data-test-subj="test subject string"
>
<h2>
Expand All @@ -12,74 +12,104 @@ exports[`EuiFlexGrid is rendered 1`] = `
</div>
`;

exports[`EuiFlexGrid props alignItems baseline is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-baseline-1-responsive"
/>
`;

exports[`EuiFlexGrid props alignItems center is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-center-1-responsive"
/>
`;

exports[`EuiFlexGrid props alignItems end is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-end-1-responsive"
/>
`;

exports[`EuiFlexGrid props alignItems start is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-start-1-responsive"
/>
`;

exports[`EuiFlexGrid props alignItems stretch is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props columns 1 is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-1-responsive"
class="euiFlexGrid emotion-euiFlexGrid-l-row-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props columns 2 is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-2-responsive"
class="euiFlexGrid emotion-euiFlexGrid-l-row-stretch-2-responsive"
/>
`;

exports[`EuiFlexGrid props columns 3 is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-3-responsive"
class="euiFlexGrid emotion-euiFlexGrid-l-row-stretch-3-responsive"
/>
`;

exports[`EuiFlexGrid props columns 4 is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-4-responsive"
class="euiFlexGrid emotion-euiFlexGrid-l-row-stretch-4-responsive"
/>
`;

exports[`EuiFlexGrid props direction column is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-column-1-responsive"
class="euiFlexGrid emotion-euiFlexGrid-l-column-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props direction row is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-1-responsive"
class="euiFlexGrid emotion-euiFlexGrid-l-row-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props gutterSize l is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-1-responsive"
class="euiFlexGrid emotion-euiFlexGrid-l-row-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props gutterSize m is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-m-row-1-responsive"
class="euiFlexGrid emotion-euiFlexGrid-m-row-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props gutterSize none is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-none-row-1-responsive"
class="euiFlexGrid emotion-euiFlexGrid-none-row-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props gutterSize s is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-s-row-1-responsive"
class="euiFlexGrid emotion-euiFlexGrid-s-row-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props gutterSize xl is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-xl-row-1-responsive"
class="euiFlexGrid emotion-euiFlexGrid-xl-row-stretch-1-responsive"
/>
`;

exports[`EuiFlexGrid props responsive is rendered 1`] = `
<div
class="euiFlexGrid emotion-euiFlexGrid-l-row-1"
class="euiFlexGrid emotion-euiFlexGrid-l-row-stretch-1"
/>
`;
17 changes: 17 additions & 0 deletions src/components/flex/flex_grid.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,22 @@ export const euiFlexGridStyles = (
gap: ${euiTheme.size.xl};
`,
},
alignItems: {
stretch: css`
align-items: stretch;
`,
start: css`
align-items: start;
`,
end: css`
align-items: end;
`,
center: css`
align-items: center;
`,
baseline: css`
align-items: baseline;
`,
},
};
};
17 changes: 16 additions & 1 deletion src/components/flex/flex_grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { shouldRenderCustomStyles } from '../../test/internal';

import { EuiFlexGrid, GUTTER_SIZES, DIRECTIONS } from './flex_grid';
import {
EuiFlexGrid,
GUTTER_SIZES,
DIRECTIONS,
ALIGN_ITEMS,
} from './flex_grid';

describe('EuiFlexGrid', () => {
shouldRenderCustomStyles(<EuiFlexGrid />);
Expand Down Expand Up @@ -57,6 +62,16 @@ describe('EuiFlexGrid', () => {
});
});

describe('alignItems', () => {
ALIGN_ITEMS.forEach((value) => {
test(`${value} is rendered`, () => {
const component = render(<EuiFlexGrid alignItems={value} />);

expect(component).toMatchSnapshot();
});
});
});

describe('responsive', () => {
test('is rendered', () => {
const component = render(<EuiFlexGrid responsive={false} />);
Expand Down
15 changes: 15 additions & 0 deletions src/components/flex/flex_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import { euiFlexGridStyles } from './flex_grid.styles';
export const DIRECTIONS = ['row', 'column'] as const;
export type FlexGridDirection = typeof DIRECTIONS[number];

export const ALIGN_ITEMS = [
'stretch',
'start',
'end',
'center',
'baseline',
] as const;
export type FlexGridAlignItems = typeof ALIGN_ITEMS[number];

export const GUTTER_SIZES = ['none', 's', 'm', 'l', 'xl'] as const;
export type FlexGridGutterSize = typeof GUTTER_SIZES[number];

Expand All @@ -38,6 +47,10 @@ export interface EuiFlexGridProps {
* Change this prop to `column` to create a top-down then left-right display.
*/
direction?: FlexGridDirection;
/**
* Aligns grid items vertically
*/
alignItems?: FlexGridAlignItems;
/**
* Space between flex items
*/
Expand All @@ -61,6 +74,7 @@ export const EuiFlexGrid: FunctionComponent<
className,
gutterSize = 'l',
direction = 'row',
alignItems = 'stretch',
responsive = true,
columns = 1,
component: Component = 'div',
Expand All @@ -77,6 +91,7 @@ export const EuiFlexGrid: FunctionComponent<
styles.euiFlexGrid,
styles.gutterSizes[gutterSize],
styles.direction[direction],
styles.alignItems[alignItems],
styles.columnCount[columns],
responsive && styles.responsive,
];
Expand Down
1 change: 1 addition & 0 deletions upcoming_changelogs/6281.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added the `alignItems` prop to `EuiFlexGrid`