Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(number-input): 新增前缀后缀内容扩展(#2906) #2907

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 5px;
yang-x20 marked this conversation as resolved.
Show resolved Hide resolved
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