Skip to content

Commit c12c25c

Browse files
authored
fix(notification): placement demo (#7419)
* fix(notification): fix placement demo * fix(notification): localize zhCN placement demo copy
1 parent dbb66f5 commit c12c25c

2 files changed

Lines changed: 92 additions & 70 deletions

File tree

src/notification/demos/enUS/placement.demo.vue

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,57 @@
44

55
<script lang="ts" setup>
66
import type { NotificationPlacement } from 'naive-ui'
7+
import type { PropType, VNode } from 'vue'
78
import { NButton, NSpace, useNotification } from 'naive-ui'
8-
import { h, ref } from 'vue'
9+
import { defineComponent, h, ref } from 'vue'
910
10-
const placementRef = ref<NotificationPlacement>('top-right')
11-
12-
function handlePlacementChange(val: NotificationPlacement) {
13-
placementRef.value = val
11+
interface Item {
12+
placement: NotificationPlacement
13+
text: string
1414
}
1515
16-
function PlacementButtons(props: {
17-
onPlacementChange?: (placement: NotificationPlacement) => void
18-
}) {
19-
const notification = useNotification()
20-
const placementList = [
21-
{ placement: 'top-left' as const, text: 'Top left' },
22-
{ placement: 'top-right' as const, text: 'Top right' },
23-
{ placement: 'bottom-left' as const, text: 'Bottom left' },
24-
{ placement: 'bottom-right' as const, text: 'Bottom right' },
25-
{ placement: 'bottom' as const, text: 'Bottom' },
26-
{ placement: 'top' as const, text: 'Top' }
27-
]
16+
const PlacementButtons = defineComponent({
17+
props: {
18+
onPlacementChange: Function as PropType<
19+
(placement: NotificationPlacement) => void
20+
>
21+
},
22+
setup(props) {
23+
const notification = useNotification()
24+
const placementList: Item[] = [
25+
{ placement: 'top-left', text: 'Top left' },
26+
{ placement: 'top-right', text: 'Top right' },
27+
{ placement: 'bottom-left', text: 'Bottom left' },
28+
{ placement: 'bottom-right', text: 'Bottom right' },
29+
{ placement: 'bottom', text: 'Bottom' },
30+
{ placement: 'top', text: 'Top' }
31+
]
32+
return (): VNode =>
33+
h(NSpace, null, {
34+
default: () =>
35+
placementList.map((item: Item) =>
36+
h(
37+
NButton,
38+
{
39+
onClick: () => {
40+
props.onPlacementChange?.(item.placement)
41+
notification.info({
42+
title: item.placement,
43+
content: 'You can change the placement'
44+
})
45+
}
46+
},
47+
{ default: () => item.text }
48+
)
49+
)
50+
})
51+
}
52+
})
53+
54+
const placementRef = ref<NotificationPlacement>('top-right')
2855
29-
return h(NSpace, null, {
30-
default: () =>
31-
placementList.map(item =>
32-
h(
33-
NButton,
34-
{
35-
onClick: () => {
36-
props.onPlacementChange?.(item.placement)
37-
notification.info({
38-
title: item.placement,
39-
content: 'You can change the placement'
40-
})
41-
}
42-
},
43-
{ default: () => item.text }
44-
)
45-
)
46-
})
56+
function handlePlacementChange(placement: NotificationPlacement) {
57+
placementRef.value = placement
4758
}
4859
</script>
4960

src/notification/demos/zhCN/placement.demo.vue

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,57 @@
44

55
<script lang="ts" setup>
66
import type { NotificationPlacement } from 'naive-ui'
7+
import type { PropType, VNode } from 'vue'
78
import { NButton, NSpace, useNotification } from 'naive-ui'
8-
import { h, ref } from 'vue'
9+
import { defineComponent, h, ref } from 'vue'
910
10-
const placementRef = ref<NotificationPlacement>('top-right')
11-
12-
function handlePlacementChange(val: NotificationPlacement) {
13-
placementRef.value = val
11+
interface Item {
12+
placement: NotificationPlacement
13+
text: string
1414
}
1515
16-
function PlacementButtons(props: {
17-
onPlacementChange?: (placement: NotificationPlacement) => void
18-
}) {
19-
const notification = useNotification()
20-
const placementList = [
21-
{ placement: 'top-left' as const, text: '左上' },
22-
{ placement: 'top-right' as const, text: '右上' },
23-
{ placement: 'bottom-left' as const, text: '左下' },
24-
{ placement: 'bottom-right' as const, text: '右下' },
25-
{ placement: 'bottom' as const, text: '' },
26-
{ placement: 'top' as const, text: '' }
27-
]
16+
const PlacementButtons = defineComponent({
17+
props: {
18+
onPlacementChange: Function as PropType<
19+
(placement: NotificationPlacement) => void
20+
>
21+
},
22+
setup(props) {
23+
const notification = useNotification()
24+
const placementList: Item[] = [
25+
{ placement: 'top-left', text: '左上' },
26+
{ placement: 'top-right', text: '右上' },
27+
{ placement: 'bottom-left', text: '左下' },
28+
{ placement: 'bottom-right', text: '右下' },
29+
{ placement: 'bottom', text: '' },
30+
{ placement: 'top', text: '' }
31+
]
32+
return (): VNode =>
33+
h(NSpace, null, {
34+
default: () =>
35+
placementList.map((item: Item) =>
36+
h(
37+
NButton,
38+
{
39+
onClick: () => {
40+
props.onPlacementChange?.(item.placement)
41+
notification.info({
42+
title: item.placement,
43+
content: '你可以切换弹出位置'
44+
})
45+
}
46+
},
47+
{ default: () => item.text }
48+
)
49+
)
50+
})
51+
}
52+
})
53+
54+
const placementRef = ref<NotificationPlacement>('top-right')
2855
29-
return h(NSpace, null, {
30-
default: () =>
31-
placementList.map(item =>
32-
h(
33-
NButton,
34-
{
35-
onClick: () => {
36-
props.onPlacementChange?.(item.placement)
37-
notification.info({
38-
title: item.placement,
39-
content: 'You can change the placement'
40-
})
41-
}
42-
},
43-
{ default: () => item.text }
44-
)
45-
)
46-
})
56+
function handlePlacementChange(placement: NotificationPlacement) {
57+
placementRef.value = placement
4758
}
4859
</script>
4960

0 commit comments

Comments
 (0)