Skip to content

Commit

Permalink
chore: release nativewind utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Viraj-10 committed Dec 3, 2024
1 parent 771896e commit 6ea1e29
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
11 changes: 9 additions & 2 deletions packages/nativewind/utils/tva/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { deepMergeObjects } from '../utils/deepMerge';
// @ts-ignore
import { tv } from 'tailwind-variants';
import { deepMergeObjects } from '../utils/deepMerge';
const tvatemp = (options, config) => {
const tvatemp = (
options,
/**
* The config object allows you to modify the default configuration.
* @see https://www.tailwind-variants.org/docs/api-reference#config-optional
*/
config
) => {
const parentVariants = options?.parentVariants;
const parentCompoundVariants = options?.parentCompoundVariants;
delete options.parentVariants;
Expand Down
14 changes: 13 additions & 1 deletion packages/nativewind/utils/withStates/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
export declare const withStates: <T>(Component: T) => T;
import React from 'react';
type WithStatesProps = {
className?: string;
states?: any;
};
export declare const withStates: <T extends React.ComponentType<any>>(
Component: T
) => React.ForwardRefExoticComponent<
React.PropsWithoutRef<React.ComponentProps<T>> &
WithStatesProps &
React.RefAttributes<T>
>;
export {};
5 changes: 1 addition & 4 deletions packages/nativewind/utils/withStates/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@ export const withStates = (Component) =>
if (!className) return;
return extractDataClassName(className, states);
}, [className, states]);
return (
// @ts-ignore
<Component className={classNamesFinal} {...props} ref={ref} />
);
return <Component className={classNamesFinal} {...props} ref={ref} />;
});
25 changes: 12 additions & 13 deletions packages/nativewind/utils/withStates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ type WithStatesProps = {
states?: any;
};

export const withStates = <T,>(Component: T) =>
React.forwardRef(
({ states, className, ...props }: T & WithStatesProps, ref?: any) => {
const classNamesFinal = React.useMemo(() => {
if (!className) return;
return extractDataClassName(className, states);
}, [className, states]);
export const withStates = <T extends React.ComponentType<any>>(Component: T) =>
React.forwardRef(({ states, className, ...props }, ref) => {
const classNamesFinal = React.useMemo(() => {
if (!className) return;
return extractDataClassName(className, states);
}, [className, states]);

return (
// @ts-ignore
<Component className={classNamesFinal} {...(props as any)} ref={ref} />
);
}
) as T;
return (
<Component className={classNamesFinal} {...(props as any)} ref={ref} />
);
}) as React.ForwardRefExoticComponent<
React.ComponentPropsWithoutRef<T> & WithStatesProps & React.RefAttributes<T>
>;

0 comments on commit 6ea1e29

Please sign in to comment.