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(checkbox): standalone page for checkbox documentation #1130

Closed
wants to merge 5 commits into from
Closed
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
82 changes: 82 additions & 0 deletions content/docs/forms/checkbox.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: React Checkbox - Flowbite
description: Get started with the checkbox component to allow the user to select one or more options in the form of a square box available in multiple sizes and colors
---

The `<Checkbox>` component can be used to receive one or more selected options from the user in the form of a square box available in multiple styles, sizes, colors, and variants coded with the utility classes from Tailwind CSS and with support for dark mode.

To start using the component make sure that you have imported it from Flowbite React:

```jsx
import { Checkbox } from 'flowbite-react';
```

## Checkbox example

Use this default example of a `<Checkbox>` element in a checked and unchecked state.

<Example name="checkbox.root" />

## Disabled state

This example can be used for the disabled state of the checkbox component by applying the disabled attribute to the input element.

<Example name="checkbox.disabled" />

## Checkbox link

Use this example if you want to add an anchor link inside the label of the `<Checkbox>` component.

<Example name="checkbox.link" />

## Helper text

Get started with this example if you want to add a secondary helper text for the `<Checkbox>` component.

<Example name="checkbox.helper" />

## Bordered

Use this example of a `<Checkbox>` inside a card element to enable a larger area of clicking activation.

<Example name="checkbox.bordered" />

## Checkbox list group

Use this example to show a list of `<Checkbox>` items grouped inside a card.

<Example name="checkbox.listGroup" />

## Horizontal list group

Use this example to show a list of `<Checkbox>` items inside a card horizontally.

<Example name="checkbox.horizontalListGroup" />

## Inline layout

You can align the checkbox elements horizontally by using a wrapper tag and applying the flex class.

<Example name="checkbox.inlineLayout" />

## Colors

Use the `text-{color}-{shade}` classes from Tailwind CSS to change the color of the `<Checkbox>` component.

<Example name="checkbox.colors" />

## Advanced layout

Use this example of an advanced layout of checkbox elements where the label parent element can be styled when the checkbox is checked.

<Example name="checkbox.advancedLayout" />

## Theme

To learn more about how to customize the appearance of components, please see the [Theme docs](/docs/customize/theme).

<Theme name="checkbox" />

## References

- [Flowbite Checkbox](https://flowbite.com/docs/components/checkbox/)
14 changes: 7 additions & 7 deletions data/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ export const COMPONENTS_DATA: Component[] = [
// link: `/docs/forms/textarea`,
// classes: 'w-56'
// },
// {
// name: 'Checkbox',
// image: '/images/components/checkbox.svg',
// imageDark: '/images/components/checkbox.svg',
// link: `/docs/forms/checkbox`,
// classes: 'w-40'
// },
{
name: 'Checkbox',
image: '/images/components/checkbox.svg',
imageDark: '/images/components/checkbox-dark.svg',
link: `/docs/forms/checkbox`,
classes: 'w-40',
},
// {
// name: 'Radio',
// image: '/images/components/radio.svg',
Expand Down
1 change: 1 addition & 0 deletions data/docs-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const DOCS_SIDEBAR: DocsSidebarSection[] = [
title: 'forms',
href: '/forms/',
items: [
{ title: 'Checkbox', href: '/docs/forms/checkbox' },
{ title: 'File Input', href: '/docs/forms/file-input' },
{ title: 'Floating Label', href: '/docs/forms/floating-label', isNew: true },
],
Expand Down
249 changes: 249 additions & 0 deletions examples/checkbox/checkbox.advancedLayout.tsx

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions examples/checkbox/checkbox.bordered.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { type CodeData } from '~/components/code-demo';
import { Checkbox, Label } from '~/src';

const code = `
'use client';

import { Checkbox, Label } from 'flowbite-react';

function Component() {
return (
<div className="flex items-center gap-6">
<div className="flex flex-1 items-center rounded border border-gray-200 pl-4 dark:border-gray-700">
<Checkbox id="default-radio" defaultChecked />
<Label htmlFor="default-radio" className="w-100 ml-2 flex py-4">
Default radio
</Label>
</div>
<div className="flex flex-1 items-center rounded border border-gray-200 pl-4 dark:border-gray-700">
<Checkbox id="checked-state" />
<Label htmlFor="checked-state" className="w-100 ml-2 flex py-4">
Checked state
</Label>
</div>
</div>
);
}
`;

const codeRSC = `
import { Checkbox, Label } from 'flowbite-react';

function Component() {
return (
<div className="flex items-center gap-6">
<div className="flex flex-1 items-center rounded border border-gray-200 pl-4 dark:border-gray-700">
<Checkbox id="default-radio" defaultChecked />
<Label htmlFor="default-radio" className="w-100 ml-2 flex py-4">
Default radio
</Label>
</div>
<div className="flex flex-1 items-center rounded border border-gray-200 pl-4 dark:border-gray-700">
<Checkbox id="checked-state" />
<Label htmlFor="checked-state" className="w-100 ml-2 flex py-4">
Checked state
</Label>
</div>
</div>
);
}
`;

function Component() {
return (
<div className="flex items-center gap-6">
<div className="flex flex-1 items-center rounded border border-gray-200 pl-4 dark:border-gray-700">
<Checkbox id="default-radio" defaultChecked />
<Label htmlFor="default-radio" className="w-100 ml-2 flex py-4">
Default radio
</Label>
</div>
<div className="flex flex-1 items-center rounded border border-gray-200 pl-4 dark:border-gray-700">
<Checkbox id="checked-state" />
<Label htmlFor="checked-state" className="w-100 ml-2 flex py-4">
Checked state
</Label>
</div>
</div>
);
}

export const bordered: CodeData = {
type: 'single',
code: [
{
fileName: 'client',
language: 'tsx',
code,
},
{
fileName: 'server',
language: 'tsx',
code: codeRSC,
},
],
githubSlug: 'checkbox/checkbox.bordered.tsx',
component: <Component />,
};
111 changes: 111 additions & 0 deletions examples/checkbox/checkbox.colors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { type CodeData } from '~/components/code-demo';
import { Checkbox, Label } from '~/src';

const code = `
'use client';

import { Checkbox, Label } from 'flowbite-react';

function Component() {
return (
<div className="flex items-center gap-2">
<div className="flex items-center gap-2">
<Checkbox id="red-checkbox" color="red" defaultChecked />
<Label htmlFor="red-checkbox">Red</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="green-checkbox" color="green" defaultChecked />
<Label htmlFor="green-checkbo">Green</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="purple-checkbox" color="purple" defaultChecked />
<Label htmlFor="purple-checkbo">Purple</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="teal-checkbox" color="teal" defaultChecked />
<Label htmlFor="teal-checkbo">Teal</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="yellow-checkbox" color="yellow" defaultChecked />
<Label htmlFor="yellow-checkbo">Yellow</Label>
</div>
</div>
);
}
`;

const codeRSC = `
import { Checkbox, Label } from 'flowbite-react';

function Component() {
return (
<div className="flex items-center gap-2">
<div className="flex items-center gap-2">
<Checkbox id="red-checkbox" color="red" defaultChecked />
<Label htmlFor="red-checkbox">Red</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="green-checkbox" color="green" defaultChecked />
<Label htmlFor="green-checkbo">Green</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="purple-checkbox" color="purple" defaultChecked />
<Label htmlFor="purple-checkbo">Purple</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="teal-checkbox" color="teal" defaultChecked />
<Label htmlFor="teal-checkbo">Teal</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="yellow-checkbox" color="yellow" defaultChecked />
<Label htmlFor="yellow-checkbo">Yellow</Label>
</div>
</div>
);
}
`;

function Component() {
return (
<div className="flex items-center gap-2">
<div className="flex items-center gap-2">
<Checkbox id="red-checkbox" color="red" defaultChecked />
<Label htmlFor="red-checkbox">Red</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="green-checkbox" color="green" defaultChecked />
<Label htmlFor="green-checkbo">Green</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="purple-checkbox" color="purple" defaultChecked />
<Label htmlFor="purple-checkbo">Purple</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="teal-checkbox" color="teal" defaultChecked />
<Label htmlFor="teal-checkbo">Teal</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="yellow-checkbox" color="yellow" defaultChecked />
<Label htmlFor="yellow-checkbo">Yellow</Label>
</div>
</div>
);
}

export const colors: CodeData = {
type: 'single',
code: [
{
fileName: 'client',
language: 'tsx',
code,
},
{
fileName: 'server',
language: 'tsx',
code: codeRSC,
},
],
githubSlug: 'checkbox/checkbox.colors.tsx',
component: <Component />,
};
79 changes: 79 additions & 0 deletions examples/checkbox/checkbox.disabled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { type CodeData } from '~/components/code-demo';
import { Checkbox, Label } from '~/src';

const code = `
'use client';

import { Checkbox, Label } from 'flowbite-react';

function Component() {
return (
<div>
<div className="mb-4 flex items-center gap-2">
<Checkbox id="disabled-checkbox" disabled />
<Label htmlFor="disabled-checkbox">Default checkbox</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="disabled-checked-state-checkbox" disabled checked />
<Label htmlFor="disabled-checked-state-checkbox" disabled>Disabled</Label>
</div>
</div>
);
}
`;

const codeRSC = `
import { Checkbox, Label } from 'flowbite-react';

function Component() {
return (
<div>
<div className="mb-4 flex items-center gap-2">
<Checkbox id="disabled-checkbox" disabled />
<Label htmlFor="disabled-checkbox">Default checkbox</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="disabled-checked-state-checkbox" disabled checked />
<Label htmlFor="disabled-checked-state-checkbox" disabled>Disabled</Label>
</div>
</div>
);
}
`;

function Component() {
return (
<div>
<div className="mb-4 flex items-center gap-2">
<Checkbox id="disabled-checkbox" disabled />
<Label htmlFor="disabled-checkbox" disabled>
Default checkbox
</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="disabled-checked-state-checkbox" disabled checked />
<Label htmlFor="disabled-checked-state-checkbox" disabled>
Disabled checked
</Label>
</div>
</div>
);
}

export const disabled: CodeData = {
type: 'single',
code: [
{
fileName: 'client',
language: 'tsx',
code,
},
{
fileName: 'server',
language: 'tsx',
code: codeRSC,
},
],
githubSlug: 'checkbox/checkbox.disabled.tsx',
component: <Component />,
};
Loading