diff --git a/.changeset/alert-dialog-loading-and-escape.md b/.changeset/alert-dialog-loading-and-escape.md new file mode 100644 index 000000000..896332f11 --- /dev/null +++ b/.changeset/alert-dialog-loading-and-escape.md @@ -0,0 +1,10 @@ +--- +"@jects/jds": patch +--- + +**AlertDialog** + +``에 `loading` prop을, ``에 `closeOnEscapeKeyDown` prop을 추가했습니다. 기존 호출부는 수정할 필요가 없습니다. + +- ``의 `loading` — 기본값 `false`, `BlockButton`의 `loading`과 동일하게 내용을 숨겨 너비를 유지한 채 스피너를 표시하고 클릭을 막음, 포커스는 유지, `disabled`와 함께 지정하면 `disabled` 우선 +- ``의 `closeOnEscapeKeyDown` — 기본값 `true`, `false`로 지정하면 Esc 키를 눌러도 다이얼로그가 닫히지 않음 diff --git a/packages/jds/src/components/AlertDialog/AlertDialog.stories.tsx b/packages/jds/src/components/AlertDialog/AlertDialog.stories.tsx index e546c2258..c7b6ab440 100644 --- a/packages/jds/src/components/AlertDialog/AlertDialog.stories.tsx +++ b/packages/jds/src/components/AlertDialog/AlertDialog.stories.tsx @@ -14,6 +14,7 @@ const SAMPLE_BUTTON = "레이블"; interface StoryArgs { closeOnInteractOutside: boolean; + closeOnEscapeKeyDown: boolean; buttonLayout: AlertDialogButtonLayout; width?: number; } @@ -30,6 +31,12 @@ const meta: Meta = { "`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"], @@ -40,6 +47,7 @@ const meta: Meta = { }, args: { closeOnInteractOutside: false, + closeOnEscapeKeyDown: true, buttonLayout: "horizontal", }, }; @@ -52,6 +60,7 @@ interface SampleProps { open?: boolean; onOpenChange?: (open: boolean) => void; closeOnInteractOutside?: boolean; + closeOnEscapeKeyDown?: boolean; buttonLayout?: AlertDialogButtonLayout; width?: number; description?: string; @@ -62,13 +71,18 @@ const Sample = ({ open, onOpenChange, closeOnInteractOutside, + closeOnEscapeKeyDown, buttonLayout, width, description = SAMPLE_DESCRIPTION, withSecondary = false, }: SampleProps) => ( - + {SAMPLE_TITLE} {description} @@ -401,3 +415,43 @@ export const Feedback: Story = { }, }, }; + +export const Loading: Story = { + render: () => ( + + + {container => ( + + {SAMPLE_BUTTON} + {SAMPLE_BUTTON} + + )} + + + {container => ( + + {SAMPLE_BUTTON} + + {SAMPLE_BUTTON} + + + )} + + + ), + parameters: { + layout: "padded", + docs: { + description: { + story: + "`loading`을 지정하면 버튼 너비를 유지한 채 스피너를 표시하고 클릭을 막습니다. 다이얼로그를 닫는 시점은 `open`으로 직접 제어합니다.", + }, + source: { + code: ` + 레이블 + 레이블 +`, + }, + }, + }, +}; diff --git a/packages/jds/src/components/AlertDialog/AlertDialog.tsx b/packages/jds/src/components/AlertDialog/AlertDialog.tsx index 2441c3b46..a07be9ca1 100644 --- a/packages/jds/src/components/AlertDialog/AlertDialog.tsx +++ b/packages/jds/src/components/AlertDialog/AlertDialog.tsx @@ -102,7 +102,10 @@ const focusSecondaryAction = (event: Event) => { }; const AlertDialogContent = forwardRef( - ({ children, closeOnInteractOutside = false, container, width }, ref) => { + ( + { children, closeOnInteractOutside = false, closeOnEscapeKeyDown = true, container, width }, + ref, + ) => { const panelStyle = width == null ? undefined : assignInlineVars({ [styles.panelWidth]: pxToRem(width) }); @@ -116,6 +119,7 @@ const AlertDialogContent = forwardRef( style={panelStyle} onOpenAutoFocus={focusSecondaryAction} onInteractOutside={closeOnInteractOutside ? undefined : event => event.preventDefault()} + onEscapeKeyDown={closeOnEscapeKeyDown ? undefined : event => event.preventDefault()} > {children} diff --git a/packages/jds/src/components/AlertDialog/alertDialog.types.ts b/packages/jds/src/components/AlertDialog/alertDialog.types.ts index cf11a89f9..746d62675 100644 --- a/packages/jds/src/components/AlertDialog/alertDialog.types.ts +++ b/packages/jds/src/components/AlertDialog/alertDialog.types.ts @@ -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"; @@ -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; @@ -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, + Omit {} export interface AlertDialogActionHierarchyProps { hierarchy?: AlertDialogActionHierarchy; diff --git a/packages/jds/src/components/Button/BlockButton/blockButton.types.ts b/packages/jds/src/components/Button/BlockButton/blockButton.types.ts index 8fdf18958..a2827e6ec 100644 --- a/packages/jds/src/components/Button/BlockButton/blockButton.types.ts +++ b/packages/jds/src/components/Button/BlockButton/blockButton.types.ts @@ -34,7 +34,7 @@ interface BlockButtonFeedbackProps { variant?: never; } -interface BlockButtonNativeProps { +export interface BlockButtonNativeProps { asChild?: false; disabled?: boolean; loading?: boolean; diff --git a/packages/vrt/backstop_data/bitmaps_reference/jds-vrt_components-alertdialog--loading_0_storybook-root_0_desktop.png b/packages/vrt/backstop_data/bitmaps_reference/jds-vrt_components-alertdialog--loading_0_storybook-root_0_desktop.png new file mode 100644 index 000000000..a953f1b39 Binary files /dev/null and b/packages/vrt/backstop_data/bitmaps_reference/jds-vrt_components-alertdialog--loading_0_storybook-root_0_desktop.png differ