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
16 changes: 16 additions & 0 deletions docs/content/react/components/snackbar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ npx @seed-design/cli@latest add ui:snackbar
```
</ComponentExample>

### Strategy

Snackbar가 이미 표시 중일 때 새로운 Snackbar를 생성하면, 기본적으로 기존 Snackbar를 즉시 교체합니다 (`immediate`).
큐에 넣고 순차적으로 보여주려면 `strategy: "queued"`를 사용합니다.

`strategy`는 `SnackbarProvider`에서 기본값을 설정하거나, `create()` 호출 시 개별적으로 지정할 수 있습니다.

<ComponentExample name="react/snackbar/strategy">
```json doc-gen:file
{
"file": "examples/react/snackbar/strategy.tsx",
"codeblock": true
}
```
</ComponentExample>

### Avoid Overlap

`<SnackbarAvoidOverlap />` 컴포넌트를 사용하여 스낵바가 겹치지 않아야 하는 영역을 지정할 수 있습니다.
Expand Down
40 changes: 40 additions & 0 deletions docs/examples/react/snackbar/strategy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ActionButton } from "seed-design/ui/action-button";
import { Snackbar, SnackbarProvider, useSnackbarAdapter } from "seed-design/ui/snackbar";

function Component() {
const adapter = useSnackbarAdapter();

return (
<div style={{ display: "flex", gap: 8 }}>
<ActionButton
variant="neutralSolid"
onClick={() =>
adapter.create({
render: () => <Snackbar variant="positive" message="저장되었습니다" />,
})
}
>
Immediate (positive)
</ActionButton>
<ActionButton
variant="neutralSolid"
onClick={() =>
adapter.create({
strategy: "queued",
render: () => <Snackbar variant="critical" message="오류가 발생했습니다" />,
})
}
>
Queued (critical)
</ActionButton>
</div>
);
}

export default function SnackbarStrategy() {
return (
<SnackbarProvider>
<Component />
</SnackbarProvider>
);
}
22 changes: 22 additions & 0 deletions examples/stackflow-spa/src/activities/ActivityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,28 @@ const ActivityHome: StaticActivityComponentType<"ActivityHome"> = ({ params }) =
),
}),
},
{
title: "Snackbar (queued)",
onClick: () =>
snackbarAdapter.create({
strategy: "queued",
render: () => <Snackbar message="Queued Snackbar" />,
}),
},
{
// 기존 스낵바를 먼저 닫고 다음 tick에 새 스낵바를 띄우는 패턴.
// dismiss 상태 전이가 적용된 뒤에 create가 실행되므로
// 항상 새 스낵바부터 활성화되는 것을 보장한다.
title: "Snackbar (dismiss+setTimeout workaround)",
onClick: () => {
snackbarAdapter.dismiss();
setTimeout(() => {
snackbarAdapter.create({
render: () => <Snackbar message="Workaround Snackbar" />,
});
}, 0);
},
},
],
},
{
Expand Down
7 changes: 2 additions & 5 deletions packages/react-headless/snackbar/src/Snackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ export interface SnackbarRootProviderProps extends UseSnackbarProps {
children: React.ReactNode;
}

export const SnackbarRootProvider = ({
children,
pauseOnInteraction,
}: SnackbarRootProviderProps) => {
const api = useSnackbar({ pauseOnInteraction });
export const SnackbarRootProvider = ({ children, ...props }: SnackbarRootProviderProps) => {
const api = useSnackbar(props);
return <SnackbarProvider value={api}>{children}</SnackbarProvider>;
};

Expand Down
Loading
Loading