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

[Feature] Select component for Codex UI #279

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions codex-ui/dev/Playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ const pages = computed(() => [
isActive: route.path === '/components/vertical-menu',
},
{
title: 'Select',
onActivate: () => router.push('/components/select'),
isActive: route.path === '/components/select',
title: 'Dropdown',
onActivate: () => router.push('/components/dropdown'),
isActive: route.path === '/components/dropdown',
},
{
title: 'Card',
Expand Down
52 changes: 52 additions & 0 deletions codex-ui/dev/pages/components/Dropdown.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<PageHeader>
Dropdown
<template #description>
Component of the form that allows you to select one or more options from the list (currently one)
</template>
</PageHeader>
<Dropdown :items="dropdownItems" />
</template>

<script setup lang="ts">
import PageHeader from '../../components/PageHeader.vue';
import { ContextMenuItem, Dropdown } from '../../../src';

const dropdownItems: ContextMenuItem[] = [
{
type: 'default',
title: 'Header',
// eslint-disable-next-line no-console
onActivate: console.log,
},
{
title: 'Header 1',
icon: 'H1',
// eslint-disable-next-line no-console
onActivate: console.log,
},
{
type: 'separator',
},
{
type: 'default',
title: 'Image',
icon: 'Picture',
// eslint-disable-next-line no-console
onActivate: console.log,
},
{
type: 'separator',
},
{
type: 'default',
title: 'Text',
icon: 'Text',
// eslint-disable-next-line no-console
onActivate: console.log,
},
];
</script>

<style scoped>
</style>
15 changes: 0 additions & 15 deletions codex-ui/dev/pages/components/Select.vue

This file was deleted.

6 changes: 3 additions & 3 deletions codex-ui/dev/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ColorShemeIcons from './pages/components/ColorShemeIcons.vue';
import Popover from './pages/components/Popover.vue';
import Row from './pages/components/Row.vue';
import Section from './pages/components/Section.vue';
import Select from './pages/components/Select.vue';
import Dropdown from './pages/components/Dropdown.vue';
import Switch from './pages/components/Switch.vue';
import Tabbar from './pages/components/Tabbar.vue';
import VerticalMenu from './pages/components/VerticalMenu.vue';
Expand Down Expand Up @@ -86,8 +86,8 @@ const routes: RouteRecordRaw[] = [
component: Section as Component,
},
{
path: '/components/select',
component: Select as Component,
path: '/components/dropdown',
component: Dropdown as Component,
e11sy marked this conversation as resolved.
Show resolved Hide resolved
},
{
path: '/components/switch',
Expand Down
2 changes: 1 addition & 1 deletion codex-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
},
"devDependencies": {
"@codexteam/icons": "^0.3.0",
"@codexteam/icons": "^0.3.3",
"@editorjs/header": "^2.8.6",
"@editorjs/nested-list": "^1.4.2",
"@types/node": "^20.11.15",
Expand Down
90 changes: 90 additions & 0 deletions codex-ui/src/vue/components/dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<template>
<div
ref="dropdown"
:class="$style['dropdown']"
>
<Button
:class="$style['dropdown__btn']"
:icon="activeItem.icon"
trailing-icon="BracketsVertical"
secondary
@click="togglePopover($event.target, {vertically: 'below', horizontally: 'left'})"
>
{{ activeItem.title }}
</Button>
</div>
</template>
<script setup lang="ts">
import type { ContextMenuItem as Item } from '../context-menu/ContextMenu.types';
import { ContextMenu } from '../context-menu';
import { onMounted, ref } from 'vue';
import { usePopover, PopoverShowParams } from '../popover';
import { Button } from '../button';
const props = defineProps<{
items: Item[];
}>();
let isOpened = false;
const items = props.items;
const { showPopover, hide } = usePopover();
function togglePopover(el: HTMLElement, align: PopoverShowParams['align']) {
if (!isOpened) {
showPopover({
targetEl: el,
with: {
component: ContextMenu,
props: {
items: items,
},
},
align,
});
} else {
hide();
}
isOpened = !isOpened;
}
/* Default item value for select on page load */
const defaultValue: Item = {
title: 'Choose an option',
type: 'default',
onActivate: () => {},
};
const activeItem = ref(defaultValue);
/* Main function to update selected item */
const updateActiveItem = (item: Item) => {
if (item.type === 'default' || !item.type) {
activeItem.value = Object.create(item);
// eslint-disable-next-line no-console
activeItem.value.onActivate = console.log;
Copy link
Contributor

Choose a reason for hiding this comment

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

onActivate will recieve no parameters, so logs would be empty.

Anyway, i think, that this loggs are unneeded in app, where this component would be used

Copy link
Contributor

@e11sy e11sy Dec 3, 2024

Choose a reason for hiding this comment

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

also this works wrong:

  • If i open popover by pressing dropdown button, then isOpened becomes true
  • Then i select any option in context menu, popover becomes hidden, and title of the button updates
  • If i press popover button one more time it makes isOpened false and nothing changes on page (i expect popover to be opened again)

so we should manually hide() popover, when new item selected or popover closed by pressing anywhere else

hide();
}
};
onMounted(() => {
items.forEach((item) => {
if (item.type === 'default' || !item.type) {
item.onActivate = () => updateActiveItem(item);
}
});
});
</script>
<style lang="postcss" module>
.dropdown {
&__btn {
user-select: none;
background-color: var(--base--bg-secondary);
margin-bottom: var(--spacing-s);
padding-right: var(--spacing-s);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

seems redundant

&__btn:hover {
background-color: var(--base--bg-secondary-hover);
cursor: pointer;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same

</style>
3 changes: 3 additions & 0 deletions codex-ui/src/vue/components/dropdown/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Dropdown from './Dropdown.vue';

export { Dropdown };
1 change: 1 addition & 0 deletions codex-ui/src/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './components/theme-preview';
export * from './components/popover';
export * from './composables/useTheme';
export * from './components/checkbox';
export * from './components/dropdown';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"codex-ui"
],
"dependencies": {
"@codexteam/icons": "^0.3.0",
"@codexteam/icons": "^0.3.3",
"@hawk.so/javascript": "^3.0.2",
"@vueuse/core": "^10.3.0",
"codex-ui": "workspace:^",
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ __metadata:
languageName: node
linkType: hard

"@codexteam/icons@npm:^0.3.0":
version: 0.3.0
resolution: "@codexteam/icons@npm:0.3.0"
checksum: 4949e753a9f8d0442c581512566167dddf7853fce0aa388ec9ddd9acc2aa3f081192d266c0eb1a2f78154492f376f7ce042f69ca45cad9a1f02583ab70e0000b
"@codexteam/icons@npm:^0.3.3":
version: 0.3.3
resolution: "@codexteam/icons@npm:0.3.3"
checksum: aa3c2ea96122e981ab6a6544cfe88f2381da4ab56a09230b9123229d85e7f2134409a694e38efe31657d13265198e2391d23347d4be2b64a2bab85b223ef5d83
languageName: node
linkType: hard

Expand Down Expand Up @@ -2165,7 +2165,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "codex-ui@workspace:codex-ui"
dependencies:
"@codexteam/icons": ^0.3.0
"@codexteam/icons": ^0.3.3
"@editorjs/editorjs": 2.30.2
"@editorjs/header": ^2.8.6
"@editorjs/nested-list": ^1.4.2
Expand Down Expand Up @@ -4325,7 +4325,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "notes.web@workspace:."
dependencies:
"@codexteam/icons": ^0.3.0
"@codexteam/icons": ^0.3.3
"@eslint/eslintrc": ^3.1.0
"@eslint/js": ^9.3.0
"@hawk.so/javascript": ^3.0.2
Expand Down
Loading