Skip to content

Commit

Permalink
feat(number-input): 新增前缀后缀内容扩展(#2906)
Browse files Browse the repository at this point in the history
* feat(number-input): 新增前缀后缀内容扩展(#2906)

* chore: 生成变更记录文件

* fix(number-input): 修改前缀样式(#2906)

* fix(number-input): 修改前缀左边距(#2906)

---------

Co-authored-by: yangxuexue <[email protected]>
  • Loading branch information
yang-x20 and yangxuexue authored Jun 28, 2024
1 parent dce209c commit 8d3e4a9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-carrots-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(number-input): 新增前缀后缀内容扩展
5 changes: 5 additions & 0 deletions .changeset/soft-actors-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/number-input": minor
---

feat: 新增前缀后缀内容扩展
3 changes: 2 additions & 1 deletion packages/ui/number-input/src/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const _prefix = getPrefixCls('number-input')
* 数字输入框
*/
export const NumberInput = forwardRef<HTMLDivElement | null, CounterProps>(
({ prefixCls = _prefix, role = _role, ...rest }, ref) => {
({ prefixCls = _prefix, role = _role, prefix, ...rest }, ref) => {
const { rootProps, getInputProps, getMinusButtonProps, getPlusButtonProps } = useCounter({
prefixCls,
role,
Expand All @@ -20,6 +20,7 @@ export const NumberInput = forwardRef<HTMLDivElement | null, CounterProps>(

return (
<div ref={ref} {...rootProps}>
{prefix ? <span className={`${prefixCls}__prefix`}>{prefix}</span> : null}
<input {...getInputProps()} />
<div className={`${prefixCls}__suffix`}>
<button {...getPlusButtonProps()}>
Expand Down
16 changes: 12 additions & 4 deletions packages/ui/number-input/src/styles/number-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $prefix: '#{$component-prefix}-number-input' !default;
$input-error-shadow: 0 0 0 2px use-color-mode('danger', 100);

position: relative;
display: inline-block;
display: inline-flex;
width: 100%;
color: use-color('gray', 700);
font-size: use-text-size('normal');
Expand Down Expand Up @@ -57,6 +57,7 @@ $prefix: '#{$component-prefix}-number-input' !default;
&__input {
@include input-reset();

flex: 1;
width: 100%;
height: 100%;
color: inherit;
Expand All @@ -68,10 +69,17 @@ $prefix: '#{$component-prefix}-number-input' !default;
}
}

&__prefix {
display: inline-flex;
margin-left: use-spacing(6);
align-items: center;
flex-shrink: 0;
color: use-color('gray', 700);
font-size: inherit;
text-align: center;
}

&__suffix {
position: absolute;
top: 0;
right: 0;
box-sizing: border-box;
height: 100%;

Expand Down
24 changes: 24 additions & 0 deletions packages/ui/number-input/stories/addon.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import NumberInput from '../src'
import { AppStoreOutlined } from '@hi-ui/icons'

/**
* @title 前缀后缀内容扩展
*/
export const Addon = () => {
return (
<>
<h1>NumberInput</h1>
<div className="NumberInput-addon__wrap">
<NumberInput
autoFocus
defaultValue={5}
min={1}
placeholder="请输入数字"
onChange={(v) => console.log('onChange', v)}
prefix={<AppStoreOutlined />}
/>
</div>
</>
)
}
1 change: 1 addition & 0 deletions packages/ui/number-input/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './step.stories'
export * from './Wheel.stories'
export * from './invalid.stories'
export * from './formatter.stories'
export * from './addon.stories'

export default {
title: 'Data Input/NumberInput',
Expand Down

0 comments on commit 8d3e4a9

Please sign in to comment.