Skip to content

Commit

Permalink
[docs] Content 2: Collapsible, demo fixes (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmoroz authored Nov 29, 2024
1 parent 5afdcd7 commit a2421c1
Show file tree
Hide file tree
Showing 28 changed files with 325 additions and 105 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ module.exports = {
// This prevents us from creating components like `<h1 {...props} />`
'jsx-a11y/heading-has-content': 'off',
'jsx-a11y/anchor-has-content': 'off',

// This rule doesn't recognise <label> wrapped around custom controls
'jsx-a11y/label-has-associated-control': 'off',
},
overrides: [
...baseline.overrides.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function useIsDarkMode() {

function Label(props) {
return (
// eslint-disable-next-line jsx-a11y/label-has-associated-control, jsx-a11y/no-noninteractive-element-interactions
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<label
className="mb-2 flex gap-2"
onMouseDown={(event) => event.preventDefault()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function useIsDarkMode() {

function Label(props: React.ComponentPropsWithoutRef<'label'>) {
return (
// eslint-disable-next-line jsx-a11y/label-has-associated-control, jsx-a11y/no-noninteractive-element-interactions
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<label
className="mb-2 flex gap-2"
onMouseDown={(event) => event.preventDefault()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function ExampleAccordion() {
<Accordion.Root className="flex min-h-48 w-96 max-w-[calc(100vw-8rem)] flex-col justify-center">
<Accordion.Item className="border-b border-gray-200">
<Accordion.Header>
<Accordion.Trigger className="group flex w-full cursor-pointer items-baseline justify-between py-2 font-medium focus-visible:outline-2 focus-visible:outline-blue">
<Accordion.Trigger className="group flex w-full cursor-pointer items-baseline justify-between py-2 font-medium focus-visible:outline-2 focus-visible:outline-blue-800">
What is Base UI?
<PlusIcon className="mr-2 size-3 transition-all ease-out group-data-[panel-open]:scale-110 group-data-[panel-open]:rotate-45" />
</Accordion.Trigger>
Expand All @@ -21,7 +21,7 @@ export default function ExampleAccordion() {

<Accordion.Item className="border-b border-gray-200">
<Accordion.Header>
<Accordion.Trigger className="group flex w-full cursor-pointer items-baseline justify-between py-2 font-medium focus-visible:outline-2 focus-visible:outline-blue">
<Accordion.Trigger className="group flex w-full cursor-pointer items-baseline justify-between py-2 font-medium focus-visible:outline-2 focus-visible:outline-blue-800">
How do I get started?
<PlusIcon className="mr-2 size-3 transition-all ease-out group-data-[panel-open]:scale-110 group-data-[panel-open]:rotate-45" />
</Accordion.Trigger>
Expand All @@ -36,7 +36,7 @@ export default function ExampleAccordion() {

<Accordion.Item className="border-b border-gray-200">
<Accordion.Header>
<Accordion.Trigger className="group flex w-full cursor-pointer items-baseline justify-between py-2 font-medium focus-visible:outline-2 focus-visible:outline-blue">
<Accordion.Trigger className="group flex w-full cursor-pointer items-baseline justify-between py-2 font-medium focus-visible:outline-2 focus-visible:outline-blue-800">
Can I use it for my next project?
<PlusIcon className="mr-2 size-3 transition-all ease-out group-data-[panel-open]:scale-110 group-data-[panel-open]:rotate-45" />
</Accordion.Trigger>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AlertDialog } from '@base-ui-components/react/alert-dialog';
export default function ExampleAlertDialog() {
return (
<AlertDialog.Root>
<AlertDialog.Trigger className="flex rounded-md bg-gray-50 px-3.5 py-2 font-medium text-red outline-1 outline-gray-200 select-none hover:bg-gray-100 focus-visible:outline-2 focus-visible:outline-blue active:bg-gray-100">
<AlertDialog.Trigger className="flex rounded-md bg-gray-50 px-3.5 py-2 font-medium text-red-800 outline-1 outline-gray-200 select-none hover:bg-gray-100 focus-visible:outline-2 focus-visible:outline-blue-800 active:bg-gray-100">
Discard draft
</AlertDialog.Trigger>
<AlertDialog.Backdrop className="fixed inset-0 bg-black opacity-20 transition-all duration-150 dark:opacity-70 [[data-starting-style],[data-ending-style]]:opacity-0" />
Expand All @@ -16,10 +16,10 @@ export default function ExampleAlertDialog() {
You can’t undo this action.
</AlertDialog.Description>
<div className="flex justify-end gap-4">
<AlertDialog.Close className="flex rounded-md bg-gray-50 px-3.5 py-2 font-medium text-gray-900 outline-1 outline-gray-200 select-none hover:bg-gray-100 focus-visible:outline-2 focus-visible:outline-blue active:bg-gray-100">
<AlertDialog.Close className="flex rounded-md bg-gray-50 px-3.5 py-2 font-medium text-gray-900 outline-1 outline-gray-200 select-none hover:bg-gray-100 focus-visible:outline-2 focus-visible:outline-blue-800 active:bg-gray-100">
Cancel
</AlertDialog.Close>
<AlertDialog.Close className="flex rounded-md bg-gray-50 px-3.5 py-2 font-medium text-red outline-1 outline-gray-200 select-none hover:bg-gray-100 focus-visible:outline-2 focus-visible:outline-blue active:bg-gray-100">
<AlertDialog.Close className="flex rounded-md bg-gray-50 px-3.5 py-2 font-medium text-red-800 outline-1 outline-gray-200 select-none hover:bg-gray-100 focus-visible:outline-2 focus-visible:outline-blue-800 active:bg-gray-100">
Discard
</AlertDialog.Close>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
gap: 0.25rem;
}

.Label {
.Caption {
font-weight: 500;
}

Expand Down Expand Up @@ -43,8 +43,7 @@
}

.Indicator {
width: 0.75rem;
height: 0.75rem;
display: flex;
color: var(--color-gray-50);

&[data-unchecked] {
Expand All @@ -53,6 +52,6 @@
}

.Icon {
width: 100%;
height: 100%;
width: 0.75rem;
height: 0.75rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,40 @@ import styles from './index.module.css';
export default function ExampleCheckboxGroup() {
return (
<CheckboxGroup.Root
aria-labelledby="apples"
aria-labelledby="apples-caption"
defaultValue={['fuji-apple']}
className={styles.Group}
>
<div className={styles.Label} id="apples">
<div className={styles.Caption} id="apples-caption">
Apples
</div>

<div className={styles.Item}>
<Checkbox.Root id="fuji-apple" name="fuji-apple" className={styles.Checkbox}>
<label className={styles.Item}>
<Checkbox.Root name="fuji-apple" className={styles.Checkbox}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon className={styles.Icon} />
</Checkbox.Indicator>
</Checkbox.Root>
<label htmlFor="fuji-apple">Fuji</label>
</div>
Fuji
</label>

<div className={styles.Item}>
<Checkbox.Root id="gala-apple" name="gala-apple" className={styles.Checkbox}>
<label className={styles.Item}>
<Checkbox.Root name="gala-apple" className={styles.Checkbox}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon className={styles.Icon} />
</Checkbox.Indicator>
</Checkbox.Root>
<label htmlFor="gala-apple">Gala</label>
</div>
Gala
</label>

<div className={styles.Item}>
<Checkbox.Root
id="granny-smith-apple"
name="granny-smith-apple"
className={styles.Checkbox}
>
<label className={styles.Item}>
<Checkbox.Root name="granny-smith-apple" className={styles.Checkbox}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon className={styles.Icon} />
</Checkbox.Indicator>
</Checkbox.Root>
<label htmlFor="granny-smith-apple">Granny Smith</label>
</div>
Granny Smith
</label>
</CheckboxGroup.Root>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,49 @@ import { CheckboxGroup } from '@base-ui-components/react/checkbox-group';
export default function ExampleCheckboxGroup() {
return (
<CheckboxGroup.Root
aria-labelledby="apples"
aria-labelledby="apples-caption"
defaultValue={['fuji-apple']}
className="flex flex-col gap-1"
>
<div className="font-medium" id="apples">
<div className="font-medium" id="apples-caption">
Apples
</div>

<div className="flex items-center gap-2">
<label className="flex items-center gap-2">
<Checkbox.Root
id="fuji-apple"
name="fuji-apple"
className="flex size-5 items-center justify-center rounded-sm outline-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue data-[checked]:bg-gray-900 data-[unchecked]:border data-[unchecked]:border-gray-300"
className="flex size-5 items-center justify-center rounded-sm outline-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-800 data-[checked]:bg-gray-900 data-[unchecked]:border data-[unchecked]:border-gray-300"
>
<Checkbox.Indicator className="size-3 text-gray-50 data-[unchecked]:hidden">
<CheckIcon className="h-full w-full" />
<Checkbox.Indicator className="flex text-gray-50 data-[unchecked]:hidden">
<CheckIcon className="size-3" />
</Checkbox.Indicator>
</Checkbox.Root>
<label htmlFor="fuji-apple">Fuji</label>
</div>
Fuji
</label>

<div className="flex items-center gap-2">
<label className="flex items-center gap-2">
<Checkbox.Root
id="gala-apple"
name="gala-apple"
className="flex size-5 items-center justify-center rounded-sm outline-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue data-[checked]:bg-gray-900 data-[unchecked]:border data-[unchecked]:border-gray-300"
className="flex size-5 items-center justify-center rounded-sm outline-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-800 data-[checked]:bg-gray-900 data-[unchecked]:border data-[unchecked]:border-gray-300"
>
<Checkbox.Indicator className="size-3 text-gray-50 data-[unchecked]:hidden">
<CheckIcon className="h-full w-full" />
<Checkbox.Indicator className="flex text-gray-50 data-[unchecked]:hidden">
<CheckIcon className="size-3" />
</Checkbox.Indicator>
</Checkbox.Root>
<label htmlFor="gala-apple">Gala</label>
</div>
Gala
</label>

<div className="flex items-center gap-2">
<label className="flex items-center gap-2">
<Checkbox.Root
id="granny-smith-apple"
name="granny-smith-apple"
className="flex size-5 items-center justify-center rounded-sm outline-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue data-[checked]:bg-gray-900 data-[unchecked]:border data-[unchecked]:border-gray-300"
className="flex size-5 items-center justify-center rounded-sm outline-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-800 data-[checked]:bg-gray-900 data-[unchecked]:border data-[unchecked]:border-gray-300"
>
<Checkbox.Indicator className="size-3 text-gray-50 data-[unchecked]:hidden">
<CheckIcon className="h-full w-full" />
<Checkbox.Indicator className="flex text-gray-50 data-[unchecked]:hidden">
<CheckIcon className="size-3" />
</Checkbox.Indicator>
</Checkbox.Root>
<label htmlFor="granny-smith-apple">Granny Smith</label>
</div>
Granny Smith
</label>
</CheckboxGroup.Root>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
}

.Indicator {
width: 0.75rem;
height: 0.75rem;
display: flex;
color: var(--color-gray-50);

&[data-unchecked] {
Expand All @@ -37,6 +36,6 @@
}

.Icon {
width: 100%;
height: 100%;
width: 0.75rem;
height: 0.75rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export default function ExampleCheckbox() {
return (
<Checkbox.Root
defaultChecked
className="flex size-5 items-center justify-center rounded-sm outline-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue data-[checked]:bg-gray-900 data-[unchecked]:border data-[unchecked]:border-gray-300"
className="flex size-5 items-center justify-center rounded-sm outline-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-800 data-[checked]:bg-gray-900 data-[unchecked]:border data-[unchecked]:border-gray-300"
>
<Checkbox.Indicator className="size-3 text-gray-50 data-[unchecked]:hidden">
<CheckIcon className="h-full w-full" />
<Checkbox.Indicator className="flex text-gray-50 data-[unchecked]:hidden">
<CheckIcon className="size-3" />
</Checkbox.Indicator>
</Checkbox.Root>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.Root {
display: flex;
width: 14rem;
min-height: 9rem;
flex-direction: column;
justify-content: center;
}

.Trigger {
display: flex;
align-items: center;
gap: 0.5rem;
margin: 0;
border: 0;
outline: 0;
padding: 0.25rem 0.5rem;
border-radius: 0.125rem;
background-color: var(--color-gray-100);
font: inherit;
font-size: 0.9375rem;
line-height: 1.375rem;
letter-spacing: 0.001em;
font-weight: 500;

@media (hover: hover) {
&:hover {
background-color: var(--color-gray-200);
}
}

&:active {
background-color: var(--color-gray-200);
}

&:focus-visible {
outline: 2px solid var(--color-blue);
}

&[data-panel-open] .Icon {
transform: rotate(90deg);
}
}

.Icon {
width: 0.75rem;
height: 0.75rem;
transition: transform 150ms ease-out;
}

.Panel {
display: flex;
height: var(--collapsible-panel-height);
flex-direction: column;
justify-content: flex-end;
overflow: hidden;
font-size: 0.9375rem;
line-height: 1.375rem;
letter-spacing: 0.001em;
transition: all 150ms ease-out;

&[data-starting-style],
&[data-ending-style] {
height: 0;
}
}

.Content {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-top: 0.25rem;
padding: 0.5rem 0 0.5rem 1.75rem;
border-radius: 0.125rem;
background-color: var(--color-gray-100);
cursor: text;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import { Collapsible } from '@base-ui-components/react/collapsible';
import styles from './index.module.css';

export default function ExampleCollapsible() {
return (
<Collapsible.Root className={styles.Root} render={<div />}>
<Collapsible.Trigger className={styles.Trigger}>
<ChevronIcon className={styles.Icon} />
Recovery keys
</Collapsible.Trigger>
<Collapsible.Panel className={styles.Panel}>
<div className={styles.Content}>
<div>alien-bean-pasta</div>
<div>wild-irish-burrito</div>
<div>horse-battery-staple</div>
</div>
</Collapsible.Panel>
</Collapsible.Root>
);
}

export function ChevronIcon(props: React.ComponentProps<'svg'>) {
return (
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" {...props}>
<path d="M3.5 9L7.5 5L3.5 1" stroke="currentcolor" />
</svg>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client';
export { default as CssModules } from './css-modules';
export { default as Tailwind } from './tailwind';
Loading

0 comments on commit a2421c1

Please sign in to comment.