From 03e6c434ea91e31a521e8e86ed106a205c65d117 Mon Sep 17 00:00:00 2001 From: hasparus Date: Thu, 10 Jun 2021 13:11:08 +0200 Subject: [PATCH 1/4] feat(components): style autofilled Input background --- packages/components/src/Input.js | 54 +++++++++++++++----- packages/docs/src/pages/components/input.mdx | 12 ++++- 2 files changed, 51 insertions(+), 15 deletions(-) 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/docs/src/pages/components/input.mdx b/packages/docs/src/pages/components/input.mdx index 4124f7418..2152fe547 100644 --- a/packages/docs/src/pages/components/input.mdx +++ b/packages/docs/src/pages/components/input.mdx @@ -16,4 +16,14 @@ import { Input } from 'theme-ui' ## Variants -Input variants can be defined in `theme.forms` and the component uses the `theme.forms.input` variant by default. +Input variants can be defined in `theme.forms` and the component uses the +`theme.forms.input` variant by default. + +## Autocomplete styles + +Background color of autofilled inputs defaults to `background`, and can be +changed by setting `autofillBackgroundColor` prop. + +```js live=true + +``` From dfda364ea0924bdc5746617d3ee7ccd29a2e7e8c Mon Sep 17 00:00:00 2001 From: hasparus Date: Thu, 10 Jun 2021 13:13:50 +0200 Subject: [PATCH 2/4] docs(components): move Select ##Variants section above custom arrow docs --- packages/docs/src/pages/components/select.mdx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/docs/src/pages/components/select.mdx b/packages/docs/src/pages/components/select.mdx index c1309bae8..3f67aa2ca 100644 --- a/packages/docs/src/pages/components/select.mdx +++ b/packages/docs/src/pages/components/select.mdx @@ -19,6 +19,11 @@ import { Select, Box } from 'theme-ui' ``` +## Variants + +Select variants can be defined in `theme.forms` and the component uses the +`theme.forms.select` variant by default. + ## Custom arrow icon ```jsx live=true @@ -46,7 +51,3 @@ import { Select, Box } from 'theme-ui' ``` - -## Variants - -Select variants can be defined in `theme.forms` and the component uses the `theme.forms.select` variant by default. From 5178a47c5f74d034302ea224cf02b9923b2dadce Mon Sep 17 00:00:00 2001 From: hasparus Date: Thu, 10 Jun 2021 13:49:37 +0200 Subject: [PATCH 3/4] docs: set (): [ } // 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/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) => { + + +