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

Automatic CSS Variable fallbacks (Components CSS) #24094

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4,971 changes: 3,864 additions & 1,107 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
],
"dependencies": {
"@babel/runtime": "^7.11.2",
"@emotion/cache": "^10.0.22",
"@emotion/core": "^10.0.22",
"@emotion/css": "^10.0.22",
"@emotion/native": "^10.0.22",
Expand Down Expand Up @@ -60,6 +61,7 @@
"react-use-gesture": "^7.0.15",
"reakit": "^1.1.0",
"rememo": "^3.0.0",
"stylis-plugin-css-variables": "^1.0.6",
"tinycolor2": "^1.4.1",
"uuid": "^8.3.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const Container = styled.div`

export const Side = styled.div`
box-sizing: border-box;
background: ${ color( 'blue.wordpress.700' ) };
background: ${ color( 'ui.theme' ) };
filter: brightness( 1 );
opacity: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ export const PointerIconPathOutline = styled( Path )`
`;

export const PointerIconPathFill = styled( Path )`
fill: ${ color( 'blue.wordpress.700' ) };
fill: ${ color( 'ui.theme' ) };
`;
1 change: 1 addition & 0 deletions packages/components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export { default as SelectControl } from './select-control';
export { default as Snackbar } from './snackbar';
export { default as SnackbarList } from './snackbar/list';
export { default as Spinner } from './spinner';
export { default as __experimentalStyledProvider } from './styled-provider';
export { default as TabPanel } from './tab-panel';
export { default as __experimentalText } from './text';
export { default as TextControl } from './text-control';
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export { default as ExternalLink } from './external-link';
export { default as TextControl } from './text-control';
export { default as ToggleControl } from './toggle-control';
export { default as SelectControl } from './select-control';
export { default as __experimentalStyledProvider } from './styled-provider';
export { default as RangeControl } from './range-control';
export { default as ResizableBox } from './resizable-box';
export { default as FooterMessageControl } from './footer-message-control';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const wrapperMargin = ( { marks } ) =>

export const Wrapper = styled.span`
box-sizing: border-box;
color: ${ color( 'blue.medium.focus' ) };
display: block;
flex: 1;
padding-top: 15px;
Expand Down
23 changes: 23 additions & 0 deletions packages/components/src/styled-provider/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* External dependencies
*/
import createEmotionCache from '@emotion/cache';
import { CacheProvider } from '@emotion/core';
import stylisPluginCssVariables from 'stylis-plugin-css-variables';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code originally existed in this repo as part of this PR.
It was abstracted to a separate repo/package:
https://github.com/ItsJonQ/stylis-plugin-css-variables

import memoize from 'memize';

const createCustomCache = memoize( () => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technique suggested by a core Emotion member:
emotion-js/emotion#760 (comment)

return createEmotionCache( {
stylisPlugins: [ stylisPluginCssVariables() ],
} );
} );

function StyledProvider( { children, ...props } ) {
return (
<CacheProvider { ...props } value={ createCustomCache() }>
{ children }
</CacheProvider>
);
}

export default StyledProvider;
6 changes: 6 additions & 0 deletions packages/components/src/styled-provider/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Implementation not required (at the moment) for react-native style rendering.
*/
export default function StyledProvider( { children } ) {
return children;
}
5 changes: 3 additions & 2 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Popover,
FocusReturnProvider,
Button,
__experimentalStyledProvider as StyledProvider,
} from '@wordpress/components';
import { EntityProvider } from '@wordpress/core-data';
import {
Expand Down Expand Up @@ -165,7 +166,7 @@ function Editor() {
}, [ isNavigationOpen ] );

return (
<>
<StyledProvider>
<EditorStyles styles={ settings.styles } />
<FullscreenMode isActive={ isFullscreenActive } />
<UnsavedChangesWarning />
Expand Down Expand Up @@ -293,7 +294,7 @@ function Editor() {
</EntityProvider>
</DropZoneProvider>
</SlotFillProvider>
</>
</StyledProvider>
);
}
export default Editor;
5 changes: 3 additions & 2 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import memize from 'memize';
/**
* WordPress dependencies
*/
import { __experimentalStyledProvider as StyledProvider } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { Component } from '@wordpress/element';
import { withDispatch, withSelect } from '@wordpress/data';
Expand Down Expand Up @@ -271,7 +272,7 @@ class EditorProvider extends Component {
);

return (
<>
<StyledProvider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables it for the post-editor (probably better moved to edit-post) but not for edit-widgets, edit-site, edit-navigation and list-reusabale-blocks (these are the top level packages).

  • How do we make sure folks don't forget to add these providers?
  • Is there a way to throw a warning if we detect a missing provider?
  • Should we embed other providers there in a single one? (thinking about popover and slot providers).
  • Should this be marked as a breaking change in the changelog of the components package?

<EditorStyles styles={ settings.styles } />
<EntityProvider kind="root" type="site">
<EntityProvider
Expand All @@ -296,7 +297,7 @@ class EditorProvider extends Component {
</BlockContextProvider>
</EntityProvider>
</EntityProvider>
</>
</StyledProvider>
);
}
}
Expand Down
1 change: 1 addition & 0 deletions storybook/decorators/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as withStyledProvider } from './with-styled-provider';
10 changes: 10 additions & 0 deletions storybook/decorators/with-styled-provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Internal dependencies
*/
import { __experimentalStyledProvider as StyledProvider } from '../../packages/components/src/index';

function withStyledProvider( storyFn ) {
return <StyledProvider>{ storyFn() }</StyledProvider>;
}

export default withStyledProvider;
2 changes: 2 additions & 0 deletions storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import '@wordpress/components/build-style/style.css';
/**
* Internal dependencies
*/
import { withStyledProvider } from './decorators';
import './style.scss';

addDecorator( withA11y );
addDecorator( withKnobs );
addDecorator( withStyledProvider );