diff --git a/.eslintrc.js b/.eslintrc.js index b813d1fe6..e4861d7c1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,5 +11,6 @@ module.exports = { rules: { 'no-use-before-define': 'off', 'react/react-in-jsx-scope': 'off', + '@typescript-eslint/no-redeclare': 'off', }, } diff --git a/packages/color-modes/src/index.tsx b/packages/color-modes/src/index.tsx index 9f17e8c85..ad3a84771 100644 --- a/packages/color-modes/src/index.tsx +++ b/packages/color-modes/src/index.tsx @@ -146,7 +146,7 @@ export function useColorMode(): [ } // We're allowing the user to specify a narrower type for its color mode name. - return ([colorMode, setColorMode] as unknown) as [ + return [colorMode, setColorMode] as unknown as [ T, Dispatch> ] diff --git a/packages/components/src/Input.js b/packages/components/src/Input.js index 3f17a0553..9132990c7 100644 --- a/packages/components/src/Input.js +++ b/packages/components/src/Input.js @@ -1,26 +1,52 @@ import React from 'react' import Box from './Box' -export const Input = React.forwardRef(function Input(props, ref) { +import { get } from '@theme-ui/css' + +/** @type {import('theme-ui').ThemeUIStyleObject} */ +const autofillStyles = { + boxShadow: 'inset 0 0 0 1000px var(--theme-ui-input-autofill-bg)', + fontSize: 'inherit', + ':first-line': { + fontSize: '1rem', + }, +} + +/** @type {import('theme-ui').ThemeUIStyleObject} */ +const defaultInputStyles = { + display: 'block', + width: '100%', + p: 2, + appearance: 'none', + fontSize: 'inherit', + lineHeight: 'inherit', + border: '1px solid', + borderRadius: 4, + color: 'inherit', + bg: 'transparent', + + ':autofill, :autofill:hover, :autofill:focus': autofillStyles, + ':-webkit-autofill, :-webkit-autofill:hover, :-webkit-autofill:focus': + autofillStyles, +} + +export const Input = React.forwardRef(function Input( + { sx, autofillBackgroundColor = 'background', ...rest }, + ref +) { return ( + get(theme.colors, autofillBackgroundColor, null), + ...sx, }} + {...rest} + __themeKey="forms" + __css={defaultInputStyles} /> ) }) diff --git a/packages/components/test/__snapshots__/index.js.snap b/packages/components/test/__snapshots__/index.js.snap index 085cdb65c..5dc4c641e 100644 --- a/packages/components/test/__snapshots__/index.js.snap +++ b/packages/components/test/__snapshots__/index.js.snap @@ -617,6 +617,32 @@ exports[`Field renders 1`] = ` background-color: transparent; } +.emotion-2:autofill, +.emotion-2:autofill:hover, +.emotion-2:autofill:focus { + box-shadow: inset 0 0 0 1000px var(--theme-ui-input-autofill-bg); + font-size: inherit; +} + +.emotion-2:autofill:first-line, +.emotion-2:autofill:hover:first-line, +.emotion-2:autofill:focus:first-line { + font-size: 1rem; +} + +.emotion-2:-webkit-autofill, +.emotion-2:-webkit-autofill:hover, +.emotion-2:-webkit-autofill:focus { + box-shadow: inset 0 0 0 1000px var(--theme-ui-input-autofill-bg); + font-size: inherit; +} + +.emotion-2:-webkit-autofill:first-line, +.emotion-2:-webkit-autofill:hover:first-line, +.emotion-2:-webkit-autofill:focus:first-line { + font-size: 1rem; +} +
@@ -666,6 +692,32 @@ exports[`Field renders with id prop 1`] = ` background-color: transparent; } +.emotion-2:autofill, +.emotion-2:autofill:hover, +.emotion-2:autofill:focus { + box-shadow: inset 0 0 0 1000px var(--theme-ui-input-autofill-bg); + font-size: inherit; +} + +.emotion-2:autofill:first-line, +.emotion-2:autofill:hover:first-line, +.emotion-2:autofill:focus:first-line { + font-size: 1rem; +} + +.emotion-2:-webkit-autofill, +.emotion-2:-webkit-autofill:hover, +.emotion-2:-webkit-autofill:focus { + box-shadow: inset 0 0 0 1000px var(--theme-ui-input-autofill-bg); + font-size: inherit; +} + +.emotion-2:-webkit-autofill:first-line, +.emotion-2:-webkit-autofill:hover:first-line, +.emotion-2:-webkit-autofill:focus:first-line { + font-size: 1rem; +} +
@@ -947,6 +999,32 @@ exports[`Input renders 1`] = ` background-color: transparent; } +.emotion-0:autofill, +.emotion-0:autofill:hover, +.emotion-0:autofill:focus { + box-shadow: inset 0 0 0 1000px var(--theme-ui-input-autofill-bg); + font-size: inherit; +} + +.emotion-0:autofill:first-line, +.emotion-0:autofill:hover:first-line, +.emotion-0:autofill:focus:first-line { + font-size: 1rem; +} + +.emotion-0:-webkit-autofill, +.emotion-0:-webkit-autofill:hover, +.emotion-0:-webkit-autofill:focus { + box-shadow: inset 0 0 0 1000px var(--theme-ui-input-autofill-bg); + font-size: inherit; +} + +.emotion-0:-webkit-autofill:first-line, +.emotion-0:-webkit-autofill:hover:first-line, +.emotion-0:-webkit-autofill:focus:first-line { + font-size: 1rem; +} + diff --git a/packages/docs/src/components/head.js b/packages/docs/src/components/head.js index 2f4d2f606..04129a793 100644 --- a/packages/docs/src/components/head.js +++ b/packages/docs/src/components/head.js @@ -13,7 +13,9 @@ export default (props) => { .filter(Boolean) .join(' – ') - const { theme } = useThemeUI() + const { theme, colorMode } = useThemeUI() + + const isColorModeDark = ['dark', 'deep'].includes(colorMode) return ( @@ -32,7 +34,10 @@ export default (props) => { + + +