-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e8cfc9
commit 66a292d
Showing
7 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { composeStories } from "@storybook/react"; | ||
import { render } from "@testing-library/react"; | ||
|
||
import * as stories from "./Radio.stories"; | ||
|
||
const { Default } = composeStories(stories); | ||
|
||
describe("Radio", () => { | ||
it("renders Default component story without breaking", () => { | ||
const { container } = render(<Default />); | ||
expect(container).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { pluralizeKeys } from "@axelarjs/utils"; | ||
|
||
import type { Meta, StoryFn } from "@storybook/react"; | ||
|
||
import { configurePlayground } from "../../StoryPlayground"; | ||
import { COLOR_VARIANTS, SIZE_VARIANTS } from "../../theme"; | ||
import { Radio } from "./Radio"; | ||
|
||
export default { | ||
title: "components/Radio", | ||
component: Radio, | ||
docs: { | ||
description: { | ||
component: "Radio, Radio, does whatever a Radio do.", | ||
}, | ||
}, | ||
} as Meta<typeof Radio>; | ||
|
||
const Template: StoryFn<typeof Radio> = (args) => { | ||
return <Radio {...args} />; | ||
}; | ||
|
||
export const Default = Template.bind({}); | ||
|
||
Default.args = {}; | ||
|
||
const { InputSizes, Variants } = pluralizeKeys( | ||
configurePlayground( | ||
Radio, | ||
{ | ||
inputSize: { | ||
values: SIZE_VARIANTS, | ||
noChildren: true, | ||
}, | ||
variant: { | ||
values: COLOR_VARIANTS, | ||
noChildren: true, | ||
}, | ||
}, | ||
{ | ||
defaultChecked: true, | ||
} | ||
) | ||
); | ||
|
||
export { InputSizes, Variants }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { forwardRef } from "react"; | ||
|
||
import { cva, VariantProps } from "class-variance-authority"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
const inputVariance = cva("radio", { | ||
variants: { | ||
variant: { | ||
primary: "radio-primary", | ||
secondary: "radio-secondary", | ||
accent: "radio-accent", | ||
success: "radio-success", | ||
warning: "radio-warning", | ||
error: "radio-error", | ||
info: "radio-info", | ||
}, | ||
inputSize: { | ||
xs: "radio-xs", | ||
sm: "radio-sm", | ||
md: "radio-md", | ||
lg: "radio-lg", | ||
}, | ||
}, | ||
}); | ||
|
||
type VProps = VariantProps<typeof inputVariance>; | ||
|
||
type InputElement = Omit<JSX.IntrinsicElements["input"], "type" | "color">; | ||
|
||
export interface RadioProps extends InputElement, VProps { | ||
type?: never; | ||
placeholder?: never; | ||
} | ||
|
||
/** | ||
* A radio input component | ||
*/ | ||
export const Radio = forwardRef<HTMLInputElement, RadioProps>( | ||
({ variant, inputSize, className, ...props }, ref) => ( | ||
<input | ||
ref={ref} | ||
type="radio" | ||
className={twMerge( | ||
inputVariance({ | ||
variant, | ||
inputSize, | ||
}), | ||
className | ||
)} | ||
{...props} | ||
/> | ||
) | ||
); | ||
|
||
Radio.displayName = "Radio"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./Radio"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters