mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Use React.Context for controlling input theme in Dialogs
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
310a2f14d9
commit
e7c3808d02
@ -12,6 +12,7 @@ import { reaction } from "mobx";
|
||||
import { Animate } from "../animate";
|
||||
import { cssNames, noop, stopPropagation } from "../../utils";
|
||||
import { navigation } from "../../navigation";
|
||||
import { InputThemeContext } from "../input";
|
||||
|
||||
// todo: refactor + handle animation-end in props.onClose()?
|
||||
|
||||
@ -139,16 +140,18 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
|
||||
|
||||
className = cssNames("Dialog flex center", className, { modal, pinned });
|
||||
let dialog = (
|
||||
<div
|
||||
className={className}
|
||||
onClick={stopPropagation}
|
||||
ref={this.ref}
|
||||
data-testid={testId}
|
||||
>
|
||||
<div className="box" ref={e => this.contentElem = e}>
|
||||
{this.props.children}
|
||||
<InputThemeContext.Provider value="light">
|
||||
<div
|
||||
className={className}
|
||||
onClick={stopPropagation}
|
||||
ref={this.ref}
|
||||
data-testid={testId}
|
||||
>
|
||||
<div className="box" ref={e => this.contentElem = e}>
|
||||
{this.props.children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</InputThemeContext.Provider>
|
||||
);
|
||||
|
||||
if (animated) {
|
||||
|
||||
@ -70,6 +70,8 @@ interface State {
|
||||
submitted: boolean;
|
||||
}
|
||||
|
||||
export const InputThemeContext = React.createContext("dark");
|
||||
|
||||
const defaultProps: Partial<InputProps> = {
|
||||
rows: 1,
|
||||
maxRows: 10000,
|
||||
@ -347,9 +349,10 @@ export class Input extends React.Component<InputProps, State> {
|
||||
...inputProps
|
||||
} = this.props;
|
||||
const { dirty, valid, validating, errors } = this.state;
|
||||
const theme = this.context;
|
||||
|
||||
const className = cssNames(styles.Input, this.props.className, {
|
||||
[styles.lightTheme]: lightTheme,
|
||||
[styles.lightTheme]: lightTheme || theme == "light",
|
||||
[styles.disabled]: disabled,
|
||||
[styles.invalid]: !valid,
|
||||
[styles.dirty]: dirty,
|
||||
@ -413,3 +416,5 @@ export class Input extends React.Component<InputProps, State> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Input.contextType = InputThemeContext;
|
||||
Loading…
Reference in New Issue
Block a user