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

[EuiHorizontalRule] convert horizontal rule to emotion #5815

Merged
merged 9 commits into from
Apr 25, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`EuiContextMenu can pass-through horizontal rule props 1`] = `
</div>
<div>
<hr
class="euiHorizontalRule euiHorizontalRule--half euiHorizontalRule--marginSmall"
class="euiHorizontalRule euiHorizontalRule--half euiHorizontalRule--marginSmall css-14bhqlx-euiHorizontalRule-half-s"
/>
</div>
</div>
Expand Down Expand Up @@ -67,7 +67,7 @@ exports[`EuiContextMenu panel item can be a separator line 1`] = `
</span>
</button>
<hr
class="euiHorizontalRule euiHorizontalRule--full"
class="euiHorizontalRule euiHorizontalRule--full css-pnauuy-euiHorizontalRule-full"
/>
<button
class="euiContextMenuItem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EuiHorizontalRule is rendered 1`] = `
<hr
aria-label="aria-label"
class="euiHorizontalRule euiHorizontalRule--full euiHorizontalRule--marginLarge testClass1 testClass2"
class="euiHorizontalRule euiHorizontalRule--full euiHorizontalRule--marginLarge testClass1 testClass2 css-14ofhbg-euiHorizontalRule-full-l"
data-test-subj="test subject string"
/>
`;
38 changes: 0 additions & 38 deletions src/components/horizontal_rule/_horizontal_rule.scss

This file was deleted.

1 change: 0 additions & 1 deletion src/components/horizontal_rule/_index.scss

This file was deleted.

54 changes: 54 additions & 0 deletions src/components/horizontal_rule/horizontal_rule.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 euiHorizontalRuleStyles = ({ euiTheme }: UseEuiTheme) => ({
euiHorizontalRule: css`
border: none;
height: ${euiTheme.border.width.thin};
background-color: ${euiTheme.border.color};
flex-shrink: 0; // Ensure when used in flex group, it retains its size
flex-grow: 0; // Ensure when used in flex group, it retains its size
`,

// Sizes
full: css`
width: 100%;
`,
half: css`
width: 50%;
margin-inline: auto;
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
`,
quarter: css`
width: 25%;
margin-inline: auto;
`,

// Margins
none: '',
xs: css`
margin-block: ${euiTheme.size.s};
`,
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
s: css`
margin-block: ${euiTheme.size.m};
`,
m: css`
margin-block: ${euiTheme.size.base};
`,
l: css`
margin-block: ${euiTheme.size.l};
`,
xl: css`
margin-block: ${euiTheme.size.xl};
`,
xxl: css`
margin-block: ${euiTheme.size.xxl};
`,
});
4 changes: 3 additions & 1 deletion src/components/horizontal_rule/horizontal_rule.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';

import { shouldRenderCustomStyles } from '../../test/internal';
import { EuiHorizontalRule } from './horizontal_rule';

describe('EuiHorizontalRule', () => {
shouldRenderCustomStyles(<EuiHorizontalRule {...requiredProps} />);

test('is rendered', () => {
const component = render(<EuiHorizontalRule {...requiredProps} />);

Expand Down
9 changes: 8 additions & 1 deletion src/components/horizontal_rule/horizontal_rule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';

import { CommonProps } from '../common';
import { useEuiTheme } from '../../services';
import { euiHorizontalRuleStyles } from './horizontal_rule.styles';

export type EuiHorizontalRuleSize = keyof typeof sizeToClassNameMap;
export type EuiHorizontalRuleMargin = keyof typeof marginToClassNameMap;
Expand Down Expand Up @@ -50,12 +52,17 @@ export const EuiHorizontalRule: FunctionComponent<EuiHorizontalRuleProps> = ({
margin = 'l',
...rest
}) => {
const euiTheme = useEuiTheme();
const styles = euiHorizontalRuleStyles(euiTheme);

const classes = classNames(
'euiHorizontalRule',
sizeToClassNameMap[size],
marginToClassNameMap[margin],
className
);

return <hr className={classes} {...rest} />;
const cssStyles = [styles.euiHorizontalRule, styles[size], styles[margin]];

return <hr css={cssStyles} className={classes} {...rest} />;
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
};
1 change: 0 additions & 1 deletion src/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@import 'form/index';
@import 'header/index';
@import 'health/index';
@import 'horizontal_rule/index';
@import 'icon/index';
@import 'image/index';
@import 'key_pad_menu/index';
Expand Down
4 changes: 4 additions & 0 deletions upcoming_changelogs/5815.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**CSS-in-JS conversions**

- Converted `EuiHorizontalRule` to emotion; Removed `$ruleMargins`