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

[FEATURE] CSS-in-JS via emotion, initial release #4511

Merged
merged 74 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8a1787e
Creating initial CL to get a draft PR started
cchaos Feb 10, 2021
a0a8b42
Merge branch 'master' into feature/css-in-js
thompsongl Feb 17, 2021
156f7fe
[CSS-in-JS] Context and foundation (#4440)
thompsongl Feb 17, 2021
90740eb
[CSS-in-JS] Support extensions via overrides prop (#4547)
thompsongl Mar 1, 2021
51604d3
Merge branch 'master' into feature/css-in-js
thompsongl Mar 1, 2021
9074437
Merge branch 'feature/css-in-js' of https://github.com/elastic/eui in…
thompsongl Mar 1, 2021
984cd48
[CSS-in-JS] Starting simple usage docs (#4558)
cchaos Mar 3, 2021
1b2f77b
Merge branch 'master' into feature/css-in-js
thompsongl Mar 3, 2021
0e82dac
[CSS-in-JS] useEuiTheme & withEuiTheme refactor (#4594)
thompsongl Mar 11, 2021
1a35553
Merge branch 'master' into feature/css-in-js
thompsongl Mar 11, 2021
64cfcd3
[CSS-in-JS] Sizes with units (#4578)
thompsongl Mar 15, 2021
113935e
Merge branch 'master' into feature/css-in-js
thompsongl Mar 29, 2021
af55700
Merge branch 'feature/css-in-js' of https://github.com/elastic/eui in…
thompsongl Mar 29, 2021
15f4509
Merge branch 'master' into feature/css-in-js
thompsongl Apr 12, 2021
2383760
Merge branch 'master' into feature/css-in-js
thompsongl Apr 21, 2021
3f39e78
[Docs] Rebrand (#4727)
miukimiu Apr 22, 2021
2041721
[Docs] [EuiStat] Incorrect reference to `size` property in example, s…
dannya Apr 22, 2021
f64b469
export Rehype2ReactOptions (#4746)
thompsongl Apr 22, 2021
373fe73
[EuiFilePicker] Added i18n for Remove text (#4750)
Lemaro86 Apr 23, 2021
b692232
[EuiComboBox] Matching placeholder color to other form elements (#4744)
Apr 27, 2021
b9a5cdc
[EuiButtonEmpty] Reduce icon in xs size (#4759)
andreadelrio Apr 27, 2021
cee865c
update i18ntokens
thompsongl Apr 27, 2021
6f24e3b
32.3.0
thompsongl Apr 27, 2021
3331094
Updated documentation.
thompsongl Apr 27, 2021
4255a69
[EuiPopover] Handle `initialFocus` (#4768)
thompsongl Apr 29, 2021
8e8357e
Fixed description prop in EuiTable (#4754)
hetanthakkar Apr 29, 2021
f559c9e
[EuiComboBox] `autoFocus` behavior (#4772)
thompsongl Apr 30, 2021
2e721df
[EuiIcon] Fix two-tone icons to inherit parent color when nested in s…
miukimiu Apr 30, 2021
0ac8774
[i18n] NPM publish `i18ntokens.json` (#4771)
afharo May 4, 2021
d86dc13
[EuiCodeBlock] Replace highlight.js with prism.js via refractor (#4638)
thompsongl May 4, 2021
ae75336
Merge branch 'master' into feature/css-in-js
thompsongl Jul 7, 2021
49e471c
Merge branch 'master' into feature/css-in-js
thompsongl Jul 13, 2021
6cb5094
update license headers
thompsongl Jul 13, 2021
53d6cf4
fix license headers
thompsongl Jul 13, 2021
c8ddff0
Merge branch 'master' into feature/css-in-js
thompsongl Jul 21, 2021
691130e
Merge branch 'master' into feature/css-in-js
thompsongl Jul 29, 2021
31a24ed
[CSS-in-JS] Global theme (#4643)
cchaos Aug 10, 2021
460c138
Shifting the `border` type to dot notation
Aug 10, 2021
795fbf8
test remove fontSIze
Aug 11, 2021
15c65f3
Removing fontSize for now
Aug 11, 2021
3cf8109
Merge branch 'master' into feature/css-in-js
thompsongl Aug 11, 2021
afce166
border and font family debounce
thompsongl Aug 11, 2021
d8144ec
clean up
thompsongl Aug 13, 2021
75d9959
scope changes to src-docs and devDependencies
thompsongl Aug 17, 2021
c15a8d5
Apply suggestions from code review
cchaos Aug 17, 2021
0f2430a
linted
Aug 17, 2021
dfd5d9f
Added section about `ColorModeSwitch` type
Aug 18, 2021
22a8c7a
Update src/components/basic_table/in_memory_table.test.tsx
cchaos Aug 18, 2021
0b6d4ae
Moving `contrast` color functions to `services`
Aug 18, 2021
72c836d
Cleaning up typography utils, but not documenting as it should only b…
Aug 18, 2021
941c930
Update Contrast docs to pass in `euiTheme.colors.body`
Aug 18, 2021
388d775
Moved `sizeToPixel` to `services/theme`
Aug 18, 2021
388db2c
Adding comments/notes to “converted” sass files that aren’t being use…
Aug 18, 2021
f7e0329
makeHighContrastColor background param
thompsongl Aug 18, 2021
ace842b
Merge branch 'feature/css-in-js' of https://github.com/elastic/eui in…
thompsongl Aug 18, 2021
7aa722e
Removing required `focus` key from theme (for now)
Aug 18, 2021
b0106e2
Update contrast docs to just use `euiTheme`
Aug 18, 2021
59f046d
utils code comments
thompsongl Aug 19, 2021
41bb5cd
clean up
thompsongl Aug 19, 2021
e9ca717
Added docs for new JS color functions
Aug 19, 2021
d228ba8
Apply suggestions from code review
cchaos Aug 20, 2021
f56976e
Merge remote-tracking branch 'origin/master' into feature/css-in-js
Aug 20, 2021
9d419eb
cl
Aug 20, 2021
95207f6
Prettier fix
Aug 20, 2021
ac9843f
makeHighContrastColor alpha
thompsongl Aug 20, 2021
6613900
readme
thompsongl Aug 20, 2021
f7905e7
Merge branch 'master' into feature/css-in-js
cee-chen Aug 23, 2021
95dae99
Run yarn prettier with new rule
cee-chen Aug 23, 2021
61ffefd
Delete file missed in upstream merge
cee-chen Aug 23, 2021
fadbeb0
skip changelog page a11y check
thompsongl Aug 23, 2021
bcf9135
Merge branch 'master' into feature/css-in-js
cchaos Aug 25, 2021
e7ca7af
[CL] Changed feature heading to h2 for now
cchaos Aug 25, 2021
c07a7c8
Remove CL from getting skipped by a11y tests
cchaos Aug 25, 2021
35396de
Merge branch 'master' into feature/css-in-js
cchaos Aug 26, 2021
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
2 changes: 1 addition & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
"modules": process.env.BABEL_MODULES ? process.env.BABEL_MODULES === 'false' ? false : process.env.BABEL_MODULES : "commonjs" // babel's default is commonjs
}],
["@babel/typescript", { isTSX: true, allExtensions: true }],
"@babel/react"
"@babel/react",
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
'prettier/standard',
'plugin:prettier/recommended',
],
plugins: ['jsx-a11y', 'prettier', 'local', 'react-hooks'],
plugins: ['jsx-a11y', 'prettier', 'local', 'react-hooks', '@emotion'],
rules: {
'prefer-template': 'error',
'local/i18n': 'error',
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `37.4.0`.
## Feature: Emotion ([#4511](https://github.com/elastic/eui/pull/4511))

- Added `EuiThemeProvider`, a React context provider for theme values and color mode selection
- Added `useEuiTheme` React hook, and `withEuiTheme` React HOC for consuming the EuiTheme
- Added global `EuiTheme` tokens for `colors`, `size`, `font`, `border`, `animation`, and `breakpoint`
- Added color services for `makeHighContrastColor`, `makeDisabledContrastColor`, `shade`, `tint`, `transparentize`, `saturate`, `desaturate`, `lightness`

## [`37.4.0`](https://github.com/elastic/eui/tree/v37.4.0)

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
"@elastic/charts": "^34.2.0",
"@elastic/datemath": "^5.0.3",
"@elastic/eslint-config-kibana": "^0.15.0",
"@emotion/babel-preset-css-prop": "^11.0.0",
"@emotion/eslint-plugin": "^11.0.0",
"@emotion/react": "^11.1.1",
"@svgr/core": "5.4.0",
"@svgr/plugin-svgo": "^4.0.3",
"@types/classnames": "^2.2.10",
Expand Down
2 changes: 1 addition & 1 deletion scripts/babel/proptypes-from-ts-props/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ function getPropTypesForNode(node, optional, state) {
types.arrayExpression(
node.properties.map(property =>
types.stringLiteral(
property.key.name || property.key.name || property.key.value
property.key ? property.key.name || property.key.value : property.argument.name
)
)
),
Expand Down
6 changes: 6 additions & 0 deletions src-docs/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ const baseConfig = require('../.babelrc.js');
const index = baseConfig.plugins.indexOf(
'./scripts/babel/proptypes-from-ts-props'
);
baseConfig.presets.push([
'@emotion/babel-preset-css-prop',
{
labelFormat: '[local]',
},
]);
baseConfig.plugins.splice(
index + 1,
0,
Expand Down
12 changes: 11 additions & 1 deletion src-docs/src/components/with_theme/theme_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import { EUI_THEMES, EUI_THEME } from '../../../../src/themes';
// @ts-ignore importing from a JS file
import { applyTheme } from '../../services';
import { EuiThemeProvider } from '../../../../src/services';
import { EuiThemeAmsterdam } from '../../../../src/themes/eui-amsterdam/theme';
import { EuiThemeDefault } from '../../../../src/themes/eui/theme';

const THEME_NAMES = EUI_THEMES.map(({ value }) => value);

Expand Down Expand Up @@ -48,7 +51,14 @@ export class ThemeProvider extends React.Component<object, State> {
changeTheme: this.changeTheme,
}}
>
{children}
<EuiThemeProvider
theme={
theme.includes('amsterdam') ? EuiThemeAmsterdam : EuiThemeDefault
}
colorMode={theme.includes('light') ? 'light' : 'dark'}
>
{children}
</EuiThemeProvider>
</ThemeContext.Provider>
);
}
Expand Down
12 changes: 12 additions & 0 deletions src-docs/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

// TODO: Delete this file when the @emotion reference is added to `src/index.d.ts`

/* eslint-disable @typescript-eslint/triple-slash-reference */
/// <reference types="@emotion/react/types/css-prop" />
18 changes: 16 additions & 2 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import WritingGuidelines from './views/guidelines/writing';

import { ColorPaletteExample } from './views/color_palette/color_palette_example';

import { IsColorDarkExample } from './views/is_color_dark/is_color_dark_example';
import { ColorExample } from './views/color/color_example';

import { PrettyDurationExample } from './views/pretty_duration/pretty_duration_example';

Expand Down Expand Up @@ -222,6 +222,9 @@ import { I18nTokens } from './views/package/i18n_tokens';

import { SuperSelectExample } from './views/super_select/super_select_example';

import { ThemeExample } from './views/theme/theme_example';
import ThemeValues from './views/theme/values';

/** Elastic Charts */

import { ElasticChartsThemingExample } from './views/elastic_charts/theming_example';
Expand Down Expand Up @@ -460,7 +463,7 @@ const navigation = [
items: [
AccessibilityExample,
BeaconExample,
IsColorDarkExample,
ColorExample,
ColorPaletteExample,
CopyExample,
UtilityClassesExample,
Expand All @@ -482,6 +485,17 @@ const navigation = [
WindowEventExample,
].map((example) => createExample(example)),
},
{
name: 'Theming',
items: [
createExample(ThemeExample, 'Theme provider'),
{
name: 'Global values',
component: ThemeValues,
isNew: true,
},
],
},
{
name: 'Package',
items: [Changelog, I18nTokens],
Expand Down
120 changes: 55 additions & 65 deletions src-docs/src/services/playground/knobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,38 @@ export const humanizeType = (type) => {
humanizedType = type.name;
}

return humanizedType;
let typeMarkup;

if (humanizedType) {
typeMarkup = humanizedType;

const functionMatches = [
...humanizedType.matchAll(/\([^=]*\) =>\s\w*\)*/g),
];

const types = humanizedType.split(/\([^=]*\) =>\s\w*\)*/);

if (functionMatches.length > 0) {
let elements = '';
let j = 0;
for (let i = 0; i < types.length; i++) {
if (functionMatches[j]) {
elements =
`${elements}` +
`${types[i]}` +
'\n' +
`${functionMatches[j][0]}` +
'\n';
j++;
} else {
elements = `${elements}` + `${types[i]}` + '\n';
}
}
typeMarkup = elements;
}
}

return typeMarkup || humanizedType;
};

const getTooltip = (description, type, name) => (
Expand Down Expand Up @@ -364,87 +395,46 @@ const Knob = ({
};

const KnobColumn = ({ state, knobNames, error, set, isPlayground }) => {
return knobNames.map((name, idx) => {
const codeBlockProps = {
className: 'guideSection__tableCodeBlock',
paddingSize: 'none',
language: 'ts',
};

/**
* TS Type
*/
let humanizedType;

if (
state[name].custom &&
state[name].custom.origin &&
state[name].custom.origin.type
)
humanizedType = humanizeType(state[name].custom.origin.type);

let typeMarkup;

if (humanizedType) {
typeMarkup = humanizedType && (
<EuiCodeBlock {...codeBlockProps}>{humanizedType}</EuiCodeBlock>
);

const functionMatches = [
...humanizedType.matchAll(/\([^=]*\) =>\s\w*\)*/g),
];

const types = humanizedType.split(/\([^=]*\) =>\s\w*\)*/);

if (functionMatches.length > 0) {
let elements = '';
let j = 0;
for (let i = 0; i < types.length; i++) {
if (functionMatches[j]) {
elements =
`${elements}` +
`${types[i]}` +
'\n' +
`${functionMatches[j][0]}` +
'\n';
j++;
} else {
elements = `${elements}` + `${types[i]}` + '\n';
}
}
typeMarkup = (
<EuiCodeBlock {...codeBlockProps}>{elements}</EuiCodeBlock>
);
}
}
const codeBlockProps = {
className: 'guideSection__tableCodeBlock',
paddingSize: 'none',
language: 'ts',
};

return knobNames.map((name, idx) => {
/**
* Prop name
*/
let humanizedName = <strong className="eui-textBreakNormal">{name}</strong>;

if (
state[name].custom &&
state[name].custom.origin &&
state[name].custom.origin.required
) {
if (state[name].custom?.origin?.required) {
humanizedName = (
<>
{humanizedName} <EuiTextColor color="danger">(required)</EuiTextColor>
</>
);
}

/**
* TS Type
*/
let typeMarkup;

if (state[name].custom?.origin?.type) {
const humanizedType = humanizeType(state[name].custom.origin.type);

if (humanizedType) {
typeMarkup = (
<EuiCodeBlock {...codeBlockProps}>{humanizedType}</EuiCodeBlock>
);
}
}

/**
* Default value
*/
let defaultValueMarkup;
if (
// !isPlayground &&
state[name].custom &&
state[name].custom.origin &&
state[name].custom.origin.defaultValue
) {
if (state[name].custom?.origin?.defaultValue) {
const defaultValue = state[name].custom.origin.defaultValue;
defaultValueMarkup = (
<EuiText size="xs">
Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/button/button_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const buttonGroupSnippet = [
options={[
{
id,
label'
label
}
]}
/>`,
Expand All @@ -163,7 +163,7 @@ const buttonGroupSnippet = [
options={[
{
id,
label'
label
}
]}
/>`,
Expand Down
4 changes: 1 addition & 3 deletions src-docs/src/views/code/code_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ export const CodeExample = {
<EuiLink external href="https://prismjs.com/">
library
</EuiLink>
.
<br />
The <EuiCode>language</EuiCode> prop can also be omitted to simply
. The <EuiCode>language</EuiCode> prop can also be omitted to simply
render formatted but unhighlighted code.
</p>
<p>
Expand Down
Loading