ant-design/components/input/Group.tsx
MadCcc 228d451832
refactor: input support cssinjs (#34288)
* refactor: input with cssinjs

* refactor: input cssinjs

* refactor: rtl

* chore: code clean

* chore: code clean

* refactor: adapt hash

* refactor: use input token

* refactor: status

* fix: style

* fix: rtl

* chore: update token

* chore: code clean

* chore: code clean

* chore: code clean

* refactor: enhance token

* fix: enhance padding

* perf: replace rtl styles

* refactor: place placeholder in input

* perf: rtl

* refactor: code perf

* style: code style

* fix: prefixCls
2022-03-09 10:38:02 +08:00

53 lines
1.5 KiB
TypeScript

import * as React from 'react';
import { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider';
import useStyle from './style';
export interface GroupProps {
className?: string;
size?: 'large' | 'small' | 'default';
children?: React.ReactNode;
style?: React.CSSProperties;
onMouseEnter?: React.MouseEventHandler<HTMLSpanElement>;
onMouseLeave?: React.MouseEventHandler<HTMLSpanElement>;
onFocus?: React.FocusEventHandler<HTMLSpanElement>;
onBlur?: React.FocusEventHandler<HTMLSpanElement>;
prefixCls?: string;
compact?: boolean;
}
const Group: React.FC<GroupProps> = props => {
const { getPrefixCls, direction, iconPrefixCls } = useContext(ConfigContext);
const { prefixCls: customizePrefixCls, className = '' } = props;
const prefixCls = getPrefixCls('input-group', customizePrefixCls);
const inputPrefixCls = getPrefixCls('input');
const [wrapSSR, hashId] = useStyle(inputPrefixCls, iconPrefixCls);
const cls = classNames(
prefixCls,
{
[`${prefixCls}-lg`]: props.size === 'large',
[`${prefixCls}-sm`]: props.size === 'small',
[`${prefixCls}-compact`]: props.compact,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
hashId,
className,
);
return wrapSSR(
<span
className={cls}
style={props.style}
onMouseEnter={props.onMouseEnter}
onMouseLeave={props.onMouseLeave}
onFocus={props.onFocus}
onBlur={props.onBlur}
>
{props.children}
</span>,
);
};
export default Group;