Skip to content

Commit

Permalink
feat(message-provider): add placement prop (tusen-ai#851)
Browse files Browse the repository at this point in the history
* feat:n-input Support hidden password

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

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

This reverts commit 0627777.

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

This reverts commit ea64917.

* feat(message provider): add placement prop(wip)

* feat(message provider): add placement prop

* feat: add demo

* feat: fix demo code

* feat: fix code

* feat: fix code

* Update CHANGELOG.en-US.md

* feat: fix style code
  • Loading branch information
doom-9-zz authored and rhengles committed Aug 31, 2021
1 parent cbae43a commit 060a4f2
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

### Feats

- `n-message-provider` add `container-style` prop
- `n-message-provider` add `container-style` prop.
- `n-message-provider` add `placement` prop.

### 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 @@ -9,6 +9,7 @@
### Feats

- `n-message-provider` 新增 `container-style` 属性
- `n-message-provider` 新增 `placement` 属性

### Fixes

Expand Down
6 changes: 4 additions & 2 deletions src/message/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { defineComponent } from 'vue'

// content
export default defineComponent({
setup () {
setup() {
const message = useMessage()
return {
warning () {
warning() {
message.warning('...')
}
}
Expand All @@ -45,6 +45,7 @@ modify-content
manually-close
about-theme
multiple-line
placement
```

## API
Expand All @@ -56,6 +57,7 @@ multiple-line
| closable | `boolean` | All messages whether to show close icon. |
| duration | `number` | `3000` | All messages's default duration. |
| max | `number` | `undefined` | Limit the number of message to display. |
| placement | `top \| top-left \| top-right \| bottom \| bottom-left \| bottom-right ` | `top` | All message's placement. |
| to | `string \| HTMLElement` | `'body'` | Container node of message container. |

### MessageProvider Injection API
Expand Down
119 changes: 119 additions & 0 deletions src/message/demos/enUS/placement.demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Placement

```html
<n-message-provider :placement="placement">
<Buttons @changePlacement="changePlacement" />
</n-message-provider>
```

```js
import { useMessage, NButton } from 'naive-ui'
import { h, ref } from 'vue'

const Buttons = {
emits: ['changePlacement'],
setup() {
const message = useMessage()
return {
message
}
},
render() {
return [
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'top')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => 'Top' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'bottom')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => 'Bottom' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'top-left')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => 'TopLeft' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'top-right')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => 'TopRight' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'bottom-left')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => 'BottomLeft' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'bottom-right')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => 'BottomRight' }
)
]
}
}

export default {
components: {
Buttons
},
setup() {
const placement = ref('top')
return {
placement,
changePlacement: (val) => {
placement.value = val
}
}
}
}
```
6 changes: 4 additions & 2 deletions src/message/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { defineComponent } from 'vue'

// content
export default defineComponent({
setup () {
setup() {
const message = useMessage()
return {
warning () {
warning() {
message.warning('...')
}
}
Expand All @@ -45,6 +45,7 @@ modify-content
manually-close
about-theme
multiple-line
placement
```

## API
Expand All @@ -56,6 +57,7 @@ multiple-line
| closable | `boolean` | 所有 Message 是否显示 close 图标 |
| duration | `number` | `3000` | 所有 Message 默认的持续时长 |
| max | `number` | `undefined` | 限制提示信息显示的个数 |
| placement | `top \| top-left \| top-right \| bottom \| bottom-left \| bottom-right ` | `top` | 所有 Message 显示的位置 |
| to | `string \| HTMLElement` | `'body'` | Message 容器节点的位置 |

### MessageProvider Injection API
Expand Down
119 changes: 119 additions & 0 deletions src/message/demos/zhCN/placement.demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# 位置

```html
<n-message-provider :placement="placement">
<Buttons @changePlacement="changePlacement" />
</n-message-provider>
```

```js
import { useMessage, NButton } from 'naive-ui'
import { h, ref } from 'vue'

const Buttons = {
emits: ['changePlacement'],
setup() {
const message = useMessage()
return {
message
}
},
render() {
return [
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'top')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => '顶部' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'bottom')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => '底部' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'top-left')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => '左上' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'top-right')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => '右上' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'bottom-left')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => '左下' }
),
h(
NButton,
{
onClick: () => {
this.$emit('changePlacement', 'bottom-right')
this.message.info('How many roads must a man walk down')
},
style: {
marginRight: '10px'
}
},
{ default: () => '右下' }
)
]
}
}

export default {
components: {
Buttons
},
setup() {
const placement = ref('top')
return {
placement,
changePlacement: (val) => {
placement.value = val
}
}
}
}
```
18 changes: 12 additions & 6 deletions src/message/src/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const iconMap = {
export default defineComponent({
name: 'Message',
props: messageProps,
setup (props) {
setup(props) {
const {
props: messageProviderProps,
mergedClsPrefixRef
Expand All @@ -51,7 +51,7 @@ export default defineComponent({
)
return {
mergedClsPrefix: mergedClsPrefixRef,
handleClose () {
handleClose() {
props.onClose?.()
},
cssVars: computed(() => {
Expand Down Expand Up @@ -106,10 +106,11 @@ export default defineComponent({
'--line-height': lineHeight,
'--border-radius': borderRadius
}
})
}),
placement: messageProviderProps.placement
}
},
render () {
render() {
const {
icon,
type,
Expand All @@ -124,7 +125,12 @@ export default defineComponent({
) : (
<div
class={`${mergedClsPrefix}-message-wrapper`}
style={cssVars as CSSProperties}
style={{
...(cssVars as CSSProperties),
alignItems: this.placement.startsWith('top')
? 'flex-start'
: 'flex-end'
}}
>
<div class={`${mergedClsPrefix}-message`}>
<div
Expand Down Expand Up @@ -152,7 +158,7 @@ export default defineComponent({
}
})

function createIconVNode (
function createIconVNode(
icon: undefined | (() => VNodeChild),
type: MessageType,
clsPrefix: string
Expand Down
Loading

0 comments on commit 060a4f2

Please sign in to comment.