Skip to content

Commit

Permalink
Merge pull request #104 from mj-studio-library/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
mym0404 authored Jun 14, 2024
2 parents fe7492a + fd2e57d commit c215bdf
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/core/src/util/createSxComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import type { ComponentType } from 'react';
import React, { forwardRef } from 'react';

import type { SxProps, TextSxProps } from '../@types/SxProps';
import type { UseSxOptions } from '../hook/useSx';
import { useSx } from '../hook/useSx';

export function createSxComponent<Props extends object, Ref>(Base: ComponentType<Props>) {
export function createSxComponent<Props extends object, Ref>(
Base: ComponentType<Props>,
{ defaultProps, sxOptions }: { defaultProps?: Props & SxProps; sxOptions?: UseSxOptions } = {},
) {
return () => {
const Transformed = forwardRef<Ref, Props & SxProps>(function (props, ref) {
const { filteredProps, getStyle } = useSx(props);
const { filteredProps, getStyle } = useSx({ ...defaultProps, ...props }, sxOptions);

return <Base {...(filteredProps as any)} style={getStyle()} ref={ref as any} />;
});
Expand All @@ -18,10 +22,19 @@ export function createSxComponent<Props extends object, Ref>(Base: ComponentType
};
}

export function createSxTextComponent<Props extends object, Ref>(Base: ComponentType<Props>) {
export function createSxTextComponent<Props extends object, Ref>(
Base: ComponentType<Props>,
{
defaultProps,
sxOptions,
}: { defaultProps?: Props & TextSxProps; sxOptions?: UseSxOptions } = {},
) {
return () => {
const Transformed = forwardRef<Ref, Props & TextSxProps>(function (props, ref) {
const { filteredProps, getStyle } = useSx(props, { styleType: 'TextStyle' });
const { filteredProps, getStyle } = useSx(
{ ...defaultProps, ...props },
{ styleType: 'TextStyle', ...sxOptions },
);

return <Base {...(filteredProps as any)} style={getStyle()} ref={ref as any} />;
});
Expand Down

0 comments on commit c215bdf

Please sign in to comment.