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

[CSS-in-JS] @emotion/react in src/ #5121

Merged
merged 59 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
681d56e
emotion as peerDep; babel and typescript
thompsongl Sep 1, 2021
155c1d5
jest config
thompsongl Sep 1, 2021
601d2d0
isDefaultTheme util
thompsongl Sep 1, 2021
43e89c2
CL TODO
thompsongl Sep 1, 2021
98714ee
Merge branch 'master' into css-in-js/breaking
thompsongl Sep 1, 2021
6ebbb0d
update snapshots
thompsongl Sep 1, 2021
e2e2dfe
Merge branch 'master' into css-in-js/breaking
thompsongl Sep 9, 2021
b28f9a5
Merge branch 'master' into css-in-js/breaking
thompsongl Sep 16, 2021
6f782d7
Merge branch 'master' into css-in-js/breaking
cchaos Sep 23, 2021
caba1df
Merge remote-tracking branch upstream/master into css-in-js/breaking
Sep 28, 2021
e673838
Merge branch 'master' into css-in-js/breaking
thompsongl Sep 30, 2021
40d355f
Merge branch 'css-in-js/breaking' of https://github.com/elastic/eui i…
thompsongl Sep 30, 2021
64aacf7
Merge remote-tracking branch 'origin/master' into css-in-js/breaking
Sep 30, 2021
f00cacc
[CSS-in-JS] [Breaking] Deprecating EUI theme to Legacy (#5222)
cchaos Oct 1, 2021
3b60df7
[CSS-in-JS] Global style reset with `emotion` (#5122)
thompsongl Oct 6, 2021
8c1ec07
Merge branch 'master' into css-in-js/breaking
thompsongl Oct 6, 2021
ae19633
Merge branch 'css-in-js/breaking' of https://github.com/elastic/eui i…
thompsongl Oct 6, 2021
f2bc587
Merge branch 'master' into css-in-js/breaking
thompsongl Oct 7, 2021
f8d8675
[CSS-in-JS] Add provider to generated codesandbox examples (#5253)
thompsongl Oct 14, 2021
acc89ae
Merge branch 'master' into css-in-js/breaking
thompsongl Oct 14, 2021
2968430
Merge remote-tracking branch origin/master into css-in-js/breaking
Oct 20, 2021
63ef281
Merge remote-tracking branch 'origin/master' into css-in-js/breaking
Oct 20, 2021
7b6ac4c
fix snapshot tests
thompsongl Oct 21, 2021
c09c18c
[CSS-in-JS] Provider for fullscreen examples; Context refactor (#5309)
thompsongl Oct 26, 2021
59e3245
[CSS-in-JS] [Breaking] Better Getting Started page (#5299)
cchaos Oct 28, 2021
48477fa
Merge branch 'master' into css-in-js/breaking
thompsongl Oct 28, 2021
438e035
fix heading level
thompsongl Oct 28, 2021
2e47d07
Merge branch 'master' into css-in-js/breaking
thompsongl Oct 28, 2021
8e6d3ac
Merge branch 'master' into css-in-js/breaking
thompsongl Nov 2, 2021
15fd846
update changelog page regex to fully remove the master section
thompsongl Nov 2, 2021
0797bff
manual merge
thompsongl Nov 2, 2021
c1662ca
update release script changelog regex
thompsongl Nov 2, 2021
2422722
Merge branch 'master' into css-in-js/breaking
thompsongl Nov 2, 2021
804a415
Cleanup some docs
Nov 2, 2021
b1e75a8
Merge remote-tracking branch origin/master into css-in-js/breaking
Nov 2, 2021
b5aa3c1
Hide LanguageSelector tour on Getting Started page
Nov 3, 2021
f1a4a56
Some GS page cleanup
Nov 3, 2021
e37a062
Merge branch 'master' into css-in-js/breaking
thompsongl Nov 3, 2021
38c7125
PR feedback
Nov 6, 2021
5a1e555
Merge remote-tracking branch 'origin/main' into css-in-js/breaking
Nov 6, 2021
ecd2e0f
cl
Nov 6, 2021
32d302b
Merge branch 'main' into css-in-js/breaking
thompsongl Nov 15, 2021
fc7577e
Merge branch 'main' into css-in-js/breaking
thompsongl Nov 18, 2021
6f9bd20
Apply suggestions from code review
thompsongl Nov 18, 2021
d71c462
lint fix
thompsongl Nov 18, 2021
6c13740
make amsterdam default
thompsongl Nov 18, 2021
a9eb789
provider updates
thompsongl Nov 18, 2021
5da968c
fix cypress styles
thompsongl Nov 18, 2021
0963b81
PR feedback:
Nov 22, 2021
f35c0e4
Merge branch 'main' into css-in-js/breaking
cchaos Nov 22, 2021
5439053
move keydown inside useeffect
thompsongl Nov 22, 2021
30f66cc
Merge branch 'main' into css-in-js/breaking
cchaos Nov 23, 2021
a89a023
Merge remote-tracking branch 'origin/main' into css-in-js/breaking
Nov 23, 2021
134d6d3
Merge remote-tracking branch 'origin/main' into css-in-js/breaking
Nov 23, 2021
895c86a
Reusing correct Sass customization snippet under Customizing
Nov 23, 2021
6ce27dc
fix cypress path
thompsongl Nov 24, 2021
4a8477f
Merge branch 'main' into css-in-js/breaking
thompsongl Nov 24, 2021
dba14b1
Merge branch 'main' into css-in-js/breaking
thompsongl Nov 30, 2021
a319356
update export
thompsongl Nov 30, 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
6 changes: 6 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ module.exports = {
}],
["@babel/typescript", { isTSX: true, allExtensions: true }],
"@babel/react",
[
"@emotion/babel-preset-css-prop",
{
"labelFormat": "[filename]-[local]"
},
],
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
Expand Down
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
## [`main`](https://github.com/elastic/eui/tree/main)

No public interface changes since `41.2.1`.
### Feature: CSS-in-JS ([#5121](https://github.com/elastic/eui/pull/5121))

- Added reset and global styles via CSS-in-JS with `@emotion/react/Global`
- Added `EuiProvider`, a React context provider for theming and global styles
- Added `isDefaultTheme` and `isLegacyTheme` utilities

**Breaking changes**

- Added `@emotion/react` to `peerDependencies`
- Amsterdam is now the default theme, deprecated and renamed old theme as "legacy"
- Re-organized Sass files including where the `globals` are imported from

## [`41.2.1`](https://github.com/elastic/eui/tree/v41.2.1)

Expand Down Expand Up @@ -240,7 +250,7 @@ No public interface changes since `41.2.1`.

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

### Feature: Emotion ([#4511](https://github.com/elastic/eui/pull/4511))
### Feature: CSS-in-JS ([#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
Expand Down
22 changes: 4 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,7 @@

Check out our [full documentation site][docs] which contains many examples of components in the EUI framework aesthetic, and how to use them in your products. We also have a [FAQ][faq] that covers common usage questions. For other general questions regarding EUI, check out the [Discussions tab](https://github.com/elastic/eui/discussions).

## Installation

To install the Elastic UI Framework into an existing project, use the `yarn` CLI (`npm` is not supported).

```
yarn add @elastic/eui
```

Note that EUI has [several `peerDependencies` requirements](package.json) that will also need to be installed if starting with a blank project. You can read more about other ways to [consume EUI][consuming].

```
yarn add @elastic/eui @elastic/datemath moment prop-types
```

The rest of this doc will detail how to run and contribute to the **EUI documentation** site locally.

## Running Locally

Expand All @@ -31,22 +18,22 @@ You will probably want to install a node version manager. [nvm](https://github.c

To install and use the correct node version with `nvm`:

```
```bash
nvm install
```

### Documentation

You can run the documentation locally at [http://localhost:8030/](http://localhost:8030/) by running the following.

```
```bash
yarn
yarn start
```

If another process is already listening on port 8030, the next free port will be used. Alternatively, you can specify a port:

```
```bash
yarn start --port 9000
```

Expand Down Expand Up @@ -75,7 +62,6 @@ directly in the code. And unit test coverage for the UI components allows us to
* [Creating components manually](wiki/creating-components-manually.md)
* [Creating components with Yeoman](wiki/creating-components-yeoman.md)
* [Creating icons](wiki/creating-icons.md)
* [Theming](wiki/theming.md)
* [Testing](wiki/testing.md)
* [Accessibility Testing](wiki/automated-accessibility-testing.md)
* [Documentation](wiki/documentation-guidelines.md)
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
// ***********************************************************

import '@cypress/code-coverage/support';
import '../../dist/eui_theme_amsterdam_dark.css';
import '../../dist/eui_theme_dark.css';
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@
"@elastic/datemath": "^5.0.3",
"@elastic/eslint-config-kibana": "^0.15.0",
"@emotion/babel-preset-css-prop": "^11.0.0",
"@emotion/cache": "^11.4.0",
"@emotion/eslint-plugin": "^11.0.0",
"@emotion/jest": "^11.1.0",
"@emotion/react": "^11.1.1",
"@svgr/core": "5.5.0",
"@svgr/plugin-svgo": "^4.0.3",
Expand Down Expand Up @@ -234,6 +236,7 @@
},
"peerDependencies": {
"@elastic/datemath": "^5.0.2",
"@emotion/react": "11.x",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.6",
"moment": "^2.13.0",
Expand Down
11 changes: 9 additions & 2 deletions scripts/compile-scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function compileScssFiles({

const inputFilenames = (await glob(sourcePattern, undefined)).filter(filename => {
if (targetTheme == null) return true;
return filename === `src/theme_${targetTheme}.scss`;
return filename === `src/themes/amsterdam/theme_${targetTheme}.scss`;
});

await Promise.all(
Expand Down Expand Up @@ -147,7 +147,14 @@ if (require.main === module) {
}

compileScssFiles({
sourcePattern: path.join('src', 'theme_*.scss'),
sourcePattern: path.join('src/themes/legacy', 'legacy_*.scss'),
destinationDirectory: 'dist',
docsVariablesDirectory: 'src-docs/src/views/theme/_json',
packageName: euiPackageName
});

compileScssFiles({
sourcePattern: path.join('src/themes/amsterdam', 'theme_*.scss'),
destinationDirectory: 'dist',
docsVariablesDirectory: 'src-docs/src/views/theme/_json',
packageName: euiPackageName
Expand Down
2 changes: 1 addition & 1 deletion scripts/cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const log = chalk.grey;
if (!skipScss) {
console.log(info('Compiling SCSS'));
execSync(
`TARGET_THEME=amsterdam_dark yarn compile-scss`,
`TARGET_THEME=dark yarn compile-scss`,
{
stdio: 'inherit'
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/jest/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"^.+\\.(js|tsx?)$": "babel-jest"
},
"snapshotSerializers": [
"<rootDir>/node_modules/enzyme-to-json/serializer"
"<rootDir>/node_modules/enzyme-to-json/serializer",
"@emotion/jest/enzyme-serializer"
]
}
4 changes: 2 additions & 2 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ async function getVersionTypeFromChangelog() {
//
// "##.+?[\r\n]+" consume the first heading & linebreak(s), which describes the main branch
// "(.+?)" capture (non-greedy) all changes until the rest of the regex matches
// "[\r\n]+##" any linebreak(s) leading up to the next ## heading
// "[\r\n]+##(?= \[`\d)" any linebreak(s) leading up to the next ## heading with a numbered release, e.g. [`1.0.0`]
//
// regex flags "su" enable dotAll (s) and unicode-character matching (u)
//
// effectively capturing pending changes in the capture group
// which is stored as the second item in the returned array from `changelog.match()`
const [, unreleasedchanges] = changelog.match(/##.+?[\r\n]+(.+?)[\r\n]+##/su);
const [, unreleasedchanges] = changelog.match(/##.+?[\r\n]+(.+?)[\r\n]+##(?= \[`\d)/su);

// these changes contain bug fixes if the string "**bug fixes**" exists
const hasBugFixes = unreleasedchanges.toLowerCase().indexOf('**bug fixes**') !== -1;
Expand Down
6 changes: 0 additions & 6 deletions src-docs/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ 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
78 changes: 61 additions & 17 deletions src-docs/src/components/codesandbox/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
hasDisplayToggles,
listExtraDeps,
} from '../../services';
import { LEGACY_NAME_KEY } from '../../../../src/themes';

import { ThemeContext } from '../with_theme';

const pkg = require('../../../../package.json');

Expand All @@ -26,7 +29,6 @@ const getVersion = (packageName) => {
* 5. Through regex we read the dependencies of both `content` and `display_toggles` and pass that to CS.
* 6. We pass the files and dependencies as params to CS through a POST call.
* */
import { ThemeContext } from '../with_theme';

const displayTogglesRawCode = require('!!raw-loader!../../views/form_controls/display_toggles')
.default;
Expand All @@ -49,11 +51,11 @@ export const CodeSandboxLinkComponent = ({
}) => {
let cssFile;
switch (context.theme) {
case 'amsterdam-light':
cssFile = '@elastic/eui/dist/eui_theme_amsterdam_light.css';
case `${LEGACY_NAME_KEY}_light`:
cssFile = '@elastic/eui/dist/eui_legacy_light.css';
break;
case 'amsterdam-dark':
cssFile = '@elastic/eui/dist/eui_theme_amsterdam_dark.css';
case `${LEGACY_NAME_KEY}_dark`:
cssFile = '@elastic/eui/dist/eui_legacy_dark.css';
break;
case 'dark':
cssFile = '@elastic/eui/dist/eui_theme_dark.css';
Expand All @@ -63,6 +65,33 @@ export const CodeSandboxLinkComponent = ({
break;
}

const isLegacyTheme = context.theme.includes(LEGACY_NAME_KEY);

const providerPropsObject = {};
// Only add configuration if it isn't the default
if (context.theme.includes('dark')) {
providerPropsObject.colorMode = 'dark';
}
// Can't spread an object inside of a string literal
const providerProps = Object.keys(providerPropsObject)
.map((prop) => {
const value = providerPropsObject[prop];
return value !== null ? `${prop}="${value}"` : `${prop}={${value}}`;
})
.join(' ');

// Renders the new Demo component generically into the code sandbox page
const exampleClose = `ReactDOM.render(
${
isLegacyTheme
? '<Demo />'
: `<EuiProvider ${providerProps}>
<Demo />
</EuiProvider>`
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
},
document.getElementById('root')
);`;

let indexContent;

if (!content) {
Expand All @@ -72,28 +101,48 @@ import '${cssFile}';
import React from 'react';

import {
EuiButton,
${
isLegacyTheme
? 'EuiButton,'
: `EuiButton,
EuiProvider,`
}
} from '@elastic/eui';

const Demo = () => (<EuiButton>Hello world!</EuiButton>);

ReactDOM.render(
<Demo />,
document.getElementById('root')
);
${exampleClose}
`;
} else {
/** This cleans the Demo JS example for Code Sanbox.
- Replaces relative imports with pure @elastic/eui ones
- Adds provider import, if necessary
- Changes the JS example from a default export to a component const named Demo
**/
const exampleCleaned = cleanEuiImports(content)
let exampleCleaned = cleanEuiImports(content)
.replace('export default', 'const Demo =')
.replace(
/(from )'(..\/)+display_toggles(\/?';)/,
"from './display_toggles';"
);

if (!isLegacyTheme && !exampleCleaned.includes('EuiProvider')) {
if (exampleCleaned.includes(" } from '@elastic/eui';")) {
// Single line import statement
exampleCleaned = exampleCleaned.replace(
" } from '@elastic/eui';",
", EuiProvider } from '@elastic/eui';"
);
} else {
// Multi line import statement
exampleCleaned = exampleCleaned.replace(
"} from '@elastic/eui';",
` EuiProvider,
} from '@elastic/eui';`
);
}
}

// If the code example still has local doc imports after the above cleaning it's
// too complicated for code sandbox so we don't provide a link
const hasLocalImports = /(from )'((.|..)\/).*?';/.test(exampleCleaned);
Expand All @@ -102,11 +151,6 @@ ReactDOM.render(
return null;
}

// Renders the new Demo component generically into the code sandbox page
const exampleClose = `ReactDOM.render(
<Demo />,
document.getElementById('root')
);`;
// The Code Sanbbox demo needs to import CSS at the top of the document. CS has trouble
// with our dynamic imports so we need to warn the user for now
const exampleStart = `import ReactDOM from 'react-dom';
Expand All @@ -116,7 +160,7 @@ import '${cssFile}';`;
const cleanedContent = `${exampleStart}
${exampleCleaned}
${exampleClose}
`;
`;
indexContent = cleanedContent.replace(
/(from )'.+display_toggles';/,
"from './display_toggles';"
Expand Down
2 changes: 2 additions & 0 deletions src-docs/src/components/guide_page/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { GuidePage } from './guide_page';

export { GuidePageChrome } from './guide_page_chrome';

export { GuidePageHeader } from './guide_page_header';
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Knobs from '../../../services/playground/knobs';
import { propUtilityForPlayground } from '../../../services/playground';

export type GuideSectionPropsTable = {
componentName: any;
componentName?: any;
component: any;
};

Expand All @@ -25,10 +25,12 @@ export const GuideSectionPropsTable: FunctionComponent<GuideSectionPropsTable> =

return (
<div>
<GuideSectionPropsDescription
componentName={componentName}
component={component}
/>
{componentName && (
<GuideSectionPropsDescription
componentName={componentName}
component={component}
/>
)}
<PlaygroundProps
isPlayground={false}
config={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const GuideFigmaLinkComponent: React.FunctionComponent<GuideFigmaLinkProps> = ({
}) => {
const isMobileSize = useIsWithinBreakpoints(['xs', 's']);

const isAmsterdam = context.theme.includes('amsterdam');
const isLegacy = context.theme.includes('legacy');

let href = 'https://www.figma.com/community/file/809845546262698150';
let href = 'https://www.figma.com/community/file/964536385682658129';
const label = 'EUI Figma Design Library';

if (isAmsterdam) {
href = 'https://www.figma.com/community/file/964536385682658129';
if (isLegacy) {
href = 'https://www.figma.com/community/file/809845546262698150';
}

return isMobileSize ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const GuideSketchLinkComponent: React.FunctionComponent<GuideSketchLinkProps> =
'https://github.com/elastic/eui/releases/download/v8.0.0/eui_sketch_8.0.0.zip';
const label = 'EUI Sketch Library (download)';

const isAmsterdam = context.theme.includes('amsterdam');
const isLegacy = context.theme.includes('legacy');

if (isAmsterdam) return <></>;
if (!isLegacy) return <></>;

return isMobileSize ? (
<EuiButtonEmpty size="s" flush="both" iconType="logoSketch" href={href}>
Expand Down
Loading