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

feat(codex-ui): popup and confirm implementation #254

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0eaaafd
Added popup to the Playground
Jul 5, 2024
030c3a0
Added popup container
Jul 5, 2024
7db5988
Added close button
Jul 5, 2024
8a17f3e
Fix border
Jul 5, 2024
524df3c
Added trigger component what can show popup
Jul 6, 2024
c7a1a82
Added close button
Jul 6, 2024
36c01de
Added teleport
Jul 6, 2024
246848f
Added confirm component
Jul 6, 2024
56a0795
Remove useless style
Jul 6, 2024
3e3d8c3
Added functions to the buttons
Jul 6, 2024
243279a
Fix component description
Jul 7, 2024
aa750f4
Fix naming of the buttons
Jul 7, 2024
9ab7986
Move popup to the bottom of Playground
Jul 7, 2024
8ed65a1
Added usePopup function
Jul 7, 2024
3b27cf0
Remove vue teleport
Jul 15, 2024
bdd791c
Added Popup to the playground
Jul 15, 2024
0aea846
Merge branch 'main' into feat/popup-implementation
Jul 15, 2024
74d557f
Fix export
Jul 15, 2024
e5efa9a
Fix naming
Jul 17, 2024
baea337
Added missed comment
Jul 20, 2024
382694b
Added close on click outside the popup container
Jul 20, 2024
1a8764f
Added close on esc button
Jul 20, 2024
01a94ee
Change z-index level and rename body to text
Jul 20, 2024
3f2bb38
Added support enter button for confirm
Jul 20, 2024
1da8277
Change popup z-index
Jul 20, 2024
9698e0a
Move confirm to separate folder
Jul 21, 2024
87fac03
Added useConfirm
Jul 21, 2024
6d1fcba
Move onCancel and onConfirm logic
Jul 21, 2024
8ef117c
move usePopup logic to the useConfirm
Jul 21, 2024
c85ec65
Fix await logic
Jul 21, 2024
bffc40a
Remove interval
Jul 24, 2024
7e49c70
Merge branch 'main' into feat/popup-implementation
Sep 4, 2024
97dae48
Removed reduant onConfirm and onCancel fuctions
Sep 4, 2024
ee91e7c
Added separate page for Confirm
Sep 6, 2024
28bd1c3
Added stub text component
Sep 6, 2024
fb7215f
get rid of result ref
Sep 6, 2024
34ef9e1
Move on Escape reaction in usePopup
Sep 6, 2024
84d5273
Added hover to close button
Sep 6, 2024
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
9 changes: 8 additions & 1 deletion codex-ui/dev/Playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</div>
</div>
<Popover />
<Popup />
</div>
</template>

Expand All @@ -38,7 +39,8 @@ import { computed } from 'vue';
import {
VerticalMenu,
Tabbar,
Popover
Popover,
Popup
} from '../src/vue';
import { useTheme } from '../src/vue/composables/useTheme';

Expand Down Expand Up @@ -197,6 +199,11 @@ const pages = computed(() => [
onActivate: () => router.push('/components/editor'),
isActive: route.path === '/components/editor',
},
{
title: 'Popup',
onActivate: () => router.push('/components/popup'),
isActive: route.path === '/components/popup',
},
],
},
]);
Expand Down
48 changes: 48 additions & 0 deletions codex-ui/dev/pages/components/Popup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<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, Confirm, usePopup } from '../../../src/vue';

function onCancelFunction(): void {
// eslint-disable-next-line no-console
console.log('The cancel button was pressed');
}

function onConfirmFunction(): void {
// eslint-disable-next-line no-console
console.log('The confirm button was pressed');
}

const { showPopup } = usePopup();

function show() {
showPopup({
component: Confirm,
props: {
title: 'CodeX',
body: 'Are you sure you want to delete the page?',
onCancel: onCancelFunction,
onConfirm: onConfirmFunction,
},
});
}

</script>

<style scoped>
</style>
5 changes: 5 additions & 0 deletions codex-ui/dev/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import VerticalMenu from './pages/components/VerticalMenu.vue';
import ContextMenu from './pages/components/ContextMenu.vue';
import Editor from './pages/components/Editor.vue';
import ThemePreview from './pages/components/ThemePreview.vue';
import Popup from './pages/components/Popup.vue';

/**
* Vue router routes list
Expand Down Expand Up @@ -145,6 +146,10 @@ const routes: RouteRecordRaw[] = [
path: '/components/theme-preview',
component: ThemePreview as Component,
},
{
path: '/components/popup',
component: Popup as Component,
},
];

export default routes;
93 changes: 93 additions & 0 deletions codex-ui/src/vue/components/popup/Confirm.vue
Copy link
Member

Choose a reason for hiding this comment

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

Let's also create a useConfirm() composable? It will be a preset using Popup + Confirm. It will simplify end usage.

Also, it is useful if "confirm" will return a promise.

Example:

const { confirm } = useConfirm()

async function deleteNote() {
  try {
    await confirm('Are you sure')?
    
    service.deleteNote()
  } catch(e){}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<template>
<div
:class="$style['confirm']"
data-dimensions="large"
>
<div :class="['text-ui-base-bold']">
TatianaFomina marked this conversation as resolved.
Show resolved Hide resolved
{{ title }}
</div>
<div :class="[$style['confirm__body'], 'text-ui-base-medium']">
{{ body }}
</div>
<div :class="$style['confirm__controls']">
<Button
secondary
@click="onCancel"
>
<div :class="$style['confirm__button-inner']">
Cancel
TatianaFomina marked this conversation as resolved.
Show resolved Hide resolved
</div>
</Button>
<Button
primary
@click="onConfirm"
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
>
<div :class="$style['confirm__button-inner']">
{{ confirmButton }}
</div>
</Button>
</div>
</div>
</template>

<script setup lang="ts">
import Button from '../button/Button.vue';

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
*/
body: string;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
body: string;
text: string;


/**
* Text that will be displayed in the confirm button
*/
confirmButton?: string;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

/**
* The function that is called when click on the cancel button
*/
onCancel: () => void;

/**
* The function that is called when click on the confirm button
*/
onConfirm: () => void;
}>(),
{
confirmButton: 'Confirm',
}
);
</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>
14 changes: 14 additions & 0 deletions codex-ui/src/vue/components/popup/Popup.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Component } from 'vue';

export interface PopupContent {
/**
* Component to render in the popup
*/
component: Component;

/**
* Props to pass to the component
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
props: Record<string, any>;
}
79 changes: 79 additions & 0 deletions codex-ui/src/vue/components/popup/Popup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div
v-show="isActive"
:class="$style['popup']"
>
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
<div :class="$style['popup__container']">
<component
:is="content.component"
v-if="content"
v-bind="content.props"
/>
</div>
<Icon
v-if="hasCloseButton"
:class="$style['popup__icon']"
name="Cross"
@click="hidePopup"
/>
</div>
</template>

<script setup lang="ts">
import Icon from '../icon/Icon.vue';
import { usePopup } from './usePopup';

const {
isActive,
hidePopup,
content,
} = usePopup();

withDefaults(
defineProps<{
/**
* If true, a button to close the popup appears
*/
hasCloseButton?: boolean;
}>(),
{
hasCloseButton: true,
}
);

</script>

<style module>

.popup {
z-index: var(--z-popover);
Copy link
Member

Choose a reason for hiding this comment

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

lets a separate variable in z-axis.pcss --z-popup which will be cal(var(--z-popover) + 1)

inset: 0;
display: grid;
grid-template-columns: auto auto;
position: fixed;
align-content: center;
gap: var(--spacing-l);
justify-content: center;
align-items: start;
background-color: rgba(0, 0, 0, 0.49);
align-items: baseline;
color: var(--base--text);

&__container {
gap: var(--spacing-ml);
padding: var(--spacing-l);
border-radius: var(--radius-ml);
background-color: var(--base--bg-primary);
box-shadow: inset 0 0 0 var(--delimiter-height) var(--base--border);
}

&__icon {
Copy link
Member

Choose a reason for hiding this comment

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

The close button is displayed lower than it should be.

image image

Copy link
Member

Choose a reason for hiding this comment

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

also, please add hover to it. (Making icon and border color of --base--text)

Copy link
Contributor Author

@elizachi elizachi Sep 6, 2024

Choose a reason for hiding this comment

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

The close button is displayed lower than it should be.

image image

The exact same sized icon is on the icon page - all indents are respected
There is a similar case in tabbar component, I think this is a problem with icons in general

cursor: pointer;
color: var(--base--text-secondary);
padding: var(--spacing-very-x);
box-shadow: inset 0 0 0 var(--delimiter-height);
border-radius: var(--radius-l);
}
}

</style>
6 changes: 6 additions & 0 deletions codex-ui/src/vue/components/popup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Popup from './Popup.vue';
import Confirm from './Confirm.vue';
export * from './usePopup';
export * from './Popup.types';

export { Popup, Confirm };
58 changes: 58 additions & 0 deletions codex-ui/src/vue/components/popup/usePopup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { createSharedComposable } from '@vueuse/core';
import { ref, shallowRef } from 'vue';
import type { PopupContent } from './Popup.types';

export const usePopup = createSharedComposable(() => {
/**
* Popup active state
*/
const isActive = ref(false);
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

/**
* Popup content: component and props
*/
const content = shallowRef<PopupContent | null>(null);

/**
* Method for attaching a component to the popup
* @param component - component to attach
* @param props - props to pass to the component
*/
function mountComponent(component: PopupContent['component'], props: PopupContent['props']): void {
content.value = {
component,
props,
};
}

/**
* Show popup
*/
function show(): void {
isActive.value = true;
}

/**
* Mount component into popup and show it
* @param params - popup showing configuration
*/
function showPopup(params: PopupContent): void {
mountComponent(params.component, params.props);
show();
}

/**
* Сlear the content inside the popup and hide popup
*/
function hidePopup(): void {
content.value = null;
isActive.value = false;
}

return {
isActive,
showPopup,
hidePopup,
content,
};
});
1 change: 1 addition & 0 deletions codex-ui/src/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export * from './components/vertical-menu';
export * from './components/colorShemeIcons';
export * from './components/theme-preview';
export * from './components/popover';
export * from './components/popup';
export * from './composables/useTheme';
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<Header />
<router-view />
<Popover />
<Popup />
</template>

<script lang="ts" setup>
import Header from '@/presentation/components/header/Header.vue';
import { onErrorCaptured } from 'vue';
import { useTheme, Popover } from 'codex-ui/vue';
import { useTheme, Popover, Popup } from 'codex-ui/vue';
import useAuthRequired from '@/application/services/useAuthRequired';

/**
Expand Down
Loading