Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Button Component #19

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions apps/docs/pages/components/button.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { SHOWCASE_HOST } from "@/constants";
import React from "react";

# Button

## Installation

To get started, install Headless UI via npm:

```
npm install headlessui-react-native
```

## Basic example

Buttons are built using the `Button` component:

<iframe
src={`${SHOWCASE_HOST}/components/button`}
width="100%"
height="400px"
></iframe>

```jsx file=<rootDir>/node_modules/headlessui-react-native-example-ui/src/button/button-example.tsx

```

## Examples

### Disabling a button

Add the disabled prop to a Button to disable it:

```jsx
import { Button } from "headlessui-react-native";
import { useState } from "react";

function Example() {
return (
<View>
<Button title="hello" disabled />
</View>
);
}
```

## Component API

### Button

A thin wrapper around the native `button` element.

| Prop | Default | Description |
| :---------- | :------- | :---------------------------------------------------------------------------- |
| `as` | `button` | `String` or `Component` The element or component the button should render as. |
| `disabled` | `false` | `Boolean` Whether or not the button is disabled. |
| `autoFocus` | `false` | `Boolean` Whether or not the button should receive focus when first rendered. |
| `type` | `button` | `String` The button type. |
2 changes: 2 additions & 0 deletions apps/showcase/app/components/button/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { ButtonExample } from "headlessui-react-native-example-ui";
export default ButtonExample;
9 changes: 7 additions & 2 deletions apps/showcase/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { View } from "react-native";
import { router } from "expo-router";
import { Button, View } from "react-native";

export default function Page() {
return <View>sddsdqdqwws</View>;
return (
<View>
<Button title="sitemap" onPress={() => router.push("/_sitemap")}></Button>
</View>
);
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"workspaces": [
"apps/*",
"packages/*"
]
],
"devDependencies": {
"turbo": "^2.0.5"
}
}
10 changes: 10 additions & 0 deletions packages/example-ui/src/button/button-example.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { View } from "react-native";
import { Button } from "headlessui-react-native";

export function ButtonExample() {
return (
<View>
<Button title="hello" />
</View>
);
}
1 change: 1 addition & 0 deletions packages/example-ui/src/button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./button-example";
1 change: 1 addition & 0 deletions packages/example-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./modal";
export * from "./disclosure";
export * from "./button";
11 changes: 11 additions & 0 deletions packages/headlessui-react-native/src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import { ReactNativeComponentPropsType } from "../constants";
import { createReactNativeElement } from "../utils";

export const Button = ({
...rest
}: ReactNativeComponentPropsType<"Button">) => {
const Component = createReactNativeElement("Button");

return <Component {...rest}></Component>;
};
1 change: 1 addition & 0 deletions packages/headlessui-react-native/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./close-button";
export * from "./disclosure";
export * from "./modal";
export * from "./button";
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["**/.env.*local"],
"pipeline": {
"tasks": {
"dev": {
"cache": false,
"persistent": true
Expand Down
42 changes: 42 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9325,11 +9325,53 @@ tslib@^2.0.1, tslib@^2.1.0, tslib@^2.4.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

[email protected]:
version "2.0.5"
resolved "https://registry.yarnpkg.com/turbo-darwin-64/-/turbo-darwin-64-2.0.5.tgz#23c711370911d66e4589928243ec086c453709df"
integrity sha512-t/9XpWYIjOhIHUdwiR47SYBGYHkR1zWLxTkTNKZwCSn8BN0cfjPZ1BR6kcwYGxLGBhtl5GBf6A29nq2K7iwAjg==

[email protected]:
version "2.0.5"
resolved "https://registry.yarnpkg.com/turbo-darwin-arm64/-/turbo-darwin-arm64-2.0.5.tgz#a1e47e97cca55ba6e15d52f2ae7af41e74a4d837"
integrity sha512-//5y4RJvnal8CttOLBwlaBqblcQb1qTlIxLN+I8O3E3rPuvHOupNKB9ZJxYIQ8oWf8ns8Ec8cxQ0GSBLTJIMtA==

[email protected]:
version "2.0.5"
resolved "https://registry.yarnpkg.com/turbo-linux-64/-/turbo-linux-64-2.0.5.tgz#ef9da9b8d90ab2d9d0c1c473ee27426e03cdc953"
integrity sha512-LDtEDU2Gm8p3lKu//aHXZFRKUCVu68BNF9LQ+HmiCKFpNyK7khpMTxIAAUhDqt+AzlrbxtrxcCpCJaWg1JDjHg==

[email protected]:
version "2.0.5"
resolved "https://registry.yarnpkg.com/turbo-linux-arm64/-/turbo-linux-arm64-2.0.5.tgz#a7a0da918effa62ecc55668d4f4dc7266dedd7fa"
integrity sha512-84wdrzntErBNxkHcwHxiTZdaginQAxGPnwLTyZj8lpUYI7okPoxy3jKpUeMHN3adm3iDedl/x0mYSIvVVkmOiA==

turbo-stream@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/turbo-stream/-/turbo-stream-2.0.1.tgz#4daf74bc678ec1285b67ce42fe7a2852acdc3235"
integrity sha512-sm0ZtcX9YWh28p5X8t5McxC2uthrt9p+g0bGE0KTVFhnhNWefpSVCr+67zRNDUOfo4bpXwiOp7otO+dyQ7/y/A==

[email protected]:
version "2.0.5"
resolved "https://registry.yarnpkg.com/turbo-windows-64/-/turbo-windows-64-2.0.5.tgz#bfdce4337e2518eee9cb656258500effb1974b79"
integrity sha512-SgaFZ0VW6kHCJogLNuLEleAauAJx2Y48wazZGVRmBpgSUS2AylXesaBMhJaEScYqLz7mIRn6KOgwM8D4wTxI9g==

[email protected]:
version "2.0.5"
resolved "https://registry.yarnpkg.com/turbo-windows-arm64/-/turbo-windows-arm64-2.0.5.tgz#eb9d038e976cd3e7e11c6af5271314db9ef093b0"
integrity sha512-foUxLOZoru0IRNIxm53fkfM4ubas9P0nTFjIcHtd+E8YHeogt8GqTweNre2e6ri1EHDo71emmuQgpuoFCOXZMg==

turbo@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/turbo/-/turbo-2.0.5.tgz#e33eaae264e8e373a1ca80762b9289a802ab4cbc"
integrity sha512-+6+hcWr4nwuESlKqUc626HMOTd3QT8hUOc9QM45PP1d4nErGkNOgExm4Pcov3in7LTuadMnB0gcd/BuzkEDIPw==
optionalDependencies:
turbo-darwin-64 "2.0.5"
turbo-darwin-arm64 "2.0.5"
turbo-linux-64 "2.0.5"
turbo-linux-arm64 "2.0.5"
turbo-windows-64 "2.0.5"
turbo-windows-arm64 "2.0.5"

[email protected]:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
Expand Down