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(drawer): [drawer] modify demo and icon #2465

Merged
merged 1 commit into from
Oct 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<script lang="tsx" setup>
import { ref } from 'vue'
import { TinyDrawer, TinyButton } from '@opentiny/vue'
import { TinyDrawer, TinyButton, Notify } from '@opentiny/vue'
Copy link
Member

Choose a reason for hiding this comment

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

建议改成使用Tiny前缀的导出吧~

import { iconHelp } from '@opentiny/vue-icon'

let drawerInstance = null
Expand All @@ -24,15 +24,26 @@ const config = ref({
showFooter: true,
// 通过 events 监听事件
events: {
open: (instance) => console.log('open 事件', instance),
close: () => console.log('close 事件')
open: (instance) =>
Notify({
type: 'info',
title: 'open 事件',
message: `${instance.title}`,
position: 'top-right'
}),
close: () =>
Notify({
type: 'info',
title: 'close 事件',
position: 'top-right'
})
Comment on lines +27 to +39
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider enhancing notification configuration

While the implementation is good, consider these improvements:

  1. Add error handling for the instance title access
  2. Use different notification types to better distinguish between open/close events

Here's a suggested implementation:

    open: (instance) =>
      Notify({
-       type: 'info',
+       type: 'success',
        title: 'open 事件',
-       message: `${instance.title}`,
+       message: instance?.title || '抽屉已打开',
        position: 'top-right'
      }),
    close: () =>
      Notify({
        type: 'info',
        title: 'close 事件',
+       message: '抽屉已关闭',
        position: 'top-right'
      })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
open: (instance) =>
Notify({
type: 'info',
title: 'open 事件',
message: `${instance.title}`,
position: 'top-right'
}),
close: () =>
Notify({
type: 'info',
title: 'close 事件',
position: 'top-right'
})
open: (instance) =>
Notify({
type: 'success',
title: 'open 事件',
message: instance?.title || '抽屉已打开',
position: 'top-right'
}),
close: () =>
Notify({
type: 'info',
title: 'close 事件',
message: '抽屉已关闭',
position: 'top-right'
})

},
// 通过属性 customSlots 设置插槽, 插槽内容可以是 string | VNode | ({h, $drawer}) => VNode
customSlots: {
// 使用 h 函数
default: (h) => h('p', { class: '' }, '抽屉主体内容。'),
// 返回 VNode 节点的方法, 可通过参数中 $drawer 访问到组件实例
headerRight: () => <IconHelp></IconHelp>,
headerRight: () => <IconHelp style="width:20px;height:20px"></IconHelp>,
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using CSS classes instead of inline styles

While the current implementation works, using inline styles reduces maintainability and reusability. Consider moving the styles to a CSS class.

Here's a suggested implementation:

-    headerRight: () => <IconHelp style="width:20px;height:20px"></IconHelp>,
+    headerRight: () => <IconHelp class="drawer-header-icon"></IconHelp>,

Add this CSS to your component's style section:

<style>
.drawer-header-icon {
  width: 20px;
  height: 20px;
}
</style>

// 直接赋值 VNode
footer: (
<TinyButton type="primary" onClick={closeDrawer}>
Expand Down
29 changes: 20 additions & 9 deletions examples/sites/demos/pc/app/drawer/use-through-method.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</template>

<script lang="tsx">
import { TinyDrawer, TinyButton } from '@opentiny/vue'
import { TinyDrawer, TinyButton, Notify } from '@opentiny/vue'
import { iconHelp } from '@opentiny/vue-icon'

export default {
Expand All @@ -18,6 +18,9 @@ export default {
}
},
methods: {
closeDrawer() {
this.drawerInstance.close()
},
Comment on lines +21 to +23
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling to closeDrawer method

The method should handle cases where drawerInstance might be null to prevent potential runtime errors.

Consider adding a null check:

 closeDrawer() {
+  if (!this.drawerInstance) {
+    return
+  }
   this.drawerInstance.close()
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
closeDrawer() {
this.drawerInstance.close()
},
closeDrawer() {
if (!this.drawerInstance) {
return
}
this.drawerInstance.close()
},

showDrawer() {
const IconHelp = iconHelp()
const config = {
Expand All @@ -27,27 +30,35 @@ export default {
showFooter: true,
// 通过 events 监听事件
events: {
open: (instance) => console.log('open 事件', instance),
close: () => console.log('close 事件')
open: (instance) =>
Notify({
type: 'info',
title: 'open 事件',
message: `${instance.title}`,
position: 'top-right'
}),
close: () =>
Notify({
type: 'info',
title: 'close 事件',
position: 'top-right'
})
Comment on lines +33 to +45
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving notification implementation

While the notifications provide good user feedback, consider these improvements:

  1. Extract repeated position config
  2. Make messages more user-friendly

Consider this refactoring:

+const NOTIFICATION_CONFIG = {
+  position: 'top-right',
+  type: 'info'
+}

 events: {
   open: (instance) =>
     Notify({
-      type: 'info',
-      title: 'open 事件',
+      ...NOTIFICATION_CONFIG,
+      title: '抽屉已打开',
       message: `${instance.title}`,
-      position: 'top-right'
     }),
   close: () =>
     Notify({
-      type: 'info',
-      title: 'close 事件',
-      position: 'top-right'
+      ...NOTIFICATION_CONFIG,
+      title: '抽屉已关闭'
     })
 }

Committable suggestion was skipped due to low confidence.

},
// 通过属性 customSlots 设置插槽, 插槽内容可以是 string | VNode | ({h, $drawer}) => VNode
customSlots: {
// 使用 h 函数
default: (h) => h('p', { class: '' }, '抽屉主体内容。'),
// 返回 VNode 节点的方法, 可通过参数中 $drawer 访问到组件实例
headerRight: () => <IconHelp></IconHelp>,
headerRight: () => <IconHelp style="width:20px;height:20px"></IconHelp>,
// 直接赋值 VNode
footer: (
<Button type="primary" onClick={this.closeDrawer}>
<TinyButton type="primary" onClick={this.closeDrawer}>
点击关闭
</Button>
</TinyButton>
)
}
}
this.drawerInstance = TinyDrawer.service(config)
},
closeDrawer() {
this.drawerInstance.close()
}
}
}
Expand Down
Loading