Skip to content

Commit

Permalink
Convert constrainedWidth modifier CSS to Emotion
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed May 11, 2022
1 parent 6103653 commit 61dc217
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 22 deletions.
6 changes: 2 additions & 4 deletions src/components/empty_prompt/_empty_prompt.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import '../text/_variables';

.euiEmptyPrompt {
text-align: center;
margin: auto;
Expand Down Expand Up @@ -60,7 +58,7 @@
}

.euiEmptyPrompt__contentInner {
max-width: $euiTextConstrainedMaxWidth;
max-width: 36em; // TODO: Use euiTextConstrainedMaxWidth in text.styles.ts
margin: auto;
}

Expand Down Expand Up @@ -97,7 +95,7 @@
}

.euiEmptyPrompt__content {
max-width: $euiTextConstrainedMaxWidth;
max-width: 36em; // TODO: Use euiTextConstrainedMaxWidth in text.styles.ts

@include euiBreakpoint('l', 'xl') {
padding: $euiSizeL 0;
Expand Down
4 changes: 2 additions & 2 deletions src/components/text/__snapshots__/text.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ exports[`EuiText is rendered 1`] = `
</div>
`;

exports[`EuiText props grow is rendered 1`] = `
exports[`EuiText props grow false 1`] = `
<div
aria-label="aria-label"
class="euiText euiText--medium testClass1 testClass2"
class="euiText euiText--medium testClass1 testClass2 css-19nx0h7-euiText-constrainedWidth"
data-test-subj="test subject string"
>
<p>
Expand Down
1 change: 0 additions & 1 deletion src/components/text/_index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@import 'variables';
@import 'text';
@import 'text_color';
@import 'text_align';
1 change: 0 additions & 1 deletion src/components/text/_variables.scss

This file was deleted.

15 changes: 8 additions & 7 deletions src/components/text/text.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { UseEuiTheme } from '../../services';
import { euiLinkCSS } from '../link/link.styles';
import { euiTitle } from '../title/title.styles';

export const euiTextConstrainedMaxWidth = '36em';

/**
* Mixins
*/
Expand Down Expand Up @@ -142,16 +144,15 @@ export const euiTextStyles = ({ euiTheme }: UseEuiTheme) => ({
letter-spacing: normal;
}
&.euiText--constrainedWidth {
max-width: 36em; // TODO
// If the max-width is way too short of the width of the container,
// at least make it 2/3 of its parent
min-width: 75%;
}
> :last-child,
.euiTextColor > :last-child {
margin-bottom: 0 !important;
}
`,
constrainedWidth: css`
max-width: ${euiTextConstrainedMaxWidth};
// If the max-width is way too short of the width of the container,
// at least make it 2/3 of its parent
min-width: 75%;
`,
});
4 changes: 2 additions & 2 deletions src/components/text/text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe('EuiText', () => {

describe('props', () => {
describe('grow', () => {
test('is rendered', () => {
test('false', () => {
const component = render(
<EuiText {...requiredProps} grow>
<EuiText {...requiredProps} grow={false}>
<p>Content</p>
</EuiText>
);
Expand Down
10 changes: 5 additions & 5 deletions src/components/text/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export const EuiText: FunctionComponent<EuiTextProps> = ({
}) => {
const euiTheme = useEuiTheme();
const styles = euiTextStyles(euiTheme);
const cssStyles = [styles.euiText];
const cssStyles = [
styles.euiText,
!grow ? styles.constrainedWidth : undefined,
];

const classes = classNames(
'euiText',
textSizeToClassNameMap[size],
className,
{
'euiText--constrainedWidth': !grow,
}
className
);

let optionallyAlteredText;
Expand Down

0 comments on commit 61dc217

Please sign in to comment.