Skip to content

Commit

Permalink
Transform docs
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Apr 11, 2024
1 parent c9ee2f5 commit 961b80c
Show file tree
Hide file tree
Showing 62 changed files with 239 additions and 279 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/system';
import { Checkbox as BaseCheckbox } from '@base_ui/react/Checkbox';
import * as BaseCheckbox from '@base_ui/react/Checkbox';
import HorizontalRule from '@mui/icons-material/HorizontalRule';

export default function UnstyledCheckboxIndeterminate() {
Expand Down Expand Up @@ -30,7 +30,7 @@ const grey = {
100: '#E5EAF2',
};

const Checkbox = styled(BaseCheckbox)(
const Checkbox = styled(BaseCheckbox.Root)(
({ theme }) => `
width: 24px;
height: 24px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/system';
import { Checkbox as BaseCheckbox } from '@base_ui/react/Checkbox';
import * as BaseCheckbox from '@base_ui/react/Checkbox';
import HorizontalRule from '@mui/icons-material/HorizontalRule';

export default function UnstyledCheckboxIndeterminate() {
Expand Down Expand Up @@ -30,7 +30,7 @@ const grey = {
100: '#E5EAF2',
};

const Checkbox = styled(BaseCheckbox)(
const Checkbox = styled(BaseCheckbox.Root)(
({ theme }) => `
width: 24px;
height: 24px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/system';
import { Checkbox as BaseCheckbox } from '@base_ui/react/Checkbox';
import * as BaseCheckbox from '@base_ui/react/Checkbox';
import HorizontalRule from '@mui/icons-material/HorizontalRule';
import Check from '@mui/icons-material/Check';

Expand Down Expand Up @@ -76,7 +76,7 @@ const grey = {
800: '#303740',
};

const Checkbox = styled(BaseCheckbox)(
const Checkbox = styled(BaseCheckbox.Root)(
({ theme }) => `
width: 24px;
height: 24px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/system';
import { Checkbox as BaseCheckbox } from '@base_ui/react/Checkbox';
import * as BaseCheckbox from '@base_ui/react/Checkbox';
import HorizontalRule from '@mui/icons-material/HorizontalRule';
import Check from '@mui/icons-material/Check';

Expand Down Expand Up @@ -76,7 +76,7 @@ const grey = {
800: '#303740',
};

const Checkbox = styled(BaseCheckbox)(
const Checkbox = styled(BaseCheckbox.Root)(
({ theme }) => `
width: 24px;
height: 24px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import * as React from 'react';
import { Checkbox } from '@base_ui/react/Checkbox';
import * as Checkbox from '@base_ui/react/Checkbox';
import { useTheme } from '@mui/system';
import Check from '@mui/icons-material/Check';

export default function UnstyledCheckboxIntroduction() {
return (
<div style={{ display: 'flex', gap: 12 }}>
<Checkbox
<Checkbox.Root
className="Checkbox"
aria-label="Basic checkbox, on by default"
defaultChecked
>
<Checkbox.Indicator className="Checkbox-indicator">
<Check className="Checkbox-icon" />
</Checkbox.Indicator>
</Checkbox>
<Checkbox className="Checkbox" aria-label="Basic checkbox, off by default">
</Checkbox.Root>
<Checkbox.Root
className="Checkbox"
aria-label="Basic checkbox, off by default"
>
<Checkbox.Indicator className="Checkbox-indicator">
<Check className="Checkbox-icon" />
</Checkbox.Indicator>
</Checkbox>
<Checkbox
</Checkbox.Root>
<Checkbox.Root
className="Checkbox"
aria-label="Disabled checkbox, on by default"
defaultChecked
Expand All @@ -29,16 +32,16 @@ export default function UnstyledCheckboxIntroduction() {
<Checkbox.Indicator className="Checkbox-indicator">
<Check className="Checkbox-icon" />
</Checkbox.Indicator>
</Checkbox>
<Checkbox
</Checkbox.Root>
<Checkbox.Root
className="Checkbox"
aria-label="Disabled checkbox, off by default"
disabled
>
<Checkbox.Indicator className="Checkbox-indicator">
<Check className="Checkbox-icon" />
</Checkbox.Indicator>
</Checkbox>
</Checkbox.Root>
<Styles />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import * as React from 'react';
import { Checkbox } from '@base_ui/react/Checkbox';
import * as Checkbox from '@base_ui/react/Checkbox';
import { useTheme } from '@mui/system';
import Check from '@mui/icons-material/Check';

export default function UnstyledCheckboxIntroduction() {
return (
<div style={{ display: 'flex', gap: 12 }}>
<Checkbox
<Checkbox.Root
className="Checkbox"
aria-label="Basic checkbox, on by default"
defaultChecked
>
<Checkbox.Indicator className="Checkbox-indicator">
<Check className="Checkbox-icon" />
</Checkbox.Indicator>
</Checkbox>
<Checkbox className="Checkbox" aria-label="Basic checkbox, off by default">
</Checkbox.Root>
<Checkbox.Root
className="Checkbox"
aria-label="Basic checkbox, off by default"
>
<Checkbox.Indicator className="Checkbox-indicator">
<Check className="Checkbox-icon" />
</Checkbox.Indicator>
</Checkbox>
<Checkbox
</Checkbox.Root>
<Checkbox.Root
className="Checkbox"
aria-label="Disabled checkbox, on by default"
defaultChecked
Expand All @@ -29,16 +32,16 @@ export default function UnstyledCheckboxIntroduction() {
<Checkbox.Indicator className="Checkbox-indicator">
<Check className="Checkbox-icon" />
</Checkbox.Indicator>
</Checkbox>
<Checkbox
</Checkbox.Root>
<Checkbox.Root
className="Checkbox"
aria-label="Disabled checkbox, off by default"
disabled
>
<Checkbox.Indicator className="Checkbox-indicator">
<Check className="Checkbox-icon" />
</Checkbox.Indicator>
</Checkbox>
</Checkbox.Root>
<Styles />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/system';
import { Checkbox as BaseCheckbox } from '@base_ui/react/Checkbox';
import * as BaseCheckbox from '@base_ui/react/Checkbox';
import Check from '@mui/icons-material/Check';

export default function UnstyledSwitchIntroduction() {
Expand Down Expand Up @@ -44,7 +44,7 @@ const blue = {
800: '#004C99',
};

const Checkbox = styled(BaseCheckbox)(
const Checkbox = styled(BaseCheckbox.Root)(
({ theme }) => `
width: 24px;
height: 24px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/system';
import { Checkbox as BaseCheckbox } from '@base_ui/react/Checkbox';
import * as BaseCheckbox from '@base_ui/react/Checkbox';
import Check from '@mui/icons-material/Check';

export default function UnstyledSwitchIntroduction() {
Expand Down Expand Up @@ -44,7 +44,7 @@ const blue = {
800: '#004C99',
};

const Checkbox = styled(BaseCheckbox)(
const Checkbox = styled(BaseCheckbox.Root)(
({ theme }) => `
width: 24px;
height: 24px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { Checkbox as BaseCheckbox } from '@base_ui/react/Checkbox';
import * as BaseCheckbox from '@base_ui/react/Checkbox';

import { useTheme } from '@mui/system';
import Check from '@mui/icons-material/Check';

Expand Down Expand Up @@ -41,7 +42,7 @@ export default function UnstyledCheckboxIntroduction() {

const Checkbox = React.forwardRef(function Checkbox(props, ref) {
return (
<BaseCheckbox
<BaseCheckbox.Root
{...props}
ref={ref}
className={(state) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import {
Checkbox as BaseCheckbox,
type CheckboxIndicatorProps,
type CheckboxProps,
import * as BaseCheckbox from '@base_ui/react/Checkbox';
import type {
CheckboxIndicatorProps,
CheckboxRootProps,
} from '@base_ui/react/Checkbox';
import { useTheme } from '@mui/system';
import Check from '@mui/icons-material/Check';
Expand Down Expand Up @@ -42,10 +42,10 @@ export default function UnstyledCheckboxIntroduction() {
);
}

const Checkbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(
const Checkbox = React.forwardRef<HTMLButtonElement, CheckboxRootProps>(
function Checkbox(props, ref) {
return (
<BaseCheckbox
<BaseCheckbox.Root
{...props}
ref={ref}
className={(state) =>
Expand Down
24 changes: 12 additions & 12 deletions docs/data/base/components/checkbox/checkbox.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
productId: base-ui
title: React Checkbox component and hook
components: Checkbox, CheckboxIndicator
components: CheckboxRoot, CheckboxIndicator
hooks: useCheckbox
githubLabel: 'component: checkbox'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/
Expand All @@ -24,47 +24,47 @@ The Checkbox component provides users with a checkbox for toggling a checked sta
## Component

```jsx
import { Checkbox } from '@base_ui/react/Checkbox';
import * as Checkbox from '@base_ui/react/Checkbox';
```

### Anatomy

The `Checkbox` component is composed of a root component and an indicator child component:

```tsx
<Checkbox>
<Checkbox.Root>
<Checkbox.Indicator />
</Checkbox>
</Checkbox.Root>
```

The indicator can contain children, such as an icon:

```tsx
<Checkbox>
<Checkbox.Root>
<Checkbox.Indicator>
<MyCheckIcon />
</Checkbox.Indicator>
</Checkbox>
</Checkbox.Root>
```

The indicator conditionally unmounts its children when the checkbox is unchecked. For CSS animations, you can use the `keepMounted` prop to transition `visibility` and `opacity` for example:

```tsx
<Checkbox>
<Checkbox.Root>
<Checkbox.Indicator keepMounted>
<MyCheckIcon />
</Checkbox.Indicator>
</Checkbox>
</Checkbox.Root>
```

### Custom structure

Use the `render` prop to override the rendered checkbox or indicator element with your own components:

```jsx
<Checkbox render={(props) => <MyCheckbox {...props} />}>
<Checkbox.Root render={(props) => <MyCheckbox {...props} />}>
<Checkbox.Indicator render={(props) => <MyCheckboxIndicator {...props} />} />
</Checkbox>
</Checkbox.Root>
```

To ensure behavior works as expected:
Expand Down Expand Up @@ -113,9 +113,9 @@ You may not need to use hooks unless you find that you're limited by the customi
Ensure the checkbox has an accessible name via a `label` element.

```jsx
<Checkbox id="my-checkbox">
<Checkbox.Root id="my-checkbox">
<Checkbox.Indicator />
</Checkbox>
</Checkbox.Root>
<label htmlFor="my-checkbox">
My label
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { NumberField as BaseNumberField } from '@base_ui/react/NumberField';
import * as BaseNumberField from '@base_ui/react/NumberField';
import { styled, css } from '@mui/system';

export default function UnstyledNumberFieldFormat() {
Expand Down Expand Up @@ -49,7 +49,7 @@ const NumberLabel = styled('label')`
font-weight: bold;
`;

const NumberField = styled(BaseNumberField)`
const NumberField = styled(BaseNumberField.Root)`
font-family: 'IBM Plex Sans', sans-serif;
font-size: 1rem;
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { NumberField as BaseNumberField } from '@base_ui/react/NumberField';
import * as BaseNumberField from '@base_ui/react/NumberField';
import { styled, css } from '@mui/system';

export default function UnstyledNumberFieldFormat() {
Expand Down Expand Up @@ -49,7 +49,7 @@ const NumberLabel = styled('label')`
font-weight: bold;
`;

const NumberField = styled(BaseNumberField)`
const NumberField = styled(BaseNumberField.Root)`
font-family: 'IBM Plex Sans', sans-serif;
font-size: 1rem;
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { NumberField } from '@base_ui/react/NumberField';
import * as NumberField from '@base_ui/react/NumberField';
import { useTheme } from '@mui/system';

function useIsDarkMode() {
Expand All @@ -14,7 +14,7 @@ export default function UnstyledNumberFieldIntroduction() {

return (
<div className={isDarkMode ? 'dark' : ''}>
<NumberField
<NumberField.Root
id={id}
className="NumberField"
aria-label="Basic number field, default value"
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function UnstyledNumberFieldIntroduction() {
+
</NumberField.Increment>
</NumberField.Group>
</NumberField>
</NumberField.Root>
<Styles />
</div>
);
Expand Down
Loading

0 comments on commit 961b80c

Please sign in to comment.