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: added KMenu component #440

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
db4d588
wip: init KMenu component
baiwusanyu-c Apr 15, 2024
2e6cf3d
wip: KMEnu api design
baiwusanyu-c Apr 15, 2024
747e776
wip: temp commit
baiwusanyu-c Apr 15, 2024
c7b1f03
wip: temp commit
baiwusanyu-c Apr 15, 2024
8a4f7f9
wip: recursive slots and dynamic context
baiwusanyu-c Apr 16, 2024
8292b95
wip: initial drawing of menu component inline mode
baiwusanyu-c Apr 16, 2024
f1f00c5
wip: KMenu component completes submenu expansion animation
baiwusanyu-c Apr 16, 2024
2ba3233
wip: KMenu component completes submenu expansion animation
baiwusanyu-c Apr 16, 2024
ea22ff8
wip: fix expend animation
baiwusanyu-c Apr 17, 2024
f625554
wip: complete the selected style of the KMenu component submenu
baiwusanyu-c Apr 17, 2024
9f39ad6
wip: KMenu component completes incremental changes in submenu backgro…
baiwusanyu-c Apr 17, 2024
f05ed44
wip: KMenu component completes inline mode default submenu expansion
baiwusanyu-c Apr 17, 2024
a760a5a
wip: KMenu component completes inline mode default submenu select item
baiwusanyu-c Apr 17, 2024
0882d56
wip: KMenu component completes inline mode expendIcon and item icon s…
baiwusanyu-c Apr 17, 2024
beadd41
wip: temp commit
baiwusanyu-c Apr 17, 2024
7073947
wip: KMenu component completes inline mode click event
baiwusanyu-c Apr 17, 2024
1a65321
wip: KMenu component completes inline mode openChange event
baiwusanyu-c Apr 18, 2024
54d6397
wip: KMenu component completes inline mode select event
baiwusanyu-c Apr 18, 2024
cd4e682
wip: updated todo list
baiwusanyu-c Apr 18, 2024
fc0d119
wip: remove types
baiwusanyu-c Apr 18, 2024
9c53c1b
wip: KMenu component completes inline mode selectable props
baiwusanyu-c Apr 19, 2024
522036c
wip:temp commit
baiwusanyu-c Apr 21, 2024
4566872
wip: KMenu component completes vertical mode group item render
baiwusanyu-c Apr 21, 2024
7633e40
wip: optimize the grouping style of KMenu component in vertical mode
baiwusanyu-c Apr 21, 2024
06305bf
wip: temp commit
baiwusanyu-c Apr 21, 2024
b0b0c1b
wip: fix gorup item render error
baiwusanyu-c Apr 21, 2024
72ad9fb
wip: KMenu component completes vertical mode subMenuCloseDelay and su…
baiwusanyu-c Apr 22, 2024
81854d4
wip: KMenu component completes vertical and inline mode onDeSelect event
baiwusanyu-c Apr 22, 2024
c5f8bcc
wip: KMenu component vertical mode openUids props temp commit
baiwusanyu-c Apr 22, 2024
6fefbd7
wip: complete KMenu component vertical mode openUids props
baiwusanyu-c Apr 22, 2024
024a978
wip: complete the styling of the KMenu component in horizontal mode
baiwusanyu-c Apr 23, 2024
a1a40a4
wip: optimization the styling of the KMenu component in horizontal mode
baiwusanyu-c Apr 23, 2024
65dc2cb
wip: complete KMenu component temp commit
baiwusanyu-c Apr 23, 2024
3d16806
wip: temp commit
baiwusanyu-c Apr 24, 2024
af38ed4
wip: complete KMenu component temp commit
baiwusanyu-c Apr 24, 2024
275cd8d
wip: horizontal mode is turned on by default and is compatible with
baiwusanyu-c Apr 25, 2024
969fe23
wip: set horizontal width more correctly
baiwusanyu-c Apr 25, 2024
add53d0
wip: Preliminary drawing of omitted icons
baiwusanyu-c Apr 26, 2024
ddbb701
wip: complete KMenu component horizontal mode omit display
baiwusanyu-c Apr 28, 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
32 changes: 32 additions & 0 deletions components/Menu/__test__/menu.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import KMenu from '../src';

let host;

const initHost = () => {
host = globalThis.document.createElement('div');
host.setAttribute('id', 'host');
globalThis.document.body.appendChild(host);
};
beforeEach(() => {
initHost();
vi.useFakeTimers();
});
afterEach(() => {
host.remove();
vi.useRealTimers();
});

describe('Test: KMenu', () => {
test('props: cls', async () => {
const instance = new KMenu({
target: host,
props: {
cls: 'k-menu--test'
}
});
expect(instance).toBeTruthy();
expect(host!.innerHTML.includes('k-menu--test')).toBeTruthy();
expect(host.innerHTML).matchSnapshot();
});
});
50 changes: 50 additions & 0 deletions components/Menu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@ikun-ui/menu",
"version": "0.2.6",
"type": "module",
"main": "src/index.ts",
"types": "src/index.d.ts",
"svelte": "src/index.ts",
"keywords": [
"svelte",
"svelte3",
"web component",
"component",
"react",
"vue",
"svelte-kit",
"dx"
],
"files": [
"dist",
"package.json"
],
"scripts": {
"build": "svelte-package -i src",
"publish:pre": "node ../../scripts/pre-publish.js",
"publish:npm": "pnpm run publish:pre && pnpm publish --no-git-checks --access public"
},
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"module": "dist/index.js",
"svelte": "dist/index.js",
"types": "dist/index.d.ts"
},
"dependencies": {
"@ikun-ui/icon": "workspace:*",
"@ikun-ui/utils": "workspace:*",
"@ikun-ui/divider": "workspace:*",
"@ikun-ui/popover": "workspace:*",
"baiwusanyu-utils": "^1.0.18",
"esm-env": "^1.0.0",
"clsx": "^2.0.0",
"svelte": "^4.2.7"
},
"devDependencies": {
"@sveltejs/package": "^2.3.1",
"@tsconfig/svelte": "^5.0.4",
"tslib": "^2.6.2",
"typescript": "^5.4.4"
}
}
114 changes: 114 additions & 0 deletions components/Menu/src/index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<script lang="ts">
import { menuKey, getPrefixCls } from '@ikun-ui/utils';
import { clsx } from 'clsx';
import type { ClickEvtPa, KMenuProps, SelectEvtPa } from './types';
import { createEventDispatcher, getContext, setContext } from 'svelte';
import { createKMenu, transitionIn, transitionOut } from './utils';
export let triggerSubMenuAction: KMenuProps['triggerSubMenuAction'] = 'hover';
export let subMenuCloseDelay: KMenuProps['subMenuCloseDelay'] = 100;
export let subMenuOpenDelay: KMenuProps['subMenuOpenDelay'] = 0;
export let inlineIndent: KMenuProps['inlineIndent'] = 24;
export let expandIcon: KMenuProps['expandIcon'] = '';
export let mode: KMenuProps['mode'] = 'vertical';
export let cls: KMenuProps['cls'] = undefined;
export let attrs: KMenuProps['attrs'] = {};
export let selectedUids: KMenuProps['selectedUids'] = [];
export let openUids: KMenuProps['openUids'] = [];
export let show: KMenuProps['show'] = true;
export let multiple: KMenuProps['multiple'] = true;
export let selectable: KMenuProps['selectable'] = true;
export let ctxKey: KMenuProps['ctxKey'] = '';
const dispatch = createEventDispatcher();
function onOpenChange(openUids: string[]) {
dispatch('openChange', openUids);
}

function onSelect(data: SelectEvtPa) {
dispatch('select', data);
}

function onClick(data: ClickEvtPa) {
dispatch('click', data);
}

function onDeSelect(data: SelectEvtPa) {
dispatch('deSelect', data);
}

let bdBg = 'transparent';
function removeBorderStyleBg() {
bdBg = '';
}

let menuRef: null | HTMLElement = null;
function getParentDom() {
if (menuRef) {
return menuRef.parentElement;
}
}
/**
* @internal
*/
const menuInst = createKMenu(
{
triggerSubMenuAction,
subMenuCloseDelay,
subMenuOpenDelay,
expandIcon,
mode,
inlineIndent,
openUids,
selectedUids,
multiple,
selectable,
attrs,
ctxKey
},
onOpenChange,
onSelect,
onClick,
onDeSelect,
removeBorderStyleBg,
getParentDom
);
if (!getContext(ctxKey || menuKey)) {
setContext(ctxKey || menuKey, menuInst);
}
$: {
menuInst.__propHandleEvtMap.forEach((cb) => {
cb({
triggerSubMenuAction,
subMenuCloseDelay,
subMenuOpenDelay,
expandIcon,
mode,
inlineIndent,
openUids,
multiple,
selectedUids,
selectable,
attrs,
ctxKey
});
});
}

const prefixCls = getPrefixCls('menu');
$: cnames = clsx(prefixCls, `${prefixCls}-${mode}`, cls);
</script>

{#if show}
<div class="overflow-hidden" bind:this={menuRef}>
<ul
class={cnames}
style:border-color={bdBg}
style:transition="height 0.3s"
in:transitionIn
out:transitionOut
{...$$restProps}
{...attrs}
>
<slot />
</ul>
</div>
{/if}
13 changes: 13 additions & 0 deletions components/Menu/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Menu from './index.svelte';
import MenuItem from './item.svelte';
export { Menu as KMenu };
export { MenuItem as KMenuItem };
export default Menu;

export type {
KMenuInstanceOption,
KMenuItemProps,
KMenuInstance,
KMenuProps,
SubMenuType
} from './types';
Loading
Loading