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

Replace prop css with emotion className #1

Merged
merged 3 commits into from
Dec 11, 2018
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"url": "https://github.com/JedWatson/react-select.git"
},
"dependencies": {
"@emotion/memoize": "^0.7.1",
"classnames": "^2.2.5",
"create-emotion": "^10.0.4",
"emotion": "^9.1.2",
Expand Down
10 changes: 7 additions & 3 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React, { Component, type ElementRef, type Node } from 'react';

import memoizeOne from 'memoize-one';
import memoize from '@emotion/memoize';
import createEmotion from 'create-emotion';
import { MenuPlacer } from './components/Menu';
import isEqual from './internal/react-fast-compare';
Expand Down Expand Up @@ -372,7 +373,8 @@ export default class Select extends Component<Props, State> {
const selectValue = cleanValue(value);
const menuOptions = this.buildMenuOptions(props, selectValue);

this.emotion = createEmotion(props.nonce ? { nonce: props.nonce } : {});
this.createEmotion = memoize(createEmotion);
this.emotion = this.createEmotion(props.nonce ? { nonce: props.nonce } : {});

this.state.menuOptions = menuOptions;
this.state.selectValue = selectValue;
Expand Down Expand Up @@ -1376,6 +1378,7 @@ export default class Select extends Component<Props, State> {
disabled={isDisabled}
tabIndex={tabIndex}
value=""
emotion={this.emotion}
/>
);
}
Expand Down Expand Up @@ -1408,6 +1411,7 @@ export default class Select extends Component<Props, State> {
theme={theme}
type="text"
value={inputValue}
emotion={this.emotion}
{...ariaAttributes}
/>
);
Expand Down Expand Up @@ -1685,7 +1689,7 @@ export default class Select extends Component<Props, State> {
onTopArrive={onMenuScrollToTop}
onBottomArrive={onMenuScrollToBottom}
>
<ScrollBlock isEnabled={menuShouldBlockScroll}>
<ScrollBlock emotion={this.emotion} isEnabled={menuShouldBlockScroll}>
<MenuList
{...commonProps}
innerRef={this.getMenuListRef}
Expand Down Expand Up @@ -1756,7 +1760,7 @@ export default class Select extends Component<Props, State> {
renderLiveRegion() {
if (!this.state.isFocused) return null;
return (
<A11yText aria-live="assertive">
<A11yText emotion={this.emotion} aria-live="assertive">
<p id="aria-selection-event">&nbsp;{this.state.ariaLiveSelection}</p>
<p id="aria-context">&nbsp;{this.constructAriaLiveMessage()}</p>
</A11yText>
Expand Down
822 changes: 593 additions & 229 deletions src/__tests__/__snapshots__/Async.test.js.snap

Large diffs are not rendered by default.

822 changes: 593 additions & 229 deletions src/__tests__/__snapshots__/AsyncCreatable.test.js.snap

Large diffs are not rendered by default.

152 changes: 54 additions & 98 deletions src/__tests__/__snapshots__/Select.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ exports[`snapshot - defaults 1`] = `
"registered": Object {},
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand All @@ -40,13 +34,7 @@ exports[`snapshot - defaults 1`] = `
"merge": [Function],
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand Down Expand Up @@ -156,13 +144,7 @@ exports[`snapshot - defaults 1`] = `
"registered": Object {},
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand All @@ -181,13 +163,7 @@ exports[`snapshot - defaults 1`] = `
"merge": [Function],
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand Down Expand Up @@ -298,13 +274,7 @@ exports[`snapshot - defaults 1`] = `
"registered": Object {},
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand All @@ -323,13 +293,7 @@ exports[`snapshot - defaults 1`] = `
"merge": [Function],
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand Down Expand Up @@ -432,13 +396,7 @@ exports[`snapshot - defaults 1`] = `
"registered": Object {},
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand All @@ -457,13 +415,7 @@ exports[`snapshot - defaults 1`] = `
"merge": [Function],
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand Down Expand Up @@ -562,6 +514,46 @@ exports[`snapshot - defaults 1`] = `
autoComplete="off"
autoCorrect="off"
cx={[Function]}
emotion={
Object {
"cache": Object {
"compat": true,
"insert": [Function],
"inserted": Object {},
"key": "css",
"nonce": undefined,
"registered": Object {},
"sheet": StyleSheet {
"before": null,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
"nonce": undefined,
"speedy": [Function],
"tags": Array [],
},
},
"css": [Function],
"cx": [Function],
"flush": [Function],
"getRegisteredStyles": [Function],
"hydrate": [Function],
"injectGlobal": [Function],
"keyframes": [Function],
"merge": [Function],
"sheet": StyleSheet {
"before": null,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
"nonce": undefined,
"speedy": [Function],
"tags": Array [],
},
}
}
getStyles={[Function]}
id="react-select-2-input"
innerRef={[Function]}
Expand Down Expand Up @@ -618,13 +610,7 @@ exports[`snapshot - defaults 1`] = `
"registered": Object {},
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand All @@ -643,13 +629,7 @@ exports[`snapshot - defaults 1`] = `
"merge": [Function],
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand Down Expand Up @@ -752,13 +732,7 @@ exports[`snapshot - defaults 1`] = `
"registered": Object {},
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand All @@ -777,13 +751,7 @@ exports[`snapshot - defaults 1`] = `
"merge": [Function],
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand Down Expand Up @@ -887,13 +855,7 @@ exports[`snapshot - defaults 1`] = `
"registered": Object {},
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand All @@ -912,13 +874,7 @@ exports[`snapshot - defaults 1`] = `
"merge": [Function],
"sheet": StyleSheet {
"before": null,
"container": <head>
<style
data-emotion=""
>

</style>
</head>,
"container": <head />,
"ctr": 0,
"isSpeedy": false,
"key": "css",
Expand Down
4 changes: 3 additions & 1 deletion src/components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type InputProps = PropsWithStyles & {
/** Whether the input is disabled */
isDisabled?: boolean,
className?: string,
emotion: any,
};

export const inputCSS = ({ isDisabled, theme: { spacing, colors } }: InputProps) => ({
Expand Down Expand Up @@ -40,9 +41,10 @@ const Input = ({
isHidden,
isDisabled,
theme,
emotion,
...props
}: InputProps) => (
<div css={getStyles('input', { theme, ...props })}>
<div className={emotion.css(getStyles('input', { theme, ...props }))}>
<AutosizeInput
className={cx(null, { 'input': true }, className)}
inputRef={innerRef}
Expand Down
14 changes: 7 additions & 7 deletions src/components/indicators.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ export const loadingIndicatorCSS = ({
verticalAlign: 'middle',
});

type DotProps = { color: string, delay: number, offset: boolean };
const LoadingDot = ({ color, delay, offset }: DotProps) => (
type DotProps = { color: string, delay: number, offset: boolean, emotion: any };
const LoadingDot = ({ color, delay, offset, emotion }: DotProps) => (
<span
css={{
className={emotion.css({
animationDuration: '1s',
animationDelay: `${delay}ms`,
animationIterationCount: 'infinite',
Expand All @@ -180,7 +180,7 @@ const LoadingDot = ({ color, delay, offset }: DotProps) => (
height: '1em',
verticalAlign: 'top',
width: '1em',
}}
})}
/>
);

Expand Down Expand Up @@ -220,9 +220,9 @@ export const LoadingIndicator = (props: LoadingIconProps) => {
className
)}
>
<LoadingDot color={color} delay={0} offset={isRtl} />
<LoadingDot color={color} delay={160} offset />
<LoadingDot color={color} delay={320} offset={!isRtl} />
<LoadingDot emotion={emotion} color={color} delay={0} offset={isRtl} />
<LoadingDot emotion={emotion} color={color} delay={160} offset />
<LoadingDot emotion={emotion} color={color} delay={320} offset={!isRtl} />
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/internal/A11yText.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
// Assistive text to describe visual elements. Hidden for sighted users.
const A11yText = (props: any) => (
<span
css={{
className={props.emotion.css({
zIndex: 9999,
border: 0,
clip: 'rect(1px, 1px, 1px, 1px)',
Expand All @@ -16,7 +16,7 @@ const A11yText = (props: any) => (
whiteSpace: 'nowrap',
backgroundColor: 'red',
color: 'blue',
}}
})}
{...props}
/>
);
Expand Down
Loading