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

[EuiText] Add kbd styles #6049

Merged
merged 4 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions src-docs/src/views/text/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ export default () => (
<dt>Release date</dt>
<dd>2002</dd>
</dl>

<p>
Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy text (Windows).
</p>

<p>
Press <kbd>Cmd</kbd> + <kbd>C</kbd> to copy text (Mac OS).
</p>
</EuiText>
</div>
);
29 changes: 29 additions & 0 deletions src/components/text/__snapshots__/text.styles.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ exports[`euiTextStyles sizes m 1`] = `
code:not(.euiCode):not(.euiCodeBlock__code) {
font-size: .9em; // 90% of parent font size
}




// when the size is 'm' the 'kbd' element gets a line between the text and the border-bottom
kbd {
padding-block-end: 4px;;
// ensures when only one character the shape looks like a square
min-inline-size: 24px;;
text-align: center;
}

kbd::after {
content: '';
border-bottom: 1px solid #343741;
position: absolute;
bottom: 2px;
left: 0;
width: 100%;
}
;;label:m;"
`;

Expand Down Expand Up @@ -251,6 +271,9 @@ exports[`euiTextStyles sizes relative 1`] = `
code:not(.euiCode):not(.euiCodeBlock__code) {
font-size: .9em; // 90% of parent font size
}



;;label:relative;"
`;

Expand Down Expand Up @@ -378,6 +401,9 @@ exports[`euiTextStyles sizes s 1`] = `
code:not(.euiCode):not(.euiCodeBlock__code) {
font-size: .9em; // 90% of parent font size
}



;;label:s;"
`;

Expand Down Expand Up @@ -505,5 +531,8 @@ exports[`euiTextStyles sizes xs 1`] = `
code:not(.euiCode):not(.euiCodeBlock__code) {
font-size: .9em; // 90% of parent font size
}



;;label:xs;"
`;
48 changes: 48 additions & 0 deletions src/components/text/text.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,40 @@ const euiScaleText = (
code:not(.euiCode):not(.euiCodeBlock__code) {
font-size: .9em; // 90% of parent font size
}



`;
};

// Internal utility for getting EuiText ornaments based on options
const euiGetTextOrnaments = (
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
euiThemeContext: UseEuiTheme,
options: _FontScaleOptions
) => {
const { euiTheme } = euiThemeContext;
const { customScale } = options;

return `
// when the size is 'm' the 'kbd' element gets a line between the text and the border-bottom
${
customScale === 'm' &&
`kbd {
${logicalCSS('padding-bottom', euiTheme.size.xs)};
// ensures when only one character the shape looks like a square
${logicalCSS('min-width', euiTheme.size.l)};
text-align: center;
}

kbd::after {
content: '';
border-bottom: 1px solid ${euiTheme.colors.text};
position: absolute;
bottom: ${euiTheme.size.xxs};
left: 0;
width: 100%;
}`
}
`;
};

Expand Down Expand Up @@ -303,6 +337,16 @@ export const euiTextStyles = (euiThemeContext: UseEuiTheme) => {
> :last-child {
margin-bottom: 0 !important;
}

kbd {
position: relative;
display: inline-block;
${logicalCSS('padding-vertical', euiTheme.size.xxs)};
${logicalCSS('padding-horizontal', euiTheme.size.xs)};
line-height: 1;
border: 1px solid ${euiTheme.colors.text};
border-radius: calc(${euiTheme.border.radius.small} / 2);
}
`,
constrainedWidth: css`
max-width: ${euiTextConstrainedMaxWidth};
Expand All @@ -313,6 +357,10 @@ export const euiTextStyles = (euiThemeContext: UseEuiTheme) => {
measurement: 'rem',
customScale: 'm',
})}

${euiGetTextOrnaments(euiThemeContext, {
customScale: 'm',
})}
`,
s: css`
${euiScaleText(euiThemeContext, {
Expand Down
1 change: 1 addition & 0 deletions upcoming_changelogs/6049.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added styles for `kbd`'s within `EuiText`