Skip to content

Commit 195bf05

Browse files
committed
2 parents 1c52147 + bf9e9ac commit 195bf05

File tree

8 files changed

+151
-5
lines changed

8 files changed

+151
-5
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import RadioGroup from './RadioGroup';
2+
import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor';
3+
import { useState } from 'react';
4+
5+
const RadioButton = (args) => {
6+
const options = [
7+
{id: 'html', value: 'html', label:'HTML'},
8+
{id: 'css', value: 'css', label:'CSS'},
9+
{id: 'javascript', value: 'javascript', label:'JavaScript'},]
10+
11+
const [language, setLanguage] = useState({})
12+
13+
const handleChange = (e) => {
14+
setLanguage(e.target.value)
15+
}
16+
return (
17+
<SandboxEditor>
18+
{options.map((option) => (
19+
<RadioGroup className='radioItems'{...args}
20+
key={option.id}
21+
id={option.id}
22+
name='language'
23+
value={option.value}
24+
checked={language === option.value}
25+
onChange={handleChange} >
26+
<span id={option.id} >{option.label}</span>
27+
</RadioGroup>
28+
))}
29+
</SandboxEditor>
30+
)
31+
}
32+
33+
export default {
34+
title: 'UI/Input/RadioGroup',
35+
component: RadioGroup,
36+
render: (args) => <RadioButton {...args}/>
37+
};
38+
39+
export const All = {};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { DetailedHTMLProps, InputHTMLAttributes, PropsWithChildren} from 'react';
2+
import { customClassSwitcher} from "~/core";
3+
import RadioPrimitive from '~/core/primitives/Radio';
4+
const COMPONENT_NAME = 'RadioGroup';
5+
6+
export type RadioGroupProps = {
7+
8+
children?: React.ReactNode;
9+
className: string;
10+
customRootClass: string;
11+
} & DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & PropsWithChildren
12+
13+
const RadioGroup =({children,type='radio', className='',customRootClass='', ...props}:RadioGroupProps) => {
14+
const rootClass= customClassSwitcher(customRootClass,COMPONENT_NAME)
15+
16+
return (
17+
<div className={`${rootClass} ${className}`} role='radiogroup'>
18+
<RadioPrimitive
19+
type={type}
20+
{...props}>
21+
22+
{children}
23+
</RadioPrimitive>
24+
</div>
25+
)
26+
}
27+
28+
export default RadioGroup;

src/components/ui/Switch/stories/Switch.stories.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ const CheckBox = (args) => {
1313
setIsChecked(state);
1414
};
1515
return <SandboxEditor className="space-x-1">
16-
{variants.map((variant, index) => (
17-
<Switch defaultChecked={args} key={index} variant={variant} onChange={handleChange} {...args} />
18-
))}
19-
20-
</SandboxEditor>;
16+
{variants.map((variant,index) => (
17+
<Switch defaultChecked={args} key={index} variant={variant} onChange={handleChange} {...args} />
18+
))}
19+
20+
</SandboxEditor>;
21+
2122
};
2223

2324
export const All = {};

src/core/primitives/Button/ButtonPrimitive.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export default {
1010
<div >
1111
<div className='flex space-x-2 w-full flex-1'>
1212
<ButtonPrimitive {...args} />
13+
1314
</div>
15+
1416
</div>
1517
</SandboxEditor>
1618
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from "react";
2+
import RadioPrimitive from '.';
3+
import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor';
4+
5+
export default {
6+
title: 'Primitives/RadioPrimitive',
7+
component: RadioPrimitive,
8+
render: (args:React.ComponentProps<typeof RadioPrimitive>) => <SandboxEditor>
9+
10+
<RadioPrimitive {...args} />
11+
</SandboxEditor>
12+
13+
}
14+
15+
export const All = {
16+
args: {
17+
role: 'radio',
18+
children: 'Radio',
19+
checked: false,
20+
}
21+
}
22+
23+
export const WithAriaLabel = {
24+
args: {
25+
role: 'radio',
26+
'aria-label': 'Aria label',
27+
children: 'Radio',
28+
}
29+
}
30+
31+
export const Checked = {
32+
33+
args: {
34+
role: 'radio',
35+
checked: true,
36+
children: 'Radio',
37+
}
38+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from "react";
2+
3+
const RadioPrimitive = ({role='radio', label='', id, value, defaultChecked, onChange, checked, children, ...props}:any) => {
4+
const ariaProps = {
5+
'aria-label': label || undefined,
6+
'aria-checked': checked ? 'true' : 'false',
7+
'data-checked': checked ? 'true' : 'false'
8+
}
9+
10+
return (
11+
<div>
12+
13+
14+
<input type='radio' id={id} {...ariaProps} {...props} value={value} checked={defaultChecked} onChange={onChange} />
15+
16+
<label htmlFor={id}> {children}</label>
17+
18+
</div>
19+
)
20+
}
21+
22+
export default RadioPrimitive
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.rad-ui-radio-group{
2+
margin-top: 20px;
3+
display: flex;
4+
flex-direction: column;
5+
gap: 10px;
6+
color: var(--rad-ui-color-accent-900);
7+
&.radioItems{
8+
font-size: 1.2rem;
9+
}
10+
11+
&:focus{
12+
outline: 2px solid var(--rad-ui-color-accent-900);
13+
outline-offset: 2px;
14+
}
15+
}

styles/themes/default.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@import "./components/progress.scss";
1919
@import "./components/toggle.scss";
2020
@import "./components/toggle-group.scss";
21+
@import "./components/radio.scss";
2122
@import "./components/switch.scss";
2223
@import "./components/skeleton.scss";
2324

0 commit comments

Comments
 (0)