Added slots to allow custom rendering panels #3428
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes
Background and context
起初是因为在做表单录入功能时,想实现飞书中的这种效果。发现color-picker组件不支持。
Solution
后面去看了ant design的ColorPicker组件,看到是使用panelRender自定义渲染函数。然后按着这个思路写了一版,后面发现对于vue来说使用插槽可能会更好,就改用了插槽的方式。
插槽把整体面板分了三大部分:调色板区域(palette)、控制条(controls)、颜色选择(color-section)颜色选择区域又增加了标题的两个插槽(history-title、preset-title)一共是五个插槽。插槽使用了作用域插槽,返回了原本默认渲染部分,可以使得用户更灵活的自定义。
本来添加插槽也可以实现最初的需求,只需要#palette和#controls 插槽内容返回空即可,但是为了方便还是增加了两个props:showPalette和showControls。
How is the change tested?
Changelog
Checklist:
npm run test
)feature
branch and othersshould be submitted to
main
branch)Other information