-
Notifications
You must be signed in to change notification settings - Fork 6
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
1e5a0cf
commit dfd0cc7
Showing
6 changed files
with
289 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui'; | ||
import { Radio, RadioGroupProps } from '@yuntijs/ui'; | ||
|
||
export default () => { | ||
const store = useCreateStore(); | ||
const options = [ | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Pear', value: 'Pear' }, | ||
{ label: 'Orange', value: 'Orange', disabled: true }, | ||
]; | ||
const control: RadioGroupProps | any = useControls( | ||
{ | ||
defaultValue: options[0].value, | ||
disabled: false, | ||
optionType: { | ||
options: ['default', 'button'], | ||
value: 'default', | ||
}, | ||
buttonStyle: { | ||
options: ['outline', 'solid'], | ||
value: 'outline', | ||
}, | ||
buttonBorderRadius: false, | ||
buttonGap: false, | ||
size: { | ||
options: ['large', 'middle', 'small'], | ||
value: 'middle', | ||
}, | ||
}, | ||
{ store } | ||
); | ||
return ( | ||
<StoryBook levaStore={store}> | ||
<Radio.Group {...control} options={options} /> | ||
</StoryBook> | ||
); | ||
}; |
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,37 @@ | ||
import { Radio, Space } from '@yuntijs/ui'; | ||
|
||
export default () => { | ||
const options = [ | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Pear', value: 'Pear' }, | ||
{ label: 'Orange', value: 'Orange', disabled: true }, | ||
]; | ||
return ( | ||
<Space direction="vertical"> | ||
<Radio.Group defaultValue={options[0].value} options={options} /> | ||
<Radio.Group defaultValue={options[0].value} optionType="button" options={options} /> | ||
<Radio.Group | ||
buttonStyle="solid" | ||
defaultValue={options[0].value} | ||
optionType="button" | ||
options={options} | ||
/> | ||
<Radio.Group | ||
buttonBorderRadius={15} | ||
buttonGap={15} | ||
buttonStyle="solid" | ||
defaultValue={options[0].value} | ||
optionType="button" | ||
options={options} | ||
/> | ||
<Radio.Group | ||
buttonBorderRadius={true} | ||
buttonGap={true} | ||
buttonStyle="solid" | ||
defaultValue={options[0].value} | ||
optionType="button" | ||
options={options} | ||
/> | ||
</Space> | ||
); | ||
}; |
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,35 @@ | ||
--- | ||
nav: Components | ||
group: Data Entry | ||
title: Radio | ||
description: Used to select a single state from multiple options. | ||
--- | ||
|
||
## Usage | ||
|
||
based on antd [Radio](https://ant.design/components/radio-cn/) component. | ||
|
||
### Simple usage | ||
|
||
```jsx | pure | ||
import { Radio } from '@yuntijs/ui'; | ||
|
||
export default () => { | ||
const options = [ | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Pear', value: 'Pear' }, | ||
{ label: 'Orange', value: 'Orange', disabled: true }, | ||
]; | ||
return <Radio.Group options={options} defaultValue={options[0].value} />; | ||
}; | ||
``` | ||
|
||
<code src="./demos/index.tsx" center></code> | ||
|
||
## Playground | ||
|
||
<code src="./demos/Playground.tsx" nopadding></code> | ||
|
||
## APIs | ||
|
||
<API></API> |
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,34 @@ | ||
import { Radio as AntdRadio, type RadioGroupProps as AntdRadioGroupProps, RadioProps } from 'antd'; | ||
import type { RadioRef } from 'antd/es/radio/interface'; | ||
import { cloneDeep } from 'lodash-es'; | ||
import React from 'react'; | ||
|
||
import { useStyles } from './style'; | ||
|
||
export interface CustomRadioProps { | ||
buttonGap?: 'small' | 'middle' | 'large' | number | boolean; | ||
buttonBorderRadius?: number | boolean; | ||
} | ||
|
||
export interface RadioGroupProps extends AntdRadioGroupProps, CustomRadioProps {} | ||
|
||
type RadioType = React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<RadioRef>> & { | ||
Group: typeof Group; | ||
Button: typeof AntdRadio.Button; | ||
}; | ||
export const Radio = cloneDeep(AntdRadio) as RadioType; | ||
|
||
const Group: React.FC<RadioGroupProps> = props => { | ||
const { className, ...otherProps } = props; | ||
|
||
const { styles, cx } = useStyles(otherProps); | ||
|
||
return <AntdRadio.Group {...otherProps} className={cx(styles.custom, className)} />; | ||
}; | ||
Radio.Group = Group; | ||
|
||
Radio.Button = AntdRadio.Button; | ||
|
||
export default Radio; | ||
|
||
export { type RadioChangeEvent, type RadioProps } from 'antd'; |
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,65 @@ | ||
import { createStyles } from 'antd-style'; | ||
|
||
import { RadioGroupProps } from './index'; | ||
|
||
export const useStyles = createStyles( | ||
({ css, token }, { size, buttonBorderRadius, buttonGap }: RadioGroupProps) => { | ||
const getButtonGapSize = () => { | ||
const buttonGapSizeMap = { | ||
small: token.sizeSM, | ||
middle: token.size, | ||
large: token.sizeLG, | ||
}; | ||
if (typeof buttonGap === 'string') { | ||
return buttonGapSizeMap[buttonGap]; | ||
} | ||
if (buttonGap === true) { | ||
return size ? buttonGapSizeMap[size] : buttonGapSizeMap['middle']; | ||
} | ||
if (!buttonGap) { | ||
return 0; | ||
} | ||
return buttonGap; | ||
}; | ||
|
||
const getButtonBorderRadius = () => { | ||
const buttonBorderRadiusSizeMap = { | ||
small: token.controlHeightSM, | ||
middle: token.controlHeight, | ||
large: token.controlHeightLG, | ||
}; | ||
if (buttonBorderRadius === true) { | ||
return size ? buttonBorderRadiusSizeMap[size] : buttonBorderRadiusSizeMap['middle']; | ||
} | ||
if (buttonBorderRadius || buttonBorderRadius === 0) { | ||
return buttonBorderRadius; | ||
} | ||
}; | ||
const buttonBorderRadiusStyle = | ||
getButtonBorderRadius() && | ||
css` | ||
label { | ||
border-inline-start-width: 1px !important; | ||
border-radius: ${getButtonBorderRadius()}px !important; | ||
} | ||
label::before { | ||
display: none !important; | ||
} | ||
`; | ||
const buttonGapStyle = css` | ||
label { | ||
margin-right: ${getButtonGapSize()}px !important; | ||
} | ||
label:last-child { | ||
margin-right: 0 !important; | ||
} | ||
`; | ||
return { | ||
custom: css` | ||
${buttonBorderRadiusStyle} | ||
${buttonGapStyle} | ||
`, | ||
}; | ||
}, | ||
{ hashPriority: 'low' } | ||
); |
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