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: Implement optionRender API #987

Merged
merged 5 commits into from
Oct 25, 2023

Conversation

RedJue
Copy link
Contributor

@RedJue RedJue commented Oct 23, 2023

close #45445

@vercel
Copy link

vercel bot commented Oct 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2023 3:33am

@RedJue RedJue changed the title feat: implement optionRender api feat: Implement optionRender API Oct 23, 2023
@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

Merging #987 (7289a86) into master (eda3dca) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 7289a86 differs from pull request most recent head c07e7fd. Consider uploading reports for the commit c07e7fd to get more accurate results

@@           Coverage Diff           @@
##           master     #987   +/-   ##
=======================================
  Coverage   99.78%   99.78%           
=======================================
  Files          38       38           
  Lines        1373     1376    +3     
  Branches      400      403    +3     
=======================================
+ Hits         1370     1373    +3     
  Misses          3        3           
Files Coverage Δ
src/OptionList.tsx 99.34% <100.00%> (+0.01%) ⬆️
src/Select.tsx 100.00% <ø> (ø)
src/SelectContext.ts 100.00% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vercel
Copy link

vercel bot commented Oct 23, 2023

@RedJue is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@RedJue RedJue force-pushed the feat-option-render branch from 5c30e98 to c8b5a35 Compare October 23, 2023 10:08
<div className={`${optionPrefixCls}-content`}>{content}</div>
<div className={`${optionPrefixCls}-content`}>
{typeof optionRender === 'function'
? optionRender({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和 SubItem 的 API 对齐吧:

type OptionRender = (oriOption, info: { index }) => ReactNode;

早期,给的东西不用太多。index 就够了~

ref https://github.com/ant-design/ant-design/wiki/API-Naming-rules#props

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok 我改下

@@ -4,6 +4,7 @@

React Select

<!-- prettier-ignore -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以直接在 prettier ignore 文件中加上过滤

@@ -67,6 +68,7 @@ export default () => (

### Select props

<!-- prettier-ignore -->
Copy link
Contributor

@crazyair crazyair Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个格式化,可以在 prettierrc 里加

 overrides: [
        {
            files: '*.md',
            options: {
                proseWrap: 'never'
            }
        }
    ]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改是直接加方便点,这样就是全局配了,应该也可以

<div className={`${optionPrefixCls}-content`}>{content}</div>
<div className={`${optionPrefixCls}-content`}>
{typeof optionRender === 'function'
? optionRender({ ...item.data, label: item.label }, { index: itemIndex })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😼 我给 param 起名叫 oriOption 就是意思不要去改这个 label 的意思哈。option 拿到什么就返回什么。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏻

src/Select.tsx Outdated
@@ -138,6 +140,7 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
optionLabelProp?: string;
children?: React.ReactNode;
options?: OptionType[];
optionRender?: (oriOption: OriOptionType, info: { index: number }) => React.ReactNode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这么写 option 的泛型没了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

@zombieJ zombieJ merged commit 44d9806 into react-component:master Oct 25, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need optionRender for customize option item in select list
4 participants