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

fix(config-provider): inherit cls-prefix from parent by default #5978

Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

`xxxx-xx-xx`

### Breaking Changes

- Fix `n-config-provider` inherit the class prefix from it's parent by default, closes [#5970](https://github.com/tusen-ai/naive-ui/issues/5970).

### Fixes

- Fix `n-infinite-scroll` bottoming out judgment error, closes [#6133](https://github.com/tusen-ai/naive-ui/issues/6133).
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

`xxxx-xx-xx`

### Breaking Changes

- 修复 `n-config-provider` 默认继承父级的类前缀 `cls-prefix`, 关闭 [#5970](https://github.com/tusen-ai/naive-ui/issues/5970)

### Fixes

- 修复 `n-infinite-scroll` 组件触底判断错误,关闭 [#6133](https://github.com/tusen-ai/naive-ui/issues/6133)
Expand Down
26 changes: 26 additions & 0 deletions src/config-provider/demos/enUS/cls-prefix.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<markdown>
# Component's class prefix
If you don't set the `cls-prefix` prop of `n-config-provider`, it will inherit the class prefix from its parent by default.

Note that this prop is not reactive.
</markdown>
<template>

Check failure on line 7 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Expected blank line before this block

Check failure on line 7 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Expected blank line before this block
<n-config-provider cls-prefix="myPrefix" abstract>
<n-flex vertical>
<n-button ref="button1Ref">

Check failure on line 10 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Component name "n-button" is not PascalCase

Check failure on line 10 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Component name "n-button" is not PascalCase
Oops · {{ button1Ref?.mergedClsPrefix }}
</n-button>
<n-config-provider abstract>
<n-button ref="button2Ref">

Check failure on line 14 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Component name "n-button" is not PascalCase

Check failure on line 14 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Component name "n-button" is not PascalCase
Oops Oops · {{ button2Ref?.mergedClsPrefix }}
</n-button>
</n-config-provider>
</n-flex>
</n-config-provider>
</template>
<script lang="ts" setup>

Check failure on line 21 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

'<script lang=ts setup>' should be above '<template>' on line 7

Check failure on line 21 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Expected blank line before this block

Check failure on line 21 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

'<script lang=ts setup>' should be above '<template>' on line 7

Check failure on line 21 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Expected blank line before this block
import { ref } from 'vue'
import { NButton } from 'naive-ui'

Check failure on line 23 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Expected 1 empty line after import statement not followed by another import

Check failure on line 23 in src/config-provider/demos/enUS/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Expected 1 empty line after import statement not followed by another import
const button1Ref = ref<InstanceType<typeof NButton>>()
const button2Ref = ref<InstanceType<typeof NButton>>()
</script>
3 changes: 2 additions & 1 deletion src/config-provider/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For more info about theming, see [Customizing Theme](../docs/customize-theme).
theme.vue
namespace.vue
inherit-theme.vue
cls-prefix.vue
os-theme.vue
language.vue
transparent.vue
Expand All @@ -24,7 +25,7 @@ inline-theme-disabled.vue
| --- | --- | --- | --- | --- |
| abstract | `boolean` | `false` | If `n-config-provider` has no wrapper DOM | |
| breakpoints | `{ [k: string]: number }` | `{ xs: 0, s: 640, m: 1024, l: 1280, xl: 1536, xxl: 1920 }` | Responsive breakpoints, it will be used in `n-grid`. The prop is not responsive, you need to set it on its first mount. | |
| cls-prefix | `string` | `n` | The class prefix of all inner components. It's applied in the first time. | |
| cls-prefix | `string` | `undefined` | The class prefix of all inner components. It's applied in the first time. | |
| date-locale | `DateLocale \| null` | `undefined` | The date locale object to be consumed by its child. If set to `null` it will use the default `dateEnUS` locale. If set to `undefined` it will inherit its parent `n-config-provider`. | |
| inline-theme-disabled | `boolean` | `false` | Whether to disabled inline theme CSS variables. If you won't change theme overrides frequently in client side, and need SSR or make devtools looks clear. You can enable the prop. Note that the prop is not responsive. | 2.26.0 |
| katex | `object` | `undefined` | Katex object for `n-equation`. | 2.34.0 |
Expand Down
27 changes: 27 additions & 0 deletions src/config-provider/demos/zhCN/cls-prefix.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<markdown>
# 组件的类前缀

如果不设置 `n-config-provider` 的类前缀 `cls-prefix`,则默认继承父级的类前缀。

注意,该属性不是响应式的。
</markdown>
<template>

Check failure on line 8 in src/config-provider/demos/zhCN/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Expected blank line before this block

Check failure on line 8 in src/config-provider/demos/zhCN/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Expected blank line before this block
<n-config-provider cls-prefix="myPrefix" abstract>
<n-flex vertical>
<n-button ref="button1Ref">

Check failure on line 11 in src/config-provider/demos/zhCN/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Component name "n-button" is not PascalCase

Check failure on line 11 in src/config-provider/demos/zhCN/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Component name "n-button" is not PascalCase
噢 {{ button1Ref?.mergedClsPrefix }}
</n-button>
<n-config-provider abstract>
<n-button ref="button2Ref">

Check failure on line 15 in src/config-provider/demos/zhCN/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (18)

Component name "n-button" is not PascalCase

Check failure on line 15 in src/config-provider/demos/zhCN/cls-prefix.demo.vue

View workflow job for this annotation

GitHub Actions / lint (20)

Component name "n-button" is not PascalCase
噢噢 {{ button2Ref?.mergedClsPrefix }}
</n-button>
</n-config-provider>
</n-flex>
</n-config-provider>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { NButton } from 'naive-ui'
const button1Ref = ref<InstanceType<typeof NButton>>()
const button2Ref = ref<InstanceType<typeof NButton>>()
</script>
3 changes: 2 additions & 1 deletion src/config-provider/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
theme.vue
namespace.vue
inherit-theme.vue
cls-prefix.vue
os-theme.vue
language.vue
transparent.vue
Expand All @@ -24,7 +25,7 @@ inline-theme-disabled.vue
| --- | --- | --- | --- | --- |
| abstract | `boolean` | `false` | 是否不存在 DOM 包裹 | |
| breakpoints | `{ [k: string]: number }` | `{ xs: 0, s: 640, m: 1024, l: 1280, xl: 1536, xxl: 1920 }` | 屏幕响应式断点,对 `n-grid` 生效。这个属性不是响应式的,你需要在组件第一次挂载时就设定好 | |
| cls-prefix | `string` | `n` | 内部所有组件的类的前缀,仅首次设定会生效 | |
| cls-prefix | `string` | `undefined` | 内部所有组件的类的前缀,仅首次设定会生效 | |
| date-locale | `DateLocale \| null` | `undefined` | 对后代组件生效的日期语言对象,为 `null` 时会使用默认 `dateEnUS`,为 `undefined` 时会继承上级 `n-config-provider` | |
| inline-theme-disabled | `boolean` | `false` | 是否禁用 inline css 主题变量,如果你不会频繁调整主题变量,并且需要 SSR 或者想让 devtools 看起来更干净,可以打开这个选项。注意,这个属性不是响应式的 | 2.26.0 |
| katex | `object` | `undefined` | 公式组件需要的 katex 对象 | 2.34.0 |
Expand Down
2 changes: 1 addition & 1 deletion src/config-provider/src/ConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const configProviderProps = {
type: Boolean as PropType<boolean | undefined>,
default: undefined
},
clsPrefix: { type: String, default: defaultClsPrefix },
clsPrefix: String,
locale: Object as PropType<NLocale | null>,
dateLocale: Object as PropType<NDateLocale | null>,
namespace: String,
Expand Down
Loading