UNPKG

@workday/canvas-kit-preview-react

Version:

Canvas Kit Preview is made up of components that have the full design and a11y review, are part of the DS ecosystem and are approved for use in product. The API's could be subject to change, but not without strong communication and migration strategies.

51 lines (50 loc) 2.18 kB
/** @jsxRuntime classic */ /** @jsx jsx */ import { jsx } from '@emotion/react'; import { borderRadius, colors, inputColors, space, type, } from '@workday/canvas-kit-react/tokens'; import { createSubcomponent, useTheme, useThemedRing, } from '@workday/canvas-kit-react/common'; import { FormField } from '@workday/canvas-kit-react/form-field'; import { useTextInputField, useTextInputModel } from './hooks'; const baseStyles = { transition: '0.2s box-shadow, 0.2s border-color', '&::placeholder': { color: inputColors.placeholder, }, '&:hover': { borderColor: inputColors.hoverBorder, }, '&:focus:not([disabled])': { outline: 'none', }, '&:disabled': { backgroundColor: inputColors.disabled.background, borderColor: colors.licorice100, color: inputColors.disabled.text, '&::placeholder': { color: inputColors.disabled.text, }, }, '::-ms-clear': { display: 'none', }, }; /** * @deprecated ⚠️ `TextInputField` in Preview has been deprecated and will be removed in a future major version. Please use [`FormField` in Preview](https://workday.github.io/canvas-kit/?path=/story/preview-inputs-form-field--basic) instead. */ export const TextInputField = createSubcomponent('input')({ displayName: 'TextInput.Field', modelHook: useTextInputModel, elemPropsHook: useTextInputField, })((elemProps, Element, model) => { const theme = useTheme(); const errorRing = useThemedRing('error'); const focusStyles = model.state.error === 'error' ? errorRing : { '&:focus:not([disabled])': { borderColor: theme.canvas.palette.common.focusOutline, boxShadow: `inset 0 0 0 1px ${theme.canvas.palette.common.focusOutline}`, }, }; return (jsx(FormField.Input, { as: "input", ...type.levels.subtext.large, css: [baseStyles, focusStyles], padding: space.xxs, margin: 0, display: "block", height: "40px", minWidth: "280px", border: `1px solid ${inputColors.border}`, backgroundColor: inputColors.background, borderRadius: borderRadius.m, ...elemProps })); });