-
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 #101 from mj-studio-library/createSxComponent
createSxComponent util
- Loading branch information
Showing
9 changed files
with
70 additions
and
36 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 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,9 @@ | ||
import type { ComponentProps } from 'react'; | ||
import { Image, View } from 'react-native'; | ||
import { createSxComponent } from '@react-native-styled-system/core'; | ||
|
||
export const StyledView = createSxComponent(View)(); | ||
export type StyledViewProps = ComponentProps<typeof StyledView>; | ||
|
||
export const StyledImage = createSxComponent(Image)(); | ||
export type StyledImageProps = ComponentProps<typeof StyledImage>; |
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,33 @@ | ||
import type { ComponentType } from 'react'; | ||
import React, { forwardRef } from 'react'; | ||
|
||
import type { SxProps, TextSxProps } from '../@types/SxProps'; | ||
import { useSx } from '../hook/useSx'; | ||
|
||
export function createSxComponent<Props extends object, Ref>(Base: ComponentType<Props>) { | ||
return () => { | ||
const Transformed = forwardRef<Ref, Props & SxProps>(function (props, ref) { | ||
const { filteredProps, getStyle } = useSx(props); | ||
|
||
return <Base {...(filteredProps as any)} style={getStyle()} ref={ref as any} />; | ||
}); | ||
|
||
Transformed.displayName = `Sx.${Base.displayName || Base.name || 'NoName'}`; | ||
|
||
return Transformed; | ||
}; | ||
} | ||
|
||
export function createSxTextComponent<Props extends object, Ref>(Base: ComponentType<Props>) { | ||
return () => { | ||
const Transformed = forwardRef<Ref, Props & TextSxProps>(function (props, ref) { | ||
const { filteredProps, getStyle } = useSx(props, { styleType: 'TextStyle' }); | ||
|
||
return <Base {...(filteredProps as any)} style={getStyle()} ref={ref as any} />; | ||
}); | ||
|
||
Transformed.displayName = `Sx.${Base.displayName || Base.name || 'NoName'}`; | ||
|
||
return Transformed; | ||
}; | ||
} |