Skip to content

Commit 7162f03

Browse files
committed
feat: ActionChip styled layer
1 parent 5fa37b0 commit 7162f03

File tree

5 files changed

+101
-29
lines changed

5 files changed

+101
-29
lines changed

docs/registry/ui/action-chip.tsx

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
import { Slot } from "@radix-ui/react-slot";
2-
import {
3-
actionChip,
4-
type ActionChipVariantProps,
5-
} from "@seed-design/recipe/actionChip";
6-
import clsx from "clsx";
1+
"use client";
2+
3+
import { ActionChip as SeedActionChip } from "@seed-design/react";
74
import * as React from "react";
85

96
import "@seed-design/stylesheet/actionChip.css";
107

11-
export interface ActionChipProps
12-
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
13-
ActionChipVariantProps {
8+
export interface ActionChipProps extends SeedActionChip.RootProps {
149
prefixIcon?: React.ReactNode;
1510

1611
suffixIcon?: React.ReactNode;
1712

1813
count?: number;
19-
20-
asChild?: boolean;
2114
}
2215

2316
export const ActionChip = React.forwardRef<HTMLButtonElement, ActionChipProps>(
@@ -30,35 +23,29 @@ export const ActionChip = React.forwardRef<HTMLButtonElement, ActionChipProps>(
3023
prefixIcon,
3124
suffixIcon,
3225
count,
33-
asChild = false,
3426
...otherProps
3527
},
3628
ref,
3729
) => {
38-
const Comp = asChild ? Slot : "button";
39-
const classNames = actionChip({ size, layout });
4030
return (
41-
<Comp
42-
ref={ref}
43-
className={clsx(classNames.root, className)}
44-
{...otherProps}
45-
>
31+
<SeedActionChip.Root ref={ref} {...otherProps}>
4632
{layout === "withText" ? (
4733
<>
48-
{prefixIcon && (
49-
<Slot className={classNames.prefixIcon}>{prefixIcon}</Slot>
50-
)}
51-
<span className={classNames.label}>{children}</span>
52-
{count && <span className={classNames.count}>{count}</span>}
53-
{suffixIcon && (
54-
<Slot className={classNames.suffixIcon}>{suffixIcon}</Slot>
55-
)}
34+
{prefixIcon && <SeedActionChip.PrefixIcon svg={prefixIcon} />}
35+
<SeedActionChip.Label>{children}</SeedActionChip.Label>
36+
{count && <SeedActionChip.Count>{count}</SeedActionChip.Count>}
37+
{suffixIcon && <SeedActionChip.SuffixIcon svg={suffixIcon} />}
5638
</>
5739
) : (
58-
<Slot className={classNames.icon}>{children}</Slot>
40+
<SeedActionChip.Icon svg={children} />
5941
)}
60-
</Comp>
42+
</SeedActionChip.Root>
6143
);
6244
},
6345
);
6446
ActionChip.displayName = "ActionChip";
47+
48+
/**
49+
* This file is generated snippet from the Seed Design.
50+
* You can extend the functionality from this snippet if needed.
51+
*/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export {
2+
ActionChipCount as Count,
3+
ActionChipIcon as Icon,
4+
ActionChipLabel as Label,
5+
ActionChipPrefixIcon as PrefixIcon,
6+
ActionChipRoot as Root,
7+
ActionChipSuffixIcon as SuffixIcon,
8+
type ActionChipCountProps as CountProps,
9+
type ActionChipIconProps as IconProps,
10+
type ActionChipLabelProps as LabelProps,
11+
type ActionChipPrefixIconProps as PrefixIconProps,
12+
type ActionChipRootProps as RootProps,
13+
type ActionChipSuffixIconProps as SuffixIconProps,
14+
} from "./ActionChip";
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive";
2+
import { actionChip, type ActionChipVariantProps } from "@seed-design/recipe/actionChip";
3+
import type * as React from "react";
4+
import { createStyleContext } from "../../utils/createStyleContext";
5+
import { Icon, type IconProps } from "../private/Icon";
6+
7+
const { withProvider, withContext } = createStyleContext(actionChip);
8+
9+
export interface ActionChipRootProps
10+
extends ActionChipVariantProps,
11+
PrimitiveProps,
12+
React.ButtonHTMLAttributes<HTMLButtonElement> {}
13+
14+
export const ActionChipRoot = withProvider<HTMLButtonElement, ActionChipRootProps>(
15+
Primitive.button,
16+
"root",
17+
);
18+
ActionChipRoot.displayName = "ActionChip";
19+
20+
export interface ActionChipLabelProps
21+
extends PrimitiveProps,
22+
React.HTMLAttributes<HTMLSpanElement> {}
23+
24+
export const ActionChipLabel = withContext<HTMLSpanElement, ActionChipLabelProps>(
25+
Primitive.span,
26+
"label",
27+
);
28+
29+
export interface ActionChipPrefixIconProps extends IconProps {}
30+
31+
export const ActionChipPrefixIcon = withContext<SVGSVGElement, ActionChipPrefixIconProps>(
32+
Icon,
33+
"prefixIcon",
34+
);
35+
36+
export interface ActionChipSuffixIconProps extends IconProps {}
37+
38+
export const ActionChipSuffixIcon = withContext<SVGSVGElement, ActionChipSuffixIconProps>(
39+
Icon,
40+
"suffixIcon",
41+
);
42+
43+
export interface ActionChipIconProps extends IconProps {}
44+
45+
export const ActionChipIcon = withContext<SVGSVGElement, ActionChipIconProps>(Icon, "icon");
46+
47+
export interface ActionChipCountProps
48+
extends PrimitiveProps,
49+
React.HTMLAttributes<HTMLSpanElement> {}
50+
51+
export const ActionChipCount = withContext<HTMLSpanElement, ActionChipCountProps>(
52+
Primitive.span,
53+
"count",
54+
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export {
2+
ActionChipCount,
3+
ActionChipIcon,
4+
ActionChipLabel,
5+
ActionChipPrefixIcon,
6+
ActionChipRoot,
7+
ActionChipSuffixIcon,
8+
type ActionChipCountProps,
9+
type ActionChipIconProps,
10+
type ActionChipLabelProps,
11+
type ActionChipPrefixIconProps,
12+
type ActionChipRootProps,
13+
type ActionChipSuffixIconProps,
14+
} from "./ActionChip";
15+
16+
export * as ActionChip from "./ActionChip.namespace";

packages/react/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./ActionButton";
2+
export * from "./ActionChip";
23
export * from "./Avatar";
34
export * from "./Badge";
45
export * from "./Box";

0 commit comments

Comments
 (0)