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(date-picker): 新增前缀后缀内容扩展(#2894) #2905

Merged
merged 7 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/cyan-rules-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/date-picker": minor
---

feat: 新增前缀后缀内容扩展
5 changes: 5 additions & 0 deletions .changeset/funny-zebras-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(date-picker): 新增前缀后缀内容扩展
2 changes: 2 additions & 0 deletions packages/ui/date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const DatePicker = forwardRef<HTMLDivElement | null, DatePickerProps>(
cellRender,
footerRender,
strideSelectMode = 'auto',
prefix,
...otherProps
},
ref
Expand Down Expand Up @@ -441,6 +442,7 @@ export const DatePicker = forwardRef<HTMLDivElement | null, DatePickerProps>(
setAttachEl={setAttachEl}
dateRangeTimePanelNow={dateRangeTimePanelNow}
invalid={invalid}
prefix={prefix}
/>
<Popper
{...(overlay || {})}
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/date-picker/src/components/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Root = ({
setAttachEl,
dateRangeTimePanelNow,
invalid,
prefix,
}: {
onTrigger: (index: number) => void
onClear: () => void
Expand All @@ -23,6 +24,7 @@ const Root = ({
inputChangeEvent: InputChangeEvent
dateRangeTimePanelNow: number
invalid: boolean
prefix: React.ReactNode
}) => {
const {
i18n,
Expand Down Expand Up @@ -136,6 +138,7 @@ const Root = ({
return (
<div className={_cls} ref={setAttachEl}>
<div className={`${prefixCls}__picker__wrapper`}>
{prefix ? <span className={`${prefixCls}__prefix`}>{prefix}</span> : null}
<div
className={cx(
`${prefixCls}__input-selector`,
Expand Down
10 changes: 10 additions & 0 deletions packages/ui/date-picker/src/styles/date-picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ $calendar-large-background-border-radius: $calendar-large-indicator-border-radiu
overflow: hidden;
}

&__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;
}

&__input-selector {
display: flex;
border-radius: use-border-radius('normal');
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/date-picker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,8 @@ export interface DatePickerProps extends Omit<HiBaseHTMLProps<'div'>, 'placehold
* @default 'auto'
*/
strideSelectMode?: 'auto' | 'fixed'
/**
* 选择框前置内容
*/
prefix?: React.ReactNode
}
22 changes: 22 additions & 0 deletions packages/ui/date-picker/stories/addon.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import DatePicker from '../src'
import { AppStoreOutlined } from '@hi-ui/icons'

/**
* @title 前置后置内容扩展
*/
export const Addon = () => {
return (
<div className="date-picker-addon__wrap">
<h2>Addon</h2>
<DatePicker
style={{ width: 240 }}
onChange={(date, dateStr) => {
console.log('onChange', date, dateStr)
}}
onSelect={console.log}
prefix={<AppStoreOutlined />}
/>
</div>
)
}
1 change: 1 addition & 0 deletions packages/ui/date-picker/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './shortcut.stories'
export * from './lunar.stories'
export * from './size.stories'
export * from './footer-render.stories'
export * from './addon.stories'

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