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

fix(components): replace Section with ListBoxSection and MenuSection #1498

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/giant-shirts-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@launchpad-ui/components": patch
---

Replace `Section` with `ListBoxSection` and `MenuSection`
15 changes: 12 additions & 3 deletions packages/components/__tests__/Menu.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { describe, expect, it } from 'vitest';

import { render, screen, userEvent } from '../../../test/utils';
import { Button, Header, Menu, MenuItem, MenuTrigger, Popover, Section, Separator } from '../src';
import {
Button,
Header,
Menu,
MenuItem,
MenuSection,
MenuTrigger,
Popover,
Separator,
} from '../src';

describe('Menu', () => {
it('renders', async () => {
Expand All @@ -13,11 +22,11 @@ describe('Menu', () => {
<Menu>
<MenuItem>Item one</MenuItem>
<Separator />
<Section>
<MenuSection>
<Header>Section</Header>
<MenuItem>Item two</MenuItem>
<MenuItem>Item three</MenuItem>
</Section>
</MenuSection>
</Menu>
</Popover>
</MenuTrigger>,
Expand Down
34 changes: 26 additions & 8 deletions packages/components/src/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
import type { forwardRefType } from '@react-types/shared';
import type { ForwardedRef } from 'react';
import type { SectionProps } from 'react-aria-components';
import type { ListBoxSectionProps, MenuSectionProps } from 'react-aria-components';

import { cva } from 'class-variance-authority';
import { forwardRef } from 'react';
import { Section as AriaSection } from 'react-aria-components';
import {
ListBoxSection as AriaListBoxSection,
MenuSection as AriaMenuSection,
} from 'react-aria-components';

import styles from './styles/Section.module.css';

const section = cva(styles.section);

const _Section = <T extends object>(
{ className, ...props }: SectionProps<T>,
const _ListBoxSection = <T extends object>(
{ className, ...props }: ListBoxSectionProps<T>,
ref: ForwardedRef<HTMLElement>,
) => {
return <AriaSection {...props} ref={ref} className={section({ className })} />;
return <AriaListBoxSection {...props} ref={ref} className={section({ className })} />;
};

const Section = (forwardRef as forwardRefType)(_Section);
/**
* A ListBoxSection represents a section within a ListBox.
*/
const ListBoxSection = (forwardRef as forwardRefType)(_ListBoxSection);

export { Section };
export type { SectionProps };
const _MenuSection = <T extends object>(
{ className, ...props }: MenuSectionProps<T>,
ref: ForwardedRef<HTMLElement>,
) => {
return <AriaMenuSection {...props} ref={ref} className={section({ className })} />;
};

/**
* A MenuSection represents a section within a Menu.
*/
const MenuSection = (forwardRef as forwardRefType)(_MenuSection);

export { ListBoxSection, MenuSection };
export type { ListBoxSectionProps, MenuSectionProps };
4 changes: 2 additions & 2 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type { RadioButtonProps } from './RadioButton';
export type { RadioGroupProps } from './RadioGroup';
export type { RadioIconButtonProps } from './RadioIconButton';
export type { SearchFieldProps } from './SearchField';
export type { SectionProps } from './Section';
export type { ListBoxSectionProps, MenuSectionProps } from './Section';
export type { SelectProps, SelectValueProps } from './Select';
export type { SeparatorProps } from './Separator';
export type { SwitchProps } from './Switch';
Expand Down Expand Up @@ -129,7 +129,7 @@ export { RadioGroup } from './RadioGroup';
export { RadioIconButton } from './RadioIconButton';
export { RouterProvider } from './RouterProvider';
export { SearchField } from './SearchField';
export { Section } from './Section';
export { ListBoxSection, MenuSection } from './Section';
export { Select, SelectValue } from './Select';
export { Separator } from './Separator';
export { Switch } from './Switch';
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/Breadcrumbs.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import { Breadcrumb, Breadcrumbs, Link } from '../src';

const meta: Meta<typeof Breadcrumbs> = {
component: Breadcrumbs,
// @ts-ignore
subcomponents: { Breadcrumb },
subcomponents: { Breadcrumb } as Record<string, ComponentType<unknown>>,
title: 'Components/Navigation/Breadcrumbs',
parameters: {
status: {
Expand Down
7 changes: 5 additions & 2 deletions packages/components/stories/Calendar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import {
getLocalTimeZone,
Expand All @@ -25,8 +26,10 @@ import {

const meta: Meta<typeof Calendar> = {
component: Calendar,
// @ts-ignore
subcomponents: { CalendarCell, CalendarGrid, CalendarPicker, Heading, Preset },
subcomponents: { CalendarCell, CalendarGrid, CalendarPicker, Heading, Preset } as Record<
string,
ComponentType<unknown>
>,
title: 'Components/Date and Time/Calendar',
parameters: {
status: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/ComboBox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryFn, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import { Icon } from '@launchpad-ui/icons';
import { vars } from '@launchpad-ui/vars';
Expand All @@ -19,8 +20,7 @@ import {

const meta: Meta<typeof ComboBox> = {
component: ComboBox,
// @ts-ignore
subcomponents: { ComboBoxClearButton },
subcomponents: { ComboBoxClearButton } as Record<string, ComponentType<unknown>>,
title: 'Components/Pickers/ComboBox',
parameters: {
status: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/DateField.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryFn, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import { vars } from '@launchpad-ui/vars';
import { userEvent } from '@storybook/test';
Expand All @@ -7,8 +8,7 @@ import { DateField, DateInput, DateSegment, Label, Text } from '../src';

const meta: Meta<typeof DateField> = {
component: DateField,
// @ts-ignore
subcomponents: { DateInput, DateSegment },
subcomponents: { DateInput, DateSegment } as Record<string, ComponentType<unknown>>,
title: 'Components/Date and Time/DateField',
parameters: {
status: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/Disclosure.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import { Icon } from '@launchpad-ui/icons';
import { vars } from '@launchpad-ui/vars';
Expand All @@ -7,8 +8,7 @@ import { Button, Disclosure, DisclosurePanel, Heading } from '../src';

const meta: Meta<typeof Disclosure> = {
component: Disclosure,
// @ts-ignore
subcomponents: { DisclosurePanel },
subcomponents: { DisclosurePanel } as Record<string, ComponentType<unknown>>,
title: 'Components/Navigation/Disclosure',
parameters: {
status: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/GridList.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import { useDragAndDrop } from 'react-aria-components';
import { useListData } from 'react-stately';
Expand All @@ -17,8 +18,7 @@ import {

const meta: Meta<typeof GridList> = {
component: GridList,
// @ts-ignore
subcomponents: { GridListItem },
subcomponents: { GridListItem } as Record<string, ComponentType<unknown>>,
title: 'Components/Collections/GridList',
parameters: {
status: {
Expand Down
14 changes: 7 additions & 7 deletions packages/components/stories/ListBox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';
import type { Selection as AriaSelection } from 'react-aria-components';

import { Icon } from '@launchpad-ui/icons';
import { fireEvent, userEvent, within } from '@storybook/test';
import { useState } from 'react';

import { Header, ListBox, ListBoxItem, Section, Text } from '../src';
import { Header, ListBox, ListBoxItem, ListBoxSection, Text } from '../src';

const meta: Meta<typeof ListBox> = {
component: ListBox,
// @ts-ignore
subcomponents: { ListBoxItem, Section, Header },
subcomponents: { ListBoxItem, ListBoxSection, Header } as Record<string, ComponentType<unknown>>,
title: 'Components/Collections/ListBox',
parameters: {
status: {
Expand Down Expand Up @@ -39,18 +39,18 @@ export const Grouping: Story = {
render: (args) => {
return (
<ListBox aria-label="Items" selectionMode="multiple" {...args}>
<Section>
<ListBoxSection>
<Header>Group 1</Header>
<ListBoxItem>Item one</ListBoxItem>
<ListBoxItem>Item two</ListBoxItem>
<ListBoxItem>Item three</ListBoxItem>
</Section>
<Section>
</ListBoxSection>
<ListBoxSection>
<Header>Group 2</Header>
<ListBoxItem>Item four</ListBoxItem>
<ListBoxItem>Item five</ListBoxItem>
<ListBoxItem>Item six</ListBoxItem>
</Section>
</ListBoxSection>
</ListBox>
);
},
Expand Down
22 changes: 15 additions & 7 deletions packages/components/stories/Menu.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryFn, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';
import type { Selection as AriaSelection } from 'react-aria-components';

import { Icon } from '@launchpad-ui/icons';
Expand All @@ -11,18 +12,25 @@ import {
Keyboard,
Menu,
MenuItem,
MenuSection,
MenuTrigger,
Popover,
Section,
Separator,
SubmenuTrigger,
Text,
} from '../src';

const meta: Meta<typeof Menu> = {
component: Menu,
// @ts-ignore
subcomponents: { MenuItem, MenuTrigger, SubmenuTrigger, Section, Header, Keyboard, Separator },
subcomponents: {
MenuItem,
MenuTrigger,
SubmenuTrigger,
MenuSection,
Header,
Keyboard,
Separator,
} as Record<string, ComponentType<unknown>>,
title: 'Components/Collections/Menu',
parameters: {
status: {
Expand Down Expand Up @@ -83,15 +91,15 @@ export const Grouping: Story = {
<Button>Trigger</Button>
<Popover>
<Menu {...args}>
<Section>
<MenuSection>
<Header>Group 1</Header>
<MenuItem>Item one</MenuItem>
<MenuItem>Item two</MenuItem>
</Section>
<Section>
</MenuSection>
<MenuSection>
<Header>Group 2</Header>
<MenuItem>Item three</MenuItem>
</Section>
</MenuSection>
</Menu>
</Popover>
</MenuTrigger>
Expand Down
10 changes: 7 additions & 3 deletions packages/components/stories/Modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Meta, ReactRenderer, StoryFn, StoryObj } from '@storybook/react';
import { expect, userEvent, within } from '@storybook/test';
import type { PlayFunction } from '@storybook/types';
import type { ComponentType } from 'react';

import { expect, userEvent, within } from '@storybook/test';

import { allModes } from '../../../.storybook/modes';
import {
Expand All @@ -16,8 +18,10 @@ import {

const meta: Meta<typeof Modal> = {
component: Modal,
// @ts-ignore
subcomponents: { ModalOverlay, Dialog, DialogTrigger, Heading },
subcomponents: { ModalOverlay, Dialog, DialogTrigger, Heading } as Record<
string,
ComponentType<unknown>
>,
title: 'Components/Overlays/Modal',
parameters: {
status: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/Popover.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Meta, ReactRenderer, StoryFn, StoryObj } from '@storybook/react';
import type { PlayFunction } from '@storybook/types';
import type { ComponentType } from 'react';

import { expect, userEvent, within } from '@storybook/test';

import { Button, Dialog, DialogTrigger, Heading, OverlayArrow, Popover, Pressable } from '../src';

const meta: Meta<typeof Popover> = {
component: Popover,
// @ts-ignore
subcomponents: { OverlayArrow, DialogTrigger },
subcomponents: { OverlayArrow, DialogTrigger } as Record<string, ComponentType<unknown>>,
title: 'Components/Overlays/Popover',
parameters: {
status: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/RadioGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import { userEvent, within } from '@storybook/test';

import { Button, FieldError, Form, Label, Radio, RadioGroup, Text } from '../src';

const meta: Meta<typeof RadioGroup> = {
component: RadioGroup,
// @ts-ignore
subcomponents: { Radio },
subcomponents: { Radio } as Record<string, ComponentType<unknown>>,
title: 'Components/Forms/RadioGroup',
parameters: {
status: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/RangeCalendar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import {
endOfMonth,
Expand Down Expand Up @@ -27,8 +28,7 @@ import {

const meta: Meta<typeof RangeCalendar> = {
component: RangeCalendar,
// @ts-ignore
subcomponents: { CalendarCell, CalendarGrid, Heading },
subcomponents: { CalendarCell, CalendarGrid, Heading } as Record<string, ComponentType<unknown>>,
title: 'Components/Date and Time/RangeCalendar',
parameters: {
status: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/stories/Select.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryFn, StoryObj } from '@storybook/react';
import type { ComponentType } from 'react';

import { Icon } from '@launchpad-ui/icons';
import { vars } from '@launchpad-ui/vars';
Expand All @@ -8,8 +9,7 @@ import { Button, Label, ListBox, ListBoxItem, Popover, Select, SelectValue, Text

const meta: Meta<typeof Select> = {
component: Select,
// @ts-ignore
subcomponents: { SelectValue },
subcomponents: { SelectValue } as Record<string, ComponentType<unknown>>,
title: 'Components/Pickers/Select',
parameters: {
status: {
Expand Down
Loading
Loading