-
Notifications
You must be signed in to change notification settings - Fork 1
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 #32 from js-tool-pack/perf
Perf
- Loading branch information
Showing
16 changed files
with
196 additions
and
187 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
import React from 'react'; | ||
import { getComponentClass } from '@pkg/shared'; | ||
import { getClassNames } from '@tool-pack/basic'; | ||
import { BaseLayoutsProps } from './layout.types'; | ||
import type { BaseLayoutsProps, LayoutProps } from './layout.types'; | ||
import { useElement } from './useElement'; | ||
import { RequiredPart } from '@tool-pack/types'; | ||
|
||
const rootClass = getComponentClass('layout'); | ||
export const Layout = React.forwardRef< | ||
HTMLElement, | ||
BaseLayoutsProps & { | ||
vertical?: boolean; | ||
} | ||
>((props, ref) => { | ||
const { vertical, className, children, ...rest } = props; | ||
return ( | ||
<section | ||
{...rest} | ||
ref={ref} | ||
className={getClassNames(rootClass, { | ||
export const Layout = React.forwardRef<HTMLElement, LayoutProps>( | ||
(props, ref) => { | ||
const { tag, vertical, className, children, ...rest } = | ||
props as RequiredPart<LayoutProps, 'tag'>; | ||
return React.createElement(tag, { | ||
...rest, | ||
ref, | ||
className: getClassNames(rootClass, { | ||
vertical, | ||
[className as string]: className, | ||
})}> | ||
{children} | ||
</section> | ||
); | ||
}); | ||
}), | ||
children, | ||
}); | ||
}, | ||
); | ||
Layout.defaultProps = { | ||
tag: 'section', | ||
} satisfies Partial<LayoutProps>; | ||
|
||
// main | ||
const mainRootClass = getComponentClass('main'); | ||
export const Main: React.FC<BaseLayoutsProps> = (props) => { | ||
return useElement(props, mainRootClass); | ||
}; | ||
Main.defaultProps = { | ||
tag: 'main', | ||
} satisfies Partial<BaseLayoutsProps>; | ||
|
||
// aside | ||
const asideRootClass = getComponentClass('aside'); | ||
export const Aside: React.FC<BaseLayoutsProps> = (props) => { | ||
return useElement(props, asideRootClass); | ||
}; | ||
Aside.defaultProps = { | ||
tag: 'aside', | ||
} satisfies Partial<BaseLayoutsProps>; | ||
|
||
// header | ||
const headerRootClass = getComponentClass('header'); | ||
export const Header: React.FC<BaseLayoutsProps> = (props) => { | ||
return useElement(props, headerRootClass); | ||
}; | ||
Header.defaultProps = { | ||
tag: 'header', | ||
} satisfies Partial<BaseLayoutsProps>; | ||
|
||
// footer | ||
const footerRootClass = getComponentClass('footer'); | ||
export const Footer: React.FC<BaseLayoutsProps> = (props) => { | ||
return useElement(props, footerRootClass); | ||
}; | ||
Footer.defaultProps = { | ||
tag: 'footer', | ||
} satisfies Partial<BaseLayoutsProps>; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
// import './layouts.scss'; | ||
export type { LayoutProps, BaseLayoutsProps } from './layout.types'; | ||
export * from './Layout'; | ||
export * from './Header'; | ||
export * from './Footer'; | ||
export * from './Main'; | ||
export * from './Aside'; |
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,3 +1,8 @@ | ||
import React from 'react'; | ||
|
||
export type BaseLayoutsProps = React.HTMLAttributes<HTMLElement>; | ||
export type BaseLayoutsProps = React.HTMLAttributes<HTMLElement> & { | ||
tag?: keyof HTMLElementTagNameMap; | ||
}; | ||
export type LayoutProps = BaseLayoutsProps & { | ||
vertical?: boolean; | ||
}; |
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 @@ | ||
import { BaseLayoutsProps } from './layout.types'; | ||
import { RequiredPart } from '@tool-pack/types'; | ||
import React from 'react'; | ||
import { getClassNames } from '@tool-pack/basic'; | ||
|
||
export function useElement(props: BaseLayoutsProps, rootClass: string) { | ||
const { children, className, tag, ...rest } = props as RequiredPart< | ||
BaseLayoutsProps, | ||
'tag' | ||
>; | ||
return React.createElement( | ||
tag, | ||
{ | ||
...rest, | ||
className: getClassNames(rootClass, { | ||
[className as string]: className, | ||
}), | ||
}, | ||
children, | ||
); | ||
} |
Oops, something went wrong.