Skip to content

Commit

Permalink
Rename owner state to state
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Nov 26, 2024
1 parent 424a7a2 commit 06ec557
Show file tree
Hide file tree
Showing 165 changed files with 597 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function UnstyledSwitchIntroduction() {

const Switch = React.forwardRef<HTMLButtonElement, BaseSwitch.Root.Props>(
function Switch({ className: classNameProp = '', ...props }, ref) {
const className = ({ checked }: BaseSwitch.Root.OwnerState) =>
const className = ({ checked }: BaseSwitch.Root.State) =>
`group relative inline-block w-[38px] h-[24px] m-2.5 p-0 transition rounded-full
border border-solid outline-none border-gray-300 dark:border-gray-700
focus-visible:shadow-outline-switch
Expand All @@ -48,7 +48,7 @@ const Thumb = React.forwardRef<
HTMLSpanElement,
React.HTMLAttributes<HTMLSpanElement>
>(function Thumb({ className: classNameProp = '', ...props }, ref) {
const className = ({ checked }: BaseSwitch.Root.OwnerState) =>
const className = ({ checked }: BaseSwitch.Root.State) =>
`block w-4 h-4 rounded-2xl border border-solid outline-none border-gray-300 dark:border-gray-700 transition
shadow-[0_1px_2px_rgb(0_0_0_/_0.1)] dark:shadow-[0_1px_2px_rgb(0_0_0_/_0.25)]
relative transition-all
Expand Down
6 changes: 1 addition & 5 deletions docs/data/guides/next-js-app-router/next-js-app-router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ export default function Page() {
return (
<React.Fragment>
{/* Next.js won't render this button without 'use-client'*/}
<Button
className={(ownerState: ButtonOwnerState) =>
ownerState.disabled ? 'bg-gray-400' : 'bg-blue-400'
}
>
<Button className={(state: ButtonState) => (state.disabled ? 'bg-gray-400' : 'bg-blue-400')}>
Submit
</Button>

Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/formattedTSDemos.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function transpileFile(tsxPath, project) {
project,
filePath: tsxPath,
shouldResolveObject: ({ name }) => {
if (name === 'classes' || name === 'ownerState') {
if (name === 'classes' || name === 'state') {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/Accordion/Header/AccordionHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const accordionRootContextValue: AccordionRootContext = {
handleValueChange: NOOP,
hiddenUntilFound: false,
orientation: 'vertical',
ownerState: {
state: {
value: [0],
disabled: false,
orientation: 'vertical',
Expand All @@ -24,7 +24,7 @@ const accordionRootContextValue: AccordionRootContext = {

const accordionItemContextValue: AccordionItemContext = {
open: true,
ownerState: {
state: {
value: [0],
disabled: false,
index: 0,
Expand All @@ -46,7 +46,7 @@ const collapsibleContextValue: CollapsibleRootContext = {
setMounted: NOOP,
setOpen: NOOP,
transitionStatus: undefined,
ownerState: {
state: {
open: true,
disabled: false,
transitionStatus: undefined,
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/Accordion/Header/AccordionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const AccordionHeader = React.forwardRef(function AccordionHeader(
) {
const { render, className, ...other } = props;

const { ownerState } = useAccordionItemContext();
const { state } = useAccordionItemContext();

const { renderElement } = useComponentRenderer({
render: render ?? 'h3',
ownerState,
state,
className,
ref: forwardedRef,
extraProps: other,
Expand All @@ -38,7 +38,7 @@ const AccordionHeader = React.forwardRef(function AccordionHeader(
});

export namespace AccordionHeader {
export interface Props extends BaseUIComponentProps<'h3', AccordionItem.OwnerState> {}
export interface Props extends BaseUIComponentProps<'h3', AccordionItem.State> {}
}

export { AccordionHeader };
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Accordion/Item/AccordionItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const accordionRootContextValue: AccordionRootContext = {
handleValueChange: NOOP,
hiddenUntilFound: false,
orientation: 'vertical',
ownerState: {
state: {
value: [0],
disabled: false,
orientation: 'vertical',
Expand Down
24 changes: 12 additions & 12 deletions packages/react/src/Accordion/Item/AccordionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const AccordionItem = React.forwardRef(function AccordionItem(
animated,
disabled: contextDisabled,
handleValueChange,
ownerState: rootOwnerState,
state: rootState,
value: openValues,
} = useAccordionRootContext();

Expand Down Expand Up @@ -80,7 +80,7 @@ const AccordionItem = React.forwardRef(function AccordionItem(
disabled,
});

const collapsibleOwnerState: CollapsibleRoot.OwnerState = React.useMemo(
const collapsibleState: CollapsibleRoot.State = React.useMemo(
() => ({
open: collapsible.open,
disabled: collapsible.disabled,
Expand All @@ -92,38 +92,38 @@ const AccordionItem = React.forwardRef(function AccordionItem(
const collapsibleContext: CollapsibleRootContext = React.useMemo(
() => ({
...collapsible,
ownerState: collapsibleOwnerState,
state: collapsibleState,
}),
[collapsible, collapsibleOwnerState],
[collapsible, collapsibleState],
);

const ownerState: AccordionItem.OwnerState = React.useMemo(
const state: AccordionItem.State = React.useMemo(
() => ({
...rootOwnerState,
...rootState,
index,
disabled,
open: isOpen,
transitionStatus: collapsible.transitionStatus,
}),
[collapsible.transitionStatus, disabled, index, isOpen, rootOwnerState],
[collapsible.transitionStatus, disabled, index, isOpen, rootState],
);

const [triggerId, setTriggerId] = React.useState<string | undefined>(useId());

const accordionItemContext: AccordionItemContext = React.useMemo(
() => ({
open: isOpen,
ownerState,
state,
setTriggerId,
triggerId,
}),
[isOpen, ownerState, setTriggerId, triggerId],
[isOpen, state, setTriggerId, triggerId],
);

const { renderElement } = useComponentRenderer({
render: render ?? 'div',
className,
ownerState,
state,
ref: mergedRef,
extraProps: other,
customStyleHookMapping: accordionStyleHookMapping,
Expand All @@ -141,14 +141,14 @@ const AccordionItem = React.forwardRef(function AccordionItem(
export namespace AccordionItem {
export type Value = number | string;

export interface OwnerState extends AccordionRoot.OwnerState {
export interface State extends AccordionRoot.State {
index: number;
open: boolean;
transitionStatus: TransitionStatus;
}

export interface Props
extends BaseUIComponentProps<'div', OwnerState>,
extends BaseUIComponentProps<'div', State>,
Pick<useCollapsibleRoot.Parameters, 'disabled' | 'onOpenChange'> {
value?: Value;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Accordion/Item/AccordionItemContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { AccordionItem } from './AccordionItem';

export interface AccordionItemContext {
open: boolean;
ownerState: AccordionItem.OwnerState;
state: AccordionItem.State;
setTriggerId: (id: string | undefined) => void;
triggerId?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Accordion/Item/styleHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CustomStyleHookMapping } from '../../utils/getStyleHookProps';
import { collapsibleOpenStateMapping as baseMapping } from '../../utils/collapsibleOpenStateMapping';
import type { AccordionItem } from './AccordionItem';

export const accordionStyleHookMapping: CustomStyleHookMapping<AccordionItem.OwnerState> = {
export const accordionStyleHookMapping: CustomStyleHookMapping<AccordionItem.State> = {
...baseMapping,
index: (value) => {
return Number.isInteger(value) ? { 'data-index': String(value) } : null;
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/Accordion/Panel/AccordionPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const accordionRootContextValue: AccordionRootContext = {
handleValueChange: NOOP,
hiddenUntilFound: false,
orientation: 'vertical',
ownerState: {
state: {
value: [0],
disabled: false,
orientation: 'vertical',
Expand All @@ -24,7 +24,7 @@ const accordionRootContextValue: AccordionRootContext = {

const accordionItemContextValue: AccordionItemContext = {
open: true,
ownerState: {
state: {
value: [0],
disabled: false,
index: 0,
Expand All @@ -46,7 +46,7 @@ const collapsibleContextValue: CollapsibleRootContext = {
setMounted: NOOP,
setOpen: NOOP,
transitionStatus: undefined,
ownerState: {
state: {
open: true,
disabled: false,
transitionStatus: undefined,
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/Accordion/Panel/AccordionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ const AccordionPanel = React.forwardRef(function AccordionPanel(
setOpen,
});

const { ownerState, triggerId } = useAccordionItemContext();
const { state, triggerId } = useAccordionItemContext();

const { renderElement } = useComponentRenderer({
propGetter: getRootProps,
render: render ?? 'div',
ownerState,
state,
className,
extraProps: {
...otherProps,
Expand All @@ -75,7 +75,7 @@ const AccordionPanel = React.forwardRef(function AccordionPanel(

export namespace AccordionPanel {
export interface Props
extends BaseUIComponentProps<'div', AccordionItem.OwnerState>,
extends BaseUIComponentProps<'div', AccordionItem.State>,
Pick<useCollapsiblePanel.Parameters, 'hiddenUntilFound'> {}
}

Expand Down
12 changes: 6 additions & 6 deletions packages/react/src/Accordion/Root/AccordionRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const AccordionRoot = React.forwardRef(function AccordionRoot(
value,
});

const ownerState: AccordionRoot.OwnerState = React.useMemo(
const state: AccordionRoot.State = React.useMemo(
() => ({
value: accordion.value,
disabled: accordion.disabled,
Expand All @@ -76,16 +76,16 @@ const AccordionRoot = React.forwardRef(function AccordionRoot(
() => ({
...accordion,
hiddenUntilFound,
ownerState,
state,
}),
[accordion, hiddenUntilFound, ownerState],
[accordion, hiddenUntilFound, state],
);

const { renderElement } = useComponentRenderer({
propGetter: getRootProps,
render: render ?? 'div',
className,
ownerState,
state,
ref: forwardedRef,
extraProps: otherProps,
customStyleHookMapping: rootStyleHookMapping,
Expand All @@ -99,15 +99,15 @@ const AccordionRoot = React.forwardRef(function AccordionRoot(
});

export namespace AccordionRoot {
export interface OwnerState {
export interface State {
value: useAccordionRoot.Value;
disabled: boolean;
orientation: useAccordionRoot.Orientation;
}

export interface Props
extends useAccordionRoot.Parameters,
Omit<BaseUIComponentProps<'div', OwnerState>, 'defaultValue'> {
Omit<BaseUIComponentProps<'div', State>, 'defaultValue'> {
hiddenUntilFound?: boolean;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Accordion/Root/AccordionRootContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { AccordionRoot } from './AccordionRoot';
import type { useAccordionRoot } from './useAccordionRoot';

export interface AccordionRootContext extends Omit<useAccordionRoot.ReturnValue, 'getRootProps'> {
ownerState: AccordionRoot.OwnerState;
state: AccordionRoot.State;
hiddenUntilFound: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const accordionRootContextValue: AccordionRootContext = {
handleValueChange: NOOP,
hiddenUntilFound: false,
orientation: 'vertical',
ownerState: {
state: {
value: [0],
disabled: false,
orientation: 'vertical',
Expand All @@ -24,7 +24,7 @@ const accordionRootContextValue: AccordionRootContext = {

const accordionItemContextValue: AccordionItemContext = {
open: true,
ownerState: {
state: {
value: [0],
disabled: false,
index: 0,
Expand All @@ -46,7 +46,7 @@ const collapsibleContextValue: CollapsibleRootContext = {
setMounted: NOOP,
setOpen: NOOP,
transitionStatus: undefined,
ownerState: {
state: {
open: true,
disabled: false,
transitionStatus: undefined,
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/Accordion/Trigger/AccordionTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const AccordionTrigger = React.forwardRef(function AccordionTrigger(
setOpen,
});

const { ownerState, setTriggerId, triggerId } = useAccordionItemContext();
const { state, setTriggerId, triggerId } = useAccordionItemContext();

useEnhancedEffect(() => {
setTriggerId(id);
Expand All @@ -50,7 +50,7 @@ const AccordionTrigger = React.forwardRef(function AccordionTrigger(
const { renderElement } = useComponentRenderer({
propGetter: getRootProps,
render: render ?? 'button',
ownerState,
state,
className,
extraProps: { ...otherProps, id: triggerId },
customStyleHookMapping: triggerOpenStateMapping,
Expand All @@ -60,7 +60,7 @@ const AccordionTrigger = React.forwardRef(function AccordionTrigger(
});

namespace AccordionTrigger {
export interface Props extends BaseUIComponentProps<'button', AccordionItem.OwnerState> {}
export interface Props extends BaseUIComponentProps<'button', AccordionItem.State> {}
}

export { AccordionTrigger };
Expand Down
Loading

0 comments on commit 06ec557

Please sign in to comment.