-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from duenyang/feature/switch
feat(switch): switch complete 🎉
- Loading branch information
Showing
32 changed files
with
568 additions
and
287 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
import { type ClassValue, clsx } from 'clsx'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
export default function classname(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)); | ||
} | ||
|
||
export function getClassPrefix() { | ||
return (window as any).__TDESIGN_THEME_PREFIX__ || 't'; | ||
} | ||
|
||
export const classPrefix = getClassPrefix(); | ||
|
||
export function getCommonClassName() { | ||
const names = { | ||
SIZE: { | ||
default: '', | ||
xs: `${classPrefix}-size-xs`, | ||
small: `${classPrefix}-size-s`, | ||
medium: `${classPrefix}-size-m`, | ||
large: `${classPrefix}-size-l`, | ||
xl: `${classPrefix}-size-xl`, | ||
block: `${classPrefix}-size-full-width`, | ||
}, | ||
STATUS: { | ||
loading: `${classPrefix}-is-loading`, | ||
disabled: `${classPrefix}-is-disabled`, | ||
focused: `${classPrefix}-is-focused`, | ||
success: `${classPrefix}-is-success`, | ||
error: `${classPrefix}-is-error`, | ||
warning: `${classPrefix}-is-warning`, | ||
selected: `${classPrefix}-is-selected`, | ||
active: `${classPrefix}-is-active`, | ||
checked: `${classPrefix}-is-checked`, | ||
current: `${classPrefix}-is-current`, | ||
hidden: `${classPrefix}-is-hidden`, | ||
visible: `${classPrefix}-is-visible`, | ||
expanded: `${classPrefix}-is-expanded`, | ||
indeterminate: `${classPrefix}-is-indeterminate`, | ||
}, | ||
}; | ||
return { | ||
SIZE: names.SIZE, | ||
STATUS: names.STATUS, | ||
sizeClassNames: names.SIZE, | ||
statusClassNames: names.STATUS, | ||
classPrefix, | ||
}; | ||
} |
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,38 @@ | ||
import isFunction from 'lodash/isFunction'; | ||
import { cloneElement } from 'omi'; | ||
|
||
import log from '../_common/js/log'; | ||
import { TNode } from '../common'; | ||
|
||
// 解析 TNode 数据结构 | ||
export default function parseTNode( | ||
renderNode: TNode | TNode<any> | undefined, | ||
renderParams?: any, | ||
defaultNode?: TNode, | ||
): TNode { | ||
let node: TNode = null; | ||
|
||
if (typeof renderNode === 'function') { | ||
node = renderNode(renderParams); | ||
} else if (renderNode !== null) { | ||
node = renderNode ?? defaultNode; | ||
} | ||
return node as TNode; | ||
} | ||
|
||
/** | ||
* 解析各种数据类型的 TNode | ||
* 函数类型:content={(props) => <Icon></Icon>} | ||
* 组件类型:content={<Button>click me</Button>} 这种方式可以避免函数重复渲染,对应的 props 已经注入 | ||
* 字符类型 | ||
*/ | ||
export function parseContentTNode<T>(tnode: TNode<T>, props: T) { | ||
if (isFunction(tnode)) return tnode(props) as TNode; | ||
if (!tnode || ['string', 'number', 'boolean'].includes(typeof tnode)) return tnode as TNode; | ||
try { | ||
return cloneElement(tnode, { ...props }); | ||
} catch (e) { | ||
log.warn('parseContentTNode', `${tnode} is not a valid ReactNode`); | ||
return null; | ||
} | ||
} |
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.