Skip to content

Commit a5c6702

Browse files
authored
Merge pull request #239 from gluestack/release/@gluestack-ui/[email protected]
release: @gluestack-ui/button version 0.1.5
2 parents 5e3cdbc + 4d11a01 commit a5c6702

File tree

11 files changed

+378
-403
lines changed

11 files changed

+378
-403
lines changed

example/storybook/.storybook/preview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const parameters = {
1616
'Overview',
1717
['Introduction', 'Accessibility'],
1818
'Getting Started',
19-
['Installation', 'SSR', 'Fonts'],
19+
['Installation', 'Install in Expo', 'Install in Next.js', 'SSR'],
2020
'Components',
2121
[
2222
'Provider',

example/storybook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@dank-style/animation-plugin": "^0.0.1",
2424
"@dank-style/react": "^0.3.10",
2525
"@expo/html-elements": "^0.4.1",
26-
"@gluestack/design-system": "0.3.19",
26+
"@gluestack/design-system": "0.3.35",
2727
"@legendapp/motion": "^2.2.0",
2828
"@react-native-aria/overlays": "0.3.5-rc.2",
2929
"@react-native-async-storage/async-storage": "~1.17.3",

example/storybook/src/components/Forms/Button/ButtonGroup.stories.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@ const ButtonGroup: ComponentMeta<any> = {
77
title: 'stories/FORMS/Button',
88
component: GroupedExample,
99
args: {
10-
size: 'md',
10+
space: 'md',
11+
isAttached: true,
12+
direction: 'row',
1113
},
1214
argTypes: {
13-
size: {
15+
space: {
1416
control: 'select',
1517
options: ['xs', 'sm', 'md', 'lg'],
16-
description: 'The size of the button.',
18+
description: 'The space between the buttons.',
1719
table: {
1820
defaultValue: { summary: 'md' },
1921
},
2022
},
23+
isAttached: {
24+
control: 'boolean',
25+
options: [true, false],
26+
},
27+
direction: {
28+
control: 'select',
29+
options: ['row', 'column'],
30+
},
2131
},
2232
parameters: {
2333
docs: {

example/storybook/src/components/Forms/Button/ButtonGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const GroupedExample: MyButtonStory = ({
1313
return (
1414
<Wrapper>
1515
<Center>
16-
<Button.Group direction="column" {...props}>
16+
<Button.Group {...props}>
1717
<Button>
1818
<Button.Text>Button 1</Button.Text>
1919
</Button>

example/storybook/src/getting-started/Installation/index.stories.mdx

Lines changed: 51 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -6,195 +6,72 @@ description: To get started with gluestack-ui, check out this quick installation
66
pageTitle: Installation
77

88
pageDescription: To get started with gluestack-ui, check out this quick installation guide. It provides simple steps to help you install and use the library in your projects.
9-
10-
showHeader: true
119
---
1210

1311
import { Canvas, Meta, Story } from '@storybook/addon-docs';
1412

1513
<Meta title="Getting Started/Installation" />
1614

17-
## Installation
18-
19-
To get started with gluestack-ui, you can install it using `npx` to do initial setup and add any desired component package.
20-
21-
### Initialiser (Step 1)
22-
23-
To do the initial setup run:
24-
25-
```bash
26-
npx gluestack-ui
27-
28-
```
29-
30-
This will:
31-
32-
- Check if gluestack-ui is installed in the project, if not it will create a `gluestack.config.ts` file which will have the default theme.
33-
- It will create `GluestackUIProvider` (Wrapper component)
34-
- Installs the required dependencies
35-
- @dank-style/react
36-
- @gluestack-ui/provider
37-
38-
<br />
39-
40-
### Component Adder (Step 2)
41-
42-
We can add a new component using npx `npx gluestack-ui add <package-name>`. For example, to add the button component package, you can run the following command:
43-
44-
```bash
45-
npx gluestack-ui add button
46-
47-
```
48-
49-
This will install the `@gluestack-ui/button` package and add it to your project's dependencies. This will add the necessary code to your project, including importing the `createButton` function and creating a `Button` component using it.
50-
51-
After installing the component, you can use it in your app by importing it and rendering it in your JSX. For example:
52-
53-
```jsx
54-
import { Button } from './components/button';
55-
function App() {
56-
return (
57-
<>
58-
<Button onPress={() => alert('Clicked!')}>
59-
<Button.Text>Click me!</Button.Text>
60-
</Button>
61-
</>
62-
);
63-
}
64-
```
65-
66-
For components to work properly we need to wrap our components with `<GluestackUIProvider/>` and pass the theme from `gluestack-ui.config.ts` file.
67-
68-
#### Next.js Projects
69-
70-
For Next.js Projects update \_app.tsx with the below code:
71-
72-
```jsx
73-
import { GluestackUIProvider } from '@/components';
74-
import { config } from '@/gluestack-ui.config';
75-
import '@/styles/globals.css';
76-
import type { AppProps } from 'next/app';
77-
78-
export default function App({ Component, pageProps }: AppProps) {
79-
return (
80-
<GluestackUIProvider config={config.theme}>
81-
<Component {...pageProps} />
82-
</GluestackUIProvider>
83-
);
84-
}
85-
```
86-
87-
#### Expo Projects
88-
89-
For Expo Projects update App.tsx with the below code:
90-
91-
```jsx
92-
import { StatusBar } from 'expo-status-bar';
93-
import { StyleSheet, Text, View } from 'react-native';
94-
import { GluestackUIProvider } from './components';
95-
import { config } from './gluestack-ui.config';
96-
97-
export default function App() {
98-
return (
99-
<GluestackUIProvider config={config.theme}>
100-
<Button onPress={() => alert('Clicked!')}>
101-
<Button.Text>Click me!</Button.Text>
102-
</Button>
103-
</GluestackUIProvider>
104-
);
105-
}
106-
```
15+
import {
16+
AppProvider,
17+
Box,
18+
HStack,
19+
Text,
20+
Hoverable,
21+
} from '@gluestack/design-system';
22+
23+
# Installation
24+
25+
`gluestack-ui` is supported in [Expo](https://expo.dev/) and [Next.js](https://nextjs.org/) initiated apps. Web support is made possible by `react-native-web`.
26+
27+
Refer the guides shown below to setup `gluestack-ui` in your Expo or Next.js app.
28+
29+
<AppProvider>
30+
<HStack
31+
space="md"
32+
flex={1}
33+
mb="$4"
34+
sx={{
35+
'@lg': {
36+
flexDirection: 'row',
37+
},
38+
'flexDirection': 'column',
39+
}}
40+
>
41+
<Hoverable
42+
heading={'Expo CLI'}
43+
subHeading={'Guide to install with expo-cli'}
44+
href="/docs/getting-started/install-expo"
45+
/>
46+
<Hoverable
47+
heading={'Next.JS'}
48+
subHeading={'Guide to install with create-next-app'}
49+
href="/docs/getting-started/install-nextjs"
50+
/>
51+
</HStack>
52+
</AppProvider>
10753

10854
### Commands provided by gluestack-ui
10955

110-
#### Init gluestack-ui
111-
112-
```bash
113-
npx gluestack-ui init
114-
```
115-
116-
#### Init and add components
117-
118-
```bash
119-
npx gluestack-ui
120-
```
121-
122-
#### Add component
123-
124-
```bash
125-
npx gluestack-ui add <component-name>
126-
```
127-
128-
#### Update component
56+
Below is the list of commands provided by `gluestack-ui`.
12957

13058
```bash
131-
npx gluestack-ui update <component-name>
132-
```
133-
134-
#### Remove component
13559

136-
```bash
137-
npx gluestack-ui remove <component-name>
138-
```
60+
# init gluestack-ui
61+
npx gluestack-ui init
13962

140-
#### Help
141-
142-
```bash
143-
npx gluestack-ui help
144-
```
145-
146-
This will render a button component that can be clicked and will display an alert when clicked.
147-
148-
## For Next.js Projects
149-
150-
It's also recommended to set up your server-side rendering (SSR) correctly. To do this, you will need to use the flush() function exported by the library and call it in your \_document.js file. So, for Next.js projects we require `@gluestack/ui-next-adapter` as a dependency and update \_document.js with the below code:
151-
152-
```jsx
153-
import * as React from 'react';
154-
import { Html, Head, Main, NextScript } from 'next/document';
155-
import { AppRegistry } from 'react-native-web';
156-
import { flush } from '@dank-style/react';
157-
158-
function Document() {
159-
return (
160-
<Html lang="en">
161-
<Head />
162-
<body>
163-
<Main />
164-
<NextScript />
165-
</body>
166-
</Html>
167-
);
168-
}
169-
170-
Document.getInitialProps = async ({ renderPage }: any) => {
171-
AppRegistry.registerComponent('Main', () => Main);
172-
const { getStyleElement } = AppRegistry.getApplication('Main');
173-
const page = await renderPage();
174-
const styles = [getStyleElement(), ...flush()];
175-
return { ...page, styles: React.Children.toArray(styles) };
176-
};
177-
178-
export default Document;
179-
```
63+
# init and add components
64+
npx gluestack-ui
18065

181-
Make the following changes in `next.config.js`
66+
# add component
67+
npx gluestack-ui add <component-name>
18268

183-
```jsx
184-
/** @type {import('next').NextConfig} */
185-
// eslint-disable-next-line @typescript-eslint/no-var-requires
186-
const { withGluestackUI } = require('@gluestack/ui-next-adapter');
69+
# update component
70+
npx gluestack-ui update <component-name>
18771

188-
const nextConfig = {
189-
reactStrictMode: true,
190-
};
72+
# remove component
73+
npx gluestack-ui remove <component-name>
19174

192-
module.exports = withGluestackUI(nextConfig);
75+
# help
76+
npx gluestack-ui help
19377
```
194-
195-
### Summary
196-
197-
In this guide, we've walked you through the process of installing gluestack-ui and adding a Button component to your project using the npx command. With gluestack-ui, you can benefit from a library of accessible and composable UI components that work seamlessly on mobile and web platforms.
198-
199-
The library follows WAI-ARIA authoring practices guidelines, making it accessible to a wide range of users.
200-
It provides both controlled and uncontrolled options for maximum flexibility. The focus is fully managed and customizable, and the dismissing and layering behaviour can be highly customized as well. With gluestack-ui, you can create high-quality UI components with ease.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Installation in Expo project | gluestack-ui
3+
4+
description: To get started with gluestack-ui, check out this quick installation guide. It provides simple steps to help you install and use the library in your projects..
5+
6+
pageTitle: Installation
7+
8+
pageDescription: To get started with gluestack-ui, check out this quick installation guide. It provides simple steps to help you install and use the library in your projects.
9+
---
10+
11+
import { Canvas, Meta, Story } from '@storybook/addon-docs';
12+
13+
import { AppProvider, Link, Box, HStack, Text } from '@gluestack/design-system';
14+
15+
<Meta title="Getting Started/Install in Expo" />
16+
17+
# Install in Expo project
18+
19+
You can create a new Expo project using [Expo CLI](https://docs.expo.dev/get-started/create-a-new-app/). `gluestack-ui` provides a CLI to help you get started with the library. It includes initial installation setup and adding components to your project.
20+
21+
To get started with `gluestack-ui`, you can install it using `npx` to do initial setup and add any desired component package.
22+
23+
### Step 1: Initialiser
24+
25+
To do the initial setup run:
26+
27+
```bash
28+
npx gluestack-ui@latest init
29+
```
30+
31+
This will:
32+
33+
- Check if gluestack-ui is installed in the project, if not it will create a `gluestack.config.ts` file at the root of project which will have the default theme.
34+
- It will create `GluestackUIProvider` (Wrapper component)
35+
- It will add `styled` function created using [FontResolver](https://dank.style/docs/plugins/fonts-plugin) and [AnimationResolver](https://dank.style/docs/plugins/animation-plugin) plugins.
36+
- Installs the required dependencies
37+
- `@dank-style/react`
38+
- `@dank-style/animation-plugin`
39+
- `@gluestack-ui/provider`
40+
41+
<br />
42+
43+
### Step 2: Setup provider
44+
45+
`GluestackUIProvider` is a component that makes the aliases and tokens available throughout your app. It uses React's Context API. Add `GluestackUIProvider` to the root of your app and update `App.tsx` as follows:
46+
47+
```jsx
48+
import { Text } from 'react-native';
49+
import { GluestackUIProvider } from './components';
50+
import { config } from './gluestack-ui.config';
51+
52+
export default function App({ Component, pageProps }: AppProps) {
53+
return (
54+
<GluestackUIProvider config={config.theme}>
55+
<Text>Hello World!</Text>
56+
</GluestackUIProvider>
57+
);
58+
}
59+
```
60+
61+
For components to work properly we need to wrap our components with `<GluestackUIProvider />` and pass the theme from `gluestack-ui.config.ts` file.
62+
63+
### Step 3: Component Adder
64+
65+
We can add a new component using npx `npx gluestack-ui add <package-name>`. For example, to add the button component package, you can run the following command:
66+
67+
```bash
68+
npx gluestack-ui add button
69+
```
70+
71+
This will install the `@gluestack-ui/button` package and add it to your project's dependencies. This will add the necessary code to your project, including importing the `createButton` function and creating a `Button` component using it.
72+
73+
### Run the Hello World example:
74+
75+
After installing the component, you can use it in your app by importing it and rendering it in your JSX. For example:
76+
77+
```jsx
78+
import { GluestackUIProvider, Button } from './components';
79+
import { config } from './gluestack-ui.config';
80+
81+
function App() {
82+
return (
83+
<GluestackUIProvider config={config.theme}>
84+
<Button onPress={() => alert('Clicked!')}>
85+
<Button.Text>Click me!</Button.Text>
86+
</Button>
87+
</GluestackUIProvider>
88+
);
89+
}
90+
```
91+
92+
Yey! you are all set, start editing App.tsx now.

0 commit comments

Comments
 (0)