Skip to content
Draft
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
26 changes: 7 additions & 19 deletions packages/accordion/src/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ import type {

const AccordionContext = React.createContext<RootContext | null>(null);

const Root = React.forwardRef<RootRef, RootProps>(
(
{
asChild,
function Root({ ref, asChild,
type,
disabled,
collapsible = true,
value: valueProp,
onValueChange: onValueChangeProps,
defaultValue,
...viewProps
},
ref
) => {
}: RootProps & { ref?: React.Ref<RootRef> }) {
const [value = type === 'multiple' ? [] : undefined, onValueChange] = useControllableState<
(string | undefined) | string[]
>({
Expand All @@ -55,7 +50,6 @@ const Root = React.forwardRef<RootRef, RootProps>(
</AccordionContext.Provider>
);
}
);

Root.displayName = 'RootNativeAccordion';

Expand All @@ -76,8 +70,7 @@ type AccordionItemContext = ItemProps & {

const AccordionItemContext = React.createContext<AccordionItemContext | null>(null);

const Item = React.forwardRef<ItemRef, ItemProps>(
({ asChild, value, disabled, ...viewProps }, ref) => {
function Item({ ref, asChild, value, disabled, ...viewProps }: ItemProps & { ref?: React.Ref<ItemRef> }) {
const { value: rootValue } = useRootContext();
const nativeID = React.useId();

Expand All @@ -95,7 +88,6 @@ const Item = React.forwardRef<ItemRef, ItemProps>(
</AccordionItemContext.Provider>
);
}
);

Item.displayName = 'ItemNativeAccordion';

Expand All @@ -109,7 +101,7 @@ function useItemContext() {
return context;
}

const Header = React.forwardRef<HeaderRef, HeaderProps>(({ asChild, ...props }, ref) => {
function Header({ ref, asChild, ...props }: HeaderProps & { ref?: React.Ref<HeaderRef> }) {
const { disabled: rootDisabled } = useRootContext();
const { disabled: itemDisabled, isExpanded } = useItemContext();

Expand All @@ -123,12 +115,11 @@ const Header = React.forwardRef<HeaderRef, HeaderProps>(({ asChild, ...props },
{...props}
/>
);
});
}

Header.displayName = 'HeaderNativeAccordion';

const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
({ asChild, onPress: onPressProp, disabled: disabledProp, ...props }, ref) => {
function Trigger({ ref, asChild, onPress: onPressProp, disabled: disabledProp, ...props }: TriggerProps & { ref?: React.Ref<TriggerRef> }) {
const {
disabled: rootDisabled,
type,
Expand Down Expand Up @@ -175,12 +166,10 @@ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
/>
);
}
);

Trigger.displayName = 'TriggerNativeAccordion';

const Content = React.forwardRef<ContentRef, ContentProps>(
({ asChild, forceMount, ...props }, ref) => {
function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref<ContentRef> }) {
const { type } = useRootContext();
const { nativeID, isExpanded } = useItemContext();

Expand All @@ -201,7 +190,6 @@ const Content = React.forwardRef<ContentRef, ContentProps>(
/>
);
}
);

Content.displayName = 'ContentNativeAccordion';

Expand Down
26 changes: 7 additions & 19 deletions packages/accordion/src/accordion.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import type {

const AccordionContext = React.createContext<RootProps | null>(null);

const Root = React.forwardRef<RootRef, RootProps>(
(
{
asChild,
function Root({ ref, asChild,
value: valueProp,
onValueChange: onValueChangeProps,
defaultValue,
Expand All @@ -35,9 +32,7 @@ const Root = React.forwardRef<RootRef, RootProps>(
orientation = 'vertical',
collapsible,
...props
},
ref
) => {
}: RootProps & { ref?: React.Ref<RootRef> }) {
const [value = type === 'multiple' ? [] : undefined, onValueChange] = useControllableState<
(string | undefined) | string[]
>({
Expand Down Expand Up @@ -75,7 +70,6 @@ const Root = React.forwardRef<RootRef, RootProps>(
</AccordionContext.Provider>
);
}
);

Root.displayName = 'RootWebAccordion';

Expand All @@ -93,8 +87,7 @@ const AccordionItemContext = React.createContext<(ItemProps & { isExpanded: bool
null
);

const Item = React.forwardRef<ItemRef, ItemProps>(
({ asChild, value: itemValue, disabled, ...props }, ref) => {
function Item({ ref, asChild, value: itemValue, disabled, ...props }: ItemProps & { ref?: React.Ref<ItemRef> }) {
const augmentedRef = useAugmentedRef({ ref });
const { value, orientation, disabled: disabledRoot } = useRootContext();

Expand Down Expand Up @@ -133,7 +126,6 @@ const Item = React.forwardRef<ItemRef, ItemProps>(
</AccordionItemContext.Provider>
);
}
);

Item.displayName = 'ItemWebAccordion';

Expand All @@ -147,7 +139,7 @@ function useItemContext() {
return context;
}

const Header = React.forwardRef<HeaderRef, HeaderProps>(({ asChild, ...props }, ref) => {
function Header({ ref, asChild, ...props }: HeaderProps & { ref?: React.Ref<HeaderRef> }) {
const augmentedRef = useAugmentedRef({ ref });
const { disabled, isExpanded } = useItemContext();
const { orientation, disabled: disabledRoot } = useRootContext();
Expand Down Expand Up @@ -177,7 +169,7 @@ const Header = React.forwardRef<HeaderRef, HeaderProps>(({ asChild, ...props },
<Component ref={augmentedRef} {...props} />
</Accordion.Header>
);
});
}

Header.displayName = 'HeaderWebAccordion';

Expand All @@ -189,8 +181,7 @@ const HIDDEN_STYLE: React.CSSProperties = {
opacity: 0,
};

const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
({ asChild, disabled: disabledProp, ...props }, ref) => {
function Trigger({ ref, asChild, disabled: disabledProp, ...props }: TriggerProps & { ref?: React.Ref<TriggerRef> }) {
const { disabled: disabledRoot } = useRootContext();
const { disabled, isExpanded } = useItemContext();
const triggerRef = React.useRef<HTMLButtonElement>(null);
Expand Down Expand Up @@ -246,12 +237,10 @@ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
</>
);
}
);

Trigger.displayName = 'TriggerWebAccordion';

const Content = React.forwardRef<ContentRef, ContentProps>(
({ asChild, forceMount, ...props }, ref) => {
function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref<ContentRef> }) {
const augmentedRef = useAugmentedRef({ ref });

const { orientation, disabled: disabledRoot } = useRootContext();
Expand Down Expand Up @@ -283,7 +272,6 @@ const Content = React.forwardRef<ContentRef, ContentProps>(
</Accordion.Content>
);
}
);

Content.displayName = 'ContentWebAccordion';

Expand Down
32 changes: 9 additions & 23 deletions packages/alert-dialog/src/alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import type {

const AlertDialogContext = React.createContext<(RootContext & { nativeID: string }) | null>(null);

const Root = React.forwardRef<RootRef, RootProps>(
({ asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => {
function Root({ ref, asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref<RootRef> }) {
const nativeID = React.useId();
const [open = false, onOpenChange] = useControllableState({
prop: openProp,
Expand All @@ -47,7 +46,6 @@ const Root = React.forwardRef<RootRef, RootProps>(
</AlertDialogContext.Provider>
);
}
);

Root.displayName = 'RootNativeAlertDialog';

Expand All @@ -61,8 +59,7 @@ function useRootContext() {
return context;
}

const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref<TriggerRef> }) {
const { open: value, onOpenChange } = useRootContext();

function onPress(ev: GestureResponderEvent) {
Expand All @@ -82,7 +79,6 @@ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
/>
);
}
);

Trigger.displayName = 'TriggerNativeAlertDialog';

Expand All @@ -105,8 +101,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) {
);
}

const Overlay = React.forwardRef<OverlayRef, OverlayProps>(
({ asChild, forceMount, ...props }, ref) => {
function Overlay({ ref, asChild, forceMount, ...props }: OverlayProps & { ref?: React.Ref<OverlayRef> }) {
const { open: value } = useRootContext();

if (!forceMount) {
Expand All @@ -118,12 +113,10 @@ const Overlay = React.forwardRef<OverlayRef, OverlayProps>(
const Component = asChild ? Slot.View : View;
return <Component ref={ref} {...props} />;
}
);

Overlay.displayName = 'OverlayNativeAlertDialog';

const Content = React.forwardRef<ContentRef, ContentProps>(
({ asChild, forceMount, ...props }, ref) => {
function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref<ContentRef> }) {
const { open: value, nativeID, onOpenChange } = useRootContext();

React.useEffect(() => {
Expand Down Expand Up @@ -156,12 +149,10 @@ const Content = React.forwardRef<ContentRef, ContentProps>(
/>
);
}
);

Content.displayName = 'ContentNativeAlertDialog';

const Cancel = React.forwardRef<CancelRef, CancelProps>(
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
function Cancel({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: CancelProps & { ref?: React.Ref<CancelRef> }) {
const { onOpenChange } = useRootContext();

function onPress(ev: GestureResponderEvent) {
Expand All @@ -182,12 +173,10 @@ const Cancel = React.forwardRef<CancelRef, CancelProps>(
/>
);
}
);

Cancel.displayName = 'CloseNativeAlertDialog';

const Action = React.forwardRef<ActionRef, ActionProps>(
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
function Action({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: ActionProps & { ref?: React.Ref<ActionRef> }) {
const { onOpenChange } = useRootContext();

function onPress(ev: GestureResponderEvent) {
Expand All @@ -208,25 +197,22 @@ const Action = React.forwardRef<ActionRef, ActionProps>(
/>
);
}
);

Action.displayName = 'ActionNativeAlertDialog';

const Title = React.forwardRef<TitleRef, TitleProps>(({ asChild, ...props }, ref) => {
function Title({ ref, asChild, ...props }: TitleProps & { ref?: React.Ref<TitleRef> }) {
const { nativeID } = useRootContext();
const Component = asChild ? Slot.Text : Text;
return <Component ref={ref} role='heading' nativeID={`${nativeID}_label`} {...props} />;
});
}

Title.displayName = 'TitleNativeAlertDialog';

const Description = React.forwardRef<DescriptionRef, DescriptionProps>(
({ asChild, ...props }, ref) => {
function Description({ ref, asChild, ...props }: DescriptionProps & { ref?: React.Ref<DescriptionRef> }) {
const { nativeID } = useRootContext();
const Component = asChild ? Slot.Text : Text;
return <Component ref={ref} nativeID={`${nativeID}_desc`} {...props} />;
}
);

Description.displayName = 'DescriptionNativeAlertDialog';

Expand Down
Loading