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(bottom-navigation): add placeholder prop #1618

Merged
merged 7 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
26 changes: 25 additions & 1 deletion packages/varlet-ui/src/bottom-navigation/BottomNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"
ref="bottomNavigationDom"
:style="`z-index:${zIndex}`"
v-bind="$attrs"
>
<slot />

Expand All @@ -21,10 +22,13 @@
var-bottom-navigation__fab
@click="handleFabClick"
v-bind="fabProps"
id="var-bottom-navigation__fab"
YHoney7 marked this conversation as resolved.
Show resolved Hide resolved
>
<slot name="fab"></slot>
</var-button>
</div>

<div v-if="fixed && placeholder" :class="n('--placeholder')" :style="{ height: placeholderHeight }" />
Copy link
Member

Choose a reason for hiding this comment

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

--placeholder -> placeholder

</template>

<script lang="ts">
Expand All @@ -33,7 +37,7 @@ import { defineComponent, ref, computed, onUpdated, watch } from 'vue'
import { props } from './props'
import { useBottomNavigationItems, type BottomNavigationProvider } from './provide'
import { createNamespace } from '../utils/components'
import { isNumber, normalizeToArray, call } from '@varlet/shared'
import { isNumber, normalizeToArray, call, getRect } from '@varlet/shared'
import { onSmartMounted } from '@varlet/use'
import { type BottomNavigationItemProvider } from '../bottom-navigation-item/provide'

Expand All @@ -57,6 +61,7 @@ export default defineComponent({
const activeColor = computed<string | undefined>(() => props.activeColor)
const inactiveColor = computed<string | undefined>(() => props.inactiveColor)
const variant = computed<boolean | undefined>(() => props.variant)
const placeholderHeight = ref()
const fabProps = ref({})
const { length, bottomNavigationItems, bindBottomNavigationItem } = useBottomNavigationItems()

Expand All @@ -81,6 +86,8 @@ export default defineComponent({
)

onSmartMounted(() => {
setPlaceholderHeight()
Copy link
Member

Choose a reason for hiding this comment

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

更名为 resizePlaceholder


if (!slots.fab) {
return
}
Expand Down Expand Up @@ -190,10 +197,27 @@ export default defineComponent({
call(props.onFabClick)
}

function setPlaceholderHeight() {
if (!props.fixed || !props.placeholder) {
return
}

const bottomRect = getRect(bottomNavigationDom.value!)
Copy link
Member

Choose a reason for hiding this comment

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

bottomRect -> bottomNavigationRect

let totalHeight = bottomRect.height

if (slots.fab) {
const fabRect = getRect(document.getElementById('var-bottom-navigation__fab')!)
totalHeight = bottomRect.top - fabRect.top + bottomRect.height
}

placeholderHeight.value = `${totalHeight}px`
}

return {
length,
bottomNavigationDom,
fabProps,
placeholderHeight,
n,
classes,
handleFabClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ exports[`test bottom-navigation component props > test variant mode 1`] = `
<div class="var-bottom-navigation-item__icon-container"><i class="var-icon var-icon--set var-icon-account-circle var-bottom-navigation-item__icon" style="transition-duration: 0ms;" var-bottom-navigation-item-cover=""></i></div><span class="var-bottom-navigation-item__label">tag 4</span>
</button>
<!--v-if-->
</div>"
</div>
<!--v-if-->"
`;

exports[`test bottom-navigation component props > test variant mode 2`] = `
Expand All @@ -33,5 +34,6 @@ exports[`test bottom-navigation component props > test variant mode 2`] = `
<div class="var-bottom-navigation-item__icon-container var-bottom-navigation-item--variant-icon-container"><i class="var-icon var-icon--set var-icon-account-circle var-bottom-navigation-item__icon" style="transition-duration: 0ms;" var-bottom-navigation-item-cover=""></i></div><span class="var-bottom-navigation-item__label">tag 4</span>
</button>
<!--v-if-->
</div>"
</div>
<!--v-if-->"
`;
17 changes: 17 additions & 0 deletions packages/varlet-ui/src/bottom-navigation/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,23 @@ describe('test bottom-navigation component props', () => {
wrapper.unmount()
})

test('test bottom-navigation placeholder', async () => {
const wrapper = mount(VarBottomNavigation, {
props: {
placeholder: true,
fixed: true,
},
})

expect(wrapper.find('.var-bottom-navigation--placeholder').exists()).toBe(true)
await wrapper.setProps({ placeholder: false, fixed: false })
expect(wrapper.find('.var-bottom-navigation--placeholder').exists()).toBe(false)
await wrapper.setProps({ placeholder: true, fixed: false })
expect(wrapper.find('.var-bottom-navigation--placeholder').exists()).toBe(false)

wrapper.unmount()
})

test('test bottom-navigation fab-props', async () => {
const wrapper = mount(Wrapper, {
props: {
Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/src/bottom-navigation/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const active = ref(0)
| `z-index` | Z-index | _number \| string_ | `1` |
| `active-color` | Color of active tab item | _string_ | `-` |
| `inactive-color` | Color of inactive tab item | _string_ | `-` |
| `placeholder` ***3.2.10*** | Whether to generate placeholder elements of the same height at the bottom (`fixed` required) | _boolean_ | `false` |
Copy link
Member

Choose a reason for hiding this comment

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

版本号也修改一下,预计在 3.2.11 发布。

Copy link
Member Author

Choose a reason for hiding this comment

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

好的

| `fab-props` | Fab button props | _ButtonProps_ | `{ type: 'primary' }` |
| `variant` ***3.2.0*** | Variant mode | _boolean_ | `false` |

Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/src/bottom-navigation/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const active = ref(0)
| `z-index` | 元素 z-index | _number \| string_ | `1` |
| `active-color` | 选中标签的颜色 | _string_ | `-` |
| `inactive-color` | 未选中标签的颜色 | _string_ | `-` |
| `placeholder` ***3.2.10*** | 是否在底部生成相同高度的占位元素(需设置 `fixed`) | _boolean_ | `false` |
| `fab-props` | 悬浮按钮属性 | _ButtonProps_ | `{ type: 'primary' }` |
| `variant` ***3.2.0*** | 变体模式 | _boolean_ | `false` |

Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/src/bottom-navigation/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const props = {
safeArea: Boolean,
activeColor: String,
inactiveColor: String,
placeholder: Boolean,
fabProps: Object as PropType<ExtractPublicPropTypes<typeof buttonProps>>,
onChange: defineListenerProp<(active: number | string) => void>(),
onBeforeChange: defineListenerProp<(active: number | string) => any | Promise<any>>(),
Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/types/bottomNavigation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface BottomNavigationProps extends BasicAttributes {
zIndex?: number | string
activeColor?: string
inactiveColor?: string
placeholder?: boolean
fabProps?: Partial<ButtonProps>
variant?: boolean
onChange?: ListenerProp<(active: string | number) => void>
Expand Down
Loading