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(cascader): 支持前缀后缀内容 #2824

Merged
merged 4 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/fresh-waves-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(cascader): 支持前置后置内容
5 changes: 5 additions & 0 deletions .changeset/lovely-queens-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(check-cascader): 支持前置后置内容
5 changes: 5 additions & 0 deletions .changeset/pretty-queens-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/check-cascader": minor
---

feat: 支持前置后置内容
5 changes: 5 additions & 0 deletions .changeset/thin-sheep-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/cascader": minor
---

feat: 支持前置后置内容
13 changes: 12 additions & 1 deletion packages/ui/cascader/src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const Cascader = forwardRef<HTMLDivElement | null, CascaderProps>((props,
flattedSearchResult = true,
visible,
size = 'md',
prefix,
suffix,
onOpen,
onClose,
renderExtraFooter,
Expand Down Expand Up @@ -240,7 +242,8 @@ export const Cascader = forwardRef<HTMLDivElement | null, CascaderProps>((props,
clearable={clearable}
placeholder={placeholder}
displayRender={displayRender as any}
suffix={menuVisible ? <UpOutlined /> : <DownOutlined />}
prefix={prefix}
suffix={[menuVisible ? <UpOutlined /> : <DownOutlined />, suffix]}
focused={menuVisible}
value={value[value.length - 1]}
onChange={() => {
Expand Down Expand Up @@ -331,6 +334,14 @@ export interface CascaderProps
* 设置尺寸
*/
size?: HiBaseSizeEnum
/**
* 选择框前置内容
*/
prefix?: React.ReactNode
/**
* 选择框后置内容
*/
suffix?: React.ReactNode
}

if (__DEV__) {
Expand Down
13 changes: 12 additions & 1 deletion packages/ui/check-cascader/src/CheckCascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const CheckCascader = forwardRef<HTMLDivElement | null, CheckCascaderProp
onClose,
tagInputProps,
size = 'md',
prefix,
suffix,
renderExtraFooter,
dropdownColumnRender,
...rest
Expand Down Expand Up @@ -234,7 +236,8 @@ export const CheckCascader = forwardRef<HTMLDivElement | null, CheckCascaderProp
placeholder={placeholder}
// @ts-ignore
displayRender={displayRender}
suffix={menuVisible ? <UpOutlined /> : <DownOutlined />}
prefix={prefix}
suffix={[menuVisible ? <UpOutlined /> : <DownOutlined />, suffix]}
focused={menuVisible}
appearance={appearance}
value={value}
Expand Down Expand Up @@ -379,6 +382,14 @@ export interface CheckCascaderProps extends Omit<PickerProps, 'trigger' | 'scrol
* 设置尺寸
*/
size?: HiBaseSizeEnum
/**
* 选择框前置内容
*/
prefix?: React.ReactNode
/**
* 选择框后置内容
*/
suffix?: React.ReactNode
/**
* 自定义下拉菜单底部渲染
*/
Expand Down
97 changes: 97 additions & 0 deletions packages/ui/check-cascader/stories/addon.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from 'react'
import CheckCascader from '../src'
import { AppStoreOutlined, InfoCircleOutlined } from '@hi-ui/icons'
/**
* @title 前后内置元素
* @desc 将选择框与内置的其他元素组合使用
*/
export const Addon = () => {
const [dataOnlyLeafCheckable] = React.useState(() => {
const data = [
{
id: '手机',
title: '手机t',
children: [
{
id: '小米',
title: '小米t',
children: [
{
id: '小米3',
title: '小米3t',
},
{
id: '小米4',
title: '小米4t',
},
],
},
{
id: '红米',
title: '红米t',
children: [
{
id: '红米3',
title: '红米3t',
},
{
id: '红米4',
title: '红米4t',
},
],
},
],
},
{
id: '电视',
title: '电视t',
children: [
{
id: '小米电视4A',
title: '小米电视4At',
},
{
id: '小米电视4C',
title: '小米电视4Ct',
},
],
},
]

const getDataOnlyLeafCheckable = (data: any) => {
return data.map((item: any) => {
if (item.children) {
item.checkable = item.checkable ?? false
item.children = getDataOnlyLeafCheckable(item.children)
}

return item
})
}

const dataOnlyLeafCheckable = getDataOnlyLeafCheckable(data)

return dataOnlyLeafCheckable
})

return (
<>
<h1>Addon</h1>
<div className="cascader-basic__wrap">
<CheckCascader
style={{ width: 240 }}
searchable={false}
// clearable
placeholder="请选择品类"
defaultValue={[['手机', '红米', '红米4']]}
tagInputProps={{ wrap: true }}
prefix={<AppStoreOutlined style={{ color: '#333' }} />}
suffix={<InfoCircleOutlined style={{ color: '#333' }} />}
changeOnSelect
data={dataOnlyLeafCheckable}
onChange={console.log}
></CheckCascader>
</div>
</>
)
}
1 change: 1 addition & 0 deletions packages/ui/check-cascader/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './dynamic.stories'
export * from './display-render.stories'
export * from './footer.stories'
export * from './dropdown-column-render.stories'
export * from './addon.stories'
// export * from './flatted.stories'

export default {
Expand Down