Skip to content

Commit

Permalink
feat(shared): 新增getClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxinssfd committed Aug 6, 2023
1 parent ea636c1 commit 6e7bd57
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/shared/src/utils/getClasses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { getComponentClass } from './getComponentClass';

export function getClasses<
const C extends readonly string[],
const S extends readonly string[],
>(
name: string,
children: C,
state: S,
): Readonly<{
root: string;
__: Record<C[number], string>;
'--': Record<S[number], string>;
}> {
const root = getComponentClass(name);
return {
root,
__: handleClasses(root, '__', children),
'--': handleClasses(root, '--', state),
};
}

function handleClasses(
root: string,
divider: '__' | '--',
list: readonly string[],
): Record<string, string> {
return list.reduce((result, status) => {
result[status] = `${root}${divider}${status}`;
return result;
}, {} as Record<string, string>);
}
1 change: 1 addition & 0 deletions packages/shared/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './getComponentClass';
export * from './numToPx';
export * from './getElRealSize';
export * from './getSizeClassName';
export * from './getClasses';

0 comments on commit 6e7bd57

Please sign in to comment.