Skip to content

Commit

Permalink
refactor: move common types to types.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nakzyu committed May 21, 2024
1 parent deec3ea commit 4cc5eca
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/headlessui-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "headlessui-react-native",
"title": "HeadlessUI React Native",
"description": "This is an unstyled, accessible headless UI library for React Native.",
"version": "1.1.4",
"version": "1.1.5",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"homepage": "https://headlessui-react-native.vercel.app",
Expand Down
7 changes: 2 additions & 5 deletions packages/headlessui-react-native/src/disclosure.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React, { useState } from "react";
import { View, ViewProps, PressableProps, Pressable } from "react-native";
import {
RenderPropsCallableComponent,
UIContext,
useUIContext,
} from "./useUIContext";
import { UIContext, useUIContext } from "./useUIContext";
import { CallableChildren } from "./callableChildren";
import { RenderPropsCallableComponent } from "./types";

export type DisclosureProps = {
defaultOpen?: boolean;
Expand Down
7 changes: 2 additions & 5 deletions packages/headlessui-react-native/src/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import {
View,
ViewProps,
} from "react-native";
import {
RenderPropsCallableComponent,
UIContext,
useUIContext,
} from "./useUIContext";
import { UIContext, useUIContext } from "./useUIContext";
import { CallableChildren } from "./callableChildren";
import { RenderPropsCallableComponent } from "./types";

export type ModalProps = {
onClose: () => void;
Expand Down
10 changes: 10 additions & 0 deletions packages/headlessui-react-native/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ReactNode } from "react";
import { ViewProps, PressableProps } from "react-native";

export type RenderPropsCallableComponent<
T extends ViewProps | PressableProps,
/* props to return */
U extends unknown
> = {
children: ReactNode | ((props: U) => ReactNode);
} & Omit<T, "children">;
13 changes: 2 additions & 11 deletions packages/headlessui-react-native/src/useUIContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ReactNode, createContext, useContext } from "react";
import { ViewProps, PressableProps } from "react-native";
import { createContext, useContext } from "react";

type UIContextValue = {
onClose: () => void;
Expand All @@ -13,15 +12,7 @@ export const UIContext = createContext<UIContextValue | undefined>(undefined);
export const useUIContext = () => {
const context = useContext(UIContext);
if (!context) {
throw new Error("useModal must be used within a Provider");
throw new Error("useUIContext must be used within a Provider");
}
return context;
};

export type RenderPropsCallableComponent<
T extends ViewProps | PressableProps,
/* props to return */
U extends unknown
> = {
children: ReactNode | ((props: U) => ReactNode);
} & Omit<T, "children">;

0 comments on commit 4cc5eca

Please sign in to comment.