Skip to content

Commit

Permalink
fix: snackbar recipe not applied
Browse files Browse the repository at this point in the history
  • Loading branch information
malangcat committed Jan 9, 2025
1 parent 77b300a commit bbdcc71
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 38 deletions.
2 changes: 2 additions & 0 deletions docs/components/example/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
"skeleton-preview": "import { Flex } from \"seed-design/ui/layout\";\nimport { Skeleton } from \"seed-design/ui/skeleton\";\n\nexport default function SkeletonPreview() {\n return (\n <Flex gap=\"s4\" alignItems=\"center\">\n <Skeleton radius=\"full\" width=\"s12\" height=\"s12\" />\n <Flex flexDirection=\"column\" gap=\"s2\">\n <Skeleton radius=\"8\" height=\"s4\" width=\"250px\" />\n <Skeleton radius=\"8\" height=\"s4\" width=\"250px\" />\n </Flex>\n </Flex>\n );\n}",
"skeleton-radius": "import { Skeleton } from \"seed-design/ui/skeleton\";\nimport { Flex } from \"seed-design/ui/layout\";\n\nexport default function SkeletonRadius() {\n return (\n <Flex gap=\"s4\" alignItems=\"center\">\n <Skeleton radius=\"0\" width=\"s12\" height=\"s12\" />\n <Skeleton radius=\"8\" width=\"s12\" height=\"s12\" />\n <Skeleton radius=\"16\" width=\"s12\" height=\"s12\" />\n <Skeleton radius=\"full\" width=\"s12\" height=\"s12\" />\n </Flex>\n );\n}",
"snackbar-avoid-overlap": "import { Flex } from \"@/registry/ui/layout\";\nimport { ActionButton } from \"seed-design/ui/action-button\";\nimport {\n Snackbar,\n SnackbarAvoidOverlap,\n SnackbarProvider,\n useSnackbarAdapter,\n} from \"seed-design/ui/snackbar\";\n\nfunction Component() {\n const adapter = useSnackbarAdapter();\n\n return (\n <Flex direction=\"column\" gap=\"s4\">\n <ActionButton\n onClick={() =>\n adapter.create({\n timeout: 5000,\n onClose: () => {},\n render: () => <Snackbar message=\"알림 메세지\" actionLabel=\"확인\" onAction={() => {}} />,\n })\n }\n >\n 실행\n </ActionButton>\n <SnackbarAvoidOverlap>\n <Flex\n width=\"full\"\n height=\"s16\"\n background=\"bg.dangerWeak\"\n justifyContent=\"center\"\n alignItems=\"center\"\n >\n Snackbar가 이 영역과 겹치지 않게 조정됩니다. 스크롤은 무시합니다.\n </Flex>\n </SnackbarAvoidOverlap>\n </Flex>\n );\n}\n\nexport default function SnackbarPreview() {\n return (\n <SnackbarProvider>\n <Component />\n </SnackbarProvider>\n );\n}",
"snackbar-danger": "import { ActionButton } from \"seed-design/ui/action-button\";\nimport { Snackbar, SnackbarProvider, useSnackbarAdapter } from \"seed-design/ui/snackbar\";\n\nfunction Component() {\n const adapter = useSnackbarAdapter();\n\n return (\n <ActionButton\n onClick={() =>\n adapter.create({\n timeout: 5000,\n onClose: () => {},\n render: () => (\n <Snackbar\n variant=\"danger\"\n message=\"알림 메세지\"\n actionLabel=\"확인\"\n onAction={() => {}}\n />\n ),\n })\n }\n >\n 실행\n </ActionButton>\n );\n}\n\nexport default function SnackbarNegative() {\n return (\n <SnackbarProvider>\n <Component />\n </SnackbarProvider>\n );\n}",
"snackbar-positive": "import { ActionButton } from \"seed-design/ui/action-button\";\nimport { Snackbar, SnackbarProvider, useSnackbarAdapter } from \"seed-design/ui/snackbar\";\n\nfunction Component() {\n const adapter = useSnackbarAdapter();\n\n return (\n <ActionButton\n onClick={() =>\n adapter.create({\n timeout: 5000,\n onClose: () => {},\n render: () => (\n <Snackbar\n variant=\"positive\"\n message=\"알림 메세지\"\n actionLabel=\"확인\"\n onAction={() => {}}\n />\n ),\n })\n }\n >\n 실행\n </ActionButton>\n );\n}\n\nexport default function SnackbarPositive() {\n return (\n <SnackbarProvider>\n <Component />\n </SnackbarProvider>\n );\n}",
"snackbar-preview": "import { ActionButton } from \"seed-design/ui/action-button\";\nimport { Snackbar, SnackbarProvider, useSnackbarAdapter } from \"seed-design/ui/snackbar\";\n\nfunction Component() {\n const adapter = useSnackbarAdapter();\n\n return (\n <ActionButton\n onClick={() =>\n adapter.create({\n timeout: 5000,\n onClose: () => {},\n render: () => <Snackbar message=\"알림 메세지\" actionLabel=\"확인\" onAction={() => {}} />,\n })\n }\n >\n 실행\n </ActionButton>\n );\n}\n\nexport default function SnackbarPreview() {\n return (\n <SnackbarProvider>\n <Component />\n </SnackbarProvider>\n );\n}",
"switch-disabled": "import { Switch } from \"seed-design/ui/switch\";\n\nexport default function SwitchDisabled() {\n return (\n <div style={{ display: \"flex\", flexDirection: \"column\", gap: 10 }}>\n <Switch disabled />\n <Switch checked disabled />\n </div>\n );\n}",
"switch-medium": "import { useState } from \"react\";\nimport { Switch } from \"seed-design/ui/switch\";\n\nexport default function SwitchMedium() {\n const [isChecked, setIsChecked] = useState(false);\n\n return <Switch size=\"medium\" checked={isChecked} onCheckedChange={setIsChecked} />;\n}",
Expand Down
37 changes: 37 additions & 0 deletions docs/components/example/snackbar-danger.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";

import { ActionButton } from "seed-design/ui/action-button";
import { Snackbar, SnackbarProvider, useSnackbarAdapter } from "seed-design/ui/snackbar";

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

return (
<ActionButton
onClick={() =>
adapter.create({
timeout: 50000000,
onClose: () => {},
render: () => (
<Snackbar
variant="danger"
message="알림 메세지"
actionLabel="확인"
onAction={() => {}}
/>
),
})
}
>
실행
</ActionButton>
);
}

export default function SnackbarNegative() {
return (
<SnackbarProvider>
<Component />
</SnackbarProvider>
);
}
37 changes: 37 additions & 0 deletions docs/components/example/snackbar-positive.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";

import { ActionButton } from "seed-design/ui/action-button";
import { Snackbar, SnackbarProvider, useSnackbarAdapter } from "seed-design/ui/snackbar";

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

return (
<ActionButton
onClick={() =>
adapter.create({
timeout: 5000,
onClose: () => {},
render: () => (
<Snackbar
variant="positive"
message="알림 메세지"
actionLabel="확인"
onAction={() => {}}
/>
),
})
}
>
실행
</ActionButton>
);
}

export default function SnackbarPositive() {
return (
<SnackbarProvider>
<Component />
</SnackbarProvider>
);
}
8 changes: 8 additions & 0 deletions docs/content/docs/react/components/snackbar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ title: Snackbar

## 예제

### Positive

<ComponentExample name="snackbar-positive" />

### Danger

<ComponentExample name="snackbar-danger" />

### Avoid Overlap

`<SnackbarAvoidOverlap />` 컴포넌트를 사용하여 스낵바가 겹치지 않아야 하는 영역을 지정할 수 있습니다.
Expand Down
1 change: 1 addition & 0 deletions docs/registry/ui/snackbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import "@seed-design/stylesheet/snackbar.css";
import "@seed-design/stylesheet/snackbarRegion.css";

import {
Snackbar as SeedSnackbar,
Expand Down
3 changes: 2 additions & 1 deletion packages/qvism-preset/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import screen from "./recipes/screen";
import segmentedControl from "./recipes/segmented-control";
import { selectBox, selectBoxGroup } from "./recipes/select-box";
import skeleton from "./recipes/skeleton";
import snackbar from "./recipes/snackbar";
import { snackbar, snackbarRegion } from "./recipes/snackbar";
import switchRecipe from "./recipes/switch";
import tab from "./recipes/tab";
import tabs from "./recipes/tabs";
Expand Down Expand Up @@ -70,6 +70,7 @@ const recipes = {
chipTabs,
skeleton,
snackbar,
snackbarRegion,
text,
textButton,
textField,
Expand Down
20 changes: 14 additions & 6 deletions packages/qvism-preset/src/recipes/snackbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { enterAnimation, exitAnimation } from "../utils/animation";

const MAX_Z_INDEX = 2147483647;

const snackbar = defineRecipe({
name: "snackbar",
slots: ["region", "root", "message", "prefixIcon", "actionButton"],
export const snackbarRegion = defineRecipe({
name: "snackbarRegion",
slots: ["root"],
base: {
region: {
root: {
zIndex: MAX_Z_INDEX,
display: "flex",
flexDirection: "column",
Expand All @@ -23,6 +23,15 @@ const snackbar = defineRecipe({
transitionDuration: vars.base.enabled.region.offsetDuration,
transitionTimingFunction: vars.base.enabled.region.offsetTimingFunction,
},
},
variants: {},
defaultVariants: {},
});

export const snackbar = defineRecipe({
name: "snackbar",
slots: ["root", "message", "prefixIcon", "actionButton"],
base: {
root: {
boxSizing: "border-box",
display: "flex",
Expand All @@ -36,6 +45,7 @@ const snackbar = defineRecipe({
paddingInline: vars.base.enabled.root.paddingX,
paddingBlock: vars.base.enabled.root.paddingY,
minHeight: vars.base.enabled.root.minHeight,
gap: vars.base.enabled.root.gap,

...enterAnimation({
timingFunction: vars.base.enabled.root.enterTimingFunction,
Expand Down Expand Up @@ -124,5 +134,3 @@ const snackbar = defineRecipe({
variant: "default",
},
});

export default snackbar;
19 changes: 7 additions & 12 deletions packages/react/src/components/Snackbar/Snackbar.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive";
import { Snackbar as SnackbarPrimitive } from "@seed-design/react-snackbar";
import { snackbar, type SnackbarVariantProps } from "@seed-design/recipe/snackbar";
import { snackbarRegion } from "@seed-design/recipe/snackbarRegion";
import { visuallyHidden } from "@seed-design/recipe/visuallyHidden";
import clsx from "clsx";
import { forwardRef, useMemo } from "react";
import { createStyleContext } from "../../utils/createStyleContext";
import { Icon, type IconProps } from "../private/Icon";

const { withRootProvider, withContext } = createStyleContext(snackbar);
const { withProvider: withRegionProvider } = createStyleContext(snackbarRegion);
const { withProvider, withContext } = createStyleContext(snackbar);

////////////////////////////////////////////////////////////////////////////////////

export interface SnackbarRootProviderProps extends SnackbarPrimitive.RootProviderProps {}

export const SnackbarRootProvider = withRootProvider<HTMLDivElement, SnackbarRootProviderProps>(
SnackbarPrimitive.RootProvider,
{
defaultProps: {
pauseOnInteraction: false,
},
},
);
export const SnackbarRootProvider = SnackbarPrimitive.RootProvider;

////////////////////////////////////////////////////////////////////////////////////

export interface SnackbarRegionProps extends SnackbarVariantProps, SnackbarPrimitive.RegionProps {}

export const SnackbarRegion = withContext<HTMLDivElement, SnackbarRegionProps>(
export const SnackbarRegion = withRegionProvider<HTMLDivElement, SnackbarRegionProps>(
SnackbarPrimitive.Region,
"region",
"root",
);

////////////////////////////////////////////////////////////////////////////////////

export interface SnackbarRootProps extends SnackbarVariantProps, SnackbarPrimitive.RootProps {}

export const SnackbarRoot = withContext<HTMLDivElement, SnackbarRootProps>(
export const SnackbarRoot = withProvider<HTMLDivElement, SnackbarRootProps>(
SnackbarPrimitive.Root,
"root",
);
Expand Down
2 changes: 1 addition & 1 deletion packages/recipe/lib/snackbar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare type SnackbarVariantMap = {

export declare type SnackbarVariantProps = Partial<SnackbarVariant>;

export declare type SnackbarSlotName = "region" | "root" | "message" | "prefixIcon" | "actionButton";
export declare type SnackbarSlotName = "root" | "message" | "prefixIcon" | "actionButton";

export declare const snackbarVariantMap: SnackbarVariantMap;

Expand Down
4 changes: 0 additions & 4 deletions packages/recipe/lib/snackbar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { mergeVariants } from "./mergeVariants.mjs";
import { splitVariantProps } from "./splitVariantProps.mjs";

const snackbarSlotNames = [
[
"region",
"snackbar__region"
],
[
"root",
"snackbar__root"
Expand Down
21 changes: 21 additions & 0 deletions packages/recipe/lib/snackbarRegion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare interface SnackbarRegionVariant {

}

declare type SnackbarRegionVariantMap = {
[key in keyof SnackbarRegionVariant]: Array<SnackbarRegionVariant[key]>;
};

export declare type SnackbarRegionVariantProps = Partial<SnackbarRegionVariant>;

export declare type SnackbarRegionSlotName = "root";

export declare const snackbarRegionVariantMap: SnackbarRegionVariantMap;

export declare const snackbarRegion: ((
props?: SnackbarRegionVariantProps,
) => Record<SnackbarRegionSlotName, string>) & {
splitVariantProps: <T extends SnackbarRegionVariantProps>(
props: T,
) => [SnackbarRegionVariantProps, Omit<T, keyof SnackbarRegionVariantProps>];
}
31 changes: 31 additions & 0 deletions packages/recipe/lib/snackbarRegion.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createClassName } from "./className.mjs";
import { mergeVariants } from "./mergeVariants.mjs";
import { splitVariantProps } from "./splitVariantProps.mjs";

const snackbarRegionSlotNames = [
[
"root",
"snackbarRegion__root"
]
];

const defaultVariant = {};

const compoundVariants = [];

export const snackbarRegionVariantMap = {};

export const snackbarRegionVariantKeys = Object.keys(snackbarRegionVariantMap);

export function snackbarRegion(props) {
return Object.fromEntries(
snackbarRegionSlotNames.map(([slot, className]) => {
return [
slot,
createClassName(className, mergeVariants(defaultVariant, props), compoundVariants),
];
}),
);
}

Object.assign(snackbarRegion, { splitVariantProps: (props) => splitVariantProps(props, snackbarRegionVariantMap) });
1 change: 1 addition & 0 deletions packages/rootage/components/snackbar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
data:
base:
enabled:
# TODO: we might split region out to a separate component
region:
paddingX: $unit.s2
paddingY: $unit.s2
Expand Down
15 changes: 1 addition & 14 deletions packages/stylesheet/snackbar.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
.snackbar__region {
z-index: 2147483647;
display: flex;
flex-direction: column;
align-items: center;
left: calc(env(safe-area-inset-left, 0px));
right: calc(env(safe-area-inset-right, 0px));
bottom: calc(env(safe-area-inset-bottom, 0px) + var(--snackbar-region-offset, 0px));
padding-inline: var(--seed-v3-unit-s2);
padding-block: var(--seed-v3-unit-s2);
transition-property: bottom;
transition-duration: var(--seed-v3-duration-s4);
transition-timing-function: var(--seed-v3-timing-function-easing);
}
.snackbar__root {
box-sizing: border-box;
display: flex;
Expand All @@ -23,6 +9,7 @@
padding-inline: var(--seed-v3-unit-s4);
padding-block: var(--seed-v3-unit-s2_5);
min-height: 44px;
gap: var(--seed-v3-unit-s2);
animation: seed-enter;
animation-timing-function: var(--seed-v3-timing-function-enter);
animation-duration: var(--seed-v3-duration-s4);
Expand Down
14 changes: 14 additions & 0 deletions packages/stylesheet/snackbarRegion.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.snackbarRegion__root {
z-index: 2147483647;
display: flex;
flex-direction: column;
align-items: center;
left: calc(env(safe-area-inset-left, 0px));
right: calc(env(safe-area-inset-right, 0px));
bottom: calc(env(safe-area-inset-bottom, 0px) + var(--snackbar-region-offset, 0px));
padding-inline: var(--seed-v3-unit-s2);
padding-block: var(--seed-v3-unit-s2);
transition-property: bottom;
transition-duration: var(--seed-v3-duration-s4);
transition-timing-function: var(--seed-v3-timing-function-easing)
}

0 comments on commit bbdcc71

Please sign in to comment.