Skip to content

Commit

Permalink
Convert EuiTextAlign to Emotion
Browse files Browse the repository at this point in the history
+ switch to logical properties
  • Loading branch information
cee-chen committed May 11, 2022
1 parent 765a581 commit 8fd4e19
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/components/text/_index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
@import 'text_color';
@import 'text_align';
11 changes: 0 additions & 11 deletions src/components/text/_text_align.scss

This file was deleted.

23 changes: 23 additions & 0 deletions src/components/text/text_align.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { logicalTextAlignCSS } from '../../global_styling';

export const euiTextAlignStyles = () => ({
euiTextAlign: css``,
left: css`
${logicalTextAlignCSS('left')}
`,
right: css`
${logicalTextAlignCSS('right')}
`,
center: css`
${logicalTextAlignCSS('center')}
`,
});
3 changes: 3 additions & 0 deletions src/components/text/text_align.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test';
import { shouldRenderCustomStyles } from '../../test/internal';

import { EuiTextAlign, ALIGNMENTS } from './text_align';

Expand All @@ -19,6 +20,8 @@ describe('EuiTextAlign', () => {
expect(component).toMatchSnapshot();
});

shouldRenderCustomStyles(<EuiTextAlign textAlign="right" />);

describe('direction prop', () => {
ALIGNMENTS.forEach((direction) => {
test(`${direction} is rendered`, () => {
Expand Down
24 changes: 9 additions & 15 deletions src/components/text/text_align.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@

import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf } from '../common';
import { CommonProps } from '../common';

export const alignmentToClassNameMap = {
left: 'euiTextAlign--left',
right: 'euiTextAlign--right',
center: 'euiTextAlign--center',
};

export type TextAlignment = keyof typeof alignmentToClassNameMap;
import { euiTextAlignStyles } from './text_align.styles';

export const ALIGNMENTS = keysOf(alignmentToClassNameMap);
export const ALIGNMENTS = ['left', 'right', 'center'] as const;
export type TextAlignment = typeof ALIGNMENTS[number];

export type EuiTextAlignProps = CommonProps &
HTMLAttributes<HTMLDivElement> & {
Expand All @@ -31,14 +26,13 @@ export const EuiTextAlign: FunctionComponent<EuiTextAlignProps> = ({
textAlign = 'left',
...rest
}) => {
const classes = classNames(
'euiTextAlign',
alignmentToClassNameMap[textAlign],
className
);
const styles = euiTextAlignStyles();
const cssStyles = [styles.euiTextAlign, styles[textAlign]];

const classes = classNames('euiTextAlign', className);

return (
<div className={classes} {...rest}>
<div css={cssStyles} className={classes} {...rest}>
{children}
</div>
);
Expand Down

0 comments on commit 8fd4e19

Please sign in to comment.