Skip to content

Commit

Permalink
feat: expose wrapper radio item level
Browse files Browse the repository at this point in the history
  • Loading branch information
rianmandala committed Nov 18, 2024
1 parent 878ab31 commit 0df8eac
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": ["packages/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.11.1",
"version": "0.11.2",
"command": {
"version": {
"message": "chore(release): publish %s"
Expand Down
2 changes: 1 addition & 1 deletion packages/apsara-icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@goto-company/icons",
"version": "0.11.1",
"version": "0.11.2",
"description": "Apsara icons",
"scripts": {
"build": "node scripts/build.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/apsara-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@goto-company/apsara",
"version": "0.11.1",
"version": "0.11.2",
"description": "A list of base components for apsara",
"author": "Praveen Yadav <[email protected]>",
"license": "Apache-2.0",
Expand Down
1 change: 0 additions & 1 deletion packages/apsara-ui/src/Radio/Radio.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const Label = styled("label")`
color: ${({ theme }) => theme?.radio?.label};
margin: ${({ dir }) => dir === "rtl" && "8px"};
font-size: 15px;
line-height: 1px;
user-select: none;
padding-left: 15px;
`;
Expand Down
55 changes: 37 additions & 18 deletions packages/apsara-ui/src/Radio/Radio.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React, { forwardRef } from "react";
import React, { forwardRef, ReactNode } from "react";
import { RadioGroup, StyledRadioItem, StyledIndicator, Label, Flex, StyledRadioButton } from "./Radio.styles";
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
import { generateRandomId } from "../helper";
import { PREFIX_CLS } from "./constants";

interface WrapperProps {
children: ReactNode;
}

export type RadioItem = {
label?: string;
value: string;
disabled?: boolean;
required?: boolean;
wrapper?: ({ children }: WrapperProps) => ReactNode;
};

type RadioButtonType = {
Expand Down Expand Up @@ -40,6 +45,10 @@ export type RadioProps = {
id?: string;
};

const defaultWrapper = ({ children }: WrapperProps) => {
return <>{children}</>;
};

const Radio = forwardRef<HTMLInputElement, RadioProps>(
({ defaultValue, value, items, onChange, required, orientation, dir, id = generateRandomId(), ...props }, ref) => {
return (
Expand All @@ -56,23 +65,33 @@ const Radio = forwardRef<HTMLInputElement, RadioProps>(
ref={ref}
>
{items &&
items.map((item, i) => (
<Flex dir={dir} key={item.value}>
<StyledRadioItem
value={item.value}
disabled={item.disabled}
required={item.required}
{...props.itemStyle}
id={`${id}${item.value}${i}`}
className={`${PREFIX_CLS} ${props.className ? props.className : ""}`}
>
<StyledIndicator />
</StyledRadioItem>
<Label dir={dir} htmlFor={`${id}${item.value}${i}`}>
{item.label}
</Label>
</Flex>
))}
items.map((item, i) => {
const { wrapper = defaultWrapper } = item;

return (
<>
{wrapper({
children: (
<Flex dir={dir} key={item.value}>
<StyledRadioItem
value={item.value}
disabled={item.disabled}
required={item.required}
{...props.itemStyle}
id={`${id}${item.value}${i}`}
className={`${PREFIX_CLS} ${props.className ? props.className : ""}`}
>
<StyledIndicator />
</StyledRadioItem>
<Label dir={dir} htmlFor={`${id}${item.value}${i}`}>
{item.label}
</Label>
</Flex>
),
})}
</>
);
})}
{!items && props.children}
</RadioGroup>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/apsara-ui/src/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export type TooltipProps = {
onOpenChange?: ((open: boolean) => void) | undefined;
delayDuration?: number;
avoidCollisions?: boolean;
} & HTMLAttributes<HTMLDivElement>;
} & HTMLAttributes<HTMLDivElement> &
RadixTooltip.TooltipContentProps;

export const PREFIX_CLS = "apsara-tooltip";
const Tooltip = ({
Expand Down

0 comments on commit 0df8eac

Please sign in to comment.