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

[#1581] Message > 외부에서 Message close 할 수 있는 기능 추가 #1582

Merged
merged 1 commit into from
Jan 19, 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
23 changes: 23 additions & 0 deletions docs/views/message/example/Default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
Show HTML
</ev-button>
</div>
<div class="case">
<p class="case-title">Close from outside</p>
<ev-button @click="showForLong">Show forever</ev-button>
<ev-button v-show="isMessageShown" @click="hide">Hide</ev-button>
</div>
</template>

<script>
Expand All @@ -80,6 +85,7 @@ import { ref, getCurrentInstance } from 'vue';
export default {
setup() {
const { ctx } = getCurrentInstance();

const showInfo = () => {
ctx.$message('Infomation. This is an Info type message.');
};
Expand Down Expand Up @@ -135,6 +141,20 @@ export default {
useHTML: true,
});
};
const isMessageShown = ref(false);
let hideFunction = () => {};
const showForLong = () => {
const { hide } = ctx.$message({
message: 'This message stays long time until you press close button.',
duration: 10000000,
});
hideFunction = hide;
isMessageShown.value = true;
};
const hide = () => {
isMessageShown.value = false;
hideFunction();
};
return {
showInfo,
showSuccess,
Expand All @@ -146,6 +166,9 @@ export default {
onCloseMsg,
showOnClose,
showHTML,
showForLong,
hide,
isMessageShown,
};
},
};
Expand Down
8 changes: 7 additions & 1 deletion src/components/message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default {
default: null,
},
},
setup(props) {
setup(props, context) {
const state = reactive({
timer: null,
isShow: true,
Expand Down Expand Up @@ -120,6 +120,9 @@ export default {
closeMsg();
}
};
const hide = () => {
closeMsg();
};

onMounted(() => {
startTimer();
Expand All @@ -129,11 +132,14 @@ export default {
document.removeEventListener('keydown', keydown);
clearTimer();
});

context.expose({ hide });
return {
startTimer,
clearTimer,
closeMsg,
...toRefs(state),
hide,
};
},
};
Expand Down
3 changes: 3 additions & 0 deletions src/components/message/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const message = (options = {}) => {
componentObj,
msgOption,
);

render(instance, container);

return instance.component.exposed;
};

message.install = (app) => {
Expand Down