From 1fde94bf707bd264d6c17f0710f4656aa1d1ab52 Mon Sep 17 00:00:00 2001 From: cc <33281802+matuancc@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:11:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Textarea):=20=E9=87=8D=E6=9E=84Textare?= =?UTF-8?q?a=E6=A0=B7=E5=BC=8F=20(#861=EF=BC=8C#845)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/react-textarea/src/index.tsx | 10 ++- packages/react-textarea/src/style/index.ts | 76 ++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 packages/react-textarea/src/style/index.ts diff --git a/packages/react-textarea/src/index.tsx b/packages/react-textarea/src/index.tsx index ea393a568f..b27447a576 100644 --- a/packages/react-textarea/src/index.tsx +++ b/packages/react-textarea/src/index.tsx @@ -1,14 +1,18 @@ import React from 'react'; import { IProps, HTMLTextProps } from '@uiw/utils'; -import './style/index.less'; +// import './style/index.less'; +import { TextareaWarp } from './style/index'; export interface TextareaProps extends IProps, HTMLTextProps {} export default React.forwardRef((props, ref) => { const { prefixCls = 'w-textarea', className, ...restProps } = props; + { + console.log('1111', props); + } return ( - + ); }); diff --git a/packages/react-textarea/src/style/index.ts b/packages/react-textarea/src/style/index.ts new file mode 100644 index 0000000000..a13310f6e7 --- /dev/null +++ b/packages/react-textarea/src/style/index.ts @@ -0,0 +1,76 @@ +import { getThemeVariantValue } from '@uiw/utils'; +import styled from 'styled-components'; +import { TextareaProps } from '../index'; + +interface TextareaWarpProps extends TextareaProps { + defaultTheme?: Record; +} + +export const TextareaWarp = styled.textarea` + position: relative; + font-size: ${(props) => getThemeVariantValue(props, 'fontSizeDefault')}; + outline: none; + border: none; + border-radius: ${(props) => getThemeVariantValue(props, 'borderRadiusDefault')}; + box-shadow: ${(props) => getThemeVariantValue(props, 'boxShadowTextarea')}; + padding: 5px 10px; + vertical-align: middle; + height: auto; + min-height: 30px; + color: ${(props) => getThemeVariantValue(props, 'colorTextareaDefault')}; + background: ${(props) => getThemeVariantValue(props, 'backgroundColorDefault')}; + font-weight: 400; + max-width: 100%; + min-width: 100%; + width: 100%; + transition: box-shadow 0.1s cubic-bezier(0.4, 1, 0.75, 0.9), -webkit-box-shadow 0.1s cubic-bezier(0.4, 1, 0.75, 0.9); + appearance: none; + &:not(:first-child) { + padding-left: 30px; + } + &:focus { + box-shadow: ${(props) => getThemeVariantValue(props, `boxShadowTextareaFocus`)}; + } + &:hover { + box-shadow: ${(props) => getThemeVariantValue(props, `boxShadowTextareaFocus`)}; + } + &:focus&:hover { + box-shadow: ${(props) => getThemeVariantValue(props, `boxShadowTextareaFocusHover`)}; + } + &:disabled { + box-shadow: none; + background: ${(props) => getThemeVariantValue(props, `backgroundTextareaDisabled`)}; + opacity: 0.75; + color: ${(props) => getThemeVariantValue(props, `colorTextareaDisabled`)}; + cursor: not-allowed; + resize: none; + } +`; + +TextareaWarp.defaultProps = { + defaultTheme: { + // 圆角 + borderRadiusDefault: '3px', + // 大小设置 + fontSizeSmall: '12px', + fontSizeDefault: '14px', + fontSizeLarge: '16px', + //字体颜色 + colorTextareaDefault: '#393e48', + colorTextareaDark: '#fff', + //背景色 + backgroundColorDefault: '#f8f9fa', + backgroundColorDark: '#fff', + // 阴影 + boxShadowTextarea: + '0 0 0 0 rgba(19, 124, 189, 0), 0 0 0 0 rgba(19, 124, 189, 0), inset 0 0 0 1px rgba(16, 22, 26, 0.15), inset 0 1px 1px rgba(16, 22, 26, 0.2)', + boxShadowTextareaFocus: + '0 0 0 1px #393e48, 0 0 0 3px rgba(57, 62, 72, 0.17), inset 0 1px 1px rgba(16, 22, 26, 0.2)', + boxShadowTextareaHover: '0 0 0 1px #6e6e6e, 0 0 0 3px rgba(57, 62, 72, 0), inset 0 1px 1px rgba(16, 22, 26, 0.2)', + boxShadowTextareaFocusHover: + '0 0 0 1px #6e6e6e, 0 0 0 3px rgba(57, 62, 72, 0.17), inset 0 1px 1px rgba(16, 22, 26, 0.2)', + //禁用 + colorTextareaDisabled: '#a5a5a5', + backgroundTextareaDisabled: '#dddddd', + }, +};