Use constants instead of writing overrides inline.
Overrides in baseui can be overwhelming when using them inline. This plugin solves that by enforcing users to spread the overrides prop into the component, so you can focus on the logic!
You'll first need to install ESLint:
npm i eslint --save-devNext, install eslint-plugin-baseui-clean-overrides:
npm install eslint-plugin-baseui-clean-overrides --save-devAdd baseui-clean-overrides to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"plugins": [
"baseui-clean-overrides"
]
}Then configure to use the basic rule under the rules section.
{
"rules": {
"baseui-clean-overrides/basic": 2
}
}import React, { useState } from "react";
import { Input } from "baseui/input";
const inputOverrides = {
overrides: {
Root: {
style: ({ $theme }) => ({
outline: `${$theme.colors.warning600} solid`,
backgroundColor: $theme.colors.warning600
})
}
}
}
export default () => {
const [value, setValue] = useState("");
return (
<Input
value={value}
onChange={e => setValue(e.target.value)}
placeholder="Controlled Input"
{...inputOverrides}
/>
);
}import React, { useState } from "react";
import { Input } from "baseui/input";
export default () => {
const [value, setValue] = useState("");
return (
<Input
value={value}
onChange={e => setValue(e.target.value)}
placeholder="Controlled Input"
overrides={{
Root: {
style: ({ $theme }) => ({
outline: `${$theme.colors.warning600} solid`,
backgroundColor: $theme.colors.warning600
})
},
}}
/>
);
}