|
1 | 1 | "use client"; |
2 | 2 |
|
3 | 3 | import "@seed-design/stylesheet/progressCircle.css"; |
| 4 | +// TODO: we have to ensure load order between reactionButton.css and progressCircle.css. should we bundle them together? |
4 | 5 | import "@seed-design/stylesheet/reactionButton.css"; |
5 | 6 |
|
6 | | -import { Slot } from "@radix-ui/react-slot"; |
7 | | -import { useToggle, type UseToggleProps } from "@seed-design/react-toggle"; |
8 | | -import { |
9 | | - reactionButton, |
10 | | - type ReactionButtonVariantProps, |
11 | | -} from "@seed-design/recipe/reactionButton"; |
12 | | -import clsx from "clsx"; |
| 7 | +import { ReactionButton as SeedReactionButton } from "@seed-design/react"; |
13 | 8 | import * as React from "react"; |
14 | | -import { ProgressCircle } from "./progress-circle"; |
15 | 9 |
|
16 | | -export interface ReactionButtonProps |
17 | | - extends React.ButtonHTMLAttributes<HTMLButtonElement>, |
18 | | - UseToggleProps, |
19 | | - ReactionButtonVariantProps { |
| 10 | +export interface ReactionButtonProps extends SeedReactionButton.RootProps { |
20 | 11 | prefixIcon?: React.ReactNode; |
21 | | - |
22 | | - count?: number; |
23 | | - |
24 | | - loading?: boolean; |
25 | | - |
26 | | - /** |
27 | | - * @default false |
28 | | - */ |
29 | | - asChild?: boolean; |
30 | 12 | } |
31 | 13 |
|
32 | 14 | /** |
33 | | - * @see https://v3.seed-design.io/docs/react/components/reaction-button |
| 15 | + * @see https://v3.seed-design.io/docs/react/components/toggle-button |
34 | 16 | */ |
35 | 17 | export const ReactionButton = React.forwardRef< |
36 | | - HTMLButtonElement, |
| 18 | + React.ElementRef<typeof SeedReactionButton.Root>, |
37 | 19 | ReactionButtonProps |
38 | 20 | >( |
39 | 21 | ( |
40 | | - { |
41 | | - className, |
42 | | - size = "small", |
43 | | - children, |
44 | | - prefixIcon, |
45 | | - count, |
46 | | - loading = false, |
47 | | - asChild = false, |
48 | | - ...otherProps |
49 | | - }, |
| 22 | + { className, loading = false, prefixIcon, children, ...otherProps }, |
50 | 23 | ref, |
51 | 24 | ) => { |
52 | | - const Comp = asChild ? Slot : "button"; |
53 | | - const { rootProps, stateProps, restProps } = useToggle(otherProps); |
54 | | - const classNames = reactionButton({ size }); |
55 | | - const dataProps = { |
56 | | - ...stateProps, |
57 | | - "data-loading": loading ? "" : undefined, |
58 | | - }; |
59 | | - |
60 | 25 | return ( |
61 | | - <Comp |
62 | | - ref={ref} |
63 | | - className={clsx(classNames.root, className)} |
64 | | - {...dataProps} |
65 | | - {...rootProps} |
66 | | - {...restProps} |
67 | | - > |
68 | | - {prefixIcon && ( |
69 | | - <Slot aria-hidden {...dataProps} className={classNames.prefixIcon}> |
70 | | - {prefixIcon} |
71 | | - </Slot> |
72 | | - )} |
73 | | - <span {...dataProps} className={classNames.label}> |
74 | | - {children} |
75 | | - </span> |
76 | | - <span {...dataProps} className={classNames.count}> |
77 | | - {count} |
78 | | - </span> |
79 | | - {loading ? ( |
80 | | - <ProgressCircle |
81 | | - {...dataProps} |
82 | | - className={classNames.progressCircle} |
83 | | - /> |
84 | | - ) : null} |
85 | | - </Comp> |
| 26 | + <SeedReactionButton.Root ref={ref} loading={loading} {...otherProps}> |
| 27 | + {prefixIcon && <SeedReactionButton.PrefixIcon svg={prefixIcon} />} |
| 28 | + <SeedReactionButton.Label>{children}</SeedReactionButton.Label> |
| 29 | + {loading ? <SeedReactionButton.ProgressCircle /> : null} |
| 30 | + </SeedReactionButton.Root> |
86 | 31 | ); |
87 | 32 | }, |
88 | 33 | ); |
89 | 34 | ReactionButton.displayName = "ReactionButton"; |
| 35 | + |
| 36 | +/** |
| 37 | + * This file is generated snippet from the Seed Design. |
| 38 | + * You can extend the functionality from this snippet if needed. |
| 39 | + */ |
0 commit comments