Skip to content

Commit 0df8eac

Browse files
committed
feat: expose wrapper radio item level
1 parent 878ab31 commit 0df8eac

File tree

6 files changed

+42
-23
lines changed

6 files changed

+42
-23
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"packages": ["packages/*"],
33
"npmClient": "yarn",
44
"useWorkspaces": true,
5-
"version": "0.11.1",
5+
"version": "0.11.2",
66
"command": {
77
"version": {
88
"message": "chore(release): publish %s"

packages/apsara-icons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@goto-company/icons",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
44
"description": "Apsara icons",
55
"scripts": {
66
"build": "node scripts/build.js",

packages/apsara-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@goto-company/apsara",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
44
"description": "A list of base components for apsara",
55
"author": "Praveen Yadav <[email protected]>",
66
"license": "Apache-2.0",

packages/apsara-ui/src/Radio/Radio.styles.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export const Label = styled("label")`
5353
color: ${({ theme }) => theme?.radio?.label};
5454
margin: ${({ dir }) => dir === "rtl" && "8px"};
5555
font-size: 15px;
56-
line-height: 1px;
5756
user-select: none;
5857
padding-left: 15px;
5958
`;

packages/apsara-ui/src/Radio/Radio.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import React, { forwardRef } from "react";
1+
import React, { forwardRef, ReactNode } from "react";
22
import { RadioGroup, StyledRadioItem, StyledIndicator, Label, Flex, StyledRadioButton } from "./Radio.styles";
33
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
44
import { generateRandomId } from "../helper";
55
import { PREFIX_CLS } from "./constants";
66

7+
interface WrapperProps {
8+
children: ReactNode;
9+
}
10+
711
export type RadioItem = {
812
label?: string;
913
value: string;
1014
disabled?: boolean;
1115
required?: boolean;
16+
wrapper?: ({ children }: WrapperProps) => ReactNode;
1217
};
1318

1419
type RadioButtonType = {
@@ -40,6 +45,10 @@ export type RadioProps = {
4045
id?: string;
4146
};
4247

48+
const defaultWrapper = ({ children }: WrapperProps) => {
49+
return <>{children}</>;
50+
};
51+
4352
const Radio = forwardRef<HTMLInputElement, RadioProps>(
4453
({ defaultValue, value, items, onChange, required, orientation, dir, id = generateRandomId(), ...props }, ref) => {
4554
return (
@@ -56,23 +65,33 @@ const Radio = forwardRef<HTMLInputElement, RadioProps>(
5665
ref={ref}
5766
>
5867
{items &&
59-
items.map((item, i) => (
60-
<Flex dir={dir} key={item.value}>
61-
<StyledRadioItem
62-
value={item.value}
63-
disabled={item.disabled}
64-
required={item.required}
65-
{...props.itemStyle}
66-
id={`${id}${item.value}${i}`}
67-
className={`${PREFIX_CLS} ${props.className ? props.className : ""}`}
68-
>
69-
<StyledIndicator />
70-
</StyledRadioItem>
71-
<Label dir={dir} htmlFor={`${id}${item.value}${i}`}>
72-
{item.label}
73-
</Label>
74-
</Flex>
75-
))}
68+
items.map((item, i) => {
69+
const { wrapper = defaultWrapper } = item;
70+
71+
return (
72+
<>
73+
{wrapper({
74+
children: (
75+
<Flex dir={dir} key={item.value}>
76+
<StyledRadioItem
77+
value={item.value}
78+
disabled={item.disabled}
79+
required={item.required}
80+
{...props.itemStyle}
81+
id={`${id}${item.value}${i}`}
82+
className={`${PREFIX_CLS} ${props.className ? props.className : ""}`}
83+
>
84+
<StyledIndicator />
85+
</StyledRadioItem>
86+
<Label dir={dir} htmlFor={`${id}${item.value}${i}`}>
87+
{item.label}
88+
</Label>
89+
</Flex>
90+
),
91+
})}
92+
</>
93+
);
94+
})}
7695
{!items && props.children}
7796
</RadioGroup>
7897
);

packages/apsara-ui/src/Tooltip/Tooltip.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export type TooltipProps = {
1414
onOpenChange?: ((open: boolean) => void) | undefined;
1515
delayDuration?: number;
1616
avoidCollisions?: boolean;
17-
} & HTMLAttributes<HTMLDivElement>;
17+
} & HTMLAttributes<HTMLDivElement> &
18+
RadixTooltip.TooltipContentProps;
1819

1920
export const PREFIX_CLS = "apsara-tooltip";
2021
const Tooltip = ({

0 commit comments

Comments
 (0)