-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
248 additions
and
196 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ActionButton } from "@/registry/ui/action-button"; | ||
import { HelpBubbleTrigger } from "seed-design/ui/help-bubble"; | ||
|
||
export default function HelpBubblePreview() { | ||
return ( | ||
<HelpBubbleTrigger title="타이틀" description="설명을 추가할 수 있어요."> | ||
<ActionButton>열기</ActionButton> | ||
</HelpBubbleTrigger> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: Help Bubble | ||
--- | ||
|
||
<ComponentExample name="help-bubble-preview" /> | ||
|
||
### 설치 | ||
|
||
<Installation name="help-bubble" /> | ||
|
||
## 예제 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "help-bubble", | ||
"dependencies": [ | ||
"@seed-design/react-popover", | ||
"@radix-ui/react-slot" | ||
], | ||
"registries": [ | ||
{ | ||
"name": "help-bubble.tsx", | ||
"type": "ui", | ||
"content": "\"use client\";\n\nimport \"@seed-design/stylesheet/helpBubble.css\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { usePopover, type UsePopoverProps } from \"@seed-design/react-popover\";\nimport { helpBubble } from \"@seed-design/recipe/helpBubble\";\nimport { createContext, forwardRef, useContext } from \"react\";\nimport { mergeRefs } from \"../util/mergeRefs\";\n\ninterface HelpBubbleArrowProps extends React.ComponentPropsWithRef<\"svg\"> {\n width: number;\n\n height: number;\n\n tipRadius: number;\n}\n\nconst HelpBubbleArrow = forwardRef<SVGSVGElement, HelpBubbleArrowProps>(\n (props, ref) => {\n const { width, height, tipRadius, ...otherProps } = props;\n const pathData = `M0,0\n H${width}\n L${width / 2 + tipRadius},${height - tipRadius}\n Q${width / 2},${height} ${width / 2 - tipRadius},${height - tipRadius}\n Z`;\n\n return (\n <svg\n aria-hidden=\"true\"\n width={width}\n height={width}\n viewBox={`0 0 ${width} ${height > width ? height : width}`}\n ref={ref}\n {...otherProps}\n >\n <path stroke=\"none\" d={pathData} />\n </svg>\n );\n },\n);\n\nconst HelpBubbleContext = createContext<{\n api: ReturnType<typeof usePopover>;\n} | null>(null);\n\nexport interface HelpBubbleTriggerProps extends UsePopoverProps {\n title: string;\n\n description?: string;\n\n children?: React.ReactNode;\n}\n\nexport const HelpBubbleTrigger = forwardRef<\n HTMLButtonElement,\n HelpBubbleTriggerProps\n>((props, ref) => {\n const {\n open,\n defaultOpen,\n onOpenChange,\n placement = \"top\",\n gutter = 4,\n overflowPadding = 16,\n arrowPadding = 14,\n flip,\n slide,\n strategy,\n title,\n description,\n ...otherProps\n } = props;\n\n const api = usePopover({\n open,\n defaultOpen,\n onOpenChange,\n placement,\n gutter,\n overflowPadding,\n arrowPadding,\n flip,\n slide,\n strategy,\n });\n const classNames = helpBubble();\n\n const arrowRect = api.rects.arrow;\n\n return (\n <>\n <Slot\n ref={mergeRefs(ref, api.refs.trigger)}\n {...api.triggerProps}\n {...otherProps}\n />\n {api.open && (\n <div\n ref={api.refs.positioner}\n {...api.positionerProps}\n className={classNames.positioner}\n >\n <div className={classNames.content}>\n <div\n ref={api.refs.arrow}\n {...api.arrowProps}\n className={classNames.arrow}\n >\n <HelpBubbleArrow\n width={arrowRect?.width ?? 0}\n height={arrowRect?.height ?? 0}\n tipRadius={1}\n />\n </div>\n <span className={classNames.title}>{props.title}</span>\n {props.description && (\n <span className={classNames.description}>\n {props.description}\n </span>\n )}\n </div>\n </div>\n )}\n </>\n );\n});\n" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
"use client"; | ||
|
||
import "@seed-design/stylesheet/helpBubble.css"; | ||
|
||
import { Slot } from "@radix-ui/react-slot"; | ||
import { usePopover, type UsePopoverProps } from "@seed-design/react-popover"; | ||
import { helpBubble } from "@seed-design/recipe/helpBubble"; | ||
import { createContext, forwardRef, useContext } from "react"; | ||
import { mergeRefs } from "../util/mergeRefs"; | ||
|
||
interface HelpBubbleArrowProps extends React.ComponentPropsWithRef<"svg"> { | ||
width: number; | ||
|
||
height: number; | ||
|
||
tipRadius: number; | ||
} | ||
|
||
const HelpBubbleArrow = forwardRef<SVGSVGElement, HelpBubbleArrowProps>( | ||
(props, ref) => { | ||
const { width, height, tipRadius, ...otherProps } = props; | ||
const pathData = `M0,0 | ||
H${width} | ||
L${width / 2 + tipRadius},${height - tipRadius} | ||
Q${width / 2},${height} ${width / 2 - tipRadius},${height - tipRadius} | ||
Z`; | ||
|
||
return ( | ||
<svg | ||
aria-hidden="true" | ||
width={width} | ||
height={width} | ||
viewBox={`0 0 ${width} ${height > width ? height : width}`} | ||
ref={ref} | ||
{...otherProps} | ||
> | ||
<path stroke="none" d={pathData} /> | ||
</svg> | ||
); | ||
}, | ||
); | ||
|
||
const HelpBubbleContext = createContext<{ | ||
api: ReturnType<typeof usePopover>; | ||
} | null>(null); | ||
|
||
export interface HelpBubbleTriggerProps extends UsePopoverProps { | ||
title: string; | ||
|
||
description?: string; | ||
|
||
children?: React.ReactNode; | ||
} | ||
|
||
export const HelpBubbleTrigger = forwardRef< | ||
HTMLButtonElement, | ||
HelpBubbleTriggerProps | ||
>((props, ref) => { | ||
const { | ||
open, | ||
defaultOpen, | ||
onOpenChange, | ||
placement = "top", | ||
gutter = 4, | ||
overflowPadding = 16, | ||
arrowPadding = 14, | ||
flip, | ||
slide, | ||
strategy, | ||
title, | ||
description, | ||
...otherProps | ||
} = props; | ||
|
||
const api = usePopover({ | ||
open, | ||
defaultOpen, | ||
onOpenChange, | ||
placement, | ||
gutter, | ||
overflowPadding, | ||
arrowPadding, | ||
flip, | ||
slide, | ||
strategy, | ||
}); | ||
const classNames = helpBubble(); | ||
|
||
const arrowRect = api.rects.arrow; | ||
|
||
return ( | ||
<> | ||
<Slot | ||
ref={mergeRefs(ref, api.refs.trigger)} | ||
{...api.triggerProps} | ||
{...otherProps} | ||
/> | ||
{api.open && ( | ||
<div | ||
ref={api.refs.positioner} | ||
{...api.positionerProps} | ||
className={classNames.positioner} | ||
> | ||
<div className={classNames.content}> | ||
<div | ||
ref={api.refs.arrow} | ||
{...api.arrowProps} | ||
className={classNames.arrow} | ||
> | ||
<HelpBubbleArrow | ||
width={arrowRect?.width ?? 0} | ||
height={arrowRect?.height ?? 0} | ||
tipRadius={1} | ||
/> | ||
</div> | ||
<span className={classNames.title}>{props.title}</span> | ||
{props.description && ( | ||
<span className={classNames.description}> | ||
{props.description} | ||
</span> | ||
)} | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type * as React from "react"; | ||
|
||
export function mergeRefs<T>( | ||
...refs: React.ForwardedRef<T>[] | ||
): React.ForwardedRef<T> { | ||
if (refs.length === 1) { | ||
return refs[0]; | ||
} | ||
|
||
return (value: T | null) => { | ||
for (const ref of refs) { | ||
if (typeof ref === "function") { | ||
ref(value); | ||
} else if (ref != null) { | ||
ref.current = value; | ||
} | ||
} | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.