-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into dropdown-component-impl
Popover component's logic changed
- Loading branch information
Showing
18 changed files
with
504 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<template> | ||
<PageHeader> | ||
Confirm | ||
<template #description> | ||
A component that allows you to accept or reject a message that appears | ||
</template> | ||
</PageHeader> | ||
<Button | ||
secondary | ||
data-dimensions="large" | ||
@click="show()" | ||
> | ||
Press here to open confirm window | ||
</Button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import PageHeader from '../../components/PageHeader.vue'; | ||
import { Button, useConfirm } from '../../../src/vue'; | ||
const { confirm } = useConfirm(); | ||
async function show() { | ||
const res = await confirm( | ||
'CodeX', | ||
'Are you sure you want to delete the page?' | ||
); | ||
if (res) { | ||
// eslint-disable-next-line no-console | ||
console.log('The confirm button was pressed'); | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.log('The cancel button was pressed'); | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<template> | ||
<PageHeader> | ||
Popup | ||
<template #description> | ||
A component that appears on top of other components. Can include any other component. | ||
</template> | ||
</PageHeader> | ||
<Button | ||
secondary | ||
data-dimensions="large" | ||
@click="show()" | ||
> | ||
Press here to open popup | ||
</Button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import PageHeader from '../../components/PageHeader.vue'; | ||
import { Button, usePopup } from '../../../src/vue'; | ||
import StubText from './StubText.vue'; | ||
const { showPopup } = usePopup(); | ||
function show(): void { | ||
showPopup({ | ||
component: StubText, | ||
props: {}, | ||
}); | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<template> | ||
<div> | ||
Popup can include any component | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
:root { | ||
--z-popover: 3; | ||
--z-popup: calc(var(--z-popover) + 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<template> | ||
<div | ||
:class="$style['confirm']" | ||
data-dimensions="large" | ||
> | ||
<div class="text-ui-base-bold"> | ||
{{ title }} | ||
</div> | ||
<div :class="[$style['confirm__body'], 'text-ui-base-medium']"> | ||
{{ text }} | ||
</div> | ||
<div :class="$style['confirm__controls']"> | ||
<Button | ||
secondary | ||
@click="onCancel" | ||
> | ||
<div :class="$style['confirm__button-inner']"> | ||
{{ cancelText }} | ||
</div> | ||
</Button> | ||
<Button | ||
primary | ||
@click="onConfirm" | ||
> | ||
<div :class="$style['confirm__button-inner']"> | ||
{{ confirmText }} | ||
</div> | ||
</Button> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Button from '../button/Button.vue'; | ||
import { onMounted, onUnmounted } from 'vue'; | ||
const props = withDefaults( | ||
defineProps<{ | ||
/** | ||
* Text that will be displayed at the top of comfirm container | ||
*/ | ||
title: string; | ||
/** | ||
* Text that will be displayed in the middle part of the confirm container | ||
*/ | ||
text: string; | ||
/** | ||
* Text that will be displayed in the confirm button | ||
*/ | ||
confirmText?: string; | ||
/** | ||
* Text that will be displayed in the cancel button | ||
*/ | ||
cancelText?: string; | ||
/** | ||
* Function that is executed after pressing the Cancel button | ||
*/ | ||
onCancel: () => void; | ||
/** | ||
* Function that is executed after pressing the Confirm button | ||
*/ | ||
onConfirm: () => void; | ||
}>(), | ||
{ | ||
confirmText: 'Confirm', | ||
cancelText: 'Cancel', | ||
} | ||
); | ||
/** | ||
* Call onConfirm when enter was pressed | ||
* | ||
* @param event - the event object representing the keyboard event | ||
* @param event.key - the property of the event object that holds the value of the pressed key | ||
*/ | ||
const confirmOnEnter = (event: { key: string }) => { | ||
if (event.key === 'Enter') { | ||
props.onConfirm(); | ||
} | ||
}; | ||
/** | ||
* Call onCancel when esc was pressed | ||
* | ||
* @param event - the event object representing the keyboard event | ||
* @param event.key - the property of the event object that holds the value of the pressed key | ||
*/ | ||
const closeOnEsc = (event: { key: string }) => { | ||
if (event.key === 'Escape') { | ||
props.onCancel(); | ||
} | ||
}; | ||
onMounted(() => { | ||
document.addEventListener('keydown', confirmOnEnter); | ||
document.addEventListener('keydown', closeOnEsc); | ||
}); | ||
onUnmounted(() => { | ||
document.removeEventListener('keydown', confirmOnEnter); | ||
document.removeEventListener('keydown', closeOnEsc); | ||
}); | ||
</script> | ||
|
||
<style module> | ||
.confirm { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--v-padding); | ||
text-align: center; | ||
width: min-content; | ||
&__body { | ||
padding: 0 var(--spacing-ml) 0 var(--spacing-ml); | ||
word-wrap: break-word; | ||
} | ||
&__controls { | ||
display: flex; | ||
padding: var(--v-padding) 0 0 0; | ||
gap: var(--spacing-m); | ||
} | ||
&__button-inner { | ||
width: 84px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Confirm from './Confirm.vue'; | ||
export * from './useConfirm'; | ||
|
||
export { Confirm }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createSharedComposable } from '@vueuse/core'; | ||
import { usePopup } from '../popup'; | ||
import { Confirm } from '.'; | ||
|
||
export const useConfirm = createSharedComposable(() => { | ||
/** | ||
* Used to create a Popup component that will display the current Confirm | ||
*/ | ||
const { showPopup, hidePopup } = usePopup(); | ||
|
||
/** | ||
* @param title - title of the confirm window | ||
* @param text - message to be displayed in confirm window | ||
* @returns user selection result | ||
*/ | ||
async function confirm(title: string, text: string): Promise<boolean> { | ||
return new Promise<boolean>((resolve) => { | ||
showPopup({ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
component: Confirm, | ||
props: { | ||
title: title, | ||
text: text, | ||
onCancel: () => { | ||
resolve(false); | ||
hidePopup(); | ||
}, | ||
onConfirm: () => { | ||
resolve(true); | ||
hidePopup(); | ||
}, | ||
}, | ||
}); | ||
}); | ||
} | ||
|
||
return { | ||
confirm, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.