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(collapse): add 'header-extra' slot #1064

Merged
merged 7 commits into from
Sep 4, 2021
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
8 changes: 3 additions & 5 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- Fix `n-cascader` click tag to delete the sub option in multi selection mode, and the tree option is not updated.
- Fix `n-input` chinese input method not correct while mouse leave the input in `clearable` is true, closes [#905](https://github.com/TuSimple/naive-ui/issues/905).
- Fix `n-description`'s warning caused by `v-if` that should not appear, closes [#1083](https://github.com/TuSimple/naive-ui/issues/1083).
- Fix `n-layout`'s `sider-placement` doesn't work after build, closes [#978](https://github.com/TuSimple/naive-ui/issues/978).
- Fix `n-input-number`'s `step` calculate error when the value is decimal, closes [#1007](https://github.com/TuSimple/naive-ui/issues/1007).

### Feats

Expand All @@ -32,11 +34,7 @@
- `n-pagination` export `PaginationInfo` type.
- `n-data-table` export `DataTableCreateSummary` type.
- `n-code` add `inline` prop, closes [#834](https://github.com/TuSimple/naive-ui/issues/834)

### Fixes

- Fix `n-layout`'s `sider-placement` doesn't work after build, closes [#978](https://github.com/TuSimple/naive-ui/issues/978).
- Fix `n-input-number`'s `step` calculate error when the value is decimal, closes [#1007](https://github.com/TuSimple/naive-ui/issues/1007).
- `n-collapse` add 'header-extra' slot, closes [#1046](https://github.com/TuSimple/naive-ui/issues/1046).

## 2.16.7 (2021-08-27)

Expand Down
8 changes: 3 additions & 5 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- 修复 `n-cascader` 多选模式下点击 tag 删除子选项未更新选中项
- 修复 `n-input` 在 `clearable` 为 `true` 时鼠标离开输入框时中文输入法不正确,关闭 [#905](https://github.com/TuSimple/naive-ui/issues/905)
- 修复 `n-description` 中因 `v-if` 导致的不该出现的警告,关闭 [#1083](https://github.com/TuSimple/naive-ui/issues/1083)
- 修复 `n-layout` 的 `sider-placement` 属性在打包之后不生效,关闭 [#978](https://github.com/TuSimple/naive-ui/issues/978)
- 修复 `n-input-number` 的 `step` 值为小数时计算错误,关闭 [#1007](https://github.com/TuSimple/naive-ui/issues/1007)

### Feats

Expand All @@ -32,11 +34,7 @@
- `n-pagination` 导出 `PaginationInfo` 类型
- `n-data-table` 导出 `DataTableCreateSummary` 类型
- `n-code` 新增 `inline` 属性, 关闭 [#834](https://github.com/TuSimple/naive-ui/issues/834)

### Fixes

- 修复 `n-layout` 的 `sider-placement` 属性在打包之后不生效,关闭 [#978](https://github.com/TuSimple/naive-ui/issues/978)
- 修复 `n-input-number` 的 `step` 值为小数时计算错误,关闭 [#1007](https://github.com/TuSimple/naive-ui/issues/1007)
- `n-collapse` 新增 slot: 'header-extra',关闭 [#1046](https://github.com/TuSimple/naive-ui/issues/1046)

## 2.16.7 (2021-08-27)

Expand Down
3 changes: 3 additions & 0 deletions src/collapse/demos/enUS/customize-icon.demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

```html
<n-collapse>
<template #header-extra>
<n-icon><cash-icon /></n-icon>
</template>
<template #arrow>
<n-icon>
<cash-icon />
Expand Down
1 change: 1 addition & 0 deletions src/collapse/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ default-expanded
| --- | --- | --- |
| default | `()` | The contents of the collapsible panel node. |
| header | `()` | The content of the header of the collapsed panel node. |
| header-extra | `()` | The extra content of the header of the collapsed panel node. |
| arrow | `(options: { collapsed: boolean })` | The custom icon of the node header of the collapsible panel. |
3 changes: 3 additions & 0 deletions src/collapse/demos/zhCN/customize-icon.demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

```html
<n-collapse>
<template #header-extra>
<n-icon><cash-icon /></n-icon>
</template>
<template #arrow>
<n-icon>
<cash-icon />
Expand Down
11 changes: 6 additions & 5 deletions src/collapse/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ default-expanded

### Collapse Item Slots

| 名称 | 参数 | 说明 |
| ------- | ----------------------------------- | ---------------------------- |
| default | `()` | 折叠面板节点的内容 |
| header | `()` | 折叠面板节点头部的内容 |
| arrow | `(options: { collapsed: boolean })` | 折叠面板节点头部的自定义图标 |
| 名称 | 参数 | 说明 |
| --- | --- | --- |
| default | `()` | 折叠面板节点的内容 |
| header | `()` | 折叠面板节点头部的内容 |
| header-extra | `()` | 折叠面板节点头部的额外内容 |
| arrow | `(options: { collapsed: boolean })` | 折叠面板节点头部的自定义图标 |
44 changes: 29 additions & 15 deletions src/collapse/src/CollapseItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,42 @@ export default defineComponent({
`${mergedClsPrefix}-collapse-item__header`,
!collapsed && `${mergedClsPrefix}-collapse-item__header--active`
]}
onClick={this.handleClick}
>
{arrowPlacement === 'right' && headerNode}
<div class={`${mergedClsPrefix}-collapse-item-arrow`}>
<div
class={`${mergedClsPrefix}-collapse-item__header-main`}
onClick={this.handleClick}
>
{arrowPlacement === 'right' && headerNode}
<div class={`${mergedClsPrefix}-collapse-item-arrow`}>
{renderSlot(
$slots.arrow
? $slots
: collapseSlots.arrow
? collapseSlots
: $slots,
'arrow',
{ collapsed: collapsed },
() => [
<NBaseIcon clsPrefix={mergedClsPrefix}>
{{
default: collapseSlots.expandIcon ?? (() => <ArrowIcon />)
}}
</NBaseIcon>
]
)}
</div>
{arrowPlacement === 'left' && headerNode}
</div>
<div class={`${mergedClsPrefix}-collapse-item__header-extra`}>
{renderSlot(
$slots.arrow
$slots['header-extra']
? $slots
: collapseSlots.arrow
: collapseSlots['header-extra']
? collapseSlots
: $slots,
'arrow',
{ collapsed: collapsed },
() => [
<NBaseIcon clsPrefix={mergedClsPrefix}>
{{
default: collapseSlots.expandIcon ?? (() => <ArrowIcon />)
}}
</NBaseIcon>
]
'header-extra'
)}
</div>
{arrowPlacement === 'left' && headerNode}
</div>
<NCollapseItemContent
clsPrefix={mergedClsPrefix}
Expand Down
17 changes: 17 additions & 0 deletions src/collapse/src/styles/index.cssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ export default cB('collapse', {
padding: 16px 0 0 0;
color: var(--title-text-color);
`, [
cE('header-main', `
display: flex;
flex-wrap: nowrap;
align-items: center;
font-weight: var(--title-font-weight);
transition: color .3s var(--bezier);
flex: 1;
color: var(--title-text-color);
`),
cE('header-extra', `
display: flex;
align-items: center;
font-size: 14px;
font-weight: 400;
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个是从那里继承的,只在 header main 作用的话应该不会影响这里吧

Copy link
Contributor Author

@LYErin LYErin Sep 3, 2021

Choose a reason for hiding this comment

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

那就改成固定font-size: 14?

Copy link
Collaborator

Choose a reason for hiding this comment

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

我说的是 font-weight

transition: color .3s var(--bezier);
color: var(--text-color);
`),
cB('collapse-item-arrow', `
display: flex;
transition:
Expand Down
23 changes: 22 additions & 1 deletion src/collapse/tests/Collapse.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,32 @@ describe('n-collapse', () => {
default: () => <NCollapseItem name="1"></NCollapseItem>
}
})
const triggerNodeWrapper = wrapper.find('.n-collapse-item__header')
const triggerNodeWrapper = wrapper.find('.n-collapse-item__header-main')
await triggerNodeWrapper.trigger('click')
expect(onClick).toHaveBeenCalled()
})

it('should work with `slots` ', async () => {
const wrapper = mount(NCollapse, {
slots: {
header: () => 'header',
'header-extra': () => 'header-extra',
default: () => <NCollapseItem name="1"></NCollapseItem>,
arrow: () => 'arrow'
}
})
expect(wrapper.find('.n-collapse-item__header-main').exists()).toBe(true)
expect(wrapper.find('.n-collapse-item__header-main').text()).toBe('arrow')

expect(wrapper.find('.n-collapse-item__header-extra').exists()).toBe(true)
expect(wrapper.find('.n-collapse-item__header-extra').text()).toBe(
'header-extra'
)

expect(wrapper.find('.n-collapse-item-arrow').exists()).toBe(true)
expect(wrapper.find('.n-collapse-item-arrow').text()).toBe('arrow')
})

it('props.defaultExpandedNames', async () => {
let wrapper = mount(NCollapse, {
props: {
Expand Down