Skip to content

Commit

Permalink
feat(page-header): support rtl (#1154)
Browse files Browse the repository at this point in the history
* feat:n-input Support hidden password

* feat(form): support require-mark-placement(#171)

* Revert "feat(form): support require-mark-placement(#171)"

This reverts commit 0627777.

* Revert "feat:n-input Support hidden password"

This reverts commit ea64917.

* feat(page-header): support rtl

* add en demo

* fix code

* fix code

* fix code
  • Loading branch information
doom-9-zz authored Sep 12, 2021
1 parent 37eaa30 commit d4ae009
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `n-config-provider` add global config of the `Empty` component, closes [#1092](https://github.com/TuSimple/naive-ui/issues/1092).
- `n-select` add `on-update:show` prop.
- `n-auto-complete` exports `AutoCompleteOption` and `AutoCompleteGroupOption` types.
- `n-page-header` add `RTL` support.

### Fixes

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `n-config-provider` 新增 `Empty` 组件的全局配置,关闭 [#1092](https://github.com/TuSimple/naive-ui/issues/1092)
- `n-select` 新增 `on-update:show` 属性
- `n-auto-complete` 导出 `AutoCompleteOption` 以及 `AutoCompleteGroupOption` 类型
- `n-page-header` 添加 `RTL` 支持

### Fixes

Expand Down
1 change: 1 addition & 0 deletions src/page-header/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

```demo
basic
rtl-debug
```

## Props
Expand Down
93 changes: 93 additions & 0 deletions src/page-header/demos/zhCN/rtl-debug.demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Rtl Debug

```html
<n-space vertical>
<n-space><n-switch v-model:value="rtlEnabled" />Rtl</n-space>
<n-config-provider :rtl="rtlEnabled ? rtlStyles : undefined">
<n-page-header subtitle="让你的听觉更懂视觉" @back="handleBack">
<n-grid :cols="5">
<n-gi>
<n-statistic label="正片" value="125 集" />
</n-gi>
<n-gi>
<n-statistic label="嘉宾" value="22 位" />
</n-gi>
<n-gi>
<n-statistic label="道歉" value="36 次" />
</n-gi>
<n-gi>
<n-statistic label="话题" value="83 个" />
</n-gi>
<n-gi>
<n-statistic label="参考链接" value="2,346 个" />
</n-gi>
</n-grid>
<template #title>
<a
href="https://anyway.fm/"
style="text-decoration: none; color: inherit;"
>Anyway.FM</a
>
</template>
<template #header>
<n-breadcrumb>
<n-breadcrumb-item>播客</n-breadcrumb-item>
<n-breadcrumb-item>精选</n-breadcrumb-item>
<n-breadcrumb-item>超级精选</n-breadcrumb-item>
<n-breadcrumb-item>Anyway.FM</n-breadcrumb-item>
</n-breadcrumb>
</template>
<template #avatar>
<n-avatar
src="https://cdnimg103.lizhi.fm/user/2017/02/04/2583325032200238082_160x160.jpg"
/>
</template>
<template #extra>
<n-space>
<n-button>催更</n-button>
<n-dropdown :options="options" placement="bottom-start">
<n-button :bordered="false" style="padding: 0 4px">···</n-button>
</n-dropdown>
</n-space>
</template>
<template #footer>截止到 2021 年 4 月 3 日</template>
</n-page-header>
</n-config-provider>
</n-space>
```

```js
import { EllipsisHorizontal } from '@vicons/ionicons5'
import { defineComponent, ref } from 'vue'
import { unstablePageHeaderRtl, useMessage } from 'naive-ui'

export default defineComponent({
components: {
EllipsisHorizontal
},
setup () {
const message = useMessage()
return {
rtlEnabled: ref(false),
rtlStyles: [unstablePageHeaderRtl],
handleBack () {
message.info('[onBack]')
},
options: [
{
label: '催更',
key: '1'
},
{
label: '催更',
key: '2'
},
{
label: '催更',
key: '3'
}
]
}
}
})
```
29 changes: 18 additions & 11 deletions src/page-header/src/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import style from './styles/index.cssr'
import { ArrowBackIcon } from '../../_internal/icons'
import { NBaseIcon } from '../../_internal'
import type { ExtractPublicPropTypes } from '../../_utils'
import useRtl from '../../_mixins/use-rtl'

const pageHeaderProps = {
...(useTheme.props as ThemeProps<PageHeaderTheme>),
Expand All @@ -23,7 +24,7 @@ export default defineComponent({
name: 'PageHeader',
props: pageHeaderProps,
setup (props) {
const { mergedClsPrefixRef } = useConfig(props)
const { mergedClsPrefixRef, NConfigProvider } = useConfig(props)
const themeRef = useTheme(
'PageHeader',
'PageHeader',
Expand All @@ -32,7 +33,14 @@ export default defineComponent({
props,
mergedClsPrefixRef
)
const rtlEnabledRef = useRtl(
'PageHeader',
NConfigProvider?.mergedRtlRef,
mergedClsPrefixRef
)

return {
rtlEnabled: rtlEnabledRef,
mergedClsPrefix: mergedClsPrefixRef,
cssVars: computed(() => {
const {
Expand Down Expand Up @@ -65,15 +73,8 @@ export default defineComponent({
}
},
render () {
const {
onBack,
title,
subtitle,
extra,
mergedClsPrefix,
cssVars,
$slots
} = this
const { onBack, title, subtitle, extra, mergedClsPrefix, cssVars, $slots } =
this
const {
title: titleSlot,
subtitle: subtitleSlot,
Expand All @@ -88,7 +89,13 @@ export default defineComponent({
const showSubtitle = subtitle || subtitleSlot
const showExtra = extra || extraSlot
return (
<div style={cssVars as CSSProperties}>
<div
style={cssVars as CSSProperties}
class={[
`${mergedClsPrefix}-page-header-wrapper`,
this.rtlEnabled && `${mergedClsPrefix}-page-header-wrapper--rtl`
]}
>
{headerSlot ? (
<div class={`${mergedClsPrefix}-page-header-header`} key="breadcrumn">
{headerSlot()}
Expand Down
20 changes: 20 additions & 0 deletions src/page-header/src/styles/page-header-rtl.cssr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { c, cB, cM } from '../../../_utils/cssr'

export default c([
cB('page-header-wrapper', [
cM('rtl', [
cB('page-header-header', `
direction: rtl;
`),
cB('page-header', `
direction: rtl;
`),
cB('page-header-content', `
direction: rtl;
`),
cB('page-header-footer', `
direction: rtl;
`)
])
])
])
1 change: 1 addition & 0 deletions src/page-header/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { pageHeaderLight } from './light'
export type { PageHeaderTheme, PageHeaderThemeVars } from './light'
export { pageHeaderDark } from './dark'
export { default as pageHeaderRtl } from './rtl'
6 changes: 6 additions & 0 deletions src/page-header/styles/rtl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import rtlStyle from '../src/styles/page-header-rtl.cssr'

export default {
name: 'PageHeader',
style: rtlStyle
}
1 change: 1 addition & 0 deletions src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export { messageDark } from './message/styles'
export { modalDark } from './modal/styles'
export { notificationDark } from './notification/styles'
export { paginationDark } from './pagination/styles'
export { pageHeaderRtl as unstablePageHeaderRtl } from './page-header/styles'
export { popconfirmDark } from './popconfirm/styles'
export { popoverDark } from './popover/styles'
export { popselectDark } from './popselect/styles'
Expand Down

0 comments on commit d4ae009

Please sign in to comment.