-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dropdown component support subMenu; add common pkg
- Loading branch information
Showing
30 changed files
with
253 additions
and
101 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 @@ | ||
Common |
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,16 @@ | ||
{ | ||
"name": "@suika/common", | ||
"private": true, | ||
"version": "0.0.1", | ||
"type": "module", | ||
"sideEffect": false, | ||
"main": "dist/common.es.js", | ||
"module": "dist/common.es.js", | ||
"types": "dist/common.d.ts", | ||
"scripts": { | ||
"build": "tsc && vite build" | ||
}, | ||
"devDependencies": { | ||
"vite": "^4.2.0" | ||
} | ||
} |
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 @@ | ||
export * from './event_emitter'; |
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 @@ | ||
/// <reference types="vite/client" /> |
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,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2015", | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"skipLibCheck": true, | ||
|
||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"] | ||
} |
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,11 @@ | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
build: { | ||
lib: { | ||
entry: 'src/index.ts', | ||
name: 'geo', | ||
fileName: (format) => `common.${format}.js`, | ||
}, | ||
}, | ||
}); |
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 |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
|
||
cursor: pointer; | ||
|
||
&:hover { | ||
&:hover, | ||
&.active { | ||
color: #fff; | ||
background-color: #0f8fff; | ||
} | ||
|
83 changes: 70 additions & 13 deletions
83
packages/components/src/components/dropdown/dropdown-item/dropdown-item.tsx
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,28 +1,85 @@ | ||
import { FC, PropsWithChildren } from 'react'; | ||
import { FC, useEffect, useState } from 'react'; | ||
import './dropdown-item.scss'; | ||
import { CheckOutlined } from '@suika/icons'; | ||
import { Dropdown } from '../dropdown'; | ||
import { DropdownEvents, Item } from '../type'; | ||
import { EventEmitter } from '@suika/common'; | ||
import classNames from 'classnames'; | ||
|
||
interface IProps extends PropsWithChildren { | ||
interface IProps { | ||
itemKey: string; | ||
label: string; | ||
suffix?: string; | ||
onClick: () => void; | ||
check?: boolean; | ||
subItems?: Item[]; | ||
|
||
onClick: (params: { key: string }) => void; | ||
|
||
emitter: EventEmitter<DropdownEvents>; | ||
} | ||
|
||
export const DropdownItem: FC<IProps> = ({ | ||
onClick, | ||
children, | ||
suffix, | ||
check, | ||
}) => { | ||
return ( | ||
<div className="sk-dropdown-item-wrap" onClick={onClick}> | ||
export const DropdownItem: FC<IProps> = (props) => { | ||
const { onClick, label, suffix, check, subItems, emitter } = props; | ||
|
||
useEffect(() => { | ||
const handleOpenSubMenu = () => { | ||
setOpen(false); | ||
}; | ||
|
||
emitter.on('openSubMenu', handleOpenSubMenu); | ||
return () => { | ||
emitter.off('openSubMenu', handleOpenSubMenu); | ||
}; | ||
}, [emitter, props.itemKey]); | ||
|
||
const item = ( | ||
<> | ||
<div className="sk-dropdown-item"> | ||
<div className="sk-dropdown-item-icon-box"> | ||
{check && <CheckOutlined />} | ||
</div> | ||
{children} | ||
{label} | ||
</div> | ||
{suffix && <span>{suffix}</span>} | ||
</div> | ||
</> | ||
); | ||
|
||
const [open, setOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
{subItems ? ( | ||
<Dropdown | ||
items={subItems} | ||
onClick={onClick} | ||
open={open} | ||
placement="right-start" | ||
offset={{ | ||
mainAxis: 0, | ||
crossAxis: -8, | ||
}} | ||
> | ||
<div | ||
className={classNames('sk-dropdown-item-wrap', { active: open })} | ||
onMouseEnter={() => { | ||
emitter.emit('openSubMenu', props.itemKey); | ||
setOpen(true); | ||
}} | ||
> | ||
{item} | ||
</div> | ||
</Dropdown> | ||
) : ( | ||
<div | ||
className="sk-dropdown-item-wrap" | ||
onClick={() => onClick({ key: props.itemKey })} | ||
onMouseEnter={() => { | ||
emitter.emit('openSubMenu', props.itemKey); | ||
}} | ||
> | ||
{item} | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; |
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
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,17 @@ | ||
export interface DropdownDivider { | ||
type: 'divider'; | ||
} | ||
|
||
export interface DropDownItemType { | ||
key: string; | ||
label: string; | ||
suffix?: string; | ||
check?: boolean; | ||
children?: DropDownItemType[]; | ||
} | ||
|
||
export type Item = DropDownItemType | DropdownDivider; | ||
|
||
export interface DropdownEvents { | ||
openSubMenu(key: string): void; | ||
} |
Oops, something went wrong.