Skip to content
Open
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
10 changes: 10 additions & 0 deletions .changeset/alert-dialog-loading-and-escape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@jects/jds": patch
---

**AlertDialog**

`<AlertDialog.Action>`에 `loading` prop을, `<AlertDialog.Content>`에 `closeOnEscapeKeyDown` prop을 추가했습니다. 기존 호출부는 수정할 필요가 없습니다.

- `<AlertDialog.Action>`의 `loading` — 기본값 `false`, `BlockButton`의 `loading`과 동일하게 내용을 숨겨 너비를 유지한 채 스피너를 표시하고 클릭을 막음, 포커스는 유지, `disabled`와 함께 지정하면 `disabled` 우선
- `<AlertDialog.Content>`의 `closeOnEscapeKeyDown` — 기본값 `true`, `false`로 지정하면 Esc 키를 눌러도 다이얼로그가 닫히지 않음
56 changes: 55 additions & 1 deletion packages/jds/src/components/AlertDialog/AlertDialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SAMPLE_BUTTON = "레이블";

interface StoryArgs {
closeOnInteractOutside: boolean;
closeOnEscapeKeyDown: boolean;
buttonLayout: AlertDialogButtonLayout;
width?: number;
}
Expand All @@ -30,6 +31,12 @@ const meta: Meta<StoryArgs> = {
"`AlertDialog.Content`의 prop입니다. `true`로 설정하면 다이얼로그 바깥을 클릭하거나 바깥으로 포커스를 이동했을 때 다이얼로그가 닫힙니다. Esc 키 동작에는 영향을 주지 않습니다.",
table: { defaultValue: { summary: "false" } },
},
closeOnEscapeKeyDown: {
control: "boolean",
description:
"`AlertDialog.Content`의 prop입니다. `false`로 설정하면 Esc 키를 눌러도 다이얼로그가 닫히지 않습니다.",
table: { defaultValue: { summary: "true" } },
},
buttonLayout: {
control: "inline-radio",
options: ["horizontal", "vertical"],
Expand All @@ -40,6 +47,7 @@ const meta: Meta<StoryArgs> = {
},
args: {
closeOnInteractOutside: false,
closeOnEscapeKeyDown: true,
buttonLayout: "horizontal",
},
};
Expand All @@ -52,6 +60,7 @@ interface SampleProps {
open?: boolean;
onOpenChange?: (open: boolean) => void;
closeOnInteractOutside?: boolean;
closeOnEscapeKeyDown?: boolean;
buttonLayout?: AlertDialogButtonLayout;
width?: number;
description?: string;
Expand All @@ -62,13 +71,18 @@ const Sample = ({
open,
onOpenChange,
closeOnInteractOutside,
closeOnEscapeKeyDown,
buttonLayout,
width,
description = SAMPLE_DESCRIPTION,
withSecondary = false,
}: SampleProps) => (
<AlertDialog.Root open={open} onOpenChange={onOpenChange}>
<AlertDialog.Content closeOnInteractOutside={closeOnInteractOutside} width={width}>
<AlertDialog.Content
closeOnInteractOutside={closeOnInteractOutside}
closeOnEscapeKeyDown={closeOnEscapeKeyDown}
width={width}
>
<AlertDialog.Title>{SAMPLE_TITLE}</AlertDialog.Title>
<AlertDialog.Description>{description}</AlertDialog.Description>
<AlertDialog.Footer buttonLayout={buttonLayout}>
Expand Down Expand Up @@ -401,3 +415,43 @@ export const Feedback: Story = {
},
},
};

export const Loading: Story = {
render: () => (
<Matrix>
<MatrixCase label='primary loading'>
{container => (
<MatrixDialog container={container}>
<AlertDialog.Action hierarchy='secondary'>{SAMPLE_BUTTON}</AlertDialog.Action>
<AlertDialog.Action loading>{SAMPLE_BUTTON}</AlertDialog.Action>
</MatrixDialog>
)}
</MatrixCase>
<MatrixCase label='destructive loading'>
{container => (
<MatrixDialog container={container}>
<AlertDialog.Action hierarchy='secondary'>{SAMPLE_BUTTON}</AlertDialog.Action>
<AlertDialog.Action feedback='destructive' loading>
{SAMPLE_BUTTON}
</AlertDialog.Action>
</MatrixDialog>
)}
</MatrixCase>
</Matrix>
),
parameters: {
layout: "padded",
docs: {
description: {
story:
"`loading`을 지정하면 버튼 너비를 유지한 채 스피너를 표시하고 클릭을 막습니다. 다이얼로그를 닫는 시점은 `open`으로 직접 제어합니다.",
},
source: {
code: `<AlertDialog.Footer>
<AlertDialog.Action hierarchy="secondary">레이블</AlertDialog.Action>
<AlertDialog.Action loading>레이블</AlertDialog.Action>
</AlertDialog.Footer>`,
},
},
},
};
6 changes: 5 additions & 1 deletion packages/jds/src/components/AlertDialog/AlertDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ const focusSecondaryAction = (event: Event) => {
};

const AlertDialogContent = forwardRef<HTMLDivElement, AlertDialogContentProps>(
({ children, closeOnInteractOutside = false, container, width }, ref) => {
(
{ children, closeOnInteractOutside = false, closeOnEscapeKeyDown = true, container, width },
ref,
) => {
const panelStyle =
width == null ? undefined : assignInlineVars({ [styles.panelWidth]: pxToRem(width) });

Expand All @@ -116,6 +119,7 @@ const AlertDialogContent = forwardRef<HTMLDivElement, AlertDialogContentProps>(
style={panelStyle}
onOpenAutoFocus={focusSecondaryAction}
onInteractOutside={closeOnInteractOutside ? undefined : event => event.preventDefault()}
onEscapeKeyDown={closeOnEscapeKeyDown ? undefined : event => event.preventDefault()}
>
<RequiredPartCheck>{children}</RequiredPartCheck>
</DialogPrimitive.Content>
Expand Down
18 changes: 11 additions & 7 deletions packages/jds/src/components/AlertDialog/alertDialog.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { Dialog } from "radix-ui";
import type { ComponentPropsWithoutRef, ReactNode } from "react";
import type { ReactNode } from "react";
import type { RenderableNode } from "types";

import type {
BaseBlockButtonProps,
BlockButtonNativeProps,
} from "../Button/BlockButton/blockButton.types";
import type { CheckedState } from "../Checkbox";

export type AlertDialogButtonLayout = "horizontal" | "vertical";
Expand All @@ -15,6 +19,8 @@ export interface AlertDialogContentProps {
children: ReactNode;
/** `true`로 설정하면 바깥을 클릭하거나 바깥으로 포커스를 이동했을 때 닫힌다. Esc 키 동작에는 영향을 주지 않는다. */
closeOnInteractOutside?: boolean;
/** `false`로 설정하면 Esc 키를 눌러도 닫히지 않는다. */
closeOnEscapeKeyDown?: boolean;
container?: HTMLElement | null;
/** 너비를 px 단위로 고정한다. 지정하지 않으면 내용에 따라 400~560px 사이에서 너비가 결정된다. */
width?: number;
Expand Down Expand Up @@ -45,12 +51,10 @@ export interface AlertDialogCheckboxProps {

export type AlertDialogActionHierarchy = "primary" | "secondary";

export interface AlertDialogActionBaseProps extends Omit<
ComponentPropsWithoutRef<"button">,
"children" | "className" | "style"
> {
children: ReactNode;
}
export interface AlertDialogActionBaseProps
extends
Omit<BaseBlockButtonProps, "size" | "prefixIcon" | "suffixIcon" | "className" | "style">,
Comment thread
itwillbeoptimal marked this conversation as resolved.
Resolved
Omit<BlockButtonNativeProps, "asChild"> {}

export interface AlertDialogActionHierarchyProps {
hierarchy?: AlertDialogActionHierarchy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface BlockButtonFeedbackProps {
variant?: never;
}

interface BlockButtonNativeProps {
export interface BlockButtonNativeProps {
asChild?: false;
disabled?: boolean;
loading?: boolean;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.