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

docs: new integration guides #1194

Merged
merged 19 commits into from
Dec 19, 2023
Merged
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": false,
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,25 @@ Add Tailwind CSS to a CSS file:

### Install Flowbite React

1. Install Flowbite and Flowbite React:
1. Run the following command to install `flowbite-react`:

```bash
npm i flowbite flowbite-react # or yarn add flowbite flowbite-react
npm i flowbite-react
```

2. Add the Flowbite plugin to `tailwind.config.js`, and include content from `flowbite-react`:

```javascript
module.exports = {
```js
/** @type {import('tailwindcss').Config} */
export default {
content: [
...,
'node_modules/flowbite-react/**/*.{js,jsx,ts,tsx}'
// ...
'node_modules/flowbite-react/lib/esm/**/*.js',
],
plugins: [
// ...
require('flowbite/plugin'),
],
plugins: [..., require('flowbite/plugin')],
...
};
```

Expand All @@ -143,7 +146,7 @@ export default function MyPage() {

#### Next.js

If you're using Next.js, you can follow the [Next.js install guide](https://flowbite.com/docs/getting-started/next-js/), which includes a [Next.js starter project](https://github.com/tulupinc/flowbite-next-starter) with Flowbite React already set up.
If you're using Next.js, you can follow the [Next.js install guide](https://flowbite.com/docs/guides/next-js/), which includes a [Next.js starter project](https://github.com/tulupinc/flowbite-next-starter) with Flowbite React already set up.

#### Dark mode

Expand Down
13 changes: 13 additions & 0 deletions components/mdx.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import type { MDXComponents } from 'mdx/types';
import { getMDXComponent } from 'next-contentlayer/hooks';
import Link from 'next/link';
import * as examples from '~/examples';
import { theme } from '~/src';
import { CodeDemo, type CodeData } from './code-demo';
import { CodeHighlight } from './code-highlight';

const components: MDXComponents = {
a: ({ ref, href = '', ...props }) => {
const isLocal = href.startsWith('/');

return (
<Link
{...props}
href={href}
ref={ref as React.Ref<HTMLAnchorElement>}
{...(!isLocal && { target: '_blank', rel: 'noreferrer' })}
/>
);
},
// TODO: revisit
h2: (props) => (
<h2 className="group relative z-20 scroll-mt-20 text-2xl font-bold text-gray-900" {...props}>
Expand Down
19 changes: 11 additions & 8 deletions content/docs/getting-started/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@ Add Tailwind CSS to a CSS file:

### Install Flowbite React

1. Install Flowbite and Flowbite React:
1. Run the following command to install `flowbite-react`:

```bash
npm i flowbite flowbite-react # or yarn add flowbite flowbite-react
npm i flowbite-react
```

2. Add the Flowbite plugin to `tailwind.config.js`, and include content from `flowbite-react`:

```javascript
module.exports = {
```js
/** @type {import('tailwindcss').Config} */
export default {
content: [
...,
// ...
'node_modules/flowbite-react/lib/esm/**/*.js',
],
plugins: [..., require('flowbite/plugin')],
...
plugins: [
// ...
require('flowbite/plugin'),
],
};
```

Expand All @@ -83,7 +86,7 @@ export default function MyPage() {

#### Next.js

If you're using Next.js, you can follow the [Next.js install guide](/docs/getting-started/nextjs), which includes a [Next.js starter project](https://github.com/tulupinc/flowbite-next-starter) with Flowbite React already set up.
If you're using Next.js, you can follow the [Next.js install guide](/docs/guides/next-js), which includes a [Next.js starter project](https://github.com/tulupinc/flowbite-next-starter) with Flowbite React already set up.

#### Dark mode

Expand Down
60 changes: 0 additions & 60 deletions content/docs/getting-started/nextjs.mdx

This file was deleted.

21 changes: 12 additions & 9 deletions content/docs/getting-started/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,25 @@ Add Tailwind CSS to a CSS file:

## Install Flowbite React

1. Install Flowbite and Flowbite React:
1. Run the following command to install `flowbite-react`:

```bash
npm i flowbite-react # or yarn add flowbite flowbite-react
npm i flowbite-react
```

2. Add the Flowbite plugin to `tailwind.config.js`, and include content from `flowbite-react`:

```javascript
module.exports = {
```js
/** @type {import('tailwindcss').Config} */
export default {
content: [
...,
'node_modules/flowbite-react/**/*.{js,jsx,ts,tsx}'
// ...
'node_modules/flowbite-react/lib/esm/**/*.js',
],
plugins: [
// ...
require('flowbite/plugin'),
],
plugins: [..., require('flowbite/plugin')],
...
};
```

Expand All @@ -79,7 +82,7 @@ export default function MyPage() {

#### Next.js

If you're using Next.js, you can follow the [Next.js install guide](/docs/getting-started/nextjs), which includes a [Next.js starter project](https://github.com/tulupinc/flowbite-next-starter) with Flowbite React already set up.
If you're using Next.js, you can follow the [Next.js install guide](/docs/guides/next-js), which includes a [Next.js starter project](https://github.com/tulupinc/flowbite-next-starter) with Flowbite React already set up.

#### Dark mode

Expand Down
136 changes: 136 additions & 0 deletions content/docs/guides/astro.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: Use with Astro - Flowbite React
description: Learn how to install Flowbite React for your Astro project and start building modern websites with a lightning fast and content-focused web framework
---

## Create project

1. Run the following command to create a new Astro project:

```bash
npm create astro@latest
```

2. Install `react` using the Astro CLI:

```bash
npx astro add react
```

**Note:** Make sure to answer `Yes` to all the questions.

## Setup Tailwind CSS

1. Install `tailwindcss` using the Astro CLI:

```bash
npx astro add tailwind
```

**Note:** Make sure to answer `Yes` to all the questions.

## Install Flowbite React

1. Run the following command to install `flowbite-react`:

```bash
npm i flowbite-react
```

2. Add the Flowbite plugin to `tailwind.config.mjs` and include content from `flowbite-react`:

```js {5,9}
/** @type {import('tailwindcss').Config} */
export default {
content: [
// ...
'node_modules/flowbite-react/lib/esm/**/*.js',
],
plugins: [
// ...
require('flowbite/plugin'),
],
};
```

## Dark mode

In server side rendered applications, such as Astro, to avoid page flicker (if `dark` mode is set) before Astro hydrates the content, `ThemeModeScript` component must be rendered in `Head` component (see implementation below).

`ThemeModeScript` renders a script tag that sets `dark` or removes `dark` from `<html>` element before hydration occurs.

### Configure

1. Create a root layout file under `src/layouts` folder called `index.astro`:

```tsx
// src/layouts/index.astro

<html lang="en">
<head></head>
<body>
<slot />
</body>
</html>
```

2. Import and render `ThemeModeScript` in the `<head>` tag:

```tsx {4,9}
// src/layouts/index.astro

---
import { ThemeModeScript } from "flowbite-react";
---

<html lang="en">
<head>
<ThemeModeScript />
</head>
<body>
<slot />
</body>
</html>
```

3. Import the newly created layout and wrap the page content with it:

```tsx {4,7-9}
// src/pages/index.astro

---
import RootLayout from "../layouts/index.astro";
---

<RootLayout>
// ...
</RootLayout>

```

## Component hydration

By default, a UI Framework component is not hydrated in the client. If no `client:*` directive is provided, its HTML is rendered onto the page without JavaScript ([Astro - Client Directives](https://docs.astro.build/en/reference/directives-reference/#client-directives)).

To enable Flowbite React components to be interactive add `client:load`, `client:idle` or `client:visible` ([see docs](https://docs.astro.build/en/reference/directives-reference/#clientload)) as a prop.

```tsx
<DarkThemeToggle client:load />
```

## Try it out

Now that you have successfully installed Flowbite React you can start using the components from the library.

```tsx
// src/pages/index.astro

---
import { Button } from "flowbite-react";
import RootLayout from "../layouts/index.astro";
---

<RootLayout>
<Button>Click me</Button>
</RootLayout>
```
Loading