Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(docs): radio-group dx #4064

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/docs/content/components/radio-group/controlled.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {RadioGroup, Radio} from "@nextui-org/react";

export default function App() {
const [selected, setSelected] = React.useState("london");

return (
<div className="flex flex-col gap-3">
<RadioGroup label="Select your favorite city" value={selected} onValueChange={setSelected}>
<Radio value="buenos-aires">Buenos Aires</Radio>
<Radio value="sydney">Sydney</Radio>
<Radio value="san-francisco">San Francisco</Radio>
<Radio value="london">London</Radio>
<Radio value="tokyo">Tokyo</Radio>
</RadioGroup>
<p className="text-default-500 text-small">Selected: {selected}</p>
</div>
);
}
23 changes: 1 addition & 22 deletions apps/docs/content/components/radio-group/controlled.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
const App = `import {RadioGroup, Radio} from "@nextui-org/react";

export default function App() {
const [selected, setSelected] = React.useState("london");

return (
<div className="flex flex-col gap-3">
<RadioGroup
label="Select your favorite city"
value={selected}
onValueChange={setSelected}
>
<Radio value="buenos-aires">Buenos Aires</Radio>
<Radio value="sydney">Sydney</Radio>
<Radio value="san-francisco">San Francisco</Radio>
<Radio value="london">London</Radio>
<Radio value="tokyo">Tokyo</Radio>
</RadioGroup>
<p className="text-default-500 text-small">Selected: {selected}</p>
</div>
);
}`;
import App from "./controlled.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
55 changes: 55 additions & 0 deletions apps/docs/content/components/radio-group/custom-impl.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {RadioGroup, useRadio, VisuallyHidden, cn} from "@nextui-org/react";

export const CustomRadio = (props) => {
const {
Component,
children,
description,
getBaseProps,
getWrapperProps,
getInputProps,
getLabelProps,
getLabelWrapperProps,
getControlProps,
} = useRadio(props);

return (
<Component
{...getBaseProps()}
className={cn(
"group inline-flex items-center hover:opacity-70 active:opacity-50 justify-between flex-row-reverse tap-highlight-transparent",
"max-w-[300px] cursor-pointer border-2 border-default rounded-lg gap-4 p-4",
"data-[selected=true]:border-primary",
)}
>
<VisuallyHidden>
<input {...getInputProps()} />
</VisuallyHidden>
<span {...getWrapperProps()}>
<span {...getControlProps()} />
</span>
<div {...getLabelWrapperProps()}>
{children && <span {...getLabelProps()}>{children}</span>}
{description && (
<span className="text-small text-foreground opacity-70">{description}</span>
)}
</div>
</Component>
);
};

export default function App() {
return (
<RadioGroup label="Plans">
<CustomRadio description="Up to 20 items" value="free">
Free
</CustomRadio>
<CustomRadio description="Unlimited items. $10 per month." value="pro">
Pro
</CustomRadio>
<CustomRadio description="24/7 support. Contact us for pricing." value="enterprise">
Enterprise
</CustomRadio>
</RadioGroup>
);
}
56 changes: 56 additions & 0 deletions apps/docs/content/components/radio-group/custom-impl.raw.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from "react";
import {RadioGroup, useRadio, VisuallyHidden, RadioProps, cn} from "@nextui-org/react";

export const CustomRadio = (props: RadioProps) => {
const {
Component,
children,
description,
getBaseProps,
getWrapperProps,
getInputProps,
getLabelProps,
getLabelWrapperProps,
getControlProps,
} = useRadio(props);

return (
<Component
{...getBaseProps()}
className={cn(
"group inline-flex items-center justify-between hover:bg-content2 flex-row-reverse",
"max-w-[300px] cursor-pointer border-2 border-default rounded-lg gap-4 p-4",
"data-[selected=true]:border-primary",
)}
>
<VisuallyHidden>
<input {...getInputProps()} />
</VisuallyHidden>
<span {...getWrapperProps()}>
<span {...getControlProps()} />
</span>
<div {...getLabelWrapperProps()}>
{children && <span {...getLabelProps()}>{children}</span>}
{description && (
<span className="text-small text-foreground opacity-70">{description}</span>
)}
</div>
</Component>
);
};

export default function App() {
return (
<RadioGroup label="Plans">
<CustomRadio description="Up to 20 items" value="free">
Free
</CustomRadio>
<CustomRadio description="Unlimited items. $10 per month." value="pro">
Pro
</CustomRadio>
<CustomRadio description="24/7 support. Contact us for pricing." value="enterprise">
Enterprise
</CustomRadio>
</RadioGroup>
);
}
121 changes: 2 additions & 119 deletions apps/docs/content/components/radio-group/custom-impl.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,5 @@
const App = `import {RadioGroup, Radio, useRadio, VisuallyHidden, cn} from "@nextui-org/react";

export const CustomRadio = (props) => {
const {
Component,
children,
isSelected,
description,
getBaseProps,
getWrapperProps,
getInputProps,
getLabelProps,
getLabelWrapperProps,
getControlProps,
} = useRadio(props);

return (
<Component
{...getBaseProps()}
className={cn(
"group inline-flex items-center hover:opacity-70 active:opacity-50 justify-between flex-row-reverse tap-highlight-transparent",
"max-w-[300px] cursor-pointer border-2 border-default rounded-lg gap-4 p-4",
"data-[selected=true]:border-primary",
)}
>
<VisuallyHidden>
<input {...getInputProps()} />
</VisuallyHidden>
<span {...getWrapperProps()}>
<span {...getControlProps()} />
</span>
<div {...getLabelWrapperProps()}>
{children && <span {...getLabelProps()}>{children}</span>}
{description && (
<span className="text-small text-foreground opacity-70">{description}</span>
)}
</div>
</Component>
);
};

export default function App() {
return (
<RadioGroup label="Plans">
<CustomRadio description="Up to 20 items" value="free">
Free
</CustomRadio>
<CustomRadio description="Unlimited items. $10 per month." value="pro">
Pro
</CustomRadio>
<CustomRadio
description="24/7 support. Contact us for pricing."
value="enterprise"
>
Enterprise
</CustomRadio>
</RadioGroup>
);
}`;

const AppTs = `import {RadioGroup, Radio, useRadio, VisuallyHidden, RadioProps, cn} from "@nextui-org/react";

export const CustomRadio = (props: RadioProps) => {
const {
Component,
children,
isSelected,
description,
getBaseProps,
getWrapperProps,
getInputProps,
getLabelProps,
getLabelWrapperProps,
getControlProps,
} = useRadio(props);

return (
<Component
{...getBaseProps()}
className={cn(
"group inline-flex items-center justify-between hover:bg-content2 flex-row-reverse",
"max-w-[300px] cursor-pointer border-2 border-default rounded-lg gap-4 p-4",
"data-[selected=true]:border-primary",
)}
>
<VisuallyHidden>
<input {...getInputProps()} />
</VisuallyHidden>
<span {...getWrapperProps()}>
<span {...getControlProps()} />
</span>
<div {...getLabelWrapperProps()}>
{children && <span {...getLabelProps()}>{children}</span>}
{description && (
<span className="text-small text-foreground opacity-70">{description}</span>
)}
</div>
</Component>
);
};

export default function App() {
return (
<RadioGroup label="Plans">
<CustomRadio description="Up to 20 items" value="free">
Free
</CustomRadio>
<CustomRadio description="Unlimited items. $10 per month." value="pro">
Pro
</CustomRadio>
<CustomRadio
description="24/7 support. Contact us for pricing."
value="enterprise"
>
Enterprise
</CustomRadio>
</RadioGroup>
);
}`;
import App from "./custom-impl.raw.jsx?raw";
import AppTs from "./custom-impl.raw.tsx?raw";

const react = {
"/App.jsx": App,
Expand Down
36 changes: 36 additions & 0 deletions apps/docs/content/components/radio-group/custom-styles.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {RadioGroup, Radio, cn} from "@nextui-org/react";

export const CustomRadio = (props) => {
const {children, ...otherProps} = props;

return (
<Radio
{...otherProps}
classNames={{
base: cn(
"inline-flex m-0 bg-content1 hover:bg-content2 items-center justify-between",
"flex-row-reverse max-w-[300px] cursor-pointer rounded-lg gap-4 p-4 border-2 border-transparent",
"data-[selected=true]:border-primary",
),
}}
>
{children}
</Radio>
);
};

export default function App() {
return (
<RadioGroup description="Selected plan can be changed at any time." label="Plans">
<CustomRadio description="Up to 20 items" value="free">
Free
</CustomRadio>
<CustomRadio description="Unlimited items. $10 per month." value="pro">
Pro
</CustomRadio>
<CustomRadio description="24/7 support. Contact us for pricing." value="enterprise">
Enterprise
</CustomRadio>
</RadioGroup>
);
}
40 changes: 1 addition & 39 deletions apps/docs/content/components/radio-group/custom-styles.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
const App = `import {RadioGroup, Radio, cn} from "@nextui-org/react";

export const CustomRadio = (props) => {
const {children, ...otherProps} = props;

return (
<Radio
{...otherProps}
classNames={{
base: cn(
"inline-flex m-0 bg-content1 hover:bg-content2 items-center justify-between",
"flex-row-reverse max-w-[300px] cursor-pointer rounded-lg gap-4 p-4 border-2 border-transparent",
"data-[selected=true]:border-primary"
),
}}
>
{children}
</Radio>
);
};

export default function App() {
return (
<RadioGroup label="Plans" description="Selected plan can be changed at any time.">
<CustomRadio description="Up to 20 items" value="free">
Free
</CustomRadio>
<CustomRadio description="Unlimited items. $10 per month." value="pro">
Pro
</CustomRadio>
<CustomRadio
description="24/7 support. Contact us for pricing."
value="enterprise"
>
Enterprise
</CustomRadio>
</RadioGroup>
);
}`;
import App from "./custom-styles.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
13 changes: 13 additions & 0 deletions apps/docs/content/components/radio-group/default-value.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {RadioGroup, Radio} from "@nextui-org/react";

export default function App() {
return (
<RadioGroup color="secondary" defaultValue="london" label="Select your favorite city">
<Radio value="buenos-aires">Buenos Aires</Radio>
<Radio value="sydney">Sydney</Radio>
<Radio value="san-francisco">San Francisco</Radio>
<Radio value="london">London</Radio>
<Radio value="tokyo">Tokyo</Radio>
</RadioGroup>
);
}
Loading