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

feat(radio): radio with tailwind forms #46

Merged
merged 16 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore(radio): added RadioLabel
  • Loading branch information
anuraghazra committed Jan 27, 2021
commit d7198f14bb752a0f2d0a32453b0ef78fac725cfb
13 changes: 11 additions & 2 deletions src/radio/Radio.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import { cx } from "@renderlesskit/react";
import {
RadioProps,
RadioGroupProps,
Radio as ReakitRadio,
RadioGroup as ReakitRadioGroup,
RadioGroupProps,
RadioProps,
} from "reakit";
import { useTheme } from "../theme";
import { createContext } from "../utils";
Expand All @@ -17,6 +17,15 @@ const [RadioProvider, useRadioContext] = createContext({
errorMessage: "Radio must be used within RadioContextProvider",
});

export const RadioLabel: React.FC<{ className?: string }> = ({
children,
className,
}) => {
const theme = useTheme();

return <label className={cx(theme.radio.base, className)}>{children}</label>;
};

export const Radio = forwardRefWithAs<
Partial<RadioProps>,
HTMLInputElement,
Expand Down
53 changes: 35 additions & 18 deletions src/radio/stories/Radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Meta } from "@storybook/react";
import { Radio, RadioGroup } from "../Radio";
import { Radio, RadioGroup, RadioLabel } from "../Radio";
import { Button } from "../../";

export default {
Expand All @@ -12,12 +12,19 @@ export const Default = () => {
return (
<RadioGroup>
<div className="flex gap-5">
<Radio value="1">One</Radio>
<Radio value="2">Two</Radio>
<Radio value="3">Three</Radio>
<Radio value="4" disabled>
<RadioLabel>
<Radio value="1" /> One
</RadioLabel>
<RadioLabel>
<Radio value="2" /> Two
</RadioLabel>
<RadioLabel>
<Radio value="3" /> Three
</RadioLabel>
<RadioLabel>
<Radio value="4" disabled />
Disabled
</Radio>
</RadioLabel>
</div>
</RadioGroup>
);
Expand All @@ -36,12 +43,19 @@ export const Controlled = () => {
}}
>
<div className="flex gap-5">
<Radio value="1">One</Radio>
<Radio value="2">Two</Radio>
<Radio value="3">Three</Radio>
<Radio value="4" disabled>
<RadioLabel>
<Radio value="1" /> One
</RadioLabel>
<RadioLabel>
<Radio value="2" /> Two
</RadioLabel>
<RadioLabel>
<Radio value="3" /> Three
</RadioLabel>
<RadioLabel>
<Radio value="4" disabled />
Disabled
</Radio>
</RadioLabel>
</div>
</RadioGroup>
<Button onClick={() => setState("2")}>change</Button>
Expand All @@ -51,17 +65,20 @@ export const Controlled = () => {

export const States = () => {
return (
<RadioGroup state={"2"}>
<RadioGroup defaultState={"2"}>
<div className="flex flex-col gap-2">
<Radio value="1" className="hover:bg-gray-100 p-2 rounded-md">
<RadioLabel className="hover:bg-gray-100 p-2 rounded-md">
<Radio value="1" />
Unchecked
</Radio>
<Radio value="2" className="hover:bg-gray-100 p-2 rounded-md">
</RadioLabel>
<RadioLabel className="hover:bg-gray-100 p-2 rounded-md">
<Radio value="2" />
Checked
</Radio>
<Radio value="3" disabled className="hover:bg-gray-100 p-2 rounded-md">
</RadioLabel>
<RadioLabel className="hover:bg-gray-100 p-2 rounded-md">
<Radio value="3" disabled />
Disabled
</Radio>
</RadioLabel>
</div>
</RadioGroup>
);
Expand Down