-
Notifications
You must be signed in to change notification settings - Fork 10
Adds Radio and RadioGroup [v1] #85
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a0b5284
feat: Adds radio Button and Radio Group
Raalzz 7cb4101
Merge branch 'main' of https://github.com/antstackio/hover-design int…
Raalzz 347de02
refactor: Refactored radio themes
Raalzz f6a13b5
feat: Updated Docs
Raalzz 09e2f90
refactor: Resolved git comments
Raalzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,193 @@ | ||
| # Radio | ||
|
|
||
| ### Quick start | ||
|
|
||
| Here's a quick start guide to get started with the Radio component, Radios are for selecting one option from many. | ||
|
|
||
| ### Importing Component | ||
|
|
||
| import "@hover-design/react/dist/style.css"; | ||
| import { Radio, RadioGroup, Card } from "@hover-design/react"; | ||
| import { | ||
| RadioExample, | ||
| RadioGroupExample | ||
| } from "@site/src/components/examples/RadioExample"; | ||
|
|
||
| export const RadioContainer = ({ children }) => ( | ||
| <Card variant="shadow">{children}</Card> | ||
| ); | ||
|
|
||
| ```jsx | ||
| import { Radio, RadioGroup } from "@hover-design/react"; | ||
| ``` | ||
|
|
||
| ### Code Snippets and Examples | ||
|
|
||
| ##### Simple Radio | ||
|
|
||
| ```jsx | ||
| import { Radio, RadioGroup } from "@hover-design/react"; | ||
|
|
||
| const Demo = () => { | ||
| const [radioVal, setRadioVal] = useState("apple"); | ||
|
|
||
| return ( | ||
| <div> | ||
| <label> | ||
| <Radio | ||
| name="fruits" | ||
| value="apple" | ||
| checked={radioVal == "apple"} | ||
| onChange={(e) => setRadioVal(e.target.value)} | ||
| ></Radio> | ||
| Apple | ||
| </label> | ||
| <label> | ||
| <Radio | ||
| name="fruits" | ||
| value="bannana" | ||
| checked={radioVal == "bannana"} | ||
| onChange={(e) => setRadioVal(e.target.value)} | ||
| ></Radio> | ||
| Bannana | ||
| </label> | ||
| <label> | ||
| <Radio | ||
| name="fruits" | ||
| value="orange" | ||
| checked={radioVal == "orange"} | ||
| isDisabled | ||
| onChange={(e) => setRadioVal(e.target.value)} | ||
| ></Radio> | ||
| Orange | ||
| </label> | ||
| </div> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| <RadioContainer> | ||
| <RadioGroupExample /> | ||
| </RadioContainer> | ||
|
|
||
| ##### Radio Group | ||
|
|
||
| ```jsx | ||
| <RadioGroup orientation="verticle"> | ||
| <label> | ||
| <Radio name="fruits" value="apple" checked></Radio> | ||
| Apple | ||
| </label> | ||
| <label> | ||
| <Radio name="fruits" value="bannana"></Radio> | ||
| Bannana | ||
| </label> | ||
| <label> | ||
| <Radio name="fruits" value="orange" isDisabled></Radio> | ||
| Orange | ||
| </label> | ||
| </RadioGroup> | ||
| ``` | ||
|
|
||
| <RadioContainer> | ||
| <RadioGroupExample radioGroupProps={{ orientation: "verticle" }} /> | ||
| </RadioContainer> | ||
|
|
||
| ##### Radio with styles | ||
|
|
||
| ```jsx | ||
| <div> | ||
| <Radio | ||
| name="fruits" | ||
| value="bannana" | ||
| checked | ||
| radioSize="xs" | ||
| selectedStyles={{ | ||
| color: "rgb(250, 250, 250)", | ||
| borderColor: "rgb(25, 113, 194)", | ||
| backgroundColor: "rgb(25, 113, 194)" | ||
| }} | ||
| /> | ||
| <Radio name="fruits" value="orange" radioSize="sm" checked /> | ||
| <Radio | ||
| name="fruits" | ||
| value="apple" | ||
| checked | ||
| radioSize="md" | ||
| selectedStyles={{ | ||
| color: "rgb(250, 250, 250)", | ||
| borderColor: "rgb(224, 49, 49)", | ||
| backgroundColor: "rgb(224, 49, 49)" | ||
| }} | ||
| /> | ||
| </div> | ||
| ``` | ||
|
|
||
| <RadioContainer> | ||
| <RadioExample | ||
| checked | ||
| radioSize="xs" | ||
| selectedStyles={{ | ||
| color: "rgb(250, 250, 250)", | ||
| borderColor: "rgb(25, 113, 194)", | ||
| backgroundColor: "rgb(25, 113, 194)" | ||
| }} | ||
| /> | ||
| <RadioExample radioSize="sm" checked /> | ||
| <RadioExample | ||
| checked | ||
| radioSize="md" | ||
| selectedStyles={{ | ||
| color: "rgb(250, 250, 250)", | ||
| borderColor: "rgb(224, 49, 49)", | ||
| backgroundColor: "rgb(224, 49, 49)" | ||
| }} | ||
| /> | ||
| </RadioContainer> | ||
|
|
||
| ### Radio Props Reference | ||
|
|
||
| | Key | type | Optional? | | ||
| | :------------- | :-----------------------------: | --------: | | ||
| | value | `string;` | No | | ||
| | name | `string;` | No | | ||
| | radioSize | `xs` `sm` `md` `lg` `xl` string | Yes | | ||
| | isDisabled | `boolean` | Yes | | ||
| | baseStyles | `baseStyles object` | Yes | | ||
| | disabledStyles | `disabledStyles object` | Yes | | ||
| | selectedStyles | `selectedStyles object` | Yes | | ||
|
|
||
| ##### Customizing Radio Base, Selected and Disabled | ||
|
|
||
| You can customize the base, selected and disabled styles of the radio by passing in the baseStyles, selectedStyles and disabledStyles props. Refer this Spec for this: | ||
|
|
||
| baseStyles | ||
|
|
||
| | Property | Description | Default | | ||
| | --------------- | ------------------- | ------------------ | | ||
| | backgroundColor | Background of Radio | rgb(250, 250, 250) | | ||
| | borderColor | Border Color | rgb(204, 204, 204) | | ||
|
|
||
| selectedStyles | ||
|
|
||
| | Property | Description | Default | | ||
| | --------------- | ------------------------------ | ------------------ | | ||
| | backgroundColor | Selected Radio BackgroundColor | rgb(250, 250, 250) | | ||
| | borderColor | Selected Border Color | rgb(204, 204, 204) | | ||
|
|
||
| disabledStyles | ||
|
|
||
| | Property | Description | Default | | ||
| | --------------- | ------------------------------ | ------------------ | | ||
| | color | Disabled Radio Color | rgb(250, 250, 250) | | ||
| | backgroundColor | Disabled Radio BackgroundColor | rgb(250, 128, 5) | | ||
| | borderColor | Disabled Radio Border Color | rgb(174, 68, 10) | | ||
|
|
||
| ### RadioGroup Props Reference | ||
|
|
||
| | Key | type | Optional? | | ||
| | :---------- | :-----------------------------: | --------: | | ||
| | children | `React.ReactNode` | No | | ||
| | spacing | `xs` `sm` `md` `lg` `xl` string | Yes | | ||
| | orientation | `verticle` `horizontal` | Yes | | ||
| | ref | `RefObject<HTMLButtonElement>;` | Yes | |
This file contains hidden or 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,61 @@ | ||
| import { | ||
| Radio, | ||
| RadioGroup, | ||
| TRadioGroupProps, | ||
| IRadioProps | ||
| } from "@hover-design/react"; | ||
|
|
||
| import React, { useState } from "react"; | ||
|
|
||
| const RadioExample = (radioProps: Omit<IRadioProps, "ref">) => { | ||
| return <Radio {...radioProps}></Radio>; | ||
| }; | ||
| const RadioGroupExample = ({ | ||
| radioGroupProps, | ||
| radioProps | ||
| }: { | ||
| radioGroupProps: Omit<TRadioGroupProps, "ref">; | ||
| radioProps: Omit<IRadioProps, "ref">; | ||
| }) => { | ||
| const [radioVal, setRadioVal] = useState("apple"); | ||
|
|
||
| console.log("radioGroupProps", radioGroupProps); | ||
|
|
||
| return ( | ||
| <RadioGroup {...radioGroupProps}> | ||
| <label> | ||
| <RadioExample | ||
| name="fruits" | ||
| value="apple" | ||
| checked={radioVal == "apple"} | ||
| onChange={(e) => setRadioVal(e.target.value)} | ||
| {...radioProps} | ||
| ></RadioExample> | ||
| Apple | ||
| </label> | ||
| <label> | ||
| <RadioExample | ||
| name="fruits" | ||
| value="bannana" | ||
| checked={radioVal == "bannana"} | ||
| onChange={(e) => setRadioVal(e.target.value)} | ||
| {...radioProps} | ||
| ></RadioExample> | ||
| Bannana | ||
| </label> | ||
| <label> | ||
| <RadioExample | ||
| name="fruits" | ||
| value="orange" | ||
| checked={radioVal == "orange"} | ||
| isDisabled | ||
| onChange={(e) => setRadioVal(e.target.value)} | ||
| {...radioProps} | ||
| ></RadioExample> | ||
| Orange | ||
| </label> | ||
| </RadioGroup> | ||
| ); | ||
| }; | ||
|
|
||
| export { RadioExample, RadioGroupExample }; |
This file contains hidden or 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 hidden or 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,19 @@ | ||
| import { Radio } from "."; | ||
| import type { Story } from "@ladle/react"; | ||
| import { IRadioProps } from "./radio.types"; | ||
| import { useRef } from "react"; | ||
|
|
||
| export const Controls: Story<Omit<IRadioProps, "ref">> = ({ | ||
| ...nativeProps | ||
| }) => { | ||
| return ( | ||
| <> | ||
| <Radio {...nativeProps} /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| Controls.args = { | ||
| disabled: false | ||
| }; | ||
| Controls.argTypes = {}; |
This file contains hidden or 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,76 @@ | ||
| import React, { ForwardRefRenderFunction } from "react"; | ||
| import { IRadioProps } from "./radio.types"; | ||
| import { | ||
| radioWrapperClass, | ||
| radioCheckMarkClass, | ||
| radioThemeVars, | ||
| radioSizes, | ||
| radioThemeClass | ||
| } from "./radio.styles.css"; | ||
| import "./radio.global.styles.css"; | ||
| import { assignInlineVars } from "@vanilla-extract/dynamic"; | ||
| import { eliminateUndefinedKeys } from "src/utils/object-utils"; | ||
| import { SvgDot } from "../_internal/Icons/SvgDot"; | ||
|
|
||
| const Radio: ForwardRefRenderFunction<HTMLInputElement, IRadioProps> = ( | ||
| { | ||
| className, | ||
| style, | ||
| value, | ||
| name, | ||
| checked, | ||
| radioSize = "xs", | ||
| isDisabled = false, | ||
| baseStyles, | ||
| disabledStyles, | ||
| selectedStyles, | ||
| ...nativeProps | ||
| }, | ||
| ref | ||
| ) => { | ||
| const assignVariables = assignInlineVars( | ||
| eliminateUndefinedKeys({ | ||
| [radioThemeVars.radioStyleSize]: radioSizes[radioSize] | ||
| ? radioSizes[radioSize] | ||
| : undefined, | ||
| [radioThemeVars.baseStyles.backgroundColor]: baseStyles?.backgroundColor, | ||
| [radioThemeVars.baseStyles.borderColor]: baseStyles?.borderColor, | ||
| [radioThemeVars.selectedStyles.backgroundColor]: | ||
| selectedStyles?.backgroundColor, | ||
| [radioThemeVars.selectedStyles.borderColor]: selectedStyles?.borderColor, | ||
| [radioThemeVars.selectedStyles.color]: selectedStyles?.color, | ||
| [radioThemeVars.disabledStyles.backgroundColor]: | ||
| disabledStyles?.backgroundColor, | ||
| [radioThemeVars.disabledStyles.borderColor]: disabledStyles?.borderColor | ||
| }) | ||
| ); | ||
|
|
||
| return ( | ||
| <div | ||
| className={`${radioWrapperClass} ${radioThemeClass} ${className || ""}`} | ||
| style={{ ...assignVariables, ...(style || {}) }} | ||
| > | ||
| <input | ||
| ref={ref} | ||
| {...nativeProps} | ||
| type="radio" | ||
| value={value} | ||
| name={name} | ||
| checked={checked} | ||
| disabled={isDisabled} | ||
| /> | ||
| <div | ||
| aria-hidden="true" | ||
| className={`${radioCheckMarkClass}`} | ||
| data-checked={checked ? "true" : "false"} | ||
| data-disabled={isDisabled ? "true" : "false"} | ||
| data-test | ||
| > | ||
| {checked ? <SvgDot /> : null} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const RadioWithRef = React.forwardRef(Radio); | ||
| export { RadioWithRef as Radio }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.