-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@react-ui/core): add system compnent & factory
- Loading branch information
Showing
13 changed files
with
384 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
extends: ['custom/typescript'], | ||
ignorePatterns: ['babel.config.js'], | ||
ignorePatterns: [], | ||
}; |
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 |
---|---|---|
@@ -1,20 +1,43 @@ | ||
import { type DOMElements } from '../utils'; | ||
import { styled } from './core.styled'; | ||
import { type AnyObject, type DOMElements } from '../utils'; | ||
import { styled } from './core.system'; | ||
import { | ||
type As, | ||
type VigorComponent, | ||
type HTMLVigorComponents, | ||
} from './core.system.type'; | ||
|
||
class VigorFactory { | ||
private readonly _cache = new Map<DOMElements, DOMElements>(); | ||
type VigorFactory = (<Element extends As, Props = AnyObject>( | ||
element: Element, | ||
options?: any, // TODO: 나중에 확인 | ||
) => VigorComponent<Element, Props>) & | ||
HTMLVigorComponents; | ||
|
||
public init = (): any => { | ||
class Factory { | ||
private readonly _cache = new Map<DOMElements, VigorComponent<DOMElements>>(); | ||
|
||
public build = (): VigorFactory => { | ||
return new Proxy(styled, { | ||
/** | ||
* @example const Div = vigor('div'); | ||
*/ | ||
apply(_, __, args: [DOMElements, any]) { | ||
return styled(...args); | ||
}, | ||
|
||
/** | ||
* @example <vigor.div> | ||
*/ | ||
get: (_, element: DOMElements) => { | ||
if (!this._cache.has(element)) this._cache.set(element, element); | ||
if (!this._cache.has(element)) { | ||
this._cache.set(element, styled(element)); | ||
} | ||
|
||
return this._cache.get(element); | ||
}, | ||
}); | ||
}) as VigorFactory; | ||
}; | ||
} | ||
|
||
const vigorFactory = new VigorFactory(); | ||
const factory = new Factory(); | ||
|
||
export const vigor = vigorFactory.init(); | ||
export const vigor = factory.build(); |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { type AnyObject } from '../utils'; | ||
import { type VigorComponent, type As } from './core.system.type'; | ||
|
||
export function styled<Element extends As, Props = AnyObject>( | ||
element: Element, | ||
options?: any, // TODO: 나중에 확인 | ||
): any { | ||
let _element = element; | ||
|
||
const vigorComponent = React.forwardRef((props: AnyObject, ref) => { | ||
const asElement = props.as as Element; | ||
if (asElement !== undefined) _element = asElement; | ||
|
||
return React.createElement(_element, { ref, ...props }); | ||
}); | ||
|
||
return vigorComponent as VigorComponent<Element, Props>; | ||
} |
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,66 @@ | ||
import { type AnyObject, type Assign, type DOMElements } from '../utils'; | ||
|
||
export interface VigorProps { | ||
csm?: CSSModule; | ||
} | ||
|
||
export type As = React.ElementType; | ||
|
||
export type PropsOf<T extends As> = React.ComponentPropsWithoutRef<T> & { | ||
as?: As; | ||
}; | ||
|
||
export type OmitCommonProps<Target, OmitAdditionalProps> = Omit< | ||
Target, | ||
'as' | keyof OmitAdditionalProps | ||
>; | ||
|
||
export type RightJoinProps< | ||
SourceProps = AnyObject, | ||
OverrideProps = AnyObject, | ||
> = OmitCommonProps<SourceProps, keyof OverrideProps> & OverrideProps; | ||
|
||
export type MergeWithAs< | ||
OriginalElementProps, | ||
AsElementProps, | ||
ComponentProps = AnyObject, | ||
AsElement = As, | ||
> = ( | ||
| RightJoinProps<OriginalElementProps, ComponentProps> | ||
| RightJoinProps<AsElementProps, ComponentProps> | ||
) & { | ||
as?: AsElement; | ||
}; | ||
|
||
export interface ComponentWithAs< | ||
OriginalElement extends As, | ||
ComponentProps = AnyObject, | ||
> { | ||
<AsElement extends As = OriginalElement>( | ||
props: MergeWithAs< | ||
React.ComponentProps<OriginalElement>, | ||
React.ComponentProps<AsElement>, | ||
ComponentProps, | ||
AsElement | ||
>, | ||
): JSX.Element; | ||
propTypes?: React.WeakValidationMap<ComponentProps>; | ||
contextTypes?: React.ValidationMap<any>; | ||
defaultProps?: Partial<ComponentProps>; | ||
displayName?: string; | ||
} | ||
|
||
export interface VigorComponent< | ||
OriginalElement extends As, | ||
ComponentProps = AnyObject, | ||
> extends ComponentWithAs< | ||
OriginalElement, | ||
Assign<VigorProps, ComponentProps> | ||
> {} | ||
|
||
export type HTMLVigorComponents = { | ||
[Tag in DOMElements]: VigorComponent<Tag, AnyObject>; | ||
}; | ||
|
||
export type HTMLVigorProps<Element extends As> = Omit<PropsOf<Element>, 'ref'> & | ||
VigorProps; |
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 +1,2 @@ | ||
export * from './util.type'; | ||
export * from './util.dom.type'; |
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,3 @@ | ||
export type AnyObject = Record<string, unknown>; | ||
|
||
export type Assign<T, U> = Omit<T, keyof U> & U; |
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,5 @@ | ||
.button { | ||
width: 100px; | ||
height: 100px; | ||
background: coral; | ||
} |
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,11 @@ | ||
import React from 'react'; | ||
import { vigor } from '@react-ui/core/src'; | ||
import styles from './app.module.css'; | ||
|
||
export function App(): React.ReactNode { | ||
return <vigor.div>example</vigor.div>; | ||
return ( | ||
<> | ||
<vigor.div className={styles.button}>example</vigor.div> | ||
</> | ||
); | ||
} |
Oops, something went wrong.