Skip to content
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
117 changes: 101 additions & 16 deletions packages/@react-spectrum/s2/src/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@
* governing permissions and limitations under the License.
*/

import {ContextValue, DisclosureGroup, DisclosureGroupProps, SlotProps} from 'react-aria-components';
import {AriaLabelingProps, DOMProps, DOMRef, DOMRefValue, Key} from '@react-types/shared';
import {ContextValue, DisclosureGroup, RenderProps, SlotProps} from 'react-aria-components';
import {
Disclosure,
DisclosureContext,
DisclosureHeader,
DisclosurePanel,
DisclosurePanelProps,
DisclosureProps,
DisclosureTitle,
DisclosureTitleProps
DisclosureTitle
} from './Disclosure';
import {DOMProps, DOMRef, DOMRefValue, GlobalDOMAttributes} from '@react-types/shared';
import {getAllowedOverrides, StylesPropWithHeight, UnsafeStyles} from './style-utils' with { type: 'macro' };
import {getAllowedOverrides, StyleProps, StylesPropWithHeight, UnsafeStyles} from './style-utils' with { type: 'macro' };
import React, {createContext, forwardRef, ReactNode} from 'react';
import {style} from '../style' with { type: 'macro' };
import {useDOMRef} from '@react-spectrum/utils';
import {useSpectrumContextProps} from './useSpectrumContextProps';

export interface AccordionProps extends Omit<DisclosureGroupProps, 'className' | 'style' | 'children' | keyof GlobalDOMAttributes>, UnsafeStyles, DOMProps, SlotProps {
/** The disclosure elements in the accordion. */
export interface AccordionProps extends UnsafeStyles, DOMProps, SlotProps {
/** The accordion item elements in the accordion. */
children: React.ReactNode,
/** Spectrum-defined styles, returned by the `style()` macro. */
styles?: StylesPropWithHeight,
Expand All @@ -39,12 +36,22 @@ export interface AccordionProps extends Omit<DisclosureGroupProps, 'className' |
*/
size?: 'S' | 'M' | 'L' | 'XL',
/**
* The amount of space between the disclosure items.
* The amount of space between the accordion items.
* @default 'regular'
*/
density?: 'compact' | 'regular' | 'spacious',
/** Whether the accordion should be displayed with a quiet style. */
isQuiet?: boolean
isQuiet?: boolean,
/** Whether multiple accordion items can be expanded at the same time. */
allowsMultipleExpanded?: boolean,
/** Whether all accordion items are disabled. */
isDisabled?: boolean,
/** The currently expanded keys in the accordion (controlled). */
expandedKeys?: Iterable<Key>,
/** The initial expanded keys in the accordion (uncontrolled). */
defaultExpandedKeys?: Iterable<Key>,
/** Handler that is called when accordion items are expanded or collapsed. */
onExpandedChange?: (keys: Set<Key>) => any
}

const accordion = style({
Expand Down Expand Up @@ -80,18 +87,85 @@ export const Accordion = forwardRef(function Accordion(props: AccordionProps, re
);
});

export interface AccordionItemProps extends DisclosureProps {
/** The contents of the accordion, consisting of a AccordionItemTitle and AccordionItemPanel. */
children: ReactNode
export interface AccordionItemState {
/** Whether the accordion item is currently expanded. */
readonly isExpanded: boolean,
/** Sets whether the accordion item is expanded. */
setExpanded(isExpanded: boolean): void,
/** Expand the accordion item. */
expand(): void,
/** Collapse the accordion item. */
collapse(): void,
/** Toggles the accordion item's visibility. */
toggle(): void
}

export interface AccordionItemRenderProps {
/**
* Whether the accordion item is expanded.
* @selector [data-expanded]
*/
isExpanded: boolean,
/**
* Whether the accordion item has keyboard focus.
* @selector [data-focus-visible-within]
*/
isFocusVisibleWithin: boolean,
/**
* Whether the accordion item is disabled.
* @selector [data-disabled]
*/
isDisabled: boolean,
/**
* State of the accordion item.
*/
state: AccordionItemState
}

export interface AccordionItemProps extends Omit<RenderProps<AccordionItemRenderProps>, 'className' | 'style'>, SlotProps, StyleProps {
/**
* The size of the accordion item.
* @default 'M'
*/
size?: 'S' | 'M' | 'L' | 'XL',
/**
* The amount of space between the accordion item.
* @default 'regular'
*/
density?: 'compact' | 'regular' | 'spacious',
/** Whether the accordion item should be displayed with a quiet style. */
isQuiet?: boolean,
/** The contents of the accordion item, consisting of a accordion item title and accordion item panel. */
children: ReactNode,
/** An id for the accordion item, matching the id used in `expandedKeys`. */
id?: Key,
/** Whether the accordion item is disabled. */
isDisabled?: boolean,
/** Handler that is called when the accordion item's expanded state changes. */
onExpandedChange?: (isExpanded: boolean) => void,
/** Whether the accordion item is expanded (controlled). */
isExpanded?: boolean,
/** Whether the accordion item is expanded by default (uncontrolled). */
defaultExpanded?: boolean
}

/**
* A accordion item is a collapsible section of content. It is composed of a header with a heading and trigger button, and a panel that contains the content.
*/
export const AccordionItem = forwardRef(function AccordionItem(props: AccordionItemProps, ref: DOMRef<HTMLDivElement>) {
return <Disclosure {...props} ref={ref} />;
});

export interface AccordionItemTitleProps extends DisclosureTitleProps {}
export interface AccordionItemTitleProps extends UnsafeStyles, DOMProps {
/** The heading level of the accordion item title.
*
* @default 3
*/
level?: number,
/** The contents of the accordion item title. */
children: React.ReactNode
}

/**
* An accordion item title consisting of a heading and a trigger button to expand/collapse the panel.
*/
Expand All @@ -100,16 +174,27 @@ export const AccordionItemTitle = forwardRef(function AccordionItemTitle(props:
});

export interface AccordionItemHeaderProps extends UnsafeStyles, DOMProps {
/** The contents of the accordion item header. */
children: React.ReactNode
}

/**
* A wrapper element for the accordion item title that can contain other elements not part of the trigger.
*/
export const AccordionItemHeader = forwardRef(function AccordionItemHeader(props: AccordionItemHeaderProps, ref: DOMRef<HTMLDivElement>) {
return <DisclosureHeader {...props} ref={ref} />;
});

export interface AccordionItemPanelProps extends DisclosurePanelProps {}
export interface AccordionItemPanelProps extends UnsafeStyles, DOMProps, AriaLabelingProps {
/** The contents of the accordion item panel. */
children: React.ReactNode,
/**
* The accessibility role for the accordion item panel.
* @default 'group'
*/
role?: 'group' | 'region'
}

/**
* An accordion item panel is a collapsible section of content that is hidden until the accordion item is expanded.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/s2/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {baseColor, focusRing, fontRelative, lightDark, linearGradient, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, fontRelative, lightDark, style} from '../style' with {type: 'macro'};
import {ButtonRenderProps, ContextValue, Link, LinkProps, OverlayTriggerStateContext, Provider, Button as RACButton, ButtonProps as RACButtonProps} from 'react-aria-components';
import {centerBaseline} from './CenterBaseline';
import {control, getAllowedOverrides, staticColor, StyleProps} from './style-utils' with {type: 'macro'};
Expand All @@ -19,6 +19,7 @@ import {FocusableRef, FocusableRefValue, GlobalDOMAttributes} from '@react-types
import {IconContext} from './Icon';
// @ts-ignore
import intlMessages from '../intl/*.json';
import {linearGradient} from '../style/spectrum-theme' with {type: 'macro'};
import {pressScale} from './pressScale';
import {ProgressCircle} from './ProgressCircle';
import {SkeletonContext} from './Skeleton';
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/s2/src/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
import {AsyncLoadable, GlobalDOMAttributes, HelpTextProps, LoadingState, SpectrumLabelableProps} from '@react-types/shared';
import {AvatarContext} from './Avatar';
import {BaseCollection, CollectionNode, createLeafComponent} from '@react-aria/collections';
import {baseColor, edgeToText, focusRing, space, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, space, style} from '../style' with {type: 'macro'};
import {centerBaseline} from './CenterBaseline';
import {centerPadding, control, controlBorderRadius, controlFont, controlSize, field, fieldInput, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
import {
Expand All @@ -51,6 +51,7 @@ import CheckmarkIcon from '../ui-icons/Checkmark';
import ChevronIcon from '../ui-icons/Chevron';
import {createContext, CSSProperties, ForwardedRef, forwardRef, ReactNode, Ref, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import {createFocusableRef} from '@react-spectrum/utils';
import {edgeToText} from '../style/spectrum-theme' with {type: 'macro'};
import {FieldErrorIcon, FieldGroup, FieldLabel, HelpText, Input} from './Field';
import {FormContext, useFormProps} from './Form';
import {forwardRefType} from './types';
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/s2/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
Separator,
SeparatorProps
} from 'react-aria-components';
import {baseColor, edgeToText, focusRing, fontRelative, size, space, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, fontRelative, size, space, style} from '../style' with {type: 'macro'};
import {box, iconStyles} from './Checkbox';
import {centerBaseline} from './CenterBaseline';
import {centerPadding, control, controlFont, controlSize, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
Expand All @@ -37,6 +37,7 @@ import ChevronRightIcon from '../ui-icons/Chevron';
import {createContext, forwardRef, JSX, ReactNode, useContext, useRef, useState} from 'react';
import {divider} from './Divider';
import {DOMRef, DOMRefValue, GlobalDOMAttributes, PressEvent} from '@react-types/shared';
import {edgeToText} from '../style/spectrum-theme' with {type: 'macro'};
import {forwardRefType} from './types';
import {HeaderContext, HeadingContext, KeyboardContext, Text, TextContext} from './Content';
import {IconContext} from './Icon'; // chevron right removed??
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/s2/src/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from 'react-aria-components';
import {AsyncLoadable, FocusableRef, FocusableRefValue, GlobalDOMAttributes, HelpTextProps, LoadingState, PressEvent, RefObject, SpectrumLabelableProps} from '@react-types/shared';
import {AvatarContext} from './Avatar';
import {baseColor, edgeToText, focusRing, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, style} from '../style' with {type: 'macro'};
import {box, iconStyles as checkboxIconStyles} from './Checkbox';
import {centerBaseline} from './CenterBaseline';
import {
Expand All @@ -57,6 +57,7 @@ import {
listboxItem,
LOADER_ROW_HEIGHTS
} from './ComboBox';
import {edgeToText} from '../style/spectrum-theme' with {type: 'macro'};
import {
FieldErrorIcon,
FieldLabel,
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/s2/src/TabsPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
Provider,
SelectValue
} from 'react-aria-components';
import {baseColor, edgeToText, focusRing, size, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, size, style} from '../style' with {type: 'macro'};
import {centerBaseline} from './CenterBaseline';
import {
checkmark,
Expand All @@ -37,6 +37,7 @@ import {
import CheckmarkIcon from '../ui-icons/Checkmark';
import ChevronIcon from '../ui-icons/Chevron';
import {controlFont, fieldInput, StyleProps} from './style-utils' with {type: 'macro'};
import {edgeToText} from '../style/spectrum-theme' with {type: 'macro'};
import {
FieldLabel
} from './Field';
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/s2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export {pressScale} from './pressScale';
export {Autocomplete, Collection, FileTrigger, parseColor, useLocale} from 'react-aria-components';
export {useListData, useTreeData, useAsyncList} from 'react-stately';

export type {AccordionProps, AccordionItemProps, AccordionItemHeaderProps, AccordionItemTitleProps, AccordionItemPanelProps} from './Accordion';
export type {AccordionProps, AccordionItemProps, AccordionItemHeaderProps, AccordionItemTitleProps, AccordionItemPanelProps, AccordionItemState, AccordionItemRenderProps} from './Accordion';
export type {ActionBarProps} from './ActionBar';
export type {ActionButtonProps} from './ActionButton';
export type {ActionButtonGroupProps} from './ActionButtonGroup';
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/s2/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Inset, fontRelative as internalFontRelative, space as internalSpace, Spa
import type {MacroContext} from '@parcel/macros';
import {StyleString} from './types';

export {baseColor, color, edgeToText, lightDark, linearGradient, colorMix, size, style} from './spectrum-theme';
export {baseColor, color, lightDark, colorMix, size, style} from './spectrum-theme';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to keep color public since it helps handle light dark for people, useful for styling arbitrary elements IMO

export type {StyleString} from './types';

// Wrap these functions in arbitrary value syntax when called from the outside.
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/s2-docs/pages/s2/ActionButton.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function PendingButton() {

## API

```tsx links={{ActionButton: '#actionbutton', Avatar: 'Avatar', Icon: 'icons'}}
```tsx links={{ActionButton: '#actionbutton', Avatar: 'Avatar', Icon: 'icons', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span'}}
<ActionButton>
<Icon /> or <Avatar />
<Text />
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/s2-docs/pages/s2/Button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function PendingButton() {

## API

```tsx links={{Button: '#button', Icon: 'icons'}}
```tsx links={{Button: '#button', Icon: 'icons', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span'}}
<Button>
<Icon />
<Text />
Expand Down
8 changes: 4 additions & 4 deletions packages/dev/s2-docs/pages/s2/Card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ import {Skeleton, Card, CardPreview, Image, Content, Text} from '@react-spectrum

### Card

```tsx links={{Image: 'Image', Illustration: 'illustrations', ActionMenu: 'ActionMenu'}}
```tsx links={{Image: 'Image', Illustration: 'illustrations', ActionMenu: 'ActionMenu', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span', Footer: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer'}}
<Card>
<CardPreview>
<Image /> or <Illustration />
Expand All @@ -273,7 +273,7 @@ import {Skeleton, Card, CardPreview, Image, Content, Text} from '@react-spectrum

### AssetCard

```tsx links={{Image: 'Image', Illustration: 'illustrations', ActionMenu: 'ActionMenu'}}
```tsx links={{Image: 'Image', Illustration: 'illustrations', ActionMenu: 'ActionMenu', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span'}}
<AssetCard>
<CardPreview>
<Image /> or <Illustration />
Expand All @@ -290,7 +290,7 @@ import {Skeleton, Card, CardPreview, Image, Content, Text} from '@react-spectrum

### UserCard

```tsx links={{Image: 'Image', ActionMenu: 'ActionMenu'}}
```tsx links={{Image: 'Image', ActionMenu: 'ActionMenu', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span', Footer: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer'}}
<UserCard>
<CardPreview>
<Image />
Expand All @@ -309,7 +309,7 @@ import {Skeleton, Card, CardPreview, Image, Content, Text} from '@react-spectrum

### ProductCard

```tsx links={{Image: 'Image', ActionMenu: 'ActionMenu', Button: 'Button', LinkButton: 'LinkButton'}}
```tsx links={{Image: 'Image', ActionMenu: 'ActionMenu', Button: 'Button', LinkButton: 'LinkButton', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span', Footer: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer'}}
<ProductCard>
<CardPreview>
<Image slot="preview" />
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/s2-docs/pages/s2/ComboBox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ import {ComboBox, ComboBoxItem} from '@react-spectrum/s2';

## API

```tsx links={{ComboBox: '#combobox', ComboBoxItem: '#comboboxitem', ComboBoxSection: '#comboboxsection', Icon: 'icons', Avatar: 'Avatar'}}
```tsx links={{ComboBox: '#combobox', ComboBoxItem: '#comboboxitem', ComboBoxSection: '#comboboxsection', Icon: 'icons', Avatar: 'Avatar', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span', Header: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header', Heading: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements'}}
<ComboBox>
<ComboBoxItem>
<Icon /> or <Avatar />
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/s2-docs/pages/s2/ContextualHelp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {ContextualHelp, Heading, Content, Footer, Link} from '@react-spectrum/s2

## API

```tsx links={{ContextualHelp: '#contextualhelp'}}
```tsx links={{ContextualHelp: '#contextualhelp', Heading: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div', Footer: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer'}}
<ContextualHelp>
<Heading />
<Content />
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/s2-docs/pages/s2/Dialog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function DialogContainerExample() {

### Dialog

```tsx links={{ButtonGroup: 'ButtonGroup', Image:' Image'}}
```tsx links={{ButtonGroup: 'ButtonGroup', Image:' Image', Heading: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements', Header: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div', Footer: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer'}}
<Dialog>
<Image slot="hero">
<Heading slot="title" />
Expand All @@ -279,7 +279,7 @@ function DialogContainerExample() {

### FullscreenDialog

```tsx links={{ButtonGroup: 'ButtonGroup'}}
```tsx links={{ButtonGroup: 'ButtonGroup', Heading: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements', Header: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div'}}
<FullscreenDialog>
<Heading slot="title" />
<Header />
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/s2-docs/pages/s2/IllustratedMessage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Image from '@react-spectrum/s2/illustrations/gradient/generic1/Image';

## API

```tsx links={{IllustratedMessage: '#illustratedmessage', ButtonGroup: 'ButtonGroup', Illustration: 'illustrations'}}
```tsx links={{IllustratedMessage: '#illustratedmessage', ButtonGroup: 'ButtonGroup', Illustration: 'illustrations', Heading: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div'}}
<IllustratedMessage>
<Illustration />
<Heading />
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/s2-docs/pages/s2/InlineAlert.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function Example() {

## API

```tsx links={{InlineAlert: '#inlinealert'}}
```tsx links={{InlineAlert: '#inlinealert', Heading: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements', Content: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div'}}
<InlineAlert>
<Heading />
<Content />
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/s2-docs/pages/s2/LinkButton.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const description = 'Combines the functionality of a link with the appear

## API

```tsx links={{LinkButton: '#linkbutton', Icon: 'icons'}}
```tsx links={{LinkButton: '#linkbutton', Icon: 'icons', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span'}}
<LinkButton>
<Icon />
<Text />
Expand Down
Loading